/////////////////////////////////////////////////////////// // UnitModelList.cs // Implementation of Class UnitModelList // CSLA type: Read only collection // Created on: 29-Oct-2004 // Object design: John // Coded: 29-Oct-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 in UI for grids and for reporting purposes. /// [Serializable] public class UnitModelList : ReadOnlyCollectionBase { #region Data structure /// /// Properties /// [Serializable] public struct UnitModelListInfo { internal GridNameValueCellItem mName; //and ID internal GridNameValueCellItem mModelNumber; //and ID internal GridNameValueCellItem mUPC; //and ID if possible internal GridNameValueCellItem mVendor; internal GridNameValueCellItem mUnitModelCategory; internal bool mLifeTimeWarranty; internal SmartDate mIntroducedDate; internal bool mDiscontinued; internal SmartDate mDiscontinuedDate; internal bool mActive; [SqlColumnNameAttribute("aUnitModel.aName", "aUnitModel.aID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.UnitModel)] public GridNameValueCellItem LT_O_UnitModel { get { return mName; } } [SqlColumnNameAttribute("aUnitModel.aModelNumber", "aUnitModel.aID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.UnitModel)] public GridNameValueCellItem LT_UnitModel_Label_ModelNumber { get { return mModelNumber; } } [SqlColumnNameAttribute("aUnitModel.aUPC", "aUnitModel.aID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.UnitModel)] public GridNameValueCellItem LT_UnitModel_Label_UPC { get { return mUPC; } } [SqlColumnNameAttribute("aVendor.aName", "aUnitModel.aVendorID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.Vendor)] public GridNameValueCellItem LT_O_Vendor { get { return mVendor; } } [SqlColumnNameAttribute("aUnitModelCategory.aName", "aUnitModel.aUnitModelCategoryID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.UnitModelCategory)] public GridNameValueCellItem LT_O_UnitModelCategory { get { return mUnitModelCategory; } } [Display(DisplayType.TrueFalse)] public bool LT_UnitModel_Label_LifeTimeWarranty { get { return mLifeTimeWarranty; } } [Display(DisplayType.DateTime)] public object LT_UnitModel_Label_IntroducedDate { get { return mIntroducedDate.DBValue; } } [Display(DisplayType.TrueFalse)] public bool LT_UnitModel_Label_Discontinued { get { return mDiscontinued; } } [Display(DisplayType.DateTime)] public object LT_UnitModel_Label_DiscontinuedDate { get { return mDiscontinuedDate.DBValue; } } [Display(DisplayType.TrueFalse)] public bool LT_UnitModel_Label_Active { get { return mActive; } } internal string mCustom1; internal string mCustom2; internal string mCustom3; internal string mCustom4; internal string mCustom5; internal string mCustom6; internal string mCustom7; internal string mCustom8; internal string mCustom9; internal string mCustom0; [Display(DisplayType.Text)] public string LT_UnitModel_Label_Custom1{get{return mCustom1;}} [Display(DisplayType.Text)] public string LT_UnitModel_Label_Custom2{get{return mCustom2;}} [Display(DisplayType.Text)] public string LT_UnitModel_Label_Custom3{get{return mCustom3;}} [Display(DisplayType.Text)] public string LT_UnitModel_Label_Custom4{get{return mCustom4;}} [Display(DisplayType.Text)] public string LT_UnitModel_Label_Custom5{get{return mCustom5;}} [Display(DisplayType.Text)] public string LT_UnitModel_Label_Custom6{get{return mCustom6;}} [Display(DisplayType.Text)] public string LT_UnitModel_Label_Custom7{get{return mCustom7;}} [Display(DisplayType.Text)] public string LT_UnitModel_Label_Custom8{get{return mCustom8;}} [Display(DisplayType.Text)] public string LT_UnitModel_Label_Custom9{get{return mCustom9;}} [Display(DisplayType.Text)] public string LT_UnitModel_Label_Custom0{get{return mCustom0;}} internal string mNotes; internal string mWarrantyTerms; [SqlColumnNameAttribute("grid"), Display(DisplayType.Text)] public string LT_UnitModel_Label_Notes {get{return mNotes;}} [Display(DisplayType.Text)] public string LT_UnitModel_Label_WarrantyTerms {get{return mWarrantyTerms;}} /// /// /// /// public bool Equals(UnitModelListInfo obj) { return this.mModelNumber.Value.Equals(obj.mModelNumber.Value); } }//end UnitModelListInfo #endregion #region Constructor protected UnitModelList() { // AllowSort=false; // AllowFind=true; // AllowEdit=false; // AllowNew=false; // AllowRemove=false; } #endregion #region Business properties and methods /// /// Get item by index /// /// public UnitModelListInfo this[int Item] { get { return (UnitModelListInfo) List[Item]; } } /// /// Returns display text that matches passed in itemid value /// /// public string this[Guid ItemID] { get { foreach (UnitModelListInfo child in List) { if(child.mModelNumber.Value==ItemID) return child.ToString(); } return "Missing: "+ItemID.ToString(); } } #endregion #region contains /// /// Check if item in collection /// /// public bool Contains(UnitModelListInfo obj) { foreach (UnitModelListInfo 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 "UnitModelList"; } } /// /// 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.UnitModel; } } /// /// 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.UnitModels"; } } /// /// 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(UnitModelListInfo); } } /// /// 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_UnitModel"; } } /// /// 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 UnitModelList Get(string Filter, int MaxRecords, List IDList) { return (UnitModelList)DataPortal.Fetch(new Criteria(Filter, IDList, MaxRecords)); } /// /// Get all UnitModel (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 UnitModelList GetList(string xmlCriteria) { return (UnitModelList) DataPortal.Fetch(new Criteria(xmlCriteria,null, -1)); } /// /// Takes a single ID and returns a "list" of one object /// /// ID of UnitModel object /// list of objects public static UnitModelList GetListForSingleItem(Guid UnitModelID) { //Case 556 List l = new List(); l.Add(UnitModelID); return GetListFromIDList(l); } /// /// Get list by items indicated in IDList /// /// Generic list of Guid's /// list of objects public static UnitModelList GetListFromIDList(List IDList) { //case 556 //Handle empty list if (IDList.Count == 0) return new UnitModelList(); return (UnitModelList)DataPortal.Fetch(new Criteria("", IDList, -1)); } /// /// Return an empty list /// used for initializing grid /// /// public static UnitModelList GetEmptyList() { return new UnitModelList(); } #endregion #region DAL DATA ACCESS /// /// protected override void DataPortal_Fetch(object Criteria) { Criteria crit = (Criteria)Criteria; SafeDataReader dr = null; try { string q = ""; if (crit.IDList != null) { //Case 556 System.Text.StringBuilder sbIN = new System.Text.StringBuilder(); sbIN.Append(" WHERE (aUnitModel.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(")) "); q = "SELECT aUnitModel.aID AS aUnitModelID, aUnitModel.aName AS aUnitModelName, " + "aUnitModel.aUPC, aUnitModel.AACTIVE, aUnitModel.aModelNumber, " + "aUnitModel.aVendorID, aVendor.aName AS aVendorName, " + "aUnitModel.aUnitModelCategoryID, aUnitModelCategory.aName " + "AS aUnitModelCategoryName, aUnitModel.aLifeTimeWarranty, " + "aUnitModel.aIntroducedDate, " + "aUnitModel.aDiscontinued, aUnitModel.aDiscontinuedDate, " + " aUnitModel.aCustom1, " + " aUnitModel.aCustom2, aUnitModel.aCustom3, " + " aUnitModel.aCustom4, " + " aUnitModel.aCustom5, aUnitModel.aCustom6, " + " aUnitModel.aCustom7, aUnitModel.aCustom8, " + " aUnitModel.aCustom9, " + " aUnitModel.aCustom0, aUnitModel.aNotes, aUnitModel.aWarrantyTerms " + "FROM aUnitModel LEFT OUTER JOIN " + "aUnitModelCategory ON aUnitModel.aUnitModelCategoryID " + "= aUnitModelCategory.aID LEFT OUTER JOIN " + "aVendor ON aUnitModel.aVendorID = aVendor.aID "; dr = DBUtil.GetReaderFromSQLString(q + sbIN.ToString() + " " + AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML)); } else { //************************************************************ q = "SELECT ~MAXRECS~ aUnitModel.aID AS aUnitModelID, aUnitModel.aName AS aUnitModelName, " + "aUnitModel.aUPC, aUnitModel.AACTIVE, aUnitModel.aModelNumber, " + "aUnitModel.aVendorID, aVendor.aName AS aVendorName, " + "aUnitModel.aUnitModelCategoryID, aUnitModelCategory.aName " + "AS aUnitModelCategoryName, aUnitModel.aLifeTimeWarranty, " + "aUnitModel.aIntroducedDate, " + "aUnitModel.aDiscontinued, aUnitModel.aDiscontinuedDate, " + " aUnitModel.aCustom1, " + " aUnitModel.aCustom2, aUnitModel.aCustom3, " + " aUnitModel.aCustom4, " + " aUnitModel.aCustom5, aUnitModel.aCustom6, " + " aUnitModel.aCustom7, aUnitModel.aCustom8, " + " aUnitModel.aCustom9, " + " aUnitModel.aCustom0, aUnitModel.aNotes, aUnitModel.aWarrantyTerms " + "FROM aUnitModel LEFT OUTER JOIN " + "aUnitModelCategory ON aUnitModel.aUnitModelCategoryID " + "= aUnitModelCategory.aID LEFT OUTER JOIN " + "aVendor ON aUnitModel.aVendorID = aVendor.aID " + AyaBizUtils.GetGridColumnCriteria(crit.CriteriaXML, true) + " " + AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML); //************************************************************ if (crit.MaxRecords > 0) q = q.Replace("~MAXRECS~", "TOP " + crit.MaxRecords.ToString()); else q = q.Replace("~MAXRECS~", ""); dr = DBUtil.GetReaderFromSQLString(q); } while(dr.Read()) { //******************************************* UnitModelListInfo info=new UnitModelListInfo(); info.mLifeTimeWarranty=dr.GetBoolean("aLifeTimeWarranty"); info.mDiscontinued=dr.GetBoolean("aDiscontinued"); info.mName=new GridNameValueCellItem( dr.GetGuid("aUnitModelID"), dr.GetString("aUnitModelName"), RootObjectTypes.UnitModel); info.mModelNumber=new GridNameValueCellItem( dr.GetGuid("aUnitModelID"), dr.GetString("aModelNumber"), RootObjectTypes.UnitModel); info.mUPC=new GridNameValueCellItem( dr.GetGuid("aUnitModelID"), dr.GetString("aUPC"), RootObjectTypes.UnitModel); info.mVendor=new GridNameValueCellItem( dr.GetGuid("aVendorID"), dr.GetString("aVendorName"), RootObjectTypes.Vendor); info.mUnitModelCategory=new GridNameValueCellItem( dr.GetGuid("aUnitModelCategoryID"), dr.GetString("aUnitModelCategoryName"), RootObjectTypes.UnitModelCategory); info.mIntroducedDate=DBUtil.ToLocal(dr.GetSmartDate("aIntroducedDate")); info.mDiscontinuedDate=DBUtil.ToLocal(dr.GetSmartDate("aDiscontinuedDate")); info.mActive=dr.GetBoolean("AACTIVE"); info.mCustom0=dr.GetString("aCustom0"); info.mCustom1=dr.GetString("aCustom1"); info.mCustom2=dr.GetString("aCustom2"); info.mCustom3=dr.GetString("aCustom3"); info.mCustom4=dr.GetString("aCustom4"); info.mCustom5=dr.GetString("aCustom5"); info.mCustom6=dr.GetString("aCustom6"); info.mCustom7=dr.GetString("aCustom7"); info.mCustom8=dr.GetString("aCustom8"); info.mCustom9=dr.GetString("aCustom9"); info.mNotes=dr.GetString("aNotes"); info.mWarrantyTerms=dr.GetString("aWarrantyTerms"); 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 UnitModelList #pragma warning restore 1591 }//end namespace GZTW.AyaNova.BLL