/////////////////////////////////////////////////////////// // FollowUpListForUser.cs // Implementation of Class FollowUpListForUser // CSLA type: Read only collection // Created on: 24-Sept-2015 // Object design: John // Coded: 24-Sept-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 { /// /// Internal utility class used to send a list of outstanding follow ups /// for a user to the manager account via memo /// [Serializable(), System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never), System.ComponentModel.Browsable(false)] public class FollowUpListForUser : ReadOnlyCollectionBase { #pragma warning disable 1591 #region Data structure [Serializable] public struct FollowUpListForUserInfo { 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; 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 Equals(FollowUpListForUserInfo obj) { return this.mID.Equals(obj.mID); } }//end FollowUpListForUserInfo #endregion #region Constructor protected FollowUpListForUser() { } #endregion #region Business properties and methods /// /// Get item by index /// /// public FollowUpListForUserInfo this[int Item] { get { return (FollowUpListForUserInfo)List[Item]; } } /// /// Returns FollowUpListForUserInfo item that matches passed in itemid value /// /// public FollowUpListForUserInfo this[Guid ItemID] { get { foreach (FollowUpListForUserInfo child in List) { if (child.mID == ItemID) return child; } throw new ArgumentException("FollowUpListForUser: ID not found:\r\n" + ItemID.ToString()); } } #endregion #region contains /// /// Check if item in collection /// /// public bool Contains(FollowUpListForUserInfo obj) { foreach (FollowUpListForUserInfo child in List) { if (child.Equals(obj)) return true; } return false; } #endregion #region Static methods /// /// Get all follow ups for user specified that have a stop date and time /// which is in the future and send them to the Manager account via memo /// /// /// list of objects [ System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never), System.ComponentModel.Browsable(false)] public static void SendListViaMemoToManager(Guid userID) { System.Text.StringBuilder sb = new StringBuilder(); if (userID == Guid.Empty) throw new System.ApplicationException("FollowUpListForUser->GetList: Error userID is empty"); string sUserName=UserPickList.GetListOfOneSpecificUser(userID)[0].Name; FollowUpListForUser l= (FollowUpListForUser)DataPortal.Fetch(new Criteria(userID)); if (l.Count > 0) { sb.AppendLine("User " + sUserName + " was set inactive and has these upcoming follow up items:"); foreach (FollowUpListForUser.FollowUpListForUserInfo i in l) { sb.Append(i.StartDateTime.ToString()); sb.Append(" - "); sb.Append(i.EndDateTime.ToString()); sb.Append(": "); sb.Append(i.FollowObjectName); sb.Append(" \""); sb.Append(i.Name); sb.AppendLine("\""); } Memo m = Memo.NewItem(); m.FromID = User.CurrentThreadUserID; m.ToID = User.AdministratorID; m.Subject = "Deactivated user " + sUserName + " list of active follow ups"; m.Message = sb.ToString(); m.Save(); } return; } #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 " + "(ASOURCEID = @FID) " + "AND " + "ASTOPDATE > @ANOW " + "AND " + "AFOLLOWID IS NOT NULL ORDER BY ASTARTDATE"; DBCommandWrapper cm = DBUtil.DB.GetSqlStringCommandWrapper(q); DateTime earliestEndDateToInclude = DBUtil.CurrentWorkingDateTime.AddDays(-1); cm.AddInParameter("@ANOW", DbType.DateTime, DBUtil.ToUTC(earliestEndDateToInclude)); cm.AddInParameter("@FID", DbType.Guid, crit.userID); dr = new SafeDataReader(DBUtil.DB.ExecuteReader(cm)); while (dr.Read()) { //******************************************* FollowUpListForUserInfo info = new FollowUpListForUserInfo(); info.mID = dr.GetGuid("AID"); info.mName = dr.GetString("ANAME"); info.mARGB = dr.GetInt32("AARGB"); info.mEndDateTime = DBUtil.ToLocal(dr.GetDateTime("ASTOPDATE")); 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 userID; public Criteria(Guid _userID) { userID = _userID; } } #endregion #pragma warning restore 1591 }//end FollowUpListForUser }