/////////////////////////////////////////////////////////// // FollowUpPickList.cs // Implementation of Class FollowUpPickList // CSLA type: Read only collection // Created on: 19-Nov-2007 // Object design: John // Coded: 19-Nov-2007 /////////////////////////////////////////////////////////// using System; using System.Collections.Generic; using System.Text; using GZTW.Data; using CSLA.Data; using CSLA; namespace GZTW.AyaNova.BLL { /// /// Lightweight list of objects representing objects /// that are linked to a root object. /// [Serializable] public class FollowUpPickList : ReadOnlyCollectionBase { #region Data structure /// /// /// [Serializable] public struct FollowUpPickListInfo { internal Guid mID; internal string mName; //Public properties /// /// /// public Guid ID { get { return mID; } } /// /// /// public string Name { get { return mName; } } /// /// /// /// public bool Equals(FollowUpPickListInfo obj) { return this.mID.Equals(obj.mID); } }//end FollowUpPickListInfo #endregion #region Constructor /// /// /// protected FollowUpPickList() { // AllowSort=false; // AllowFind=true; // AllowEdit=false; // AllowNew=false; // AllowRemove=false; } #endregion #region Business properties and methods /// /// Get item by index /// /// public FollowUpPickListInfo this[int Item] { get { return (FollowUpPickListInfo)List[Item]; } } /// /// Returns FollowUpPickListInfo item that matches passed in itemid value /// /// public FollowUpPickListInfo this[Guid ItemID] { get { foreach (FollowUpPickListInfo child in List) { if (child.mID == ItemID) return child; } throw new ArgumentException("FollowUpPickList: ID not found:\r\n" + ItemID.ToString()); } } #endregion #region contains /// /// Check if item in collection /// /// public bool Contains(FollowUpPickListInfo obj) { foreach (FollowUpPickListInfo child in List) { if (child.Equals(obj)) return true; } return false; } #endregion #region Static methods /// /// Get all follow ups for id /// /// list of objects public static FollowUpPickList GetList(Guid rootObjectID) { if (rootObjectID == Guid.Empty) throw new System.ApplicationException("FollowUpPickList->GetList: Error rootObjectID is empty"); return (FollowUpPickList)DataPortal.Fetch(new Criteria(rootObjectID)); } #endregion #region DAL DATA ACCESS /// /// protected override void DataPortal_Fetch(object Criteria) { Criteria crit = (Criteria)Criteria; SafeDataReader dr = null; try { dr = DBUtil.GetReaderFromSQLString( //************************************************************ "SELECT AID, ANAME FROM aschedulemarker " + "WHERE AFOLLOWID = @ID ORDER BY ANAME", crit.rootObjectID //************************************************************ ); while (dr.Read()) { //******************************************* FollowUpPickListInfo info = new FollowUpPickListInfo(); info.mID = dr.GetGuid("aID"); 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 rootObjectID; public Criteria(Guid _rootObjectID) { rootObjectID=_rootObjectID; } } #endregion }//end FollowUpPickList }