857 lines
26 KiB
C#
857 lines
26 KiB
C#
///////////////////////////////////////////////////////////
|
|
// HeadOfficeListDetailed.cs
|
|
// Implementation of Class HeadOfficeListDetailed
|
|
// 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="HeadOfficeListDetailed.HeadOfficeListDetailedInfo"/> objects representing HeadOffices used for reporting, not UI
|
|
///
|
|
///
|
|
/// </summary>
|
|
[Serializable]
|
|
public class HeadOfficeListDetailed : ReadOnlyCollectionBase
|
|
{
|
|
|
|
|
|
#region Data structure
|
|
/// <summary>
|
|
/// Properties
|
|
/// </summary>
|
|
[Serializable]
|
|
public struct HeadOfficeListDetailedInfo
|
|
{
|
|
#region summary fields
|
|
internal GridNameValueCellItem mHeadOffice;
|
|
internal GridNameValueCellItem mClientGroup;
|
|
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 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 mNotes;
|
|
|
|
|
|
#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_HeadOffice_Label_Custom1
|
|
{get{return mCustom1;}}
|
|
public string LT_HeadOffice_Label_Custom2
|
|
{get{return mCustom2;}}
|
|
public string LT_HeadOffice_Label_Custom3
|
|
{get{return mCustom3;}}
|
|
public string LT_HeadOffice_Label_Custom4
|
|
{get{return mCustom4;}}
|
|
public string LT_HeadOffice_Label_Custom5
|
|
{get{return mCustom5;}}
|
|
public string LT_HeadOffice_Label_Custom6
|
|
{get{return mCustom6;}}
|
|
public string LT_HeadOffice_Label_Custom7
|
|
{get{return mCustom7;}}
|
|
public string LT_HeadOffice_Label_Custom8
|
|
{get{return mCustom8;}}
|
|
public string LT_HeadOffice_Label_Custom9
|
|
{get{return mCustom9;}}
|
|
public string LT_HeadOffice_Label_Custom0
|
|
{get{return mCustom0;}}
|
|
|
|
[SqlColumnNameAttribute("grid")]
|
|
public string LT_HeadOffice_Label_Notes
|
|
{get{return mNotes;}}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region Summary properties
|
|
[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_HeadOffice_Label_AccountNumber
|
|
{
|
|
get
|
|
{
|
|
return mAccountNumber;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("aClientGroup.aName",
|
|
"aClientGroup.aID")]
|
|
public GridNameValueCellItem LT_O_ClientGroup
|
|
{
|
|
get
|
|
{
|
|
return mClientGroup;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
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_HeadOffice_Label_Active
|
|
{
|
|
get
|
|
{
|
|
return mActive;
|
|
}
|
|
}
|
|
|
|
public string LT_HeadOffice_Label_WebAddress
|
|
{
|
|
get
|
|
{
|
|
return mWebAddress;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public bool LT_HeadOffice_Label_UsesBanking
|
|
{
|
|
get
|
|
{
|
|
return mUsesBanking;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
[SqlColumnNameAttribute("aContract.aName",
|
|
"aHeadOffice.aContractID")]
|
|
public GridNameValueCellItem LT_O_Contract
|
|
{
|
|
get
|
|
{
|
|
return mContract;
|
|
}
|
|
}
|
|
|
|
|
|
[SqlColumnNameAttribute("aHeadOffice.aContractExpires")]
|
|
public object LT_HeadOffice_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
|
|
//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_HeadOffice_Label_Contact
|
|
{ get { return mContact; } }
|
|
|
|
[Display(DisplayType.URL_Email)]
|
|
public string LT_HeadOffice_Label_Email
|
|
{ get { return mEmail; } }
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_HeadOffice_Label_Phone1
|
|
{ get { return mPhone1; } }
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_HeadOffice_Label_Phone2
|
|
{ get { return mPhone2; } }
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_HeadOffice_Label_Phone3
|
|
{ get { return mPhone3; } }
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_HeadOffice_Label_Phone4
|
|
{ get { return mPhone4; } }
|
|
|
|
[Display(DisplayType.Text)]
|
|
public string LT_HeadOffice_Label_Phone5
|
|
{ get { return mPhone5; } }
|
|
|
|
[Display(DisplayType.MultiLineText)]
|
|
public string LT_HeadOffice_Label_ContactNotes
|
|
{ get { return mContactNotes; } }
|
|
|
|
//------------------
|
|
#endregion
|
|
//=======================================================================
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Equals(HeadOfficeListDetailedInfo obj)
|
|
{
|
|
return this.mHeadOffice.Value.Equals(obj.mHeadOffice.Value);
|
|
}
|
|
|
|
}//end HeadOfficeListDetailedInfo
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
protected HeadOfficeListDetailed()
|
|
{
|
|
// 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 HeadOfficeListDetailedInfo this[int Item]
|
|
{
|
|
|
|
get
|
|
{
|
|
return (HeadOfficeListDetailedInfo) List[Item];
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Returns display text that matches passed in itemid value
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
public string this[Guid ItemID]
|
|
{
|
|
|
|
get
|
|
{
|
|
foreach (HeadOfficeListDetailedInfo child in List)
|
|
{
|
|
if(child.mHeadOffice.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(HeadOfficeListDetailedInfo obj)
|
|
{
|
|
foreach (HeadOfficeListDetailedInfo 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 "HeadOfficeListDetailed";
|
|
}
|
|
}
|
|
|
|
/// <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 HeadOfficeList.IDField;
|
|
}
|
|
}
|
|
|
|
/// <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 HeadOfficeListDetailed Get(string Filter, int MaxRecords, List<Guid> IDList)
|
|
{
|
|
return (HeadOfficeListDetailed)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="HeadOfficeListDetailed.HeadOfficeListDetailedInfo"/> objects</returns>
|
|
public static HeadOfficeListDetailed GetListByCriteria(string xmlCriteria)
|
|
{
|
|
return (HeadOfficeListDetailed) DataPortal.Fetch(new Criteria(xmlCriteria,null,-1));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Takes a single ID and returns a "list" of one object
|
|
/// </summary>
|
|
/// <param name="HeadOfficeID">ID of HeadOffice object</param>
|
|
/// <returns></returns>
|
|
public static HeadOfficeListDetailed GetListForSingleItem(Guid HeadOfficeID)
|
|
{
|
|
//Case 556
|
|
List<Guid> l = new List<Guid>();
|
|
l.Add(HeadOfficeID);
|
|
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="HeadOfficeListDetailed.HeadOfficeListDetailedInfo"/> objects</returns>
|
|
public static HeadOfficeListDetailed GetListFromIDList(List<Guid> IDList)
|
|
{
|
|
//case 556
|
|
//Handle empty list
|
|
if (IDList.Count == 0)
|
|
return new HeadOfficeListDetailed();
|
|
return (HeadOfficeListDetailed)DataPortal.Fetch(new Criteria("", IDList, -1));
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Return an empty list
|
|
/// used for initializing grid
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static HeadOfficeListDetailed GetEmptyList()
|
|
{
|
|
return new HeadOfficeListDetailed();
|
|
}
|
|
|
|
|
|
#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 (aHeadOffice.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(")) ");
|
|
|
|
cm = DBUtil.DB.GetSqlStringCommandWrapper(
|
|
"SELECT aHeadOffice.aID, aHeadOffice.aName, aHeadOffice.aModified, " +
|
|
" aHeadOffice.AACTIVE, aHeadOffice.aUsesBanking, " +
|
|
" aHeadOffice.aWebAddress, " +
|
|
" aHeadOffice.aClientGroupID, " +
|
|
" (SELECT TOP 1 aSBANK.aHoursBalance " +
|
|
"FROM aServiceBank aSBANK WHERE aSBANK.AAPPLIESTOROOTOBJECTID " +
|
|
"= aHeadOffice.aID ORDER " +
|
|
"BY aSBANK.aCreated DESC) AS HOURSBAL, (SELECT TOP " +
|
|
"1 aSBANK.aIncidentsBalance FROM aServiceBank aSBANK " +
|
|
"WHERE aSBANK.AAPPLIESTOROOTOBJECTID = aHeadOffice.aID " +
|
|
"ORDER BY aSBANK.aCreated DESC) AS INCIDENTSBAL, " +
|
|
" (SELECT TOP 1 aSBANK.aCurrencyBalance FROM " +
|
|
"aServiceBank aSBANK WHERE aSBANK.AAPPLIESTOROOTOBJECTID " +
|
|
"= aHeadOffice.aID ORDER BY aSBANK.aCreated DESC) " +
|
|
"AS CURRENCYBAL, aHeadOffice.AACCOUNTNUMBER, " +
|
|
" AHEADOFFICE.ACONTACT, AHEADOFFICE.AEMAIL, AHEADOFFICE.APHONE1, AHEADOFFICE.APHONE2, AHEADOFFICE.APHONE3, AHEADOFFICE.APHONE4, AHEADOFFICE.APHONE5, AHEADOFFICE.ACONTACTNOTES, " +
|
|
|
|
"aHeadOffice.aName " +
|
|
"AS aHeadOfficeName, aHeadOffice.aID " +
|
|
"AS aHeadOfficeID, " +
|
|
" aHeadOffice.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, " +
|
|
" aHeadOffice.aContractID, aContract.aName AS " +
|
|
"aContractName, aHeadOffice.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, aHeadOffice.aCustom1, aHeadOffice.aCustom2, " +
|
|
" aHeadOffice.aCustom3, aHeadOffice.aCustom4, " +
|
|
" aHeadOffice.aCustom5, aHeadOffice.aCustom6, " +
|
|
" aHeadOffice.aCustom7, aHeadOffice.aCustom8, aHeadOffice.aCustom9, " +
|
|
" aHeadOffice.aCustom0, " +
|
|
" aHeadOffice.aNotes " +
|
|
"FROM " +
|
|
|
|
|
|
" AHEADOFFICE " +
|
|
" LEFT OUTER JOIN ACLIENTGROUP ON (aHeadOffice.ACLIENTGROUPID=ACLIENTGROUP.AID) " +
|
|
" LEFT OUTER JOIN AADDRESS APHYSICAL ON (aHeadOffice.AID=APHYSICAL.AROOTOBJECTID) " +
|
|
" LEFT OUTER JOIN AADDRESS APOSTAL ON (aHeadOffice.AID=APOSTAL.AROOTOBJECTID) " +
|
|
" LEFT OUTER JOIN ACONTRACT ON (aHeadOffice.ACONTRACTID=ACONTRACT.AID) " +
|
|
" LEFT OUTER JOIN AREGION ON (aHeadOffice.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 AHEADOFFICE.ANAME ");
|
|
|
|
}
|
|
else
|
|
{
|
|
string sCurrencySelect=
|
|
" (SELECT TOP 1 aSBANK.aCurrencyBalance FROM aServiceBank aSBANK " +
|
|
"WHERE aSBANK.AAPPLIESTOROOTOBJECTID = aHeadOffice.aID " +
|
|
"ORDER BY aSBANK.aCreated DESC) ";
|
|
string sIncidentsSelect=
|
|
" (SELECT TOP 1 aSBANK.aIncidentsBalance FROM aServiceBank aSBANK " +
|
|
"WHERE aSBANK.AAPPLIESTOROOTOBJECTID = aHeadOffice.aID " +
|
|
"ORDER BY aSBANK.aCreated DESC) ";
|
|
string sHoursSelect=
|
|
" (SELECT TOP 1 aSBANK.aHoursBalance FROM aServiceBank aSBANK " +
|
|
"WHERE aSBANK.AAPPLIESTOROOTOBJECTID = aHeadOffice.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 HeadOfficeList 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
|
|
//HeadOfficeList will match the column names in the HeadOfficeListDetailed
|
|
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 HeadOfficeList 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
|
|
//HeadOfficeList will match the column names in the HeadOfficeListDetailed
|
|
order=order.Replace("AADDRESS","aPHYSICAL");
|
|
|
|
|
|
string q=
|
|
"SELECT ~MAXRECS~ aHeadOffice.aID, aHeadOffice.aName, aHeadOffice.aModified, " +
|
|
" aHeadOffice.AACTIVE, aHeadOffice.aUsesBanking, " +
|
|
" aHeadOffice.aWebAddress, " +
|
|
" aHeadOffice.aClientGroupID, " +
|
|
" (SELECT TOP 1 aSBANK.aHoursBalance " +
|
|
"FROM aServiceBank aSBANK WHERE aSBANK.AAPPLIESTOROOTOBJECTID " +
|
|
"= aHeadOffice.aID ORDER " +
|
|
"BY aSBANK.aCreated DESC) AS HOURSBAL, (SELECT TOP " +
|
|
"1 aSBANK.aIncidentsBalance FROM aServiceBank aSBANK " +
|
|
"WHERE aSBANK.AAPPLIESTOROOTOBJECTID = aHeadOffice.aID " +
|
|
"ORDER BY aSBANK.aCreated DESC) AS INCIDENTSBAL, " +
|
|
" (SELECT TOP 1 aSBANK.aCurrencyBalance FROM " +
|
|
"aServiceBank aSBANK WHERE aSBANK.AAPPLIESTOROOTOBJECTID " +
|
|
"= aHeadOffice.aID ORDER BY aSBANK.aCreated DESC) " +
|
|
"AS CURRENCYBAL, " +
|
|
" AHEADOFFICE.ACONTACT, AHEADOFFICE.AEMAIL, AHEADOFFICE.APHONE1, AHEADOFFICE.APHONE2, AHEADOFFICE.APHONE3, AHEADOFFICE.APHONE4, AHEADOFFICE.APHONE5, AHEADOFFICE.ACONTACTNOTES, " +
|
|
|
|
"aHeadOffice.AACCOUNTNUMBER, aHeadOffice.aName " +
|
|
"AS aHeadOfficeName, aHeadOffice.aID " +
|
|
"AS aHeadOfficeID, " +
|
|
" aHeadOffice.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, " +
|
|
" aHeadOffice.aContractID, aContract.aName AS " +
|
|
"aContractName, aHeadOffice.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, aHeadOffice.aCustom1, aHeadOffice.aCustom2, " +
|
|
" aHeadOffice.aCustom3, aHeadOffice.aCustom4, " +
|
|
" aHeadOffice.aCustom5, aHeadOffice.aCustom6, " +
|
|
" aHeadOffice.aCustom7, aHeadOffice.aCustom8, aHeadOffice.aCustom9, " +
|
|
" aHeadOffice.aCustom0, " +
|
|
" aHeadOffice.aNotes " +
|
|
"FROM " +
|
|
|
|
|
|
" AHEADOFFICE aHeadOffice " +
|
|
" LEFT OUTER JOIN ACLIENTGROUP ON (aHeadOffice.ACLIENTGROUPID=ACLIENTGROUP.AID) " +
|
|
" LEFT OUTER JOIN AADDRESS APHYSICAL ON (aHeadOffice.AID=APHYSICAL.AROOTOBJECTID) " +
|
|
" LEFT OUTER JOIN AADDRESS APOSTAL ON (aHeadOffice.AID=APOSTAL.AROOTOBJECTID) " +
|
|
" LEFT OUTER JOIN ACONTACT ON (aHeadOffice.AID=ACONTACT.AROOTOBJECTID) " +
|
|
" LEFT OUTER JOIN ACONTACTPHONE ON (ACONTACT.AID=ACONTACTPHONE.ACONTACTID) " +
|
|
" LEFT OUTER JOIN ACONTRACT ON (aHeadOffice.ACONTRACTID=ACONTRACT.AID) " +
|
|
" LEFT OUTER JOIN AREGION ON (aHeadOffice.AREGIONID=AREGION.AID) " +
|
|
" LEFT OUTER JOIN ACONTACTTITLE ON (ACONTACT.ACONTACTTITLEID=ACONTACTTITLE.AID) " +
|
|
|
|
"WHERE (aPHYSICAL.AADDRESSTYPE " +
|
|
"IS NULL OR aPHYSICAL.AADDRESSTYPE " +
|
|
"= 2) AND (aPOSTAL.AADDRESSTYPE IS NULL OR aPOSTAL.AADDRESSTYPE " +
|
|
"= 1) " +
|
|
where + " \r\n " +
|
|
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));
|
|
|
|
|
|
while (dr.Read())
|
|
{
|
|
HeadOfficeListDetailedInfo info=new HeadOfficeListDetailedInfo();
|
|
|
|
info.mHeadOffice=new GridNameValueCellItem(
|
|
dr.GetGuid("aID"),
|
|
dr.GetString("aName"),
|
|
RootObjectTypes.HeadOffice);
|
|
|
|
|
|
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.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.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.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 HeadOfficeListDetailed
|
|
#pragma warning restore 1591
|
|
}//end namespace GZTW.AyaNova.BLL |