534 lines
11 KiB
C#
534 lines
11 KiB
C#
///////////////////////////////////////////////////////////
|
|
// UIGridLayoutShared.cs
|
|
// Implementation of Class UIGridLayoutShared
|
|
// CSLA type: Editable Root
|
|
// Created on: 20-March-2006
|
|
// Object design: John
|
|
// Coded: John 20-March-2006
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using CSLA.Data;
|
|
using GZTW.Data;
|
|
using CSLA;
|
|
using System.Threading;
|
|
using CSLA.Security;
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
/// User interface grid layout preferences
|
|
/// Used to store and retrieve user and default
|
|
/// layouts for all grid objects in user interface
|
|
/// </summary>
|
|
[Serializable]
|
|
public class UIGridLayoutShared : BusinessBase
|
|
{
|
|
|
|
#region Attributes
|
|
|
|
private Guid mID;
|
|
private SmartDate mCreated;
|
|
private SmartDate mModified;
|
|
private Guid mCreator;
|
|
private Guid mModifier;
|
|
|
|
private string mGridKey=null;
|
|
|
|
private string mName="";
|
|
private int mLayoutSize;
|
|
private byte[] mLayoutContent;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
/// <summary>
|
|
/// Private constructor to prevent direct instantiation
|
|
/// </summary>
|
|
private UIGridLayoutShared()
|
|
{
|
|
|
|
//New ID
|
|
mID = Guid.NewGuid();
|
|
//prebreak the rule
|
|
Name="";
|
|
mCreated = new SmartDate(DBUtil.CurrentWorkingDateTime);
|
|
mModified=new SmartDate();
|
|
mCreator=Guid.Empty;
|
|
mModifier=Guid.Empty;
|
|
//pre-break the rules
|
|
this.GridKey="";
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Business properties
|
|
|
|
|
|
/// <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
|
|
|
|
/// <summary>
|
|
/// Get Document binary data
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public byte[] GetLayoutContent()
|
|
{
|
|
return mLayoutContent;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set document binary data
|
|
/// </summary>
|
|
/// <param name="bData"></param>
|
|
public void SetLayoutContent(byte[] bData)
|
|
{
|
|
mLayoutContent=bData;
|
|
MarkDirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Set/get GridKey of item
|
|
///
|
|
/// </summary>
|
|
public string GridKey
|
|
{
|
|
get
|
|
{
|
|
return mGridKey;
|
|
}
|
|
set
|
|
{
|
|
|
|
if(mGridKey!=value)
|
|
{
|
|
mGridKey = value;
|
|
|
|
BrokenRules.Assert("GridKeyRequired","Error.Object.RequiredFieldEmpty,UIGridLayoutShared.Label.GridKey","GridKey",value.Length==0);
|
|
|
|
BrokenRules.Assert("GridKeyLength",
|
|
"Error.Object.FieldLengthExceeded255,UIGridLayoutShared.Label.GridKey","GridKey",value.Length>255);
|
|
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Set/get Name of item
|
|
///
|
|
///
|
|
/// </summary>
|
|
public string Name
|
|
{
|
|
get
|
|
{
|
|
return mName;
|
|
}
|
|
set
|
|
{
|
|
|
|
if(mName!=value)
|
|
{
|
|
mName = value;
|
|
|
|
BrokenRules.Assert("NameRequired",
|
|
"Error.Object.RequiredFieldEmpty,UIGridLayoutShared.Label.Name",
|
|
"Name",value.Length==0);
|
|
|
|
BrokenRules.Assert("NameLength",
|
|
"Error.Object.FieldLengthExceeded255,UIGridLayoutShared.Label.Name","Name",value.Length>255);
|
|
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region System.Object overrides
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override string ToString()
|
|
{
|
|
return "UIGridLayoutShared" + mGridKey+" - " +mName;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <returns></returns>
|
|
public override bool Equals(Object obj)
|
|
{
|
|
if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false;
|
|
UIGridLayoutShared c=(UIGridLayoutShared)obj;
|
|
return ((mID==c.mID));
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override int GetHashCode()
|
|
{
|
|
return ("UIGridLayoutShared" + mID).GetHashCode();
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// Get new object
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static UIGridLayoutShared NewItem()
|
|
{
|
|
return new UIGridLayoutShared();
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Fetch shared Grid layout requested
|
|
///
|
|
/// </summary>
|
|
/// <param name="_ID"></param>
|
|
/// <returns></returns>
|
|
public static UIGridLayoutShared GetItem(Guid _ID)
|
|
{
|
|
return (UIGridLayoutShared)DataPortal.Fetch(new Criteria(_ID));
|
|
|
|
}
|
|
|
|
|
|
#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 aUIGridLayoutShared WHERE " +
|
|
"aUIGridLayoutShared.aID=@ID"
|
|
);
|
|
dbCommandWrapper.AddInParameter("@ID",DbType.Guid,crit.ID);
|
|
|
|
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");
|
|
|
|
|
|
//UIGridLayoutShared fields
|
|
|
|
//Unbreaking property style
|
|
Name=dr.GetString("aName");
|
|
|
|
mLayoutSize=dr.GetInt32("aLayoutSize");
|
|
mID=crit.ID;
|
|
|
|
//Important: use property not internal field
|
|
//so that initial broken rule is unbroken on fetch
|
|
GridKey=dr.GetString("aGridKey");
|
|
|
|
//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 aUIGridLayoutShared WHERE aID=@ID");
|
|
cmDelete.AddInParameter("@ID",DbType.Guid,this.mID);
|
|
|
|
|
|
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 aUIGridLayoutShared (aGridKey, " +
|
|
"aName, aLayoutSize, aLayoutContent, " +
|
|
"aCreated,aModified,aCreator,aModifier) VALUES (@GridKey, " +
|
|
"@Name,@LayoutSize,@LayoutContent,@Created,@Modified,@CurrentUserID, " +
|
|
"@CurrentUserID)"
|
|
);
|
|
else
|
|
cm=DBUtil.GetCommandFromSQL(
|
|
"UPDATE aUIGridLayoutShared SET aGridKey=@GridKey, " +
|
|
"aName=@Name, " +
|
|
"aLayoutSize=@LayoutSize, aLayoutContent=@LayoutContent, " +
|
|
"aModifier=@CurrentUserID, " +
|
|
"aModified=@Modified WHERE aUIGridLayoutShared.aID=@ID "
|
|
);
|
|
|
|
cm.AddInParameter("@ID",DbType.Guid, mID);
|
|
cm.AddInParameter("@GridKey",DbType.String,this.mGridKey);
|
|
cm.AddInParameter("@Name",DbType.String,mName);
|
|
cm.AddInParameter("@LayoutSize",DbType.Int32,mLayoutSize);
|
|
cm.AddInParameter("@LayoutContent",DbType.Object,mLayoutContent);
|
|
|
|
//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 Guid ID;
|
|
public Criteria(Guid _ID)
|
|
{
|
|
ID=_ID;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}//end UIGridLayoutShared
|
|
|
|
}//end namespace GZTW.AyaNova.BLL |