144 lines
5.0 KiB
C#
144 lines
5.0 KiB
C#
///////////////////////////////////////////////////////////
|
|
// DashBoardMemoListRI.cs
|
|
// Implementation of Class DashBoardMemoListRI
|
|
// CSLA type: Read only collection
|
|
// Created on: 25-Sept-2014
|
|
// Object design: John
|
|
// Coded: 25-Sept-2014
|
|
///////////////////////////////////////////////////////////
|
|
|
|
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 objects representing <see cref="Memo"/> object
|
|
/// used internally for Web dashboard
|
|
///
|
|
/// </summary>
|
|
[Serializable]
|
|
public class DashBoardMemoListRI : ReadOnlyBase
|
|
{
|
|
public long _Count = 0;
|
|
public Dictionary<Guid, string> list = null;
|
|
|
|
#region Constructor
|
|
protected DashBoardMemoListRI()
|
|
{
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
public static Dictionary<Guid, string> GetList(int MaxRecords = 3)
|
|
{
|
|
return ((DashBoardMemoListRI)DataPortal.Fetch(new Criteria(false, MaxRecords))).list;
|
|
}
|
|
|
|
public static long GetCount()
|
|
{
|
|
return ((DashBoardMemoListRI)DataPortal.Fetch(new Criteria(true, 0)))._Count;
|
|
}
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
///
|
|
/// <param name="Criteria"></param>
|
|
protected override void DataPortal_Fetch(object Criteria)
|
|
{
|
|
|
|
Criteria crit = (Criteria)Criteria;
|
|
|
|
SafeDataReader dr = null;
|
|
DateTime dtNow = DBUtil.CurrentWorkingDateTime;
|
|
try
|
|
{
|
|
DBCommandWrapper cm = null;
|
|
string qFields = "";
|
|
if (crit.Count)
|
|
qFields = "SELECT COUNT(*) ";
|
|
else
|
|
qFields = "SELECT ~MAXRECS~ AMEMO.AID AS AMEMOID, AMEMO.ACREATED, " +
|
|
"AMEMO.AVIEWED, AMEMO.ASUBJECT, " +
|
|
"AMEMO.AFROMID, AUSER.AFIRSTNAME, AUSER.ALASTNAME, AUSER.AINITIALS, AREGION.ANAME AS AREGIONNAME, " +
|
|
"AUSER.AEMPLOYEENUMBER ";
|
|
|
|
string q = qFields + " FROM AMEMO " +
|
|
" LEFT OUTER JOIN AUSER ON AMEMO.AFROMID = AUSER.AID " +
|
|
" LEFT OUTER JOIN AREGION ON (AUSER.AREGIONID=AREGION.AID) " +
|
|
" WHERE (AMEMO.ATOID = @ID) " ;
|
|
|
|
if (!crit.Count)
|
|
q = q + "ORDER BY AMEMO.ACREATED ";
|
|
|
|
if (!crit.Count)
|
|
{
|
|
if (crit.MaxRecords > 0)
|
|
q = q.Replace("~MAXRECS~", "TOP " + crit.MaxRecords.ToString());
|
|
else
|
|
q = q.Replace("~MAXRECS~", "");
|
|
}
|
|
|
|
cm = DBUtil.DB.GetSqlStringCommandWrapper(q);
|
|
cm.AddInParameter("@ID",DbType.Guid,User.CurrentThreadUserID);
|
|
dr = new SafeDataReader(DBUtil.DB.ExecuteReader(cm));
|
|
if (!crit.Count)
|
|
list = new Dictionary<Guid, string>(crit.MaxRecords);
|
|
while (dr.Read())
|
|
{
|
|
if (crit.Count)
|
|
{
|
|
object o = dr.GetValue(0);
|
|
_Count = long.Parse(o.ToString());
|
|
}
|
|
else
|
|
{
|
|
//id = new TypeAndID(RootObjectTypes.Memo, i.ID);
|
|
//item = i.LT_Memo_Label_Sent.ToString() + " " + i.LT_Memo_Label_FromID.Display + " " + i.LT_Memo_Label_Subject;
|
|
//created + " " + from uyser " " subject
|
|
|
|
list.Add(dr.GetGuid("AMEMOID"),
|
|
DBUtil.ToLocal(dr.GetSmartDate("ACREATED")).ToString() + " " +
|
|
User.NameFormatter(dr.GetString("AFIRSTNAME"), dr.GetString("ALASTNAME"), dr.GetString("AINITIALS"),
|
|
dr.GetString("AEMPLOYEENUMBER"), dr.GetString("AREGIONNAME"), AyaBizUtils.GlobalSettings.DefaultScheduleableUserNameDisplayFormat) + " " +
|
|
dr.GetString("ASUBJECT")
|
|
);
|
|
_Count++;
|
|
}
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if (dr != null) dr.Close();
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region criteria
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[Serializable]
|
|
private class Criteria
|
|
{
|
|
public bool Count;
|
|
public int MaxRecords;
|
|
public Criteria(bool count, int maxRecords)
|
|
{
|
|
MaxRecords = maxRecords;
|
|
Count = count;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
}//end DashBoardMemoListRI
|
|
#pragma warning restore 1591
|
|
}//end namespace GZTW.AyaNova.BLL
|