127 lines
3.2 KiB
C#
127 lines
3.2 KiB
C#
///////////////////////////////////////////////////////////
|
|
// Bool.cs
|
|
// Implementation of Class UnitLastMeterReadingFetcher
|
|
// CSLA type: Read-only object
|
|
// Created on: 25-Sept-2007
|
|
// Object design: John
|
|
// Coded: 25-Sept-2007
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using CSLA.Data;
|
|
using GZTW.Data;
|
|
using CSLA;
|
|
using System.Threading;
|
|
using CSLA.Security;
|
|
using System.ComponentModel;
|
|
|
|
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
//case 500
|
|
/// <summary>
|
|
///Gets the last meter reading for a unit
|
|
///in the AyaNova database
|
|
/// </summary>
|
|
[Serializable, EditorBrowsable(EditorBrowsableState.Never)]
|
|
internal class UnitLastMeterReadingFetcher : ReadOnlyBase
|
|
{
|
|
|
|
#region Attributes
|
|
private long _Meter = 0;
|
|
//private Guid _ID;
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
/// <summary>
|
|
/// Private constructor to prevent direct instantiation
|
|
/// </summary>
|
|
private UnitLastMeterReadingFetcher()
|
|
{
|
|
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region Static methods
|
|
|
|
|
|
|
|
|
|
internal static long LastMeterReading(Guid ID)
|
|
{
|
|
|
|
return ((UnitLastMeterReadingFetcher)DataPortal.Fetch(new Criteria(ID)))._Meter;
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
///
|
|
/// <param Bool="Criteria"></param>
|
|
protected override void DataPortal_Fetch(object Criteria)
|
|
{
|
|
Criteria crit = (Criteria)Criteria;
|
|
switch (DBUtil.DB.DBType)
|
|
{
|
|
case DataBaseType.FireBird:
|
|
{
|
|
this._Meter = DBUtil.ScalarToLong(
|
|
DBUtil.GetScalarFromSQLString(
|
|
"SELECT FIRST 1 aMeter FROM aUnitMeterReading WHERE " +
|
|
"(aUnitMeterReading.aUnitID = @ID) " +
|
|
"ORDER BY aCreated DESC ", crit.ID)
|
|
);
|
|
}
|
|
break;
|
|
|
|
case DataBaseType.MSSQL:
|
|
{
|
|
this._Meter = DBUtil.ScalarToLong(
|
|
DBUtil.GetScalarFromSQLString(
|
|
"SELECT TOP 1 aMeter FROM aUnitMeterReading WHERE " +
|
|
"(aUnitMeterReading.aUnitID = @ID) " +
|
|
"ORDER BY aCreated DESC ", crit.ID)
|
|
);
|
|
}
|
|
break;
|
|
|
|
default:
|
|
throw new ApplicationException("UNKNOWN DB TYPE IN Unit.MeterHelper");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region criteria
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[Serializable]
|
|
private class Criteria
|
|
{
|
|
|
|
public Guid ID;
|
|
|
|
public Criteria(Guid _ID)
|
|
{
|
|
ID = _ID;
|
|
|
|
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}//end class
|
|
|
|
}//end namespace GZTW.AyaNova.BLL |