253 lines
8.7 KiB
C#
253 lines
8.7 KiB
C#
///////////////////////////////////////////////////////////
|
|
// FollowUpListForUser.cs
|
|
// Implementation of Class FollowUpListForUser
|
|
// CSLA type: Read only collection
|
|
// Created on: 24-Sept-2015
|
|
// Object design: John
|
|
// Coded: 24-Sept-2015
|
|
///////////////////////////////////////////////////////////
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Data;
|
|
using GZTW.Data;
|
|
using CSLA.Data;
|
|
using CSLA;
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
/// Internal utility class used to send a list of outstanding follow ups
|
|
/// for a user to the manager account via memo
|
|
/// </summary>
|
|
[Serializable(), System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never), System.ComponentModel.Browsable(false)]
|
|
public class FollowUpListForUser : ReadOnlyCollectionBase
|
|
{
|
|
#pragma warning disable 1591
|
|
|
|
#region Data structure
|
|
[Serializable]
|
|
public struct FollowUpListForUserInfo
|
|
{
|
|
|
|
internal Guid mID;
|
|
internal string mName;
|
|
internal string mNotes;
|
|
internal string mTechName;
|
|
internal string mFollowObjectName;
|
|
internal TypeAndID mFollowObject;
|
|
internal int mARGB;
|
|
internal DateTime mStartDateTime;
|
|
internal DateTime mEndDateTime;
|
|
|
|
|
|
public Guid ID { get { return mID; } }
|
|
public string Name { get { return mName; } }
|
|
public string Notes { get { return mNotes; } }
|
|
public string TechName { get { return mTechName; } }
|
|
public string FollowObjectName { get { return mFollowObjectName; } }
|
|
public TypeAndID FollowObject { get { return mFollowObject; } }
|
|
public int ARGB { get { return mARGB; } }
|
|
public DateTime StartDateTime { get { return mStartDateTime; } }
|
|
public DateTime EndDateTime { get { return mEndDateTime; } }
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Equals(FollowUpListForUserInfo obj)
|
|
{
|
|
return this.mID.Equals(obj.mID);
|
|
}
|
|
|
|
}//end FollowUpListForUserInfo
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
protected FollowUpListForUser()
|
|
{
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Business properties and methods
|
|
|
|
/// <summary>
|
|
/// Get item by index
|
|
/// </summary>
|
|
/// <param name="Item"></param>
|
|
public FollowUpListForUserInfo this[int Item]
|
|
{
|
|
|
|
get
|
|
{
|
|
return (FollowUpListForUserInfo)List[Item];
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Returns FollowUpListForUserInfo item that matches passed in itemid value
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
public FollowUpListForUserInfo this[Guid ItemID]
|
|
{
|
|
|
|
get
|
|
{
|
|
foreach (FollowUpListForUserInfo child in List)
|
|
{
|
|
if (child.mID == ItemID) return child;
|
|
}
|
|
throw new ArgumentException("FollowUpListForUser: ID not found:\r\n" + ItemID.ToString());
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region contains
|
|
/// <summary>
|
|
/// Check if item in collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Contains(FollowUpListForUserInfo obj)
|
|
{
|
|
foreach (FollowUpListForUserInfo child in List)
|
|
{
|
|
if (child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// Get all follow ups for user specified that have a stop date and time
|
|
/// which is in the future and send them to the Manager account via memo
|
|
///
|
|
/// </summary>
|
|
/// <returns>list of <see cref="FollowUpListForUser.FollowUpListForUserInfo"/> objects</returns>
|
|
[ System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never), System.ComponentModel.Browsable(false)]
|
|
public static void SendListViaMemoToManager(Guid userID)
|
|
{
|
|
System.Text.StringBuilder sb = new StringBuilder();
|
|
if (userID == Guid.Empty)
|
|
throw new System.ApplicationException("FollowUpListForUser->GetList: Error userID is empty");
|
|
|
|
string sUserName=UserPickList.GetListOfOneSpecificUser(userID)[0].Name;
|
|
|
|
FollowUpListForUser l= (FollowUpListForUser)DataPortal.Fetch(new Criteria(userID));
|
|
if (l.Count > 0)
|
|
{
|
|
sb.AppendLine("User " + sUserName + " was set inactive and has these upcoming follow up items:");
|
|
|
|
foreach (FollowUpListForUser.FollowUpListForUserInfo i in l)
|
|
{
|
|
sb.Append(i.StartDateTime.ToString());
|
|
sb.Append(" - ");
|
|
sb.Append(i.EndDateTime.ToString());
|
|
sb.Append(": ");
|
|
sb.Append(i.FollowObjectName);
|
|
sb.Append(" \"");
|
|
sb.Append(i.Name);
|
|
sb.AppendLine("\"");
|
|
}
|
|
|
|
Memo m = Memo.NewItem();
|
|
m.FromID = User.CurrentThreadUserID;
|
|
m.ToID = User.AdministratorID;
|
|
m.Subject = "Deactivated user " + sUserName + " list of active follow ups";
|
|
m.Message = sb.ToString();
|
|
m.Save();
|
|
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
///
|
|
/// <param name="Criteria"></param>
|
|
protected override void DataPortal_Fetch(object Criteria)
|
|
{
|
|
UserPickList ulist = UserPickList.GetList(false);
|
|
//DateTime dtNow = DateTime.Now;
|
|
Criteria crit = (Criteria)Criteria;
|
|
SafeDataReader dr = null;
|
|
try
|
|
{
|
|
string q =
|
|
"SELECT * FROM ASCHEDULEMARKER " +
|
|
"WHERE " +
|
|
"(ASOURCEID = @FID) " +
|
|
"AND " +
|
|
"ASTOPDATE > @ANOW " +
|
|
"AND " +
|
|
"AFOLLOWID IS NOT NULL ORDER BY ASTARTDATE";
|
|
|
|
|
|
|
|
|
|
DBCommandWrapper cm = DBUtil.DB.GetSqlStringCommandWrapper(q);
|
|
DateTime earliestEndDateToInclude = DBUtil.CurrentWorkingDateTime.AddDays(-1);
|
|
cm.AddInParameter("@ANOW", DbType.DateTime, DBUtil.ToUTC(earliestEndDateToInclude));
|
|
cm.AddInParameter("@FID", DbType.Guid, crit.userID);
|
|
dr = new SafeDataReader(DBUtil.DB.ExecuteReader(cm));
|
|
|
|
while (dr.Read())
|
|
{
|
|
//*******************************************
|
|
FollowUpListForUserInfo info = new FollowUpListForUserInfo();
|
|
info.mID = dr.GetGuid("AID");
|
|
info.mName = dr.GetString("ANAME");
|
|
info.mARGB = dr.GetInt32("AARGB");
|
|
info.mEndDateTime = DBUtil.ToLocal(dr.GetDateTime("ASTOPDATE"));
|
|
|
|
info.mStartDateTime = DBUtil.ToLocal(dr.GetDateTime("ASTARTDATE"));
|
|
info.mFollowObject = new TypeAndID((RootObjectTypes)dr.GetInt16("AFOLLOWTYPE"), dr.GetGuid("AFOLLOWID"));
|
|
info.mFollowObjectName = NameFetcher.GetItem(info.mFollowObject).RecordName;
|
|
info.mNotes = dr.GetString("ANOTES");
|
|
Guid gTech = dr.GetGuid("ASOURCEID");
|
|
if (gTech != Guid.Empty)
|
|
info.mTechName = ulist[gTech];
|
|
else
|
|
info.mTechName = string.Empty;
|
|
|
|
InnerList.Add(info);
|
|
//*******************************************
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if (dr != null) dr.Close();
|
|
}
|
|
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region criteria
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[Serializable]
|
|
private class Criteria
|
|
{
|
|
public Guid userID;
|
|
public Criteria(Guid _userID)
|
|
{
|
|
userID = _userID;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#pragma warning restore 1591
|
|
}//end FollowUpListForUser
|
|
|
|
}
|
|
|