217 lines
7.0 KiB
C#
217 lines
7.0 KiB
C#
///////////////////////////////////////////////////////////
|
|
// MemoListRi.cs
|
|
// Implementation of Class MemoListRi
|
|
// CSLA type: Read only collection
|
|
// Created on: 19-March-2015
|
|
// Object design: John
|
|
// Coded: 19-March-2015
|
|
///////////////////////////////////////////////////////////
|
|
//created for case 1975
|
|
using System;
|
|
using System.Data;
|
|
using GZTW.Data;
|
|
using CSLA.Data;
|
|
using CSLA;
|
|
using System.Threading;
|
|
using CSLA.Security;
|
|
using System.Collections.Generic;
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
#pragma warning disable 1591
|
|
/// <summary>
|
|
/// Lightweight read only list of <see cref="MemoListRi.MemoListRiInfo"/> objects representing <see cref="Memo"/> object
|
|
///
|
|
/// </summary>
|
|
[Serializable]
|
|
public class MemoListRi : ReadOnlyCollectionBase
|
|
{
|
|
|
|
|
|
#region Data structure
|
|
/// <summary>
|
|
/// Properties
|
|
/// </summary>
|
|
[Serializable]
|
|
public struct MemoListRiInfo
|
|
{
|
|
internal Guid mID;
|
|
internal string mCreated;
|
|
internal string mSubject;
|
|
internal string mFrom;
|
|
internal bool mViewed;
|
|
internal bool mReplied;
|
|
internal decimal mTotal;
|
|
|
|
public Guid ID { get {return mID;}}
|
|
public string Created {get{return mCreated;}}
|
|
public string From {get{return mFrom;}}
|
|
public string Subject {get{return mSubject;}}
|
|
public bool Viewed { get { return mViewed; } }
|
|
public bool Replied { get { return mReplied; } }
|
|
public decimal Total { get { return mTotal; } }
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Equals(MemoListRiInfo obj)
|
|
{
|
|
return this.ID.Equals(obj.ID);
|
|
}
|
|
|
|
}//end MemoListRiInfo
|
|
#endregion
|
|
|
|
#region Constructor
|
|
//private RelativeTimeFormatter rtfm=null;
|
|
|
|
protected MemoListRi()
|
|
{
|
|
|
|
//rtfm=RelativeTimeFormatter.GetItem(User.CurrentUserLanguage);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Business properties and methods
|
|
|
|
/// <summary>
|
|
/// Get item by index
|
|
/// </summary>
|
|
/// <param name="Item"></param>
|
|
public MemoListRiInfo this[int Item]
|
|
{
|
|
|
|
get
|
|
{
|
|
return (MemoListRiInfo)List[Item];
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Returns display text that matches passed in itemid value
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
public string this[Guid ItemID]
|
|
{
|
|
|
|
get
|
|
{
|
|
foreach (MemoListRiInfo child in List)
|
|
{
|
|
if (child.ID == 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(MemoListRiInfo obj)
|
|
{
|
|
foreach (MemoListRiInfo child in List)
|
|
{
|
|
if (child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
//case 1975
|
|
/// <summary>
|
|
/// Get MaxRecords Client notes for specified client (-1 for all)
|
|
/// </summary>
|
|
public static MemoListRi GetList(int MaxRecords)
|
|
{
|
|
return (MemoListRi)DataPortal.Fetch(new Criteria(MaxRecords));
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
///
|
|
/// <param name="Criteria"></param>
|
|
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 aMemo WHERE aMemo.aToID=@ID", CurrentUserID));
|
|
|
|
//************************************************************
|
|
string q = "SELECT ~MAXRECS~ aMemo.aID, aMemo.aCreated, " +
|
|
"aMemo.aViewed, aMemo.aReplied, aMemo.aSubject, " +
|
|
"aMemo.aFromID, aUser.aFirstName, aUser.aLastName, aUser.aInitials, AREGION.ANAME AS AREGIONNAME, " +
|
|
"aUser.aEmployeeNumber FROM aMemo " +
|
|
" LEFT OUTER JOIN aUser ON aMemo.aFromID = aUser.aID " +
|
|
" LEFT OUTER JOIN AREGION ON (AUSER.AREGIONID=AREGION.AID) " +
|
|
"WHERE (aMemo.aToID = @ID) " +
|
|
"ORDER BY AMEMO.ACREATED DESC;";
|
|
//************************************************************
|
|
|
|
if (crit.MaxRecords > 0)
|
|
q = q.Replace("~MAXRECS~", "TOP " + crit.MaxRecords.ToString());
|
|
else
|
|
q = q.Replace("~MAXRECS~", "");
|
|
|
|
dr = DBUtil.GetReaderFromSQLString(q, CurrentUserID);
|
|
bool bFirst = true;
|
|
while (dr.Read())
|
|
{
|
|
//*******************************************
|
|
MemoListRiInfo info = new MemoListRiInfo();
|
|
info.mID = dr.GetGuid("aID");
|
|
info.mCreated = DBUtil.ToLocal(dr.GetSmartDate("aCreated")).ToString();
|
|
info.mFrom = User.NameFormatter(dr.GetString("aFirstName"), dr.GetString("aLastName"), dr.GetString("aInitials"),
|
|
dr.GetString("aEmployeeNumber"), dr.GetString("AREGIONNAME"), AyaBizUtils.GlobalSettings.DefaultScheduleableUserNameDisplayFormat);
|
|
info.mSubject = dr.GetString("aSubject");
|
|
info.mViewed = dr.GetBoolean("aViewed");
|
|
info.mReplied = dr.GetBoolean("aReplied");
|
|
if (bFirst)
|
|
{
|
|
info.mTotal = dTotal;
|
|
bFirst = false;
|
|
}
|
|
InnerList.Add(info);
|
|
//*******************************************
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if (dr != null) dr.Close();
|
|
}
|
|
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region criteria
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[Serializable]
|
|
private class Criteria
|
|
{
|
|
public int MaxRecords;
|
|
public Criteria(int _MaxRecords)
|
|
{
|
|
MaxRecords = _MaxRecords;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
}//end MemoListRi
|
|
#pragma warning restore 1591
|
|
}//end namespace GZTW.AyaNova.BLL |