Exemplo n.º 1
0
        protected void ButtonOk_OnClick(Object sender, EventArgs e)
        {
            Telerik.Web.UI.GridDataItem selectedGridItem = (Telerik.Web.UI.GridDataItem)EntityContactInformationGrid.SelectedItems[0];

            Telerik.Web.UI.DataKey selectedDataKey = selectedGridItem.OwnerTableView.DataKeyValues[selectedGridItem.ItemIndex];


            if (String.IsNullOrEmpty(ContactRegarding.Text))
            {
                ActionResponseLabel.Text = "** Contact Regarding is required.";

                ActionResponseLabel.Visible = true;

                return;
            }

            if (!ContactDateTime.SelectedDate.HasValue)
            {
                ActionResponseLabel.Text = "** Contact Date/Time is required.";

                ActionResponseLabel.Visible = true;

                return;
            }

            else if (ContactDateTime.SelectedDate.Value > DateTime.Now)
            {
                ActionResponseLabel.Text = "** Contact Date/Time cannot be in the future.";

                ActionResponseLabel.Visible = true;

                return;
            }


            ActionResponseLabel.Text = String.Empty;

            ActionResponseLabel.Visible = false;


            entityContact = new Mercury.Client.Core.Entity.EntityContact(MercuryApplication);

            entityContact.EntityId = Convert.ToInt64(selectedDataKey["EntityId"]);

            entityContact.RelatedEntityId = (RelatedEntity != null) ? RelatedEntity.Id : 0;

            entityContact.EntityContactInformationId = Convert.ToInt64(selectedDataKey["Id"]);


            entityContact.ContactDate = (AllowEditContactDateTime) ? ContactDateTime.SelectedDate.Value : DateTime.Now;

            entityContact.ContactedByName = MercuryApplication.Session.UserDisplayName;


            entityContact.ContactType = (Server.Application.EntityContactType)selectedDataKey["ContactType"];

            entityContact.Direction = (Mercury.Server.Application.ContactDirection)Int32.Parse(ContactDirection.SelectedValue);


            entityContact.ContactRegardingId = (!String.IsNullOrWhiteSpace(ContactRegarding.SelectedValue)) ? Convert.ToInt64(ContactRegarding.SelectedValue) : 0;

            entityContact.Regarding = ContactRegarding.Text;

            entityContact.Remarks = ContactRemarks.Text;


            entityContact.Successful = (Int32.Parse(ContactOutcome.SelectedValue) == 1);

            entityContact.ContactOutcome = (Server.Application.ContactOutcome)Int32.Parse(ContactOutcome.SelectedValue);

            if (Contact != null)
            {
                Contact(this, new ContactEntityEventArgs(Entity, RelatedEntity, entityContact));
            }

            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;
        }