/////////////////////////////////////////////////////////// // FollowUpList.cs // Implementation of Class FollowUpList // CSLA type: Read only collection // Created on: 5-Mar-2015 // Object design: John // Coded: 5-Mar-2015 /////////////////////////////////////////////////////////// using System; using System.Collections.Generic; using System.Text; using System.Data; using GZTW.Data; using CSLA.Data; using CSLA; namespace GZTW.AyaNova.BLL { /// /// List of objects representing objects /// that are linked to a root object. A more detailed version of /// however this object only retrieves current items, not old ones past their end date. /// [Serializable] public class FollowUpList : ReadOnlyCollectionBase { #pragma warning disable 1591 #region Data structure [Serializable] public struct FollowUpListInfo { internal Guid mID; internal string mName; internal string mNotes; internal string mTechName; internal string mFollowObjectName; internal TypeAndID mFollowObject; internal int mARGB; internal DateTime mStartDateTime; internal DateTime mEndDateTime; internal bool mOutDated; public Guid ID { get { return mID; } } public string Name { get { return mName; } } public string Notes { get { return mNotes; } } public string TechName { get { return mTechName; } } public string FollowObjectName { get { return mFollowObjectName; } } public TypeAndID FollowObject { get { return mFollowObject; } } public int ARGB { get { return mARGB; } } public DateTime StartDateTime { get { return mStartDateTime; } } public DateTime EndDateTime { get { return mEndDateTime; } } public bool OutDated { get { return mOutDated; } } /// /// /// /// public bool Equals(FollowUpListInfo obj) { return this.mID.Equals(obj.mID); } }//end FollowUpListInfo #endregion #region Constructor protected FollowUpList() { } #endregion #region Business properties and methods /// /// Get item by index /// /// public FollowUpListInfo this[int Item] { get { return (FollowUpListInfo)List[Item]; } } /// /// Returns FollowUpListInfo item that matches passed in itemid value /// /// public FollowUpListInfo this[Guid ItemID] { get { foreach (FollowUpListInfo child in List) { if (child.mID == ItemID) return child; } throw new ArgumentException("FollowUpList: ID not found:\r\n" + ItemID.ToString()); } } #endregion #region contains /// /// Check if item in collection /// /// public bool Contains(FollowUpListInfo obj) { foreach (FollowUpListInfo child in List) { if (child.Equals(obj)) return true; } return false; } #endregion #region Static methods /// /// Get current and future follow ups for id /// /// list of objects public static FollowUpList GetList(Guid rootObjectID) { if (rootObjectID == Guid.Empty) throw new System.ApplicationException("FollowUpList->GetList: Error rootObjectID is empty"); return (FollowUpList)DataPortal.Fetch(new Criteria(rootObjectID)); } #endregion #region DAL DATA ACCESS /// /// protected override void DataPortal_Fetch(object Criteria) { UserPickList ulist = UserPickList.GetList(false); DateTime dtNow = DateTime.Now; Criteria crit = (Criteria)Criteria; SafeDataReader dr = null; try { string q = "SELECT * FROM ASCHEDULEMARKER " + "WHERE (AFOLLOWID = @FID) AND (ASTOPDATE > @ANOW) ORDER BY ASTARTDATE"; DBCommandWrapper cm = DBUtil.DB.GetSqlStringCommandWrapper(q); DateTime earliestEndDateToInclude = DBUtil.CurrentWorkingDateTime.AddDays(-15); cm.AddInParameter("@ANOW", DbType.DateTime, DBUtil.ToUTC(earliestEndDateToInclude)); cm.AddInParameter("@FID", DbType.Guid, crit.rootObjectID); dr = new SafeDataReader(DBUtil.DB.ExecuteReader(cm)); while (dr.Read()) { //******************************************* FollowUpListInfo info = new FollowUpListInfo(); info.mID = dr.GetGuid("AID"); info.mName = dr.GetString("ANAME"); info.mARGB = dr.GetInt32("AARGB"); info.mEndDateTime = DBUtil.ToLocal(dr.GetDateTime("ASTOPDATE")); info.mOutDated = (info.mEndDateTime < dtNow); info.mStartDateTime = DBUtil.ToLocal(dr.GetDateTime("ASTARTDATE")); info.mFollowObject = new TypeAndID((RootObjectTypes)dr.GetInt16("AFOLLOWTYPE"), dr.GetGuid("AFOLLOWID")); info.mFollowObjectName = NameFetcher.GetItem(info.mFollowObject).RecordName; info.mNotes = dr.GetString("ANOTES"); Guid gTech = dr.GetGuid("ASOURCEID"); if (gTech != Guid.Empty) info.mTechName = ulist[gTech]; else info.mTechName = string.Empty; 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 #pragma warning restore 1591 }//end FollowUpList }