/////////////////////////////////////////////////////////// // 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 { /// /// Regions are used in AyaNova to compartmentalize objects and keep them separate. For example a 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. /// [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; /// /// Address of AyaNova company - used in PO's and reports /// private Address mAddress; // /// // /// Select from TaxCode list // /// // private Guid mDefaultTaxCodeParts; // /// // /// Select from TaxCode list // /// // 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 /// /// Private constructor to prevent direct instantiation /// 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 /// /// Get internal id number Read only property because it's set internally, not /// externally /// public Guid ID { get { return mID; } } /// /// Get created date /// /// /// public string Created { get { return mCreated.ToString(); } } /// /// Get modified date /// /// /// public string Modified { get { return mModified.ToString(); } } /// /// Get user record ID of person who created this record /// /// /// public Guid Creator { get { return mCreator; } } /// /// Get user ID of person who modified this record /// /// /// public Guid Modifier { get { return mModifier; } } /// /// Set/get Name of item /// /// 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(); } } } } /// /// Get mailing address object for this region /// (Note: this address is deliberately not indexed for searching) /// public Address MailToAddress { get { return mAddress; } } /// /// regions workorder closed status /// public Guid WorkorderClosedStatus { get { return mWorkorderClosedStatus; } set { if(bReadOnly) ThrowSetError(); else { if(mWorkorderClosedStatus!=value) { mWorkorderClosedStatus = value; MarkDirty(); } } } } /// /// Regions default language /// 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(); // } // } // } //} // /// // /// Select from TaxCode list // /// // public Guid DefaultTaxCodeParts // { // get // { // return mDefaultTaxCodeParts; // } // set // { // if(bReadOnly) // ThrowSetError(); // else // { // if(mDefaultTaxCodeParts!=value) // { // mDefaultTaxCodeParts = value; // MarkDirty(); // // } // } // } // } // // /// // /// Select from TaxCode list // /// // 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(); // } // } // } //} /// /// Active - selectable /// public bool Active { get { return mActive; } set { if(bReadOnly) ThrowSetError(); else { if(mActive!=value) { mActive = value; MarkDirty(); } } } } /// /// Flag - indicates if current user can open the wiki page for this object /// See method for details /// /// This is cached for the lifetime of this object /// 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 /// /// Turn on or off Client Notification for this region /// public bool ClientNotification { get { return mClientNotification; } set { if (bReadOnly) ThrowSetError(); else { if (mClientNotification != value) { mClientNotification = value; MarkDirty(); } } } } /// /// Set/get ReplyToEmail /// Used in Client Notification emails /// 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(); } } } } /// /// Set/get WBIUrl /// Used in client notification emails /// 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(); } } } } /// /// NotifyCSRAccepted notification on or off /// public bool NotifyCSRAccepted { get { return mNotifyCSRAccepted; } set { if (bReadOnly) ThrowSetError(); else { if (mNotifyCSRAccepted != value) { mNotifyCSRAccepted = value; MarkDirty(); } } } } /// /// Set/get NotifyCSRMSG /// Used in client notification emails /// public string NotifyCSRMSG { get { return mNotifyCSRMSG; } set { if (bReadOnly) ThrowSetError(); else { if (mNotifyCSRMSG != value) { mNotifyCSRMSG = value; MarkDirty(); } } } } /// /// NotifyCSRRejected notification on or off /// public bool NotifyCSRRejected { get { return mNotifyCSRRejected; } set { if (bReadOnly) ThrowSetError(); else { if (mNotifyCSRRejected != value) { mNotifyCSRRejected = value; MarkDirty(); } } } } /// /// Set/get NotifyCSRRejectMSG /// Used in client notification emails /// public string NotifyCSRRejectMSG { get { return mNotifyCSRRejectMSG; } set { if (bReadOnly) ThrowSetError(); else { if (mNotifyCSRRejectMSG != value) { mNotifyCSRRejectMSG = value; MarkDirty(); } } } } /// /// NotifyNewWO notification on or off /// public bool NotifyNewWO { get { return mNotifyNewWO; } set { if (bReadOnly) ThrowSetError(); else { if (mNotifyNewWO != value) { mNotifyNewWO = value; MarkDirty(); } } } } /// /// Set/get NotifyNewWOMSG /// Used in client notification emails /// public string NotifyNewWOMSG { get { return mNotifyNewWOMSG; } set { if (bReadOnly) ThrowSetError(); else { if (mNotifyNewWOMSG != value) { mNotifyNewWOMSG = value; MarkDirty(); } } } } /// /// ************ DEPRECATED v7.0 **************** /// DO NOT USE THIS PROPERTY, USE /// /// COLLECTION CLASS INSTEAD /// **************************************** /// /// NotifyWOStatus notification on or off /// public bool NotifyWOStatus { get { return mNotifyWOStatus; } set { if (bReadOnly) ThrowSetError(); else { if (mNotifyWOStatus != value) { mNotifyWOStatus = value; MarkDirty(); } } } } /// /// ************ DEPRECATED v7.0 **************** /// DO NOT USE THIS PROPERTY, USE /// /// COLLECTION CLASS INSTEAD /// **************************************** /// /// 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(); } } } } /// /// ************ DEPRECATED v7.0 **************** /// DO NOT USE THIS PROPERTY, USE /// /// COLLECTION CLASS INSTEAD /// **************************************** /// /// Workorder status to notify customer about /// public Guid NotifyWOStatusID { get { return mNotifyWOStatusID; } set { if (bReadOnly) ThrowSetError(); else { if (mNotifyWOStatusID != value) { mNotifyWOStatusID = value; MarkDirty(); } } } } /// /// NotifyWOClosed notification on or off /// public bool NotifyWOClosed { get { return mNotifyWOClosed; } set { if (bReadOnly) ThrowSetError(); else { if (mNotifyWOClosed != value) { mNotifyWOClosed = value; MarkDirty(); } } } } /// /// Set/get NotifyWOClosedMSG /// Used in client notification emails /// public string NotifyWOClosedMSG { get { return mNotifyWOClosedMSG; } set { if (bReadOnly) ThrowSetError(); else { if (mNotifyWOClosedMSG != value) { mNotifyWOClosedMSG = value; MarkDirty(); } } } } /// /// NotifyWOClosedAttachWO attach pdf workorder report or not /// to notification message /// public bool NotifyWOClosedAttachWO { get { return mNotifyWOClosedAttachWO; } set { if (bReadOnly) ThrowSetError(); else { if (mNotifyWOClosedAttachWO != value) { mNotifyWOClosedAttachWO = value; MarkDirty(); } } } } /// /// Workorder report to use for /// client notification /// public Guid NotifyWOClosedRPT { get { return mNotifyWOClosedRPT; } set { if (bReadOnly) ThrowSetError(); else { if (mNotifyWOClosedRPT != value) { mNotifyWOClosedRPT = value; MarkDirty(); } } } } /// /// NotifyWOFollowUp notification on or off /// public bool NotifyWOFollowUp { get { return mNotifyWOFollowUp; } set { if (bReadOnly) ThrowSetError(); else { if (mNotifyWOFollowUp != value) { mNotifyWOFollowUp = value; MarkDirty(); } } } } /// /// Set/get NotifyWOFollowUpMSG /// Used in client notification emails /// public string NotifyWOFollowUpMSG { get { return mNotifyWOFollowUpMSG; } set { if (bReadOnly) ThrowSetError(); else { if (mNotifyWOFollowUpMSG != value) { mNotifyWOFollowUpMSG = value; MarkDirty(); } } } } /// /// Set/get NotifyWOFollowUpDays /// Used in client notification emails /// Number of days after work order is closed /// to send a follow up email. /// public int NotifyWOFollowUpDays { get { return mNotifyWOFollowUpDays; } set { if (bReadOnly) ThrowSetError(); else { if (mNotifyWOFollowUpDays != value) { mNotifyWOFollowUpDays = value; if (mNotifyWOFollowUpDays < 0) mNotifyWOFollowUpDays = 0; MarkDirty(); } } } } //case 1151 /// /// Collection of workorder status change notifications to be sent to clients /// public RegionWoStatusNotifyItems WoStatusNotifyItems { get { return mRegionWoStatusNotifyItems; } } /// /// NotifyQuoteStatus notification on or off /// public bool NotifyQuoteStatus { get { return mNotifyQuoteStatus; } set { if (bReadOnly) ThrowSetError(); else { if (mNotifyQuoteStatus != value) { mNotifyQuoteStatus = value; MarkDirty(); } } } } /// /// Set/get message sent on quote status change /// client notification emails /// public string NotifyQuoteStatMSG { get { return mNotifyQuoteStatMSG; } set { if (bReadOnly) ThrowSetError(); else { if (mNotifyQuoteStatMSG != value) { mNotifyQuoteStatMSG = value; MarkDirty(); } } } } /// /// Quote status to notify customer about /// public WorkorderQuoteStatusTypes NotifyQuoteStatusType { get { return mNotifyQuoteStatusType; } set { if (bReadOnly) ThrowSetError(); else { if (mNotifyQuoteStatusType != value) { mNotifyQuoteStatusType = value; MarkDirty(); } } } } /// /// Quote report to use for /// client quote status changed notification /// public Guid NotifyQuoteStatusRPT { get { return mNotifyQuoteStatusRPT; } set { if (bReadOnly) ThrowSetError(); else { if (mNotifyQuoteStatusRPT != value) { mNotifyQuoteStatusRPT = 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 /// /// To string override /// /// public override string ToString() { return "Region" + mID.ToString(); } /// /// public override bool Equals(Object obj) { if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false; Region c=(Region)obj; return mID==c.mID; } /// /// /// /// public override int GetHashCode() { return ("Region" + mID).GetHashCode(); } #endregion #region Static methods /// /// Get new object /// /// 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"))); } /// /// Region Guid 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"))); } /// /// Delete Region /// /// Region GUID 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") /// /// The one and only ID for the default region built into AyaNova /// Anyone set to this region has access to *ALL* regions /// /// public static Guid DefaultRegionID { get { return new Guid("{8236E8D1-CAB1-4797-9C34-93861954AE6A}"); } } /// /// Retrieve internal ID from name. /// /// /// Text value /// Guid ID value or Guid.Empty if no match public static Guid GetIDFromName(string Name) { return GuidFetcher.GetItem("AREGION", "ANAME", Name); } #endregion #region DAL DATA ACCESS #region Fetch /// /// 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 /// /// Called by DataPortal to delete/add/update data into the database /// 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 /// /// Remove a Region record from the database /// /// 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 /// /// Confirm business object is valid with no broken rules /// public override bool IsValid { get { return base.IsValid && mRegionWoStatusNotifyItems.IsValid; } } /// /// Check if business object has unsaved changes /// public override bool IsDirty { get { return base.IsDirty || mRegionWoStatusNotifyItems.IsDirty; } } #endregion #region criteria /// /// Criteria for identifying existing object /// [Serializable] private class Criteria { public Guid ID; public Criteria(Guid _ID) { ID=_ID; } } #endregion }//end Region }//end namespace GZTW.AyaNova.BLL