/////////////////////////////////////////////////////////// // ContractList.cs // Implementation of Class ContractList // CSLA type: Read only collection // Created on: 26-Jan-2005 // Object design: John // Coded: 26-Jan-2005 /////////////////////////////////////////////////////////// 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 /// /// Lightweight list of objects representing objects /// /// [Serializable] public class ContractList : ReadOnlyCollectionBase { #region Data structure /// /// Properties /// [Serializable] public struct ContractListInfo { internal GridNameValueCellItem mName; //and ID internal bool mActive; [SqlColumnNameAttribute("aContract.aName", "aContract.aID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.Contract)] public GridNameValueCellItem LT_O_Contract //changed 12-June-2006 was LT_Contract_Label_ID { get { return mName; } } [Display(DisplayType.TrueFalse)] public bool LT_Contract_Label_Active { get { return mActive; } } internal decimal mDiscountParts; [Display(DisplayType.Percentage)] public decimal LT_Contract_Label_DiscountParts { get { return mDiscountParts; } } internal bool mContractRatesOnly; internal string mNotes; [Display(DisplayType.TrueFalse)] public bool LT_Contract_Label_ContractRatesOnly { get { return mContractRatesOnly; } } [SqlColumnNameAttribute("grid"),Display(DisplayType.Text)] public string LT_Contract_Label_Notes { get { return mNotes; } } //Case 58 internal GridNameValueCellItem mRegion; [SqlColumnNameAttribute("aRegion.aName", "aRegion.aID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.Region)] public GridNameValueCellItem LT_O_Region { get { return mRegion; } } 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_Contract_Label_Custom1{get{return mCustom1;}} [Display(DisplayType.Text)] public string LT_Contract_Label_Custom2{get{return mCustom2;}} [Display(DisplayType.Text)] public string LT_Contract_Label_Custom3{get{return mCustom3;}} [Display(DisplayType.Text)] public string LT_Contract_Label_Custom4{get{return mCustom4;}} [Display(DisplayType.Text)] public string LT_Contract_Label_Custom5{get{return mCustom5;}} [Display(DisplayType.Text)] public string LT_Contract_Label_Custom6{get{return mCustom6;}} [Display(DisplayType.Text)] public string LT_Contract_Label_Custom7{get{return mCustom7;}} [Display(DisplayType.Text)] public string LT_Contract_Label_Custom8{get{return mCustom8;}} [Display(DisplayType.Text)] public string LT_Contract_Label_Custom9{get{return mCustom9;}} [Display(DisplayType.Text)] public string LT_Contract_Label_Custom0{get{return mCustom0;}} /// /// /// /// public bool Equals(ContractListInfo obj) { return this.mName.Value.Equals(obj.mName.Value); } }//end ContractListInfo #endregion #region Constructor protected ContractList() { // AllowSort=false; // AllowFind=true; // AllowEdit=false; // AllowNew=false; // AllowRemove=false; } #endregion #region Business properties and methods /// /// Get item by index /// /// public ContractListInfo this[int Item] { get { return (ContractListInfo) List[Item]; } } /// /// Returns display text that matches passed in itemid value /// /// public string this[Guid ItemID] { get { foreach (ContractListInfo child in List) { if(child.mName.Value==ItemID) return child.ToString(); } return "Missing: "+ItemID.ToString(); } } #endregion #region contains /// /// Check if item in collection /// /// public bool Contains(ContractListInfo obj) { foreach (ContractListInfo 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 "ContractList"; } } /// /// 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.Contract; } } /// /// Locale key so that generic list editor /// UI code knows what title to give the list in a /// grid /// public string LocaleKey { get { return "Contract.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(ContractListInfo); } } /// /// 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_Contract"; } } /// /// 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 ContractList Get(string Filter, int MaxRecords, List IDList) { return (ContractList)DataPortal.Fetch(new Criteria(Filter, IDList, MaxRecords)); } /// /// Get all Contract (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 ContractList GetList(string xmlCriteria) { return (ContractList) DataPortal.Fetch(new Criteria(xmlCriteria,null,-1)); } /// /// Get list by items indicated in IDList /// /// Generic list of Guid's /// list of objects public static ContractList GetListFromIDList(List IDList) { //case 556 //Handle empty list if (IDList.Count == 0) return new ContractList(); return (ContractList)DataPortal.Fetch(new Criteria("", IDList, -1)); } /// /// Return an empty list /// used for initializing grid /// /// public static ContractList GetEmptyList() { return new ContractList(); } #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 aContract.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 aContract.aID AS aContractID, aContract.aName AS aContractName, " + "aContract.AACTIVE, " + " aContract.aRegionID, aRegion.aName AS aRegionName, " + //case 58 " aContract.aCustom1, " + " aContract.aCustom2, aContract.aCustom3, " + " aContract.aCustom4, " + " aContract.aCustom5, aContract.aCustom6, " + " aContract.aCustom7, aContract.aCustom8, " + " aContract.aCustom9, " + " aContract.aCustom0, aDiscountParts, aContractRatesOnly,aNotes " + "FROM aContract " + "LEFT OUTER JOIN aRegion ON aContract.aRegionID = aRegion.aID " + //Case 58 sbIN.ToString() + " " + AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML); } else { //************************************************************ q = "SELECT ~MAXRECS~ aContract.aID AS aContractID, aContract.aName AS aContractName, " + "aContract.AACTIVE, " + " aContract.aRegionID, aRegion.aName AS aRegionName, " + " aContract.aCustom1, " + " aContract.aCustom2, aContract.aCustom3, " + " aContract.aCustom4, " + " aContract.aCustom5, aContract.aCustom6, " + " aContract.aCustom7, aContract.aCustom8, " + " aContract.aCustom9, " + " aContract.aCustom0, aDiscountParts, aContractRatesOnly,aNotes " + "FROM aContract " + "LEFT OUTER JOIN aRegion ON aContract.aRegionID = aRegion.aID " + //Case 58 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(DBUtil.AddRegionFilter(q,"aContract",""));//case 58 while(dr.Read()) { //******************************************* ContractListInfo info=new ContractListInfo(); info.mName=new GridNameValueCellItem( dr.GetGuid("aContractID"), dr.GetString("aContractName"), RootObjectTypes.Contract); //Case 58 info.mRegion = new GridNameValueCellItem( dr.GetGuid("aRegionID"), dr.GetString("aRegionName"), RootObjectTypes.Region); 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.mDiscountParts=dr.GetDecimal("aDiscountParts"); info.mContractRatesOnly=dr.GetBoolean("aContractRatesOnly"); info.mNotes=dr.GetString("aNotes"); 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 ContractList #pragma warning restore 1591 }//end namespace GZTW.AyaNova.BLL