Files
2018-06-29 19:47:36 +00:00

429 lines
14 KiB
C#

///////////////////////////////////////////////////////////
// TemplateQuoteList.cs
// Implementation of Class TemplateQuoteList
// CSLA type: Read only collection
// Created on: 07-Nov-2007
// Object design: John
// Coded: 07-Nov-2007
///////////////////////////////////////////////////////////
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="TemplateQuoteList.TemplateQuoteListInfo"/> objects representing quote templates.
/// Used in UI grids and reporting.
///
/// </summary>
[Serializable]
public class TemplateQuoteList : ReadOnlyCollectionBase
{
#region Data structure
/// <summary>
/// Properties
/// </summary>
[Serializable]
public struct TemplateQuoteListInfo
{
internal GridNameValueCellItem mQuoteWorkorder;
internal GridNameValueCellItem mDescription;
internal SmartDate mDateCreated;
//====================================================================================
[SqlColumnNameAttribute("aWorkorderQuote.aQuoteNumber", "aWorkorder.aID"),
Display(DisplayType.Button, RootObjectType = RootObjectTypes.WorkorderQuoteTemplate, CompareAs = CompareType.StringToInt32)]
public GridNameValueCellItem LT_O_WorkorderQuote { get { return mQuoteWorkorder; } }
[SqlColumnNameAttribute("aWorkorder.aTemplateDescription", "aWorkorder.aID"),
Display(DisplayType.Button, RootObjectType = RootObjectTypes.WorkorderServiceTemplate)]
public GridNameValueCellItem LT_Workorder_Label_TemplateDescription { get { return mDescription; } }
//[Display(DisplayType.Text)]
//public string LT_Workorder_Label_TemplateDescription { get { return mDescription; } }
[Display(DisplayType.DateTime)]
public object LT_WorkorderQuote_Label_Created { get { return mDateCreated.DBValue; } }
//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(TemplateQuoteListInfo obj)
{
return this.mQuoteWorkorder.Value.Equals(obj.mQuoteWorkorder.Value);
}
}//end TemplateQuoteListInfo
#endregion
#region Constructor
protected TemplateQuoteList()
{
// 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 TemplateQuoteListInfo this[int Item]
{
get
{
return (TemplateQuoteListInfo)List[Item];
}
}
/// <summary>
/// Returns display text that matches passed in itemid value
/// </summary>
/// <param name="ItemID"></param>
public string this[Guid ItemID]
{
get
{
foreach (TemplateQuoteListInfo child in List)
{
if (child.mQuoteWorkorder.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(TemplateQuoteListInfo obj)
{
foreach (TemplateQuoteListInfo 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 "TemplateQuoteList";
}
}
/// <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.WorkorderQuoteTemplate;
}
}
/// <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(TemplateQuoteListInfo);
}
}
/// <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 "WorkorderQuote.Label.List";
}
}
/// <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_WorkorderQuote";
}
}
/// <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 TemplateQuoteList Get(string Filter, int MaxRecords, List<Guid> IDList)
{
return (TemplateQuoteList)DataPortal.Fetch(new Criteria(Filter, IDList, MaxRecords));
}
/// <summary>
/// Get all WorkorderQuote (filtered by crit)
/// </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="TemplateQuoteList.TemplateQuoteListInfo"/> objects</returns>
public static TemplateQuoteList GetList(string xmlCriteria)
{
return (TemplateQuoteList)DataPortal.Fetch(new Criteria(xmlCriteria, null, -1));
}
/// <summary>
/// Takes a single ID and returns a "list" of one object
/// </summary>
/// <param name="WorkorderID">ID of Workorder object</param>
/// <returns></returns>
public static TemplateQuoteList GetListForSingleItem(Guid WorkorderID)
{
//Case 556
List<Guid> l = new List<Guid>();
l.Add(WorkorderID);
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="TemplateQuoteList.TemplateQuoteListInfo"/> objects</returns>
public static TemplateQuoteList GetListFromIDList(List<Guid> IDList)
{
//case 556
//Handle empty list
if (IDList.Count == 0)
return new TemplateQuoteList();
return (TemplateQuoteList)DataPortal.Fetch(new Criteria("", IDList, -1));
}
/// <summary>
/// Return an empty list
/// used for initializing grid
/// </summary>
/// <returns></returns>
public static TemplateQuoteList GetEmptyList()
{
return new TemplateQuoteList();
}
#endregion
#region DAL DATA ACCESS
///
/// <param name="Criteria"></param>
protected override void DataPortal_Fetch(object Criteria)
{
Criteria crit = (Criteria)Criteria;
SafeDataReader dr = null;
try
{
DBCommandWrapper cm = null;
//Base query
string q = "SELECT ~MAXRECS~ aWorkorder.aID AS aWorkorderID, aWorkorderQuote.aQuoteNumber, aWorkorder.aTemplateDescription, " +
"aWorkorder.aRegionID, aRegion.aName AS aRegionName, " + //case 58
" aWorkorder.ACreated as CREATED " +
"FROM " +
" AWORKORDER " +
" INNER JOIN AWORKORDERQUOTE ON (AWORKORDERQUOTE.AWORKORDERID=AWORKORDER.AID) " +
"LEFT OUTER JOIN aRegion ON aWorkorder.aRegionID = aRegion.aID " + //Case 58
"WHERE (aWorkorder.aWorkorderType = 6) ";
if (crit.MaxRecords > 0)
q = q.Replace("~MAXRECS~", "TOP " + crit.MaxRecords.ToString());
else
q = q.Replace("~MAXRECS~", "");
//One item or grid criteria?
if (crit.IDList != null)
{
//Case 556
System.Text.StringBuilder sbIN = new System.Text.StringBuilder();
sbIN.Append(" AND (aWorkorder.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(")) ");
//One item:
cm = DBUtil.DB.GetSqlStringCommandWrapper(q + sbIN.ToString() + " " +
AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML));
}
else
{
//Grid criteria
cm = DBUtil.DB.GetSqlStringCommandWrapper(DBUtil.AddRegionFilter(//case 58
q +
AyaBizUtils.GetGridColumnCriteria(crit.CriteriaXML, false) + " " +
AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML),
"aWorkorder",
""
)
);
}
dr = new SafeDataReader(DBUtil.DB.ExecuteReader(cm));
while (dr.Read())
{
//*******************************************
TemplateQuoteListInfo info = new TemplateQuoteListInfo();
info.mQuoteWorkorder = new GridNameValueCellItem(
dr.GetGuid("aWorkorderID"),
dr.GetInt32("aQuoteNumber").ToString(),
RootObjectTypes.Workorder);
//Case 58
info.mRegion = new GridNameValueCellItem(
dr.GetGuid("aRegionID"),
dr.GetString("aRegionName"),
RootObjectTypes.Region);
//info.mDescription = dr.GetString("aTemplateDescription");
info.mDescription = new GridNameValueCellItem(
dr.GetGuid("aWorkorderID"), dr.GetString("aTemplateDescription"), RootObjectTypes.Workorder
);
info.mDateCreated = DBUtil.ToLocal(dr.GetSmartDate("Created"));
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 TemplateQuoteList
#pragma warning restore 1591
}//end namespace GZTW.AyaNova.BLL