395 lines
13 KiB
C#
395 lines
13 KiB
C#
///////////////////////////////////////////////////////////
|
|
// ServiceBankListRI.cs
|
|
// Implementation of Class ServiceBankListRI
|
|
// CSLA type: Read only collection
|
|
// Created on: 1-April-2015
|
|
// Object design: John
|
|
// Coded: 1-April-2015
|
|
///////////////////////////////////////////////////////////
|
|
|
|
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="ServiceBankListRI.ServiceBankListRIInfo"/> objects representing <see cref="ServiceBank"/> object entries.
|
|
/// Used for reporting and grid display in responsive UI.
|
|
/// </summary>
|
|
[Serializable]
|
|
public class ServiceBankListRI : ReadOnlyCollectionBase
|
|
{
|
|
|
|
#region Data structure
|
|
/// <summary>
|
|
/// Properties
|
|
/// </summary>
|
|
[Serializable]
|
|
public struct ServiceBankListRIInfo
|
|
{
|
|
internal Guid mID;
|
|
internal GridNameValueCellItem mSource; //and ID
|
|
|
|
internal string mCreated;
|
|
internal string mCreator;
|
|
internal string mDescription;
|
|
|
|
internal string mEffectiveDate;
|
|
internal decimal mIncidents;
|
|
internal decimal mIncidentsBalance;
|
|
internal decimal mCurrency;
|
|
internal decimal mCurrencyBalance;
|
|
internal decimal mHours;
|
|
internal decimal mHoursBalance;
|
|
|
|
internal decimal mTotal;
|
|
public decimal Total { get { return mTotal; } }
|
|
|
|
|
|
public Guid LT_ServiceBank_Label_ID
|
|
{
|
|
get
|
|
{
|
|
return mID;
|
|
}
|
|
}
|
|
|
|
|
|
[SqlColumnNameAttribute("ASERVICEBANK.ASOURCEROOTOBJECTTYPE",
|
|
"ASERVICEBANK.ASOURCEROOTOBJECTID")]
|
|
public GridNameValueCellItem LT_ServiceBank_Label_SourceRootObjectType
|
|
{
|
|
get
|
|
{
|
|
return mSource;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
public string LT_ServiceBank_Label_Created
|
|
{
|
|
get
|
|
{
|
|
return mCreated;
|
|
}
|
|
}
|
|
|
|
|
|
public string LT_ServiceBank_Label_Creator
|
|
{
|
|
get
|
|
{
|
|
return mCreator;
|
|
}
|
|
}
|
|
|
|
|
|
public string LT_ServiceBank_Label_Description
|
|
{
|
|
get
|
|
{
|
|
return mDescription;
|
|
}
|
|
}
|
|
|
|
public string LT_ServiceBank_Label_EffectiveDate
|
|
{
|
|
get
|
|
{
|
|
return mEffectiveDate;
|
|
}
|
|
}
|
|
|
|
public decimal LT_ServiceBank_Label_Incidents
|
|
{
|
|
get
|
|
{
|
|
return mIncidents;
|
|
}
|
|
}
|
|
|
|
public decimal LT_ServiceBank_Label_IncidentsBalance
|
|
{
|
|
get
|
|
{
|
|
return mIncidentsBalance;
|
|
}
|
|
}
|
|
|
|
public decimal LT_ServiceBank_Label_Currency
|
|
{
|
|
get
|
|
{
|
|
return mCurrency;
|
|
}
|
|
}
|
|
|
|
public decimal LT_ServiceBank_Label_CurrencyBalance
|
|
{
|
|
get
|
|
{
|
|
return mCurrencyBalance;
|
|
}
|
|
}
|
|
|
|
public decimal LT_ServiceBank_Label_Hours
|
|
{
|
|
get
|
|
{
|
|
return mHours;
|
|
}
|
|
}
|
|
|
|
public decimal LT_ServiceBank_Label_HoursBalance
|
|
{
|
|
get
|
|
{
|
|
return mHoursBalance;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Equals(ServiceBankListRIInfo obj)
|
|
{
|
|
return this.mID.Equals(obj.mID);
|
|
}
|
|
|
|
}//end ServiceBankListRIInfo
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
protected ServiceBankListRI()
|
|
{
|
|
// 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 ServiceBankListRIInfo this[int Item]
|
|
{
|
|
|
|
get
|
|
{
|
|
return (ServiceBankListRIInfo)List[Item];
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Returns display text that matches passed in itemid value
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
public string this[Guid ItemID]
|
|
{
|
|
|
|
get
|
|
{
|
|
foreach (ServiceBankListRIInfo child in List)
|
|
{
|
|
if (child.mID == 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(ServiceBankListRIInfo obj)
|
|
{
|
|
foreach (ServiceBankListRIInfo child in List)
|
|
{
|
|
if (child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
|
|
//case 1975
|
|
/// <summary>
|
|
/// Get MaxRecords service bank records for specified object (-1 for all)
|
|
/// </summary>
|
|
/// <param name="ObjectID"></param>
|
|
/// <param name="MaxRecords"></param>
|
|
/// <returns></returns>
|
|
public static ServiceBankListRI GetList(Guid ObjectID, int MaxRecords)
|
|
{
|
|
return (ServiceBankListRI)DataPortal.Fetch(new Criteria(ObjectID, MaxRecords));
|
|
}
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
///
|
|
/// <param name="Criteria"></param>
|
|
protected override void DataPortal_Fetch(object Criteria)
|
|
{
|
|
Criteria crit = (Criteria)Criteria;
|
|
SafeDataReader dr = null;
|
|
try
|
|
{
|
|
decimal dTotal = DBUtil.ScalarToDecimal(DBUtil.GetScalarFromSQLString("SELECT COUNT(AID) FROM ASERVICEBANK WHERE AAPPLIESTOROOTOBJECTID=@ID", crit.ObjectID));
|
|
|
|
|
|
//************************************************************
|
|
string q = "SELECT ~MAXRECS~ ASERVICEBANK.ACREATED , ASERVICEBANK.ADESCRIPTION, " +
|
|
"ASERVICEBANK.ASOURCEROOTOBJECTTYPE, ASERVICEBANK.ASOURCEROOTOBJECTID, " +
|
|
"ASERVICEBANK.AEFFECTIVEDATE, " +
|
|
"ASERVICEBANK.AINCIDENTS, ASERVICEBANK.AINCIDENTSBALANCE, " +
|
|
"ASERVICEBANK.ACURRENCY, ASERVICEBANK.ACURRENCYBALANCE, " +
|
|
"ASERVICEBANK.AHOURS, " +
|
|
"ASERVICEBANK.AHOURSBALANCE, " +
|
|
"ASERVICEBANK.AID, " +
|
|
"AUSER.AFIRSTNAME, AUSER.ALASTNAME, AUSER.AINITIALS, AREGION.ANAME AS AREGIONNAME, AUSER.AEMPLOYEENUMBER " +
|
|
"FROM " +
|
|
"ASERVICEBANK " +
|
|
"LEFT OUTER JOIN AUSER ON (ASERVICEBANK.ACREATOR=AUSER.AID) " +
|
|
"LEFT OUTER JOIN AREGION ON (AUSER.AREGIONID=AREGION.AID) " +
|
|
"WHERE (AAPPLIESTOROOTOBJECTID = @ID) " +
|
|
"ORDER BY ASERVICEBANK.ACREATED DESC;";
|
|
//************************************************************
|
|
|
|
if (crit.MaxRecords > 0)
|
|
q = q.Replace("~MAXRECS~", "TOP " + crit.MaxRecords.ToString());
|
|
else
|
|
q = q.Replace("~MAXRECS~", "");
|
|
|
|
dr = DBUtil.GetReaderFromSQLString(q, crit.ObjectID);
|
|
|
|
//Cache some items in advance
|
|
//cache the found service numbers for performance
|
|
Dictionary<Guid, string> WorkorderServiceNumbersList = new Dictionary<Guid, string>();
|
|
string sDeletedText = LocalizedTextTable.GetLocalizedTextDirect("Workorder.Label.Deleted");
|
|
string sWorkorderObjectText = LocalizedTextTable.GetLocalizedTextDirect("O.Workorder");
|
|
string sServiceBankObjectText = LocalizedTextTable.GetLocalizedTextDirect("O.ServiceBank");
|
|
bool bFirst = true;
|
|
while (dr.Read())
|
|
{
|
|
//*******************************************
|
|
ServiceBankListRIInfo info = new ServiceBankListRIInfo();
|
|
RootObjectTypes roSource = (RootObjectTypes)dr.GetInt16("ASOURCEROOTOBJECTTYPE");
|
|
Guid SourceID = dr.GetGuid("ASOURCEROOTOBJECTID");
|
|
|
|
string sServiceNumber = "";
|
|
//get the workorder service number if it's from a work order
|
|
if (roSource == RootObjectTypes.WorkorderItemLabor || roSource == RootObjectTypes.WorkorderItemTravel)
|
|
{
|
|
//look it up
|
|
Guid WoID = WorkorderIDFetcher.GetWorkorderByRelative(roSource, SourceID);
|
|
if (WoID == Guid.Empty)
|
|
{ //No workorder found, it appears to have been deleted since it was banked
|
|
//so it's a reversing entry
|
|
sServiceNumber = sDeletedText;
|
|
SourceID = Guid.Empty;//so user can't attempt to open the record in the UI
|
|
}
|
|
else
|
|
{
|
|
//Found the workorder
|
|
//Add the description to the cache?
|
|
if (!WorkorderServiceNumbersList.ContainsKey(WoID))
|
|
WorkorderServiceNumbersList.Add(WoID, WorkorderDescriptionFetcher.GetItem(WoID).WorkorderNumber);
|
|
|
|
//get the text for display
|
|
sServiceNumber = sWorkorderObjectText + " - " + WorkorderServiceNumbersList[WoID];
|
|
}
|
|
}
|
|
|
|
|
|
switch (roSource)
|
|
{
|
|
case RootObjectTypes.WorkorderItemLabor:
|
|
case RootObjectTypes.WorkorderItemTravel:
|
|
info.mSource = new GridNameValueCellItem(
|
|
SourceID,
|
|
sServiceNumber,
|
|
roSource);
|
|
break;
|
|
case RootObjectTypes.ServiceBank:
|
|
info.mSource = new GridNameValueCellItem(
|
|
SourceID,
|
|
sServiceBankObjectText,
|
|
roSource);
|
|
break;
|
|
|
|
}
|
|
|
|
info.mCreated = DBUtil.ToLocal(dr.GetSmartDate("ACREATED")).ToString();
|
|
info.mCreator = User.NameFormatter(dr.GetString("AFIRSTNAME"), dr.GetString("ALASTNAME"), dr.GetString("AINITIALS"),
|
|
dr.GetString("AEMPLOYEENUMBER"), dr.GetString("AREGIONNAME"), AyaBizUtils.GlobalSettings.DefaultScheduleableUserNameDisplayFormat);
|
|
info.mCurrency = dr.GetDecimal("ACURRENCY");
|
|
info.mCurrencyBalance = dr.GetDecimal("ACURRENCYBALANCE");
|
|
info.mEffectiveDate = DBUtil.ToLocal(dr.GetSmartDate("AEFFECTIVEDATE")).ToString();
|
|
info.mHours = dr.GetDecimal("AHOURS");
|
|
info.mHoursBalance = dr.GetDecimal("AHOURSBALANCE");
|
|
info.mID = dr.GetGuid("AID");
|
|
info.mIncidents = dr.GetDecimal("AINCIDENTS");
|
|
info.mIncidentsBalance = dr.GetDecimal("AINCIDENTSBALANCE");
|
|
info.mDescription = dr.GetString("ADESCRIPTION");
|
|
if (bFirst)
|
|
{
|
|
info.mTotal = dTotal;
|
|
bFirst = false;
|
|
}
|
|
InnerList.Add(info);
|
|
//*******************************************
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if (dr != null) dr.Close();
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region criteria
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[Serializable]
|
|
private class Criteria
|
|
{
|
|
public Guid ObjectID;
|
|
public int MaxRecords;
|
|
|
|
public Criteria(Guid _ObjectID, int _MaxRecords)
|
|
{
|
|
ObjectID = _ObjectID;
|
|
MaxRecords = _MaxRecords;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
}//end ServiceBankListRI
|
|
#pragma warning restore 1591
|
|
}//end namespace GZTW.AyaNova.BLL |