/////////////////////////////////////////////////////////// // PurchaseOrderReceiptListDetailed.cs // Implementation of Class PurchaseOrderReceiptListDetailed // CSLA type: Read only collection // Created on: 24-Dec-2008 // Object design: John // Coded: 24-Dec-2008 /////////////////////////////////////////////////////////// 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 detailed info about objects. /// Used for reporting purposes. /// [Serializable] public class PurchaseOrderReceiptListDetailed : ReadOnlyCollectionBase { #region Data structure /// /// Properties /// [Serializable] public struct PurchaseOrderReceiptListDetailedInfo { internal GridNameValueCellItem mVendor; internal SmartDate mReceivedDate; internal Guid mID; internal GridNameValueCellItem mReceipt; [Display(DisplayType.Hidden)] public Guid ID { get { return mID; } } [SqlColumnNameAttribute("aVendor.aName", "aVendor.aID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.Vendor)] public GridNameValueCellItem LT_O_Vendor { get { return mVendor; } } [Display(DisplayType.DateTime)] public object LT_PurchaseOrderReceipt_Label_ReceivedDate { get { return mReceivedDate.DBValue; } } [SqlColumnNameAttribute("grid", "aPurchaseOrderReceipt.aID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.Vendor)]//WTF? Vendor? How is this even working public GridNameValueCellItem LT_O_PurchaseOrderReceipt { get { return mReceipt; } } internal GridNameValueCellItem mPONumber; //and ID [SqlColumnNameAttribute("aPurchaseOrder.aPONumber", "aPurchaseOrder.aID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.PurchaseOrder)] public GridNameValueCellItem LT_PurchaseOrder_Label_PONumber { get { return mPONumber; } } internal GridNameValueCellItem mWorkorder; //case 1088 [SqlColumnNameAttribute("aWorkorderService.aServiceNumber", "aWorkorderService.aWorkorderID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.Workorder, CompareAs = CompareType.StringToInt32)] public GridNameValueCellItem LT_O_Workorder { get { return mWorkorder; } } //PART STUFF internal GridNameValueCellItem mName; //and ID internal GridNameValueCellItem mPartNumber; //and ID internal GridNameValueCellItem mPartCategory; //and ID internal GridNameValueCellItem mPartAssembly; //and ID internal decimal mReceiptCost; internal bool mActive; [SqlColumnNameAttribute("aPart.aName", "aPart.aID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.Part)] public GridNameValueCellItem LT_O_Part { get { return mName; } } [SqlColumnNameAttribute("aPart.aPartNumber", "aPart.aID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.Part)] public GridNameValueCellItem LT_Part_Label_PartNumber { get { return mPartNumber; } } [SqlColumnNameAttribute("aPartCategory.aName", "aPartCategory.aID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.PartCategory)] public GridNameValueCellItem LT_O_PartCategory { get { return mPartCategory; } } [SqlColumnNameAttribute("aPartAssembly.aName", "aPartAssembly.aID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.PartAssembly)] public GridNameValueCellItem LT_O_PartAssembly { get { return mPartAssembly; } } [Display(DisplayType.Currency)] public decimal LT_PurchaseOrderReceiptItem_Label_ReceiptCost { get { return mReceiptCost; } } [Display(DisplayType.TrueFalse)] public bool LT_Part_Label_Active { get { return mActive; } } internal GridNameValueCellItem mPartWarehouseID; [SqlColumnNameAttribute("aPartWarehouse.aName", "aPurchaseOrderReceiptItem.aPartWarehouseID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.PartWarehouse)] public GridNameValueCellItem LT_O_PartWarehouse { get { return mPartWarehouseID; } } //PART SERIAL NUMBER internal string mPartSerial; [SqlColumnNameAttribute("aPartSerial.aSerialNumber"), Display(DisplayType.Text)] public string LT_WorkorderItemPart_Label_PartSerialID { get { return mPartSerial; } } //quantities internal decimal mQuantityOrdered; [Display(DisplayType.DecimalNumber)] public decimal LT_PurchaseOrderItem_Label_QuantityOrdered { get { return mQuantityOrdered; } } internal decimal mQuantityReceived; [Display(DisplayType.DecimalNumber)] public decimal LT_PurchaseOrderReceiptItem_Label_QuantityReceived { get { return mQuantityReceived; } } //more stuff internal string mText1; internal string mText2; [Display(DisplayType.Text)] public string LT_PurchaseOrderReceipt_Label_Text1 { get { return mText1; } } [Display(DisplayType.Text)] public string LT_PurchaseOrderReceipt_Label_Text2 { get { return mText2; } } //case 765 internal decimal mRetail; [Display(DisplayType.Currency)] public decimal LT_Part_Label_Retail { get { return mRetail; } } /// /// /// /// public bool Equals(PurchaseOrderReceiptListDetailedInfo obj) { return this.mID.Equals(obj.mID); } }//end PurchaseOrderReceiptListDetailedInfo #endregion #region Constructor protected PurchaseOrderReceiptListDetailed() { // AllowSort=false; // AllowFind=true; // AllowEdit=false; // AllowNew=false; // AllowRemove=false; } #endregion #region Business properties and methods /// /// Get item by index /// /// public PurchaseOrderReceiptListDetailedInfo this[int Item] { get { return (PurchaseOrderReceiptListDetailedInfo) List[Item]; } } /// /// Returns display text that matches passed in itemid value /// /// public string this[Guid ItemID] { get { foreach (PurchaseOrderReceiptListDetailedInfo child in List) { if(child.mID==ItemID) return child.ToString(); } return "Missing: "+ItemID.ToString(); } } #endregion #region contains /// /// Check if item in collection /// /// public bool Contains(PurchaseOrderReceiptListDetailedInfo obj) { foreach (PurchaseOrderReceiptListDetailedInfo 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 "PurchaseOrderReceiptListDetailed"; } } /// /// 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.PurchaseOrderReceiptItem; } } /// /// Locale key so that generic list editor /// UI code knows what title to give the list in a /// grid /// public string LocaleKey { get { return "UI.Go.Inventory.PurchaseOrderReceiptsDetailed"; } } /// /// 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(PurchaseOrderReceiptListDetailedInfo); } } /// /// 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_PurchaseOrderReceipt"; } } /// /// 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 PurchaseOrderReceiptListDetailed Get(string Filter, int MaxRecords, List IDList) { return (PurchaseOrderReceiptListDetailed)DataPortal.Fetch(new Criteria(Filter, IDList, MaxRecords)); } /// /// Get all PurchaseOrderReceipt (filtered by crit) /// /// Use AyaNova UI to easily build xmlCriteria and Ctrl-Alt-g keyboard command to display it for use in your code /// public static PurchaseOrderReceiptListDetailed GetList(string xmlCriteria) { return (PurchaseOrderReceiptListDetailed) DataPortal.Fetch(new Criteria(xmlCriteria,null,-1)); } /// /// Takes a single ID and returns a "list" of one object /// /// ID of PurchaseOrderReceipt object /// list of objects public static PurchaseOrderReceiptListDetailed GetListForSingleItem(Guid PurchaseOrderReceiptID) { //Case 556 List l = new List(); l.Add(PurchaseOrderReceiptID); return GetListFromIDList(l); } /// /// Get list by items indicated in IDList /// /// Generic list of Guid's /// list of objects public static PurchaseOrderReceiptListDetailed GetListFromIDList(List IDList) { //case 556 //Handle empty list if (IDList.Count == 0) return new PurchaseOrderReceiptListDetailed(); return (PurchaseOrderReceiptListDetailed)DataPortal.Fetch(new Criteria("", IDList, -1)); } /// /// Return an empty list /// used for initializing grid /// /// public static PurchaseOrderReceiptListDetailed GetEmptyList() { return new PurchaseOrderReceiptListDetailed(); } #endregion #region DAL DATA ACCESS /// /// protected override void DataPortal_Fetch(object Criteria) { string receiptobjectname = LocalizedTextTable.GetLocalizedTextDirect("UI.Command.Open"); Criteria crit = (Criteria)Criteria; SafeDataReader dr = null; try { DBCommandWrapper cm = null; string q= //************************************************************ "SELECT ~MAXRECS~ " + " APURCHASEORDERRECEIPT.AID, " + " APURCHASEORDERRECEIPT.ARECEIVEDDATE, " + " AVENDOR.AID AS AVENDORID, " + " AVENDOR.ANAME AS AVENDORNAME, " + " APURCHASEORDERRECEIPT.ATEXT1, " + " APURCHASEORDERRECEIPT.ATEXT2, " + " APURCHASEORDERRECEIPTITEM.AQUANTITYRECEIVED AS ARECEIPTRECEIVED, " + " APURCHASEORDERRECEIPTITEM.ARECEIPTCOST, " + " APARTSERIAL.ASERIALNUMBER, " + " APURCHASEORDER.APONUMBER, " + " APURCHASEORDER.AID AS APURCHASEORDERID, " + " APART.AID AS APARTID, " + " APART.ANAME AS APARTNAME, " + " APART.APARTNUMBER, " + " APARTCATEGORY.ANAME AS APARTCATEGORYNAME, " + " APARTCATEGORY.AID AS APARTCATEGORYID, " + " AMANUFACTURERS.ANAME AS AMANUFACTURERNAME, " + " AMANUFACTURERS.AID AS AMANUFACTURERID, " + " AWHOLESALERS.ANAME AS AWHOLESALERNAME, " + " AWHOLESALERS.AID AS AWHOLESALERID, " + " APART.AMANUFACTURERNUMBER, " + " APART.AWHOLESALERNUMBER, " + " APART.ARETAIL, " + //case 765 " AALTERNATIVEWHOLESALERS.ANAME AS AALTERNATIVEWHOLESALERNAME, " + " AALTERNATIVEWHOLESALERS.AID AS AALTERNATIVEWHOLESALERID, " + " APART.AALTERNATIVEWHOLESALERNUMBER, " + " AUNITOFMEASURE.ANAME AS AUNITOFMEASURENAME, " + " AUNITOFMEASURE.AID AS AUNITOFMEASUREID, " + " APARTASSEMBLY.ANAME AS APARTASSEMBLYNAME, " + " APARTASSEMBLY.AID AS APARTASSEMBLYID, " + " APART.AUPC, " + " APART.ATRACKSERIALNUMBER, " + " APART.AACTIVE AS APARTACTIVE, " + " APARTWAREHOUSE.ANAME AS APARTWAREHOUSENAME, " + " APARTWAREHOUSE.AID AS APARTWAREHOUSEID, " + " APURCHASEORDERITEM.AQUANTITYORDERED, " + //case 1088 " AWORKORDERSERVICE.ASERVICENUMBER, AWORKORDERSERVICE.AWORKORDERID " + "FROM " + " APURCHASEORDERRECEIPT " + " LEFT OUTER JOIN AVENDOR ON (APURCHASEORDERRECEIPT.AVENDORID = AVENDOR.AID) " + " INNER JOIN APURCHASEORDERRECEIPTITEM ON (APURCHASEORDERRECEIPT.AID = APURCHASEORDERRECEIPTITEM.APURCHASEORDERRECEIPTID) " + " LEFT OUTER JOIN APARTSERIAL ON (APURCHASEORDERRECEIPTITEM.AID = APARTSERIAL.APURCHASEORDERRECEIPTITEMID) " + " INNER JOIN APURCHASEORDER ON (APURCHASEORDERRECEIPTITEM.APURCHASEORDERID = APURCHASEORDER.AID) " + " INNER JOIN APART ON (APURCHASEORDERRECEIPTITEM.APARTID = APART.AID) " + " LEFT OUTER JOIN APARTASSEMBLY ON (APART.APARTASSEMBLYID = APARTASSEMBLY.AID) " + " LEFT OUTER JOIN AVENDOR AMANUFACTURERS ON (APART.AMANUFACTURERID = AMANUFACTURERS.AID) " + " LEFT OUTER JOIN AVENDOR AWHOLESALERS ON (APART.AWHOLESALERID = AWHOLESALERS.AID) " + " LEFT OUTER JOIN AVENDOR AALTERNATIVEWHOLESALERS ON (APART.AALTERNATIVEWHOLESALERID = AALTERNATIVEWHOLESALERS.AID) " + " LEFT OUTER JOIN AUNITOFMEASURE ON (APART.AUNITOFMEASUREID = AUNITOFMEASURE.AID) " + " LEFT OUTER JOIN APARTCATEGORY ON (APART.APARTCATEGORYID = APARTCATEGORY.AID) " + " INNER JOIN APARTWAREHOUSE ON (APURCHASEORDERRECEIPTITEM.APARTWAREHOUSEID = APARTWAREHOUSE.AID) " + " INNER JOIN APURCHASEORDERITEM ON (APURCHASEORDERRECEIPTITEM.APURCHASEORDERITEMID = APURCHASEORDERITEM.AID) " + //case 1088 //" LEFT OUTER JOIN APURCHASEORDERITEM ON (APURCHASEORDERRECEIPTITEM.APURCHASEORDERITEMID = APURCHASEORDERITEM.AID) " + " LEFT OUTER JOIN AWORKORDERITEMPARTREQUEST ON (APURCHASEORDERITEM.AWORKORDERITEMPARTREQUESTID = AWORKORDERITEMPARTREQUEST.AID) " + " LEFT OUTER JOIN AWORKORDERITEM ON (AWORKORDERITEMPARTREQUEST.AWORKORDERITEMID = AWORKORDERITEM.AID) " + " LEFT OUTER JOIN AWORKORDERSERVICE ON (AWORKORDERITEM.AWORKORDERID = AWORKORDERSERVICE.AWORKORDERID) " + "WHERE " + " (APURCHASEORDERRECEIPTITEM.AQUANTITYRECEIVED > 0) " ; if (crit.MaxRecords > 0) q = q.Replace("~MAXRECS~", "TOP " + crit.MaxRecords.ToString()); else q = q.Replace("~MAXRECS~", ""); if (crit.IDList != null) { //Case 556 System.Text.StringBuilder sbIN = new System.Text.StringBuilder(); sbIN.Append(" AND (aPurchaseOrderReceipt.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(q + AyaBizUtils.GetGridColumnCriteria(crit.CriteriaXML,false) + " " + AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML)); } dr=new SafeDataReader(DBUtil.DB.ExecuteReader(cm)); while(dr.Read()) { //******************************************* PurchaseOrderReceiptListDetailedInfo info=new PurchaseOrderReceiptListDetailedInfo(); info.mID=dr.GetGuid("aID"); info.mReceivedDate=DBUtil.ToLocal(dr.GetSmartDate("aReceivedDate")); info.mVendor=new GridNameValueCellItem( dr.GetGuid("aVendorID"), dr.GetString("aVendorName"), RootObjectTypes.Vendor); info.mReceipt = new GridNameValueCellItem( dr.GetGuid("aID"), receiptobjectname, RootObjectTypes.PurchaseOrderReceiptItem); info.mPONumber = new GridNameValueCellItem( dr.GetGuid("APURCHASEORDERID"), dr.GetInt32("aPONumber").ToString(), RootObjectTypes.PurchaseOrder); //case 1088 info.mWorkorder = new GridNameValueCellItem( dr.GetGuid("AWORKORDERID"), dr.GetInt32("ASERVICENUMBER").ToString(), RootObjectTypes.Workorder); if (info.mWorkorder.Display == "0") info.mWorkorder = new GridNameValueCellItem(Guid.Empty, "", RootObjectTypes.Workorder); //PART STUFF info.mName = new GridNameValueCellItem( dr.GetGuid("APARTID"), dr.GetString("APARTNAME"), RootObjectTypes.Part); info.mPartNumber = new GridNameValueCellItem( dr.GetGuid("APARTID"), dr.GetString("aPartNumber"), RootObjectTypes.Part); info.mPartCategory = new GridNameValueCellItem( dr.GetGuid("aPartCategoryID"), dr.GetString("aPartCategoryName"), RootObjectTypes.PartCategory); info.mPartAssembly = new GridNameValueCellItem( dr.GetGuid("aPartAssemblyID"), dr.GetString("aPartAssemblyName"), RootObjectTypes.PartAssembly); //case 765 info.mRetail = dr.GetDecimal("aRetail"); info.mReceiptCost = dr.GetDecimal("aReceiptCost"); info.mActive = dr.GetBoolean("APARTACTIVE"); info.mPartWarehouseID = new GridNameValueCellItem( dr.GetGuid("aPartWarehouseID"), dr.GetString("aPartWarehouseName"), RootObjectTypes.PartWarehouse); //PART SERIAL info.mPartSerial=dr.GetString("aSerialNumber"); //Quantities info.mQuantityOrdered = dr.GetDecimal("aQuantityOrdered"); info.mQuantityReceived = dr.GetDecimal("ARECEIPTRECEIVED"); //more stuff info.mText1 = dr.GetString("ATEXT1"); info.mText2 = dr.GetString("ATEXT2"); 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 PurchaseOrderReceiptListDetailed #pragma warning restore 1591 }//end namespace GZTW.AyaNova.BLL