/////////////////////////////////////////////////////////// // WorkorderServiceList.cs // Implementation of Class WorkorderServiceList // CSLA type: Read only collection // Created on: 03-Jan-2005 // Object design: John // Coded: 03-Jan-2005 /////////////////////////////////////////////////////////// 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 /// /// Read only list of objects representing service workorders. /// Used by grids and summary reports. /// [Serializable] public class WorkorderServiceList : ReadOnlyCollectionBase { #region Data structure /// /// Properties /// [Serializable] public struct WorkorderServiceListInfo { #region Attributes internal GridNameValueCellItem mWorkorder; internal GridNameValueCellItem mFromQuoteID; internal GridNameValueCellItem mFromPMID; internal GridNameValueCellItem mClient; internal GridNameValueCellItem mProject; internal GridNameValueCellItem mRegion; internal GridNameValueCellItem mStatus; internal int mStatusARGB; internal GridNameValueCellItem mCategory; internal string mInternalReferenceNumber; internal string mCustomerReferenceNumber; internal string mCustomerContactName; internal string mSummary; internal SmartDate mServiceDate; internal string mInvoiceNumber; internal bool mOnsite; internal bool mServiceCompleted; internal bool mClosed; internal GridNameValueCellItem mClientGroup; internal GridNameValueCellItem mDispatchZone; internal SmartDate mCloseByDate; internal GridRelativeTimeCellItem mServiceDateRelative; //Case 39 internal GridNameValueCellItem mHeadOffice; //case 1909 internal int mAge; //case 2008 internal string mPhysicalPostalCode; #endregion attributes #region Properties [SqlColumnNameAttribute("aWorkorderService.aServiceNumber", "aWorkorder.aID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.Workorder, CompareAs=CompareType.StringToInt32)] public GridNameValueCellItem LT_O_Workorder { get { return mWorkorder; } } [SqlColumnNameAttribute("aWorkorderQuote.aQuoteNumber", "aWorkorder.aFromQuoteID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.WorkorderQuote, CompareAs=CompareType.StringToInt32)] public GridNameValueCellItem LT_Workorder_Label_FromQuoteID { get { return mFromQuoteID; } } [SqlColumnNameAttribute("aWorkorderPreventiveMaintenance.aPreventiveMaintenanceNumber","aWorkorder.aFromPMID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.WorkorderPreventiveMaintenance, CompareAs=CompareType.StringToInt32)] public GridNameValueCellItem LT_Workorder_Label_FromPMID { get { return mFromPMID; } } [SqlColumnNameAttribute("aClient.aName", "aClient.aID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.Client)] public GridNameValueCellItem LT_O_Client { get { return mClient; } } //Case 39 [SqlColumnNameAttribute("aHeadOffice.aName", "aClient.aHeadOfficeID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.HeadOffice)] public GridNameValueCellItem LT_O_HeadOffice { get { return mHeadOffice; } } [SqlColumnNameAttribute("aProject.aName","aProject.aID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.Project)] public GridNameValueCellItem LT_O_Project { get { return mProject; } } [SqlColumnNameAttribute("aRegion.aName","aRegion.aID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.Region)] public GridNameValueCellItem LT_O_Region { get { return mRegion; } } [SqlColumnNameAttribute("aWorkorderStatus.aName", "aWorkorderService.aWorkorderStatusID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.WorkorderStatus, Color = true, ColorField = "LT_WorkorderStatus_Label_ARGB")] public GridNameValueCellItem LT_O_WorkorderStatus { get { return mStatus; } } /// /// Not for viewing directly, sets the color of the status button /// [Display(DisplayType.Hidden)] public int LT_WorkorderStatus_Label_ARGB { get { return mStatusARGB; } } [SqlColumnNameAttribute("aWorkorderCategory.aName", "aWorkorderCategory.aID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.WorkorderCategory)] public GridNameValueCellItem LT_O_WorkorderCategory { get { return mCategory; } } [Display(DisplayType.Text)] public string LT_Workorder_Label_InternalReferenceNumber { get { return mInternalReferenceNumber; } } [Display(DisplayType.Text)] public string LT_Workorder_Label_CustomerReferenceNumber { get { return mCustomerReferenceNumber; } } [Display(DisplayType.Text)] public string LT_Workorder_Label_CustomerContactName { get { return mCustomerContactName; } } [Display(DisplayType.Text)] public string LT_Workorder_Label_Summary { get { return mSummary; } } [/*Case 230*/SqlColumnNameAttribute("grid"), Display(DisplayType.Text)] public GridRelativeTimeCellItem LT_WorkorderService_Label_ServiceDateRelative { get { return mServiceDateRelative; } } [Display(DisplayType.DateTime)] public object LT_WorkorderService_Label_ServiceDate { get { return mServiceDate.DBValue; } } [Display(DisplayType.Text)] public string LT_WorkorderService_Label_InvoiceNumber { get { return mInvoiceNumber; } } [Display(DisplayType.TrueFalse)] public bool LT_Workorder_Label_Onsite { get { return mOnsite; } } [Display(DisplayType.TrueFalse)] public bool LT_Workorder_Label_ServiceCompleted { get { return mServiceCompleted; } } [Display(DisplayType.TrueFalse)] public bool LT_Workorder_Label_Closed { get { return mClosed; } } [SqlColumnNameAttribute("aClientGroup.aName","aClientGroup.aID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.ClientGroup)] public GridNameValueCellItem LT_O_ClientGroup { get { return mClientGroup; } } [SqlColumnNameAttribute("aDispatchZone.aName","aDispatchZone.aID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.DispatchZone)] public GridNameValueCellItem LT_O_DispatchZone { get { return mDispatchZone; } } [Display(DisplayType.DateTime, ShowInLite = false)] public object LT_WorkorderService_Label_CloseByDate { get { return this.mCloseByDate.DBValue; } } //case 781 - contract name and expiry fields internal GridNameValueCellItem mContract; [SqlColumnNameAttribute("aContract.aName", "aClient.aContractID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.Contract, ShowInLite = false)] public GridNameValueCellItem LT_O_Contract {get { return mContract; }} internal SmartDate mContractExpires; [SqlColumnNameAttribute("aClient.aContractExpires"), Display(DisplayType.DateTime, ShowInLite = false)] public object LT_Client_Label_ContractExpires { get { return mContractExpires.DBValue; }} //case 1346 internal byte[] mSignatureImage; [Display(DisplayType.Hidden)] public byte[] SignatureImage { get { return mSignatureImage; } } internal SmartDate mSignatureClientDate; [Display(DisplayType.Hidden)] public SmartDate SignatureClientDate { get { return mSignatureClientDate; } } internal SmartDate mSignatureHostDate; [Display(DisplayType.Hidden)] public SmartDate SignatureHostDate { get { return mSignatureHostDate; } } //case 1909 [SqlColumnNameAttribute("~AGE~"), Display(DisplayType.WholeNumber)] public int LT_WorkorderService_Label_Age { get { return mAge; } } //case 2008 [Display(DisplayType.Text)] public string LT_Address_Label_Postal { get { return mPhysicalPostalCode; } } #endregion properties /// /// /// /// public bool Equals(WorkorderServiceListInfo obj) { return this.mWorkorder.Value.Equals(obj.mWorkorder.Value); } }//end WorkorderServiceListInfo #endregion #region Constructor private RelativeTimeFormatter rtfm = null; protected WorkorderServiceList() { rtfm = RelativeTimeFormatter.GetItem(User.CurrentUserLanguage); // AllowSort=false; // AllowFind=true; // AllowEdit=false; // AllowNew=false; // AllowRemove=false; } #endregion #region Business properties and methods /// /// Get item by index /// /// public WorkorderServiceListInfo this[int Item] { get { return (WorkorderServiceListInfo)List[Item]; } } /// /// Returns display text that matches passed in itemid value /// /// public string this[Guid ItemID] { get { foreach (WorkorderServiceListInfo child in List) { if (child.mWorkorder.Value == ItemID) return child.ToString(); } return "Missing: " + ItemID.ToString(); } } #endregion #region contains /// /// Check if item in collection /// /// public bool Contains(WorkorderServiceListInfo obj) { foreach (WorkorderServiceListInfo 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 "WorkorderServiceList"; } } /// /// 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 "WorkorderServiceDetailed"; } } /// /// 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.WorkorderService; } } /// /// 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(WorkorderServiceListInfo); } } /// /// Locale key so that generic list editor /// UI code knows what title to give the list in a /// grid /// public string LocaleKey { get { return "WorkorderService.Label.List"; } } /// /// 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_Workorder"; } } /// /// Same as IDField but for detailed reports /// public static string IDFieldDetailed { get { return IDField; } } #endregion #region Static methods /// /// Internal method used by list factory /// internal static WorkorderServiceList Get(string Filter, int MaxRecords, List IDList) { return (WorkorderServiceList)DataPortal.Fetch(new Criteria(Filter, IDList, MaxRecords)); } /// /// Get all WorkorderService (filtered by crit) /// /// 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 WorkorderServiceList GetList(string xmlCriteria) { return (WorkorderServiceList)DataPortal.Fetch(new Criteria(xmlCriteria, null, -1)); } //added for case 1975 RI /// /// Get MaxRecord workorders filtered by criteria /// /// /// /// public static WorkorderServiceList GetList(string xmlCriteria, int MaxRecords) { return (WorkorderServiceList)DataPortal.Fetch(new Criteria(xmlCriteria, null, MaxRecords)); } /// /// Takes a single ID and returns a "list" of one object /// /// ID of Workorder object /// list of objects public static WorkorderServiceList GetListForSingleItem(Guid WorkorderID) { //Case 554 List l=new List(); l.Add(WorkorderID); return GetListFromIDList(l); //return (WorkorderServiceList)DataPortal.Fetch(new Criteria("", WorkorderID, -1)); } /// /// Get's all workorders in the provided List of workorder id's /// (used for pick and choose printing etc) /// /// Generic list of Guid's of workorders /// public static WorkorderServiceList GetListFromIDList(List WorkorderIDList) {//case 554 //Handle empty list if (WorkorderIDList.Count == 0) return new WorkorderServiceList(); return (WorkorderServiceList)DataPortal.Fetch(new Criteria("", WorkorderIDList, -1)); } /// /// Return an empty list /// used for initializing grid /// /// public static WorkorderServiceList GetEmptyList() { return new WorkorderServiceList(); } #endregion #region DAL DATA ACCESS /// /// protected override void DataPortal_Fetch(object Criteria) { //case 1909 string AgeFragment=" CASE AWORKORDER.ACLOSED " + " WHEN 1 THEN DATEDIFF(DAY,AWORKORDER.ACREATED, AWORKORDER.AMODIFIED) " + " WHEN 0 THEN DATEDIFF(DAY, AWORKORDER.ACREATED, CURRENT_TIMESTAMP) " + " END "; Criteria crit = (Criteria)Criteria; DateTime dtNow = DBUtil.CurrentWorkingDateTime; SafeDataReader dr = null; try { DBCommandWrapper cm = null; //Base query string q = "SELECT ~MAXRECS~ aWorkorder.aID AS aWorkorderID, aWorkorderService.aServiceNumber " + "AS aWorkorderNumber, " + " aContract.aName AS aContractName, ACLIENT.aContractExpires, ACLIENT.aContractID, " +//case 781 "aClient.aName AS aClientName, aClient.aID " + "AS aClientID, aClient.aHeadOfficeID, aHeadOffice.aName as aHeadOfficeName, aWorkorder.aInternalReferenceNumber, " + " aWorkorder.aCustomerReferenceNumber, aProject.aName " + "AS aProjectName, aProject.aID AS " + "aProjectID, aRegion.aName AS aRegionName, aRegion.aID " + "AS aRegionID, aWorkorderStatus.aName " + "AS aWorkorderStatusName, aWorkorderStatus.aID " + "AS aWorkorderStatusID, aWorkorderStatus.AARGB, " + " aWorkorderService.aServiceDate, aWorkorderService.aInvoiceNumber, " + " AWORKORDERSERVICE.ASIGNATURE, AWORKORDERSERVICE.ASIGNED, " + //case 1346 " aWorkorder.aOnsite, " + " aWorkorder.aClosed, aWorkorder.aServiceCompleted, " + " aWorkorder.aCustomerContactName, aWorkorder.aSummary, " + " aWorkorderCategory.aName " + "AS aWorkorderCategoryName, aWorkorderCategory.aID " + "AS aWorkorderCategoryID, aWorkorder.aFromPMID, " + " aWorkorderPreventiveMaintenance.aPreventiveMaintenanceNumber, " + " aWorkorder.aFromQuoteID, " + " aWorkorderQuote.aQuoteNumber, aWorkorderService.aCloseByDate, " + " aClient.aDispatchZoneID, " + " aDispatchZone.aName AS aDispatchZoneName, aClient.aClientGroupID, " + " aClientGroup.aName AS aClientGroupName, " + //case 2008 " AADDRESS.APOSTAL, " + //case 1909 " ~AGE~ AS AAGE " + "FROM " + " ACLIENT " + " LEFT OUTER JOIN ADISPATCHZONE ON (ACLIENT.ADISPATCHZONEID=ADISPATCHZONE.AID) " + " LEFT OUTER JOIN ACLIENTGROUP ON (ACLIENT.ACLIENTGROUPID=ACLIENTGROUP.AID) " + " INNER JOIN AWORKORDER ON (ACLIENT.AID=AWORKORDER.ACLIENTID) " + " LEFT OUTER JOIN AREGION ON (ACLIENT.AREGIONID=AREGION.AID) " + " LEFT OUTER JOIN AWORKORDERCATEGORY ON (AWORKORDER.AWORKORDERCATEGORYID=AWORKORDERCATEGORY.AID) " + " LEFT OUTER JOIN AWORKORDERQUOTE ON (AWORKORDER.AFROMQUOTEID=AWORKORDERQUOTE.AID) " + " LEFT OUTER JOIN AWORKORDERPREVENTIVEMAINTENANCE ON (AWORKORDER.AFROMPMID=AWORKORDERPREVENTIVEMAINTENANCE.AID) " + " INNER JOIN AWORKORDERSERVICE ON (AWORKORDERSERVICE.AWORKORDERID=AWORKORDER.AID) " + " LEFT OUTER JOIN APROJECT ON (APROJECT.AID=AWORKORDER.APROJECTID) " + " LEFT OUTER JOIN AWORKORDERSTATUS ON (AWORKORDERSERVICE.AWORKORDERSTATUSID=AWORKORDERSTATUS.AID) " + //Case 39 " LEFT OUTER JOIN AHEADOFFICE ON (ACLIENT.AHEADOFFICEID=AHEADOFFICE.AID) " + //case 781 " LEFT OUTER JOIN aContract ON ACLIENT.aContractID = aContract.aID " + //case 2008 " LEFT OUTER JOIN AADDRESS ON ACLIENT.AID = AADDRESS.AROOTOBJECTID " + "WHERE (aWorkorder.aWorkorderType = 1) AND AADDRESS.AADDRESSTYPE=2 "; if (crit.MaxRecords > 0) q = q.Replace("~MAXRECS~", "TOP " + crit.MaxRecords.ToString()); else q = q.Replace("~MAXRECS~", ""); //One item or grid criteria? if (crit.IDList != null) { //Case 554 System.Text.StringBuilder sbIN = new System.Text.StringBuilder(); sbIN.Append(" AND (aWorkorder.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(")) "); cm = DBUtil.DB.GetSqlStringCommandWrapper(q + sbIN.ToString() + " " + AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML)); } else { //Grid criteria cm = DBUtil.DB.GetSqlStringCommandWrapper(DBUtil.AddRegionFilter(//case 58 q + AyaBizUtils.GetGridColumnCriteria(crit.CriteriaXML, false) + " " + AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML)) ); } //case 1909 cm.Command.CommandText = cm.Command.CommandText.Replace("~AGE~", AgeFragment); dr = new SafeDataReader(DBUtil.DB.ExecuteReader(cm)); //case 1346 AySignature sig = new AySignature(); while (dr.Read()) { //******************************************* WorkorderServiceListInfo info = new WorkorderServiceListInfo(); info.mWorkorder = new GridNameValueCellItem( dr.GetGuid("aWorkorderID"), dr.GetInt32("aWorkorderNumber").ToString(), RootObjectTypes.Workorder); info.mFromQuoteID = new GridNameValueCellItem( dr.GetGuid("aFromQuoteID"), dr.GetInt32("aQuoteNumber") == 0 ? "" : dr.GetInt32("aQuoteNumber").ToString(), RootObjectTypes.WorkorderQuote); info.mFromPMID = new GridNameValueCellItem( dr.GetGuid("aFromPMID"), dr.GetInt32("aPreventiveMaintenanceNumber") == 0 ? "" : dr.GetInt32("aPreventiveMaintenanceNumber").ToString(), RootObjectTypes.WorkorderPreventiveMaintenance); //case 781 info.mContract = new GridNameValueCellItem( dr.GetGuid("aContractID"), dr.GetString("aContractName"), RootObjectTypes.Contract); info.mContractExpires = DBUtil.ToLocal(dr.GetSmartDate("aContractExpires")); info.mClient = new GridNameValueCellItem( dr.GetGuid("aClientID"), dr.GetString("aClientName"), RootObjectTypes.Client); info.mHeadOffice = new GridNameValueCellItem( dr.GetGuid("aHeadOfficeID"), dr.GetString("aHeadOfficeName"), RootObjectTypes.HeadOffice); info.mProject = new GridNameValueCellItem( dr.GetGuid("aProjectID"), dr.GetString("aProjectName"), RootObjectTypes.Project); info.mRegion = new GridNameValueCellItem( dr.GetGuid("aRegionID"), dr.GetString("aRegionName"), RootObjectTypes.Region); info.mStatus = new GridNameValueCellItem( dr.GetGuid("aWorkorderStatusID"), dr.GetString("aWorkorderStatusName"), RootObjectTypes.WorkorderStatus); info.mCategory = new GridNameValueCellItem( dr.GetGuid("aWorkorderCategoryID"), dr.GetString("aWorkorderCategoryName"), RootObjectTypes.WorkorderCategory); info.mStatusARGB = dr.GetInt32("AARGB"); info.mInternalReferenceNumber = dr.GetString("aInternalReferenceNumber"); info.mCustomerReferenceNumber = dr.GetString("aCustomerReferenceNumber"); info.mCustomerContactName = dr.GetString("aCustomerContactName"); info.mSummary = dr.GetString("aSummary"); info.mServiceDate = DBUtil.ToLocal(dr.GetSmartDate("aServiceDate")); info.mServiceDateRelative = new GridRelativeTimeCellItem(rtfm.Format(dtNow, info.mServiceDate)); info.mInvoiceNumber = dr.GetString("aInvoiceNumber"); info.mOnsite = dr.GetBoolean("aOnsite"); info.mClosed = dr.GetBoolean("aClosed"); info.mServiceCompleted = dr.GetBoolean("aServiceCompleted"); info.mDispatchZone = new GridNameValueCellItem( dr.GetGuid("aDispatchZoneID"), dr.GetString("aDispatchZoneName"), RootObjectTypes.DispatchZone); info.mClientGroup = new GridNameValueCellItem( dr.GetGuid("aClientGroupID"), dr.GetString("aClientGroupName"), RootObjectTypes.ClientGroup); info.mCloseByDate = DBUtil.ToLocal(dr.GetSmartDate("aCloseByDate")); //case 1346 sig.Clear(); sig.SignatureCode = dr.GetString("ASIGNATURE"); info.mSignatureHostDate = DBUtil.ToLocal(dr.GetSmartDate("ASIGNED")); info.mSignatureClientDate = new SmartDate(sig.ClientCapturedDateTime); info.mSignatureImage = sig.SignatureBitmapAsByteArray; //case 1909 info.mAge = dr.GetInt32("AAGE"); //case 2008 info.mPhysicalPostalCode = dr.GetString("APOSTAL"); InnerList.Add(info); //******************************************* } } finally { if (dr != null) dr.Close(); } } #endregion #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 WorkorderServiceList #pragma warning restore 1591 }//end namespace GZTW.AyaNova.BLL