279 lines
8.9 KiB
C#
279 lines
8.9 KiB
C#
///////////////////////////////////////////////////////////
|
|
// UnitMeterReadingListRI.cs
|
|
// Implementation of Class UnitMeterReadingListRI
|
|
// CSLA type: Read only collection
|
|
// Created on: 9-April-2015
|
|
// Object design: John
|
|
// Coded: 9-April-2015
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using GZTW.Data;
|
|
using CSLA.Data;
|
|
using CSLA;
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
#pragma warning disable 1591
|
|
/// <summary>
|
|
/// Read only list of <see cref="UnitMeterReadingListRI.UnitMeterReadingListInfo"/> objects representing <see cref="UnitMeterReading"/> object.
|
|
/// Used in responsive UI
|
|
/// </summary>
|
|
[Serializable]
|
|
public class UnitMeterReadingListRI : ReadOnlyCollectionBase
|
|
{
|
|
|
|
#region Data structure
|
|
/// <summary>
|
|
/// Properties
|
|
/// </summary>
|
|
[Serializable]
|
|
public struct UnitMeterReadingListInfo
|
|
{
|
|
internal Guid mID;
|
|
internal GridNameValueCellItem mWorkorderItem; //and ID
|
|
|
|
internal string mDescription;
|
|
|
|
internal string mMeterDate;
|
|
internal long mMeter;
|
|
internal string mCreated;
|
|
internal string mCreator;
|
|
|
|
internal decimal mTotal;
|
|
public decimal Total { get { return mTotal; } }
|
|
|
|
public Guid LT_UnitMeterReading_Label_ID
|
|
{
|
|
get
|
|
{
|
|
return mID;
|
|
}
|
|
}
|
|
|
|
|
|
[SqlColumnNameAttribute("aWorkorderService.aServiceNumber",
|
|
"aUnitMeterReading.aWorkorderItemID")]
|
|
public GridNameValueCellItem LT_UnitMeterReading_Label_WorkorderItemID
|
|
{
|
|
get
|
|
{
|
|
return mWorkorderItem;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public string LT_UnitMeterReading_Label_MeterDate
|
|
{
|
|
get
|
|
{
|
|
return mMeterDate;
|
|
}
|
|
}
|
|
|
|
public long LT_UnitMeterReading_Label_Meter
|
|
{
|
|
get
|
|
{
|
|
return mMeter;
|
|
}
|
|
}
|
|
|
|
public string LT_UnitMeterReading_Label_Description
|
|
{
|
|
get
|
|
{
|
|
return mDescription;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("aUnitMeterReading.aCreated")]
|
|
public string LT_Common_Label_Created
|
|
{
|
|
get
|
|
{
|
|
return mCreated;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("aUser.aInitials")]
|
|
public string LT_Common_Label_Creator
|
|
{
|
|
get
|
|
{
|
|
return mCreator;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Equals(UnitMeterReadingListInfo obj)
|
|
{
|
|
return this.mID.Equals(obj.mID);
|
|
}
|
|
|
|
}//end UnitMeterReadingListInfo
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
protected UnitMeterReadingListRI()
|
|
{
|
|
// 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 UnitMeterReadingListInfo this[int Item]
|
|
{
|
|
|
|
get
|
|
{
|
|
return (UnitMeterReadingListInfo)List[Item];
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Returns display text that matches passed in itemid value
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
public string this[Guid ItemID]
|
|
{
|
|
|
|
get
|
|
{
|
|
foreach (UnitMeterReadingListInfo child in List)
|
|
{
|
|
if (child.mID == ItemID) return child.ToString();
|
|
}
|
|
return "Missing: " + ItemID.ToString();
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
|
|
//case 1975
|
|
/// <summary>
|
|
/// Get MaxRecords meter readings for specified unit (-1 for all)
|
|
/// </summary>
|
|
/// <param name="UnitID"></param>
|
|
/// <param name="MaxRecords"></param>
|
|
/// <returns></returns>
|
|
public static UnitMeterReadingListRI GetList(Guid UnitID, int MaxRecords)
|
|
{
|
|
return (UnitMeterReadingListRI)DataPortal.Fetch(new Criteria(UnitID, 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 AUNITMETERREADING WHERE AUNITID=@ID", crit.UnitID));
|
|
|
|
dr = DBUtil.GetReaderFromSQLString(
|
|
//************************************************************
|
|
"SELECT AUNITMETERREADING.ADESCRIPTION, " +
|
|
"AUNITMETERREADING.AID, AUNITMETERREADING.AMETER, " +
|
|
"AUNITMETERREADING.AMETERDATE, AUNITMETERREADING.AUNITID, " +
|
|
"AUNITMETERREADING.AWORKORDERITEMID, AUNITMETERREADING.ACREATED AS ACREATEDDATE, " +
|
|
"AWORKORDERSERVICE.ASERVICENUMBER, AUSER.AINITIALS " +
|
|
"AS ACREATORINITIALS FROM AUNITMETERREADING " +
|
|
"LEFT OUTER JOIN AUSER ON AUNITMETERREADING.ACREATOR " +
|
|
"= AUSER.AID LEFT OUTER JOIN AWORKORDERITEM " +
|
|
"ON AUNITMETERREADING.AWORKORDERITEMID " +
|
|
"= AWORKORDERITEM.AID FULL OUTER JOIN AWORKORDERSERVICE " +//BAD FULL OUTER JOIN
|
|
"ON AWORKORDERITEM.AWORKORDERID = " +
|
|
"AWORKORDERSERVICE.AWORKORDERID " +
|
|
"WHERE (AUNITMETERREADING.AUNITID = @ID) ORDER BY AMETERDATE DESC", crit.UnitID
|
|
//************************************************************
|
|
);
|
|
|
|
bool bFirst = true;
|
|
while (dr.Read())
|
|
{
|
|
//*******************************************
|
|
UnitMeterReadingListInfo info = new UnitMeterReadingListInfo();
|
|
if (dr.GetGuid("AWORKORDERITEMID") != Guid.Empty)
|
|
{
|
|
info.mWorkorderItem = new GridNameValueCellItem(
|
|
dr.GetGuid("AWORKORDERITEMID"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.Workorder") + " " + dr.GetInt32("ASERVICENUMBER").ToString(),
|
|
RootObjectTypes.WorkorderItem);
|
|
}
|
|
else
|
|
{
|
|
info.mWorkorderItem = new GridNameValueCellItem(
|
|
Guid.Empty,
|
|
"",
|
|
RootObjectTypes.UnitMeterReading);
|
|
}
|
|
info.mMeterDate = DBUtil.ToLocal(dr.GetSmartDate("AMETERDATE")).ToString();
|
|
info.mMeter = dr.GetInt64("AMETER");
|
|
info.mID = dr.GetGuid("AID");
|
|
info.mDescription = dr.GetString("ADESCRIPTION");
|
|
info.mCreated = DBUtil.ToLocal(dr.GetSmartDate("ACREATEDDATE")).ToString();
|
|
info.mCreator = dr.GetString("ACREATORINITIALS");
|
|
|
|
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 UnitID;
|
|
public int MaxRecords;
|
|
public Criteria(Guid _UnitID, int _MaxRecords)
|
|
{
|
|
UnitID = _UnitID;
|
|
MaxRecords = _MaxRecords;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
}//end UnitMeterReadingListRI
|
|
#pragma warning restore 1591
|
|
}//end namespace GZTW.AyaNova.BLL
|