1026 lines
35 KiB
C#
1026 lines
35 KiB
C#
///////////////////////////////////////////////////////////
|
|
// ClientListDetailed.cs
|
|
// Implementation of Class ClientListDetailed
|
|
// CSLA type: Read only collection
|
|
// Created on: 27-Nov-2005
|
|
// Object design: Joyce
|
|
// Coded: 27-Nov-2005
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
using System;
|
|
using System.Data;
|
|
using GZTW.Data;
|
|
using CSLA.Data;
|
|
using CSLA;
|
|
using System.Threading;
|
|
using CSLA.Security;
|
|
using System.Collections.Generic;
|
|
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
#pragma warning disable 1591
|
|
|
|
|
|
/// <summary>
|
|
/// Read only detailed list of <see cref="ClientListDetailed.ClientListDetailedInfo"/> objects representing clients used for reporting, not UI
|
|
///
|
|
/// </summary>
|
|
[Serializable]
|
|
public class ClientListDetailed : ReadOnlyCollectionBase
|
|
{
|
|
|
|
|
|
#region Data structure
|
|
/// <summary>
|
|
/// Properties
|
|
/// </summary>
|
|
[Serializable]
|
|
public struct ClientListDetailedInfo
|
|
{
|
|
#region summary fields
|
|
internal GridNameValueCellItem mClient;
|
|
internal GridNameValueCellItem mHeadOffice;
|
|
internal GridNameValueCellItem mClientGroup;
|
|
internal GridNameValueCellItem mDispatchZone;
|
|
internal GridNameValueCellItem mRegion;
|
|
|
|
|
|
internal string mAccountNumber;
|
|
internal string mDeliveryAddress;
|
|
internal string mCity;
|
|
internal string mStateProv;
|
|
internal string mCountry;
|
|
internal string mPostal;
|
|
|
|
internal bool mActive;
|
|
|
|
internal string mWebAddress;
|
|
internal GridNameValueCellItem mWorkorder;
|
|
internal SmartDate mServiceDate;
|
|
|
|
internal bool mBillHeadOffice;
|
|
internal bool mUsesBanking;
|
|
|
|
|
|
internal GridNameValueCellItem mContract;
|
|
internal SmartDate mContractExpires;
|
|
internal string mLatitude;
|
|
internal string mLongitude;
|
|
internal string mCountryCode;
|
|
internal decimal mHoursBalance;
|
|
internal decimal mIncidentsBalance;
|
|
internal decimal mCurrencyBalance;
|
|
|
|
#endregion
|
|
|
|
#region Detailed fields
|
|
internal string mPDeliveryAddress;
|
|
internal string mPCity; //(these are all from postaladdress)
|
|
internal string mPStateProv;
|
|
internal string mPCountry;
|
|
internal string mPPostal;
|
|
|
|
//to be able to provide into reports
|
|
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;
|
|
|
|
internal string mTechNotes;
|
|
internal string mNotes;
|
|
internal string mPopUpNotes;
|
|
|
|
|
|
#endregion
|
|
|
|
#region Detail properties
|
|
public string LT_Address_Label_PostalDeliveryAddress
|
|
{get{return mPDeliveryAddress;}}
|
|
public string LT_Address_Label_PostalCity
|
|
{get{return mPCity;}}
|
|
public string LT_Address_Label_PostalStateProv
|
|
{get{return mPStateProv;}}
|
|
public string LT_Address_Label_PostalCountry
|
|
{get{return mPCountry;}}
|
|
public string LT_Address_Label_PostalPostal
|
|
{get{return mPPostal;}}
|
|
|
|
public string LT_Client_Label_Custom1
|
|
{get{return mCustom1;}}
|
|
|
|
public string LT_Client_Label_Custom2
|
|
{get{return mCustom2;}}
|
|
public string LT_Client_Label_Custom3
|
|
{get{return mCustom3;}}
|
|
public string LT_Client_Label_Custom4
|
|
{get{return mCustom4;}}
|
|
public string LT_Client_Label_Custom5
|
|
{get{return mCustom5;}}
|
|
public string LT_Client_Label_Custom6
|
|
{get{return mCustom6;}}
|
|
public string LT_Client_Label_Custom7
|
|
{get{return mCustom7;}}
|
|
public string LT_Client_Label_Custom8
|
|
{get{return mCustom8;}}
|
|
public string LT_Client_Label_Custom9
|
|
{get{return mCustom9;}}
|
|
public string LT_Client_Label_Custom0
|
|
{get{return mCustom0;}}
|
|
|
|
[SqlColumnNameAttribute("grid")]
|
|
public string LT_Client_Label_TechNotes
|
|
{get{return mTechNotes;}}
|
|
[SqlColumnNameAttribute("grid")]
|
|
public string LT_Client_Label_Notes
|
|
{get{return mNotes;}}
|
|
[SqlColumnNameAttribute("grid")]
|
|
public string LT_Client_Label_PopUpNotes
|
|
{get{return mPopUpNotes;}}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region Summary properties
|
|
[SqlColumnNameAttribute("aClient.aName", "aClient.aID")]
|
|
public GridNameValueCellItem LT_O_Client
|
|
{
|
|
get
|
|
{
|
|
return mClient;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("aHeadOffice.aName","aHeadOffice.aID")]
|
|
public GridNameValueCellItem LT_O_HeadOffice
|
|
{
|
|
get
|
|
{
|
|
return mHeadOffice;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("aRegion.aName",
|
|
"aRegion.aID")]
|
|
public GridNameValueCellItem LT_O_Region
|
|
{
|
|
get
|
|
{
|
|
return mRegion;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public string LT_Client_Label_AccountNumber
|
|
{
|
|
get
|
|
{
|
|
return mAccountNumber;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("aClientGroup.aName",
|
|
"aClientGroup.aID")]
|
|
public GridNameValueCellItem LT_O_ClientGroup
|
|
{
|
|
get
|
|
{
|
|
return mClientGroup;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("aDispatchZone.aName",
|
|
"aDispatchZone.aID")]
|
|
public GridNameValueCellItem LT_O_DispatchZone
|
|
{
|
|
get
|
|
{
|
|
return mDispatchZone;
|
|
}
|
|
}
|
|
|
|
public string LT_Address_Label_DeliveryAddress
|
|
{
|
|
get
|
|
{
|
|
return mDeliveryAddress;
|
|
}
|
|
}
|
|
|
|
public string LT_Address_Label_City
|
|
{
|
|
get
|
|
{
|
|
return mCity;
|
|
}
|
|
}
|
|
public string LT_Address_Label_StateProv
|
|
{
|
|
get
|
|
{
|
|
return mStateProv;
|
|
}
|
|
}
|
|
public string LT_Address_Label_Country
|
|
{
|
|
get
|
|
{
|
|
return mCountry;
|
|
}
|
|
}
|
|
public string LT_Address_Label_Postal
|
|
{
|
|
get
|
|
{
|
|
return mPostal;
|
|
}
|
|
}
|
|
|
|
public bool LT_Client_Label_Active
|
|
{
|
|
get
|
|
{
|
|
return mActive;
|
|
}
|
|
}
|
|
|
|
public string LT_Client_Label_WebAddress
|
|
{
|
|
get
|
|
{
|
|
return mWebAddress;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("aWorkorderService.aServiceNumber",
|
|
"aClient.aLastWorkorderID")]
|
|
public GridNameValueCellItem LT_UI_Label_LastWorkorder
|
|
{
|
|
get
|
|
{
|
|
return mWorkorder;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("aClient.aLastServiceDate")]
|
|
public object LT_UI_Label_LastServiceDate
|
|
{
|
|
get
|
|
{
|
|
return mServiceDate.DBValue;
|
|
}
|
|
}
|
|
|
|
public bool LT_Client_Label_UsesBanking
|
|
{
|
|
get
|
|
{
|
|
return mUsesBanking;
|
|
}
|
|
}
|
|
|
|
public bool LT_Client_Label_BillHeadOffice
|
|
{
|
|
get
|
|
{
|
|
return this.mBillHeadOffice;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("aContract.aName",
|
|
"aClient.aContractID")]
|
|
public GridNameValueCellItem LT_O_Contract
|
|
{
|
|
get
|
|
{
|
|
return mContract;
|
|
}
|
|
}
|
|
|
|
|
|
[SqlColumnNameAttribute("aClient.aContractExpires")]
|
|
public object LT_Client_Label_ContractExpires
|
|
{
|
|
get
|
|
{
|
|
return mContractExpires.DBValue;
|
|
}
|
|
}
|
|
|
|
public string LT_Address_Label_Latitude
|
|
{
|
|
get
|
|
{
|
|
return mLatitude;
|
|
}
|
|
}
|
|
|
|
public string LT_Address_Label_Longitude
|
|
{
|
|
get
|
|
{
|
|
return mLongitude;
|
|
}
|
|
}
|
|
|
|
public string LT_Address_Label_CountryCode
|
|
{
|
|
get
|
|
{
|
|
return mCountryCode;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("HOURSBAL")]
|
|
public decimal LT_ServiceBank_Label_HoursBalance
|
|
{
|
|
get
|
|
{
|
|
return mHoursBalance;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("INCIDENTSBAL")]
|
|
public decimal LT_ServiceBank_Label_IncidentsBalance
|
|
{
|
|
get
|
|
{
|
|
return mIncidentsBalance;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("CURRENCYBAL")]
|
|
public decimal LT_ServiceBank_Label_CurrencyBalance
|
|
{
|
|
get
|
|
{
|
|
return mCurrencyBalance;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region Contact fields and properties
|
|
//CONTACT FIELDS
|
|
internal string mContact;
|
|
internal string mEmail;
|
|
internal string mPhone1;
|
|
internal string mPhone2;
|
|
internal string mPhone3;
|
|
internal string mPhone4;
|
|
internal string mPhone5;
|
|
internal string mContactNotes;
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_Client_Label_Contact
|
|
{ get { return mContact; } }
|
|
|
|
[Display(DisplayType.URL_Email)]
|
|
public string LT_Client_Label_Email
|
|
{ get { return mEmail; } }
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_Client_Label_Phone1
|
|
{ get { return mPhone1; } }
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_Client_Label_Phone2
|
|
{ get { return mPhone2; } }
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_Client_Label_Phone3
|
|
{ get { return mPhone3; } }
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_Client_Label_Phone4
|
|
{ get { return mPhone4; } }
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_Client_Label_Phone5
|
|
{ get { return mPhone5; } }
|
|
|
|
[Display(DisplayType.MultiLineText)]
|
|
public string LT_Client_Label_ContactNotes
|
|
{ get { return mContactNotes; } }
|
|
|
|
|
|
#endregion
|
|
//=======================================================================
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Equals(ClientListDetailedInfo obj)
|
|
{
|
|
return this.mClient.Value.Equals(obj.mClient.Value);
|
|
}
|
|
|
|
}//end ClientListDetailedInfo
|
|
#endregion
|
|
|
|
#region Constructor
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
protected ClientListDetailed()
|
|
{
|
|
// 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 ClientListDetailedInfo this[int Item]
|
|
{
|
|
|
|
get
|
|
{
|
|
return (ClientListDetailedInfo) List[Item];
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Returns display text that matches passed in itemid value
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
public string this[Guid ItemID]
|
|
{
|
|
|
|
get
|
|
{
|
|
foreach (ClientListDetailedInfo child in List)
|
|
{
|
|
if(child.mClient.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(ClientListDetailedInfo obj)
|
|
{
|
|
foreach (ClientListDetailedInfo child in List)
|
|
{
|
|
if(child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Reporting
|
|
|
|
/// <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 "ClientListDetailed";
|
|
}
|
|
}
|
|
|
|
/// <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
|
|
{
|
|
//returns the id field used for presentation in the grid
|
|
return ClientList.IDField;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Same as IDField but for detailed reports
|
|
/// </summary>
|
|
public static string IDFieldDetailed
|
|
{
|
|
get
|
|
{
|
|
return ClientList.IDField;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
|
|
/// <summary>
|
|
/// Internal method used by list factory
|
|
/// </summary>
|
|
internal static ClientListDetailed Get(string Filter, int MaxRecords, List<Guid> IDList)
|
|
{
|
|
return (ClientListDetailed)DataPortal.Fetch(new Criteria(Filter, IDList, MaxRecords));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Takes an xml column list and where criteria
|
|
/// and returns a list filtered and sorted accordingly
|
|
/// </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="ClientListDetailed.ClientListDetailedInfo"/> objects</returns>
|
|
public static ClientListDetailed GetListByCriteria(string xmlCriteria)
|
|
{
|
|
return (ClientListDetailed) DataPortal.Fetch(new Criteria(xmlCriteria,null,-1));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Takes a single ID and returns a "list" of one object
|
|
/// </summary>
|
|
/// <param name="ClientID">ID of object</param>
|
|
public static ClientListDetailed GetListForSingleItem(Guid ClientID)
|
|
{
|
|
//Case 556
|
|
List<Guid> l = new List<Guid>();
|
|
l.Add(ClientID);
|
|
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="ClientListDetailed.ClientListDetailedInfo"/> objects</returns>
|
|
public static ClientListDetailed GetListFromIDList(List<Guid> IDList)
|
|
{
|
|
//case 556
|
|
//Handle empty list
|
|
if (IDList.Count == 0)
|
|
return new ClientListDetailed();
|
|
return (ClientListDetailed)DataPortal.Fetch(new Criteria("", IDList, -1));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Return an empty list
|
|
/// used for initializing grid
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static ClientListDetailed GetEmptyList()
|
|
{
|
|
return new ClientListDetailed();
|
|
}
|
|
|
|
|
|
#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;
|
|
if (crit.IDList != null)
|
|
{
|
|
//Case 556
|
|
System.Text.StringBuilder sbIN = new System.Text.StringBuilder();
|
|
sbIN.Append(" AND (aClient.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(")) ");
|
|
|
|
|
|
|
|
|
|
string q =
|
|
"SELECT ACLIENT.aID, ACLIENT.aName, ACLIENT.aModified, " +
|
|
" ACLIENT.AACTIVE, ACLIENT.aUsesBanking, " +
|
|
" ACLIENT.aBillHeadOffice, ACLIENT.aWebAddress, " +
|
|
" ACLIENT.aDispatchZoneID, ACLIENT.aClientGroupID, " +
|
|
" ACLIENT.aLastWorkorderID, " +
|
|
" ACLIENT.aLastServiceDate, (SELECT TOP 1 aSBANK.aHoursBalance " +
|
|
"FROM aServiceBank aSBANK WHERE aSBANK.AAPPLIESTOROOTOBJECTID " +
|
|
"= ACLIENT.aID ORDER " +
|
|
"BY aSBANK.aCreated DESC) AS HOURSBAL, (SELECT TOP " +
|
|
"1 aSBANK.aIncidentsBalance FROM aServiceBank aSBANK " +
|
|
"WHERE aSBANK.AAPPLIESTOROOTOBJECTID = ACLIENT.aID " +
|
|
"ORDER BY aSBANK.aCreated DESC) AS INCIDENTSBAL, " +
|
|
" (SELECT TOP 1 aSBANK.aCurrencyBalance FROM " +
|
|
"aServiceBank aSBANK WHERE aSBANK.AAPPLIESTOROOTOBJECTID " +
|
|
"= ACLIENT.aID ORDER BY aSBANK.aCreated DESC) " +
|
|
"AS CURRENCYBAL, " +
|
|
" ACLIENT.AACCOUNTNUMBER, aHeadOffice.aName " +
|
|
"AS aHeadOfficeName, aHeadOffice.aID " +
|
|
"AS aHeadOfficeID, aDispatchZone.aName AS aDispatchZoneName, " +
|
|
" ACLIENT.aRegionID, aRegion.aName " +
|
|
"AS aRegionName, aClientGroup.aName AS " +
|
|
"aClientGroupName, aPHYSICAL.aDeliveryAddress, " +
|
|
"aPHYSICAL.aCity, aPHYSICAL.aStateProv, aPHYSICAL.aCountry, " +
|
|
" aPHYSICAL.aPostal, aPHYSICAL.AADDRESSTYPE, " +
|
|
" aPHYSICAL.aLongitude, aPHYSICAL.aLatitude, " +
|
|
" aWorkorderService.aServiceNumber, " +
|
|
" ACLIENT.aContractID, aContract.aName AS " +
|
|
"aContractName, ACLIENT.aContractExpires, aPHYSICAL.aCountryCode, " +
|
|
" aPOSTAL.AADDRESSTYPE AS aPAddressType, " +
|
|
" aPOSTAL.aDeliveryAddress AS aPDeliveryAddress, " +
|
|
" aPOSTAL.aCity AS aPCity, aPOSTAL.aStateProv " +
|
|
"AS aPStateProv, aPOSTAL.aCountryCode AS aPCountryCode, " +
|
|
" aPOSTAL.aCountry AS aPCountry, aPOSTAL.aPostal " +
|
|
"AS aPPostal, ACLIENT.aCustom1, ACLIENT.aCustom2, " +
|
|
" ACLIENT.aCustom3, ACLIENT.aCustom4, " +
|
|
" ACLIENT.aCustom5, ACLIENT.aCustom6, " +
|
|
" ACLIENT.aCustom7, ACLIENT.aCustom8, ACLIENT.aCustom9, " +
|
|
" ACLIENT.aCustom0, ACLIENT.aTechNotes, " +
|
|
" ACLIENT.aNotes, ACLIENT.aPopUpNotes, " +
|
|
" ACLIENT.ACONTACT, ACLIENT.AEMAIL, ACLIENT.APHONE1, ACLIENT.APHONE2, ACLIENT.APHONE3, ACLIENT.APHONE4, ACLIENT.APHONE5, ACLIENT.ACONTACTNOTES " +
|
|
|
|
|
|
"FROM " +
|
|
" ACLIENT " +
|
|
" LEFT OUTER JOIN ADISPATCHZONE ON (ACLIENT.ADISPATCHZONEID=ADISPATCHZONE.AID) " +
|
|
" LEFT OUTER JOIN ACLIENTGROUP ON (ACLIENT.ACLIENTGROUPID=ACLIENTGROUP.AID) " +
|
|
" LEFT OUTER JOIN AADDRESS aPHYSICAL ON (ACLIENT.AID=aPHYSICAL.AROOTOBJECTID) " +
|
|
" LEFT OUTER JOIN AADDRESS aPOSTAL ON (ACLIENT.AID=aPOSTAL.AROOTOBJECTID) " +
|
|
" LEFT OUTER JOIN ACONTRACT ON (ACLIENT.ACONTRACTID=ACONTRACT.AID) " +
|
|
" LEFT OUTER JOIN AHEADOFFICE ON (ACLIENT.AHEADOFFICEID=AHEADOFFICE.AID) " +
|
|
" LEFT OUTER JOIN AWORKORDERSERVICE ON (ACLIENT.ALASTWORKORDERID=AWORKORDERSERVICE.AWORKORDERID) " +
|
|
" LEFT OUTER JOIN AREGION ON (ACLIENT.AREGIONID=AREGION.AID) " +
|
|
|
|
"WHERE (aPHYSICAL.AADDRESSTYPE " +
|
|
"IS NULL OR aPHYSICAL.AADDRESSTYPE " +
|
|
"= 2) AND (aPOSTAL.AADDRESSTYPE IS NULL OR aPOSTAL.AADDRESSTYPE " +
|
|
"= 1) " + sbIN.ToString() + " ORDER BY ACLIENT.ANAME ";
|
|
|
|
|
|
|
|
cm = DBUtil.DB.GetSqlStringCommandWrapper(q);
|
|
|
|
}
|
|
else
|
|
{
|
|
string sCurrencySelect=
|
|
" (SELECT TOP 1 aSBANK.aCurrencyBalance FROM aServiceBank aSBANK " +
|
|
"WHERE aSBANK.AAPPLIESTOROOTOBJECTID = ACLIENT.aID " +
|
|
"ORDER BY aSBANK.aCreated DESC) ";
|
|
string sIncidentsSelect=
|
|
" (SELECT TOP 1 aSBANK.aIncidentsBalance FROM aServiceBank aSBANK " +
|
|
"WHERE aSBANK.AAPPLIESTOROOTOBJECTID = ACLIENT.aID " +
|
|
"ORDER BY aSBANK.aCreated DESC) ";
|
|
string sHoursSelect=
|
|
" (SELECT TOP 1 aSBANK.aHoursBalance FROM aServiceBank aSBANK " +
|
|
"WHERE aSBANK.AAPPLIESTOROOTOBJECTID = ACLIENT.aID " +
|
|
"ORDER BY aSBANK.aCreated DESC) ";
|
|
|
|
string where=AyaBizUtils.GetGridColumnCriteria(crit.CriteriaXML,false);
|
|
where=where.Replace("CURRENCYBAL",sCurrencySelect);
|
|
where=where.Replace("INCIDENTSBAL",sIncidentsSelect);
|
|
where=where.Replace("HOURSBAL",sHoursSelect);
|
|
//In the clientList where the criteria comes from
|
|
//there is only one address and it's not aliased
|
|
//but it's the physical one, so to make this work
|
|
//we replace AADDRESS with aPHYSICAL to match the
|
|
//aliased name in this query so that the criteria from the
|
|
//ClientList will match the column names in the ClientListDetailed
|
|
where=where.Replace("AADDRESS","aPHYSICAL");
|
|
|
|
string order=AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML);
|
|
//case 1184
|
|
//order=order.Replace("CURRENCYBAL",sCurrencySelect);
|
|
//order=order.Replace("INCIDENTSBAL",sIncidentsSelect);
|
|
//order=order.Replace("HOURSBAL",sHoursSelect);
|
|
|
|
//In the clientList where the criteria comes from
|
|
//there is only one address and it's not aliased
|
|
//but it's the physical one, so to make this work
|
|
//we replace AADDRESS with aPHYSICAL to match the
|
|
//aliased name in this query so that the criteria from the
|
|
//ClientList will match the column names in the ClientListDetailed
|
|
order=order.Replace("AADDRESS","aPHYSICAL");
|
|
|
|
|
|
|
|
string q =
|
|
"SELECT ~MAXRECS~ ACLIENT.aID, ACLIENT.aName, ACLIENT.aModified, " +
|
|
" ACLIENT.AACTIVE, ACLIENT.aUsesBanking, " +
|
|
" ACLIENT.aBillHeadOffice, ACLIENT.aWebAddress, " +
|
|
" ACLIENT.aDispatchZoneID, ACLIENT.aClientGroupID, " +
|
|
" ACLIENT.aLastWorkorderID, " +
|
|
" ACLIENT.aLastServiceDate, (SELECT TOP 1 aSBANK.aHoursBalance " +
|
|
"FROM aServiceBank aSBANK WHERE aSBANK.AAPPLIESTOROOTOBJECTID " +
|
|
"= ACLIENT.aID ORDER " +
|
|
"BY aSBANK.aCreated DESC) AS HOURSBAL, (SELECT TOP " +
|
|
"1 aSBANK.aIncidentsBalance FROM aServiceBank aSBANK " +
|
|
"WHERE aSBANK.AAPPLIESTOROOTOBJECTID = ACLIENT.aID " +
|
|
"ORDER BY aSBANK.aCreated DESC) AS INCIDENTSBAL, " +
|
|
" (SELECT TOP 1 aSBANK.aCurrencyBalance FROM " +
|
|
"aServiceBank aSBANK WHERE aSBANK.AAPPLIESTOROOTOBJECTID " +
|
|
"= ACLIENT.aID ORDER BY aSBANK.aCreated DESC) " +
|
|
"AS CURRENCYBAL, " +
|
|
" ACLIENT.AACCOUNTNUMBER, aHeadOffice.aName " +
|
|
"AS aHeadOfficeName, aHeadOffice.aID " +
|
|
"AS aHeadOfficeID, aDispatchZone.aName AS aDispatchZoneName, " +
|
|
" ACLIENT.aRegionID, aRegion.aName " +
|
|
"AS aRegionName, aClientGroup.aName AS " +
|
|
"aClientGroupName, aPHYSICAL.aDeliveryAddress, " +
|
|
"aPHYSICAL.aCity, aPHYSICAL.aStateProv, aPHYSICAL.aCountry, " +
|
|
" aPHYSICAL.aPostal, aPHYSICAL.AADDRESSTYPE, " +
|
|
" aPHYSICAL.aLongitude, aPHYSICAL.aLatitude, " +
|
|
" aWorkorderService.aServiceNumber, " +
|
|
" ACLIENT.aContractID, aContract.aName AS " +
|
|
"aContractName, ACLIENT.aContractExpires, aPHYSICAL.aCountryCode, " +
|
|
" aPOSTAL.AADDRESSTYPE AS aPAddressType, " +
|
|
" aPOSTAL.aDeliveryAddress AS aPDeliveryAddress, " +
|
|
" aPOSTAL.aCity AS aPCity, aPOSTAL.aStateProv " +
|
|
"AS aPStateProv, aPOSTAL.aCountryCode AS aPCountryCode, " +
|
|
" aPOSTAL.aCountry AS aPCountry, aPOSTAL.aPostal " +
|
|
"AS aPPostal, ACLIENT.aCustom1, ACLIENT.aCustom2, " +
|
|
" ACLIENT.aCustom3, ACLIENT.aCustom4, " +
|
|
" ACLIENT.aCustom5, ACLIENT.aCustom6, " +
|
|
" ACLIENT.aCustom7, ACLIENT.aCustom8, ACLIENT.aCustom9, " +
|
|
" ACLIENT.aCustom0, ACLIENT.aTechNotes, " +
|
|
" ACLIENT.aNotes, ACLIENT.aPopUpNotes, " +
|
|
" ACLIENT.ACONTACT, ACLIENT.AEMAIL, ACLIENT.APHONE1, ACLIENT.APHONE2, ACLIENT.APHONE3, ACLIENT.APHONE4, ACLIENT.APHONE5, ACLIENT.ACONTACTNOTES " +
|
|
|
|
|
|
|
|
"FROM " +
|
|
" ACLIENT ACLIENT " +
|
|
" LEFT OUTER JOIN ADISPATCHZONE ON (ACLIENT.ADISPATCHZONEID=ADISPATCHZONE.AID) " +
|
|
" LEFT OUTER JOIN ACLIENTGROUP ON (ACLIENT.ACLIENTGROUPID=ACLIENTGROUP.AID) " +
|
|
" LEFT OUTER JOIN AADDRESS aPHYSICAL ON (ACLIENT.AID=aPHYSICAL.AROOTOBJECTID) " +
|
|
" LEFT OUTER JOIN AADDRESS aPOSTAL ON (ACLIENT.AID=aPOSTAL.AROOTOBJECTID) " +
|
|
" LEFT OUTER JOIN ACONTRACT ON (ACLIENT.ACONTRACTID=ACONTRACT.AID) " +
|
|
" LEFT OUTER JOIN AHEADOFFICE ON (ACLIENT.AHEADOFFICEID=AHEADOFFICE.AID) " +
|
|
" LEFT OUTER JOIN AWORKORDERSERVICE ON (ACLIENT.ALASTWORKORDERID=AWORKORDERSERVICE.AWORKORDERID) " +
|
|
" LEFT OUTER JOIN AREGION ON (ACLIENT.AREGIONID=AREGION.AID) " +
|
|
|
|
"WHERE (aPHYSICAL.AADDRESSTYPE " +
|
|
"IS NULL OR aPHYSICAL.AADDRESSTYPE " +
|
|
"= 2) AND (aPOSTAL.AADDRESSTYPE IS NULL OR aPOSTAL.AADDRESSTYPE " +
|
|
"= 1) \r\n ";
|
|
|
|
//Can't use regular addregion because of subqueries so just insert it here
|
|
q = q + DBUtil.RegionAClientClause;//case 58
|
|
|
|
q = q + where + " \r\n ";
|
|
|
|
|
|
|
|
q = q + order;
|
|
|
|
if (crit.MaxRecords > 0)
|
|
q = q.Replace("~MAXRECS~", "TOP " + crit.MaxRecords.ToString());
|
|
else
|
|
q = q.Replace("~MAXRECS~", "");
|
|
|
|
cm = DBUtil.DB.GetSqlStringCommandWrapper(q);
|
|
}
|
|
cm.AddInParameter("@TRUE",DbType.Boolean,true);
|
|
dr=new SafeDataReader(DBUtil.DB.ExecuteReader(cm));
|
|
|
|
#region GetOrdinals
|
|
//case 1298
|
|
int AID = dr.GetOrdinal("AID");
|
|
int ANAME = dr.GetOrdinal("ANAME");
|
|
int AHEADOFFICEID = dr.GetOrdinal("AHEADOFFICEID");
|
|
int AHEADOFFICENAME = dr.GetOrdinal("AHEADOFFICENAME");
|
|
int ADISPATCHZONEID = dr.GetOrdinal("ADISPATCHZONEID");
|
|
int ADISPATCHZONENAME = dr.GetOrdinal("ADISPATCHZONENAME");
|
|
int ACLIENTGROUPID = dr.GetOrdinal("ACLIENTGROUPID");
|
|
int ACLIENTGROUPNAME = dr.GetOrdinal("ACLIENTGROUPNAME");
|
|
int AREGIONID = dr.GetOrdinal("AREGIONID");
|
|
int AREGIONNAME = dr.GetOrdinal("AREGIONNAME");
|
|
int ALASTWORKORDERID = dr.GetOrdinal("ALASTWORKORDERID");
|
|
int ASERVICENUMBER = dr.GetOrdinal("ASERVICENUMBER");
|
|
int ALASTSERVICEDATE = dr.GetOrdinal("ALASTSERVICEDATE");
|
|
int ACONTACT = dr.GetOrdinal("ACONTACT");
|
|
int AEMAIL = dr.GetOrdinal("AEMAIL");
|
|
int APHONE1 = dr.GetOrdinal("APHONE1");
|
|
int APHONE2 = dr.GetOrdinal("APHONE2");
|
|
int APHONE3 = dr.GetOrdinal("APHONE3");
|
|
int APHONE4 = dr.GetOrdinal("APHONE4");
|
|
int APHONE5 = dr.GetOrdinal("APHONE5");
|
|
int ACONTACTNOTES = dr.GetOrdinal("ACONTACTNOTES");
|
|
int AACCOUNTNUMBER = dr.GetOrdinal("AACCOUNTNUMBER");
|
|
int ADELIVERYADDRESS = dr.GetOrdinal("ADELIVERYADDRESS");
|
|
int ACITY = dr.GetOrdinal("ACITY");
|
|
int ASTATEPROV = dr.GetOrdinal("ASTATEPROV");
|
|
int ACOUNTRY = dr.GetOrdinal("ACOUNTRY");
|
|
int APOSTAL = dr.GetOrdinal("APOSTAL");
|
|
int AACTIVE = dr.GetOrdinal("AACTIVE");
|
|
int AWEBADDRESS = dr.GetOrdinal("AWEBADDRESS");
|
|
int AUSESBANKING = dr.GetOrdinal("AUSESBANKING");
|
|
int ABILLHEADOFFICE = dr.GetOrdinal("ABILLHEADOFFICE");
|
|
int ACONTRACTID = dr.GetOrdinal("ACONTRACTID");
|
|
int ACONTRACTNAME = dr.GetOrdinal("ACONTRACTNAME");
|
|
int ACONTRACTEXPIRES = dr.GetOrdinal("ACONTRACTEXPIRES");
|
|
int ALATITUDE = dr.GetOrdinal("ALATITUDE");
|
|
int ALONGITUDE = dr.GetOrdinal("ALONGITUDE");
|
|
int ACOUNTRYCODE = dr.GetOrdinal("ACOUNTRYCODE");
|
|
int HOURSBAL = dr.GetOrdinal("HOURSBAL");
|
|
int INCIDENTSBAL = dr.GetOrdinal("INCIDENTSBAL");
|
|
int CURRENCYBAL = dr.GetOrdinal("CURRENCYBAL");
|
|
int APDELIVERYADDRESS = dr.GetOrdinal("APDELIVERYADDRESS");
|
|
int APCITY = dr.GetOrdinal("APCITY");
|
|
int APSTATEPROV = dr.GetOrdinal("APSTATEPROV");
|
|
int APCOUNTRY = dr.GetOrdinal("APCOUNTRY");
|
|
int APPOSTAL = dr.GetOrdinal("APPOSTAL");
|
|
int ACUSTOM1 = dr.GetOrdinal("ACUSTOM1");
|
|
int ACUSTOM2 = dr.GetOrdinal("ACUSTOM2");
|
|
int ACUSTOM3 = dr.GetOrdinal("ACUSTOM3");
|
|
int ACUSTOM4 = dr.GetOrdinal("ACUSTOM4");
|
|
int ACUSTOM5 = dr.GetOrdinal("ACUSTOM5");
|
|
int ACUSTOM6 = dr.GetOrdinal("ACUSTOM6");
|
|
int ACUSTOM7 = dr.GetOrdinal("ACUSTOM7");
|
|
int ACUSTOM8 = dr.GetOrdinal("ACUSTOM8");
|
|
int ACUSTOM9 = dr.GetOrdinal("ACUSTOM9");
|
|
int ACUSTOM0 = dr.GetOrdinal("ACUSTOM0");
|
|
int ATECHNOTES = dr.GetOrdinal("ATECHNOTES");
|
|
int ANOTES = dr.GetOrdinal("ANOTES");
|
|
int APOPUPNOTES = dr.GetOrdinal("APOPUPNOTES");
|
|
//int XXX = dr.GetOrdinal("XXX");
|
|
// int XXX = dr.GetOrdinal("XXX");
|
|
#endregion getordinals
|
|
|
|
//System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
|
|
//sw.Start();
|
|
|
|
while (dr.Read())
|
|
{
|
|
ClientListDetailedInfo info=new ClientListDetailedInfo();
|
|
|
|
info.mClient=new GridNameValueCellItem(
|
|
dr.GetGuid(AID),
|
|
dr.GetString(ANAME),
|
|
RootObjectTypes.Client);
|
|
|
|
info.mHeadOffice=new GridNameValueCellItem(
|
|
dr.GetGuid(AHEADOFFICEID),
|
|
dr.GetString(AHEADOFFICENAME),
|
|
RootObjectTypes.HeadOffice);
|
|
|
|
info.mDispatchZone = new GridNameValueCellItem(
|
|
dr.GetGuid(ADISPATCHZONEID),
|
|
dr.GetString(ADISPATCHZONENAME),
|
|
RootObjectTypes.DispatchZone);
|
|
|
|
info.mClientGroup = new GridNameValueCellItem(
|
|
dr.GetGuid(ACLIENTGROUPID),
|
|
dr.GetString(ACLIENTGROUPNAME),
|
|
RootObjectTypes.ClientGroup);
|
|
|
|
info.mRegion = new GridNameValueCellItem(
|
|
dr.GetGuid(AREGIONID),
|
|
dr.GetString(AREGIONNAME),
|
|
RootObjectTypes.Region);
|
|
|
|
|
|
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.mContact = dr.GetString(ACONTACT);
|
|
info.mEmail = dr.GetString(AEMAIL);
|
|
info.mPhone1 = dr.GetString(APHONE1);
|
|
info.mPhone2 = dr.GetString(APHONE2);
|
|
info.mPhone3 = dr.GetString(APHONE3);
|
|
info.mPhone4 = dr.GetString(APHONE4);
|
|
info.mPhone5 = dr.GetString(APHONE5);
|
|
info.mContactNotes = dr.GetString(ACONTACTNOTES);
|
|
|
|
info.mAccountNumber = dr.GetString(AACCOUNTNUMBER);
|
|
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.mActive = dr.GetBoolean(AACTIVE);
|
|
info.mWebAddress = dr.GetString(AWEBADDRESS);
|
|
|
|
info.mUsesBanking = dr.GetBoolean(AUSESBANKING);
|
|
info.mBillHeadOffice = dr.GetBoolean(ABILLHEADOFFICE);
|
|
|
|
info.mContract = new GridNameValueCellItem(
|
|
dr.GetGuid(ACONTRACTID),
|
|
dr.GetString(ACONTRACTNAME),
|
|
RootObjectTypes.Contract);
|
|
|
|
info.mContractExpires = DBUtil.ToLocal(dr.GetSmartDate(ACONTRACTEXPIRES));
|
|
|
|
info.mLatitude = Address.LatitudeToString(dr.GetDecimal(ALATITUDE));
|
|
info.mLongitude = Address.LongitudeToString(dr.GetDecimal(ALONGITUDE));
|
|
info.mCountryCode = dr.GetString(ACOUNTRYCODE);
|
|
info.mHoursBalance = dr.GetDecimal(HOURSBAL);
|
|
info.mIncidentsBalance = dr.GetDecimal(INCIDENTSBAL);
|
|
info.mCurrencyBalance = dr.GetDecimal(CURRENCYBAL);
|
|
|
|
//------- Detailed fields ----------------
|
|
info.mPDeliveryAddress = dr.GetString(APDELIVERYADDRESS);
|
|
info.mPCity = dr.GetString(APCITY);
|
|
info.mPStateProv = dr.GetString(APSTATEPROV);
|
|
info.mPCountry = dr.GetString(APCOUNTRY);
|
|
info.mPPostal = dr.GetString(APPOSTAL);
|
|
|
|
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.mCustom0=dr.GetString(ACUSTOM0);
|
|
|
|
info.mTechNotes=dr.GetString(ATECHNOTES);
|
|
info.mNotes=dr.GetString(ANOTES);
|
|
info.mPopUpNotes=dr.GetString(APOPUPNOTES);
|
|
|
|
|
|
//-------------------------------------------------
|
|
|
|
InnerList.Add(info);
|
|
|
|
}
|
|
|
|
//sw.Stop();
|
|
//string selapsed = sw.Elapsed.ToString();
|
|
|
|
}
|
|
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 ClientListDetailed
|
|
|
|
#pragma warning restore 1591
|
|
}//end namespace GZTW.AyaNova.BLL |