/////////////////////////////////////////////////////////// // DashboardReminderList.cs // Implementation of Class DashboardReminderList // CSLA type: Read only collection // Created on: 10-Jan-2012 // Object design: John // Coded: 10-Jan-2012 /////////////////////////////////////////////////////////// using System; using System.Data; using GZTW.Data; using CSLA.Data; using CSLA; using System.Text.RegularExpressions; using System.Threading; using CSLA.Security; namespace GZTW.AyaNova.BLL { /// /// A list of reminders (schedule markers) for populating the dashboard in AyaNova /// (Read only collection ) /// [Serializable] public class DashboardReminderList : ReadOnlyCollectionBase { #region Data structure /// /// /// [Serializable] public struct DashboardReminderListInfo { //used to indicate there is nothing in this //struct internal bool mIsEmpty; //internal Guid mWorkorderID; //internal Guid mWorkorderItemID; //internal int mServiceNumber; internal RootObjectTypes mAppliesToObjectType; internal Guid mAppliesToObjectID; internal RootObjectTypes mSourceObjectType; //This is the workorderitemscheduleduser record ID internal Guid mSourceObjectID; internal string mSubject; internal string mDetails; internal DateTime mStartDateTime; internal DateTime mEndDateTime; internal bool mAllDay; //If internal bool mShowPriorityFlag; internal int mPriorityARGB; internal int mBackColorARGB; #pragma warning disable 1591 /// /// true if there is nothing in this record /// false if this record contains a valid appointment /// public bool IsEmpty {get{return mIsEmpty;}set{mIsEmpty=value;}} /// /// What object type this appointment applies to, can be single user /// or another object type that represents a group of users /// such as: region, sched user group etc etc /// public RootObjectTypes AppliesToObjectType{get{return mAppliesToObjectType;}} /// /// Object ID appointment applies to /// public Guid AppliesToObjectID{get{return mAppliesToObjectID;}} /// /// Type of appointment /// either ScheduleMarker or WorkorderItemScheduledUser /// public RootObjectTypes SourceObjectType{get{return mSourceObjectType;}} /// /// The ID of the schedulemarker or workorderitemscheduleduser object /// public Guid SourceObjectID {get{return mSourceObjectID;}} ///// ///// ID of workorder if this appointment is a scheduled workorder user ///// //public Guid WorkorderID {get{return mWorkorderID;}} ///// ///// ID of workorder item if this appointment is a scheduled workorder user ///// //public Guid WorkorderItemID {get{return mWorkorderItemID;}} ///// ///// Visible sequential workorder number of workorder ///// if this appointment is a scheduled workorder user ///// //public int ServiceNumber {get{return mServiceNumber;}} /// /// Description of appointment, either a schedulemarker /// description or a summary of the workorder /// formatted according to the workorder /// public string Subject {get{return mSubject;}} public string Details {get{return mDetails;}} public DateTime StartDateTime {get{return mStartDateTime;}} public DateTime EndDateTime {get{return mEndDateTime;}} public bool AllDay {get{return mAllDay;}} public int PriorityARGB {get{return mPriorityARGB;}} public bool ShowPriorityFlag {get{return mShowPriorityFlag;}} /// /// Back color of appointment /// could be workorder status or schedmarker colour /// public int BackColorARGB {get{return mBackColorARGB;} } #pragma warning restore 1591 /// /// /// /// public bool Equals(DashboardReminderListInfo obj) { return this.mSourceObjectID.Equals(obj.mSourceObjectID); } }//end DashboardReminderListInfo #endregion #region Constructor /// /// /// protected DashboardReminderList() { // AllowSort=false; // AllowFind=true; // AllowEdit=false; // AllowNew=false; // AllowRemove=false; } #endregion #region Business properties and methods /// /// Get item by index /// /// public DashboardReminderListInfo this[int Item] { get { return (DashboardReminderListInfo) List[Item]; } } /// /// Returns DashboardReminderListInfo item that matches passed in itemid value /// /// public DashboardReminderListInfo this[Guid o] { get { foreach (DashboardReminderListInfo child in List) { if(child.mSourceObjectID==o) return child; } throw new ArgumentException("DashboardReminderList: SourceObjectID not found\r\n"); } } #endregion #region contains /// /// Check if item in collection /// /// public bool Contains(DashboardReminderListInfo obj) { foreach (DashboardReminderListInfo child in List) { if(child.Equals(obj)) return true; } return false; } #endregion #region Static methods /// /// Get list of objects. /// Returns list of closest upcoming reminders for currently logged in user /// /// /// What it says /// A read only collection of objects (ScheduleMarkers) public static DashboardReminderList GetList(int MaximumItemsToRetrieve) { return (DashboardReminderList)DataPortal.Fetch(new Criteria(MaximumItemsToRetrieve)); } #endregion #region DAL DATA ACCESS /// /// protected override void DataPortal_Fetch(object Criteria) { System.Collections.Generic.List ListOfAppointmentSubjects = new System.Collections.Generic.List(); Criteria crit = (Criteria)Criteria; SafeDataReader dr = null; UserListScheduleable ulist = UserListScheduleable.GetList(); try { #region Schedule markers //Not filtered by user if specific user is specified which is what we want //next query DBCommandWrapper cmSM = DBUtil.DB.GetSqlStringCommandWrapper( "SELECT aScheduleMarkerSourceType, aSourceID,aID,aNotes,aName, " + "aStopDate,aStartDate, AARGB FROM aScheduleMarker " + "WHERE (aStartDate > @CurrentDateTime) ORDER BY ASTARTDATE " ); //Add parameters cmSM.AddInParameter("@CurrentDateTime", DbType.DateTime, DBUtil.ToUTC(DBUtil.CurrentWorkingDateTime)); dr=new SafeDataReader(DBUtil.DB.ExecuteReader(cmSM)); while (dr.Read()) { DashboardReminderListInfo info=new DashboardReminderListInfo(); info.mAllDay=false; info.mIsEmpty=false; ScheduleMarkerSourceTypes smt=(ScheduleMarkerSourceTypes)dr.GetInt16("aScheduleMarkerSourceType"); info.mAppliesToObjectID = dr.GetGuid("aSourceID"); switch(smt) { case ScheduleMarkerSourceTypes.User: info.mAppliesToObjectType=RootObjectTypes.User; //screen the user to make sure they are scheduleable and active && are the current logged in user //case 1963 //If not, skip 'em if (info.mAppliesToObjectID != Guid.Empty && info.mAppliesToObjectID != ScheduleMarker.ScheduleMarkerGlobalSourceID)//is it a user? { //case 1963 changed following, not sure why it was done that way, completely wrong //if(!ulist.ContainsActiveUser(dr.GetGuid("aSourceID"))) if(info.mAppliesToObjectID!= User.CurrentThreadUserID) continue; } break; case ScheduleMarkerSourceTypes.Regional: //Case 58 //If it applies to a specific region besides default and the current user is not default region and the applies to region id is not //the current users then don't show it if ((info.mAppliesToObjectID!=Region.DefaultRegionID) && (User.CurrentUserRegionID != Region.DefaultRegionID) && info.mAppliesToObjectID != User.CurrentUserRegionID) continue; info.mAppliesToObjectType=RootObjectTypes.Region; break; case ScheduleMarkerSourceTypes.Global: info.mAppliesToObjectType=RootObjectTypes.Global; break; case ScheduleMarkerSourceTypes.DispatchZone: info.mAppliesToObjectType=RootObjectTypes.DispatchZone; break; case ScheduleMarkerSourceTypes.ScheduleableUserGroup: info.mAppliesToObjectType=RootObjectTypes.ScheduleableUserGroup; break; } info.mSourceObjectType=RootObjectTypes.ScheduleMarker; info.mSourceObjectID=dr.GetGuid("aID"); info.mDetails=dr.GetString("aNotes"); info.mSubject=dr.GetString("aName"); info.mEndDateTime=DBUtil.ToLocal(dr.GetDateTime("aStopDate")); info.mStartDateTime=DBUtil.ToLocal(dr.GetDateTime("aStartDate")); //priority doesn't apply here, but don't //leave it dangling info.mShowPriorityFlag=false; info.mPriorityARGB=0; info.mBackColorARGB=dr.GetInt32("AARGB"); InnerList.Add(info); } #endregion schedulemarkers } finally { if(dr!=null) dr.Close(); } } #endregion #region criteria /// /// Criteria for identifying existing object /// [Serializable] private class Criteria { public int MaximumItemsToRetrieve; public Criteria(int _MaximumItemsToRetrieve) { MaximumItemsToRetrieve = _MaximumItemsToRetrieve; } } #endregion }//end DashboardReminderList }//end namespace GZTW.AyaNova.BLL