602 lines
19 KiB
C#
602 lines
19 KiB
C#
///////////////////////////////////////////////////////////
|
|
// UnitModelList.cs
|
|
// Implementation of Class UnitModelList
|
|
// CSLA type: Read only collection
|
|
// Created on: 29-Oct-2004
|
|
// Object design: John
|
|
// Coded: 29-Oct-2004
|
|
///////////////////////////////////////////////////////////
|
|
|
|
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="UnitModelList.UnitModelListInfo"/> objects representing <see cref="UnitModel"/> objects.
|
|
/// Used in UI for grids and for reporting purposes.
|
|
/// </summary>
|
|
[Serializable]
|
|
public class UnitModelList : ReadOnlyCollectionBase
|
|
{
|
|
|
|
|
|
#region Data structure
|
|
/// <summary>
|
|
/// Properties
|
|
/// </summary>
|
|
[Serializable]
|
|
public struct UnitModelListInfo
|
|
{
|
|
internal GridNameValueCellItem mName; //and ID
|
|
internal GridNameValueCellItem mModelNumber; //and ID
|
|
internal GridNameValueCellItem mUPC; //and ID if possible
|
|
internal GridNameValueCellItem mVendor;
|
|
internal GridNameValueCellItem mUnitModelCategory;
|
|
internal bool mLifeTimeWarranty;
|
|
internal SmartDate mIntroducedDate;
|
|
internal bool mDiscontinued;
|
|
internal SmartDate mDiscontinuedDate;
|
|
internal bool mActive;
|
|
|
|
|
|
[SqlColumnNameAttribute("aUnitModel.aName",
|
|
"aUnitModel.aID"),
|
|
Display(DisplayType.Button, RootObjectType = RootObjectTypes.UnitModel)]
|
|
public GridNameValueCellItem LT_O_UnitModel
|
|
{
|
|
get
|
|
{
|
|
return mName;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("aUnitModel.aModelNumber",
|
|
"aUnitModel.aID"),
|
|
Display(DisplayType.Button, RootObjectType = RootObjectTypes.UnitModel)]
|
|
public GridNameValueCellItem LT_UnitModel_Label_ModelNumber
|
|
{
|
|
get
|
|
{
|
|
return mModelNumber;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("aUnitModel.aUPC",
|
|
"aUnitModel.aID"),
|
|
Display(DisplayType.Button, RootObjectType = RootObjectTypes.UnitModel)]
|
|
public GridNameValueCellItem LT_UnitModel_Label_UPC
|
|
{
|
|
get
|
|
{
|
|
return mUPC;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("aVendor.aName",
|
|
"aUnitModel.aVendorID"),
|
|
Display(DisplayType.Button, RootObjectType = RootObjectTypes.Vendor)]
|
|
public GridNameValueCellItem LT_O_Vendor
|
|
{
|
|
get
|
|
{
|
|
return mVendor;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("aUnitModelCategory.aName",
|
|
"aUnitModel.aUnitModelCategoryID"),
|
|
Display(DisplayType.Button, RootObjectType = RootObjectTypes.UnitModelCategory)]
|
|
public GridNameValueCellItem LT_O_UnitModelCategory
|
|
{
|
|
get
|
|
{
|
|
return mUnitModelCategory;
|
|
}
|
|
}
|
|
|
|
|
|
[Display(DisplayType.TrueFalse)]
|
|
public bool LT_UnitModel_Label_LifeTimeWarranty
|
|
{
|
|
get
|
|
{
|
|
return mLifeTimeWarranty;
|
|
}
|
|
}
|
|
|
|
[Display(DisplayType.DateTime)]
|
|
public object LT_UnitModel_Label_IntroducedDate
|
|
{
|
|
get
|
|
{
|
|
return mIntroducedDate.DBValue;
|
|
}
|
|
}
|
|
|
|
[Display(DisplayType.TrueFalse)]
|
|
public bool LT_UnitModel_Label_Discontinued
|
|
{
|
|
get
|
|
{
|
|
return mDiscontinued;
|
|
}
|
|
}
|
|
|
|
[Display(DisplayType.DateTime)]
|
|
public object LT_UnitModel_Label_DiscontinuedDate
|
|
{
|
|
get
|
|
{
|
|
return mDiscontinuedDate.DBValue;
|
|
}
|
|
}
|
|
|
|
|
|
[Display(DisplayType.TrueFalse)]
|
|
public bool LT_UnitModel_Label_Active
|
|
{
|
|
get
|
|
{
|
|
return mActive;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
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_UnitModel_Label_Custom1{get{return mCustom1;}}
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_UnitModel_Label_Custom2{get{return mCustom2;}}
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_UnitModel_Label_Custom3{get{return mCustom3;}}
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_UnitModel_Label_Custom4{get{return mCustom4;}}
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_UnitModel_Label_Custom5{get{return mCustom5;}}
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_UnitModel_Label_Custom6{get{return mCustom6;}}
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_UnitModel_Label_Custom7{get{return mCustom7;}}
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_UnitModel_Label_Custom8{get{return mCustom8;}}
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_UnitModel_Label_Custom9{get{return mCustom9;}}
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_UnitModel_Label_Custom0{get{return mCustom0;}}
|
|
|
|
|
|
internal string mNotes;
|
|
internal string mWarrantyTerms;
|
|
[SqlColumnNameAttribute("grid"), Display(DisplayType.Text)]
|
|
public string LT_UnitModel_Label_Notes {get{return mNotes;}}
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_UnitModel_Label_WarrantyTerms {get{return mWarrantyTerms;}}
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Equals(UnitModelListInfo obj)
|
|
{
|
|
return this.mModelNumber.Value.Equals(obj.mModelNumber.Value);
|
|
}
|
|
|
|
}//end UnitModelListInfo
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
protected UnitModelList()
|
|
{
|
|
// 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 UnitModelListInfo this[int Item]
|
|
{
|
|
|
|
get
|
|
{
|
|
return (UnitModelListInfo) List[Item];
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Returns display text that matches passed in itemid value
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
public string this[Guid ItemID]
|
|
{
|
|
|
|
get
|
|
{
|
|
foreach (UnitModelListInfo child in List)
|
|
{
|
|
if(child.mModelNumber.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(UnitModelListInfo obj)
|
|
{
|
|
foreach (UnitModelListInfo 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 "UnitModelList";
|
|
}
|
|
}
|
|
|
|
/// <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.UnitModel;
|
|
}
|
|
}
|
|
|
|
/// <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 "UI.Go.UnitModels";
|
|
}
|
|
}
|
|
|
|
/// <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(UnitModelListInfo);
|
|
}
|
|
}
|
|
|
|
|
|
/// <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_UnitModel";
|
|
}
|
|
}
|
|
/// <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 UnitModelList Get(string Filter, int MaxRecords, List<Guid> IDList)
|
|
{
|
|
return (UnitModelList)DataPortal.Fetch(new Criteria(Filter, IDList, MaxRecords));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get all UnitModel (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="UnitModelList.UnitModelListInfo"/> objects</returns>
|
|
public static UnitModelList GetList(string xmlCriteria)
|
|
{
|
|
return (UnitModelList) DataPortal.Fetch(new Criteria(xmlCriteria,null, -1));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Takes a single ID and returns a "list" of one object
|
|
/// </summary>
|
|
/// <param name="UnitModelID">ID of UnitModel object</param>
|
|
/// <returns>list of <see cref="UnitModelList.UnitModelListInfo"/> objects</returns>
|
|
public static UnitModelList GetListForSingleItem(Guid UnitModelID)
|
|
{
|
|
//Case 556
|
|
List<Guid> l = new List<Guid>();
|
|
l.Add(UnitModelID);
|
|
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="UnitModelList.UnitModelListInfo"/> objects</returns>
|
|
public static UnitModelList GetListFromIDList(List<Guid> IDList)
|
|
{
|
|
//case 556
|
|
//Handle empty list
|
|
if (IDList.Count == 0)
|
|
return new UnitModelList();
|
|
return (UnitModelList)DataPortal.Fetch(new Criteria("", IDList, -1));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Return an empty list
|
|
/// used for initializing grid
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static UnitModelList GetEmptyList()
|
|
{
|
|
return new UnitModelList();
|
|
}
|
|
|
|
|
|
#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 (aUnitModel.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 aUnitModel.aID AS aUnitModelID, aUnitModel.aName AS aUnitModelName, " +
|
|
"aUnitModel.aUPC, aUnitModel.AACTIVE, aUnitModel.aModelNumber, " +
|
|
"aUnitModel.aVendorID, aVendor.aName AS aVendorName, " +
|
|
"aUnitModel.aUnitModelCategoryID, aUnitModelCategory.aName " +
|
|
"AS aUnitModelCategoryName, aUnitModel.aLifeTimeWarranty, " +
|
|
"aUnitModel.aIntroducedDate, " +
|
|
"aUnitModel.aDiscontinued, aUnitModel.aDiscontinuedDate, " +
|
|
" aUnitModel.aCustom1, " +
|
|
" aUnitModel.aCustom2, aUnitModel.aCustom3, " +
|
|
" aUnitModel.aCustom4, " +
|
|
" aUnitModel.aCustom5, aUnitModel.aCustom6, " +
|
|
" aUnitModel.aCustom7, aUnitModel.aCustom8, " +
|
|
" aUnitModel.aCustom9, " +
|
|
" aUnitModel.aCustom0, aUnitModel.aNotes, aUnitModel.aWarrantyTerms " +
|
|
"FROM aUnitModel LEFT OUTER JOIN " +
|
|
"aUnitModelCategory ON aUnitModel.aUnitModelCategoryID " +
|
|
"= aUnitModelCategory.aID LEFT OUTER JOIN " +
|
|
"aVendor ON aUnitModel.aVendorID = aVendor.aID ";
|
|
|
|
dr = DBUtil.GetReaderFromSQLString(q + sbIN.ToString() + " " +
|
|
AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML));
|
|
}
|
|
else
|
|
{
|
|
|
|
//************************************************************
|
|
q = "SELECT ~MAXRECS~ aUnitModel.aID AS aUnitModelID, aUnitModel.aName AS aUnitModelName, " +
|
|
"aUnitModel.aUPC, aUnitModel.AACTIVE, aUnitModel.aModelNumber, " +
|
|
"aUnitModel.aVendorID, aVendor.aName AS aVendorName, " +
|
|
"aUnitModel.aUnitModelCategoryID, aUnitModelCategory.aName " +
|
|
"AS aUnitModelCategoryName, aUnitModel.aLifeTimeWarranty, " +
|
|
"aUnitModel.aIntroducedDate, " +
|
|
"aUnitModel.aDiscontinued, aUnitModel.aDiscontinuedDate, " +
|
|
" aUnitModel.aCustom1, " +
|
|
" aUnitModel.aCustom2, aUnitModel.aCustom3, " +
|
|
" aUnitModel.aCustom4, " +
|
|
" aUnitModel.aCustom5, aUnitModel.aCustom6, " +
|
|
" aUnitModel.aCustom7, aUnitModel.aCustom8, " +
|
|
" aUnitModel.aCustom9, " +
|
|
" aUnitModel.aCustom0, aUnitModel.aNotes, aUnitModel.aWarrantyTerms " +
|
|
"FROM aUnitModel LEFT OUTER JOIN " +
|
|
"aUnitModelCategory ON aUnitModel.aUnitModelCategoryID " +
|
|
"= aUnitModelCategory.aID LEFT OUTER JOIN " +
|
|
"aVendor ON aUnitModel.aVendorID = aVendor.aID " +
|
|
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(q);
|
|
}
|
|
while(dr.Read())
|
|
{
|
|
//*******************************************
|
|
UnitModelListInfo info=new UnitModelListInfo();
|
|
info.mLifeTimeWarranty=dr.GetBoolean("aLifeTimeWarranty");
|
|
info.mDiscontinued=dr.GetBoolean("aDiscontinued");
|
|
|
|
info.mName=new GridNameValueCellItem(
|
|
dr.GetGuid("aUnitModelID"),
|
|
dr.GetString("aUnitModelName"),
|
|
RootObjectTypes.UnitModel);
|
|
|
|
info.mModelNumber=new GridNameValueCellItem(
|
|
dr.GetGuid("aUnitModelID"),
|
|
dr.GetString("aModelNumber"),
|
|
RootObjectTypes.UnitModel);
|
|
|
|
info.mUPC=new GridNameValueCellItem(
|
|
dr.GetGuid("aUnitModelID"),
|
|
dr.GetString("aUPC"),
|
|
RootObjectTypes.UnitModel);
|
|
|
|
info.mVendor=new GridNameValueCellItem(
|
|
dr.GetGuid("aVendorID"),
|
|
dr.GetString("aVendorName"),
|
|
RootObjectTypes.Vendor);
|
|
|
|
info.mUnitModelCategory=new GridNameValueCellItem(
|
|
dr.GetGuid("aUnitModelCategoryID"),
|
|
dr.GetString("aUnitModelCategoryName"),
|
|
RootObjectTypes.UnitModelCategory);
|
|
|
|
info.mIntroducedDate=DBUtil.ToLocal(dr.GetSmartDate("aIntroducedDate"));
|
|
info.mDiscontinuedDate=DBUtil.ToLocal(dr.GetSmartDate("aDiscontinuedDate"));
|
|
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.mNotes=dr.GetString("aNotes");
|
|
info.mWarrantyTerms=dr.GetString("aWarrantyTerms");
|
|
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 UnitModelList
|
|
#pragma warning restore 1591
|
|
}//end namespace GZTW.AyaNova.BLL |