Files
ayanova7/source/bizobjects/AyaLib/GZTW.AyaNova.BLL/UnitMeterReadingList.cs
2018-06-29 19:47:36 +00:00

405 lines
12 KiB
C#

///////////////////////////////////////////////////////////
// UnitMeterReadingList.cs
// Implementation of Class UnitMeterReadingList
// CSLA type: Read only collection
// Created on: 12-Feb-2005
// Object design: John
// Coded: 12-Feb-2005
///////////////////////////////////////////////////////////
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="UnitMeterReadingList.UnitMeterReadingListInfo"/> objects representing <see cref="UnitMeterReading"/> object.
/// Used in UI and reporting.
/// </summary>
[Serializable]
public class UnitMeterReadingList : ReadOnlyCollectionBase
{
#region Data structure
/// <summary>
/// Properties
/// </summary>
[Serializable]
public struct UnitMeterReadingListInfo
{
internal Guid mID;
internal GridNameValueCellItem mWorkorderItem; //and ID
internal string mDescription;
internal SmartDate mMeterDate;
internal long mMeter;
internal SmartDate mCreated;
internal string mCreator;
public Guid LT_UnitMeterReading_Label_ID
{
get
{
return mID;
}
}
[SqlColumnNameAttribute("aWorkorderService.aServiceNumber",
"aUnitMeterReading.aWorkorderItemID")]
public GridNameValueCellItem LT_UnitMeterReading_Label_WorkorderItemID
{
get
{
return mWorkorderItem;
}
}
public object LT_UnitMeterReading_Label_MeterDate
{
get
{
return mMeterDate.DBValue;
}
}
public long LT_UnitMeterReading_Label_Meter
{
get
{
return mMeter;
}
}
public string LT_UnitMeterReading_Label_Description
{
get
{
return mDescription;
}
}
[SqlColumnNameAttribute("aUnitMeterReading.aCreated")]
public object LT_Common_Label_Created
{
get
{
return mCreated.DBValue;
}
}
[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 UnitMeterReadingList()
{
// 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 contains
/// <summary>
/// Check if item in collection
/// </summary>
/// <param name="obj"></param>
public bool Contains(UnitMeterReadingListInfo obj)
{
foreach (UnitMeterReadingListInfo child in List)
{
if(child.Equals(obj)) return true;
}
return false;
}
#endregion
//Added: 24-Oct-2006 for reporting on unit meter reading support
#region Reporting and shared UI editor helpers
/// <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 "UnitMeterReadingList";
}
}
/// <summary>
/// Returns the Detailed report key
/// which is used to determine which reports and objects
/// will be used for detailed reports
///
/// If empty string then indicates there is no detailed report object or reports
/// </summary>
public static string DetailedReportKey
{
get
{
return "";
}
}
/// <summary>
/// Base object that this list is reporting on
/// used by shared UI editor to instantiate new objects
/// when user selects new in UI elements that display this list
///
/// (I.E. when user clicks on new in a read only list grid, this is the object type created)
/// </summary>
public static RootObjectTypes BaseObjectType
{
get
{
return RootObjectTypes.UnitMeterReading;
}
}
/// <summary>
/// Locale key so that generic list editor
/// UI code knows what title to give the list in a
/// grid
/// </summary>
public string LocaleKey
{
get
{
return "UnitMeterReading.Label.List";
}
}
/// <summary>
/// The Type of the struct used to store list records
/// Used to fetch the custom display attributes of the fields
/// contained within the record to modify the grid display accordingly
/// <see cref="DisplayAttribute"/>
/// </summary>
public static Type ListRecordType
{
get
{
return typeof(UnitMeterReadingListInfo);
}
}
#endregion
#region Static methods
/// <summary>
/// GetList for unit
/// </summary>
/// <param name="UnitID"><see cref="Unit"/> ID</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="UnitMeterReadingList.UnitMeterReadingListInfo"/> objects</returns>
public static UnitMeterReadingList GetList(Guid UnitID, string xmlCriteria)
{
return (UnitMeterReadingList) DataPortal.Fetch(new Criteria(UnitID, xmlCriteria));
}
/// <summary>
/// Return an empty list
/// used for initializing grid
/// </summary>
/// <returns></returns>
public static UnitMeterReadingList GetEmptyList()
{
return new UnitMeterReadingList();
}
#endregion
#region DAL DATA ACCESS
///
/// <param name="Criteria"></param>
protected override void DataPortal_Fetch(object Criteria)
{
Criteria crit = (Criteria)Criteria;
SafeDataReader dr = null;
try
{
//Added:25-Oct-2005 to give natural order to results
//for wbi when not using grid sort and filter criteria
if (string.IsNullOrEmpty(crit.CriteriaXML))
{
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
//************************************************************
);
}
else
{
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) " +
AyaBizUtils.GetGridColumnCriteria(crit.CriteriaXML, false) + " " +
AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML), crit.UnitID
//************************************************************
);
}
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"));
info.mMeter=dr.GetInt64("aMeter");
info.mID=dr.GetGuid("aID");
info.mDescription=dr.GetString("aDescription");
info.mCreated=DBUtil.ToLocal(dr.GetSmartDate("aCreatedDate"));
info.mCreator=dr.GetString("aCreatorInitials");
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 string CriteriaXML;
public Criteria(Guid _UnitID, string _CriteriaXML)
{
UnitID=_UnitID;
CriteriaXML=_CriteriaXML;
}
}
#endregion
}//end UnitMeterReadingList
#pragma warning restore 1591
}//end namespace GZTW.AyaNova.BLL