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

385 lines
12 KiB
C#

///////////////////////////////////////////////////////////
// ClientWorkorderList.cs
// Implementation of Class ClientWorkorderList
// CSLA type: Read only collection
// Created on: 11-Nov-2006
// Object design: Joyce & John Nov 11th 2006
// Coded: John 11-Nov-2006
///////////////////////////////////////////////////////////
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 client work orders
/// Displayed in AyaNova WBI for client logins
///
/// </summary>
[Serializable]
public class ClientWorkorderList : ReadOnlyCollectionBase
{
#region Data structure
/// <summary>
/// Properties
/// </summary>
[Serializable]
public struct ClientWorkorderListInfo
{
internal GridNameValueCellItem mWorkorder;
internal string mInvoice;
internal SmartDate mServiceDate;
internal bool mClosed;
internal string mClientRef;
internal string mClientContact;
internal string mClient;
internal string mHeadOffice;
//Case 228
internal string mSummary;
[SqlColumnNameAttribute("aWorkorderService.aServiceNumber", "aWorkorder.aID"),
Display(DisplayType.Button, RootObjectType = RootObjectTypes.WorkorderItem, CompareAs = CompareType.StringToInt32)]
public GridNameValueCellItem LT_O_Workorder { get { return mWorkorder; } }
[Display(DisplayType.Text)]
public string LT_WorkorderService_Label_InvoiceNumber { get { return mInvoice; } }
[SqlColumnNameAttribute("AWORKORDERSERVICE.ASERVICEDATE"), Display(DisplayType.DateTime)]
public object LT_WorkorderService_Label_ServiceDate
{ get { return mServiceDate.DBValue; } }
[Display(DisplayType.TrueFalse)]
public bool LT_Workorder_Label_Closed { get { return mClosed; } }
[SqlColumnNameAttribute("aWorkorder.ACLIENTREF"), Display(DisplayType.Text)]
public string LT_Workorder_Label_CustomerReferenceNumber
{ get { return this.mClientRef; } }
[Display(DisplayType.Text)]
public string LT_Workorder_Label_CustomerContactName { get { return mClientContact; } }
[SqlColumnNameAttribute("aClient.aName"), Display(DisplayType.Text)]
public string LT_O_Client { get { return mClient; } }
[SqlColumnNameAttribute("aHeadOffice.aName"), Display(DisplayType.Text)]
public string LT_O_HeadOffice { get { return mHeadOffice; } }
//Case 228
[Display(DisplayType.Text)]
public string LT_Workorder_Label_Summary { get { return mSummary; } }
/// <summary>
///
/// </summary>
/// <param name="obj"></param>
public bool Equals(ClientWorkorderListInfo obj)
{
return this.mWorkorder.Value.Equals(obj.mWorkorder.Value);
}
}//end ClientWorkorderListInfo
#endregion
#region Constructor
protected ClientWorkorderList()
{
}
#endregion
#region Business properties and methods
/// <summary>
/// Get item by index
/// </summary>
/// <param name="Item"></param>
public ClientWorkorderListInfo this[int Item]
{
get
{
return (ClientWorkorderListInfo)List[Item];
}
}
/// <summary>
/// Returns display text that matches passed in itemid value
/// </summary>
/// <param name="ItemID"></param>
public string this[Guid ItemID]
{
get
{
foreach (ClientWorkorderListInfo child in List)
{
if (child.mWorkorder.Value == 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(ClientWorkorderListInfo obj)
{
foreach (ClientWorkorderListInfo child in List)
{
if (child.Equals(obj)) return true;
}
return false;
}
#endregion
#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 "ClientWorkorderList";
}
}
/// <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
{
//Nothing so that no accidental possibility of
//client creating a workorder
return RootObjectTypes.Nothing;
}
}
/// <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 "WorkorderService.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(ClientWorkorderListInfo);
}
}
#endregion
#region Static methods
/// <summary>
/// Get all Workorders for a specified head office
/// (returns all workorders for all clients under headOfficeID)
/// </summary>
/// <param name="headOfficeID"></param>
/// <returns></returns>
public static ClientWorkorderList GetListForHeadOffice(Guid headOfficeID)
{
return (ClientWorkorderList)DataPortal.Fetch(new Criteria(headOfficeID, Guid.Empty));
}
/// <summary>
/// Get all Workorders for a specified client
/// </summary>
/// <param name="clientID">ID of client object</param>
/// <returns></returns>
public static ClientWorkorderList GetListForClient(Guid clientID)
{
return (ClientWorkorderList)DataPortal.Fetch(new Criteria(Guid.Empty, clientID));
}
///// <summary>
///// Return an empty list
///// used for initializing grid
///// </summary>
///// <returns></returns>
//public static ClientWorkorderList GetEmptyList()
//{
// return new ClientWorkorderList();
//}
#endregion
#region DAL DATA ACCESS
///
/// <param name="Criteria"></param>
protected override void DataPortal_Fetch(object Criteria)
{
Criteria crit = (Criteria)Criteria;
SafeDataReader dr = null;
try
{
string q = "";
if (crit.ClientID != Guid.Empty)
{
q = "SELECT " +
" AWORKORDERSERVICE.ASERVICENUMBER, " +
" AWORKORDERSERVICE.AINVOICENUMBER, " +
" AWORKORDERSERVICE.ASERVICEDATE, " +
" AWORKORDER.ACLOSED, " +
" AWORKORDER.ACUSTOMERREFERENCENUMBER, " +
" AWORKORDER.ACUSTOMERCONTACTNAME, " +
" ACLIENT.ANAME AS ACLIENTNAME, " +
" AHEADOFFICE.ANAME AS AHEADOFFICENAME, " +
" AWORKORDER.AID, AWORKORDER.ASUMMARY " +//case 228 added summary column
"FROM " +
" AWORKORDERSERVICE " +
" INNER JOIN AWORKORDER ON (AWORKORDERSERVICE.AWORKORDERID = AWORKORDER.AID) " +
" INNER JOIN ACLIENT ON (AWORKORDER.ACLIENTID = ACLIENT.AID) " +
" LEFT OUTER JOIN AHEADOFFICE ON (ACLIENT.AHEADOFFICEID = AHEADOFFICE.AID) " +
"WHERE " +
" (AWORKORDER.AWORKORDERTYPE = 1) AND AWORKORDER.ACLIENTID=@ID " +
" ORDER BY AWORKORDERSERVICE.ASERVICENUMBER DESC ";
dr = DBUtil.GetReaderFromSQLString(q, crit.ClientID);
}
else
{
q = "SELECT " +
" AWORKORDERSERVICE.ASERVICENUMBER, " +
" AWORKORDERSERVICE.AINVOICENUMBER, " +
" AWORKORDERSERVICE.ASERVICEDATE, " +
" AWORKORDER.ACLOSED, " +
" AWORKORDER.ACUSTOMERREFERENCENUMBER, " +
" AWORKORDER.ACUSTOMERCONTACTNAME, " +
" ACLIENT.ANAME AS ACLIENTNAME, " +
" AHEADOFFICE.ANAME AS AHEADOFFICENAME, " +
" AWORKORDER.AID, AWORKORDER.ASUMMARY " +//case 228 added summary column
"FROM " +
" AWORKORDERSERVICE " +
" INNER JOIN AWORKORDER ON (AWORKORDERSERVICE.AWORKORDERID = AWORKORDER.AID) " +
" INNER JOIN ACLIENT ON (AWORKORDER.ACLIENTID = ACLIENT.AID) " +
" LEFT OUTER JOIN AHEADOFFICE ON (ACLIENT.AHEADOFFICEID = AHEADOFFICE.AID) " +
"WHERE " +
" (AWORKORDER.AWORKORDERTYPE = 1) AND ACLIENT.AHEADOFFICEID=@ID " +
" ORDER BY AWORKORDERSERVICE.ASERVICENUMBER DESC ";
dr = DBUtil.GetReaderFromSQLString(q, crit.HeadOfficeID);
}
//************************************************************
while (dr.Read())
{
//*******************************************
ClientWorkorderListInfo info = new ClientWorkorderListInfo();
info.mWorkorder = new GridNameValueCellItem(
dr.GetGuid("AID"),
dr.GetInt32("ASERVICENUMBER") == 0 ? "" : dr.GetInt32("ASERVICENUMBER").ToString(),
RootObjectTypes.Workorder);
info.mInvoice = dr.GetString("AINVOICENUMBER");
info.mServiceDate = DBUtil.ToLocal(dr.GetSmartDate("ASERVICEDATE"));
info.mClosed = dr.GetBoolean("ACLOSED");
info.mClientRef = dr.GetString("ACUSTOMERREFERENCENUMBER");
info.mClientContact = dr.GetString("ACUSTOMERCONTACTNAME");
info.mClient = dr.GetString("ACLIENTNAME");
info.mHeadOffice = dr.GetString("AHEADOFFICENAME");
//Case 228
info.mSummary = dr.GetString("ASUMMARY");
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 HeadOfficeID;
public Guid ClientID;
public Criteria(Guid _HeadOfficeID, Guid _ClientID)
{
HeadOfficeID = _HeadOfficeID;
ClientID = _ClientID;
}
}
#endregion
}//end ClientWorkorderList
#pragma warning restore 1591
}//end namespace GZTW.AyaNova.BLL