490 lines
14 KiB
C#
490 lines
14 KiB
C#
///////////////////////////////////////////////////////////
|
|
// MemoList.cs
|
|
// Implementation of Class MemoList
|
|
// CSLA type: Read only collection
|
|
// Created on: 26-Oct-2004
|
|
// Object design: John
|
|
// Coded: 26-Oct-2004
|
|
///////////////////////////////////////////////////////////
|
|
|
|
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 <see cref="MemoList.MemoListInfo"/> objects representing <see cref="Memo"/> object
|
|
///
|
|
/// </summary>
|
|
[Serializable]
|
|
public class MemoList : ReadOnlyCollectionBase
|
|
{
|
|
|
|
|
|
#region Data structure
|
|
/// <summary>
|
|
/// Properties
|
|
/// </summary>
|
|
[Serializable]
|
|
public struct MemoListInfo
|
|
{
|
|
internal Guid mID;
|
|
internal SmartDate mCreated;
|
|
internal GridRelativeTimeCellItem mCreatedRelative;
|
|
internal GridNameValueCellItem mSubject;
|
|
internal string mMessage;
|
|
internal GridNameValueCellItem mFrom;
|
|
//internal Guid mFrom;
|
|
internal bool mViewed;
|
|
internal bool mReplied;
|
|
|
|
//ID Not localized as it's an invisible field
|
|
[Display(DisplayType.Hidden)]
|
|
public Guid ID
|
|
{
|
|
get
|
|
{
|
|
return mID;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("aMemo.aCreated"),Display(DisplayType.DateTime)]
|
|
public object LT_Memo_Label_Sent
|
|
{
|
|
get
|
|
{
|
|
return mCreated.DBValue;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("grid"), Display(DisplayType.Text)]
|
|
public GridRelativeTimeCellItem LT_Memo_Label_Sent_Relative
|
|
{
|
|
get
|
|
{
|
|
return mCreatedRelative;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("aUser.aLastName",
|
|
"aMemo.aFromID"),
|
|
Display(DisplayType.Button, RootObjectType = RootObjectTypes.Client)]
|
|
public GridNameValueCellItem LT_Memo_Label_FromID
|
|
{
|
|
get
|
|
{
|
|
return mFrom;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("aMemo.aSubject", "aMemo.aID"), Display(DisplayType.Button, RootObjectType = RootObjectTypes.Memo)]
|
|
public GridNameValueCellItem LT_Memo_Label_Subject
|
|
{
|
|
get
|
|
{
|
|
return mSubject;
|
|
}
|
|
}
|
|
|
|
[Display(DisplayType.Hidden)]
|
|
public string LT_Memo_Label_Message
|
|
{
|
|
get
|
|
{
|
|
return mMessage;
|
|
}
|
|
}
|
|
|
|
[SqlColumnNameAttribute("aMemo.aViewed"), Display(DisplayType.Hidden)]//case 1805 added column name attribute so can set criteria for dashboard
|
|
public bool LT_Memo_Label_Viewed
|
|
{
|
|
get
|
|
{
|
|
return mViewed;
|
|
}
|
|
}
|
|
|
|
//Special control, i.e. in this case image checkbox showing replied graphic or not replied graphic
|
|
[Display(DisplayType.SpecialControl)]
|
|
public bool LT_Memo_Label_Replied
|
|
{
|
|
get
|
|
{
|
|
return this.mReplied;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Equals(MemoListInfo obj)
|
|
{
|
|
return this.ID.Equals(obj.ID);
|
|
}
|
|
|
|
}//end MemoListInfo
|
|
#endregion
|
|
|
|
#region Constructor
|
|
private RelativeTimeFormatter rtfm=null;
|
|
|
|
protected MemoList()
|
|
{
|
|
|
|
rtfm=RelativeTimeFormatter.GetItem(User.CurrentUserLanguage);
|
|
// 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 MemoListInfo this[int Item]
|
|
{
|
|
|
|
get
|
|
{
|
|
return (MemoListInfo) List[Item];
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Returns display text that matches passed in itemid value
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
public string this[Guid ItemID]
|
|
{
|
|
|
|
get
|
|
{
|
|
foreach (MemoListInfo child in List)
|
|
{
|
|
if(child.ID==ItemID) return child.ToString();
|
|
}
|
|
return "Missing: "+ItemID.ToString();
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region contains
|
|
/// <summary>
|
|
/// Check if item in collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Contains(MemoListInfo obj)
|
|
{
|
|
foreach (MemoListInfo child in List)
|
|
{
|
|
if(child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Reporting and shared UI editor helpers
|
|
|
|
/// <summary>
|
|
/// Returns the report key which is a property of
|
|
/// reports used to link all reports that can be used
|
|
/// with a particular data source.
|
|
/// </summary>
|
|
public static string ReportKey
|
|
{
|
|
get
|
|
{
|
|
return "MemoList";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the Detailed report key
|
|
/// which is used to determine which reports and objects
|
|
/// will be used for detailed reports
|
|
///
|
|
/// If empty string then indicates there is no detailed report object or reports
|
|
/// </summary>
|
|
public static string DetailedReportKey
|
|
{
|
|
get
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Base object that this list is reporting on
|
|
/// used by shared UI editor to instantiate new objects
|
|
/// when user selects new in UI elements that display this list
|
|
///
|
|
/// (I.E. when user clicks on new in a read only list grid, this is the object type created)
|
|
/// </summary>
|
|
public static RootObjectTypes BaseObjectType
|
|
{
|
|
get
|
|
{
|
|
return RootObjectTypes.Memo;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Locale key so that generic list editor
|
|
/// UI code knows what title to give the list in a
|
|
/// grid
|
|
/// </summary>
|
|
public string LocaleKey
|
|
{
|
|
get
|
|
{
|
|
return "Memo.Label.List";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The Type of the struct used to store list records
|
|
/// Used to fetch the custom display attributes of the fields
|
|
/// contained within the record to modify the grid display accordingly
|
|
/// <see cref="DisplayAttribute"/>
|
|
/// </summary>
|
|
public static Type ListRecordType
|
|
{
|
|
get
|
|
{
|
|
return typeof(MemoListInfo);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Field that contains the ID of the objects
|
|
/// that are the basis of this list.
|
|
///
|
|
/// Used for compiling an ID list for reporting from user
|
|
/// selections in a grid.
|
|
/// </summary>
|
|
public static string IDField
|
|
{
|
|
get
|
|
{
|
|
return "ID";
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Same as IDField but for detailed reports
|
|
/// </summary>
|
|
public static string IDFieldDetailed
|
|
{
|
|
get
|
|
{
|
|
return IDField;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Static methods
|
|
|
|
/// <summary>
|
|
/// Internal method used by list factory
|
|
/// </summary>
|
|
internal static MemoList Get(string Filter, int MaxRecords, List<Guid> IDList)
|
|
{
|
|
return (MemoList)DataPortal.Fetch(new Criteria(Filter, IDList, MaxRecords));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get all Memo (filtered by crit)
|
|
/// </summary>
|
|
/// <param name="xmlCriteria">Use AyaNova UI to easily build xmlCriteria and Ctrl-Alt-g keyboard command to display it for use in your code</param>
|
|
/// <returns>list of <see cref="MemoList.MemoListInfo"/> objects</returns>
|
|
|
|
public static MemoList GetList(string xmlCriteria)
|
|
{
|
|
return (MemoList)DataPortal.Fetch(new Criteria(xmlCriteria, null, -1));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Takes a single ID and returns a "list" of one object
|
|
/// </summary>
|
|
/// <param name="MemoID">ID of Memo object</param>
|
|
/// <returns></returns>
|
|
public static MemoList GetListForSingleItem(Guid MemoID)
|
|
{
|
|
//Case 556
|
|
List<Guid> l = new List<Guid>();
|
|
l.Add(MemoID);
|
|
return GetListFromIDList(l);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Get list by items indicated in IDList
|
|
/// </summary>
|
|
/// <param name="IDList">Generic list of Guid's</param>
|
|
/// <returns>list of <see cref="MemoList.MemoListInfo"/> objects</returns>
|
|
public static MemoList GetListFromIDList(List<Guid> IDList)
|
|
{
|
|
//case 556
|
|
//Handle empty list
|
|
if (IDList.Count == 0)
|
|
return new MemoList();
|
|
return (MemoList)DataPortal.Fetch(new Criteria("", IDList, -1));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Return an empty list
|
|
/// used for initializing grid
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static MemoList GetEmptyList()
|
|
{
|
|
return new MemoList();
|
|
}
|
|
|
|
|
|
#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
|
|
{
|
|
|
|
if (crit.IDList != null)
|
|
{
|
|
//Case 556
|
|
System.Text.StringBuilder sbIN = new System.Text.StringBuilder();
|
|
sbIN.Append(" WHERE (aMemo.aID in (");
|
|
foreach (Guid gItem in crit.IDList)
|
|
{
|
|
sbIN.Append("'");
|
|
sbIN.Append("{");
|
|
sbIN.Append(gItem.ToString().ToUpperInvariant());
|
|
sbIN.Append("}");
|
|
sbIN.Append("',");
|
|
}
|
|
sbIN.Length = sbIN.Length - 1;
|
|
sbIN.Append(")) ");
|
|
|
|
//************************************************************
|
|
dr = DBUtil.GetReaderFromSQLString(
|
|
"SELECT aMemo.aID, aMemo.aCreated, " +
|
|
"aMemo.aViewed, aMemo.aReplied, aMemo.aSubject, aMemo.aMessage, " +
|
|
"aMemo.aFromID, aUser.aFirstName, aUser.aLastName, aUser.aInitials, AREGION.ANAME AS AREGIONNAME, " +
|
|
"aUser.aEmployeeNumber FROM aMemo " +
|
|
|
|
" LEFT OUTER JOIN aUser ON aMemo.aFromID = aUser.aID " +
|
|
" LEFT OUTER JOIN AREGION ON (AUSER.AREGIONID=AREGION.AID) " +
|
|
sbIN.ToString() + " " +
|
|
AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML));
|
|
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
//************************************************************
|
|
string q = "SELECT ~MAXRECS~ aMemo.aID, aMemo.aCreated, " +
|
|
"aMemo.aViewed, aMemo.aReplied, aMemo.aSubject, aMemo.aMessage, " +
|
|
"aMemo.aFromID, aUser.aFirstName, aUser.aLastName, aUser.aInitials, AREGION.ANAME AS AREGIONNAME, " +
|
|
"aUser.aEmployeeNumber FROM aMemo " +
|
|
|
|
" LEFT OUTER JOIN aUser ON aMemo.aFromID = aUser.aID " +
|
|
" LEFT OUTER JOIN AREGION ON (AUSER.AREGIONID=AREGION.AID) " +
|
|
"WHERE (aMemo.aToID = @ID) " +
|
|
AyaBizUtils.GetGridColumnCriteria(crit.CriteriaXML, false) + " " +
|
|
AyaBizUtils.GetGridSortOrderColumns(crit.CriteriaXML);
|
|
//************************************************************
|
|
|
|
if (crit.MaxRecords > 0)
|
|
q = q.Replace("~MAXRECS~", "TOP " + crit.MaxRecords.ToString());
|
|
else
|
|
q = q.Replace("~MAXRECS~", "");
|
|
|
|
dr = DBUtil.GetReaderFromSQLString(q, CurrentUserID);
|
|
}
|
|
while(dr.Read())
|
|
{
|
|
//*******************************************
|
|
MemoListInfo info=new MemoListInfo();
|
|
|
|
info.mID=dr.GetGuid("aID");
|
|
|
|
info.mCreated=DBUtil.ToLocal(dr.GetSmartDate("aCreated"));
|
|
info.mCreatedRelative = new GridRelativeTimeCellItem(rtfm.Format(dtNow,info.mCreated));
|
|
info.mFrom=new GridNameValueCellItem(
|
|
dr.GetGuid("aFromID"),
|
|
User.NameFormatter(dr.GetString("aFirstName"),dr.GetString("aLastName"),dr.GetString("aInitials"),
|
|
dr.GetString("aEmployeeNumber"), dr.GetString("AREGIONNAME"), AyaBizUtils.GlobalSettings.DefaultScheduleableUserNameDisplayFormat)
|
|
,RootObjectTypes.User);
|
|
|
|
info.mSubject = new GridNameValueCellItem(
|
|
dr.GetGuid("aID"),
|
|
dr.GetString("aSubject"),
|
|
RootObjectTypes.Memo);
|
|
|
|
|
|
info.mViewed=dr.GetBoolean("aViewed");
|
|
info.mReplied=dr.GetBoolean("aReplied");
|
|
info.mMessage = dr.GetString("aMessage");
|
|
|
|
InnerList.Add(info);
|
|
//*******************************************
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if(dr!=null) dr.Close();
|
|
}
|
|
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region criteria
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[Serializable]
|
|
private class Criteria
|
|
{
|
|
public List<Guid> IDList;
|
|
public string CriteriaXML;
|
|
public int MaxRecords;
|
|
public Criteria(string _CriteriaXML, List<Guid> _IDList, int _MaxRecords)
|
|
{
|
|
CriteriaXML = _CriteriaXML;
|
|
IDList = _IDList;
|
|
MaxRecords = _MaxRecords;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
}//end MemoList
|
|
#pragma warning restore 1591
|
|
}//end namespace GZTW.AyaNova.BLL |