213 lines
7.2 KiB
C#
213 lines
7.2 KiB
C#
///////////////////////////////////////////////////////////
|
|
// FollowUpList.cs
|
|
// Implementation of Class FollowUpList
|
|
// CSLA type: Read only collection
|
|
// Created on: 5-Mar-2015
|
|
// Object design: John
|
|
// Coded: 5-Mar-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>
|
|
/// List of <see cref="FollowUpList.FollowUpListInfo"/> objects representing <see cref="ScheduleMarker"/> objects
|
|
/// that are linked to a root object. A more detailed version of <see cref="FollowUpPickList"/>
|
|
/// however this object only retrieves current items, not old ones past their end date.
|
|
/// </summary>
|
|
[Serializable]
|
|
public class FollowUpList : ReadOnlyCollectionBase
|
|
{
|
|
#pragma warning disable 1591
|
|
|
|
#region Data structure
|
|
[Serializable]
|
|
public struct FollowUpListInfo
|
|
{
|
|
|
|
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;
|
|
internal bool mOutDated;
|
|
|
|
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; } }
|
|
public bool OutDated { get { return mOutDated; } }
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Equals(FollowUpListInfo obj)
|
|
{
|
|
return this.mID.Equals(obj.mID);
|
|
}
|
|
|
|
}//end FollowUpListInfo
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
protected FollowUpList()
|
|
{
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Business properties and methods
|
|
|
|
/// <summary>
|
|
/// Get item by index
|
|
/// </summary>
|
|
/// <param name="Item"></param>
|
|
public FollowUpListInfo this[int Item]
|
|
{
|
|
|
|
get
|
|
{
|
|
return (FollowUpListInfo)List[Item];
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Returns FollowUpListInfo item that matches passed in itemid value
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
public FollowUpListInfo this[Guid ItemID]
|
|
{
|
|
|
|
get
|
|
{
|
|
foreach (FollowUpListInfo child in List)
|
|
{
|
|
if (child.mID == ItemID) return child;
|
|
}
|
|
throw new ArgumentException("FollowUpList: ID not found:\r\n" + ItemID.ToString());
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region contains
|
|
/// <summary>
|
|
/// Check if item in collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Contains(FollowUpListInfo obj)
|
|
{
|
|
foreach (FollowUpListInfo child in List)
|
|
{
|
|
if (child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// Get current and future follow ups for id
|
|
/// </summary>
|
|
/// <returns>list of <see cref="FollowUpList.FollowUpListInfo"/> objects</returns>
|
|
public static FollowUpList GetList(Guid rootObjectID)
|
|
{
|
|
if (rootObjectID == Guid.Empty)
|
|
throw new System.ApplicationException("FollowUpList->GetList: Error rootObjectID is empty");
|
|
return (FollowUpList)DataPortal.Fetch(new Criteria(rootObjectID));
|
|
}
|
|
|
|
#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 (AFOLLOWID = @FID) AND (ASTOPDATE > @ANOW) ORDER BY ASTARTDATE";
|
|
|
|
DBCommandWrapper cm = DBUtil.DB.GetSqlStringCommandWrapper(q);
|
|
DateTime earliestEndDateToInclude = DBUtil.CurrentWorkingDateTime.AddDays(-15);
|
|
cm.AddInParameter("@ANOW", DbType.DateTime, DBUtil.ToUTC(earliestEndDateToInclude));
|
|
cm.AddInParameter("@FID", DbType.Guid, crit.rootObjectID);
|
|
dr = new SafeDataReader(DBUtil.DB.ExecuteReader(cm));
|
|
|
|
while (dr.Read())
|
|
{
|
|
//*******************************************
|
|
FollowUpListInfo info = new FollowUpListInfo();
|
|
info.mID = dr.GetGuid("AID");
|
|
info.mName = dr.GetString("ANAME");
|
|
info.mARGB = dr.GetInt32("AARGB");
|
|
info.mEndDateTime = DBUtil.ToLocal(dr.GetDateTime("ASTOPDATE"));
|
|
info.mOutDated = (info.mEndDateTime < dtNow);
|
|
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 rootObjectID;
|
|
public Criteria(Guid _rootObjectID)
|
|
{
|
|
rootObjectID = _rootObjectID;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#pragma warning restore 1591
|
|
}//end FollowUpList
|
|
|
|
}
|
|
|