/////////////////////////////////////////////////////////// // TaskPickList.cs // Implementation of Class TaskPickList // CSLA type: Read only collection // Created on: 30-Dec-2004 // Object design: John // Coded: 30-Dec-2004 /////////////////////////////////////////////////////////// using System; using System.Data; using GZTW.Data; using CSLA.Data; using CSLA; namespace GZTW.AyaNova.BLL { /// /// Lightweight read only list of objects representing objects. /// Used for selection in UI and by API business objects internally. /// [Serializable] public class TaskPickList : ReadOnlyCollectionBase { #region Data structure /// /// /// [Serializable] public struct TaskPickListInfo { internal Guid mID; internal string mName; internal bool mActive; //internal string mNotes; //Public properties /// /// /// public Guid ID {get{return mID;}} /// /// /// public string Name {get{return mName;}} /// /// /// public bool Active {get{return mActive;}} //public string Notes {get{return mNotes;}} /// /// /// /// public bool Equals(TaskPickListInfo obj) { return this.mID.Equals(obj.mID); } }//end TaskPickListInfo #endregion #region Constructor /// /// /// protected TaskPickList() { // AllowSort=false; // AllowFind=true; // AllowEdit=false; // AllowNew=false; // AllowRemove=false; } #endregion #region Business properties and methods /// /// Get item by index /// /// public TaskPickListInfo this[int Item] { get { return (TaskPickListInfo) List[Item]; } } /// /// Returns TaskPickListInfo item that matches passed in itemid value /// /// public TaskPickListInfo this[Guid ItemID] { get { foreach (TaskPickListInfo child in List) { if(child.mID==ItemID) return child; } throw new ArgumentException("TaskPickList: ID not found:\r\n"+ItemID.ToString()); } } #endregion #region contains /// /// Check if item in collection /// /// public bool Contains(TaskPickListInfo obj) { foreach (TaskPickListInfo child in List) { if(child.Equals(obj)) return true; } return false; } #endregion #region Static methods /// /// Get all tasks /// /// list of objects public static TaskPickList GetList() { return (TaskPickList) DataPortal.Fetch(new Criteria()); } #endregion #region DAL DATA ACCESS /// /// protected override void DataPortal_Fetch(object Criteria) { SafeDataReader dr = null; try { dr=DBUtil.GetReaderFromSQLString( //************************************************************ "SELECT aID, AACTIVE, aName FROM aTask" //************************************************************ ); while(dr.Read()) { //******************************************* TaskPickListInfo info=new TaskPickListInfo(); info.mID=dr.GetGuid("aID"); info.mActive=dr.GetBoolean("AACTIVE"); info.mName=dr.GetString("aName"); InnerList.Add(info); //******************************************* } } finally { if(dr!=null) dr.Close(); } } #endregion #region criteria /// /// Criteria for identifying existing object /// [Serializable] private class Criteria { //public Guid TaskID; public Criteria( ) { //TaskID=_TaskID; } } #endregion }//end TaskPickList }//end namespace GZTW.AyaNova.BLL