/////////////////////////////////////////////////////////// // UIUserFormSetting.cs // Implementation of Class UIUserFormSetting // CSLA type: Editable Child // Created on: 06-"Rocktober"-2004 // Object design: John // Coded: John 06-"Rocktober"-2004 /////////////////////////////////////////////////////////// using System; using System.Data; using CSLA.Data; using GZTW.Data; using CSLA; using System.Threading; using CSLA.Security; namespace GZTW.AyaNova.BLL { /// /// Used by Windows forms user interface to /// hold settings pertaining to a forms last /// size and other pertinent display variables. /// /// Used to ensure that the forms appear the same as the /// user last left them in. /// /// [Serializable] public class UIUserFormSetting : BusinessBase { #region Attributes private Guid mUserID; private string mFormName; //private int mFormWidth; //private int mFormHeight; //private int mSplitPosition1; //private int mSplitPosition2; //private int mLocationX; //private int mLocationY; //Toolbar layout stuff //private int mToolBarManagerLayoutSize; //private byte[] mToolBarManagerLayoutContent; private string mLayout; #endregion #region Constructor /// /// Private constructor to prevent direct instantiation /// private UIUserFormSetting() { //Set as child object MarkAsChild(); mUserID=CurrentUserID; } #endregion #region Business properties /// /// User ID number /// public Guid UserID { get { return mUserID; } set { if(mUserID!=value) { mUserID=value; MarkDirty(); } } } /// /// /// public string FormName { get { return mFormName; } set { if(mFormName!=value) { mFormName=value; MarkDirty(); } } } /// /// Toolbar layout as xml fragment /// public string Layout { get { return mLayout; } set { if (mLayout != value) { mLayout = value; MarkDirty(); } } } /// /// Toolbar layout as dataset /// public DataSet LayoutDS { get { if (string.IsNullOrEmpty(mLayout)) return new DataSet(); System.IO.StringReader sr = new System.IO.StringReader(AyaBizUtils.EscapeXml(mLayout));//case 1724 DataSet ds = new DataSet(); ds.ReadXml(sr); return ds; } } #endregion #region System.Object overrides /// /// /// /// public override string ToString() { return "UIUserFormSetting"+ mFormName + mUserID.ToString() ; } /// /// public override bool Equals(Object obj) { if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false; UIUserFormSetting c=(UIUserFormSetting)obj; return ((mUserID==c.mUserID) && (mFormName==c.mFormName)); } /// /// /// /// public override int GetHashCode() { return ("UIUserFormSetting" + mFormName + mUserID).GetHashCode(); } #endregion #region Static methods /// /// Get new object /// /// internal static UIUserFormSetting NewItem(string FormName) { UIUserFormSetting child=new UIUserFormSetting(); child.FormName=FormName; return child; } /// /// GetItem /// /// /// internal static UIUserFormSetting GetItem(SafeDataReader dr) { UIUserFormSetting child = new UIUserFormSetting(); child.Fetch(dr); return child; } #endregion #region DAL DATA ACCESS /// /// Fetch /// /// private void Fetch(SafeDataReader dr) { //UIUserFormSetting fields mFormName=dr.GetString("aFormName"); //case 2102 added in schema 83 if (AyaBizUtils.GlobalX.DBSchemaVersion > 82) { mLayout = dr.GetString("ALAYOUT"); } MarkOld(); } /// /// Update /// /// 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 aUIUserFormSetting WHERE aUserID=@UserID AND aFormName=@FormName"); cmDelete.AddInParameter("@UserID",DbType.String,mUserID); cmDelete.AddInParameter("@FormName",DbType.String,mFormName); DBUtil.DB.ExecuteNonQuery(cmDelete, tr); //----------------------------- } MarkNew(); return; } #endregion #region Add / Update DBCommandWrapper cm = null; if(IsNew)//Add or update? cm=DBUtil.GetCommandFromSQL( "INSERT INTO aUIUserFormSetting (aUserID, aFormName, aLayout) " + "VALUES (@UserID, @FormName, @Layout)" ); else cm=DBUtil.GetCommandFromSQL( "UPDATE aUIUserFormSetting SET aUserID=@UserID, aFormName=@FormName, aLayout=@Layout " + "WHERE aUserID=@UserID AND aFormName=@FormName" ); //UIUserFormSetting fields cm.AddInParameter("@UserID",DbType.Guid,mUserID); cm.AddInParameter("@FormName",DbType.String,mFormName); cm.AddInParameter("@Layout", DbType.String, mLayout); DBUtil.DB.ExecuteNonQuery(cm, tr); MarkOld();//db is now synched with object #endregion } #endregion }//end UIUserFormSetting }//end namespace GZTW.AyaNova.BLL