/////////////////////////////////////////////////////////// // ScheduleMarkerList.cs // Implementation of Class ScheduleMarkerList for case 1967 // CSLA type: Read only collection // Created on: 13-Feb-2017 // Object design: John // Coded: 13-Feb-2017 /////////////////////////////////////////////////////////// using System; using System.Data; using GZTW.Data; using CSLA.Data; using CSLA; using System.Collections.Generic; namespace GZTW.AyaNova.BLL { #pragma warning disable 1591 /// /// Lightweight list of objects representing objects /// /// [Serializable] public class ScheduleMarkerList : ReadOnlyCollectionBase { #region Data structure /// /// Properties /// [Serializable] public struct ScheduleMarkerListInfo { internal GridNameValueCellItem mScheduleMarker; internal string mMarkerFor; internal string mFollowObject; internal int mARGB; internal SmartDate mStartDateTime; internal SmartDate mEndDateTime; internal bool mCompleted; [SqlColumnNameAttribute("ASCHEDULEMARKER.ANAME", "ASCHEDULEMARKER.AID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.ScheduleMarker)] public GridNameValueCellItem LT_O_ScheduleMarker { get { return mScheduleMarker; } } [SqlColumnNameAttribute("grid"), Display(DisplayType.Text)] public string LT_ScheduleMarker_Label_ScheduleMarkerSourceType { get { return mMarkerFor; } } [SqlColumnNameAttribute("grid"), Display(DisplayType.Text)] public string LT_ScheduleMarker_Label_FollowUp { get { return mFollowObject; } } //see workorder pm custom list case 40 for how to deal with this //on a coloured button might be useful for this list [Display(DisplayType.Hidden)] public int ARGB { get { return mARGB; } } [SqlColumnNameAttribute("ASCHEDULEMARKER.ASTARTDATE"), Display(DisplayType.DateTime)] public object LT_ScheduleMarker_Label_StartDate { get { return mStartDateTime.DBValue; } } [SqlColumnNameAttribute("ASCHEDULEMARKER.ASTOPDATE"), Display(DisplayType.DateTime)] public object LT_ScheduleMarker_Label_StopDate { get { return mEndDateTime.DBValue; } } [SqlColumnNameAttribute("ASCHEDULEMARKER.ACOMPLETED"),Display(DisplayType.TrueFalse)] public bool LT_ScheduleMarker_Label_Completed { get { return mCompleted; } } /// /// /// /// public bool Equals(ScheduleMarkerListInfo obj) { return this.mScheduleMarker.Value.Equals(obj.mScheduleMarker.Value); } }//end ScheduleMarkerListInfo #endregion #region Constructor protected ScheduleMarkerList() { // AllowSort=false; // AllowFind=true; // AllowEdit=false; // AllowNew=false; // AllowRemove=false; } #endregion #region Business properties and methods /// /// Get item by index /// /// public ScheduleMarkerListInfo this[int Item] { get { return (ScheduleMarkerListInfo) List[Item]; } } /// /// Returns display text that matches passed in itemid value /// /// public string this[Guid ItemID] { get { foreach (ScheduleMarkerListInfo child in List) { if (child.mScheduleMarker.Value == ItemID) return child.ToString(); } return "Missing: "+ItemID.ToString(); } } #endregion #region contains /// /// Check if item in collection /// /// public bool Contains(ScheduleMarkerListInfo obj) { foreach (ScheduleMarkerListInfo child in List) { if(child.Equals(obj)) return true; } return false; } #endregion #region Reporting and shared UI editor helpers /// /// Returns the report key which is a property of /// reports used to link all reports that can be used /// with a particular data source. /// public static string ReportKey { get { return "ScheduleMarkerList"; } } /// /// Returns the Detailed report key /// which is used to determine which reports and objects /// will be used for detailed reports /// /// If empty string then indicates there is no detailed report object or reports /// public static string DetailedReportKey { get { return ""; } } /// /// Base object that this list is reporting on /// used by shared UI editor to instantiate new objects /// when user selects new in UI elements that display this list /// /// (I.E. when user clicks on new in a read only list grid, this is the object type created) /// public static RootObjectTypes BaseObjectType { get { return RootObjectTypes.ScheduleMarker; } } /// /// Locale key so that generic list editor /// UI code knows what title to give the list in a /// grid /// public string LocaleKey { get { return "ScheduleMarker.Label.List"; } } /// /// The Type of the struct used to store list records /// Used to fetch the custom display attributes of the fields /// contained within the record to modify the grid display accordingly /// /// public static Type ListRecordType { get { return typeof(ScheduleMarkerListInfo); } } /// /// Field that contains the ID of the objects /// that are the basis of this list. /// /// Used for compiling an ID list for reporting from user /// selections in a grid. /// public static string IDField { get { return "LT_O_ScheduleMarker"; } } /// /// Same as IDField but for detailed reports /// public static string IDFieldDetailed { get { return IDField; } } #endregion #region Static methods /// /// Internal method used by list factory /// Fetches all items for current user if they are scheduleable /// internal static ScheduleMarkerList Get(string Filter, int MaxRecords, List IDList) { //instead of throwing exception, return an empty list if they are not a scheduleable user if (User.CurrentUserType != UserTypes.Schedulable) return new ScheduleMarkerList(); else return (ScheduleMarkerList)DataPortal.Fetch(new Criteria(Filter, IDList, MaxRecords)); } /// /// Get all ScheduleMarker (filtered by crit) /// gets all items for current user if they are scheduleable /// /// Use AyaNova UI to easily build xmlCriteria and Ctrl-Alt-g keyboard command to display it for use in your code /// list of objects public static ScheduleMarkerList GetList(string xmlCriteria) { //instead of throwing exception, return an empty list if they are not a scheduleable user if (User.CurrentUserType != UserTypes.Schedulable) return new ScheduleMarkerList(); else return (ScheduleMarkerList)DataPortal.Fetch(new Criteria(xmlCriteria, null, -1)); } /// /// Get list by items indicated in IDList /// /// Generic list of Guid's /// list of objects public static ScheduleMarkerList GetListFromIDList(List IDList) { //case 556 //Handle empty list if (IDList.Count == 0) return new ScheduleMarkerList(); //instead of throwing exception, return an empty list if they are not a scheduleable user if (User.CurrentUserType != UserTypes.Schedulable) return new ScheduleMarkerList(); else return (ScheduleMarkerList)DataPortal.Fetch(new Criteria("", IDList, -1)); } /// /// Return an empty list /// used for initializing grid /// /// public static ScheduleMarkerList GetEmptyList() { return new ScheduleMarkerList(); } #endregion #region DAL DATA ACCESS /// /// protected override void DataPortal_Fetch(object Criteria) { Criteria crit = (Criteria)Criteria; SafeDataReader dr = null; Guid activeUserId = User.CurrentThreadUserID; //cached data UserListScheduleable uls = UserListScheduleable.GetList(); try { string q = ""; if (crit.IDList != null) { //Case 556 System.Text.StringBuilder sbIN = new System.Text.StringBuilder(); sbIN.Append(" WHERE aScheduleMarker.aID in ("); foreach (Guid gItem in crit.IDList) { sbIN.Append("'"); sbIN.Append("{"); sbIN.Append(gItem.ToString().ToUpperInvariant()); sbIN.Append("}"); sbIN.Append("',"); } sbIN.Length = sbIN.Length - 1; sbIN.Append(") "); q = "SELECT * FROM aScheduleMarker " + sbIN.ToString() + " " + AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML); } else { //************************************************************ q = "SELECT ~MAXRECS~ ASCHEDULEMARKER.* FROM ASCHEDULEMARKER "+ AyaBizUtils.GetGridColumnCriteria(crit.CriteriaXML, true) + " " + AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML); if (crit.MaxRecords > 0) q = q.Replace("~MAXRECS~", "TOP " + crit.MaxRecords.ToString()); else q = q.Replace("~MAXRECS~", ""); //************************************************************ } //----------------------------------------------------------- dr=DBUtil.GetReaderFromSQLString(q); while(dr.Read()) { ScheduleMarkerSourceTypes smt = (ScheduleMarkerSourceTypes)dr.GetInt16("ASCHEDULEMARKERSOURCETYPE"); Guid AppliesToObjectID = dr.GetGuid("ASOURCEID"); if (relevantScheduleMarker(activeUserId, smt, AppliesToObjectID, uls)) { //******************************************* ScheduleMarkerListInfo info = new ScheduleMarkerListInfo(); info.mScheduleMarker = new GridNameValueCellItem( dr.GetGuid("AID"), dr.GetString("ANAME"), RootObjectTypes.ScheduleMarker); //marker for switch (smt) { case ScheduleMarkerSourceTypes.User: info.mMarkerFor = uls[AppliesToObjectID].FullName; break; case ScheduleMarkerSourceTypes.Regional: info.mMarkerFor = NameFetcher.GetItem(RootObjectTypes.Region, AppliesToObjectID).RecordName; break; case ScheduleMarkerSourceTypes.Global: info.mMarkerFor = NameFetcher.GetItem(RootObjectTypes.Global, Guid.Empty).RecordName; break; case ScheduleMarkerSourceTypes.DispatchZone: info.mMarkerFor = NameFetcher.GetItem(RootObjectTypes.DispatchZone, AppliesToObjectID).RecordName; break; case ScheduleMarkerSourceTypes.ScheduleableUserGroup: info.mMarkerFor = NameFetcher.GetItem(RootObjectTypes.ScheduleableUserGroup, AppliesToObjectID).RecordName; break; } RootObjectTypes followType = (RootObjectTypes)dr.GetInt16("AFOLLOWTYPE"); Guid followId = dr.GetGuid("AFOLLOWID"); info.mFollowObject = ""; if (followId != Guid.Empty && followType != RootObjectTypes.Nothing) { info.mFollowObject = NameFetcher.GetItem(followType, followId).RecordName; } info.mARGB = dr.GetInt32("AARGB"); info.mStartDateTime = DBUtil.ToLocal(dr.GetSmartDate("ASTARTDATE")); info.mEndDateTime = DBUtil.ToLocal(dr.GetSmartDate("ASTOPDATE")); info.mCompleted = dr.GetBoolean("ACOMPLETED"); InnerList.Add(info); } //******************************************* } } finally { if(dr!=null) dr.Close(); } } #endregion private static bool relevantScheduleMarker(Guid activeUserId, ScheduleMarkerSourceTypes appliesToObjectType, Guid appliesToObjectId, UserListScheduleable uls) { //Don't process for unassigned user if (activeUserId == Guid.Empty) return false; //Could be a bunch by region , global , dispatchzone, schedusergroup //or could be a single by one user ID switch (appliesToObjectType) { case ScheduleMarkerSourceTypes.User: { if (appliesToObjectId == activeUserId) return true; } break; case ScheduleMarkerSourceTypes.Regional: { if (uls[activeUserId].RegionID == appliesToObjectId) return true; } break; case ScheduleMarkerSourceTypes.DispatchZone: { if (uls[activeUserId].DispatchZoneID == appliesToObjectId) return true; } break; case ScheduleMarkerSourceTypes.ScheduleableUserGroup: { ScheduleableUserGroupUsersList ScheduleMarkerGroup = ScheduleableUserGroupUsersList.GetList(appliesToObjectId); if (ScheduleMarkerGroup.Contains(activeUserId))//Case 835 return true; } break; case ScheduleMarkerSourceTypes.Global: { return true; } } return false; } #region criteria /// /// Criteria for identifying existing object /// [Serializable] private class Criteria { public List IDList; public string CriteriaXML; public int MaxRecords; public Criteria(string _CriteriaXML, List _IDList, int _MaxRecords) { CriteriaXML = _CriteriaXML; IDList = _IDList; MaxRecords = _MaxRecords; } } #endregion }//end ScheduleMarkerList #pragma warning restore 1591 }//end namespace GZTW.AyaNova.BLL