429 lines
9.6 KiB
C#
429 lines
9.6 KiB
C#
///////////////////////////////////////////////////////////
|
|
// Bool.cs
|
|
// Implementation of Class MemoFetcher
|
|
// CSLA type: Read-only object
|
|
// Created on: 22-Sept-2005
|
|
// Object design: John
|
|
// Coded: John 22-Sept-2005
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using CSLA.Data;
|
|
using GZTW.Data;
|
|
using CSLA;
|
|
using System.Threading;
|
|
using CSLA.Security;
|
|
using System.Text;
|
|
|
|
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
/// Lightweight read only version of <see cref="Memo"/> object for display only.
|
|
/// </summary>
|
|
[Serializable]
|
|
public class MemoFetcher : ReadOnlyBase
|
|
{
|
|
|
|
#region Attributes
|
|
|
|
private string mLanguage="";
|
|
private Guid mID;
|
|
private SmartDate mCreated;
|
|
private string mSentRelative;
|
|
|
|
|
|
|
|
private string mSubject="";
|
|
private string mMessage="";
|
|
private Guid mFromID;
|
|
private Guid mToID;
|
|
private bool mReplied;
|
|
private bool mViewed;
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
/// <summary>
|
|
/// Private constructor to prevent direct instantiation
|
|
/// </summary>
|
|
private MemoFetcher()
|
|
{
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Business properties
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Get internal id number Read only property because it's set internally, not
|
|
/// externally
|
|
/// </summary>
|
|
public Guid ID
|
|
{
|
|
get
|
|
{
|
|
return mID;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get created date
|
|
///
|
|
///
|
|
/// </summary>
|
|
public string Created
|
|
{
|
|
get
|
|
{
|
|
return mCreated.ToString();
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get sent date as a relative time formatted object
|
|
///
|
|
///
|
|
/// </summary>
|
|
public string SentRelative
|
|
{
|
|
get
|
|
{
|
|
return this.mSentRelative;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Set/get Subject of item
|
|
///
|
|
/// </summary>
|
|
public string Subject
|
|
{
|
|
get
|
|
{
|
|
return mSubject;
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set/get Subject of item
|
|
///
|
|
/// </summary>
|
|
public string Message
|
|
{
|
|
get
|
|
{
|
|
return mMessage;
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// From whom
|
|
/// </summary>
|
|
public Guid FromID
|
|
{
|
|
get
|
|
{
|
|
return mFromID;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Replied - user has replied to the message
|
|
/// </summary>
|
|
public bool Replied
|
|
{
|
|
get
|
|
{
|
|
return mReplied;
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Viewed - user has viewed the message
|
|
/// </summary>
|
|
public bool Viewed
|
|
{
|
|
get
|
|
{
|
|
return mViewed;
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Consolidated header for display and replying
|
|
///
|
|
///
|
|
/// </summary>
|
|
public string Header
|
|
{
|
|
get
|
|
{
|
|
|
|
StringBuilder sb=new StringBuilder();
|
|
UserPickList up=UserPickList.GetListOfOneSpecificUser(this.FromID);
|
|
|
|
//From
|
|
//case 3826
|
|
if (up.Count == 0)//User not found (utility user probably)
|
|
{
|
|
sb.Append(LocalizedTextTable.GetLocalizedTextDirect("Memo.Label.FromID", mLanguage) + ": -\r\n");
|
|
}
|
|
else
|
|
{
|
|
sb.Append(LocalizedTextTable.GetLocalizedTextDirect("Memo.Label.FromID", mLanguage) + ": " + up[0].Name + "\r\n");
|
|
}
|
|
|
|
//Sent
|
|
sb.Append(LocalizedTextTable.GetLocalizedTextDirect("Memo.Label.Sent", mLanguage) + ": " + this.SentRelative + " (" + this.Created +")\r\n");
|
|
|
|
|
|
//Subject
|
|
sb.Append(LocalizedTextTable.GetLocalizedTextDirect("Memo.Label.Subject", mLanguage) + ": " + this.Subject +"\r\n");
|
|
|
|
|
|
return sb.ToString();
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Consolidated header for display and replying
|
|
/// Shortened for optimization on small screen displays
|
|
///
|
|
///
|
|
/// </summary>
|
|
public string ShortHeader
|
|
{
|
|
get
|
|
{
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
UserPickList up = UserPickList.GetListOfOneSpecificUser(this.FromID);
|
|
|
|
//From
|
|
sb.Append(LocalizedTextTable.GetLocalizedTextDirect("Memo.Label.FromID", mLanguage) + ": " + up[0].Name + "\r\n");
|
|
|
|
|
|
//Sent
|
|
string sDate = "";
|
|
if (mCreated.Date.ToShortDateString() == DateTime.Today.ToShortDateString())
|
|
sDate = mCreated.Date.ToShortTimeString();//today so no date reqd
|
|
else
|
|
sDate = mCreated.Date.ToShortDateString() + " " + mCreated.Date.ToShortTimeString();
|
|
|
|
sb.Append(LocalizedTextTable.GetLocalizedTextDirect("Memo.Label.Sent", mLanguage) + ": " + sDate + "\r\n");
|
|
|
|
|
|
//Subject
|
|
sb.Append(LocalizedTextTable.GetLocalizedTextDirect("Memo.Label.Subject", mLanguage) + ": " + this.Subject + "\r\n");
|
|
|
|
|
|
return sb.ToString();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// From name only for notification etc.
|
|
/// </summary>
|
|
public string From
|
|
{
|
|
get
|
|
{
|
|
return UserPickList.GetListOfOneSpecificUser(this.FromID)[0].Name;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Generate a new memo as a Reply or Forward based on this fetched read only memo
|
|
/// </summary>
|
|
/// <param name="bForward">If true, this is a forward reply to don't set the toID just yet</param>
|
|
/// <returns>A memo object with fields filled in ready for typing reply/forward text</returns>
|
|
public Memo ReplyForward(bool bForward)
|
|
{
|
|
Memo m=Memo.NewItem();
|
|
if(!bForward)
|
|
m.ToID=this.FromID;
|
|
|
|
m.Subject=LocalizedTextTable.GetLocalizedTextDirect("Memo.Label.Re")+ " " + this.Subject;
|
|
m.Message="\r\n\r\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n" + this.Header + "\r\n\r\n" + this.Message;
|
|
|
|
return m;
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region System.Object overrides
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override string ToString()
|
|
{
|
|
return this.mID.ToString();
|
|
}
|
|
|
|
///
|
|
/// <param Bool="obj"></param>
|
|
public override bool Equals(Object obj)
|
|
{
|
|
if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false;
|
|
MemoFetcher c=(MemoFetcher)obj;
|
|
return mID==c.mID;
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override int GetHashCode()
|
|
{
|
|
return ("MemoMessage" + mID.ToString()).GetHashCode();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Static methods
|
|
|
|
/// <summary>
|
|
/// Fetch Memo of indicated ID, using specific language for
|
|
/// formatting headers etc.
|
|
/// </summary>
|
|
/// <param name="MemoID"></param>
|
|
/// <param name="Language"></param>
|
|
/// <returns></returns>
|
|
public static MemoFetcher GetItem(Guid MemoID, string Language)
|
|
{
|
|
|
|
if(AyaBizUtils.Right("Object.Memo")>(int)SecurityLevelTypes.NoAccess || AyaBizUtils.IsGenerator)
|
|
return (MemoFetcher)DataPortal.Fetch(new Criteria( MemoID, Language));
|
|
else
|
|
throw new System.Security.SecurityException(
|
|
string.Format(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToRetrieve"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.Memo")));
|
|
}
|
|
|
|
|
|
//Case 136 - removed this, it should not be called, not sure why it's here
|
|
|
|
|
|
//public static MemoFetcher GetItem(Guid MemoID)
|
|
//{
|
|
// return GetItem(MemoID,"");
|
|
|
|
//}
|
|
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
///
|
|
/// <param Bool="Criteria"></param>
|
|
protected override void DataPortal_Fetch(object Criteria)
|
|
{
|
|
|
|
Criteria crit = (Criteria)Criteria;
|
|
this.mLanguage=crit.Language;
|
|
SafeDataReader dr = null;
|
|
try
|
|
{
|
|
dr=DBUtil.GetReaderFromSQLString(
|
|
"SELECT aMemo.aID, aMemo.aCreated, aMemo.aSubject, " +
|
|
" aMemo.aMessage, aMemo.aReplied, aMemo.aViewed, " +
|
|
"aUser.aFirstName, aUser.aLastName, aMemo.aToID, aMemo.aFromID " +
|
|
"FROM aMemo LEFT OUTER JOIN aUser " +
|
|
"ON aMemo.aFromID = aUser.aID WHERE (aMemo.aID " +
|
|
"= @ID)"
|
|
,crit.MemoID);
|
|
if(!dr.Read())
|
|
DBUtil.ThrowFetchError("MemoFetcher ID: " + crit.MemoID.ToString());
|
|
|
|
//get to id for extra security
|
|
//only the admin user can read eMemo destined for other users
|
|
mToID=dr.GetGuid("aToID");
|
|
if(!AyaBizUtils.IsGenerator && !User.IsAdmin && mToID!=User.CurrentThreadUserID)
|
|
throw new System.Security.SecurityException(
|
|
string.Format(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToRetrieve"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.Memo")));
|
|
|
|
//Standard fields
|
|
mID=crit.MemoID;
|
|
mCreated=DBUtil.ToLocal(dr.GetSmartDate("aCreated"));
|
|
|
|
|
|
|
|
//Memo fields
|
|
mSubject=dr.GetString("aSubject");
|
|
mMessage=dr.GetString("aMessage");
|
|
mFromID=dr.GetGuid("aFromID");
|
|
|
|
mReplied=dr.GetBoolean("aReplied");
|
|
mViewed=dr.GetBoolean("aViewed");
|
|
|
|
RelativeTimeFormatter rtfm=RelativeTimeFormatter.GetItem(crit.Language);
|
|
|
|
this.mSentRelative = rtfm.Format(DBUtil.CurrentWorkingDateTime, mCreated.Date);
|
|
|
|
|
|
}
|
|
finally
|
|
{
|
|
if(dr!=null) dr.Close();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region criteria
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[Serializable]
|
|
private class Criteria
|
|
{
|
|
|
|
|
|
public Guid MemoID;
|
|
public string Language;
|
|
|
|
public Criteria(Guid _MemoID, string _Language)
|
|
{
|
|
MemoID=_MemoID;
|
|
Language=_Language;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}//end Bool
|
|
|
|
}//end Boolspace GZTW.AyaNova.BLL |