263 lines
7.7 KiB
C#
263 lines
7.7 KiB
C#
///////////////////////////////////////////////////////////
|
|
// UserMRU.cs
|
|
// Implementation of Class UserMRU
|
|
// CSLA type: Editable Child
|
|
// Created on: 31-"Rocktober"-2007
|
|
// Object design: John
|
|
// Coded: John 31-"Rocktober"-2007
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using CSLA.Data;
|
|
using GZTW.Data;
|
|
using CSLA;
|
|
using System.Threading;
|
|
using CSLA.Security;
|
|
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
/// Most recently used object list
|
|
///
|
|
/// When various objects are opened an entry is made in the user's MRU list
|
|
/// so that they can quickly open an item they were recently working on by selecting it
|
|
/// in the AyaNova user interface.
|
|
///
|
|
/// The tracking of what was opened is done at the business object level which is why each object has several overrides
|
|
/// to optionally track MRU or not when an item is opened because code opens objects internally as often as the user initiates from the UI.
|
|
/// </summary>
|
|
[Serializable]
|
|
public class UserMRU : BusinessBase
|
|
{
|
|
|
|
|
|
#region Attributes
|
|
private Guid mID;
|
|
private Guid mUserID;
|
|
private RootObjectTypes mObjectType;
|
|
private Guid mObjectID;
|
|
private DateTime mCreated;
|
|
private string mDescription="";
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
/// <summary>
|
|
/// Private constructor to prevent direct instantiation
|
|
/// </summary>
|
|
private UserMRU()
|
|
{
|
|
//Set as child object
|
|
MarkAsChild();
|
|
mUserID = CurrentUserID;
|
|
mID = Guid.NewGuid();
|
|
}
|
|
#endregion
|
|
|
|
#region Business properties
|
|
|
|
/// <summary>
|
|
/// Description created on the fly when object loaded to
|
|
/// ensure correct localization etc
|
|
/// </summary>
|
|
public string Description {get{return mDescription;}}
|
|
/// <summary>
|
|
/// MRU ID
|
|
/// </summary>
|
|
public Guid ID { get { return mID; } }
|
|
/// <summary>
|
|
/// <see cref="User"/> ID
|
|
/// </summary>
|
|
public Guid UserID { get { return mUserID; } }
|
|
/// <summary>
|
|
/// MRU Object ID
|
|
/// </summary>
|
|
public Guid ObjectID { get { return mObjectID; } }
|
|
|
|
/// <summary>
|
|
/// MRU Object Type
|
|
/// </summary>
|
|
public RootObjectTypes ObjectType { get { return mObjectType; } }
|
|
|
|
/// <summary>
|
|
/// MRU Record created
|
|
/// </summary>
|
|
public DateTime Created
|
|
{
|
|
get { return mCreated; }
|
|
set
|
|
{
|
|
if (mCreated != value)
|
|
{
|
|
mCreated = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region System.Object overrides
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override string ToString()
|
|
{
|
|
return "UserMRU" + mID.ToString();
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <returns></returns>
|
|
public override bool Equals(Object obj)
|
|
{
|
|
if (obj == null || GetType() != obj.GetType()) return false;
|
|
UserMRU c = (UserMRU)obj;
|
|
return ((mID == c.mID));
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override int GetHashCode()
|
|
{
|
|
return ("UserMRU" + mID.ToString()).GetHashCode();
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// Get new object
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
internal static UserMRU NewItem(RootObjectTypes ObjectType, Guid ObjectID)
|
|
{
|
|
UserMRU child = new UserMRU();
|
|
child.mObjectType = ObjectType;
|
|
child.mObjectID = ObjectID;
|
|
child.mCreated = DBUtil.CurrentWorkingDateTime;
|
|
child.mDescription = NameFetcher.GetItem(new TypeAndID(ObjectType, ObjectID)).RecordName;
|
|
return child;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// GetItem
|
|
/// </summary>
|
|
/// <param name="dr"></param>
|
|
/// <returns></returns>
|
|
internal static UserMRU GetItem(SafeDataReader dr)
|
|
{
|
|
|
|
UserMRU child = new UserMRU();
|
|
child.Fetch(dr);
|
|
return child;
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
/// <summary>
|
|
/// Fetch
|
|
/// </summary>
|
|
/// <param name="dr"></param>
|
|
private void Fetch(SafeDataReader dr)
|
|
{
|
|
|
|
//UserMRU fields
|
|
mID = dr.GetGuid("aID");
|
|
mObjectID = dr.GetGuid("aObjectID");
|
|
mObjectType = (RootObjectTypes)dr.GetInt16("aObjectType");
|
|
mCreated = dr.GetDateTime("aCreated");
|
|
mUserID = dr.GetGuid("aUserID");
|
|
mDescription = NameFetcher.GetItem(new TypeAndID(mObjectType, mObjectID)).RecordName;
|
|
MarkOld();
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update
|
|
/// </summary>
|
|
/// <param name="tr"></param>
|
|
internal void Update(IDbTransaction tr)
|
|
{
|
|
//No need to update if there is nothing changed
|
|
if (!this.IsDirty) return;
|
|
|
|
//No concurrency check here, maybe need it in future?
|
|
//shouldn't if users don't log in more than once under
|
|
//same account though.
|
|
|
|
// If not a new record, check if record was modified
|
|
//by another user since original retrieval:
|
|
// if(!IsNew)
|
|
// DBUtil.CheckSafeToUpdate(this.mModified.Date,this.mID,"PartCategory");
|
|
|
|
#region Delete
|
|
if (IsDeleted)
|
|
{
|
|
if (!IsNew)
|
|
{
|
|
//Delete object and child objects
|
|
DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aUserMRU WHERE aID=@ID");
|
|
cmDelete.AddInParameter("@ID", DbType.Guid, mID);
|
|
DBUtil.DB.ExecuteNonQuery(cmDelete, tr);
|
|
//-----------------------------
|
|
}
|
|
MarkNew();
|
|
return;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Add / Update
|
|
|
|
|
|
|
|
DBCommandWrapper cm = null;
|
|
if (IsNew)//Add or update?
|
|
cm = DBUtil.GetCommandFromSQL(
|
|
"INSERT INTO aUserMRU (aID, aObjectID, aObjectType, aCreated, aUserID) " +
|
|
"VALUES (@ID, @ObjectID, @ObjectType, @Created, @UserID)"
|
|
);
|
|
else
|
|
cm = DBUtil.GetCommandFromSQL(
|
|
"UPDATE aUserMRU SET aObjectID=@ObjectID, aUserID=@UserID, aObjectType=@ObjectType, aCreated=@Created " +
|
|
"WHERE aID=@ID"
|
|
);
|
|
|
|
|
|
//UserMRU fields
|
|
cm.AddInParameter("@ID", DbType.Guid, mID);
|
|
cm.AddInParameter("@UserID", DbType.Guid, mUserID);
|
|
cm.AddInParameter("@ObjectID", DbType.Guid, mObjectID);
|
|
cm.AddInParameter("@ObjectType", DbType.Int16, (int)mObjectType);
|
|
cm.AddInParameter("@Created", DbType.DateTime, mCreated);
|
|
if(mUserID!=Guid.Empty)
|
|
DBUtil.DB.ExecuteNonQuery(cm, tr);
|
|
MarkOld();//db is now synched with object
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}//end UserMRU
|
|
|
|
}//end namespace GZTW.AyaNova.BLL |