582 lines
13 KiB
C#
582 lines
13 KiB
C#
///////////////////////////////////////////////////////////
|
|
// UIGridLayout.cs
|
|
// Implementation of Class UIGridLayout
|
|
// CSLA type: Editable Root
|
|
// Created on: Sept 24 2004
|
|
// Object design: John
|
|
// Coded: John Sept 24 2004
|
|
///////////////////////////////////////////////////////////
|
|
|
|
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>
|
|
/// DEPRECATED - DO NOT USE
|
|
/// OLD User interface grid layout preferences
|
|
/// WAS Used to store and retrieve user and default
|
|
/// layouts for all grid objects in user interface
|
|
/// DEPRECATED - DO NOT USE
|
|
/// </summary>
|
|
[Serializable]
|
|
public class UIGridLayout : BusinessBase
|
|
{
|
|
|
|
#region Attributes
|
|
|
|
|
|
private SmartDate mCreated;
|
|
private SmartDate mModified;
|
|
private Guid mCreator;
|
|
private Guid mModifier;
|
|
private Guid mUserID;
|
|
private string mGridKey=null;
|
|
private string mGridSubKey="";
|
|
private string mDescription="";
|
|
private int mLayoutSize;
|
|
private byte[] mLayoutContent;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
|
|
/// <summary>
|
|
/// Private constructor to prevent direct instantiation
|
|
/// </summary>
|
|
private UIGridLayout()
|
|
{
|
|
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>
|
|
///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
|
|
|
|
/// <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,UIGridLayout.Label.GridKey","GridKey",value.Length==0);
|
|
|
|
BrokenRules.Assert("GridKeyLength",
|
|
"Error.Object.FieldLengthExceeded255,UIGridLayout.Label.GridKey","GridKey",value.Length>255);
|
|
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set/get GridSubKey of item
|
|
///
|
|
/// </summary>
|
|
public string GridSubKey
|
|
{
|
|
get
|
|
{
|
|
return mGridSubKey;
|
|
}
|
|
set
|
|
{
|
|
|
|
if(mGridSubKey!=value)
|
|
{
|
|
mGridSubKey = value;
|
|
|
|
|
|
BrokenRules.Assert("GridSubKeyLength",
|
|
"Error.Object.FieldLengthExceeded255,UIGridLayout.Label.GridSubKey","GridSubKey",value.Length>255);
|
|
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Set/get description of item
|
|
/// Optional property
|
|
///
|
|
/// </summary>
|
|
public string Description
|
|
{
|
|
get
|
|
{
|
|
return mDescription;
|
|
}
|
|
set
|
|
{
|
|
|
|
if(mDescription!=value)
|
|
{
|
|
mDescription = value;
|
|
|
|
BrokenRules.Assert("DescriptionLength",
|
|
"Error.Object.FieldLengthExceeded255,UIGridLayout.Label.Description","Description",value.Length>255);
|
|
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region System.Object overrides
|
|
public override string ToString()
|
|
{
|
|
return "UIGridLayout" + mGridKey+" - " +mDescription;
|
|
}
|
|
|
|
///
|
|
/// <param name="obj"></param>
|
|
public override bool Equals(Object obj)
|
|
{
|
|
if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false;
|
|
UIGridLayout c=(UIGridLayout)obj;
|
|
return ((mGridSubKey==c.GridSubKey)&&(mGridKey==c.GridKey)&&(mUserID==c.mUserID));
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return ("UIGridLayout" + mUserID.ToString()+mGridKey+mGridSubKey).GetHashCode();
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// DEPRECATED - DO NOT USE
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static UIGridLayout NewItem()
|
|
{
|
|
return new UIGridLayout();
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// DEPRECATED - DO NOT USE
|
|
/// </summary>
|
|
/// <param name="sGridKey"></param>
|
|
/// <param name="sGridSubKey"></param>
|
|
/// <param name="UserID"></param>
|
|
/// <returns></returns>
|
|
public static UIGridLayout GetItem(string sGridKey,string sGridSubKey,Guid UserID)
|
|
{
|
|
|
|
|
|
UIGridLayout uTemp=(UIGridLayout)DataPortal.Fetch(new Criteria(sGridKey,sGridSubKey,UserID));
|
|
if(uTemp.mGridKey=="")
|
|
{
|
|
uTemp=(UIGridLayout)DataPortal.Fetch(new Criteria(sGridKey,sGridSubKey,Guid.Empty));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 aUIGridLayout WHERE " +
|
|
"(aUIGridLayout.aUserID=@UserID AND aUIGridLayout.aGridKey=@GridKey " +
|
|
"AND aUIGridLayout.aGridSubKey=@GridSubKey)"
|
|
);
|
|
dbCommandWrapper.AddInParameter("@UserID",DbType.Guid,crit.UserID);
|
|
dbCommandWrapper.AddInParameter("@GridKey",DbType.String,crit.GridKey);
|
|
dbCommandWrapper.AddInParameter("@GridSubKey",DbType.String,crit.GridSubKey);
|
|
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");
|
|
|
|
|
|
//UIGridLayout fields
|
|
|
|
mDescription=dr.GetString("aDescription");
|
|
mLayoutSize=dr.GetInt32("aLayoutSize");
|
|
mUserID=crit.UserID;
|
|
|
|
//Important: use property not internal field
|
|
//so that initial broken rule is unbroken on fetch
|
|
GridKey=crit.GridKey;
|
|
|
|
//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 aUIGridLayout WHERE aUserID=@UserID AND aGridKey=@GridKey " +
|
|
"AND aGridSubKey=@GridSubKey");
|
|
cmDelete.AddInParameter("@UserID",DbType.Guid,this.mUserID);
|
|
cmDelete.AddInParameter("@GridKey",DbType.String,this.mGridKey);
|
|
cmDelete.AddInParameter("@GridSubKey",DbType.String,this.mGridSubKey);
|
|
|
|
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 aUIGridLayout (aUserID, aGridKey, aGridSubKey, " +
|
|
"aDescription, aLayoutSize, aLayoutContent, " +
|
|
"aCreated,aModified,aCreator,aModifier) VALUES (@UserID,@GridKey,@GridSubKey, " +
|
|
"@Description,@LayoutSize,@LayoutContent,@Created,@Modified,@CurrentUserID, " +
|
|
"@CurrentUserID)"
|
|
);
|
|
else
|
|
cm=DBUtil.GetCommandFromSQL(
|
|
"UPDATE aUIGridLayout SET aUserID=@UserID, aGridKey=@GridKey, " +
|
|
"aGridSubKey=@GridSubKey, aDescription=@Description, " +
|
|
"aLayoutSize=@LayoutSize, aLayoutContent=@LayoutContent, " +
|
|
"aModifier=@CurrentUserID, " +
|
|
"aModified=@Modified WHERE aUIGridLayout.aUserID=@UserID " +
|
|
"AND aUIGridLayout.aGridKey=@GridKey AND " +
|
|
"aUIGridLayout.aGridSubKey=@GridSubKey"
|
|
);
|
|
|
|
cm.AddInParameter("@UserID",DbType.Guid,this.mUserID);
|
|
cm.AddInParameter("@GridKey",DbType.String,this.mGridKey);
|
|
cm.AddInParameter("@GridSubKey",DbType.String,this.mGridSubKey);
|
|
cm.AddInParameter("@Description",DbType.String,mDescription);
|
|
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 string GridKey;
|
|
public string GridSubKey;
|
|
public Guid UserID;
|
|
public Criteria(string _GridKey,string _GridSubKey, Guid _UserID)
|
|
{
|
|
GridSubKey=_GridSubKey;
|
|
GridKey=_GridKey;
|
|
UserID=_UserID;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}//end UIGridLayout
|
|
#pragma warning restore 1591
|
|
}//end namespace GZTW.AyaNova.BLL |