Files
ayanova7/source/bizobjects/AyaLib/GZTW.AyaNova.BLL/ContractList.cs
2018-06-29 19:47:36 +00:00

496 lines
15 KiB
C#

///////////////////////////////////////////////////////////
// ContractList.cs
// Implementation of Class ContractList
// CSLA type: Read only collection
// Created on: 26-Jan-2005
// Object design: John
// Coded: 26-Jan-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>
/// Lightweight list of <see cref="ContractList.ContractListInfo"/> objects representing <see cref="Contract"/> objects
///
/// </summary>
[Serializable]
public class ContractList : ReadOnlyCollectionBase
{
#region Data structure
/// <summary>
/// Properties
/// </summary>
[Serializable]
public struct ContractListInfo
{
internal GridNameValueCellItem mName; //and ID
internal bool mActive;
[SqlColumnNameAttribute("aContract.aName", "aContract.aID"),
Display(DisplayType.Button, RootObjectType = RootObjectTypes.Contract)]
public GridNameValueCellItem LT_O_Contract //changed 12-June-2006 was LT_Contract_Label_ID
{
get
{
return mName;
}
}
[Display(DisplayType.TrueFalse)]
public bool LT_Contract_Label_Active
{
get
{
return mActive;
}
}
internal decimal mDiscountParts;
[Display(DisplayType.Percentage)]
public decimal LT_Contract_Label_DiscountParts
{ get { return mDiscountParts; } }
internal bool mContractRatesOnly;
internal string mNotes;
[Display(DisplayType.TrueFalse)]
public bool LT_Contract_Label_ContractRatesOnly
{ get { return mContractRatesOnly; } }
[SqlColumnNameAttribute("grid"),Display(DisplayType.Text)]
public string LT_Contract_Label_Notes
{ get { return mNotes; } }
//Case 58
internal GridNameValueCellItem mRegion;
[SqlColumnNameAttribute("aRegion.aName", "aRegion.aID"),
Display(DisplayType.Button, RootObjectType = RootObjectTypes.Region)]
public GridNameValueCellItem LT_O_Region
{
get
{
return mRegion;
}
}
internal string mCustom1;
internal string mCustom2;
internal string mCustom3;
internal string mCustom4;
internal string mCustom5;
internal string mCustom6;
internal string mCustom7;
internal string mCustom8;
internal string mCustom9;
internal string mCustom0;
[Display(DisplayType.Text)]
public string LT_Contract_Label_Custom1{get{return mCustom1;}}
[Display(DisplayType.Text)]
public string LT_Contract_Label_Custom2{get{return mCustom2;}}
[Display(DisplayType.Text)]
public string LT_Contract_Label_Custom3{get{return mCustom3;}}
[Display(DisplayType.Text)]
public string LT_Contract_Label_Custom4{get{return mCustom4;}}
[Display(DisplayType.Text)]
public string LT_Contract_Label_Custom5{get{return mCustom5;}}
[Display(DisplayType.Text)]
public string LT_Contract_Label_Custom6{get{return mCustom6;}}
[Display(DisplayType.Text)]
public string LT_Contract_Label_Custom7{get{return mCustom7;}}
[Display(DisplayType.Text)]
public string LT_Contract_Label_Custom8{get{return mCustom8;}}
[Display(DisplayType.Text)]
public string LT_Contract_Label_Custom9{get{return mCustom9;}}
[Display(DisplayType.Text)]
public string LT_Contract_Label_Custom0{get{return mCustom0;}}
/// <summary>
///
/// </summary>
/// <param name="obj"></param>
public bool Equals(ContractListInfo obj)
{
return this.mName.Value.Equals(obj.mName.Value);
}
}//end ContractListInfo
#endregion
#region Constructor
protected ContractList()
{
// 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 ContractListInfo this[int Item]
{
get
{
return (ContractListInfo) List[Item];
}
}
/// <summary>
/// Returns display text that matches passed in itemid value
/// </summary>
/// <param name="ItemID"></param>
public string this[Guid ItemID]
{
get
{
foreach (ContractListInfo child in List)
{
if(child.mName.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(ContractListInfo obj)
{
foreach (ContractListInfo 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 "ContractList";
}
}
/// <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.Contract;
}
}
/// <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 "Contract.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(ContractListInfo);
}
}
/// <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_Contract";
}
}
/// <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 ContractList Get(string Filter, int MaxRecords, List<Guid> IDList)
{
return (ContractList)DataPortal.Fetch(new Criteria(Filter, IDList, MaxRecords));
}
/// <summary>
/// Get all Contract (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="ContractList.ContractListInfo"/> objects</returns>
public static ContractList GetList(string xmlCriteria)
{
return (ContractList) DataPortal.Fetch(new Criteria(xmlCriteria,null,-1));
}
/// <summary>
/// Get list by items indicated in IDList
/// </summary>
/// <param name="IDList">Generic list of Guid's</param>
/// <returns>list of <see cref="ContractList.ContractListInfo"/> objects</returns>
public static ContractList GetListFromIDList(List<Guid> IDList)
{
//case 556
//Handle empty list
if (IDList.Count == 0)
return new ContractList();
return (ContractList)DataPortal.Fetch(new Criteria("", IDList, -1));
}
/// <summary>
/// Return an empty list
/// used for initializing grid
/// </summary>
/// <returns></returns>
public static ContractList GetEmptyList()
{
return new ContractList();
}
#endregion
#region DAL DATA ACCESS
///
/// <param name="Criteria"></param>
protected override void DataPortal_Fetch(object Criteria)
{
Criteria crit = (Criteria)Criteria;
SafeDataReader dr = null;
try
{
string q="";
if (crit.IDList != null)
{
//Case 556
System.Text.StringBuilder sbIN = new System.Text.StringBuilder();
sbIN.Append(" WHERE aContract.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(") ");
q = "SELECT aContract.aID AS aContractID, aContract.aName AS aContractName, " +
"aContract.AACTIVE, " +
" aContract.aRegionID, aRegion.aName AS aRegionName, " + //case 58
" aContract.aCustom1, " +
" aContract.aCustom2, aContract.aCustom3, " +
" aContract.aCustom4, " +
" aContract.aCustom5, aContract.aCustom6, " +
" aContract.aCustom7, aContract.aCustom8, " +
" aContract.aCustom9, " +
" aContract.aCustom0, aDiscountParts, aContractRatesOnly,aNotes " +
"FROM aContract " +
"LEFT OUTER JOIN aRegion ON aContract.aRegionID = aRegion.aID " + //Case 58
sbIN.ToString() +
" " +
AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML);
}
else
{
//************************************************************
q = "SELECT ~MAXRECS~ aContract.aID AS aContractID, aContract.aName AS aContractName, " +
"aContract.AACTIVE, " +
" aContract.aRegionID, aRegion.aName AS aRegionName, " +
" aContract.aCustom1, " +
" aContract.aCustom2, aContract.aCustom3, " +
" aContract.aCustom4, " +
" aContract.aCustom5, aContract.aCustom6, " +
" aContract.aCustom7, aContract.aCustom8, " +
" aContract.aCustom9, " +
" aContract.aCustom0, aDiscountParts, aContractRatesOnly,aNotes " +
"FROM aContract " +
"LEFT OUTER JOIN aRegion ON aContract.aRegionID = aRegion.aID " + //Case 58
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~", "");
//************************************************************
}
dr=DBUtil.GetReaderFromSQLString(DBUtil.AddRegionFilter(q,"aContract",""));//case 58
while(dr.Read())
{
//*******************************************
ContractListInfo info=new ContractListInfo();
info.mName=new GridNameValueCellItem(
dr.GetGuid("aContractID"),
dr.GetString("aContractName"),
RootObjectTypes.Contract);
//Case 58
info.mRegion = new GridNameValueCellItem(
dr.GetGuid("aRegionID"),
dr.GetString("aRegionName"),
RootObjectTypes.Region);
info.mActive=dr.GetBoolean("AACTIVE");
info.mCustom0=dr.GetString("aCustom0");
info.mCustom1=dr.GetString("aCustom1");
info.mCustom2=dr.GetString("aCustom2");
info.mCustom3=dr.GetString("aCustom3");
info.mCustom4=dr.GetString("aCustom4");
info.mCustom5=dr.GetString("aCustom5");
info.mCustom6=dr.GetString("aCustom6");
info.mCustom7=dr.GetString("aCustom7");
info.mCustom8=dr.GetString("aCustom8");
info.mCustom9=dr.GetString("aCustom9");
info.mDiscountParts=dr.GetDecimal("aDiscountParts");
info.mContractRatesOnly=dr.GetBoolean("aContractRatesOnly");
info.mNotes=dr.GetString("aNotes");
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 ContractList
#pragma warning restore 1591
}//end namespace GZTW.AyaNova.BLL