/////////////////////////////////////////////////////////// // RegionWoStatusNotifyItem.cs // Implementation of Class RegionWoStatusNotifyItem // CSLA type: Editable Child // Created on: 21-Dec-2010 // Object design: John // Coded: John 21-Dec-2010 /////////////////////////////////////////////////////////// using System; using System.Data; using CSLA.Data; using CSLA; using System.Threading; using CSLA.Security; using GZTW.Data; namespace GZTW.AyaNova.BLL { /// /// Workorder status change notification to a object's objects work orders /// [Serializable] public class RegionWoStatusNotifyItem : BusinessBase { #region Attributes private bool bReadOnly; //Used only for keyword indexing //and assigned docs collection //primary key is user and certification ID combo private Guid mID; private Guid mCreator; private Guid mModifier; private SmartDate mCreated; private SmartDate mModified; private bool mActive = false; private string mNotifyWOStatMSG = "Your workorder status message here"; private Guid mNotifyWOStatusID = Guid.Empty; private Guid mWoReportID = Guid.Empty; private Guid mRegionID; #endregion #region Constructor private RegionWoStatusNotifyItem() { //Set to read / write initially so that properties //can be set bReadOnly=false; //New ID - For assigned Docs list only mID = Guid.NewGuid(); //Child object MarkAsChild(); //Set record history to defaults mCreated = new SmartDate(DBUtil.CurrentWorkingDateTime); mModified=new SmartDate(); mCreator=Guid.Empty; mModifier=Guid.Empty; } #endregion #region BusinessProperties //---Common properties /// /// Initial created date of this object /// public string Created { get { return mCreated.ToString(); } } /// /// User ID of who initially created this object /// public Guid Creator { get { return mCreator; } } /// /// Last modified date of this object /// public string Modified { get { return mModified.ToString(); } } /// /// User ID of who last modified this object /// public Guid Modifier { get { return mModifier; } } /// /// Unique ID of this object /// public Guid ID { get { return mID; } } //---RegionWoStatusNotifyItem specific properties /// /// Turn this particular notification on or off /// if not active won't be checked at all on status changes /// turning it on won't catch past status changes, only future ones. /// public bool Active { get { return mActive; } set { if (bReadOnly) ThrowSetError(); else { if (mActive != value) { mActive = value; MarkDirty(); } } } } /// /// Set/get NotifyWOStatMSG /// Used in client notification emails /// public string NotifyWOStatMSG { get { return mNotifyWOStatMSG; } set { if (bReadOnly) ThrowSetError(); else { if (mNotifyWOStatMSG != value) { mNotifyWOStatMSG = value; MarkDirty(); } } } } /// /// Workorder status to notify customer about /// public Guid NotifyWOStatusID { get { return mNotifyWOStatusID; } set { if (bReadOnly) ThrowSetError(); else { if (mNotifyWOStatusID != value) { mNotifyWOStatusID = value; MarkDirty(); } } } } /// /// Workorder report to use for /// client notification /// public Guid WoReportID { get { return mWoReportID; } set { if (bReadOnly) ThrowSetError(); else { if (mWoReportID != value) { mWoReportID = value; MarkDirty(); } } } } /// /// Parent Region ID /// public Guid RegionID { get { return mRegionID; } set { if(bReadOnly) ThrowSetError(); else { if (mRegionID != value) { mRegionID = value; MarkDirty(); } } } } /// /// Throw an error when a read only user /// tries to set a property /// (this should normally never be called unless someone is using the developer api since the UI /// should prevent it from happening initially) /// private void ThrowSetError() { throw new System.Security.SecurityException ( string.Format ( LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToChange"), LocalizedTextTable.GetLocalizedTextDirect("O.Region") ) ); } #endregion #region System.object overrides /// /// /// /// public override string ToString() { return "RegionWoStatusNotifyItem" + mID.ToString(); } /// /// /// /// /// public override bool Equals(Object obj) { if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false; RegionWoStatusNotifyItem c=(RegionWoStatusNotifyItem)obj; return (mID==c.ID); } /// /// /// /// public override int GetHashCode() { return ("RegionWoStatusNotifyItem" + mID.ToString()).GetHashCode(); } #endregion #region Static methods /// /// NewItem /// /// /// internal static RegionWoStatusNotifyItem NewItem(Region obj) { if (AyaBizUtils.Right("Object.Region") > (int)SecurityLevelTypes.ReadOnly) { RegionWoStatusNotifyItem child=new RegionWoStatusNotifyItem(); child.RegionID=obj.ID; return child; } else throw new System.Security.SecurityException( string.Format( LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToCreate"), LocalizedTextTable.GetLocalizedTextDirect("O.Region"))); } /// /// Retrieve item /// /// Data reader /// item from database internal static RegionWoStatusNotifyItem GetItem(SafeDataReader dr) { if(AyaBizUtils.Right("Object.Region")>(int)SecurityLevelTypes.NoAccess) { RegionWoStatusNotifyItem child = new RegionWoStatusNotifyItem(); child.Fetch(dr); return child; } else throw new System.Security.SecurityException( string.Format( LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToRetrieve"), LocalizedTextTable.GetLocalizedTextDirect("O.Region"))); } #endregion #region DAL Data Access /// /// Fetch from db /// /// private void Fetch(SafeDataReader dr) { //Standard items mCreated = DBUtil.ToLocal(dr.GetSmartDate("aCreated")); mCreator = dr.GetGuid("aCreator"); mModified = DBUtil.ToLocal(dr.GetSmartDate("aModified")); mModifier = dr.GetGuid("aModifier"); mID = dr.GetGuid("aID"); //specific items mNotifyWOStatMSG = dr.GetString("ANOTIFYWOSTATMSG"); mNotifyWOStatusID = dr.GetGuid("ANOTIFYWOSTATUSID"); mActive = dr.GetBoolean("AACTIVE"); mWoReportID = dr.GetGuid("AWOREPORTID"); mRegionID = dr.GetGuid("AREGIONID"); //Get access rights level bReadOnly = AyaBizUtils.Right("Object.Region") < (int)SecurityLevelTypes.ReadWrite; MarkOld(); } /// /// Update /// /// internal void Update(IDbTransaction tr) { //No need to update if there is nothing changed if(!this.IsDirty) return; // 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, "AREGIONNOTIFYSTAT"); #region Delete if(IsDeleted) { if(!IsNew) { DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM AREGIONNOTIFYSTAT WHERE aID = @ID;"); cmDelete.AddInParameter("@ID",DbType.Guid,this.mID); DBUtil.DB.ExecuteNonQuery(cmDelete, tr); } 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 AREGIONNOTIFYSTAT (aID, aCreated, aModified, aCreator,aModifier, AREGIONID, AACTIVE, ANOTIFYWOSTATMSG, ANOTIFYWOSTATUSID, AWOREPORTID ) " + " VALUES (@ID,@Created,@Modified,@CurrentUserID,@CurrentUserID, @AREGIONID, @AACTIVE, @ANOTIFYWOSTATMSG, @ANOTIFYWOSTATUSID, @AWOREPORTID)" ); else cm=DBUtil.GetCommandFromSQL( "UPDATE AREGIONNOTIFYSTAT SET " + " AID=@ID, AMODIFIER=@CURRENTUSERID, " + " AMODIFIED=@MODIFIED, " + " AREGIONID=@AREGIONID, AACTIVE=@AACTIVE, ANOTIFYWOSTATMSG=@ANOTIFYWOSTATMSG, ANOTIFYWOSTATUSID=@ANOTIFYWOSTATUSID, AWOREPORTID=@AWOREPORTID " + " WHERE AID=@ID" ); cm.AddInParameter("@ID",DbType.Guid, mID); cm.AddInParameter("@CURRENTUSERID",DbType.Guid, CurrentUserID); cm.AddInParameter("@CREATED",DbType.DateTime, DBUtil.ToUTC(mCreated).DBValue); cm.AddInParameter("@MODIFIED",DbType.DateTime, DBUtil.ToUTC(dtModified)); cm.AddInParameter("@AREGIONID", DbType.Guid, mRegionID); cm.AddInParameter("@AACTIVE", DbType.Boolean, mActive); cm.AddLargeStringInParameter("@ANOTIFYWOSTATMSG", mNotifyWOStatMSG); cm.AddInParameter("@ANOTIFYWOSTATUSID", DbType.Guid, mNotifyWOStatusID); cm.AddInParameter("@AWOREPORTID", DbType.Guid, mWoReportID); DBUtil.DB.ExecuteNonQuery(cm, tr); MarkOld();//db is now synched with object //Successful update so //change modification time to match this.mModified.Date=dtModified; #endregion } #endregion }//end RegionWoStatusNotifyItem }//end namespace GZTW.AyaNova.BLL