///////////////////////////////////////////////////////////
// WorkorderPickList.cs
// Implementation of Class WorkorderPickList
// CSLA type: Read only collection
// Created on: 11-Feb-2005
// Object design: John
// Coded: 11-Feb-2005
///////////////////////////////////////////////////////////
using System;
using System.Data;
using GZTW.Data;
using CSLA.Data;
using CSLA;
namespace GZTW.AyaNova.BLL
{
///
/// Lightweight read only list of objects representing objects.
/// Fetched by client for selection in UI.
///
[Serializable]
public class WorkorderPickList : ReadOnlyCollectionBase
{
#region Data structure
///
///
///
[Serializable]
public struct WorkorderPickListInfo
{
internal Guid mID;
internal string mServiceNumber;
internal DateTime mServiceDate;
internal string mSummary;
//Public properties
///
/// object ID
///
public Guid ID {get{return mID;}}
///
/// object's number
///
public string ServiceNumber {get{return mServiceNumber;}}
///
///
///
public string Summary {get{return mSummary;}}
///
///
///
public DateTime ServiceDate {get{return mServiceDate;}}
///
///
///
///
public bool Equals(WorkorderPickListInfo obj)
{
return this.mID.Equals(obj.mID);
}
}//end WorkorderPickListInfo
#endregion
#region Constructor
///
///
///
protected WorkorderPickList()
{
// AllowSort=false;
// AllowFind=true;
// AllowEdit=false;
// AllowNew=false;
// AllowRemove=false;
}
#endregion
#region Business properties and methods
///
/// Get item by index
///
///
public WorkorderPickListInfo this[int Item]
{
get
{
return (WorkorderPickListInfo) List[Item];
}
}
///
/// Returns WorkorderPickListInfo item that matches passed in itemid value
///
///
public WorkorderPickListInfo this[Guid ItemID]
{
get
{
foreach (WorkorderPickListInfo child in List)
{
if(child.mID==ItemID) return child;
}
throw new ArgumentException("WorkorderPickList: ID not found:\r\n"+ItemID.ToString());
}
}
#endregion
#region contains
///
/// Check if item in collection
///
///
public bool Contains(WorkorderPickListInfo obj)
{
foreach (WorkorderPickListInfo child in List)
{
if(child.Equals(obj)) return true;
}
return false;
}
#endregion
#region Static methods
///
/// Get all Workorders owned by client specified
///
/// Client owning Workorders
/// list of objects
public static WorkorderPickList GetListByClient(Guid ClientID)
{
return (WorkorderPickList) DataPortal.Fetch(new Criteria(ClientID, Guid.Empty));
}
///
/// Get all Workorders owned by client specified
/// except one specified in workorder id parameter
///
/// Client owning Workorders
/// Guid of workorder that should not be included in return list
/// list of objects
public static WorkorderPickList GetListByClient(Guid ClientID, Guid WorkorderId)
{
return (WorkorderPickList)DataPortal.Fetch(new Criteria(ClientID, WorkorderId));
}
#endregion
#region DAL DATA ACCESS
///
///
protected override void DataPortal_Fetch(object Criteria)
{
Criteria crit = (Criteria)Criteria;
SafeDataReader dr = null;
try
{
DBCommandWrapper dbCommandWrapper = DBUtil.DB.GetSqlStringCommandWrapper(
//************************************************************
"SELECT aWorkorder.aID, aWorkorderService.aServiceNumber, " +
" aWorkorderService.aServiceDate, aWorkorder.aSummary " +
"FROM aWorkorder INNER JOIN aWorkorderService " +
"ON aWorkorder.aID = aWorkorderService.aWorkorderID " +
"WHERE(aWorkorder.aClientID " +
"= @ClientID) AND (aWorkorder.aClosed = @aFalse) AND " +
"(aWorkorder.aServiceCompleted = @aFalse) AND (aWorkorder.aWorkorderType " +
"= @WorkorderType) ORDER BY AWORKORDERSERVICE.ASERVICENUMBER DESC "
//************************************************************
);
dbCommandWrapper.AddInParameter("@ClientID",DbType.Guid,crit.ClientID);
dbCommandWrapper.AddInParameter("@aFalse",DbType.Boolean,false);
dbCommandWrapper.AddInParameter("@WorkorderType",DbType.Int16,(int)WorkorderTypes.Service);
dr = new SafeDataReader(DBUtil.DB.ExecuteReader(dbCommandWrapper));
while(dr.Read())
{
//*******************************************
WorkorderPickListInfo info=new WorkorderPickListInfo();
info.mID=dr.GetGuid("aID");
if (info.mID == crit.WorkorderID)
continue;//case 1975
info.mServiceNumber=dr.GetInt32("aServiceNumber").ToString();
info.mSummary=dr.GetString("aSummary");
info.mServiceDate=DBUtil.ToLocal(dr.GetDateTime("aServiceDate"));
InnerList.Add(info);
//*******************************************
}
}
finally
{
if(dr!=null) dr.Close();
}
}
#endregion
#region criteria
///
/// Criteria for identifying existing object
///
[Serializable]
private class Criteria
{
public Guid ClientID;
public Guid WorkorderID;
public Criteria(Guid _ClientID, Guid _WorkorderID )
{
ClientID=_ClientID;
WorkorderID = _WorkorderID;
}
}
#endregion
}//end WorkorderPickList
}//end namespace GZTW.AyaNova.BLL