///////////////////////////////////////////////////////////
// ClientNoteList.cs
// Implementation of Class ClientNoteList
// CSLA type: Read only collection
// Created on: 18-FEB-2015
// Object design: John
// Coded: 18-FEB-2015
///////////////////////////////////////////////////////////
//created for case 1975
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 objects.
/// Used for display in responsive interface (AyaNova RI)
///
[Serializable]
public class ClientNoteList : ReadOnlyCollectionBase
{
#region Data structure
///
/// Properties
///
[Serializable]
public struct ClientNoteListInfo
{
internal string mCreator;
internal string mNoteDate;
internal string mNotes;
internal string mClientNoteType;
internal decimal mTotal;
internal Guid mId;
public string Creator
{ get { return mCreator; } }
public string NoteDate
{ get { return mNoteDate; } }
public string Notes
{ get { return mNotes; } }
public string ClientNoteType
{ get { return mClientNoteType; } }
public decimal Total
{ get { return mTotal; } }
public Guid Id
{ get { return mId; } }
}//end ClientNoteListInfo
#endregion
#region Constructor
protected ClientNoteList()
{
}
#endregion
#region Business properties and methods
/////
///// Get item by index
/////
/////
//public ClientNoteListInfo this[int Item]
//{
// get
// {
// return (ClientNoteListInfo)List[Item];
// }
//}
#endregion
#region Static methods
//case 1975
///
/// Get MaxRecords Client notes for specified client (-1 for all)
///
public static ClientNoteList GetList(Guid ClientID, int MaxRecords)
{
return (ClientNoteList)DataPortal.Fetch(new Criteria(ClientID, MaxRecords));
}
#endregion
#region DAL DATA ACCESS
///
///
protected override void DataPortal_Fetch(object Criteria)
{
Criteria crit = (Criteria)Criteria;
SafeDataReader dr = null;
try
{
decimal dTotal=DBUtil.ScalarToDecimal(DBUtil.GetScalarFromSQLString("SELECT COUNT(AID) FROM ACLIENTNOTE WHERE ACLIENTNOTE.ACLIENTID=@ID", crit.ClientID));
string q = "SELECT ~MAXRECS~ ACLIENTNOTE.AID AS ACLIENTNOTEID, ACLIENTNOTE.ANOTEDATE, ACLIENTNOTE.ANOTES, " +
" AUSER.AFIRSTNAME, AUSER.ALASTNAME, " +
" AUSER.AINITIALS, AUSER.AEMPLOYEENUMBER, " +
" ACLIENTNOTETYPE.ANAME AS ACLIENTNOTETYPENAME " +
" FROM ACLIENTNOTE " +
" INNER JOIN AUSER ON (ACLIENTNOTE.ACREATOR = AUSER.AID)" +
" LEFT OUTER JOIN ACLIENTNOTETYPE ON (ACLIENTNOTE.ACLIENTNOTETYPEID=ACLIENTNOTETYPE.AID) " +
" WHERE ACLIENTNOTE.ACLIENTID=@ID " +
" ORDER BY ANOTEDATE DESC";
if (crit.MaxRecords > 0)
q = q.Replace("~MAXRECS~", "TOP " + crit.MaxRecords.ToString());
else
q = q.Replace("~MAXRECS~", "");
dr = DBUtil.GetReaderFromSQLString(q, crit.ClientID);
//************************************************************
bool bFirst = true;
while (dr.Read())
{
//*******************************************
ClientNoteListInfo info = new ClientNoteListInfo();
info.mId = dr.GetGuid("ACLIENTNOTEID");
info.mCreator = User.NameFormatter(dr.GetString("aFirstName"), dr.GetString("aLastName"),
dr.GetString("aInitials"), dr.GetString("aEmployeeNumber"), "",
AyaBizUtils.GlobalSettings.DefaultScheduleableUserNameDisplayFormat);
info.mClientNoteType = dr.GetString("ACLIENTNOTETYPENAME");
info.mNoteDate = DBUtil.ToLocal(dr.GetSmartDate("ANOTEDATE")).ToString();
info.mNotes = dr.GetString("ANOTES");
if (bFirst)
{
info.mTotal = dTotal;
bFirst = false;
}
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 int MaxRecords;
public Criteria(Guid _ClientID, int _MaxRecords)
{
ClientID = _ClientID;
MaxRecords = _MaxRecords;
}
}
#endregion
}//end ClientNoteList
#pragma warning restore 1591
}//end namespace GZTW.AyaNova.BLL