Files
ayanova7/source/bizobjects/AyaLib/GZTW.AyaNova.BLL/DashboardReminderList.cs
2018-06-29 19:47:36 +00:00

381 lines
11 KiB
C#

///////////////////////////////////////////////////////////
// DashboardReminderList.cs
// Implementation of Class DashboardReminderList
// CSLA type: Read only collection
// Created on: 10-Jan-2012
// Object design: John
// Coded: 10-Jan-2012
///////////////////////////////////////////////////////////
using System;
using System.Data;
using GZTW.Data;
using CSLA.Data;
using CSLA;
using System.Text.RegularExpressions;
using System.Threading;
using CSLA.Security;
namespace GZTW.AyaNova.BLL
{
/// <summary>
/// A list of reminders (schedule markers) for populating the dashboard in AyaNova
/// (Read only collection )
/// </summary>
[Serializable]
public class DashboardReminderList : ReadOnlyCollectionBase
{
#region Data structure
/// <summary>
///
/// </summary>
[Serializable]
public struct DashboardReminderListInfo
{
//used to indicate there is nothing in this
//struct
internal bool mIsEmpty;
//internal Guid mWorkorderID;
//internal Guid mWorkorderItemID;
//internal int mServiceNumber;
internal RootObjectTypes mAppliesToObjectType;
internal Guid mAppliesToObjectID;
internal RootObjectTypes mSourceObjectType;
//This is the workorderitemscheduleduser record ID
internal Guid mSourceObjectID;
internal string mSubject;
internal string mDetails;
internal DateTime mStartDateTime;
internal DateTime mEndDateTime;
internal bool mAllDay;
//If
internal bool mShowPriorityFlag;
internal int mPriorityARGB;
internal int mBackColorARGB;
#pragma warning disable 1591
/// <summary>
/// true if there is nothing in this record
/// false if this record contains a valid appointment
/// </summary>
public bool IsEmpty {get{return mIsEmpty;}set{mIsEmpty=value;}}
/// <summary>
/// What object type this appointment applies to, can be single user
/// or another object type that represents a group of users
/// such as: region, sched user group etc etc
/// </summary>
public RootObjectTypes AppliesToObjectType{get{return mAppliesToObjectType;}}
/// <summary>
/// Object ID appointment applies to
/// </summary>
public Guid AppliesToObjectID{get{return mAppliesToObjectID;}}
/// <summary>
/// Type of appointment
/// either ScheduleMarker or WorkorderItemScheduledUser
/// </summary>
public RootObjectTypes SourceObjectType{get{return mSourceObjectType;}}
/// <summary>
/// The ID of the schedulemarker or workorderitemscheduleduser object
/// </summary>
public Guid SourceObjectID {get{return mSourceObjectID;}}
///// <summary>
///// ID of workorder if this appointment is a scheduled workorder user
///// </summary>
//public Guid WorkorderID {get{return mWorkorderID;}}
///// <summary>
///// ID of workorder item if this appointment is a scheduled workorder user
///// </summary>
//public Guid WorkorderItemID {get{return mWorkorderItemID;}}
///// <summary>
///// Visible sequential workorder number of workorder
///// if this appointment is a scheduled workorder user
///// </summary>
//public int ServiceNumber {get{return mServiceNumber;}}
/// <summary>
/// Description of appointment, either a schedulemarker
/// description or a summary of the workorder
/// formatted according to the workorder
/// </summary>
public string Subject {get{return mSubject;}}
public string Details {get{return mDetails;}}
public DateTime StartDateTime {get{return mStartDateTime;}}
public DateTime EndDateTime {get{return mEndDateTime;}}
public bool AllDay {get{return mAllDay;}}
public int PriorityARGB {get{return mPriorityARGB;}}
public bool ShowPriorityFlag {get{return mShowPriorityFlag;}}
/// <summary>
/// Back color of appointment
/// could be workorder status or schedmarker colour
/// </summary>
public int BackColorARGB {get{return mBackColorARGB;} }
#pragma warning restore 1591
/// <summary>
///
/// </summary>
/// <param name="obj"></param>
public bool Equals(DashboardReminderListInfo obj)
{
return this.mSourceObjectID.Equals(obj.mSourceObjectID);
}
}//end DashboardReminderListInfo
#endregion
#region Constructor
/// <summary>
///
/// </summary>
protected DashboardReminderList()
{
// AllowSort=false;
// AllowFind=true;
// AllowEdit=false;
// AllowNew=false;
// AllowRemove=false;
}
#endregion
#region Business properties and methods
/// <summary>
/// Get item by index
/// </summary>
/// <param name="Item"></param>
public DashboardReminderListInfo this[int Item]
{
get
{
return (DashboardReminderListInfo) List[Item];
}
}
/// <summary>
/// Returns DashboardReminderListInfo item that matches passed in itemid value
/// </summary>
/// <param name="o"></param>
public DashboardReminderListInfo this[Guid o]
{
get
{
foreach (DashboardReminderListInfo child in List)
{
if(child.mSourceObjectID==o) return child;
}
throw new ArgumentException("DashboardReminderList: SourceObjectID not found\r\n");
}
}
#endregion
#region contains
/// <summary>
/// Check if item in collection
/// </summary>
/// <param name="obj"></param>
public bool Contains(DashboardReminderListInfo obj)
{
foreach (DashboardReminderListInfo child in List)
{
if(child.Equals(obj)) return true;
}
return false;
}
#endregion
#region Static methods
/// <summary>
/// Get list of <see cref="DashboardReminderListInfo"/> objects.
/// Returns list of closest upcoming reminders for currently logged in user
///
/// </summary>
/// <param name="MaximumItemsToRetrieve">What it says</param>
/// <returns>A read only collection of <see cref="DashboardReminderListInfo"/> objects (ScheduleMarkers)</returns>
public static DashboardReminderList GetList(int MaximumItemsToRetrieve)
{
return (DashboardReminderList)DataPortal.Fetch(new Criteria(MaximumItemsToRetrieve));
}
#endregion
#region DAL DATA ACCESS
///
/// <param name="Criteria"></param>
protected override void DataPortal_Fetch(object Criteria)
{
System.Collections.Generic.List<string> ListOfAppointmentSubjects = new System.Collections.Generic.List<string>();
Criteria crit = (Criteria)Criteria;
SafeDataReader dr = null;
UserListScheduleable ulist = UserListScheduleable.GetList();
try
{
#region Schedule markers
//Not filtered by user if specific user is specified which is what we want
//next query
DBCommandWrapper cmSM = DBUtil.DB.GetSqlStringCommandWrapper(
"SELECT aScheduleMarkerSourceType, aSourceID,aID,aNotes,aName, " +
"aStopDate,aStartDate, AARGB FROM aScheduleMarker " +
"WHERE (aStartDate > @CurrentDateTime) ORDER BY ASTARTDATE "
);
//Add parameters
cmSM.AddInParameter("@CurrentDateTime", DbType.DateTime, DBUtil.ToUTC(DBUtil.CurrentWorkingDateTime));
dr=new SafeDataReader(DBUtil.DB.ExecuteReader(cmSM));
while (dr.Read())
{
DashboardReminderListInfo info=new DashboardReminderListInfo();
info.mAllDay=false;
info.mIsEmpty=false;
ScheduleMarkerSourceTypes smt=(ScheduleMarkerSourceTypes)dr.GetInt16("aScheduleMarkerSourceType");
info.mAppliesToObjectID = dr.GetGuid("aSourceID");
switch(smt)
{
case ScheduleMarkerSourceTypes.User:
info.mAppliesToObjectType=RootObjectTypes.User;
//screen the user to make sure they are scheduleable and active && are the current logged in user //case 1963
//If not, skip 'em
if (info.mAppliesToObjectID != Guid.Empty &&
info.mAppliesToObjectID != ScheduleMarker.ScheduleMarkerGlobalSourceID)//is it a user?
{
//case 1963 changed following, not sure why it was done that way, completely wrong
//if(!ulist.ContainsActiveUser(dr.GetGuid("aSourceID")))
if(info.mAppliesToObjectID!= User.CurrentThreadUserID)
continue;
}
break;
case ScheduleMarkerSourceTypes.Regional:
//Case 58
//If it applies to a specific region besides default and the current user is not default region and the applies to region id is not
//the current users then don't show it
if ((info.mAppliesToObjectID!=Region.DefaultRegionID) && (User.CurrentUserRegionID != Region.DefaultRegionID) && info.mAppliesToObjectID != User.CurrentUserRegionID)
continue;
info.mAppliesToObjectType=RootObjectTypes.Region;
break;
case ScheduleMarkerSourceTypes.Global:
info.mAppliesToObjectType=RootObjectTypes.Global;
break;
case ScheduleMarkerSourceTypes.DispatchZone:
info.mAppliesToObjectType=RootObjectTypes.DispatchZone;
break;
case ScheduleMarkerSourceTypes.ScheduleableUserGroup:
info.mAppliesToObjectType=RootObjectTypes.ScheduleableUserGroup;
break;
}
info.mSourceObjectType=RootObjectTypes.ScheduleMarker;
info.mSourceObjectID=dr.GetGuid("aID");
info.mDetails=dr.GetString("aNotes");
info.mSubject=dr.GetString("aName");
info.mEndDateTime=DBUtil.ToLocal(dr.GetDateTime("aStopDate"));
info.mStartDateTime=DBUtil.ToLocal(dr.GetDateTime("aStartDate"));
//priority doesn't apply here, but don't
//leave it dangling
info.mShowPriorityFlag=false;
info.mPriorityARGB=0;
info.mBackColorARGB=dr.GetInt32("AARGB");
InnerList.Add(info);
}
#endregion schedulemarkers
}
finally
{
if(dr!=null) dr.Close();
}
}
#endregion
#region criteria
/// <summary>
/// Criteria for identifying existing object
/// </summary>
[Serializable]
private class Criteria
{
public int MaximumItemsToRetrieve;
public Criteria(int _MaximumItemsToRetrieve)
{
MaximumItemsToRetrieve = _MaximumItemsToRetrieve;
}
}
#endregion
}//end DashboardReminderList
}//end namespace GZTW.AyaNova.BLL