187 lines
4.2 KiB
C#
187 lines
4.2 KiB
C#
///////////////////////////////////////////////////////////
|
|
// AddressFieldPickList.cs
|
|
// Implementation of Class AddressFieldPickList
|
|
// CSLA type: Read only collection
|
|
// Created on: 15-Dec-2008
|
|
// Object design: John
|
|
// Coded: 15-Dec-2008
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using GZTW.Data;
|
|
using CSLA.Data;
|
|
using CSLA;
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
#pragma warning disable 1591
|
|
//case 486
|
|
/// <summary>
|
|
/// List of distinct address fields previously entered
|
|
/// for autocomplete selection in address editing
|
|
///
|
|
/// </summary>
|
|
[Serializable]
|
|
public class AddressFieldPickList : ReadOnlyCollectionBase
|
|
{
|
|
#region Data structure
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Serializable]
|
|
public struct AddressFieldPickListInfo
|
|
{
|
|
|
|
internal string mName;
|
|
public string Name {get{return mName;}}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Equals(AddressFieldPickListInfo obj)
|
|
{
|
|
return this.mName.Equals(obj.mName);
|
|
}
|
|
|
|
}//end AddressFieldPickListInfo
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
protected AddressFieldPickList()
|
|
{
|
|
// AllowSort=false;
|
|
// AllowFind=true;
|
|
// AllowEdit=false;
|
|
// AllowNew=false;
|
|
// AllowRemove=false;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Business properties and methods
|
|
|
|
/// <summary>
|
|
/// Get item by index
|
|
/// </summary>
|
|
/// <param name="Item"></param>
|
|
public AddressFieldPickListInfo this[int Item]
|
|
{
|
|
|
|
get
|
|
{
|
|
return (AddressFieldPickListInfo) List[Item];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region contains
|
|
/// <summary>
|
|
/// Check if item in collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Contains(AddressFieldPickListInfo obj)
|
|
{
|
|
foreach (AddressFieldPickListInfo child in List)
|
|
{
|
|
if(child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
|
|
|
|
public static AddressFieldPickList GetList(AddressField fld)
|
|
{
|
|
return (AddressFieldPickList) DataPortal.Fetch(new Criteria(fld));
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
///
|
|
/// <param name="Criteria"></param>
|
|
protected override void DataPortal_Fetch(object Criteria)
|
|
{
|
|
Criteria crit = (Criteria)Criteria;
|
|
SafeDataReader dr = null;
|
|
try
|
|
{
|
|
switch (crit.fld)
|
|
{
|
|
case AddressField.City:
|
|
dr = DBUtil.GetReaderFromSQLString("SELECT DISTINCT ACITY AS AFLD FROM AADDRESS ORDER BY ACITY ASC");
|
|
break;
|
|
case AddressField.Country:
|
|
dr = DBUtil.GetReaderFromSQLString("SELECT DISTINCT ACOUNTRY AS AFLD FROM AADDRESS ORDER BY ACOUNTRY ASC");
|
|
break;
|
|
case AddressField.Postal:
|
|
dr = DBUtil.GetReaderFromSQLString("SELECT DISTINCT APOSTAL AS AFLD FROM AADDRESS ORDER BY APOSTAL ASC");
|
|
break;
|
|
case AddressField.State:
|
|
dr = DBUtil.GetReaderFromSQLString("SELECT DISTINCT ASTATEPROV AS AFLD FROM AADDRESS ORDER BY ASTATEPROV ASC");
|
|
break;
|
|
}
|
|
|
|
|
|
|
|
while(dr.Read())
|
|
{
|
|
//*******************************************
|
|
AddressFieldPickListInfo info=new AddressFieldPickListInfo();
|
|
info.mName=dr.GetString("AFLD");
|
|
InnerList.Add(info);
|
|
//*******************************************
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if(dr!=null) dr.Close();
|
|
}
|
|
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region criteria
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[Serializable]
|
|
private class Criteria
|
|
{
|
|
|
|
|
|
public AddressField fld;
|
|
|
|
public Criteria(AddressField _fld )
|
|
{
|
|
fld = _fld;
|
|
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
public enum AddressField
|
|
{
|
|
City, Postal, State, Country
|
|
}
|
|
|
|
}//end AddressFieldPickList
|
|
#pragma warning restore 1591
|
|
}//end namespace GZTW.AyaNova.BLL |