233 lines
5.2 KiB
C#
233 lines
5.2 KiB
C#
///////////////////////////////////////////////////////////
|
|
// RegionList.cs
|
|
// Implementation of Class RegionList
|
|
// CSLA type: Read only collection
|
|
// Created on: 10-Nov-2004
|
|
// Object design: John
|
|
// Coded: 10-Nov-2004
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using GZTW.Data;
|
|
using CSLA.Data;
|
|
using CSLA;
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
#pragma warning disable 1591
|
|
|
|
/// <summary>
|
|
/// Read only list of <see cref="RegionList.RegionListInfo"/> objects representing <see cref="Region"/> objects.
|
|
/// Used for grids and reporting.
|
|
/// </summary>
|
|
[Serializable]
|
|
public class RegionList : ReadOnlyCollectionBase
|
|
{
|
|
#region Data structure
|
|
/// <summary>
|
|
/// Properties
|
|
/// </summary>
|
|
[Serializable]
|
|
public struct RegionListInfo
|
|
{
|
|
|
|
|
|
internal GridNameValueCellItem mName; //and ID
|
|
|
|
|
|
|
|
|
|
[SqlColumnNameAttribute("","aRegion.aID")]
|
|
public GridNameValueCellItem LT_Region_Label_Name
|
|
{
|
|
get
|
|
{
|
|
return mName;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Equals(RegionListInfo obj)
|
|
{
|
|
return this.mName.Value.Equals(obj.mName.Value);
|
|
}
|
|
|
|
}//end RegionListInfo
|
|
#endregion
|
|
|
|
#region Constructor
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
protected RegionList()
|
|
{
|
|
// 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 RegionListInfo this[int Item]
|
|
{
|
|
|
|
get
|
|
{
|
|
return (RegionListInfo) List[Item];
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Returns display text that matches passed in itemid value
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
public string this[Guid ItemID]
|
|
{
|
|
|
|
get
|
|
{
|
|
foreach (RegionListInfo child in List)
|
|
{
|
|
if (child.mName.Value == ItemID) return child.mName.Display;
|
|
}
|
|
return "Missing: "+ItemID.ToString();
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region contains
|
|
/// <summary>
|
|
/// Check if item in collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Contains(RegionListInfo obj)
|
|
{
|
|
foreach (RegionListInfo child in List)
|
|
{
|
|
if(child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
//case 2072
|
|
/// <summary>
|
|
/// Check if item in collection by Id
|
|
/// </summary>
|
|
/// <param name="Id"></param>
|
|
public bool Contains(Guid Id)
|
|
{
|
|
foreach (RegionListInfo child in List)
|
|
{
|
|
if (child.LT_Region_Label_Name.Value.Equals(Id)) return true;
|
|
}
|
|
return false;
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// Get list by criteria
|
|
/// </summary>
|
|
/// <param name="xmlCriteria">Use AyaNova UI to easily build xmlCriteria and Ctrl-Alt-g keyboard command to display it for use in your code</param>
|
|
/// <returns>list of <see cref="RegionList.RegionListInfo"/> objects</returns>
|
|
public static RegionList GetList(string xmlCriteria)
|
|
{
|
|
return (RegionList) DataPortal.Fetch(new Criteria(xmlCriteria));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Return an empty list
|
|
/// used for initializing grid
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static RegionList GetEmptyList()
|
|
{
|
|
return new RegionList();
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
///
|
|
/// <param name="Criteria"></param>
|
|
protected override void DataPortal_Fetch(object Criteria)
|
|
{
|
|
|
|
Criteria crit = (Criteria)Criteria;
|
|
|
|
SafeDataReader dr = null;
|
|
try
|
|
{
|
|
dr=DBUtil.GetReaderFromSQLString(
|
|
//************************************************************
|
|
"SELECT aRegion.aID, aRegion.aName " +
|
|
"FROM aRegion " +
|
|
AyaBizUtils.GetGridColumnCriteria(crit.CriteriaXML,true) + " " +
|
|
AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML)
|
|
//************************************************************
|
|
);
|
|
|
|
while(dr.Read())
|
|
{
|
|
//*******************************************
|
|
RegionListInfo info=new RegionListInfo();
|
|
|
|
info.mName = new GridNameValueCellItem(
|
|
dr.GetGuid("aID"),
|
|
dr.GetString("aName"),
|
|
RootObjectTypes.Region);
|
|
|
|
|
|
InnerList.Add(info);
|
|
//*******************************************
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if(dr!=null) dr.Close();
|
|
}
|
|
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region criteria
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[Serializable]
|
|
private class Criteria
|
|
{
|
|
|
|
|
|
public string CriteriaXML;
|
|
|
|
public Criteria( string _CriteriaXML)
|
|
{
|
|
CriteriaXML=_CriteriaXML;
|
|
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}//end RegionList
|
|
#pragma warning restore 1591
|
|
}//end namespace GZTW.AyaNova.BLL |