318 lines
7.9 KiB
C#
318 lines
7.9 KiB
C#
///////////////////////////////////////////////////////////
|
|
// 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
|
|
{
|
|
/// <summary>
|
|
/// Lightweight read only list of <see cref="ReportPickList.ReportPickListInfo"/> objects representing <see cref="Report"/> objects.
|
|
/// Used for choosing reports in UI
|
|
/// </summary>
|
|
[Serializable]
|
|
public class ReportPickList : ReadOnlyCollectionBase
|
|
{
|
|
|
|
|
|
#region Data structure
|
|
/// <summary>
|
|
/// Properties
|
|
/// </summary>
|
|
[Serializable]
|
|
public struct ReportPickListInfo
|
|
{
|
|
|
|
|
|
|
|
internal Guid mID;
|
|
internal string mName;
|
|
|
|
|
|
internal bool mIsSummary;
|
|
internal bool mActive;
|
|
|
|
|
|
/// <summary>
|
|
/// <see cref="Report"/> ID
|
|
/// </summary>
|
|
public Guid ID
|
|
{
|
|
get
|
|
{
|
|
return mID;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set/get Name of item
|
|
///
|
|
/// </summary>
|
|
public string Name
|
|
{
|
|
get
|
|
{
|
|
return mName;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Report is summary type (single flat datasource) as opposed to detailed type (Hiearchichal data sources joined in a relationship)
|
|
/// </summary>
|
|
public bool IsSummary
|
|
{
|
|
get
|
|
{
|
|
return this.mIsSummary;
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// Available in lists for reporting
|
|
/// </summary>
|
|
public bool Active
|
|
{
|
|
get
|
|
{
|
|
return this.mActive;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Equals(ReportPickListInfo obj)
|
|
{
|
|
return this.mID.Equals(obj.mID);
|
|
}
|
|
|
|
}//end ReportListInfo
|
|
#endregion
|
|
|
|
#region Constructor
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
protected ReportPickList()
|
|
{
|
|
// AllowSort=false;
|
|
// AllowFind=true;
|
|
// AllowEdit=false;
|
|
// AllowNew=false;
|
|
// AllowRemove=false;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Business properties and methods
|
|
|
|
/// <summary>
|
|
/// Get item by index
|
|
/// </summary>
|
|
/// <param name="Item"></param>
|
|
public ReportPickListInfo this[int Item]
|
|
{
|
|
|
|
get
|
|
{
|
|
return (ReportPickListInfo) List[Item];
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Returns item that matches passed in itemid value
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
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
|
|
/// <summary>
|
|
/// Check if item in collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Contains(ReportPickListInfo obj)
|
|
{
|
|
foreach (ReportPickListInfo child in List)
|
|
{
|
|
if(child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// Get all Report (unfiltered as it's not bound)
|
|
/// </summary>
|
|
/// <returns>list of <see cref="ReportPickList.ReportPickListInfo"/> objects</returns>
|
|
public static ReportPickList GetList(string ReportKeySummary, string ReportKeyDetailed, bool Regional)
|
|
{
|
|
return (ReportPickList) DataPortal.Fetch(new Criteria(ReportKeySummary, ReportKeyDetailed, Regional));
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
///
|
|
/// <param name="Criteria"></param>
|
|
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
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[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 |