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

321 lines
8.4 KiB
C#

///////////////////////////////////////////////////////////
// ClientNotesReportList.cs
// Implementation of Class ClientNotesReportList case 274
// CSLA type: Read only collection
// Created on: 3-Nov-2009
// Object design: John
// Coded: 3-Nov-2009
///////////////////////////////////////////////////////////
using System;
using System.Data;
using GZTW.Data;
using CSLA.Data;
using CSLA;
using System.Collections.Generic;
namespace GZTW.AyaNova.BLL
{
#pragma warning disable 1591
/// <summary>
/// Read only list of <see cref="ClientNotesReportList.ClientNotesReportListInfo"/> objects representing ClientNotes used for reporting (printing) client notes
///
///
/// </summary>
[Serializable]
public class ClientNotesReportList : ReadOnlyCollectionBase
{
#region Data structure
/// <summary>
/// Properties
/// </summary>
[Serializable]
public struct ClientNotesReportListInfo
{
internal Guid mID;
internal string mCreator;
internal SmartDate mCreated;
internal SmartDate mNoteDate;
internal string mNotes;
internal string mClientNoteType;
internal string mClient;
public Guid ID
{
get
{
return mID;
}
}
public object LT_Common_Label_Created
{
get
{
return mCreated.DBValue;
}
}
public string LT_Common_Label_Creator
{
get
{
return mCreator;
}
}
public object LT_ClientNote_Label_NoteDate
{
get
{
return mNoteDate.DBValue;
}
}
public string LT_ClientNote_Label_Notes
{
get
{
return mNotes;
}
}
public string LT_ClientNoteType_Label_Name
{
get
{
return mClientNoteType;
}
}
public string LT_O_Client
{
get
{
return mClient;
}
}
/// <summary>
///
/// </summary>
/// <param name="obj"></param>
public bool Equals(ClientNotesReportListInfo obj)
{
return this.mID.Equals(obj.mID);
}
}//end ClientNotesReportListInfo
#endregion
#region Constructor
protected ClientNotesReportList()
{
// 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 ClientNotesReportListInfo this[int Item]
{
get
{
return (ClientNotesReportListInfo) List[Item];
}
}
/// <summary>
/// Returns display text that matches passed in itemid value
/// </summary>
/// <param name="ItemID"></param>
public string this[Guid ItemID]
{
get
{
foreach (ClientNotesReportListInfo child in List)
{
if(child.mID==ItemID) return child.ToString();
}
return "Missing: "+ItemID.ToString();
}
}
#endregion
#region Reporting
/// <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 "ClientNote";
}
}
#endregion
#region contains
/// <summary>
/// Check if item in collection
/// </summary>
/// <param name="obj"></param>
public bool Contains(ClientNotesReportListInfo obj)
{
foreach (ClientNotesReportListInfo child in List)
{
if(child.Equals(obj)) return true;
}
return false;
}
#endregion
#region Static methods
/// <summary>
/// Get list of notes for client id passed in
/// </summary>
/// <param name="ClientID"></param>
/// <returns>list of <see cref="ClientNotesReportList.ClientNotesReportListInfo"/> objects</returns>
public static ClientNotesReportList GetList(Guid ClientID)
{
return (ClientNotesReportList) DataPortal.Fetch(new Criteria(ClientID,null));
}
/// <summary>
/// Get list of notes by items indicated in IDList
/// </summary>
/// <param name="IDList">Generic list of ClientNote.ID Guid's</param>
/// <returns>list of <see cref="ClientNotesReportList.ClientNotesReportListInfo"/> objects</returns>
public static ClientNotesReportList GetListFromIDList(List<Guid> IDList)
{
//case 274
//Handle empty list
if (IDList.Count == 0)
return new ClientNotesReportList();
return (ClientNotesReportList)DataPortal.Fetch(new Criteria(Guid.Empty, IDList));
}
#endregion
#region DAL DATA ACCESS
/// <summary>
/// Fetch children
/// </summary>
/// <param name="Criteria"></param>
protected override void DataPortal_Fetch(object Criteria)
{
//cached user name list
UserPickList users = UserPickList.GetList(false);
Criteria crit = (Criteria)Criteria;
SafeDataReader dr = null;
try
{
string q = "SELECT ACLIENTNOTE.*, ACLIENT.ANAME AS ACLIENTNAME, " +
"ACLIENTNOTETYPE.ANAME AS ACLIENTNOTETYPENAME " +
"FROM ACLIENTNOTE " +
"LEFT OUTER JOIN ACLIENT ON (ACLIENT.AID = ACLIENTNOTE.ACLIENTID) " +
"LEFT OUTER JOIN ACLIENTNOTETYPE ON (ACLIENTNOTETYPE.AID = ACLIENTNOTE.ACLIENTNOTETYPEID) ";
if (crit.IDList != null)
{
System.Text.StringBuilder sbIN = new System.Text.StringBuilder();
sbIN.Append(" WHERE aClientNote.aID in (");
foreach (Guid gItem in crit.IDList)
{
sbIN.Append("'");
sbIN.Append("{");
sbIN.Append(gItem.ToString().ToUpperInvariant());
sbIN.Append("}");
sbIN.Append("',");
}
sbIN.Length = sbIN.Length - 1;
sbIN.Append(") ");
dr = DBUtil.GetReaderFromSQLString(q + sbIN.ToString() + " ORDER BY ANOTEDATE DESC");
}
else
{
dr = DBUtil.GetReaderFromSQLString(q + " WHERE aClientID=@ID ORDER BY ANOTEDATE DESC", crit.ClientID);
}
while (dr.Read())
{
ClientNotesReportListInfo info = new ClientNotesReportListInfo();
info.mID = dr.GetGuid("AID");
info.mCreator = users[dr.GetGuid("ACREATOR")];
info.mCreated = DBUtil.ToLocal(dr.GetSmartDate("ACREATED"));
info.mNoteDate = DBUtil.ToLocal(dr.GetSmartDate("ANOTEDATE"));
info.mNotes = dr.GetString("ANOTES");
info.mClientNoteType = dr.GetString("ACLIENTNOTETYPENAME");
info.mClient = dr.GetString("ACLIENTNAME");
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 ClientID;
public List<Guid> IDList;
public Criteria(Guid _ClientID, List<Guid> _IDList)
{
ClientID = _ClientID;
IDList = _IDList;
}
}
#endregion
}//end ClientNotesReportList
#pragma warning restore 1591
}//end namespace GZTW.AyaNova.BLL