コード例 #1
0
        protected void btnAccept_Click(object sender, EventArgs e)
        {
            if (rbContactYes.Checked == false & rbContactNo.Checked == false)
            {
                msg.ShowWarning(Localization.GetString("ContactWarning"));
            }
            else
            {
                try
                {
                    var UPSReg = new Registration();

                    UPSReg.Address1 = inAddress1.Text.Trim();
                    if (inAddress2.Text.Trim().Length > 0)
                    {
                        UPSReg.Address2 = inAddress2.Text.Trim();
                    }
                    if (inAddress3.Text.Trim().Length > 0)
                    {
                        UPSReg.Address3 = inAddress3.Text.Trim();
                    }
                    UPSReg.City    = inCity.Text.Trim();
                    UPSReg.Company = inCompany.Text.Trim();
                    UPSReg.Title   = inTitle.Text.Trim();
                    UPSReg.Country = inCountry.SelectedValue;
                    UPSReg.Email   = inEmail.Text.Trim();
                    UPSReg.Name    = inName.Text.Trim();
                    UPSReg.URL     = inURL.Text.Trim();
                    UPSReg.Phone   = inPhone.Text.Trim();
                    if (inCountry.SelectedValue == "US" || inCountry.SelectedValue == "CA")
                    {
                        UPSReg.State = inState.SelectedValue;
                        UPSReg.Zip   = inZip.Text.Trim();
                    }
                    if (rbContactYes.Checked)
                    {
                        UPSReg.ContactMe = "yes";
                    }
                    else
                    {
                        UPSReg.ContactMe = "no";
                    }
                    UPSReg.AccountNumber = inUPSAccountNumber.Text.Trim();

                    var sTempLicense = lblLicense.Text;
                    sTempLicense = sTempLicense.Replace("&nbsp;<br/>", ((char)10).ToString());
                    sTempLicense = Server.HtmlDecode(sTempLicense);

                    UPSReg.License = sTempLicense;


                    if (UPSReg.AcceptLicense(UPSService.UPSLIVESERVER))
                    {
                        HccApp.CurrentStore.Settings.ShippingUpsLicense = UPSReg.LicenseNumber;

                        // Complete Registration process here...

                        var tempUsername = "******";
                        if (inPhone.Text.Trim().Length > 3)
                        {
                            tempUsername += inPhone.Text.Trim().Substring(inPhone.Text.Trim().Length - 4, 4);
                        }
                        UPSReg.Password = PasswordGenerator.GeneratePassword(10);
                        if (UPSReg.Password.Length > 10)
                        {
                            UPSReg.Password = UPSReg.Password.Substring(0, 10);
                        }

                        var RegistrationComplete    = false;
                        var MaxRegistrationAttempts = 10;
                        var CurrentAttempts         = 0;


                        while (true)
                        {
                            CurrentAttempts += 1;
                            if (RegistrationComplete | CurrentAttempts > MaxRegistrationAttempts)
                            {
                                break;
                            }
                            UPSReg.Username = tempUsername;

                            UPSReg.RequestSuggestedUsername = true;
                            if (UPSReg.Register(UPSService.UPSLIVESERVER))
                            {
                                // Got Suggested Username
                                UPSReg.Username = UPSReg.SuggestedUsername;

                                // Now attempt actual registration
                                UPSReg.RequestSuggestedUsername = false;
                                if (UPSReg.Register(UPSService.UPSLIVESERVER))
                                {
                                    HccApp.CurrentStore.Settings.ShippingUpsUsername = UPSReg.Username;
                                    HccApp.CurrentStore.Settings.ShippingUpsPassword = UPSReg.Password;
                                    HccApp.AccountServices.Stores.Update(HccApp.CurrentStore);
                                    RegistrationComplete = true;
                                    break;
                                }
                            }

                            UPSReg.RequestSuggestedUsername = false;
                        }

                        if (RegistrationComplete)
                        {
                            Response.Redirect("ShippingUpsThanks.aspx");
                        }
                        else
                        {
                            msg.ShowError(Localization.GetString("RegistrationIncompleteError"));
                        }
                    }
                    else
                    {
                        msg.ShowError(string.Concat(UPSReg.ErrorMessage, "<br/>", Localization.GetString("ErrorCode"),
                                                    ":", UPSReg.ErrorCode));
                    }
                }
                catch (Exception Ex)
                {
                    ExceptionLogger.LogException(Ex);
                    msg.ShowException(Ex);
                }
            }

            HccApp.UpdateCurrentStore();
        }