/////////////////////////////////////////////////////////// // 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 /// /// Read only list of objects representing ClientNotes used for reporting (printing) client notes /// /// /// [Serializable] public class ClientNotesReportList : ReadOnlyCollectionBase { #region Data structure /// /// Properties /// [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; } } /// /// /// /// 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 /// /// Get item by index /// /// public ClientNotesReportListInfo this[int Item] { get { return (ClientNotesReportListInfo) List[Item]; } } /// /// Returns display text that matches passed in itemid value /// /// 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 /// /// Returns the report key which is a property of /// reports used to link all reports that can be used /// with a particular data source. /// public static string ReportKey { get { return "ClientNote"; } } #endregion #region contains /// /// Check if item in collection /// /// public bool Contains(ClientNotesReportListInfo obj) { foreach (ClientNotesReportListInfo child in List) { if(child.Equals(obj)) return true; } return false; } #endregion #region Static methods /// /// Get list of notes for client id passed in /// /// /// list of objects public static ClientNotesReportList GetList(Guid ClientID) { return (ClientNotesReportList) DataPortal.Fetch(new Criteria(ClientID,null)); } /// /// Get list of notes by items indicated in IDList /// /// Generic list of ClientNote.ID Guid's /// list of objects public static ClientNotesReportList GetListFromIDList(List 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 /// /// Fetch children /// /// 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 /// /// Criteria for identifying existing object /// [Serializable] private class Criteria { public Guid ClientID; public List IDList; public Criteria(Guid _ClientID, List _IDList) { ClientID = _ClientID; IDList = _IDList; } } #endregion }//end ClientNotesReportList #pragma warning restore 1591 }//end namespace GZTW.AyaNova.BLL