/////////////////////////////////////////////////////////// // PurchaseOrderReceiptList.cs // Implementation of Class PurchaseOrderReceiptList // CSLA type: Read only collection // Created on: 25-Nov-2004 // Object design: John // Coded: 25-Nov-2004 /////////////////////////////////////////////////////////// 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 objects. /// Used for reporting. /// [Serializable] public class PurchaseOrderReceiptList : ReadOnlyCollectionBase { #region Data structure /// /// Properties /// [Serializable] public struct PurchaseOrderReceiptListInfo { 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)] public GridNameValueCellItem LT_O_PurchaseOrderReceipt { get { return mReceipt; } } /// /// /// /// public bool Equals(PurchaseOrderReceiptListInfo obj) { return this.mID.Equals(obj.mID); } }//end PurchaseOrderReceiptListInfo #endregion #region Constructor protected PurchaseOrderReceiptList() { // AllowSort=false; // AllowFind=true; // AllowEdit=false; // AllowNew=false; // AllowRemove=false; } #endregion #region Business properties and methods /// /// Get item by index /// /// public PurchaseOrderReceiptListInfo this[int Item] { get { return (PurchaseOrderReceiptListInfo) List[Item]; } } /// /// Returns display text that matches passed in itemid value /// /// public string this[Guid ItemID] { get { foreach (PurchaseOrderReceiptListInfo 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(PurchaseOrderReceiptListInfo obj) { foreach (PurchaseOrderReceiptListInfo 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 "PurchaseOrderReceiptList"; } } /// /// 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.PurchaseOrderReceipts"; } } /// /// 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(PurchaseOrderReceiptListInfo); } } /// /// 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 PurchaseOrderReceiptList Get(string Filter, int MaxRecords, List IDList) { return (PurchaseOrderReceiptList)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 /// list of objects public static PurchaseOrderReceiptList GetList(string xmlCriteria) { return (PurchaseOrderReceiptList) 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 PurchaseOrderReceiptList 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 PurchaseOrderReceiptList GetListFromIDList(List IDList) { //case 556 //Handle empty list if (IDList.Count == 0) return new PurchaseOrderReceiptList(); return (PurchaseOrderReceiptList)DataPortal.Fetch(new Criteria("", IDList, -1)); } /// /// Return an empty list /// used for initializing grid /// /// public static PurchaseOrderReceiptList GetEmptyList() { return new PurchaseOrderReceiptList(); } #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 FROM aPurchaseOrderReceipt " + "LEFT OUTER JOIN aVendor ON " + "aPurchaseOrderReceipt.aVendorID = aVendor.aID "; 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(" WHERE (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,true) + " " + AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML)); } dr=new SafeDataReader(DBUtil.DB.ExecuteReader(cm)); while(dr.Read()) { //******************************************* PurchaseOrderReceiptListInfo info=new PurchaseOrderReceiptListInfo(); 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); 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 PurchaseOrderReceiptList #pragma warning restore 1591 }//end namespace GZTW.AyaNova.BLL