456 lines
14 KiB
C#
456 lines
14 KiB
C#
///////////////////////////////////////////////////////////
|
|
// 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
|
|
/// <summary>
|
|
/// Read only list of <see cref="ReportList.ReportListInfo"/> objects representing <see cref="Report"/> objects.
|
|
/// Used for grid lists and reporting (ironically enough).
|
|
/// </summary>
|
|
[Serializable]
|
|
public class ReportList : ReadOnlyCollectionBase
|
|
{
|
|
#region Data structure
|
|
/// <summary>
|
|
/// Properties
|
|
/// </summary>
|
|
[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;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
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
|
|
|
|
/// <summary>
|
|
/// Get item by index
|
|
/// </summary>
|
|
/// <param name="Item"></param>
|
|
public ReportListInfo this[int Item]
|
|
{
|
|
|
|
get
|
|
{
|
|
return (ReportListInfo) List[Item];
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Returns display text that matches passed in itemid value
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
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
|
|
/// <summary>
|
|
/// Check if item in collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
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
|
|
|
|
/// <summary>
|
|
/// Returns the report key which is a property of
|
|
/// reports used to link all reports that can be used
|
|
/// with a particular data source.
|
|
/// </summary>
|
|
public static string ReportKey
|
|
{
|
|
get
|
|
{
|
|
return "ReportList";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 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
|
|
/// </summary>
|
|
public static string DetailedReportKey
|
|
{
|
|
get
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 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)
|
|
/// </summary>
|
|
public static RootObjectTypes BaseObjectType
|
|
{
|
|
get
|
|
{
|
|
return RootObjectTypes.Report;//case 1313
|
|
//return RootObjectTypes.Nothing;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Locale key so that generic list editor
|
|
/// UI code knows what title to give the list in a
|
|
/// grid
|
|
/// </summary>
|
|
public string LocaleKey
|
|
{
|
|
get
|
|
{
|
|
return "Report.Label.List";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 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
|
|
/// <see cref="DisplayAttribute"/>
|
|
/// </summary>
|
|
public static Type ListRecordType
|
|
{
|
|
get
|
|
{
|
|
return typeof(ReportListInfo);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
public static string IDField
|
|
{
|
|
get
|
|
{
|
|
return "LT_O_Report";
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Same as IDField but for detailed reports
|
|
/// </summary>
|
|
public static string IDFieldDetailed
|
|
{
|
|
get
|
|
{
|
|
return IDField;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// Internal method used by list factory
|
|
/// </summary>
|
|
internal static ReportList Get(string Filter, int MaxRecords, List<Guid> IDList)
|
|
{
|
|
return (ReportList)DataPortal.Fetch(new Criteria(Filter,IDList, MaxRecords));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get list by criteria
|
|
/// </summary>
|
|
/// <param name="xmlCriteria">Use AyaNova UI to easily build xmlCriteria and Ctrl-Alt-g keyboard command to display it for use in your code</param>
|
|
/// <returns>list of <see cref="ReportList.ReportListInfo"/> objects</returns>
|
|
|
|
public static ReportList GetList(string xmlCriteria)
|
|
{
|
|
return (ReportList) DataPortal.Fetch(new Criteria(xmlCriteria,null,-1));
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Takes a single ID and returns a "list" of one object
|
|
/// </summary>
|
|
/// <param name="ReportID">ID of Report object</param>
|
|
/// <returns>list of <see cref="ReportList.ReportListInfo"/> objects</returns>
|
|
public static ReportList GetListForSingleItem(Guid ReportID)
|
|
{
|
|
//Case 556
|
|
List<Guid> l = new List<Guid>();
|
|
l.Add(ReportID);
|
|
return GetListFromIDList(l);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Get list by items indicated in IDList
|
|
/// </summary>
|
|
/// <param name="IDList">Generic list of Guid's</param>
|
|
/// <returns>list of <see cref="ReportList.ReportListInfo"/> objects</returns>
|
|
public static ReportList GetListFromIDList(List<Guid> IDList)
|
|
{
|
|
//case 556
|
|
//Handle empty list
|
|
if (IDList.Count == 0)
|
|
return new ReportList();
|
|
return (ReportList)DataPortal.Fetch(new Criteria("", IDList, -1));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Return an empty list
|
|
/// used for initializing grid
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static ReportList GetEmptyList()
|
|
{
|
|
return new ReportList();
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
///
|
|
/// <param name="Criteria"></param>
|
|
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
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[Serializable]
|
|
private class Criteria
|
|
{
|
|
public List<Guid> IDList;
|
|
public string CriteriaXML;
|
|
public int MaxRecords;
|
|
public Criteria(string _CriteriaXML, List<Guid> _IDList, int _MaxRecords)
|
|
{
|
|
CriteriaXML = _CriteriaXML;
|
|
IDList = _IDList;
|
|
MaxRecords = _MaxRecords;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}//end ReportList
|
|
#pragma warning restore 1591
|
|
}//end namespace GZTW.AyaNova.BLL |