Files
2018-06-29 19:47:36 +00:00

437 lines
12 KiB
C#

///////////////////////////////////////////////////////////
// ServiceBankList.cs
// Implementation of Class ServiceBankList
// CSLA type: Read only collection
// Created on: 30-Jan-2005
// Object design: John
// Coded: 30-Jan-2005
///////////////////////////////////////////////////////////
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="ServiceBankList.ServiceBankListInfo"/> objects representing <see cref="ServiceBank"/> object entries.
/// Used for reporting and grid display in UI.
/// </summary>
[Serializable]
public class ServiceBankList : ReadOnlyCollectionBase
{
#region Data structure
/// <summary>
/// Properties
/// </summary>
[Serializable]
public struct ServiceBankListInfo
{
internal Guid mID;
internal GridNameValueCellItem mSource; //and ID
internal SmartDate mCreated;
internal string mCreator;
internal string mDescription;
internal SmartDate mEffectiveDate;
internal decimal mIncidents;
internal decimal mIncidentsBalance;
internal decimal mCurrency;
internal decimal mCurrencyBalance;
internal decimal mHours;
internal decimal mHoursBalance;
public Guid LT_ServiceBank_Label_ID
{
get
{
return mID;
}
}
[SqlColumnNameAttribute("aServiceBank.aSourceRootObjectType",
"aServiceBank.aSourceRootObjectID")]
public GridNameValueCellItem LT_ServiceBank_Label_SourceRootObjectType
{
get
{
return mSource;
}
}
public object LT_ServiceBank_Label_Created
{
get
{
return mCreated.DBValue;
}
}
public string LT_ServiceBank_Label_Creator
{
get
{
return mCreator;
}
}
public string LT_ServiceBank_Label_Description
{
get
{
return mDescription;
}
}
public object LT_ServiceBank_Label_EffectiveDate
{
get
{
return mEffectiveDate.DBValue;
}
}
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(ServiceBankListInfo obj)
{
return this.mID.Equals(obj.mID);
}
}//end ServiceBankListInfo
#endregion
#region Constructor
protected ServiceBankList()
{
// 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 ServiceBankListInfo this[int Item]
{
get
{
return (ServiceBankListInfo) List[Item];
}
}
/// <summary>
/// Returns display text that matches passed in itemid value
/// </summary>
/// <param name="ItemID"></param>
public string this[Guid ItemID]
{
get
{
foreach (ServiceBankListInfo child in List)
{
if(child.mID==ItemID) return child.ToString();
}
return "Missing: "+ItemID.ToString();
}
}
#endregion
#region Reporting
//Added this section case 126
/// <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 "ServiceBank";
}
}
#endregion
#region contains
/// <summary>
/// Check if item in collection
/// </summary>
/// <param name="obj"></param>
public bool Contains(ServiceBankListInfo obj)
{
foreach (ServiceBankListInfo child in List)
{
if(child.Equals(obj)) return true;
}
return false;
}
#endregion
#region Static methods
/// <summary>
/// Get List
/// </summary>
/// <param name="ObjectType"></param>
/// <param name="ObjectID"></param>
/// <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="ServiceBankList.ServiceBankListInfo"/> objects</returns>
public static ServiceBankList GetList(RootObjectTypes ObjectType, Guid ObjectID, string xmlCriteria)
{
return (ServiceBankList) DataPortal.Fetch(new Criteria(ObjectType, ObjectID, xmlCriteria));
}
/// <summary>
/// Return an empty list
/// used for initializing grid
/// </summary>
/// <returns></returns>
public static ServiceBankList GetEmptyList()
{
return new ServiceBankList();
}
#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 = DBUtil.DB.GetSqlStringCommandWrapper(
//************************************************************
"SELECT aServiceBank.aCreated , aServiceBank.aDescription, " +
"aServiceBank.aSourceRootObjectType, aServiceBank.aSourceRootObjectID, " +
"aServiceBank.aEffectiveDate, " +
"aServiceBank.aIncidents, aServiceBank.aIncidentsBalance, " +
"aServiceBank.aCurrency, aServiceBank.aCurrencyBalance, " +
"aServiceBank.aHours, " +
"aServiceBank.aHoursBalance, aUser.aInitials AS aCreatorInitials, " +
"aServiceBank.aID " + //, aWorkorderService.aServiceNumber " +
"FROM " +
" ASERVICEBANK " +
" LEFT OUTER JOIN AUSER ON (ASERVICEBANK.ACREATOR=AUSER.AID) " +
//" LEFT OUTER JOIN AWORKORDERITEMLABOR ON (ASERVICEBANK.ASOURCEROOTOBJECTID=AWORKORDERITEMLABOR.AID) " +
//" LEFT OUTER JOIN AWORKORDERITEM ON (AWORKORDERITEMLABOR.AWORKORDERITEMID=AWORKORDERITEM.AID) " +
//" LEFT OUTER JOIN AWORKORDERSERVICE ON (AWORKORDERITEM.AWORKORDERID=AWORKORDERSERVICE.AWORKORDERID) " +
"WHERE (AAPPLIESTOROOTOBJECTTYPE = @RootObjectType ) " +
"AND (AAPPLIESTOROOTOBJECTID = @RootObjectID) " +
AyaBizUtils.GetGridColumnCriteria(crit.CriteriaXML,false) + " " +
AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML)
//************************************************************
);
cm.AddInParameter("@RootObjectType",DbType.Int16,(int)crit.ObjectType);
cm.AddInParameter("@RootObjectID",DbType.Guid,crit.ObjectID);
dr= new SafeDataReader(DBUtil.DB.ExecuteReader(cm));
//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");
while(dr.Read())
{
//*******************************************
ServiceBankListInfo info=new ServiceBankListInfo();
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"));
info.mCreator=dr.GetString("aCreatorInitials");
info.mCurrency=dr.GetDecimal("aCurrency");
info.mCurrencyBalance=dr.GetDecimal("aCurrencyBalance");
info.mEffectiveDate=DBUtil.ToLocal(dr.GetSmartDate("aEffectiveDate"));
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");
InnerList.Add(info);
//*******************************************
}
}
finally
{
if(dr!=null) dr.Close();
}
}
#endregion
#region criteria
/// <summary>
/// Criteria for identifying existing object
/// </summary>
[Serializable]
private class Criteria
{
public RootObjectTypes ObjectType;
public Guid ObjectID;
public string CriteriaXML;
public Criteria( RootObjectTypes _ObjectType, Guid _ObjectID, string _CriteriaXML)
{
ObjectType=_ObjectType;
ObjectID=_ObjectID;
CriteriaXML=_CriteriaXML;
}
}
#endregion
}//end ServiceBankList
#pragma warning restore 1591
}//end namespace GZTW.AyaNova.BLL