/////////////////////////////////////////////////////////// // MemoListRi.cs // Implementation of Class MemoListRi // CSLA type: Read only collection // Created on: 19-March-2015 // Object design: John // Coded: 19-March-2015 /////////////////////////////////////////////////////////// //created for case 1975 using System; using System.Data; using GZTW.Data; using CSLA.Data; using CSLA; using System.Threading; using CSLA.Security; using System.Collections.Generic; namespace GZTW.AyaNova.BLL { #pragma warning disable 1591 /// /// Lightweight read only list of objects representing object /// /// [Serializable] public class MemoListRi : ReadOnlyCollectionBase { #region Data structure /// /// Properties /// [Serializable] public struct MemoListRiInfo { internal Guid mID; internal string mCreated; internal string mSubject; internal string mFrom; internal bool mViewed; internal bool mReplied; internal decimal mTotal; public Guid ID { get {return mID;}} public string Created {get{return mCreated;}} public string From {get{return mFrom;}} public string Subject {get{return mSubject;}} public bool Viewed { get { return mViewed; } } public bool Replied { get { return mReplied; } } public decimal Total { get { return mTotal; } } /// /// /// /// public bool Equals(MemoListRiInfo obj) { return this.ID.Equals(obj.ID); } }//end MemoListRiInfo #endregion #region Constructor //private RelativeTimeFormatter rtfm=null; protected MemoListRi() { //rtfm=RelativeTimeFormatter.GetItem(User.CurrentUserLanguage); } #endregion #region Business properties and methods /// /// Get item by index /// /// public MemoListRiInfo this[int Item] { get { return (MemoListRiInfo)List[Item]; } } /// /// Returns display text that matches passed in itemid value /// /// public string this[Guid ItemID] { get { foreach (MemoListRiInfo child in List) { if (child.ID == ItemID) return child.ToString(); } return "Missing: " + ItemID.ToString(); } } #endregion #region contains /// /// Check if item in collection /// /// public bool Contains(MemoListRiInfo obj) { foreach (MemoListRiInfo child in List) { if (child.Equals(obj)) return true; } return false; } #endregion #region Static methods //case 1975 /// /// Get MaxRecords Client notes for specified client (-1 for all) /// public static MemoListRi GetList(int MaxRecords) { return (MemoListRi)DataPortal.Fetch(new Criteria(MaxRecords)); } #endregion #region DAL DATA ACCESS /// /// protected override void DataPortal_Fetch(object Criteria) { Criteria crit = (Criteria)Criteria; SafeDataReader dr = null; try { decimal dTotal = DBUtil.ScalarToDecimal(DBUtil.GetScalarFromSQLString("SELECT COUNT(AID) FROM aMemo WHERE aMemo.aToID=@ID", CurrentUserID)); //************************************************************ string q = "SELECT ~MAXRECS~ aMemo.aID, aMemo.aCreated, " + "aMemo.aViewed, aMemo.aReplied, aMemo.aSubject, " + "aMemo.aFromID, aUser.aFirstName, aUser.aLastName, aUser.aInitials, AREGION.ANAME AS AREGIONNAME, " + "aUser.aEmployeeNumber FROM aMemo " + " LEFT OUTER JOIN aUser ON aMemo.aFromID = aUser.aID " + " LEFT OUTER JOIN AREGION ON (AUSER.AREGIONID=AREGION.AID) " + "WHERE (aMemo.aToID = @ID) " + "ORDER BY AMEMO.ACREATED DESC;"; //************************************************************ if (crit.MaxRecords > 0) q = q.Replace("~MAXRECS~", "TOP " + crit.MaxRecords.ToString()); else q = q.Replace("~MAXRECS~", ""); dr = DBUtil.GetReaderFromSQLString(q, CurrentUserID); bool bFirst = true; while (dr.Read()) { //******************************************* MemoListRiInfo info = new MemoListRiInfo(); info.mID = dr.GetGuid("aID"); info.mCreated = DBUtil.ToLocal(dr.GetSmartDate("aCreated")).ToString(); info.mFrom = User.NameFormatter(dr.GetString("aFirstName"), dr.GetString("aLastName"), dr.GetString("aInitials"), dr.GetString("aEmployeeNumber"), dr.GetString("AREGIONNAME"), AyaBizUtils.GlobalSettings.DefaultScheduleableUserNameDisplayFormat); info.mSubject = dr.GetString("aSubject"); info.mViewed = dr.GetBoolean("aViewed"); info.mReplied = dr.GetBoolean("aReplied"); if (bFirst) { info.mTotal = dTotal; bFirst = false; } InnerList.Add(info); //******************************************* } } finally { if (dr != null) dr.Close(); } } #endregion #region criteria /// /// Criteria for identifying existing object /// [Serializable] private class Criteria { public int MaxRecords; public Criteria(int _MaxRecords) { MaxRecords = _MaxRecords; } } #endregion }//end MemoListRi #pragma warning restore 1591 }//end namespace GZTW.AyaNova.BLL