Files
ayanova7/source/bizobjects/AyaLib/GZTW.AyaNova.BLL/Region.cs
2018-06-29 19:47:36 +00:00

1668 lines
47 KiB
C#

///////////////////////////////////////////////////////////
// Region.cs
// Implementation of Class Region
// CSLA type: Editable Root
// Created on: 07-Jun-2004 8:41:34 AM
// Object design: Joyce
// Coded: John July 12 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>
/// Regions are used in AyaNova to compartmentalize objects and keep them separate. For example a <see cref="Client"/> can be set to a specific region
/// in which case only users also set to that Region will be able to see and use that Client.
///
/// In addition some default settings are applied from a regional level between Global and User settings.
/// </summary>
[Serializable]
public class Region : BusinessBase {
#region Attributes
private bool bReadOnly;
private Guid mID;
private string mName=null;
private bool mActive;
private SmartDate mCreated;
private SmartDate mModified;
private Guid mCreator;
private Guid mModifier;
/// <summary>
/// Address of AyaNova company - used in PO's and reports
/// </summary>
private Address mAddress;
// /// <summary>
// /// Select from TaxCode list
// /// </summary>
// private Guid mDefaultTaxCodeParts;
// /// <summary>
// /// Select from TaxCode list
// /// </summary>
// private Guid mDefaultTaxCodeServices;
//private Guid mDefaultWorkorderTemplate;
//private Guid mDefaultQuoteTemplate;
//private Guid mDefaultPurchaseOrderTemplate;
private string mDefaultLanguage="";
private Guid mWorkorderClosedStatus;
//case 53 client notifications
private bool mClientNotification = false;
private string mReplyToEmail = "youremail.here.com";
private string mWBIUrl = "http://www.yourdomain.com/AyaNovaWBI";
private bool mNotifyCSRAccepted = false;
private string mNotifyCSRMSG = "Your customer service request accepted message here";
private bool mNotifyCSRRejected = false;
private string mNotifyCSRRejectMSG = "Your customer service request rejected message here";
private bool mNotifyNewWO = false;
private string mNotifyNewWOMSG = "Your new workorder message here";
private bool mNotifyWOStatus = false;
private string mNotifyWOStatMSG = "Your workorder status message here";
private Guid mNotifyWOStatusID = Guid.Empty;
private bool mNotifyWOClosed = false;
private string mNotifyWOClosedMSG = "Your workorder closed message here";
private bool mNotifyWOClosedAttachWO = false;
private Guid mNotifyWOClosedRPT = Guid.Empty;
private bool mNotifyWOFollowUp = false;
private string mNotifyWOFollowUpMSG = "Your follow up message here";
private int mNotifyWOFollowUpDays = 10;
//case 1151
private RegionWoStatusNotifyItems mRegionWoStatusNotifyItems;
//case 1499
private bool mNotifyQuoteStatus = false;
private string mNotifyQuoteStatMSG = "Your Quote status message here";
private WorkorderQuoteStatusTypes mNotifyQuoteStatusType = WorkorderQuoteStatusTypes.NotSet;
private Guid mNotifyQuoteStatusRPT = Guid.Empty;
#endregion
#region Constructor
/// <summary>
/// Private constructor to prevent direct instantiation
/// </summary>
private Region()
{
//Set to read / write initially so that properties
//can be set
bReadOnly=false;
//New ID
mID = Guid.NewGuid();
//pre-break the rule
Name="";
mActive=true;
//
//Set record history to defaults
mCreated = new SmartDate(DBUtil.CurrentWorkingDateTime);
mModified=new SmartDate();
mCreator=Guid.Empty;
mModifier=Guid.Empty;
//case 1151
mRegionWoStatusNotifyItems = RegionWoStatusNotifyItems.NewItems();
}
#endregion
#region Business properties
/// <summary>
/// Get internal id number Read only property because it's set internally, not
/// externally
/// </summary>
public Guid ID
{
get
{
return mID;
}
}
/// <summary>
/// Get created date
///
///
/// </summary>
public string Created
{
get
{
return mCreated.ToString();
}
}
/// <summary>
/// Get modified date
///
///
/// </summary>
public string Modified
{
get
{
return mModified.ToString();
}
}
/// <summary>
/// Get user record ID of person who created this record
///
///
/// </summary>
public Guid Creator
{
get
{
return mCreator;
}
}
/// <summary>
/// Get user ID of person who modified this record
///
///
/// </summary>
public Guid Modifier
{
get
{
return mModifier;
}
}
/// <summary>
/// Set/get Name of item
///
/// </summary>
public string Name
{
get
{
return mName;
}
set
{
if(bReadOnly)
ThrowSetError();
else
{
if(mName!=value)
{
mName = value;
BrokenRules.Assert("NameRequired","Error.Object.RequiredFieldEmpty,Region.Label.Name","Name",value.Length==0);
BrokenRules.Assert("NameLength",
"Error.Object.FieldLengthExceeded255,Region.Label.Name","Name",value.Length>255);
MarkDirty();
}
}
}
}
/// <summary>
/// Get mailing address object for this region
/// (Note: this address is deliberately not indexed for searching)
/// </summary>
public Address MailToAddress
{
get
{
return mAddress;
}
}
/// <summary>
/// regions workorder closed status
/// </summary>
public Guid WorkorderClosedStatus
{
get
{
return mWorkorderClosedStatus;
}
set
{
if(bReadOnly)
ThrowSetError();
else
{
if(mWorkorderClosedStatus!=value)
{
mWorkorderClosedStatus = value;
MarkDirty();
}
}
}
}
/// <summary>
/// Regions default language
/// </summary>
public string DefaultLanguage
{
get
{
return mDefaultLanguage;
}
set
{
if(bReadOnly)
ThrowSetError();
else
{
if(mDefaultLanguage!=value)
{
mDefaultLanguage = value;
MarkDirty();
}
}
}
}
//public Guid DefaultPurchaseOrderTemplate
//{
// get
// {
// return mDefaultPurchaseOrderTemplate;
// }
// set
// {
// if(bReadOnly)
// ThrowSetError();
// else
// {
// if(mDefaultPurchaseOrderTemplate!=value)
// {
// mDefaultPurchaseOrderTemplate = value;
// MarkDirty();
// }
// }
// }
//}
//public Guid DefaultQuoteTemplate
//{
// get
// {
// return mDefaultQuoteTemplate;
// }
// set
// {
// if(bReadOnly)
// ThrowSetError();
// else
// {
// if(mDefaultQuoteTemplate!=value)
// {
// mDefaultQuoteTemplate = value;
// MarkDirty();
// }
// }
// }
//}
// /// <summary>
// /// Select from TaxCode list
// /// </summary>
// public Guid DefaultTaxCodeParts
// {
// get
// {
// return mDefaultTaxCodeParts;
// }
// set
// {
// if(bReadOnly)
// ThrowSetError();
// else
// {
// if(mDefaultTaxCodeParts!=value)
// {
// mDefaultTaxCodeParts = value;
// MarkDirty();
//
// }
// }
// }
// }
//
// /// <summary>
// /// Select from TaxCode list
// /// </summary>
// public Guid DefaultTaxCodeServices
// {
// get
// {
// return mDefaultTaxCodeServices;
// }
// set
// {
// if(bReadOnly)
// ThrowSetError();
// else
// {
// if(mDefaultTaxCodeServices!=value)
// {
// mDefaultTaxCodeServices = value;
// MarkDirty();
//
// }
// }
// }
// }
//public Guid DefaultWorkorderTemplate
//{
// get
// {
// return mDefaultWorkorderTemplate;
// }
// set
// {
// if(bReadOnly)
// ThrowSetError();
// else
// {
// if(mDefaultWorkorderTemplate!=value)
// {
// mDefaultWorkorderTemplate = value;
// MarkDirty();
// }
// }
// }
//}
/// <summary>
/// Active - selectable
/// </summary>
public bool Active
{
get
{
return mActive;
}
set
{
if(bReadOnly)
ThrowSetError();
else
{
if(mActive!=value)
{
mActive = value;
MarkDirty();
}
}
}
}
/// <summary>
/// Flag - indicates if current user can open the wiki page for this object
/// See <see cref="WikiPage.ShowWikiLink(RootObjectTypes, Guid)"/> method for details
///
/// This is cached for the lifetime of this object
/// </summary>
public bool CanWiki//case 73
{
get
{
if (!bCanWiki.HasValue)
bCanWiki = WikiPage.ShowWikiLink(RootObjectTypes.Region, mID);
return bCanWiki.Value;
}
}
//cache the result in case the UI calls this repeatedly
private bool? bCanWiki = null;
//Case 53 client notifications
/// <summary>
/// Turn on or off Client Notification for this region
/// </summary>
public bool ClientNotification
{
get
{
return mClientNotification;
}
set
{
if (bReadOnly)
ThrowSetError();
else
{
if (mClientNotification != value)
{
mClientNotification = value;
MarkDirty();
}
}
}
}
/// <summary>
/// Set/get ReplyToEmail
/// Used in Client Notification emails
/// </summary>
public string ReplyToEmail
{
get
{
return mReplyToEmail;
}
set
{
if (bReadOnly)
ThrowSetError();
else
{
if (mReplyToEmail != value)
{
mReplyToEmail = value;
BrokenRules.Assert("ReplyToEmailLength",
"Error.Object.FieldLengthExceeded500,Region.Label.ReplyToEmail", "ReplyToEmail", value.Length > 500);
MarkDirty();
}
}
}
}
/// <summary>
/// Set/get WBIUrl
/// Used in client notification emails
/// </summary>
public string WBIUrl
{
get
{
return mWBIUrl;
}
set
{
if (bReadOnly)
ThrowSetError();
else
{
if (mWBIUrl != value)
{
mWBIUrl = value;
BrokenRules.Assert("WBIUrlLength",
"Error.Object.FieldLengthExceeded500,Region.Label.WBIUrl", "WBIUrl", value.Length > 500);
MarkDirty();
}
}
}
}
/// <summary>
/// NotifyCSRAccepted notification on or off
/// </summary>
public bool NotifyCSRAccepted
{
get
{
return mNotifyCSRAccepted;
}
set
{
if (bReadOnly)
ThrowSetError();
else
{
if (mNotifyCSRAccepted != value)
{
mNotifyCSRAccepted = value;
MarkDirty();
}
}
}
}
/// <summary>
/// Set/get NotifyCSRMSG
/// Used in client notification emails
/// </summary>
public string NotifyCSRMSG
{
get
{
return mNotifyCSRMSG;
}
set
{
if (bReadOnly)
ThrowSetError();
else
{
if (mNotifyCSRMSG != value)
{
mNotifyCSRMSG = value;
MarkDirty();
}
}
}
}
/// <summary>
/// NotifyCSRRejected notification on or off
/// </summary>
public bool NotifyCSRRejected
{
get
{
return mNotifyCSRRejected;
}
set
{
if (bReadOnly)
ThrowSetError();
else
{
if (mNotifyCSRRejected != value)
{
mNotifyCSRRejected = value;
MarkDirty();
}
}
}
}
/// <summary>
/// Set/get NotifyCSRRejectMSG
/// Used in client notification emails
/// </summary>
public string NotifyCSRRejectMSG
{
get
{
return mNotifyCSRRejectMSG;
}
set
{
if (bReadOnly)
ThrowSetError();
else
{
if (mNotifyCSRRejectMSG != value)
{
mNotifyCSRRejectMSG = value;
MarkDirty();
}
}
}
}
/// <summary>
/// NotifyNewWO notification on or off
/// </summary>
public bool NotifyNewWO
{
get
{
return mNotifyNewWO;
}
set
{
if (bReadOnly)
ThrowSetError();
else
{
if (mNotifyNewWO != value)
{
mNotifyNewWO = value;
MarkDirty();
}
}
}
}
/// <summary>
/// Set/get NotifyNewWOMSG
/// Used in client notification emails
/// </summary>
public string NotifyNewWOMSG
{
get
{
return mNotifyNewWOMSG;
}
set
{
if (bReadOnly)
ThrowSetError();
else
{
if (mNotifyNewWOMSG != value)
{
mNotifyNewWOMSG = value;
MarkDirty();
}
}
}
}
/// <summary>
/// ************ DEPRECATED v7.0 ****************
/// DO NOT USE THIS PROPERTY, USE
/// <see cref="RegionWoStatusNotifyItems"/>
/// COLLECTION CLASS INSTEAD
/// ****************************************
///
/// NotifyWOStatus notification on or off
/// </summary>
public bool NotifyWOStatus
{
get
{
return mNotifyWOStatus;
}
set
{
if (bReadOnly)
ThrowSetError();
else
{
if (mNotifyWOStatus != value)
{
mNotifyWOStatus = value;
MarkDirty();
}
}
}
}
/// <summary>
/// ************ DEPRECATED v7.0 ****************
/// DO NOT USE THIS PROPERTY, USE
/// <see cref="RegionWoStatusNotifyItems"/>
/// COLLECTION CLASS INSTEAD
/// ****************************************
///
/// 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>
/// ************ DEPRECATED v7.0 ****************
/// DO NOT USE THIS PROPERTY, USE
/// <see cref="RegionWoStatusNotifyItems"/>
/// COLLECTION CLASS INSTEAD
/// ****************************************
///
/// 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>
/// NotifyWOClosed notification on or off
/// </summary>
public bool NotifyWOClosed
{
get
{
return mNotifyWOClosed;
}
set
{
if (bReadOnly)
ThrowSetError();
else
{
if (mNotifyWOClosed != value)
{
mNotifyWOClosed = value;
MarkDirty();
}
}
}
}
/// <summary>
/// Set/get NotifyWOClosedMSG
/// Used in client notification emails
/// </summary>
public string NotifyWOClosedMSG
{
get
{
return mNotifyWOClosedMSG;
}
set
{
if (bReadOnly)
ThrowSetError();
else
{
if (mNotifyWOClosedMSG != value)
{
mNotifyWOClosedMSG = value;
MarkDirty();
}
}
}
}
/// <summary>
/// NotifyWOClosedAttachWO attach pdf workorder report or not
/// to notification message
/// </summary>
public bool NotifyWOClosedAttachWO
{
get
{
return mNotifyWOClosedAttachWO;
}
set
{
if (bReadOnly)
ThrowSetError();
else
{
if (mNotifyWOClosedAttachWO != value)
{
mNotifyWOClosedAttachWO = value;
MarkDirty();
}
}
}
}
/// <summary>
/// Workorder report to use for
/// client notification
/// </summary>
public Guid NotifyWOClosedRPT
{
get
{
return mNotifyWOClosedRPT;
}
set
{
if (bReadOnly)
ThrowSetError();
else
{
if (mNotifyWOClosedRPT != value)
{
mNotifyWOClosedRPT = value;
MarkDirty();
}
}
}
}
/// <summary>
/// NotifyWOFollowUp notification on or off
/// </summary>
public bool NotifyWOFollowUp
{
get
{
return mNotifyWOFollowUp;
}
set
{
if (bReadOnly)
ThrowSetError();
else
{
if (mNotifyWOFollowUp != value)
{
mNotifyWOFollowUp = value;
MarkDirty();
}
}
}
}
/// <summary>
/// Set/get NotifyWOFollowUpMSG
/// Used in client notification emails
/// </summary>
public string NotifyWOFollowUpMSG
{
get
{
return mNotifyWOFollowUpMSG;
}
set
{
if (bReadOnly)
ThrowSetError();
else
{
if (mNotifyWOFollowUpMSG != value)
{
mNotifyWOFollowUpMSG = value;
MarkDirty();
}
}
}
}
/// <summary>
/// Set/get NotifyWOFollowUpDays
/// Used in client notification emails
/// Number of days after work order is closed
/// to send a follow up email.
/// </summary>
public int NotifyWOFollowUpDays
{
get
{
return mNotifyWOFollowUpDays;
}
set
{
if (bReadOnly)
ThrowSetError();
else
{
if (mNotifyWOFollowUpDays != value)
{
mNotifyWOFollowUpDays = value;
if (mNotifyWOFollowUpDays < 0) mNotifyWOFollowUpDays = 0;
MarkDirty();
}
}
}
}
//case 1151
/// <summary>
/// Collection of workorder status change notifications to be sent to clients
/// </summary>
public RegionWoStatusNotifyItems WoStatusNotifyItems
{
get
{
return mRegionWoStatusNotifyItems;
}
}
/// <summary>
/// NotifyQuoteStatus notification on or off
/// </summary>
public bool NotifyQuoteStatus
{
get
{
return mNotifyQuoteStatus;
}
set
{
if (bReadOnly)
ThrowSetError();
else
{
if (mNotifyQuoteStatus != value)
{
mNotifyQuoteStatus = value;
MarkDirty();
}
}
}
}
/// <summary>
/// Set/get message sent on quote status change
/// client notification emails
/// </summary>
public string NotifyQuoteStatMSG
{
get
{
return mNotifyQuoteStatMSG;
}
set
{
if (bReadOnly)
ThrowSetError();
else
{
if (mNotifyQuoteStatMSG != value)
{
mNotifyQuoteStatMSG = value;
MarkDirty();
}
}
}
}
/// <summary>
/// Quote status to notify customer about
/// </summary>
public WorkorderQuoteStatusTypes NotifyQuoteStatusType
{
get
{
return mNotifyQuoteStatusType;
}
set
{
if (bReadOnly)
ThrowSetError();
else
{
if (mNotifyQuoteStatusType != value)
{
mNotifyQuoteStatusType = value;
MarkDirty();
}
}
}
}
/// <summary>
/// Quote report to use for
/// client quote status changed notification
/// </summary>
public Guid NotifyQuoteStatusRPT
{
get
{
return mNotifyQuoteStatusRPT;
}
set
{
if (bReadOnly)
ThrowSetError();
else
{
if (mNotifyQuoteStatusRPT != value)
{
mNotifyQuoteStatusRPT = 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>
/// To string override
/// </summary>
/// <returns></returns>
public override string ToString()
{
return "Region" + mID.ToString();
}
///
/// <param name="obj"></param>
public override bool Equals(Object obj)
{
if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false;
Region c=(Region)obj;
return mID==c.mID;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public override int GetHashCode()
{
return ("Region" + mID).GetHashCode();
}
#endregion
#region Static methods
/// <summary>
/// Get new object
/// </summary>
/// <returns></returns>
public static Region NewItem()
{
if(AyaBizUtils.Right("Object.Region")>(int)SecurityLevelTypes.ReadOnly)
{
Region c = new Region();
c.mAddress=Address.NewItem();
c.mAddress.AddressType=AddressTypes.Postal;
c.mAddress.RootObjectID=c.ID;
c.mAddress.RootObjectType=RootObjectTypes.Region;
return c;
}
else
throw new System.Security.SecurityException(
string.Format(
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToCreate"),
LocalizedTextTable.GetLocalizedTextDirect("O.Region")));
}
///
/// <param name="_ID">Region Guid</param>
public static Region GetItem(Guid _ID)
{
//if(AyaBizUtils.Right("Object.Region")>(int)SecurityLevelTypes.NoAccess)
//Need biz object level rights to open this no matter what
//so security setting only affects UI
return (Region)DataPortal.Fetch(new Criteria(_ID));
// else
// throw new System.Security.SecurityException(
// string.Format(
// LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToRetrieve"),
// LocalizedTextTable.GetLocalizedTextDirect("O.Region")));
}
/// <summary>
/// Delete Region
/// </summary>
/// <param name="_ID">Region GUID</param>
public static void DeleteItem(Guid _ID)
{
//ensure no deletion of default region
if(_ID==DefaultRegionID)
{
throw new System.Security.SecurityException(
string.Format(
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToDeleteDefaultObject"),
LocalizedTextTable.GetLocalizedTextDirect("O.Region")));
}
if(AyaBizUtils.Right("Object.Region")>(int)SecurityLevelTypes.ReadWrite)
DataPortal.Delete(new Criteria(_ID));
else
throw new System.Security.SecurityException(
string.Format(
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToDelete"),
LocalizedTextTable.GetLocalizedTextDirect("O.Region")));
}
//case 58
//(Maybe it should have been called "AllRegionID")
/// <summary>
/// The one and only ID for the default region built into AyaNova
/// Anyone set to this region has access to *ALL* regions
///
/// </summary>
public static Guid DefaultRegionID
{
get
{
return new Guid("{8236E8D1-CAB1-4797-9C34-93861954AE6A}");
}
}
/// <summary>
/// Retrieve internal ID from name.
///
/// </summary>
/// <param name="Name">Text value</param>
/// <returns>Guid ID value or Guid.Empty if no match</returns>
public static Guid GetIDFromName(string Name)
{
return GuidFetcher.GetItem("AREGION", "ANAME", Name);
}
#endregion
#region DAL DATA ACCESS
#region Fetch
///
/// <param name="Criteria"></param>
protected override void DataPortal_Fetch(object Criteria)
{
//set to false to load items initially
bReadOnly=false;
Criteria crit = (Criteria)Criteria;
SafeDataReader dr = null;
try
{
dr=DBUtil.GetReaderFromSQLString("SELECT * FROM aRegion WHERE aID=@ID;",crit.ID);
if(!dr.Read())
DBUtil.ThrowFetchError("Region ID: " + crit.ID.ToString());
//Standard fields
mID=dr.GetGuid("aID");
mCreated=DBUtil.ToLocal(dr.GetSmartDate("aCreated"));
mModified=DBUtil.ToLocal(dr.GetSmartDate("aModified"));
mCreator=dr.GetGuid("aCreator");
mModifier=dr.GetGuid("aModifier");
//Region fields
//Important: use property not internal field
//so that initial broken rule is unbroken on fetch
Name = dr.GetString("aName");
mActive = dr.GetBoolean("AACTIVE");
mDefaultLanguage = dr.GetString("aLanguage");
mWorkorderClosedStatus = dr.GetGuid("aWorkorderClosedStatus");
//case 2102 added in schema 71
if (AyaBizUtils.GlobalX.DBSchemaVersion > 70)
{
//case 53
mClientNotification = dr.GetBoolean("ACLIENTNOTIFICATION");
mReplyToEmail = dr.GetString("AREPLYTOEMAIL");
//case 966
if (string.IsNullOrEmpty(mReplyToEmail))
ReplyToEmail = "youremail.here.com";
mWBIUrl = dr.GetString("AWBIURL");
mNotifyCSRAccepted = dr.GetBoolean("ANOTIFYCSRACCEPTED");
mNotifyCSRMSG = dr.GetString("ANOTIFYCSRMSG");
mNotifyCSRRejected = dr.GetBoolean("ANOTIFYCSRREJECTED");
mNotifyCSRRejectMSG = dr.GetString("ANOTIFYCSRREJECTMSG");
mNotifyNewWO = dr.GetBoolean("ANOTIFYNEWWO");
mNotifyNewWOMSG = dr.GetString("ANOTIFYNEWWOMSG");
mNotifyWOStatus = dr.GetBoolean("ANOTIFYWOSTATUS");
mNotifyWOStatMSG = dr.GetString("ANOTIFYWOSTATMSG");
mNotifyWOStatusID = dr.GetGuid("ANOTIFYWOSTATUSID");
mNotifyWOClosed = dr.GetBoolean("ANOTIFYWOCLOSED");
mNotifyWOClosedMSG = dr.GetString("ANOTIFYWOCLOSEDMSG");
mNotifyWOClosedAttachWO = dr.GetBoolean("ANOTIFYWOCLOSEDATTACHWO");
mNotifyWOClosedRPT = dr.GetGuid("ANOTIFYWOCLOSEDRPT");
mNotifyWOFollowUp = dr.GetBoolean("ANOTIFYWOFOLLOWUP");
mNotifyWOFollowUpMSG = dr.GetString("ANOTIFYWOFOLLOWUPMSG");
mNotifyWOFollowUpDays = dr.GetInt32("ANOTIFYWOFOLLOWUPDAYS");
}
if (mNotifyWOFollowUpDays < 1) mNotifyWOFollowUpDays = 1;
//case 2099 added in schema 116
if (AyaBizUtils.GlobalX.DBSchemaVersion > 115)
{
//case 1499
mNotifyQuoteStatus = dr.GetBoolean("ANOTIFYQUOTESTATUS");
mNotifyQuoteStatMSG = dr.GetString("ANOTIFYQUOTESTATMSG");
mNotifyQuoteStatusType = (WorkorderQuoteStatusTypes)dr.GetInt16("ANOTIFYQUOTESTATUSTYPE");
mNotifyQuoteStatusRPT = dr.GetGuid("ANOTIFYQUOTESTATUSRPT");
}
if(dr!=null) dr.Close();
//* Load child collection objects
//case 2099 added in schema 114
if (AyaBizUtils.GlobalX.DBSchemaVersion > 113)
{
//Workorder status change notifications
dr = DBUtil.GetReaderFromSQLString("SELECT * FROM AREGIONNOTIFYSTAT WHERE AREGIONID=@ID;", crit.ID);
mRegionWoStatusNotifyItems = RegionWoStatusNotifyItems.GetItems(dr);
if (dr != null) dr.Close();
}
//**************
//NEW METHOD
//MailToAddress
dr=DBUtil.GetReaderFromSQLString("SELECT * " +
"FROM AADDRESS WHERE aRootObjectID=@ID AND " +
"aRootObjectType=2 AND AADDRESSTYPE=1",crit.ID);
if(!dr.Read())
{
mAddress=Address.NewItem();
mAddress.RootObjectID=crit.ID;
mAddress.RootObjectType=RootObjectTypes.Region;
mAddress.AddressType=AddressTypes.Postal;
}
else
{
mAddress=Address.GetItem(dr);
}
//****************
if(dr!=null) dr.Close();
}
finally
{
if(dr!=null) dr.Close();
}
MarkOld();
//Get access rights level
bReadOnly=AyaBizUtils.Right("Object.Region")<(int)SecurityLevelTypes.ReadWrite;
}
#endregion fetch
#region Update
/// <summary>
/// Called by DataPortal to delete/add/update data into the database
/// </summary>
protected override void DataPortal_Update()
{
// 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,"aRegion");
#region Delete
if(IsDeleted)
{
if(!IsNew)
{
//ensure no deletion of default region
if(mID==DefaultRegionID)//case 58
{
throw new System.Security.SecurityException(
string.Format(
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToDeleteDefaultObject"),
LocalizedTextTable.GetLocalizedTextDirect("O.Region")));
}
//Delete object and child objects
DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aRegion WHERE aID = @ID;");
cmDelete.AddInParameter("@ID",DbType.Guid,this.mID);
//Delete all address record types with matching root object ID
DBCommandWrapper cmDeleteAddress = DBUtil.GetCommandFromSQL("DELETE FROM AADDRESS WHERE aRootObjectID = @ID;");
cmDeleteAddress.AddInParameter("@ID",DbType.Guid,this.mID);
using (IDbConnection connection = DBUtil.DB.GetConnection())
{
connection.Open();
IDbTransaction transaction = connection.BeginTransaction();
try
{
//case 73
DBUtil.RemoveDocs(transaction, RootObjectTypes.Region, this.mID);
DBUtil.DB.ExecuteNonQuery(cmDelete, transaction);
DBUtil.DB.ExecuteNonQuery(cmDeleteAddress, transaction);
// Commit the transaction
transaction.Commit();
}
catch
{
// Rollback transaction
transaction.Rollback();
throw;
}
finally
{
connection.Close();
}
}
//-----------------------------
}
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 aRegion (aID, AACTIVE, " +
"aLanguage, aName, aWorkorderClosedStatus, aCreated,aModified, " +
"aCreator,aModifier, "+
"ACLIENTNOTIFICATION, AREPLYTOEMAIL, AWBIURL, ANOTIFYCSRACCEPTED, ANOTIFYCSRMSG, ANOTIFYCSRREJECTED, ANOTIFYCSRREJECTMSG, " +
"ANOTIFYNEWWO, ANOTIFYNEWWOMSG, ANOTIFYWOSTATUS, ANOTIFYWOSTATMSG, ANOTIFYWOSTATUSID, ANOTIFYWOCLOSED, ANOTIFYWOCLOSEDMSG, " +
"ANOTIFYWOCLOSEDATTACHWO, ANOTIFYWOCLOSEDRPT, ANOTIFYWOFOLLOWUP, ANOTIFYWOFOLLOWUPMSG, ANOTIFYWOFOLLOWUPDAYS, " +
"ANOTIFYQUOTESTATUS, ANOTIFYQUOTESTATMSG, ANOTIFYQUOTESTATUSTYPE, ANOTIFYQUOTESTATUSRPT " +
") VALUES (@ID,@Active, " +
"@DefaultLanguage,@Name,@WorkorderClosedStatus, " +
"@Created,@Modified,@CurrentUserID,@CurrentUserID, " +
"@CLIENTNOTIFICATION, @REPLYTOEMAIL, @WBIURL, @NOTIFYCSRACCEPTED, @NOTIFYCSRMSG, @NOTIFYCSRREJECTED, @NOTIFYCSRREJECTMSG, " +
"@NOTIFYNEWWO, @NOTIFYNEWWOMSG, @NOTIFYWOSTATUS, @NOTIFYWOSTATMSG, @NOTIFYWOSTATUSID, @NOTIFYWOCLOSED, @NOTIFYWOCLOSEDMSG, " +
"@NOTIFYWOCLOSEDATTACHWO, @NOTIFYWOCLOSEDRPT, @NOTIFYWOFOLLOWUP, @NOTIFYWOFOLLOWUPMSG, @NOTIFYWOFOLLOWUPDAYS, " +
"@NOTIFYQUOTESTATUS, @NOTIFYQUOTESTATMSG, @NOTIFYQUOTESTATUSTYPE, @NOTIFYQUOTESTATUSRPT )"
);
else
cm=DBUtil.GetCommandFromSQL(
"UPDATE aRegion SET aID=@ID, AACTIVE=@Active, " +
"aLanguage=@DefaultLanguage, aName=@Name, " +
"ACLIENTNOTIFICATION=@CLIENTNOTIFICATION, AREPLYTOEMAIL=@REPLYTOEMAIL, " +
"AWBIURL=@WBIURL, ANOTIFYCSRACCEPTED=@NOTIFYCSRACCEPTED, " +
"ANOTIFYCSRMSG=@NOTIFYCSRMSG, ANOTIFYCSRREJECTED=@NOTIFYCSRREJECTED, " +
"ANOTIFYCSRREJECTMSG=@NOTIFYCSRREJECTMSG, ANOTIFYNEWWO=@NOTIFYNEWWO, " +
"ANOTIFYNEWWOMSG=@NOTIFYNEWWOMSG, ANOTIFYWOSTATUS=@NOTIFYWOSTATUS, " +
"ANOTIFYWOSTATMSG=@NOTIFYWOSTATMSG, ANOTIFYWOSTATUSID=@NOTIFYWOSTATUSID, " +
"ANOTIFYWOCLOSED=@NOTIFYWOCLOSED, ANOTIFYWOCLOSEDMSG=@NOTIFYWOCLOSEDMSG, " +
"ANOTIFYWOCLOSEDATTACHWO=@NOTIFYWOCLOSEDATTACHWO, ANOTIFYWOCLOSEDRPT=@NOTIFYWOCLOSEDRPT, " +
"ANOTIFYWOFOLLOWUP=@NOTIFYWOFOLLOWUP, ANOTIFYWOFOLLOWUPMSG=@NOTIFYWOFOLLOWUPMSG, " +
"ANOTIFYWOFOLLOWUPDAYS=@NOTIFYWOFOLLOWUPDAYS, " +
"ANOTIFYQUOTESTATUS=@NOTIFYQUOTESTATUS, ANOTIFYQUOTESTATMSG=@NOTIFYQUOTESTATMSG, ANOTIFYQUOTESTATUSTYPE=@NOTIFYQUOTESTATUSTYPE, ANOTIFYQUOTESTATUSRPT=@NOTIFYQUOTESTATUSRPT, " +
"aWorkorderClosedStatus=@WorkorderClosedStatus, aModifier=@CurrentUserID, " +
" aModified=@Modified WHERE " +
"aID=@ID"
);
cm.AddInParameter("@Name",DbType.String, mName);
cm.AddInParameter("@ID",DbType.Guid,mID);
cm.AddInParameter("@Active",DbType.Boolean, mActive);
cm.AddInParameter("@DefaultLanguage",DbType.String,mDefaultLanguage);
cm.AddInParameter("@WorkorderClosedStatus",DbType.Guid,mWorkorderClosedStatus);
cm.AddInParameter("@CLIENTNOTIFICATION", DbType.Boolean, mClientNotification);
cm.AddLargeStringInParameter("@REPLYTOEMAIL", mReplyToEmail);
cm.AddLargeStringInParameter("@WBIURL", mWBIUrl);
cm.AddInParameter("@NOTIFYCSRACCEPTED", DbType.Boolean, mNotifyCSRAccepted);
cm.AddInParameter("@NOTIFYCSRMSG", DbType.String, mNotifyCSRMSG);
cm.AddInParameter("@NOTIFYCSRREJECTED", DbType.Boolean, mNotifyCSRRejected);
cm.AddInParameter("@NOTIFYCSRREJECTMSG", DbType.String, mNotifyCSRRejectMSG);
cm.AddInParameter("@NOTIFYNEWWO", DbType.Boolean, mNotifyNewWO);
cm.AddInParameter("@NOTIFYNEWWOMSG", DbType.String, mNotifyNewWOMSG);
cm.AddInParameter("@NOTIFYWOSTATUS", DbType.Boolean, mNotifyWOStatus);
cm.AddInParameter("@NOTIFYWOSTATMSG", DbType.String, mNotifyWOStatMSG);
cm.AddInParameter("@NOTIFYWOSTATUSID", DbType.Guid, mNotifyWOStatusID);
cm.AddInParameter("@NOTIFYWOCLOSED", DbType.Boolean, mNotifyWOClosed);
cm.AddInParameter("@NOTIFYWOCLOSEDMSG", DbType.String, mNotifyWOClosedMSG);
cm.AddInParameter("@NOTIFYWOCLOSEDATTACHWO", DbType.Boolean, mNotifyWOClosedAttachWO);
cm.AddInParameter("@NOTIFYWOCLOSEDRPT", DbType.Guid, mNotifyWOClosedRPT);
cm.AddInParameter("@NOTIFYWOFOLLOWUP", DbType.Boolean, mNotifyWOFollowUp);
cm.AddInParameter("@NOTIFYWOFOLLOWUPMSG", DbType.String, mNotifyWOFollowUpMSG);
cm.AddInParameter("@NOTIFYWOFOLLOWUPDAYS", DbType.Int32, mNotifyWOFollowUpDays);
//case 1499
cm.AddInParameter("@NOTIFYQUOTESTATUS", DbType.Boolean, mNotifyQuoteStatus);
cm.AddInParameter("@NOTIFYQUOTESTATMSG", DbType.String, mNotifyQuoteStatMSG);
cm.AddInParameter("@NOTIFYQUOTESTATUSTYPE", DbType.Int16, (int)mNotifyQuoteStatusType);
cm.AddInParameter("@NOTIFYQUOTESTATUSRPT", DbType.Guid, mNotifyQuoteStatusRPT);
//Standard fields
cm.AddInParameter("@CurrentUserID",DbType.Guid, CurrentUserID);
cm.AddInParameter("@Created",DbType.DateTime, DBUtil.ToUTC(mCreated).DBValue);
cm.AddInParameter("@Modified",DbType.DateTime, DBUtil.ToUTC(dtModified));
using (IDbConnection connection = DBUtil.DB.GetConnection())
{
connection.Open();
IDbTransaction transaction = connection.BeginTransaction();
try
{
DBUtil.DB.ExecuteNonQuery(cm, transaction);
//MailToAddress
mAddress.Update(RootObjectTypes.Region,mID,AddressTypes.Postal,transaction);
//case 1151
mRegionWoStatusNotifyItems.Update(transaction);
MarkOld();//db is now synched with object
// Commit the transaction
transaction.Commit();
}
catch
{
// Rollback transaction
transaction.Rollback();
throw;
}
finally
{
connection.Close();
}
//Successful update so
//change modification time to match
this.mModified.Date=dtModified;
}
#endregion
}
#endregion update
#region Delete
/// <summary>
/// Remove a Region record from the database
/// </summary>
/// <param name="Criteria"></param>
protected override void DataPortal_Delete(object Criteria)
{
Criteria crit = (Criteria)Criteria;
//ensure no deletion of default region
if(crit.ID==DefaultRegionID)//case 58
{
throw new System.Security.SecurityException(
string.Format(
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToDeleteDefaultObject"),
LocalizedTextTable.GetLocalizedTextDirect("O.Region")));
}
//Delete object and child objects
DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aRegion WHERE aID = @ID;");
cmDelete.AddInParameter("@ID",DbType.Guid,crit.ID);
//Delete all address record types with matching root object ID
DBCommandWrapper cmDeleteAddress = DBUtil.GetCommandFromSQL("DELETE FROM AADDRESS WHERE aRootObjectID = @ID;");
cmDeleteAddress.AddInParameter("@ID",DbType.Guid,crit.ID);
using (IDbConnection connection = DBUtil.DB.GetConnection())
{
connection.Open();
IDbTransaction transaction = connection.BeginTransaction();
try
{
//case 73
DBUtil.RemoveDocs(transaction, RootObjectTypes.Region, crit.ID);
DBUtil.DB.ExecuteNonQuery(cmDelete, transaction);
DBUtil.DB.ExecuteNonQuery(cmDeleteAddress, transaction);
// Commit the transaction
transaction.Commit();
}
catch
{
// Rollback transaction
transaction.Rollback();
throw;
}
finally
{
connection.Close();
}
}
}
#endregion delete
#endregion
#region Override IsValid / IsDirty
//Override base class version if there are child objects
/// <summary>
/// Confirm business object is valid with no broken rules
/// </summary>
public override bool IsValid
{
get
{
return base.IsValid && mRegionWoStatusNotifyItems.IsValid;
}
}
/// <summary>
/// Check if business object has unsaved changes
/// </summary>
public override bool IsDirty
{
get
{
return base.IsDirty || mRegionWoStatusNotifyItems.IsDirty;
}
}
#endregion
#region criteria
/// <summary>
/// Criteria for identifying existing object
/// </summary>
[Serializable]
private class Criteria
{
public Guid ID;
public Criteria(Guid _ID)
{
ID=_ID;
}
}
#endregion
}//end Region
}//end namespace GZTW.AyaNova.BLL