291 lines
8.6 KiB
C#
291 lines
8.6 KiB
C#
///////////////////////////////////////////////////////////
|
|
// HeadOfficeUnitPickList.cs
|
|
// Implementation of Class HeadOfficeUnitPickList
|
|
// CSLA type: Read only collection
|
|
// Created on: 15-Feb-2016
|
|
// Object design: John
|
|
// Coded: 15-Feb-2016
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using GZTW.Data;
|
|
using CSLA.Data;
|
|
using CSLA;
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
/// Lightweight read only list of <see cref="HeadOfficeUnitPickList.HeadOfficeUnitPickListInfo"/> objects representing <see cref="Unit"/> objects owned by clients of the specified head office.
|
|
/// Used for selection in AyaNova RI
|
|
/// </summary>
|
|
[Serializable]
|
|
public class HeadOfficeUnitPickList : ReadOnlyCollectionBase
|
|
{
|
|
#region Data structure
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Serializable]
|
|
public struct HeadOfficeUnitPickListInfo
|
|
{
|
|
|
|
internal Guid mID;
|
|
internal string mSerial;
|
|
internal string mVendorName;
|
|
internal string mModelName;
|
|
internal string mModelNumber;
|
|
internal bool mActive;
|
|
internal bool mUsesBanking;
|
|
internal bool mMetered;
|
|
internal Guid mClientID;
|
|
|
|
//case 3150
|
|
internal string mDescription;
|
|
|
|
|
|
|
|
#pragma warning disable 1591
|
|
//Public properties
|
|
public Guid ID {get{return mID;}}
|
|
public string Serial {get{return mSerial;}}
|
|
public string VendorName {get{return mVendorName;}}
|
|
public string ModelName {get{return mModelName;}}
|
|
public string ModelNumber {get{return mModelNumber;}}
|
|
public bool Active {get{return mActive;}}
|
|
public bool UsesBanking {get{return mUsesBanking;}}
|
|
public bool Metered {get{return mMetered;}}
|
|
|
|
//Added:30-Sept-2006 for WBI usage
|
|
public Guid ClientID { get { return mClientID; } }
|
|
|
|
//case 3150
|
|
public string Description {get{return mDescription;}}
|
|
|
|
#pragma warning restore 1591
|
|
|
|
/// <summary>
|
|
/// Return unitname in selected <see cref="UnitNameDisplayFormats"/> format
|
|
/// </summary>
|
|
/// <param name="Format"></param>
|
|
/// <returns></returns>
|
|
public string UnitName(UnitNameDisplayFormats Format)
|
|
{
|
|
return Unit.UnitNameFormatter(mModelNumber,mModelName, mVendorName, mSerial, mDescription, Format);
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Return unitname in current global selected format
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string UnitName()
|
|
{
|
|
return Unit.UnitNameFormatter(mModelNumber, mModelName,mVendorName,mSerial, mDescription);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Equals(HeadOfficeUnitPickListInfo obj)
|
|
{
|
|
return this.mID.Equals(obj.mID);
|
|
}
|
|
|
|
}//end HeadOfficeUnitPickListInfo
|
|
#endregion
|
|
|
|
#region Constructor
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
protected HeadOfficeUnitPickList()
|
|
{
|
|
// 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 HeadOfficeUnitPickListInfo this[int Item]
|
|
{
|
|
|
|
get
|
|
{
|
|
return (HeadOfficeUnitPickListInfo) List[Item];
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Returns HeadOfficeUnitPickListInfo item that matches passed in itemid value
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
public HeadOfficeUnitPickListInfo this[Guid ItemID]
|
|
{
|
|
|
|
get
|
|
{
|
|
foreach (HeadOfficeUnitPickListInfo child in List)
|
|
{
|
|
if(child.mID==ItemID) return child;
|
|
}
|
|
throw new ArgumentException("HeadOfficeUnitPickList: ID not found:\r\n"+ItemID.ToString());
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region contains
|
|
/// <summary>
|
|
/// Check if item in collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Contains(HeadOfficeUnitPickListInfo obj)
|
|
{
|
|
foreach (HeadOfficeUnitPickListInfo child in List)
|
|
{
|
|
if(child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if item in collection by UnitID
|
|
/// </summary>
|
|
/// <param name="UnitID"></param>
|
|
/// <returns></returns>
|
|
public bool Contains(Guid UnitID)
|
|
{
|
|
foreach (HeadOfficeUnitPickListInfo child in List)
|
|
{
|
|
if(child.ID.Equals(UnitID)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// Get a list of units owned by a specific headoffice
|
|
/// or self owned.
|
|
/// </summary>
|
|
/// <param name="HeadOfficeID">Head office Guid for units owned by all clients of that head office only</param>
|
|
/// <returns>A list of <see cref="HeadOfficeUnitPickList.HeadOfficeUnitPickListInfo"/> objects</returns>
|
|
public static HeadOfficeUnitPickList GetListByHeadOffice(Guid HeadOfficeID)
|
|
{
|
|
return (HeadOfficeUnitPickList)DataPortal.Fetch(new Criteria(string.Empty, HeadOfficeID, false, Guid.Empty, Guid.Empty));
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
///
|
|
/// <param name="Criteria"></param>
|
|
protected override void DataPortal_Fetch(object Criteria)
|
|
{
|
|
Criteria crit = (Criteria)Criteria;
|
|
|
|
SafeDataReader dr = null;
|
|
try
|
|
{
|
|
dr = DBUtil.GetReaderFromSQLString(
|
|
//************************************************************
|
|
"SELECT AUNIT.ASERIAL, AUNIT.ADESCRIPTION, AUNIT.ACLIENTID, AUNITMODEL.ANAME " +
|
|
" AS AMODELNAME,AMODELNUMBER, AVENDOR.ANAME " +
|
|
" AS AVENDORNAME, AUNIT.AACTIVE, AUNIT.AUSESBANKING, " +
|
|
" AUNIT.AMETERED, AUNIT.AID " +
|
|
" FROM AUNIT " +
|
|
" LEFT OUTER JOIN AUNITMODEL ON (AUNIT.AUNITMODELID=AUNITMODEL.AID) " +
|
|
" LEFT OUTER JOIN AVENDOR ON (AUNITMODEL.AVENDORID=AVENDOR.AID) " +
|
|
" LEFT OUTER JOIN ACLIENT ON (AUNIT.ACLIENTID=ACLIENT.AID) " +
|
|
" LEFT OUTER JOIN AHEADOFFICE ON (AHEADOFFICE.AID=ACLIENT.AHEADOFFICEID) " +
|
|
" WHERE AHEADOFFICE.AID = @ID " +
|
|
" ORDER BY AUNIT.ASERIAL ", crit.HeadOfficeID
|
|
//************************************************************
|
|
);
|
|
|
|
|
|
while(dr.Read())
|
|
{
|
|
//*******************************************
|
|
HeadOfficeUnitPickListInfo info=new HeadOfficeUnitPickListInfo();
|
|
info.mID=dr.GetGuid("aID");
|
|
|
|
////case 1975 (should have just done this a long time ago to save code)
|
|
////this filters out the "ExceptThisUnitId" used to populate lists where a single
|
|
////unit is not a valid selection (Unit screen parent for ex.)
|
|
//if (crit.AllUnits && crit.UnitID == info.mID)
|
|
// continue;
|
|
|
|
info.mActive=dr.GetBoolean("AACTIVE");
|
|
info.mUsesBanking=dr.GetBoolean("aUsesBanking");
|
|
info.mMetered=dr.GetBoolean("aMetered");
|
|
info.mSerial=dr.GetString("aSerial");
|
|
info.mVendorName=dr.GetString("aVendorName");
|
|
info.mModelName=dr.GetString("aModelName");
|
|
info.mModelNumber=dr.GetString("aModelNumber");
|
|
info.mClientID = dr.GetGuid("aClientID");
|
|
info.mDescription=dr.GetString("ADESCRIPTION");//case 3150
|
|
InnerList.Add(info);
|
|
//*******************************************
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if(dr!=null) dr.Close();
|
|
}
|
|
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region criteria
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[Serializable]
|
|
private class Criteria
|
|
{
|
|
//case 2033 KEPT MOST OF THIS IN CASE WE NEED IT IN FUTURE BUT CURRENTLY ONLY HEADOFFICEID IS USED
|
|
//REST CAN BE GOTTEN FROM REGULAR UNIT PICK LIST
|
|
public string SearchTerm;//case 1975
|
|
public Guid HeadOfficeID;
|
|
public bool AllUnits;
|
|
public Guid UnitID;
|
|
//case 1175
|
|
public Guid WorkorderID;
|
|
|
|
public Criteria(string _searchTerm, Guid _HeadOfficeID, bool _AllUnits, Guid _UnitID, Guid _WorkorderID)
|
|
{
|
|
SearchTerm = _searchTerm;
|
|
HeadOfficeID = _HeadOfficeID;
|
|
AllUnits=_AllUnits;
|
|
UnitID=_UnitID;
|
|
WorkorderID = _WorkorderID;//case 1175
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}//end HeadOfficeUnitPickList
|
|
|
|
}//end namespace GZTW.AyaNova.BLL
|