/////////////////////////////////////////////////////////// // ClientWorkorderList.cs // Implementation of Class ClientWorkorderList // CSLA type: Read only collection // Created on: 11-Nov-2006 // Object design: Joyce & John Nov 11th 2006 // Coded: John 11-Nov-2006 /////////////////////////////////////////////////////////// using System; using System.Data; using GZTW.Data; using CSLA.Data; using CSLA; namespace GZTW.AyaNova.BLL { #pragma warning disable 1591 /// /// Read only list of client work orders /// Displayed in AyaNova WBI for client logins /// /// [Serializable] public class ClientWorkorderList : ReadOnlyCollectionBase { #region Data structure /// /// Properties /// [Serializable] public struct ClientWorkorderListInfo { internal GridNameValueCellItem mWorkorder; internal string mInvoice; internal SmartDate mServiceDate; internal bool mClosed; internal string mClientRef; internal string mClientContact; internal string mClient; internal string mHeadOffice; //Case 228 internal string mSummary; [SqlColumnNameAttribute("aWorkorderService.aServiceNumber", "aWorkorder.aID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.WorkorderItem, CompareAs = CompareType.StringToInt32)] public GridNameValueCellItem LT_O_Workorder { get { return mWorkorder; } } [Display(DisplayType.Text)] public string LT_WorkorderService_Label_InvoiceNumber { get { return mInvoice; } } [SqlColumnNameAttribute("AWORKORDERSERVICE.ASERVICEDATE"), Display(DisplayType.DateTime)] public object LT_WorkorderService_Label_ServiceDate { get { return mServiceDate.DBValue; } } [Display(DisplayType.TrueFalse)] public bool LT_Workorder_Label_Closed { get { return mClosed; } } [SqlColumnNameAttribute("aWorkorder.ACLIENTREF"), Display(DisplayType.Text)] public string LT_Workorder_Label_CustomerReferenceNumber { get { return this.mClientRef; } } [Display(DisplayType.Text)] public string LT_Workorder_Label_CustomerContactName { get { return mClientContact; } } [SqlColumnNameAttribute("aClient.aName"), Display(DisplayType.Text)] public string LT_O_Client { get { return mClient; } } [SqlColumnNameAttribute("aHeadOffice.aName"), Display(DisplayType.Text)] public string LT_O_HeadOffice { get { return mHeadOffice; } } //Case 228 [Display(DisplayType.Text)] public string LT_Workorder_Label_Summary { get { return mSummary; } } /// /// /// /// public bool Equals(ClientWorkorderListInfo obj) { return this.mWorkorder.Value.Equals(obj.mWorkorder.Value); } }//end ClientWorkorderListInfo #endregion #region Constructor protected ClientWorkorderList() { } #endregion #region Business properties and methods /// /// Get item by index /// /// public ClientWorkorderListInfo this[int Item] { get { return (ClientWorkorderListInfo)List[Item]; } } /// /// Returns display text that matches passed in itemid value /// /// public string this[Guid ItemID] { get { foreach (ClientWorkorderListInfo 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(ClientWorkorderListInfo obj) { foreach (ClientWorkorderListInfo 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 "ClientWorkorderList"; } } /// /// 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 { //Nothing so that no accidental possibility of //client creating a workorder return RootObjectTypes.Nothing; } } /// /// 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"; } } /// /// 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(ClientWorkorderListInfo); } } #endregion #region Static methods /// /// Get all Workorders for a specified head office /// (returns all workorders for all clients under headOfficeID) /// /// /// public static ClientWorkorderList GetListForHeadOffice(Guid headOfficeID) { return (ClientWorkorderList)DataPortal.Fetch(new Criteria(headOfficeID, Guid.Empty)); } /// /// Get all Workorders for a specified client /// /// ID of client object /// public static ClientWorkorderList GetListForClient(Guid clientID) { return (ClientWorkorderList)DataPortal.Fetch(new Criteria(Guid.Empty, clientID)); } ///// ///// Return an empty list ///// used for initializing grid ///// ///// //public static ClientWorkorderList GetEmptyList() //{ // return new ClientWorkorderList(); //} #endregion #region DAL DATA ACCESS /// /// protected override void DataPortal_Fetch(object Criteria) { Criteria crit = (Criteria)Criteria; SafeDataReader dr = null; try { string q = ""; if (crit.ClientID != Guid.Empty) { q = "SELECT " + " AWORKORDERSERVICE.ASERVICENUMBER, " + " AWORKORDERSERVICE.AINVOICENUMBER, " + " AWORKORDERSERVICE.ASERVICEDATE, " + " AWORKORDER.ACLOSED, " + " AWORKORDER.ACUSTOMERREFERENCENUMBER, " + " AWORKORDER.ACUSTOMERCONTACTNAME, " + " ACLIENT.ANAME AS ACLIENTNAME, " + " AHEADOFFICE.ANAME AS AHEADOFFICENAME, " + " AWORKORDER.AID, AWORKORDER.ASUMMARY " +//case 228 added summary column "FROM " + " AWORKORDERSERVICE " + " INNER JOIN AWORKORDER ON (AWORKORDERSERVICE.AWORKORDERID = AWORKORDER.AID) " + " INNER JOIN ACLIENT ON (AWORKORDER.ACLIENTID = ACLIENT.AID) " + " LEFT OUTER JOIN AHEADOFFICE ON (ACLIENT.AHEADOFFICEID = AHEADOFFICE.AID) " + "WHERE " + " (AWORKORDER.AWORKORDERTYPE = 1) AND AWORKORDER.ACLIENTID=@ID " + " ORDER BY AWORKORDERSERVICE.ASERVICENUMBER DESC "; dr = DBUtil.GetReaderFromSQLString(q, crit.ClientID); } else { q = "SELECT " + " AWORKORDERSERVICE.ASERVICENUMBER, " + " AWORKORDERSERVICE.AINVOICENUMBER, " + " AWORKORDERSERVICE.ASERVICEDATE, " + " AWORKORDER.ACLOSED, " + " AWORKORDER.ACUSTOMERREFERENCENUMBER, " + " AWORKORDER.ACUSTOMERCONTACTNAME, " + " ACLIENT.ANAME AS ACLIENTNAME, " + " AHEADOFFICE.ANAME AS AHEADOFFICENAME, " + " AWORKORDER.AID, AWORKORDER.ASUMMARY " +//case 228 added summary column "FROM " + " AWORKORDERSERVICE " + " INNER JOIN AWORKORDER ON (AWORKORDERSERVICE.AWORKORDERID = AWORKORDER.AID) " + " INNER JOIN ACLIENT ON (AWORKORDER.ACLIENTID = ACLIENT.AID) " + " LEFT OUTER JOIN AHEADOFFICE ON (ACLIENT.AHEADOFFICEID = AHEADOFFICE.AID) " + "WHERE " + " (AWORKORDER.AWORKORDERTYPE = 1) AND ACLIENT.AHEADOFFICEID=@ID " + " ORDER BY AWORKORDERSERVICE.ASERVICENUMBER DESC "; dr = DBUtil.GetReaderFromSQLString(q, crit.HeadOfficeID); } //************************************************************ while (dr.Read()) { //******************************************* ClientWorkorderListInfo info = new ClientWorkorderListInfo(); info.mWorkorder = new GridNameValueCellItem( dr.GetGuid("AID"), dr.GetInt32("ASERVICENUMBER") == 0 ? "" : dr.GetInt32("ASERVICENUMBER").ToString(), RootObjectTypes.Workorder); info.mInvoice = dr.GetString("AINVOICENUMBER"); info.mServiceDate = DBUtil.ToLocal(dr.GetSmartDate("ASERVICEDATE")); info.mClosed = dr.GetBoolean("ACLOSED"); info.mClientRef = dr.GetString("ACUSTOMERREFERENCENUMBER"); info.mClientContact = dr.GetString("ACUSTOMERCONTACTNAME"); info.mClient = dr.GetString("ACLIENTNAME"); info.mHeadOffice = dr.GetString("AHEADOFFICENAME"); //Case 228 info.mSummary = dr.GetString("ASUMMARY"); InnerList.Add(info); //******************************************* } } finally { if (dr != null) dr.Close(); } } #endregion #region criteria /// /// Criteria for identifying existing object /// [Serializable] private class Criteria { public Guid HeadOfficeID; public Guid ClientID; public Criteria(Guid _HeadOfficeID, Guid _ClientID) { HeadOfficeID = _HeadOfficeID; ClientID = _ClientID; } } #endregion }//end ClientWorkorderList #pragma warning restore 1591 }//end namespace GZTW.AyaNova.BLL