Files
ayanova7/source/bizobjects/AyaLib/GZTW.AyaNova.BLL/UnitList.cs
2020-03-10 17:28:09 +00:00

996 lines
41 KiB
C#

///////////////////////////////////////////////////////////
// UnitList.cs
// Implementation of Class UnitList
// CSLA type: Read only collection
// Created on: 26-Oct-2004
// Object design: John
// Coded: 26-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="UnitList.UnitListInfo"/> objects representing <see cref="Unit"/> objects.
/// Used for UI grids and summary reports and internally in API by other business objects.
/// </summary>
[Serializable]
public class UnitList : ReadOnlyCollectionBase
{
#region Data structure
/// <summary>
/// Properties
/// </summary>
[Serializable]
public struct UnitListInfo
{
internal bool mActive;
internal GridNameValueCellItem mSerial; //and ID
internal GridNameValueCellItem mClient;
internal GridNameValueCellItem mUnitModel;
internal SmartDate mPurchasedDate;
internal GridNameValueCellItem mParentUnit; //and ID
internal GridNameValueCellItem mWorkorder;
internal SmartDate mServiceDate;
internal GridNameValueCellItem mUnitModelNumber;//case 1727
[SqlColumnNameAttribute("aClient.aName", "aChildUnits.aClientID"),
Display(DisplayType.Button, RootObjectType = RootObjectTypes.Client)]
public GridNameValueCellItem LT_O_Client
{
get
{
return mClient;
}
}
[SqlColumnNameAttribute("aUnitModel.aName",
"aChildUnits.aUnitModelID"),
Display(DisplayType.Button, RootObjectType = RootObjectTypes.UnitModel)]
public GridNameValueCellItem LT_O_UnitModel
{
get
{
return mUnitModel;
}
}
//case 1727
[SqlColumnNameAttribute("aUnitModel.aModelNumber",
"aChildUnits.aUnitModelID"),
Display(DisplayType.Button, RootObjectType = RootObjectTypes.UnitModel)]
public GridNameValueCellItem LT_UnitModel_Label_ModelNumber
{
get
{
return mUnitModelNumber;
}
}
//15-Sept-2006 Add unitmodel category
internal GridNameValueCellItem mUnitModelCategory;
[SqlColumnNameAttribute("aUnitModelCategory.aName",
"aUnitModel.aUnitModelCategoryID"),
Display(DisplayType.Button, RootObjectType = RootObjectTypes.UnitModelCategory)]
public GridNameValueCellItem LT_O_UnitModelCategory
{
get
{
return mUnitModelCategory;
}
}
[SqlColumnNameAttribute("aChildUnits.aPurchasedDate"), Display(DisplayType.DateTime)]
public object LT_Unit_Label_PurchasedDate
{
get
{
return mPurchasedDate.DBValue;
}
}
[SqlColumnNameAttribute("aChildUnits.AACTIVE"), Display(DisplayType.TrueFalse)]
public bool LT_Unit_Label_Active
{
get
{
return mActive;
}
}
[SqlColumnNameAttribute("aChildUnits.aSerial", "aChildUnits.aID"),
Display(DisplayType.Button, RootObjectType = RootObjectTypes.Unit)]
public GridNameValueCellItem LT_Unit_Label_Serial
{
get
{
return mSerial;
}
}
[SqlColumnNameAttribute("aParentUnits.aSerial", "aChildUnits.aParentUnitID"),
Display(DisplayType.Button, RootObjectType = RootObjectTypes.Unit)]
public GridNameValueCellItem LT_Unit_Label_ParentUnitID
{
get
{
return mParentUnit;
}
}
[SqlColumnNameAttribute("aWorkorderService.aServiceNumber",
"aChildUnits.aLastWorkorderID"),
Display(DisplayType.Button, RootObjectType = RootObjectTypes.WorkorderService)]
public GridNameValueCellItem LT_UI_Label_LastWorkorder
{
get
{
return mWorkorder;
}
}
[SqlColumnNameAttribute("aChildUnits.aLastServiceDate"), Display(DisplayType.DateTime)]
public object LT_UI_Label_LastServiceDate
{
get
{
return mServiceDate.DBValue;
}
}
internal decimal mHoursBalance;
internal decimal mIncidentsBalance;
internal decimal mCurrencyBalance;
[SqlColumnNameAttribute("grid"), Display(DisplayType.DecimalNumber)]
public decimal LT_ServiceBank_Label_HoursBalance
{
get
{
return mHoursBalance;
}
}
[SqlColumnNameAttribute("grid"), Display(DisplayType.DecimalNumber)]
public decimal LT_ServiceBank_Label_IncidentsBalance
{
get
{
return mIncidentsBalance;
}
}
[SqlColumnNameAttribute("grid"), Display(DisplayType.Currency)]
public decimal LT_ServiceBank_Label_CurrencyBalance
{
get
{
return mCurrencyBalance;
}
}
internal bool mUsesBanking;
[SqlColumnNameAttribute("aChildUnits.aUsesBanking"), Display(DisplayType.TrueFalse)]
public bool LT_Client_Label_UsesBanking
{
get
{
return mUsesBanking;
}
}
internal bool mMetered;
internal bool mOverrideModelWarranty;
internal int mWarrantyLength;
internal bool mLifeTimeWarranty;
internal bool mUnitHasOwnAddress;
internal decimal mLastMeter;
[SqlColumnNameAttribute("aChildUnits.aMetered"), Display(DisplayType.TrueFalse)]
public bool LT_Unit_Label_Metered { get { return mMetered; } }
[SqlColumnNameAttribute("aChildUnits.aOverrideModelWarranty"), Display(DisplayType.TrueFalse)]
public bool LT_Unit_Label_OverrideWarranty { get { return mOverrideModelWarranty; } }
[SqlColumnNameAttribute("aChildUnits.aWarrantyLength"), Display(DisplayType.WholeNumber)]
public int LT_Unit_Label_OverrideLength { get { return mWarrantyLength; } }//case 1741
[SqlColumnNameAttribute("aChildUnits.aLifeTimeWarranty"), Display(DisplayType.TrueFalse)]
public bool LT_Unit_Label_OverrideLifeTime { get { return mLifeTimeWarranty; } }//case 1741
[SqlColumnNameAttribute("aChildUnits.aUnitHasOwnAddress"), Display(DisplayType.TrueFalse)]
public bool LT_Unit_Label_UnitHasOwnAddress { get { return mUnitHasOwnAddress; } }
[SqlColumnNameAttribute("grid"), Display(DisplayType.DecimalNumber)]
public decimal LT_Unit_Label_LastMeter { get { return mLastMeter; } }
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;
[SqlColumnNameAttribute("grid"), Display(DisplayType.Text)]
public string LT_Unit_Label_Custom1 { get { return mCustom1; } }
[SqlColumnNameAttribute("grid"), Display(DisplayType.Text)]
public string LT_Unit_Label_Custom2 { get { return mCustom2; } }
[SqlColumnNameAttribute("grid"), Display(DisplayType.Text)]
public string LT_Unit_Label_Custom3 { get { return mCustom3; } }
[SqlColumnNameAttribute("grid"), Display(DisplayType.Text)]
public string LT_Unit_Label_Custom4 { get { return mCustom4; } }
[SqlColumnNameAttribute("grid"), Display(DisplayType.Text)]
public string LT_Unit_Label_Custom5 { get { return mCustom5; } }
[SqlColumnNameAttribute("grid"), Display(DisplayType.Text)]
public string LT_Unit_Label_Custom6 { get { return mCustom6; } }
[SqlColumnNameAttribute("grid"), Display(DisplayType.Text)]
public string LT_Unit_Label_Custom7 { get { return mCustom7; } }
[SqlColumnNameAttribute("grid"), Display(DisplayType.Text)]
public string LT_Unit_Label_Custom8 { get { return mCustom8; } }
[SqlColumnNameAttribute("grid"), Display(DisplayType.Text)]
public string LT_Unit_Label_Custom9 { get { return mCustom9; } }
[SqlColumnNameAttribute("grid"), Display(DisplayType.Text)]
public string LT_Unit_Label_Custom0 { get { return mCustom0; } }
internal string mDeliveryAddress;
internal string mCity;
internal string mStateProv;
internal string mCountry;
internal string mPostal;
internal string mCountryCode;
internal string mLatitude;
internal string mLongitude;
[Display(DisplayType.Text)]
public string LT_Address_Label_DeliveryAddress { get { return mDeliveryAddress; } }
[Display(DisplayType.Text)]
public string LT_Address_Label_City { get { return mCity; } }
[Display(DisplayType.Text)]
public string LT_Address_Label_StateProv { get { return mStateProv; } }
[Display(DisplayType.Text)]
public string LT_Address_Label_Country { get { return mCountry; } }
[Display(DisplayType.Text)]
public string LT_Address_Label_Postal { get { return mPostal; } }
[Display(DisplayType.Text)]
public string LT_Address_Label_CountryCode { get { return mCountryCode; } }
[Display(DisplayType.GeoCoordinate)]
public string LT_Address_Label_Latitude { get { return mLatitude; } }
[Display(DisplayType.GeoCoordinate)]
public string LT_Address_Label_Longitude { get { return mLongitude; } }
internal string mWarrantyTerms;
internal string mNotes;
[SqlColumnNameAttribute("aChildUnits.aWarrantyTerms"), Display(DisplayType.Text)]
public string LT_Unit_Label_OverrideWarrantyTerms { get { return mWarrantyTerms; } }
[SqlColumnNameAttribute("grid"), Display(DisplayType.Text)]
public string LT_Unit_Label_Notes { get { return mNotes; } }
//Case 427
internal string mReceipt;
[SqlColumnNameAttribute("aChildUnits.ARECEIPT"), Display(DisplayType.Text)]
//case 3731 was defined as "object" not string causing grid filter to offer date related not string related filters
public string LT_Unit_Label_Receipt
{
get
{
return mReceipt;
}
}
internal GridNameValueCellItem mPurchaseFromID;
[SqlColumnNameAttribute("APurchaseFromVendors.AName", "aChildUnits.aPurchasedFromID"),
Display(DisplayType.Button, RootObjectType = RootObjectTypes.Vendor)]
public GridNameValueCellItem LT_Unit_Label_PurchaseFromID
{
get
{
return mPurchaseFromID;
}
}
internal GridNameValueCellItem mModelVendorID;
[SqlColumnNameAttribute("AUnitModelVendors.AName",
"aUnitModel.AVendorID"),
Display(DisplayType.Button, RootObjectType = RootObjectTypes.Vendor)]
public GridNameValueCellItem LT_UnitModel_Label_VendorID
{
get
{
return mModelVendorID;
}
}
//Case 444
internal string mDescription;
[SqlColumnNameAttribute("aChildUnits.ADescription"), Display(DisplayType.Text)]
public string LT_Unit_Label_Description //Case 861 was set as type object not string
{
get
{
return mDescription;
}
}
//case 78
internal string mText1;
internal string mText2;
internal string mText3;
internal string mText4;
[SqlColumnNameAttribute("aChildUnits.ATEXT1"), Display(DisplayType.Text)]
public string LT_Unit_Label_Text1 {get{return mText1;}}
[SqlColumnNameAttribute("aChildUnits.ATEXT2"), Display(DisplayType.Text)]
public string LT_Unit_Label_Text2 { get { return mText2; } }
[SqlColumnNameAttribute("aChildUnits.ATEXT3"), Display(DisplayType.Text)]
public string LT_Unit_Label_Text3 { get { return mText3; } }
[SqlColumnNameAttribute("aChildUnits.ATEXT4"), Display(DisplayType.Text)]
public string LT_Unit_Label_Text4 { get { return mText4; } }
//case 974 (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 bool mBoughtHere;
[SqlColumnNameAttribute("aChildUnits.aBoughtHere"), Display(DisplayType.TrueFalse)]
public bool LT_Unit_Label_BoughtHere
{
get
{
return mBoughtHere;
}
}
/// <summary>
///
/// </summary>
/// <param name="obj"></param>
public bool Equals(UnitListInfo obj)
{
return this.mSerial.Value.Equals(obj.mSerial.Value);
}
}//end UnitListInfo
#endregion
#region Constructor
protected UnitList()
{
// 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 UnitListInfo this[int Item]
{
get
{
return (UnitListInfo)List[Item];
}
}
/// <summary>
/// Returns display text that matches passed in itemid value
/// </summary>
/// <param name="ItemID"></param>
public string this[Guid ItemID]
{
get
{
foreach (UnitListInfo child in List)
{
if (child.mSerial.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(UnitListInfo obj)
{
foreach (UnitListInfo 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 "UnitList";
}
}
/// <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.Unit;
}
}
/// <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 "Unit.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(UnitListInfo);
}
}
/// <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_Unit_Label_Serial";
}
}
/// <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 UnitList Get(string Filter, int MaxRecords, List<Guid> IDList)
{
return (UnitList)DataPortal.Fetch(new Criteria(Filter, IDList, MaxRecords));
}
/// <summary>
/// Get all Unit (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="UnitList.UnitListInfo"/> objects </returns>
public static UnitList GetList(string xmlCriteria)
{
return (UnitList)DataPortal.Fetch(new Criteria(xmlCriteria, null, -1));
}
//case 1975
/// <summary>
/// Get all Unit (filtered by crit and with maximum records)
/// </summary>
public static UnitList GetList(string Filter, int MaxRecords)
{
return (UnitList)DataPortal.Fetch(new Criteria(Filter, null, MaxRecords));
}
/// <summary>
/// Takes a single ID and returns a "list" of one object
/// </summary>
/// <param name="UnitID">ID of Unit object</param>
/// <returns>list of <see cref="UnitList.UnitListInfo"/> objects </returns>
public static UnitList GetListForSingleItem(Guid UnitID)
{
//Case 556
List<Guid> l = new List<Guid>();
l.Add(UnitID);
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="UnitList.UnitListInfo"/> objects </returns>
public static UnitList GetListFromIDList(List<Guid> IDList)
{
//case 556
//Handle empty list
if (IDList.Count == 0)
return new UnitList();
return (UnitList)DataPortal.Fetch(new Criteria("", IDList, -1));
}
/// <summary>
/// Return an empty list
/// used for initializing grid
/// </summary>
/// <returns></returns>
public static UnitList GetEmptyList()
{
return new UnitList();
}
#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 (aChildUnits.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 aUnitModelCategory.aName as aUnitModelCategoryName, aUnitModel.aUnitModelCategoryID, " +
"aChildUnits.aID, aChildUnits.aSerial, aChildUnits.AACTIVE, " +
"aChildUnits.ATEXT1, aChildUnits.ATEXT2, aChildUnits.ATEXT3, aChildUnits.ATEXT4, " + //case 78
" aClient.aRegionID, aRegion.aName AS aRegionName, " + //case 974 (case 58)
" aChildUnits.aLastWorkorderID, aChildUnits.aLastServiceDate, aUnitModel.aModelNumber, " +
" aUnitModel.aName AS aUnitModelName, (SELECT TOP 1 aSBANK.aHoursBalance " +
"FROM aServiceBank aSBANK WHERE aSBANK.AAPPLIESTOROOTOBJECTID " +
"= aChildUnits.aID ORDER " +
"BY aSBANK.aCreated DESC) AS HOURSBAL, (SELECT TOP 1 aSBANK.aIncidentsBalance " +
"FROM aServiceBank aSBANK WHERE " +
"aSBANK.AAPPLIESTOROOTOBJECTID = aChildUnits.aID ORDER " +
"BY aSBANK.aCreated DESC) AS INCIDENTSBAL, (SELECT " +
"TOP 1 aSBANK.aCurrencyBalance FROM aServiceBank aSBANK " +
"WHERE aSBANK.AAPPLIESTOROOTOBJECTID = aChildUnits.aID " +
"ORDER BY aSBANK.aCreated DESC) AS CURRENCYBAL, " +
"(SELECT TOP 1 aMeter FROM aUnitMeterReading WHERE " +
"(aUnitMeterReading.aUnitID = aChildUnits.aID) " +
"ORDER BY aCreated DESC) AS aLASTMETERCOUNT, " +
" aChildUnits.aUnitModelID, aClient.aName " +
"AS aClientName, aChildUnits.aClientID, aChildUnits.aPurchasedDate, " +
" aChildUnits.aParentUnitID, " +
" aParentUnits.aSerial AS aParentUnitName, aWorkorderService.aServiceNumber, " +
" aChildUnits.aMetered, " +
" aChildUnits.aOverrideModelWarranty, aChildUnits.aWarrantyLength, " +
" aChildUnits.aLifeTimeWarranty, " +
"aChildUnits.aUnitHasOwnAddress, aChildUnits.aCustom1, " +
" aChildUnits.aCustom2, aChildUnits.aCustom3, aChildUnits.aCustom4, " +
" aChildUnits.aCustom5, aChildUnits.aCustom6, " +
" aChildUnits.aCustom7, aChildUnits.aCustom8, " +
" aChildUnits.aCustom9, aChildUnits.aCustom0, " +
//case 771
" aChildUnits.ABoughtHere, " +
//Case 427
" AChildUnits.APurchasedFromID AS ACHILDPURCHASEDFROMID, APurchaseFromVendors.AName AS APURCHASEVENDORNAME, " +
" aUnitModel.AVendorID AS AMODELVENDORID, AUnitModelVendors.AName AS AMODELVENDORNAME, " +
//Case 444
" AChildUnits.ADescription AS ACHILDDESCRIPTION, " +
" AADDRESS.aLatitude, AADDRESS.aLongitude, " +
" AADDRESS.aPostal, AADDRESS.aCountry, AADDRESS.aCountryCode, " +
" AADDRESS.aStateProv, AADDRESS.aCity, " +
" AADDRESS.aDeliveryAddress, aChildUnits.aWarrantyTerms, " +
" aChildUnits.aNotes, aChildUnits.aReceipt, " +
" aChildUnits.aUsesBanking FROM aUnit " +
"aChildUnits LEFT OUTER JOIN AADDRESS " +
"ON aChildUnits.aID = AADDRESS.aRootObjectID LEFT " +
"OUTER JOIN aWorkorderService ON aChildUnits.aLastWorkorderID " +
"= aWorkorderService.aWorkorderID " +
"LEFT OUTER JOIN aUnit aParentUnits ON aChildUnits.aParentUnitID " +
"= aParentUnits.aID LEFT OUTER " +
"JOIN aClient ON aChildUnits.aClientID = aClient.aID " +
"LEFT OUTER JOIN aUnitModel ON aChildUnits.aUnitModelID " +
"= aUnitModel.aID \r\n" +
//15-Sept-2006 add UnitModelCategory
"LEFT OUTER JOIN aUnitModelCategory ON aUnitModel.aUnitModelCategoryID = aUnitModelCategory.aID \r\n" +
//Case 427
"LEFT OUTER JOIN AVendor APurchaseFromVendors ON aChildUnits.aPurchasedFromID = APurchaseFromVendors.aID \r\n" +
"LEFT OUTER JOIN AVendor AUnitModelVendors ON aUnitModel.AVendorID = AUnitModelVendors.aID \r\n" +
//case 974 (case 58)
"LEFT OUTER JOIN aRegion ON aClient.aRegionID = aRegion.aID " +
sbIN.ToString();
dr = DBUtil.GetReaderFromSQLString(q);
}
else
{
string sCurrencySelect =
" (SELECT TOP 1 aSBANK.aCurrencyBalance FROM aServiceBank aSBANK " +
"WHERE aSBANK.AAPPLIESTOROOTOBJECTID = aChildUnits.aID " +
"ORDER BY aSBANK.aCreated DESC) ";
string sIncidentsSelect =
" (SELECT TOP 1 aSBANK.aIncidentsBalance " +
"FROM aServiceBank aSBANK WHERE " +
"aSBANK.AAPPLIESTOROOTOBJECTID = aChildUnits.aID ORDER " +
"BY aSBANK.aCreated DESC) ";
string sHoursSelect =
" (SELECT TOP 1 aSBANK.aHoursBalance " +
"FROM aServiceBank aSBANK WHERE aSBANK.AAPPLIESTOROOTOBJECTID " +
"= aChildUnits.aID ORDER " +
"BY aSBANK.aCreated DESC) ";
string sMeterSelect =
" (SELECT TOP 1 aMeter FROM aUnitMeterReading WHERE " +
"(aUnitMeterReading.aUnitID = aChildUnits.aID) " +
"ORDER BY aCreated DESC) ";
string where = AyaBizUtils.GetGridColumnCriteria(crit.CriteriaXML, true);
where = where.Replace("CURRENCYBAL", sCurrencySelect);
where = where.Replace("INCIDENTSBAL", sIncidentsSelect);
where = where.Replace("HOURSBAL", sHoursSelect);
where = where.Replace("aLASTMETERCOUNT", sMeterSelect);
string order = AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML);
//case 1184
//order = order.Replace("CURRENCYBAL", sCurrencySelect);
//order = order.Replace("INCIDENTSBAL", sIncidentsSelect);
//order = order.Replace("HOURSBAL", sHoursSelect);
//order = order.Replace("aLASTMETERCOUNT", sMeterSelect);
//Changed: 15-Sept-2006 to add UnitModelCategoryName
q = "SELECT ~MAXRECS~ aUnitModelCategory.aName as aUnitModelCategoryName, aUnitModel.aUnitModelCategoryID, " +
"aChildUnits.aID, aChildUnits.aSerial, aChildUnits.AACTIVE, " +
"aChildUnits.ATEXT1, aChildUnits.ATEXT2, aChildUnits.ATEXT3, aChildUnits.ATEXT4, " + //case 78
" aClient.aRegionID, aRegion.aName AS aRegionName, " + //case 974 (case 58)
" aChildUnits.aLastWorkorderID, aChildUnits.aLastServiceDate, aUnitModel.aModelNumber, " +
" aUnitModel.aName AS aUnitModelName, (SELECT TOP 1 aSBANK.aHoursBalance " +
"FROM aServiceBank aSBANK WHERE aSBANK.AAPPLIESTOROOTOBJECTID " +
"= aChildUnits.aID ORDER " +
"BY aSBANK.aCreated DESC) AS HOURSBAL, (SELECT TOP 1 aSBANK.aIncidentsBalance " +
"FROM aServiceBank aSBANK WHERE " +
"aSBANK.AAPPLIESTOROOTOBJECTID = aChildUnits.aID ORDER " +
"BY aSBANK.aCreated DESC) AS INCIDENTSBAL, (SELECT " +
"TOP 1 aSBANK.aCurrencyBalance FROM aServiceBank aSBANK " +
"WHERE aSBANK.AAPPLIESTOROOTOBJECTID = aChildUnits.aID " +
"ORDER BY aSBANK.aCreated DESC) AS CURRENCYBAL, " +
"(SELECT TOP 1 aMeter FROM aUnitMeterReading WHERE " +
"(aUnitMeterReading.aUnitID = aChildUnits.aID) " +
"ORDER BY aCreated DESC) AS aLASTMETERCOUNT, " +
" aChildUnits.aUnitModelID, aClient.aName " +
"AS aClientName, aChildUnits.aClientID, aChildUnits.aPurchasedDate, " +
" aChildUnits.aParentUnitID, " +
" aParentUnits.aSerial AS aParentUnitName, aWorkorderService.aServiceNumber, " +
" aChildUnits.aMetered, " +
" aChildUnits.aOverrideModelWarranty, aChildUnits.aWarrantyLength, " +
" aChildUnits.aLifeTimeWarranty, " +
"aChildUnits.aUnitHasOwnAddress, aChildUnits.aCustom1, " +
" aChildUnits.aCustom2, aChildUnits.aCustom3, aChildUnits.aCustom4, " +
" aChildUnits.aCustom5, aChildUnits.aCustom6, " +
" aChildUnits.aCustom7, aChildUnits.aCustom8, " +
" aChildUnits.aCustom9, aChildUnits.aCustom0, " +
//case 771
" aChildUnits.ABoughtHere, " +
//Case 427
" AChildUnits.APurchasedFromID AS ACHILDPURCHASEDFROMID, APurchaseFromVendors.AName AS APURCHASEVENDORNAME, " +
" aUnitModel.AVendorID AS AMODELVENDORID, AUnitModelVendors.AName AS AMODELVENDORNAME, " +
//Case 444
" AChildUnits.ADescription AS ACHILDDESCRIPTION, " +
" AADDRESS.aLatitude, AADDRESS.aLongitude, " +
" AADDRESS.aPostal, AADDRESS.aCountry, AADDRESS.aCountryCode, " +
" AADDRESS.aStateProv, AADDRESS.aCity, " +
" AADDRESS.aDeliveryAddress, aChildUnits.aWarrantyTerms, " +
" aChildUnits.aNotes, aChildUnits.aReceipt, " +
" aChildUnits.aUsesBanking FROM aUnit " +
"aChildUnits LEFT OUTER JOIN AADDRESS " +
"ON aChildUnits.aID = AADDRESS.aRootObjectID LEFT " +
"OUTER JOIN aWorkorderService ON aChildUnits.aLastWorkorderID " +
"= aWorkorderService.aWorkorderID " +
"LEFT OUTER JOIN aUnit aParentUnits ON aChildUnits.aParentUnitID " +
"= aParentUnits.aID LEFT OUTER " +
"JOIN aClient ON aChildUnits.aClientID = aClient.aID " +
"LEFT OUTER JOIN aUnitModel ON aChildUnits.aUnitModelID " +
"= aUnitModel.aID \r\n" +
//15-Sept-2006 testing to add UnitModelCategory
"LEFT OUTER JOIN aUnitModelCategory ON aUnitModel.aUnitModelCategoryID = aUnitModelCategory.aID \r\n" +
//Case 427
"LEFT OUTER JOIN AVendor APurchaseFromVendors ON aChildUnits.aPurchasedFromID = APurchaseFromVendors.aID \r\n" +
"LEFT OUTER JOIN AVendor AUnitModelVendors ON aUnitModel.AVendorID = AUnitModelVendors.aID \r\n" +
//case 974 (case 58)
"inner JOIN aRegion ON aClient.aRegionID = aRegion.aID " +
where + " \r\n " +
order;
if (crit.MaxRecords > 0)
q = q.Replace("~MAXRECS~", "TOP " + crit.MaxRecords.ToString());
else
q = q.Replace("~MAXRECS~", "");
q = DBUtil.AddRegionFilter(q, "", "");//case 974 (case 58)
dr = DBUtil.GetReaderFromSQLString(q);
}
//************************************************************
while (dr.Read())
{
//*******************************************
UnitListInfo info = new UnitListInfo();
info.mActive = dr.GetBoolean("AACTIVE");
info.mClient = new GridNameValueCellItem(dr.GetGuid("aClientID"), dr.GetString("aClientName"), RootObjectTypes.Client);
info.mPurchasedDate = DBUtil.ToLocal(dr.GetSmartDate("aPurchasedDate"));
info.mSerial = new GridNameValueCellItem(dr.GetGuid("aID"), dr.GetString("aSerial"), RootObjectTypes.Unit);
info.mUnitModel = new GridNameValueCellItem(
dr.GetGuid("aUnitModelID"),
AyaBizUtils.SS("", dr.GetString("aUnitModelName"), " ") + dr.GetString("aModelNumber"),
RootObjectTypes.UnitModel);
//case 1727
info.mUnitModelNumber = new GridNameValueCellItem(
dr.GetGuid("aUnitModelID"),
dr.GetString("aModelNumber"),
RootObjectTypes.UnitModel);
info.mUnitModelCategory = new GridNameValueCellItem(
dr.GetGuid("aUnitModelCategoryID"),
dr.GetString("aUnitModelCategoryName"),
RootObjectTypes.UnitModelCategory);
info.mParentUnit = new GridNameValueCellItem(dr.GetGuid("aParentUnitID"), dr.GetString("aParentUnitName"), RootObjectTypes.Unit);
info.mWorkorder = new GridNameValueCellItem(
dr.GetGuid("aLastWorkorderID"),
dr.GetInt32("aServiceNumber") == 0 ? "" : dr.GetInt32("aServiceNumber").ToString(),
RootObjectTypes.Workorder);
info.mServiceDate = DBUtil.ToLocal(dr.GetSmartDate("aLastServiceDate"));
info.mMetered = dr.GetBoolean("aMetered");
info.mOverrideModelWarranty = dr.GetBoolean("aOverrideModelWarranty");
info.mWarrantyLength = dr.GetInt32("aWarrantyLength");
info.mLifeTimeWarranty = dr.GetBoolean("aLifeTimeWarranty");
info.mUnitHasOwnAddress = dr.GetBoolean("aUnitHasOwnAddress");
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.mDeliveryAddress = dr.GetString("aDeliveryAddress");
info.mCity = dr.GetString("aCity");
info.mStateProv = dr.GetString("aStateProv");
info.mCountry = dr.GetString("aCountry");
info.mPostal = dr.GetString("aPostal");
info.mLatitude = Address.LatitudeToString(dr.GetDecimal("aLatitude"));
info.mLongitude = Address.LongitudeToString(dr.GetDecimal("aLongitude"));
info.mCountryCode = dr.GetString("aCountryCode");
info.mWarrantyTerms = dr.GetString("aWarrantyTerms");
info.mNotes = dr.GetString("aNotes");
info.mHoursBalance = dr.GetDecimal("HOURSBAL");
info.mIncidentsBalance = dr.GetDecimal("INCIDENTSBAL");
info.mCurrencyBalance = dr.GetDecimal("CURRENCYBAL");
info.mLastMeter = dr.GetInt64("aLASTMETERCOUNT");
//Added:3-Oct-2006
//was missing this bit so uses banking was
//always false in the grid and on reports
info.mUsesBanking = dr.GetBoolean("aUsesBanking");
//Case 427
info.mReceipt = dr.GetString("aReceipt");
info.mPurchaseFromID = new GridNameValueCellItem(
dr.GetGuid("ACHILDPURCHASEDFROMID"),
dr.GetString("APURCHASEVENDORNAME"),
RootObjectTypes.Vendor);
info.mModelVendorID = new GridNameValueCellItem(
dr.GetGuid("AMODELVENDORID"),
dr.GetString("AMODELVENDORNAME"),
RootObjectTypes.Vendor);
//Case 444
info.mDescription = dr.GetString("ACHILDDESCRIPTION");
//case 78
info.mText1 = dr.GetString("aText1");
info.mText2 = dr.GetString("aText2");
info.mText3 = dr.GetString("aText3");
info.mText4 = dr.GetString("aText4");
//Case 974 (Case 58)
info.mRegion = new GridNameValueCellItem(
dr.GetGuid("aRegionID"),
dr.GetString("aRegionName"),
RootObjectTypes.Region);
//case 771
info.mBoughtHere = dr.GetBoolean("aBoughtHere");
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 UnitList
#pragma warning restore 1591
}//end namespace GZTW.AyaNova.BLL