529 lines
11 KiB
C#
529 lines
11 KiB
C#
///////////////////////////////////////////////////////////
|
|
// UIExplorerBarLayout.cs
|
|
// Implementation of Class UIExplorerBarLayout
|
|
// CSLA type: Editable Root
|
|
// Created on: 16-Dec-2005
|
|
// Object design: John
|
|
// Coded: John 16-Dec-2005
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using CSLA.Data;
|
|
using GZTW.Data;
|
|
using CSLA;
|
|
using System.Threading;
|
|
using CSLA.Security;
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
#pragma warning disable 1591
|
|
|
|
/// <summary>
|
|
/// User interface ExplorerBar layout preferences
|
|
/// Used to store and retreive user and default
|
|
/// layouts for all ExplorerBar objects in user interface
|
|
/// </summary>
|
|
[Serializable]
|
|
public class UIExplorerBarLayout : BusinessBase
|
|
{
|
|
|
|
#region Attributes
|
|
|
|
|
|
private SmartDate mCreated;
|
|
private SmartDate mModified;
|
|
private Guid mCreator;
|
|
private Guid mModifier;
|
|
private Guid mUserID;
|
|
private string mKey=null;
|
|
private int mLayoutSize;
|
|
private byte[] mLayoutContent;
|
|
private int mSplitPosition1;
|
|
private int mSplitPosition2;
|
|
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
/// <summary>
|
|
/// Private constructor to prevent direct instantiation
|
|
/// </summary>
|
|
private UIExplorerBarLayout()
|
|
{
|
|
mCreated = new SmartDate(DBUtil.CurrentWorkingDateTime);
|
|
mModified=new SmartDate();
|
|
mCreator=Guid.Empty;
|
|
mModifier=Guid.Empty;
|
|
//pre-break the rules
|
|
this.Key="";
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Business properties
|
|
/// <summary>
|
|
///User ID this layout applies to, if Guid.Empty then it's
|
|
///the default layout for the gridkey specified
|
|
/// </summary>
|
|
public Guid UserID
|
|
{
|
|
get
|
|
{
|
|
return mUserID;
|
|
}
|
|
set
|
|
{
|
|
if(mUserID!=value)
|
|
mUserID=value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get created date
|
|
///
|
|
///
|
|
/// </summary>
|
|
public string Created
|
|
{
|
|
get
|
|
{
|
|
return mCreated.ToString();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get modified date
|
|
///
|
|
///
|
|
/// </summary>
|
|
public string Modified
|
|
{
|
|
get
|
|
{
|
|
return mModified.ToString();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get user record ID of person who created this record
|
|
///
|
|
///
|
|
/// </summary>
|
|
public Guid Creator
|
|
{
|
|
get
|
|
{
|
|
return mCreator;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get user ID of person who modified this record
|
|
///
|
|
///
|
|
/// </summary>
|
|
public Guid Modifier
|
|
{
|
|
get
|
|
{
|
|
return mModifier;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Size of binary layout data content
|
|
/// </summary>
|
|
public int LayoutSize
|
|
{
|
|
get
|
|
{
|
|
return mLayoutSize;
|
|
}
|
|
set
|
|
{
|
|
if(mLayoutSize!=value)
|
|
{
|
|
mLayoutSize=value;
|
|
MarkDirty();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//These are done as methods rather
|
|
//than property accessors because
|
|
//of an efficiency problem with binary data
|
|
//and properties
|
|
|
|
|
|
|
|
public System.IO.MemoryStream GetExplorerBarLayoutContent()
|
|
{
|
|
return new System.IO.MemoryStream(mLayoutContent);
|
|
|
|
}
|
|
|
|
public void SetExplorerBarLayoutContent(System.IO.MemoryStream mStream)
|
|
{
|
|
mStream.Position=0;
|
|
byte[] bData=new byte[mStream.Length+1];
|
|
mStream.Read(bData,0,(int)mStream.Length);
|
|
mLayoutSize=(int)mStream.Length;
|
|
mLayoutContent=bData;
|
|
MarkDirty();
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Set/get GridKey of item
|
|
///
|
|
/// </summary>
|
|
public string Key
|
|
{
|
|
get
|
|
{
|
|
return mKey;
|
|
}
|
|
set
|
|
{
|
|
|
|
if(mKey!=value)
|
|
{
|
|
mKey = value;
|
|
|
|
BrokenRules.Assert("KeyRequired","Error.Object.RequiredFieldEmpty,UIExplorerBarLayout.Label.Key","Key",value.Length==0);
|
|
|
|
BrokenRules.Assert("KeyLength",
|
|
"Error.Object.FieldLengthExceeded255,UIExplorerBarLayout.Label.Key","Key",value.Length>255);
|
|
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public int SplitPosition1
|
|
{
|
|
get
|
|
{
|
|
return mSplitPosition1;
|
|
}
|
|
set
|
|
{
|
|
if(mSplitPosition1!=value)
|
|
{
|
|
mSplitPosition1=value;
|
|
MarkDirty();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public int SplitPosition2
|
|
{
|
|
get
|
|
{
|
|
return mSplitPosition2;
|
|
}
|
|
set
|
|
{
|
|
if(mSplitPosition2!=value)
|
|
{
|
|
mSplitPosition2=value;
|
|
MarkDirty();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// Get new object
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static UIExplorerBarLayout NewItem()
|
|
{
|
|
return new UIExplorerBarLayout();
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Fetch explorer bar layout requested
|
|
///
|
|
/// </summary>
|
|
/// <param name="sKey"></param>
|
|
/// <param name="UserID"></param>
|
|
/// <returns></returns>
|
|
public static UIExplorerBarLayout GetItem(string sKey,Guid UserID)
|
|
{
|
|
UIExplorerBarLayout uTemp=(UIExplorerBarLayout)DataPortal.Fetch(new Criteria(sKey,UserID));
|
|
if(uTemp.mKey=="")
|
|
{
|
|
uTemp=new UIExplorerBarLayout();
|
|
uTemp.Key=sKey;
|
|
uTemp.UserID=UserID;
|
|
|
|
}
|
|
return uTemp;
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
|
|
#region Fetch
|
|
///
|
|
/// <param name="Criteria"></param>
|
|
protected override void DataPortal_Fetch(object Criteria)
|
|
{
|
|
|
|
|
|
Criteria crit = (Criteria)Criteria;
|
|
SafeDataReader dr = null;
|
|
|
|
try
|
|
{
|
|
DBCommandWrapper dbCommandWrapper = DBUtil.DB.GetSqlStringCommandWrapper(
|
|
"SELECT * from aUIExplorerBarLayout WHERE " +
|
|
"(aUIExplorerBarLayout.aUserID=@UserID AND aUIExplorerBarLayout.aKey=@Key)"
|
|
);
|
|
dbCommandWrapper.AddInParameter("@UserID",DbType.Guid,crit.UserID);
|
|
dbCommandWrapper.AddInParameter("@Key",DbType.String,crit.Key);
|
|
dr= new SafeDataReader(DBUtil.DB.ExecuteReader(dbCommandWrapper));
|
|
|
|
if(dr.Read())
|
|
{
|
|
|
|
//Standard fields
|
|
mCreated=DBUtil.ToLocal(dr.GetSmartDate("aCreated"));
|
|
mModified=DBUtil.ToLocal(dr.GetSmartDate("aModified"));
|
|
mCreator=dr.GetGuid("aCreator");
|
|
mModifier=dr.GetGuid("aModifier");
|
|
|
|
|
|
//UIExplorerBarLayout fields
|
|
|
|
mLayoutSize=dr.GetInt32("aLayoutSize");
|
|
mUserID=crit.UserID;
|
|
mSplitPosition1=dr.GetInt16("aSplitPosition1");
|
|
mSplitPosition2=dr.GetInt16("aSplitPosition2");
|
|
//Important: use property not internal field
|
|
//so that initial broken rule is unbroken on fetch
|
|
Key=crit.Key;
|
|
|
|
//Get the number of bytes
|
|
mLayoutContent=new Byte[mLayoutSize];
|
|
//retrieve the bytes
|
|
dr.GetBytes("aLayoutContent",0,mLayoutContent,0,mLayoutContent.Length);
|
|
}
|
|
|
|
}
|
|
finally
|
|
{
|
|
if(dr!=null) dr.Close();
|
|
}
|
|
MarkOld();
|
|
|
|
|
|
|
|
}
|
|
#endregion fetch
|
|
|
|
#region Update
|
|
|
|
/// <summary>
|
|
/// Called by DataPortal to delete/add/update data into the database
|
|
/// </summary>
|
|
protected override void DataPortal_Update()
|
|
{
|
|
//Apparently no concurrency check for this as it wasn't in the old data layer code when ported
|
|
//makes sense as long as users aren't logging in with same account at more than one station
|
|
|
|
#region Delete
|
|
if(IsDeleted)
|
|
{
|
|
if(!IsNew)
|
|
{
|
|
|
|
|
|
//Delete object and child objects
|
|
DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL(
|
|
"DELETE FROM aUIExplorerBarLayout WHERE aUserID=@UserID AND aKey=@Key");
|
|
cmDelete.AddInParameter("@UserID",DbType.Guid,this.mUserID);
|
|
cmDelete.AddInParameter("@Key",DbType.String,this.mKey);
|
|
|
|
using (IDbConnection connection = DBUtil.DB.GetConnection())
|
|
{
|
|
connection.Open();
|
|
IDbTransaction transaction = connection.BeginTransaction();
|
|
|
|
try
|
|
{
|
|
|
|
DBUtil.DB.ExecuteNonQuery(cmDelete, transaction);
|
|
|
|
// Commit the transaction
|
|
transaction.Commit();
|
|
|
|
}
|
|
catch
|
|
{
|
|
// Rollback transaction
|
|
transaction.Rollback();
|
|
throw;
|
|
}
|
|
finally
|
|
{
|
|
connection.Close();
|
|
}
|
|
}
|
|
|
|
|
|
//-----------------------------
|
|
}
|
|
MarkNew();
|
|
return;
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
#region Add / Update
|
|
|
|
//get modification time temporarily, if update succeeds then
|
|
//set to this time
|
|
System.DateTime dtModified = DBUtil.CurrentWorkingDateTime;
|
|
|
|
DBCommandWrapper cm = null;
|
|
if(IsNew)//Add or update?
|
|
cm=DBUtil.GetCommandFromSQL(
|
|
"INSERT INTO aUIExplorerBarLayout (aUserID, aKey, " +
|
|
"aLayoutSize, aLayoutContent, aSplitPosition1, aSplitPosition2, " +
|
|
"aCreated,aModified,aCreator,aModifier) VALUES (@UserID,@Key, " +
|
|
"@LayoutSize,@LayoutContent,@SplitPosition1, " +
|
|
"@SplitPosition2,@Created,@Modified,@CurrentUserID, " +
|
|
"@CurrentUserID)"
|
|
);
|
|
else
|
|
cm=DBUtil.GetCommandFromSQL(
|
|
"UPDATE aUIExplorerBarLayout SET aUserID=@UserID, aKey=@Key, " +
|
|
"aLayoutSize=@LayoutSize, aLayoutContent=@LayoutContent, " +
|
|
"aSplitPosition1=@SplitPosition1, " +
|
|
"aSplitPosition2=@SplitPosition2, aModifier=@CurrentUserID, " +
|
|
"aModified=@Modified WHERE aUIExplorerBarLayout.aUserID=@UserID " +
|
|
"AND aUIExplorerBarLayout.aKey=@Key"
|
|
);
|
|
|
|
cm.AddInParameter("@UserID",DbType.Guid,this.mUserID);
|
|
cm.AddInParameter("@Key",DbType.String,this.mKey);
|
|
cm.AddInParameter("@LayoutSize",DbType.Int32,mLayoutSize);
|
|
cm.AddInParameter("@LayoutContent",DbType.Object,mLayoutContent);
|
|
cm.AddInParameter("@SplitPosition1",DbType.Int16,mSplitPosition1);
|
|
cm.AddInParameter("@SplitPosition2",DbType.Int16,mSplitPosition2);
|
|
|
|
//Standard fields
|
|
cm.AddInParameter("@CurrentUserID",DbType.Guid, CurrentUserID);
|
|
cm.AddInParameter("@Created",DbType.DateTime, DBUtil.ToUTC(mCreated).DBValue);
|
|
cm.AddInParameter("@Modified",DbType.DateTime, DBUtil.ToUTC(dtModified));
|
|
|
|
|
|
|
|
using (IDbConnection connection = DBUtil.DB.GetConnection())
|
|
{
|
|
connection.Open();
|
|
IDbTransaction transaction = connection.BeginTransaction();
|
|
|
|
try
|
|
{
|
|
|
|
DBUtil.DB.ExecuteNonQuery(cm, transaction);
|
|
MarkOld();//db is now synched with object
|
|
|
|
// Commit the transaction
|
|
transaction.Commit();
|
|
|
|
}
|
|
catch
|
|
{
|
|
// Rollback transaction
|
|
transaction.Rollback();
|
|
throw;
|
|
}
|
|
finally
|
|
{
|
|
connection.Close();
|
|
}
|
|
//Successful update so
|
|
//change modification time to match
|
|
this.mModified.Date=dtModified;
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
#endregion update
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region Override IsValid / IsDirty
|
|
//Override base class version if there are child objects
|
|
/*
|
|
public override bool IsValid
|
|
{
|
|
get
|
|
{
|
|
return base.IsValid && ChildItem.IsValid;
|
|
}
|
|
}
|
|
public override bool IsDirty
|
|
{
|
|
get
|
|
{
|
|
return base.IsDirty || ChildItem.IsDirty;
|
|
}
|
|
}
|
|
*/
|
|
#endregion
|
|
|
|
#region criteria
|
|
/// <summary>
|
|
/// Criteria for identifying existing object
|
|
/// </summary>
|
|
[Serializable]
|
|
private class Criteria
|
|
{
|
|
public string Key;
|
|
public Guid UserID;
|
|
public Criteria(string _Key, Guid _UserID)
|
|
{
|
|
Key=_Key;
|
|
UserID=_UserID;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}//end UIExplorerBarLayout
|
|
#pragma warning restore 1591
|
|
}//end namespace GZTW.AyaNova.BLL |