/////////////////////////////////////////////////////////// // WorkorderItemTask.cs // Implementation of Class WorkorderItemTask // CSLA type: Editable Child // Created on: 07-Jun-2004 8:41:50 AM // Object design: Joyce // Coded: John 26-July-2004 /////////////////////////////////////////////////////////// using System; using System.Data; using CSLA.Data; using GZTW.Data; using CSLA; using System.Threading; using CSLA.Security; namespace GZTW.AyaNova.BLL { /// /// A single task item for a work order /// [Serializable] public class WorkorderItemTask : BusinessBase { #region Attributes private bool bReadOnly; private Guid mID; private Guid mCreator; private Guid mModifier; private SmartDate mCreated; private SmartDate mModified; private Guid mTaskID; /// /// ID of WorkorderItem this task belongs with /// private Guid mWorkorderItemID; /// /// Whether completed, incomplete, not applicable Default is 0 (incomplete) /// private WorkorderItemTaskCompletionTypes mCompletionType; /// /// Back reference to group it came from /// private Guid mTaskGroupID; #endregion #region Constructor private WorkorderItemTask() { //Set to read / write initially so that properties //can be set bReadOnly=false; //Child object MarkAsChild(); //New ID mID = Guid.NewGuid(); //Set record history to defaults mCreated = new SmartDate(DBUtil.CurrentWorkingDateTime); mModified=new SmartDate(); mCreator=Guid.Empty; mModifier=Guid.Empty; mCompletionType = WorkorderItemTaskCompletionTypes.Incomplete; } #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; } } //---WorkorderItemTask specific properties /// /// /// public WorkorderItemTaskCompletionTypes WorkorderItemTaskCompletionType { get { return mCompletionType; } set { if(bReadOnly) ThrowSetError(); else { if(mCompletionType!=value) { mCompletionType = value; MarkDirty(); } } } } /// /// ID of /// public Guid TaskID { get { return mTaskID; } set { if(bReadOnly) ThrowSetError(); else { if(mTaskID!=value) { mTaskID = value; MarkDirty(); } } } } /// /// ID of /// public Guid TaskGroupID { get { return mTaskGroupID; } set { if(bReadOnly) ThrowSetError(); else { if(mTaskGroupID!=value) { mTaskGroupID = value; MarkDirty(); } } } } /// /// Guid ID of parent object /// public Guid WorkorderItemID { get { return mWorkorderItemID; } } /// /// Called by parent collection object /// when called in turn by workorder object that is read only due to /// security or closed or service completed /// /// Either true or the rights allowed for the current user public void SetReadOnly(bool RO) { bReadOnly=RO; } /// /// 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("WorkorderItemO.Task") ) ); } #endregion #region System.object overrides /// /// /// /// public override string ToString() { return "WorkorderItemTask" + mID.ToString(); } /// /// /// /// /// public override bool Equals(Object obj) { if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false; WorkorderItemTask c=(WorkorderItemTask)obj; return mID==c.mID; } /// /// /// /// public override int GetHashCode() { return ("WorkorderItemTask" + mID).GetHashCode(); } #endregion #region Static methods /// /// Create item /// /// Parent ID /// New Item internal static WorkorderItemTask NewItem(WorkorderItem obj) { //case 1387 if (AyaBizUtils.IsGenerator || ((obj.mHeaderRights > SecurityLevelTypes.ReadOnly) && (AyaBizUtils.Right("Object.WorkorderItemTask") > (int)SecurityLevelTypes.ReadOnly))) { WorkorderItemTask child=new WorkorderItemTask(); child.mWorkorderItemID=obj.ID; return child; } else throw new System.Security.SecurityException( string.Format( LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToCreate"), LocalizedTextTable.GetLocalizedTextDirect("WorkorderItemO.Task"))); } /// /// Retrieve item /// /// Data reader /// /// item from database internal static WorkorderItemTask GetItem(SafeDataReader dr, WorkorderItem obj) { //case 1387 if ((obj.mHeaderRights > SecurityLevelTypes.NoAccess) && (AyaBizUtils.Right("Object.WorkorderItemTask") > (int)SecurityLevelTypes.NoAccess)) { WorkorderItemTask child = new WorkorderItemTask(); child.Fetch(dr); return child; } else throw new System.Security.SecurityException( string.Format( LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToRetrieve"), LocalizedTextTable.GetLocalizedTextDirect("WorkorderItemO.Task"))); } #endregion #region DAL DATA ACCESS #region Fetch /// /// 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"); //WorkorderItemTask specific parameters mTaskID=dr.GetGuid("aTaskID"); mTaskGroupID=dr.GetGuid("aTaskGroupID"); mWorkorderItemID=dr.GetGuid("aWorkorderItemID"); mCompletionType=(WorkorderItemTaskCompletionTypes)dr.GetInt16("aWorkorderItemTaskCmpltnType"); //Get access rights level bReadOnly=AyaBizUtils.Right("Object.WorkorderItemTask")<(int)SecurityLevelTypes.ReadWrite; MarkOld(); } #endregion fetch #region Add / Update /// /// Persist object to database /// /// Parent object /// Parents transaction object internal void Update(WorkorderItem obj,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.CheckSafeToUpdateInsideTransaction(this.mModified.Date, this.mID, "aWorkorderItemTask", tr);//case 1960 #region Delete if(IsDeleted) { if(!IsNew) { DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aWorkorderItemTask 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 aWorkorderItemTask (aTaskID, aTaskGroupID, " + "aID, aWorkorderItemID, aWorkorderItemTaskCmpltnType, " + "aCreated,aModified,aCreator,aModifier) VALUES (@TaskID,@TaskGroupID, " + "@ID,@WorkorderItemID,@WorkorderItemTaskCompletionType, " + "@Created,@Modified,@CurrentUserID,@CurrentUserID)" ); else cm=DBUtil.GetCommandFromSQL( "UPDATE aWorkorderItemTask SET aTaskID=@TaskID, aTaskGroupID=@TaskGroupID, " + "aID=@ID, aWorkorderItemID=@WorkorderItemID, " + "aWorkorderItemTaskCmpltnType=@WorkorderItemTaskCompletionType, " + " aModifier=@CurrentUserID, " + " aModified=@Modified WHERE aID=@ID" ); //WorkorderItemTask specific parameters cm.AddInParameter("@ID",DbType.Guid,mID); cm.AddInParameter("@WorkorderItemID",DbType.Guid,mWorkorderItemID); cm.AddInParameter("@TaskID",DbType.Guid,mTaskID); cm.AddInParameter("@TaskGroupID",DbType.Guid,mTaskGroupID); cm.AddInParameter("@WorkorderItemTaskCompletionType",DbType.Int16,(int)mCompletionType); //standard parameters cm.AddInParameter("@CurrentUserID",DbType.Guid, CurrentUserID); cm.AddInParameter("@Created",DbType.DateTime, DBUtil.ToUTC(mCreated.Date)); cm.AddInParameter("@Modified",DbType.DateTime, DBUtil.ToUTC(dtModified)); 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 add/update #endregion }//end WorkorderItemTask }//end namespace GZTW.AyaNova.BLL