173 lines
6.1 KiB
C#
173 lines
6.1 KiB
C#
///////////////////////////////////////////////////////////
|
|
// DashboardReminderListRI.cs
|
|
// Implementation of Class DashboardReminderListRI
|
|
// 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.Collections.Generic;
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
#pragma warning disable 1591
|
|
/// <summary>
|
|
/// A list of reminders (schedule markers) for populating the web dashboard in AyaNova RI
|
|
/// (Read only collection )
|
|
/// </summary>
|
|
[Serializable]
|
|
public class DashboardReminderListRI : ReadOnlyBase
|
|
{
|
|
public long _Count = 0;
|
|
public Dictionary<Guid, string> list = null;
|
|
|
|
#region Constructor
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
protected DashboardReminderListRI()
|
|
{
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Static methods
|
|
|
|
public static Dictionary<Guid, string> GetList(int MaxRecords = 3)
|
|
{
|
|
return ((DashboardReminderListRI)DataPortal.Fetch(new Criteria(false, MaxRecords))).list;
|
|
}
|
|
|
|
public static long GetCount()
|
|
{
|
|
return ((DashboardReminderListRI)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;
|
|
UserListScheduleable uls = UserListScheduleable.GetList();
|
|
Guid activeUserId = User.CurrentThreadUserID;
|
|
try
|
|
{
|
|
DBCommandWrapper cm = null;
|
|
string qFields = "";
|
|
qFields = "SELECT ~MAXRECS~ AID, ANAME, ASTARTDATE, ASOURCEID, ASCHEDULEMARKERSOURCETYPE ";
|
|
string q = qFields + "FROM ASCHEDULEMARKER WHERE (ASTARTDATE > @RIGHTNOW) ORDER BY ASTARTDATE ";
|
|
|
|
//bugbug: because it's fetching all types then seeing which apply you can't restrict it this way
|
|
//if (crit.MaxRecords > 0)
|
|
// q = q.Replace("~MAXRECS~", "TOP " + crit.MaxRecords.ToString());
|
|
//else
|
|
q = q.Replace("~MAXRECS~", "");
|
|
|
|
cm = DBUtil.DB.GetSqlStringCommandWrapper(q);
|
|
cm.AddInParameter("@RIGHTNOW", DbType.DateTime, DBUtil.ToUTC(DBUtil.CurrentWorkingDateTime));
|
|
dr = new SafeDataReader(DBUtil.DB.ExecuteReader(cm));
|
|
if (!crit.Count)
|
|
list = new Dictionary<Guid, string>(crit.MaxRecords);
|
|
while (dr.Read())
|
|
{
|
|
if (relevantScheduleMarker(activeUserId, (ScheduleMarkerSourceTypes)dr.GetInt16("aScheduleMarkerSourceType"), dr.GetGuid("ASOURCEID"), uls))
|
|
{
|
|
_Count++;
|
|
if (!crit.Count)
|
|
{
|
|
list.Add(dr.GetGuid("AID"), DBUtil.ToLocal(dr.GetSmartDate("ASTARTDATE")).ToString() + " " + dr.GetString("ANAME"));
|
|
if (_Count >= crit.MaxRecords)
|
|
break;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if (dr != null) dr.Close();
|
|
}
|
|
}
|
|
|
|
|
|
private static bool relevantScheduleMarker(Guid activeUserId, ScheduleMarkerSourceTypes appliesToObjectType, Guid appliesToObjectId, UserListScheduleable uls)
|
|
{
|
|
//appliesToObjectId==aSourceId
|
|
//ScheduleMarkerSourceTypes smt=(ScheduleMarkerSourceTypes)dr.GetInt16("aScheduleMarkerSourceType");
|
|
|
|
//Don't process for unassigned user
|
|
if (activeUserId == Guid.Empty) return false;
|
|
|
|
//Could be a bunch by region , global , dispatchzone, schedusergroup
|
|
//or could be a single by one user ID
|
|
switch (appliesToObjectType)
|
|
{
|
|
case ScheduleMarkerSourceTypes.User:
|
|
{
|
|
if (appliesToObjectId == activeUserId)
|
|
return true;
|
|
}
|
|
break;
|
|
case ScheduleMarkerSourceTypes.Regional:
|
|
{
|
|
if (uls[activeUserId].RegionID == appliesToObjectId)
|
|
return true;
|
|
}
|
|
break;
|
|
case ScheduleMarkerSourceTypes.DispatchZone:
|
|
{
|
|
if (uls[activeUserId].DispatchZoneID == appliesToObjectId)
|
|
return true;
|
|
}
|
|
break;
|
|
case ScheduleMarkerSourceTypes.ScheduleableUserGroup:
|
|
{
|
|
ScheduleableUserGroupUsersList ScheduleMarkerGroup = ScheduleableUserGroupUsersList.GetList(appliesToObjectId);
|
|
if (ScheduleMarkerGroup.Contains(activeUserId))//Case 835
|
|
return true;
|
|
}
|
|
break;
|
|
case ScheduleMarkerSourceTypes.Global:
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
#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 DashboardReminderListRI
|
|
#pragma warning restore 1591
|
|
}//end namespace GZTW.AyaNova.BLL
|