/////////////////////////////////////////////////////////// // PartInventoryAdjustmentList.cs // Implementation of Class PartInventoryAdjustmentList // CSLA type: Read only collection // Created on: 03-Dec-2004 // Object design: John // Coded: 03-Dec-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 used in grid lists and summary report /// [Serializable] public class PartInventoryAdjustmentList : ReadOnlyCollectionBase { #region Data structure /// /// Properties /// [Serializable] public struct PartInventoryAdjustmentListInfo { internal GridNameValueCellItem mAdjustmentNumber; //and ID internal string mReasonForAdjustment; internal SmartDate mDateAdjusted; [SqlColumnNameAttribute("aPartInventoryAdjustment.AADJUSTMENTNUMBER", "aPartInventoryAdjustment.aID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.PartInventoryAdjustment)] public GridNameValueCellItem LT_PartInventoryAdjustment_Label_AdjustmentNumber { get { return mAdjustmentNumber; } } [Display(DisplayType.Text)] public string LT_PartInventoryAdjustment_Label_ReasonForAdjustment { get { return mReasonForAdjustment; } } [Display(DisplayType.DateTime)] public object LT_PartInventoryAdjustment_Label_DateAdjusted { get { return mDateAdjusted.DBValue; } } /// /// /// /// public bool Equals(PartInventoryAdjustmentListInfo obj) { return this.mAdjustmentNumber.Value.Equals(obj.mAdjustmentNumber.Value); } }//end PartInventoryAdjustmentListInfo #endregion #region Constructor /// /// /// protected PartInventoryAdjustmentList() { // AllowSort=false; // AllowFind=true; // AllowEdit=false; // AllowNew=false; // AllowRemove=false; } #endregion #region Business properties and methods /// /// Get item by index /// /// public PartInventoryAdjustmentListInfo this[int Item] { get { return (PartInventoryAdjustmentListInfo) List[Item]; } } /// /// Returns display text that matches passed in itemid value /// /// public string this[Guid ItemID] { get { foreach (PartInventoryAdjustmentListInfo child in List) { if(child.mAdjustmentNumber.Value==ItemID) return child.ToString(); } return "Missing: "+ItemID.ToString(); } } #endregion #region contains /// /// Check if item in collection /// /// public bool Contains(PartInventoryAdjustmentListInfo obj) { foreach (PartInventoryAdjustmentListInfo 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 "PartInventoryAdjustmentList"; } } /// /// 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 PartInventoryAdjustmentDetailedReportData.ReportKey; } } /// /// 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.PartInventoryAdjustment; } } /// /// 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.PartInventoryAdjustments"; } } /// /// 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(PartInventoryAdjustmentListInfo); } } /// /// 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_PartInventoryAdjustment_Label_AdjustmentNumber"; } } /// /// 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 PartInventoryAdjustmentList Get(string Filter, int MaxRecords, List IDList) { return (PartInventoryAdjustmentList)DataPortal.Fetch(new Criteria(Filter, IDList, MaxRecords)); } /// /// Get all PartInventoryAdjustment (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 PartInventoryAdjustmentList GetList(string xmlCriteria) { return (PartInventoryAdjustmentList) DataPortal.Fetch(new Criteria(xmlCriteria,null,-1)); } /// /// Takes a single ID and returns a "list" of one object /// /// ID of PartInventoryAdjustment object /// list of objects public static PartInventoryAdjustmentList GetListForSingleItem(Guid PartInventoryAdjustmentID) { //Case 556 List l = new List(); l.Add(PartInventoryAdjustmentID); return GetListFromIDList(l); } /// /// Get list by items indicated in IDList /// /// Generic list of Guid's /// list of objects public static PartInventoryAdjustmentList GetListFromIDList(List IDList) { //case 556 //Handle empty list if (IDList.Count == 0) return new PartInventoryAdjustmentList(); return (PartInventoryAdjustmentList)DataPortal.Fetch(new Criteria("", IDList, -1)); } /// /// Return an empty list /// used for initializing grid /// /// public static PartInventoryAdjustmentList GetEmptyList() { return new PartInventoryAdjustmentList(); } #endregion #region DAL DATA ACCESS /// /// protected override void DataPortal_Fetch(object Criteria) { Criteria crit = (Criteria)Criteria; SafeDataReader dr = null; try { DBCommandWrapper cm = null; string q= //************************************************************ "SELECT ~MAXRECS~ aPartInventoryAdjustment.aID, " + "aPartInventoryAdjustment.aDateAdjusted, " + "aPartInventoryAdjustment.AADJUSTMENTNUMBER, " + "aPartInventoryAdjustment.aReasonForAdjustment " + "FROM aPartInventoryAdjustment " ; 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 (aPartInventoryAdjustment.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()) { //******************************************* PartInventoryAdjustmentListInfo info=new PartInventoryAdjustmentListInfo(); info.mAdjustmentNumber=new GridNameValueCellItem( dr.GetGuid("aID"), dr.GetInt32("AADJUSTMENTNUMBER").ToString(), RootObjectTypes.PartInventoryAdjustment); info.mReasonForAdjustment=dr.GetString("aReasonForAdjustment"); info.mDateAdjusted=DBUtil.ToLocal(dr.GetSmartDate("aDateAdjusted")); 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 PartInventoryAdjustmentList #pragma warning restore 1591 }//end namespace GZTW.AyaNova.BLL