Ejemplo n.º 1
0
        void AddressValidationControl_VerifyAddressClicked(AddressValidationControl ucontrol)
        {
            ucontrol.useSuggested.CheckState = CheckState.Unchecked;
            _isErrorFromResponse             = true;
            IContact contactRecord  = _recordContext.GetWorkspaceRecord(RightNow.AddIns.Common.WorkspaceRecordType.Contact) as IContact;
            Address  contactAddress = new Address();

            try
            {
                if (contactRecord.AddrCountryID != 1)
                {
                    string errorMsg = "Please--USA only postal address verification!";
                    ucontrol.addrValidResponseText.Text = errorMsg;
                    ConfigurationSetting.logWrap.NoticeLog(0, contactRecord.ID, logMessage: errorMsg);
                    return;
                }

                // get the contactRecord.Addrxxx
                contactAddress.Address2 = contactRecord.AddrStreet;
                contactAddress.City     = contactRecord.AddrCity;
                if (contactRecord.AddrProvID != null)
                {
                    contactAddress.StateID = (int)contactRecord.AddrProvID;
                }
                contactAddress.Zip = contactRecord.AddrPostalCode;

                _responseAddr = null;

                _responseAddr = ValidateAddress(contactAddress);

                string addressStg = _responseAddr.Address2 + ", " + _responseAddr.City
                                    + ", " + _responseAddr.State + " " + _responseAddr.Zip5 + "-" + _responseAddr.Zip4;

                ucontrol.addrValidResponseText.Text = "Address verified: " + addressStg;
                _isErrorFromResponse = false;
                ConfigurationSetting.logWrap.DebugLog(0, contactRecord.ID, logMessage: ucontrol.addrValidResponseText.Text);

                if (_responseAddr.ReturnText != null)
                {
                    string sanitizeMsg = _responseAddr.ReturnText.Replace("Default address:", "Address verified:");
                    ucontrol.addrValidResponseText.Text = sanitizeMsg + " " + addressStg;
                }
            }
            catch (Exception e)
            {
                // log e.Message
                if (e.Message.Contains("Authorization failure") ||
                    e.Message.Contains("Username exceeds maximum length") ||
                    e.Message.Contains("Misconfiguration or some other invalid data received."))
                {
                    ConfigurationSetting.logWrap.ErrorLog(0, contactRecord.ID, logMessage: e.Message);
                }
                else
                {
                    ConfigurationSetting.logWrap.NoticeLog(0, contactRecord.ID, logMessage: e.Message);
                }
                ucontrol.addrValidResponseText.Text = "Not valid: " + e.Message;
                _isErrorFromResponse = true;
            }
        }
 /// <summary>
 /// Method called by the Add-In framework to retrieve the control.
 /// </summary>
 /// <returns>The control, typically 'this'.</returns>
 public Control GetControl()
 {
     _uspsURL = ConfigurationSetting.ext_address_validate_url;
     _uspsUsername = ConfigurationSetting.uspsUsername;
     AddressValidationControl addressValidationControl = new AddressValidationControl();
     addressValidationControl.VerifyAddressClicked += new AddressValidationControl.VerifyAddressHandler(AddressValidationControl_VerifyAddressClicked);
     addressValidationControl.UsedSuggestedChanged += new AddressValidationControl.UsedSuggestedHandler(AddressValidationControl_UsedSuggestedChanged);
     return addressValidationControl;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Method called by the Add-In framework to retrieve the control.
        /// </summary>
        /// <returns>The control, typically 'this'.</returns>
        public Control GetControl()
        {
            _uspsURL      = ConfigurationSetting.ext_address_validate_url;
            _uspsUsername = ConfigurationSetting.uspsUsername;
            AddressValidationControl addressValidationControl = new AddressValidationControl();

            addressValidationControl.VerifyAddressClicked += new AddressValidationControl.VerifyAddressHandler(AddressValidationControl_VerifyAddressClicked);
            addressValidationControl.UsedSuggestedChanged += new AddressValidationControl.UsedSuggestedHandler(AddressValidationControl_UsedSuggestedChanged);
            return(addressValidationControl);
        }
        void AddressValidationControl_VerifyAddressClicked(AddressValidationControl ucontrol)
        {
            ucontrol.useSuggested.CheckState = CheckState.Unchecked;
            _isErrorFromResponse = true;
            IContact contactRecord = _recordContext.GetWorkspaceRecord(RightNow.AddIns.Common.WorkspaceRecordType.Contact) as IContact;
            Address contactAddress = new Address();
            try
            {
                if (contactRecord.AddrCountryID != 1)
                {
                    string errorMsg = "Please--USA only postal address verification!";
                    ucontrol.addrValidResponseText.Text = errorMsg;
                    ConfigurationSetting.logWrap.NoticeLog(0, contactRecord.ID, logMessage: errorMsg);
                    return;
                }

                // get the contactRecord.Addrxxx
                contactAddress.Address2 = contactRecord.AddrStreet;
                contactAddress.City = contactRecord.AddrCity;
                if (contactRecord.AddrProvID != null)
                    contactAddress.StateID = (int)contactRecord.AddrProvID;
                contactAddress.Zip = contactRecord.AddrPostalCode;

                _responseAddr = null;

                _responseAddr = ValidateAddress(contactAddress);
                
                string addressStg = _responseAddr.Address2 + ", " + _responseAddr.City 
                    + ", " + _responseAddr.State + " " + _responseAddr.Zip5 + "-" + _responseAddr.Zip4;

                 ucontrol.addrValidResponseText.Text = "Address verified: " + addressStg;
                 _isErrorFromResponse = false;
                 ConfigurationSetting.logWrap.DebugLog(0, contactRecord.ID, logMessage: ucontrol.addrValidResponseText.Text);
                
                if (_responseAddr.ReturnText != null)
                {
                    string sanitizeMsg = _responseAddr.ReturnText.Replace("Default address:", "Address verified:");
                    ucontrol.addrValidResponseText.Text = sanitizeMsg + " " + addressStg; 
                }
            }
            catch (Exception e)
            {
                // log e.Message  
                if (e.Message.Contains("Authorization failure") ||
                    e.Message.Contains("Username exceeds maximum length") ||
                    e.Message.Contains("Misconfiguration or some other invalid data received."))
                    ConfigurationSetting.logWrap.ErrorLog(0, contactRecord.ID, logMessage: e.Message);
                else
                    ConfigurationSetting.logWrap.NoticeLog(0, contactRecord.ID, logMessage: e.Message);
                ucontrol.addrValidResponseText.Text = "Not valid: " + e.Message;
                _isErrorFromResponse = true;
            }
        }
Ejemplo n.º 5
0
        void AddressValidationControl_UsedSuggestedChanged(AddressValidationControl ucontrol)
        {
            if (ucontrol.addrValidResponseText.Text == null || _isErrorFromResponse)
            {
                return;
            }

            if (ucontrol.useSuggested.Checked && !_isErrorFromResponse)
            {
                IContact contactRecord = _recordContext.GetWorkspaceRecord(RightNow.AddIns.Common.WorkspaceRecordType.Contact) as IContact;
                contactRecord.AddrStreet     = _responseAddr.Address2 + " " + _responseAddr.Address1;
                contactRecord.AddrCity       = _responseAddr.City;
                contactRecord.AddrProvID     = _responseAddr.StateID;
                contactRecord.AddrPostalCode = _responseAddr.Zip;
            }
        }
        void AddressValidationControl_UsedSuggestedChanged(AddressValidationControl ucontrol)
        {
            if (ucontrol.addrValidResponseText.Text == null || _isErrorFromResponse)
                return;

            if (ucontrol.useSuggested.Checked && !_isErrorFromResponse)
            {
                IContact contactRecord = _recordContext.GetWorkspaceRecord(RightNow.AddIns.Common.WorkspaceRecordType.Contact) as IContact;
                contactRecord.AddrStreet = _responseAddr.Address2 + " " + _responseAddr.Address1;
                contactRecord.AddrCity = _responseAddr.City;
                contactRecord.AddrProvID = _responseAddr.StateID;
                contactRecord.AddrPostalCode = _responseAddr.Zip;
            }
        }