479 lines
12 KiB
C#
479 lines
12 KiB
C#
///////////////////////////////////////////////////////////
|
|
// 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
|
|
{
|
|
/// <summary>
|
|
/// Workorder status change notification to a <see cref="Region"/> object's <see cref="Client"/> objects work orders
|
|
/// </summary>
|
|
[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
|
|
/// <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;
|
|
}
|
|
}
|
|
|
|
//---RegionWoStatusNotifyItem specific properties
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
public bool Active
|
|
{
|
|
get
|
|
{
|
|
return mActive;
|
|
}
|
|
set
|
|
{
|
|
if (bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if (mActive != value)
|
|
{
|
|
mActive = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set/get NotifyWOStatMSG
|
|
/// Used in client notification emails
|
|
/// </summary>
|
|
public string NotifyWOStatMSG
|
|
{
|
|
get
|
|
{
|
|
return mNotifyWOStatMSG;
|
|
}
|
|
set
|
|
{
|
|
if (bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if (mNotifyWOStatMSG != value)
|
|
{
|
|
mNotifyWOStatMSG = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Workorder status to notify customer about
|
|
/// </summary>
|
|
public Guid NotifyWOStatusID
|
|
{
|
|
get
|
|
{
|
|
return mNotifyWOStatusID;
|
|
}
|
|
set
|
|
{
|
|
if (bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if (mNotifyWOStatusID != value)
|
|
{
|
|
mNotifyWOStatusID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Workorder report to use for
|
|
/// client notification
|
|
/// </summary>
|
|
public Guid WoReportID
|
|
{
|
|
get
|
|
{
|
|
return mWoReportID;
|
|
}
|
|
set
|
|
{
|
|
if (bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if (mWoReportID != value)
|
|
{
|
|
mWoReportID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Parent Region ID
|
|
/// </summary>
|
|
public Guid RegionID
|
|
{
|
|
get
|
|
{
|
|
return mRegionID;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if (mRegionID != value)
|
|
{
|
|
mRegionID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <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("O.Region")
|
|
)
|
|
);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region System.object overrides
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override string ToString()
|
|
{
|
|
return "RegionWoStatusNotifyItem" + mID.ToString();
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <returns></returns>
|
|
public override bool Equals(Object obj)
|
|
{
|
|
if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false;
|
|
RegionWoStatusNotifyItem c=(RegionWoStatusNotifyItem)obj;
|
|
return (mID==c.ID);
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override int GetHashCode()
|
|
{
|
|
return ("RegionWoStatusNotifyItem" + mID.ToString()).GetHashCode();
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// NewItem
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <returns></returns>
|
|
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")));
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve item
|
|
/// </summary>
|
|
/// <param name="dr">Data reader</param>
|
|
/// <returns>item from database</returns>
|
|
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
|
|
|
|
/// <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");
|
|
|
|
//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();
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update
|
|
/// </summary>
|
|
/// <param name="tr"></param>
|
|
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 |