protected void EntityContactInformationTerminateWindow_ButtonOk_OnClick(Object sender, EventArgs e) { Boolean success = true; if (!EntityContactInformationTerminateTerminationDate.SelectedDate.HasValue) { EntityContactInformationTerminateTerminationDate.SelectedDate = null; EntityContactInformationTerminateResponse.Text = "Unable to determine the requested Termination Date."; return; } Int64 terminatedEntityContactInformationId = Convert.ToInt64(EntityContactInformationTerminateId.Text); Client.Core.Entity.EntityContactInformation currentEntityContactInformation = MercuryApplication.EntityContactInformationGet(terminatedEntityContactInformationId, false); if (Convert.ToDateTime(EntityContactInformationTerminateTerminationDate.SelectedDate) < currentEntityContactInformation.EffectiveDate) { EntityContactInformationTerminateTerminationDate.SelectedDate = null; EntityContactInformationTerminateResponse.Text = "The requested Termination Date is not valid."; return; } success = MercuryApplication.EntityContactInformationTerminate(currentEntityContactInformation, EntityContactInformationTerminateTerminationDate.SelectedDate.Value); if (success) { EntityContactInformationHistoryGrid_ManualDataRebind(); EntityContactInformationTerminateTerminationDate.SelectedDate = null; Telerik.Web.UI.RadAjaxManager telerikAjaxManager = (Telerik.Web.UI.RadAjaxManager)Page.FindControl("TelerikAjaxManager"); if (telerikAjaxManager != null) { telerikAjaxManager.ResponseScripts.Add("EntityContactInformationTerminateWindow_Close ();"); } } else { if (MercuryApplication.LastException != null) { EntityContactInformationTerminateResponse.Text = MercuryApplication.LastException.Message; } else { EntityContactInformationTerminateResponse.Text = "Unknown exception occurreed. Unable to Terminate."; } } return; }
protected void ButtonOk_OnClick(Object sender, EventArgs e) { Telerik.Web.UI.GridDataItem selectedGridItem = (Telerik.Web.UI.GridDataItem)EntitySendCorrespondenceInformationGrid.SelectedItems[0]; Telerik.Web.UI.DataKey selectedDataKey = selectedGridItem.OwnerTableView.DataKeyValues[selectedGridItem.ItemIndex]; System.Text.RegularExpressions.Regex expressionValidator; Int64 correspondenceId = 0; Client.Core.Reference.Correspondence correspondence = null; Client.Core.Entity.EntityContactInformation entityContactInformation = null; #region Validation if (String.IsNullOrEmpty(SendCorrespondenceSelection.SelectedValue)) { ActionResponseLabel.Text = "** No Correspondence selected to send."; return; } if (!Int64.TryParse(SendCorrespondenceSelection.SelectedValue, out correspondenceId)) { ActionResponseLabel.Text = "** No Correspondence Selected."; return; } correspondence = MercuryApplication.CorrespondenceGet(correspondenceId, true); if (correspondence == null) { ActionResponseLabel.Text = "** Unable to retreive correspondence."; return; } if (!SendCorrespondenceDate.SelectedDate.HasValue) { ActionResponseLabel.Text = "** No valid send date selected."; return; } if (CorrespondenceUseAlternativeFaxNumber.Checked) { String faxPattern = @"^([\(]{1}[0-9]{3}[\)]{1}[\.| |\-]{0,1}|^[0-9]{3}[\.|\-| ]?)?[0-9]{3}(\.|\-| )?[0-9]{4}$"; expressionValidator = new System.Text.RegularExpressions.Regex(faxPattern); if (!expressionValidator.IsMatch(CorrespondenceAlternateFaxNumber.Text)) { ActionResponseLabel.Text = "** No valid alternate FAX number provided, or not in correct format."; return; } } if (CorrespondenceUseAlternativeEmail.Checked) { String emailPattern = @"^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$"; expressionValidator = new System.Text.RegularExpressions.Regex(emailPattern); if (!expressionValidator.IsMatch(CorrespondenceAlternateEmail.Text)) { ActionResponseLabel.Text = "** No valid alternate email provided, or not in correct format."; return; } } #endregion ActionResponseLabel.Text = String.Empty; entityCorrespondence = new Mercury.Client.Core.Entity.EntityCorrespondence(MercuryApplication); entityCorrespondence.EntityId = Int64.Parse(selectedDataKey["EntityId"].ToString()); entityCorrespondence.RelatedEntityId = (RelatedEntity != null) ? RelatedEntity.Id : 0; entityCorrespondence.CorrespondenceId = correspondence.Id; entityCorrespondence.CorrespondenceName = correspondence.Name; entityCorrespondence.CorrespondenceVersion = correspondence.Version; entityCorrespondence.ReadyToSendDate = SendCorrespondenceDate.SelectedDate.Value; entityCorrespondence.Attention = SendCorrespondenceAttention.Text; entityCorrespondence.Remarks = SendCorrespondenceRemarks.Text; Boolean useAlternateInformation = false; useAlternateInformation |= CorrespondenceUseAlternativeAddress.Checked; useAlternateInformation |= CorrespondenceUseAlternativeFaxNumber.Checked; useAlternateInformation |= CorrespondenceUseAlternativeEmail.Checked; if (!useAlternateInformation) { Mercury.Server.Application.EntityContactType contactType; contactType = (Mercury.Server.Application.EntityContactType)Convert.ToInt32(selectedDataKey["ContactType"].ToString()); switch (contactType) { case Mercury.Server.Application.EntityContactType.ByMail: entityCorrespondence.ContactType = contactType; entityCorrespondence.EntityAddressId = Convert.ToInt64(selectedDataKey["AddressId"].ToString()); Client.Core.Entity.EntityAddress entityAddress = MercuryApplication.EntityAddressGet(entityCorrespondence.EntityAddressId, false); if (entityAddress != null) { entityCorrespondence.AddressLine1 = entityAddress.Line1; entityCorrespondence.AddressLine2 = entityAddress.Line2; entityCorrespondence.AddressCity = entityAddress.City; entityCorrespondence.AddressState = entityAddress.State; entityCorrespondence.AddressZipCode = entityAddress.ZipCode; } break; case Mercury.Server.Application.EntityContactType.Facsimile: entityCorrespondence.ContactType = contactType; entityCorrespondence.EntityContactInformationId = Convert.ToInt64(selectedDataKey["AddressId"].ToString()); entityContactInformation = MercuryApplication.EntityContactInformationGet(entityCorrespondence.EntityContactInformationId, true); if (entityContactInformation != null) { entityCorrespondence.ContactFaxNumber = entityContactInformation.Number; } break; case Mercury.Server.Application.EntityContactType.Email: entityCorrespondence.ContactType = contactType; entityCorrespondence.EntityContactInformationId = Convert.ToInt64(selectedDataKey["AddressId"].ToString()); entityContactInformation = MercuryApplication.EntityContactInformationGet(entityCorrespondence.EntityContactInformationId, true); if (entityContactInformation != null) { entityCorrespondence.ContactEmail = entityContactInformation.Email; } break; case Mercury.Server.Application.EntityContactType.InPerson: entityCorrespondence.ContactType = contactType; break; default: ActionResponseLabel.Text = "Check selection. Unknown or unhandled contact type: " + contactType.ToString(); return; } } else if (CorrespondenceUseAlternativeAddress.Checked) { entityCorrespondence.ContactType = Mercury.Server.Application.EntityContactType.ByMail; entityCorrespondence.EntityAddressId = 0; entityCorrespondence.EntityContactInformationId = 0; entityCorrespondence.AddressLine1 = CorrespondenceAlternateAddressLine1.Text; entityCorrespondence.AddressLine2 = CorrespondenceAlternateAddressLine2.Text; entityCorrespondence.AddressCity = CorrespondenceAlternateAddressCity.Text; entityCorrespondence.AddressState = CorrespondenceAlternateAddressState.Text; entityCorrespondence.AddressZipCode = CorrespondenceAlternateAddressZipCode.Text; } else if (CorrespondenceUseAlternativeFaxNumber.Checked) { entityCorrespondence.ContactType = Mercury.Server.Application.EntityContactType.Facsimile; entityCorrespondence.EntityAddressId = 0; entityCorrespondence.EntityContactInformationId = 0; entityCorrespondence.ContactFaxNumber = CorrespondenceAlternateFaxNumber.Text; } else if (CorrespondenceUseAlternativeEmail.Checked) { entityCorrespondence.ContactType = Mercury.Server.Application.EntityContactType.Email; entityCorrespondence.EntityAddressId = 0; entityCorrespondence.EntityContactInformationId = 0; entityCorrespondence.ContactEmail = CorrespondenceAlternateEmail.Text; } else { ActionResponseLabel.Text = "Unable to determine method. Please check your selection."; return; } if (SendCorrespondence != null) { SendCorrespondence(this, new SendCorrespondenceEntityEventArgs(Entity, RelatedEntity, entityCorrespondence)); } return; }
protected void EntityContactInformationHistoryGrid_OnInsertUpdateCommand(Object sender, Telerik.Web.UI.GridCommandEventArgs e) { if (MercuryApplication == null) { return; } Telerik.Web.UI.GridEditFormItem item = (Telerik.Web.UI.GridEditFormItem)e.Item; Boolean isInsertMode = (e.Item is Telerik.Web.UI.GridEditFormInsertItem); Boolean hasValidationError = false; Telerik.Web.UI.RadComboBox EntityContactInformationEditContactType; Telerik.Web.UI.RadMaskedTextBox EntityContactInformationEditNumber; Telerik.Web.UI.RadTextBox EntityContactInformationEditExtension; Telerik.Web.UI.RadTextBox EntityContactInformationEditEmail; Telerik.Web.UI.RadDatePicker EntityContactInformationEditEffectiveDate; Telerik.Web.UI.RadDatePicker EntityContactInformationEditTerminationDate; Label EntityContactInformationSaveResponse; Client.Core.Entity.EntityContactInformation entityContactInformation; Client.Core.Entity.EntityContactInformation modifiedEntityContactInformation; EntityContactInformationEditContactType = (Telerik.Web.UI.RadComboBox)item.FindControl("EntityContactInformationEditContactType"); EntityContactInformationEditNumber = (Telerik.Web.UI.RadMaskedTextBox)item.FindControl("EntityContactInformationEditNumber"); EntityContactInformationEditExtension = (Telerik.Web.UI.RadTextBox)item.FindControl("EntityContactInformationEditExtension"); EntityContactInformationEditEmail = (Telerik.Web.UI.RadTextBox)item.FindControl("EntityContactInformationEditEmail"); EntityContactInformationEditEffectiveDate = (Telerik.Web.UI.RadDatePicker)item.FindControl("EntityContactInformationEditEffectiveDate"); EntityContactInformationEditTerminationDate = (Telerik.Web.UI.RadDatePicker)item.FindControl("EntityContactInformationEditTerminationDate"); EntityContactInformationSaveResponse = (Label)item.FindControl("EntityContactInformationSaveResponse"); if (isInsertMode) { entityContactInformation = new Client.Core.Entity.EntityContactInformation(MercuryApplication); modifiedEntityContactInformation = new Client.Core.Entity.EntityContactInformation(MercuryApplication); } else { // RELOAD BASED ON ID entityContactInformation = MercuryApplication.EntityContactInformationGet(Convert.ToInt64(item.GetDataKeyValue("Id")), false); modifiedEntityContactInformation = entityContactInformation.Copy(); } modifiedEntityContactInformation.EntityId = Entity.Id; modifiedEntityContactInformation.ContactType = (Mercury.Server.Application.EntityContactType)Convert.ToInt32(EntityContactInformationEditContactType.SelectedValue); modifiedEntityContactInformation.ContactSequence = 1; modifiedEntityContactInformation.Number = EntityContactInformationEditNumber.Text; modifiedEntityContactInformation.NumberExtension = EntityContactInformationEditExtension.Text; modifiedEntityContactInformation.Email = EntityContactInformationEditEmail.Text; if (EntityContactInformationEditEffectiveDate.SelectedDate.HasValue) { modifiedEntityContactInformation.EffectiveDate = EntityContactInformationEditEffectiveDate.SelectedDate.Value; } else { hasValidationError = true; EntityContactInformationSaveResponse.Text = "Invalid Effective Date selected."; } if (EntityContactInformationEditTerminationDate.SelectedDate.HasValue) { modifiedEntityContactInformation.TerminationDate = EntityContactInformationEditTerminationDate.SelectedDate.Value; } else { modifiedEntityContactInformation.TerminationDate = new DateTime(9999, 12, 31); } if ((!isInsertMode) && (entityContactInformation.IsEqual(modifiedEntityContactInformation))) { hasValidationError = true; EntityContactInformationSaveResponse.Text = "No modifications to contact information detected. Changes not saved."; } if (!hasValidationError) { // SAVE CHANGES hasValidationError = !MercuryApplication.EntityContactInformationSave(modifiedEntityContactInformation); if (hasValidationError) { if (MercuryApplication.LastException != null) { EntityContactInformationSaveResponse.Text = MercuryApplication.LastExceptionMessage; } else { EntityContactInformationSaveResponse.Text = "Unknown exception occurred. Unable to save changes."; } } } e.Canceled = hasValidationError; return; }