This commit is contained in:
453
source/bizobjects/AyaLib/GZTW.AyaNova.BLL/WorkorderItemTask.cs
Normal file
453
source/bizobjects/AyaLib/GZTW.AyaNova.BLL/WorkorderItemTask.cs
Normal file
@@ -0,0 +1,453 @@
|
||||
///////////////////////////////////////////////////////////
|
||||
// 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
|
||||
{
|
||||
/// <summary>
|
||||
/// A single task item for a work order
|
||||
/// </summary>
|
||||
[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;
|
||||
/// <summary>
|
||||
/// ID of WorkorderItem this task belongs with
|
||||
/// </summary>
|
||||
private Guid mWorkorderItemID;
|
||||
/// <summary>
|
||||
/// Whether completed, incomplete, not applicable Default is 0 (incomplete)
|
||||
/// </summary>
|
||||
private WorkorderItemTaskCompletionTypes mCompletionType;
|
||||
|
||||
/// <summary>
|
||||
/// Back reference to group it came from
|
||||
/// </summary>
|
||||
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
|
||||
/// <summary>
|
||||
/// Initial created date of this object
|
||||
/// </summary>
|
||||
public string Created
|
||||
{
|
||||
get
|
||||
{
|
||||
return mCreated.ToString();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// User ID of who initially created this object
|
||||
/// </summary>
|
||||
public Guid Creator
|
||||
{
|
||||
get
|
||||
{
|
||||
return mCreator;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Last modified date of this object
|
||||
/// </summary>
|
||||
public string Modified
|
||||
{
|
||||
get
|
||||
{
|
||||
return mModified.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// User ID of who last modified this object
|
||||
/// </summary>
|
||||
public Guid Modifier
|
||||
{
|
||||
get
|
||||
{
|
||||
return mModifier;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unique ID of this object
|
||||
/// </summary>
|
||||
public Guid ID
|
||||
{
|
||||
get
|
||||
{
|
||||
return mID;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//---WorkorderItemTask specific properties
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="WorkorderItemTaskCompletionTypes"/>
|
||||
/// </summary>
|
||||
public WorkorderItemTaskCompletionTypes WorkorderItemTaskCompletionType
|
||||
{
|
||||
get
|
||||
{
|
||||
return mCompletionType;
|
||||
}
|
||||
set
|
||||
{
|
||||
if(bReadOnly)
|
||||
ThrowSetError();
|
||||
else
|
||||
{
|
||||
if(mCompletionType!=value)
|
||||
{
|
||||
mCompletionType = value;
|
||||
MarkDirty();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ID of <see cref="Task"/>
|
||||
/// </summary>
|
||||
public Guid TaskID
|
||||
{
|
||||
get
|
||||
{
|
||||
return mTaskID;
|
||||
}
|
||||
set
|
||||
{
|
||||
if(bReadOnly)
|
||||
ThrowSetError();
|
||||
else
|
||||
{
|
||||
if(mTaskID!=value)
|
||||
{
|
||||
mTaskID = value;
|
||||
MarkDirty();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ID of <see cref="TaskGroup"/>
|
||||
/// </summary>
|
||||
public Guid TaskGroupID
|
||||
{
|
||||
get
|
||||
{
|
||||
return mTaskGroupID;
|
||||
}
|
||||
set
|
||||
{
|
||||
if(bReadOnly)
|
||||
ThrowSetError();
|
||||
else
|
||||
{
|
||||
if(mTaskGroupID!=value)
|
||||
{
|
||||
mTaskGroupID = value;
|
||||
MarkDirty();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Guid ID of parent <see cref="WorkorderItem"/> object
|
||||
/// </summary>
|
||||
public Guid WorkorderItemID
|
||||
{
|
||||
get
|
||||
{
|
||||
return mWorkorderItemID;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Called by parent collection object
|
||||
/// when called in turn by workorder object that is read only due to
|
||||
/// security or closed or service completed
|
||||
/// </summary>
|
||||
/// <param name="RO">Either true or the rights allowed for the current user</param>
|
||||
public void SetReadOnly(bool RO)
|
||||
{
|
||||
bReadOnly=RO;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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)
|
||||
/// </summary>
|
||||
private void ThrowSetError()
|
||||
{
|
||||
throw new System.Security.SecurityException
|
||||
(
|
||||
string.Format
|
||||
(
|
||||
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToChange"),
|
||||
LocalizedTextTable.GetLocalizedTextDirect("WorkorderItemO.Task")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region System.object overrides
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return "WorkorderItemTask" + mID.ToString();
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public override bool Equals(Object obj)
|
||||
{
|
||||
if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false;
|
||||
WorkorderItemTask c=(WorkorderItemTask)obj;
|
||||
return mID==c.mID;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return ("WorkorderItemTask" + mID).GetHashCode();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Static methods
|
||||
/// <summary>
|
||||
/// Create item
|
||||
/// </summary>
|
||||
/// <param name="obj">Parent ID</param>
|
||||
/// <returns>New Item</returns>
|
||||
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")));
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve item
|
||||
/// </summary>
|
||||
/// <param name="dr">Data reader</param>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns>item from database</returns>
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
/// Fetch from db
|
||||
/// </summary>
|
||||
/// <param name="dr"></param>
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
/// Persist object to database
|
||||
/// </summary>
|
||||
/// <param name="obj">Parent object</param>
|
||||
/// <param name="tr">Parents transaction object</param>
|
||||
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
|
||||
Reference in New Issue
Block a user