/////////////////////////////////////////////////////////// // ReportList.cs // Implementation of Class ReportList // CSLA type: Read only collection // Created on: 28-Nov-2005 // Object design: John // Coded: 28-Nov-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 /// /// Read only list of objects representing objects. /// Used for grid lists and reporting (ironically enough). /// [Serializable] public class ReportList : ReadOnlyCollectionBase { #region Data structure /// /// Properties /// [Serializable] public struct ReportListInfo { internal GridNameValueCellItem mReport; [SqlColumnNameAttribute("aReport.aName", "aReport.aID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.Report)] public GridNameValueCellItem LT_O_Report {get{return mReport;}} internal bool mActive; [Display(DisplayType.TrueFalse)] public bool LT_Report_Label_Active {get{return mActive;}} internal string mReportKey; [Display(DisplayType.Text)] public string LT_Report_Label_ReportKey {get{return mReportKey;}} internal int mReportSize; [Display(DisplayType.WholeNumber)] public int LT_Report_Label_ReportSize {get{return mReportSize;}} internal SmartDate mCreated; [SqlColumnNameAttribute("aReport.aCreated"),Display(DisplayType.DateTime)] public object LT_Common_Label_Created {get{return mCreated.DBValue;}} internal SmartDate mModified; [SqlColumnNameAttribute("aReport.aModified"), Display(DisplayType.DateTime)] public object LT_Common_Label_Modified {get{return mModified.DBValue;}} internal GridNameValueCellItem mCreator; [SqlColumnNameAttribute("aReport.aCreator", "aReport.aCreator"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.User)] public GridNameValueCellItem LT_Common_Label_Creator { get { return mCreator; } } internal GridNameValueCellItem mModifier; [SqlColumnNameAttribute("aReport.aModifier", "aReport.aModifier"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.User)] public GridNameValueCellItem LT_Common_Label_Modifier { get { return mModifier; } } //Case 58 internal GridNameValueCellItem mRegion; [SqlColumnNameAttribute("aRegion.aName", "aRegion.aID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.Region)] public GridNameValueCellItem LT_O_Region { get { return mRegion; } } /// /// /// /// public bool Equals(ReportListInfo obj) { return this.mReport.Value.Equals(obj.mReport.Value); } }//end ReportListInfo #endregion #region Constructor protected ReportList() { // AllowSort=false; // AllowFind=true; // AllowEdit=false; // AllowNew=false; // AllowRemove=false; } #endregion #region Business properties and methods /// /// Get item by index /// /// public ReportListInfo this[int Item] { get { return (ReportListInfo) List[Item]; } } /// /// Returns display text that matches passed in itemid value /// /// public string this[Guid ItemID] { get { foreach (ReportListInfo child in List) { if(child.mReport.Value==ItemID) return child.ToString(); } return "Missing: "+ItemID.ToString(); } } #endregion #region contains /// /// Check if item in collection /// /// public bool Contains(ReportListInfo obj) { foreach (ReportListInfo 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 "ReportList"; } } /// /// 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.Report;//case 1313 //return RootObjectTypes.Nothing; } } /// /// Locale key so that generic list editor /// UI code knows what title to give the list in a /// grid /// public string LocaleKey { get { return "Report.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(ReportListInfo); } } /// /// 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_Report"; } } /// /// 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 ReportList Get(string Filter, int MaxRecords, List IDList) { return (ReportList)DataPortal.Fetch(new Criteria(Filter,IDList, MaxRecords)); } /// /// Get list by criteria /// /// 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 ReportList GetList(string xmlCriteria) { return (ReportList) DataPortal.Fetch(new Criteria(xmlCriteria,null,-1)); } /// /// Takes a single ID and returns a "list" of one object /// /// ID of Report object /// list of objects public static ReportList GetListForSingleItem(Guid ReportID) { //Case 556 List l = new List(); l.Add(ReportID); return GetListFromIDList(l); } /// /// Get list by items indicated in IDList /// /// Generic list of Guid's /// list of objects public static ReportList GetListFromIDList(List IDList) { //case 556 //Handle empty list if (IDList.Count == 0) return new ReportList(); return (ReportList)DataPortal.Fetch(new Criteria("", IDList, -1)); } /// /// Return an empty list /// used for initializing grid /// /// public static ReportList GetEmptyList() { return new ReportList(); } #endregion #region DAL DATA ACCESS /// /// protected override void DataPortal_Fetch(object Criteria) { //cached user list UserPickList users = UserPickList.GetList(false); Criteria crit = (Criteria)Criteria; SafeDataReader dr = null; try { //************************************************************ string q = "SELECT ~MAXRECS~ aReport.aID,aReport.aCreated,aReport.aModified,aReport.aCreator, " + "aReport.aModifier, aReport.aReportSize,aReport.aName,aReport.aReportKey, " + "aReport.aRegionID, aRegion.aName AS aRegionName, " + //case 58 "aReport.AACTIVE " + "FROM aReport " + "LEFT OUTER JOIN aRegion ON aReport.aRegionID = aRegion.aID "; if (crit.IDList != null) { //Case 556 System.Text.StringBuilder sbIN = new System.Text.StringBuilder(); sbIN.Append(" WHERE (aReport.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(")) "); sbIN.Append(AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML)); q = q.Replace("~MAXRECS~", "") + sbIN.ToString(); } else { q+=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~", ""); q = DBUtil.AddRegionFilter(q, "aReport", "");//case 58 } dr=DBUtil.GetReaderFromSQLString(q); while(dr.Read()) { //******************************************* ReportListInfo info=new ReportListInfo(); info.mReport=new GridNameValueCellItem( dr.GetGuid("aID"), dr.GetString("aName"), RootObjectTypes.Report); info.mActive=dr.GetBoolean("AACTIVE"); info.mCreated=DBUtil.ToLocal(dr.GetSmartDate("aCreated")); info.mCreator = new GridNameValueCellItem( dr.GetGuid("aCreator"), users[dr.GetGuid("aCreator")], RootObjectTypes.User); info.mModifier = new GridNameValueCellItem( dr.GetGuid("aModifier"), users[dr.GetGuid("aModifier")], RootObjectTypes.User); info.mModified=DBUtil.ToLocal(dr.GetSmartDate("aModified")); info.mReportKey=dr.GetString("aReportKey"); info.mReportSize=dr.GetInt32("aReportSize"); //Case 58 info.mRegion = new GridNameValueCellItem( dr.GetGuid("aRegionID"), dr.GetString("aRegionName"), RootObjectTypes.Region); 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 ReportList #pragma warning restore 1591 }//end namespace GZTW.AyaNova.BLL