/////////////////////////////////////////////////////////// // ReportList.cs // Implementation of Class ReportList // CSLA type: Read only collection // Created on: 23-March-2005 // Object design: John // Coded: 23-March-2005 /////////////////////////////////////////////////////////// using System; using System.Data; using GZTW.Data; using CSLA.Data; using CSLA; namespace GZTW.AyaNova.BLL { /// /// Lightweight read only list of objects representing objects. /// Used for choosing reports in UI /// [Serializable] public class ReportPickList : ReadOnlyCollectionBase { #region Data structure /// /// Properties /// [Serializable] public struct ReportPickListInfo { internal Guid mID; internal string mName; internal bool mIsSummary; internal bool mActive; /// /// ID /// public Guid ID { get { return mID; } } /// /// Set/get Name of item /// /// public string Name { get { return mName; } } /// /// Report is summary type (single flat datasource) as opposed to detailed type (Hiearchichal data sources joined in a relationship) /// public bool IsSummary { get { return this.mIsSummary; } } /// /// Available in lists for reporting /// public bool Active { get { return this.mActive; } } /// /// /// /// public bool Equals(ReportPickListInfo obj) { return this.mID.Equals(obj.mID); } }//end ReportListInfo #endregion #region Constructor /// /// /// protected ReportPickList() { // AllowSort=false; // AllowFind=true; // AllowEdit=false; // AllowNew=false; // AllowRemove=false; } #endregion #region Business properties and methods /// /// Get item by index /// /// public ReportPickListInfo this[int Item] { get { return (ReportPickListInfo) List[Item]; } } /// /// Returns item that matches passed in itemid value /// /// public ReportPickListInfo this[Guid ItemID] { get { foreach (ReportPickListInfo child in List) { if(child.mID==ItemID) return child; } throw new ArgumentException("ReportPickList: ReportID not found:\r\n"+ItemID.ToString()); } } #endregion #region contains /// /// Check if item in collection /// /// public bool Contains(ReportPickListInfo obj) { foreach (ReportPickListInfo child in List) { if(child.Equals(obj)) return true; } return false; } #endregion #region Static methods /// /// Get all Report (unfiltered as it's not bound) /// /// list of objects public static ReportPickList GetList(string ReportKeySummary, string ReportKeyDetailed, bool Regional) { return (ReportPickList) DataPortal.Fetch(new Criteria(ReportKeySummary, ReportKeyDetailed, Regional)); } #endregion #region DAL DATA ACCESS /// /// protected override void DataPortal_Fetch(object Criteria) { Criteria crit = (Criteria)Criteria; //case 36 Guid secgroup = User.CurrentUserSecurityGroupID; Guid repgroup = Guid.Empty; bool bIsAdmin = User.IsAdmin || AyaBizUtils.Lite;//case 1172 SafeDataReader dr = null; try { if(crit.ReportKeySummary!="") { DBCommandWrapper dbCommandWrapper = DBUtil.DB.GetSqlStringCommandWrapper( //************************************************************ DBUtil.AddRegionFilter(//case 58 "SELECT aID,aName, AACTIVE, ASECURITYGROUPID " +//CASE 36 "FROM aReport WHERE aReportKey=@ReportKey " + "ORDER BY aName", "aReport", "", crit.Regional ) //************************************************************ ); dbCommandWrapper.AddInParameter("@ReportKey",DbType.String,crit.ReportKeySummary); dr = new SafeDataReader(DBUtil.DB.ExecuteReader(dbCommandWrapper)); while(dr.Read()) { //******************************************* //case 36 - if user isn't admin and the report has a restriction and it's different security group than current user then ignore this report repgroup = dr.GetGuid("ASECURITYGROUPID"); if (repgroup != Guid.Empty && !bIsAdmin && repgroup != secgroup) continue; ReportPickListInfo info=new ReportPickListInfo(); info.mID=dr.GetGuid("aID"); info.mName=dr.GetString("aName"); info.mIsSummary=true; info.mActive=dr.GetBoolean("AACTIVE"); InnerList.Add(info); //******************************************* } dr.Close(); } if(crit.ReportKeyDetailed!="") { DBCommandWrapper cm = DBUtil.DB.GetSqlStringCommandWrapper( //************************************************************ DBUtil.AddRegionFilter(//case 58 "SELECT aID,aName,AACTIVE, ASECURITYGROUPID " +//CASE 36 "FROM aReport WHERE aReportKey=@ReportKey " + "ORDER BY aName", "aReport", "", crit.Regional ) //************************************************************ ); cm.AddInParameter("@ReportKey",DbType.String,crit.ReportKeyDetailed); dr = new SafeDataReader(DBUtil.DB.ExecuteReader(cm)); while(dr.Read()) { //******************************************* //case 36 - if user isn't admin and the report has a restriction and it's different security group than current user then ignore this report repgroup = dr.GetGuid("ASECURITYGROUPID"); if (repgroup != Guid.Empty && !bIsAdmin && repgroup != secgroup) continue; ReportPickListInfo info=new ReportPickListInfo(); info.mID=dr.GetGuid("aID"); info.mName=dr.GetString("aName"); info.mActive=dr.GetBoolean("AACTIVE"); info.mIsSummary=false; InnerList.Add(info); //******************************************* } } } finally { if(dr!=null) dr.Close(); } } #endregion #region criteria /// /// Criteria for identifying existing object /// [Serializable] private class Criteria { public string ReportKeySummary; public string ReportKeyDetailed; public bool Regional; public Criteria( string _ReportKeySummary, string _ReportKeyDetailed, bool _Regional) { ReportKeySummary=_ReportKeySummary; ReportKeyDetailed=_ReportKeyDetailed; Regional = _Regional; } } #endregion }//end ReportList }//end namespace GZTW.AyaNova.BLL