Example #1
0
        /// <summary>
        /// Validate Address using API specified in AppConfig VerifyAddressesProvider.
        /// <para>This static public method is to be used without requiring the declaration
        /// of an AddressValidation instance.</para>
        /// </summary>
        /// <param name="EnteredAddress">The address as entered by a customer</param>
        /// <param name="ResultAddress">The resulting validated address</param>
        /// <returns>String,
        /// ro_OK => ResultAddress = EnteredAddress proceed with no further user review,
        /// 'some message' => address requires edit or verification by customer
        /// </returns>
        static public String RunValidate(Address EnteredAddress, out Address ResultAddress)
        {
            AddressValidation av = new AddressValidation();

            return(av.Validate(EnteredAddress, out ResultAddress));
        }
Example #2
0
        void btnNewAddress_Click(object sender, EventArgs e)
        {
            lblErrMsg.Text = "";
            AddressTypes AddressType = (AddressTypes)Enum.Parse(typeof(AddressTypes), AddressTypeString, true);
            int          OriginalRecurringOrderNumber   = CommonLogic.QueryStringUSInt("OriginalRecurringOrderNumber");
            bool         AllowShipToDifferentThanBillTo = AppLogic.AppConfigBool("AllowShipToDifferentThanBillTo") && !AppLogic.AppConfigBool("SkipShippingOnCheckout");

            if (!AllowShipToDifferentThanBillTo)
            {
                //Shipping and Billing address nust be the same so save both
                AddressType = AddressTypes.Billing | AddressTypes.Shipping;
            }

            if (CommonLogic.FormCanBeDangerousContent("AddressFirstName") == "")
            {
                lblErrMsg.Text += "First Name is required";
            }
            if (CommonLogic.FormCanBeDangerousContent("AddressLastName") == "")
            {
                lblErrMsg.Text += "Last Name is required";
            }
            if (CommonLogic.FormCanBeDangerousContent("AddressPhone") == "")
            {
                lblErrMsg.Text += "Phone is required";
            }
            if (CommonLogic.FormCanBeDangerousContent("AddressAddress1") == "")
            {
                lblErrMsg.Text += "Address1 is required";
            }
            if (CommonLogic.FormCanBeDangerousContent("AddressCity") == "")
            {
                lblErrMsg.Text += "City is required";
            }
            if (CommonLogic.FormCanBeDangerousContent("AddressState") == "")
            {
                lblErrMsg.Text += "State is required";
            }
            if (CommonLogic.FormCanBeDangerousContent("AddressZip") == "")
            {
                lblErrMsg.Text += "ZIP is required";
            }
            if (ValidateAddress(CommonLogic.FormCanBeDangerousContent("AddressAddress1")))
            {
                lblErrMsg.Text += AppLogic.GetString("createaccount_process.aspx.3", SkinID, ThisCustomer.LocaleSetting) + "";
            }

            Address thisAddress = new Address();

            thisAddress.CustomerID    = ThisCustomer.CustomerID;
            thisAddress.NickName      = CommonLogic.FormCanBeDangerousContent("AddressNickName");
            thisAddress.FirstName     = CommonLogic.FormCanBeDangerousContent("AddressFirstName");
            thisAddress.LastName      = CommonLogic.FormCanBeDangerousContent("AddressLastName");
            thisAddress.Company       = CommonLogic.FormCanBeDangerousContent("AddressCompany");
            thisAddress.Address1      = CommonLogic.FormCanBeDangerousContent("AddressAddress1");
            thisAddress.Address2      = CommonLogic.FormCanBeDangerousContent("AddressAddress2");
            thisAddress.Suite         = CommonLogic.FormCanBeDangerousContent("AddressSuite");
            thisAddress.City          = CommonLogic.FormCanBeDangerousContent("AddressCity");
            thisAddress.State         = CommonLogic.FormCanBeDangerousContent("AddressState");
            thisAddress.Zip           = CommonLogic.FormCanBeDangerousContent("AddressZip");
            thisAddress.Country       = CommonLogic.FormCanBeDangerousContent("AddressCountry");
            thisAddress.Phone         = CommonLogic.FormCanBeDangerousContent("AddressPhone");
            thisAddress.EMail         = ThisCustomer.EMail;
            thisAddress.ResidenceType = (ResidenceTypes)CommonLogic.FormNativeInt("ResidenceType");

            if (lblErrMsg.Text == "")
            {
                thisAddress.InsertDB();
                int AddressID = thisAddress.AddressID;

                if (ThisCustomer.PrimaryBillingAddressID == 0)
                {
                    DB.ExecuteSQL("Update Customer set BillingAddressID=" + AddressID.ToString() + " where CustomerID=" + ThisCustomer.CustomerID.ToString());
                }
                if (ThisCustomer.PrimaryShippingAddressID == 0)
                {
                    DB.ExecuteSQL("Update Customer set ShippingAddressID=" + AddressID.ToString() + " where CustomerID=" + ThisCustomer.CustomerID.ToString());
                    ThisCustomer.SetPrimaryShippingAddressForShoppingCart(ThisCustomer.PrimaryShippingAddressID, AddressID);
                }

                if (OriginalRecurringOrderNumber != 0)
                {
                    //put it in the ShoppingCart record
                    string sql = String.Empty;
                    if ((AddressType & AddressTypes.Billing) != 0)
                    {
                        sql = String.Format("BillingAddressID={0}", AddressID);
                    }
                    if ((AddressType & AddressTypes.Shipping) != 0)
                    {
                        if (sql.Length != 0)
                        {
                            sql += ",";
                        }
                        sql += String.Format("ShippingAddressID={0}", AddressID);
                    }
                    sql = String.Format("update ShoppingCart set " + sql + " where OriginalRecurringOrderNumber={0}", OriginalRecurringOrderNumber.ToString());
                    DB.ExecuteSQL(sql);
                }

                if (AppLogic.AppConfig("VerifyAddressesProvider") != "")
                {
                    Address StandardizedAddress = new Address();
                    String  VerifyResult        = AddressValidation.RunValidate(thisAddress, out StandardizedAddress);
                    VerifyAddressPrompt = (VerifyResult != AppLogic.ro_OK);
                    if (VerifyAddressPrompt)
                    {
                        thisAddress = StandardizedAddress;
                        thisAddress.UpdateDB();
                        Response.Redirect(String.Format("editaddress.aspx?Checkout={0}&AddressType={1}&ReturnURL={2}&AddressID={3}&Prompt={4}", Checkout.ToString(), AddressTypeString, Server.UrlEncode(ReturnURL), thisAddress.AddressID, VerifyResult));
                    }
                    else
                    {
                        Response.Redirect(String.Format("selectaddress.aspx?Checkout={0}&AddressType={1}&ReturnURL={2}", Checkout.ToString(), AddressTypeString, Server.UrlEncode(ReturnURL)));
                    }
                }
                else
                {
                    Response.Redirect(String.Format("selectaddress.aspx?Checkout={0}&AddressType={1}&ReturnURL={2}", Checkout.ToString(), AddressTypeString, Server.UrlEncode(ReturnURL)));
                }
            }
            else
            {
                // Redisplay the info they gave us so they don't have to re-enter it.
                litNewAddressForm.Text = thisAddress.InputHTML();
            }
        }
Example #3
0
        private void ProcessForm(bool UseValidationService, int AddressID)
        {
            ThisCustomer.RequireCustomerRecord();
            string ResidenceType = ddlResidenceType.SelectedValue;
            bool   valid         = true;
            string errormsg      = string.Empty;

            // Payment method validations
            if (AddressType == AddressTypes.Billing)
            {
                string paymentMethodLastUsed = AppLogic.CleanPaymentMethod(CommonLogic.FormCanBeDangerousContent("PaymentMethod"));
                if (paymentMethodLastUsed == AppLogic.ro_PMECheck && ShowEcheck)
                {
                    if (string.IsNullOrEmpty(CommonLogic.FormCanBeDangerousContent("ECheckBankABACode")))
                    {
                        valid     = false;
                        errormsg += "&bull;Bank ABA Code is required";
                    }
                    if (string.IsNullOrEmpty(CommonLogic.FormCanBeDangerousContent("ECheckBankAccountNumber")))
                    {
                        valid     = false;
                        errormsg += "&bull;Bank Account Number is required";
                    }
                    if (string.IsNullOrEmpty(CommonLogic.FormCanBeDangerousContent("ECheckBankName")))
                    {
                        valid     = false;
                        errormsg += "&bull;Bank Account Name is required";
                    }
                    if (string.IsNullOrEmpty(CommonLogic.FormCanBeDangerousContent("ECheckBankAccountName")))
                    {
                        valid     = false;
                        errormsg += "&bull;Bank Account Name is required";
                    }
                }
                if (paymentMethodLastUsed == AppLogic.ro_PMCreditCard)
                {
                    if (string.IsNullOrEmpty(CommonLogic.FormCanBeDangerousContent("CardName")))
                    {
                        valid     = false;
                        errormsg += "&bull;Card Name is required";
                    }
                    if (string.IsNullOrEmpty(CommonLogic.FormCanBeDangerousContent("CardType")))
                    {
                        valid     = false;
                        errormsg += "&bull;Card Type is required";
                    }
                    if (string.IsNullOrEmpty(CommonLogic.FormCanBeDangerousContent("CardNumber")))
                    {
                        valid     = false;
                        errormsg += "&bull;Card Number is required";
                    }

                    int    iexpMonth = 0;
                    int    iexpYear  = 0;
                    string expMonth  = CommonLogic.FormCanBeDangerousContent("CardExpirationMonth");
                    string expYear   = CommonLogic.FormCanBeDangerousContent("CardExpirationYear");

                    if (string.IsNullOrEmpty(expMonth) ||
                        !int.TryParse(expMonth, out iexpMonth) ||
                        !(iexpMonth > 0))
                    {
                        valid     = false;
                        errormsg += "&bull;Please select the Card Expiration Month";
                    }
                    if (string.IsNullOrEmpty(expYear) ||
                        !int.TryParse(expYear, out iexpYear) ||
                        !(iexpYear > 0))
                    {
                        valid     = false;
                        errormsg += "&bull;Please select the Card Expiration Year";
                    }
                }
            }

            if (!Page.IsValid || !valid)
            {
                ErrorMsgLabel.Text = "" + AppLogic.GetString("editaddress.aspx.15", SkinID, ThisCustomer.LocaleSetting) + "";
                foreach (IValidator aValidator in this.Validators)
                {
                    if (!aValidator.IsValid)
                    {
                        ErrorMsgLabel.Text += "&bull; " + aValidator.ErrorMessage + "";
                    }
                }
                ErrorMsgLabel.Text += "";
                ErrorMsgLabel.Text += errormsg;
                InitializePageContent();
                return;
            }

            theAddress.AddressType = AddressType;
            theAddress.NickName    = txtAddressNickName.Text;
            theAddress.FirstName   = txtFirstName.Text;
            theAddress.LastName    = txtLastName.Text;
            theAddress.Company     = txtCompany.Text;
            theAddress.Address1    = txtAddress1.Text;
            theAddress.Address2    = txtAddress2.Text;
            theAddress.Suite       = txtSuite.Text;
            theAddress.City        = txtCity.Text;
            theAddress.State       = ddlState.SelectedValue;
            theAddress.Zip         = txtZip.Text;
            theAddress.Country     = ddlCountry.SelectedValue;
            theAddress.Phone       = txtPhone.Text;
            if (ResidenceType == "2")
            {
                theAddress.ResidenceType = ResidenceTypes.Commercial;
            }
            else if (ResidenceType == "1")
            {
                theAddress.ResidenceType = ResidenceTypes.Residential;
            }
            else
            {
                theAddress.ResidenceType = ResidenceTypes.Unknown;
            }
            if (theAddress.AddressType == AddressTypes.Billing)
            {
                theAddress.PaymentMethodLastUsed = AppLogic.CleanPaymentMethod(CommonLogic.FormCanBeDangerousContent("PaymentMethod"));
                if (theAddress.PaymentMethodLastUsed == AppLogic.ro_PMECheck && ShowEcheck)
                {
                    string eCheckABACode = CommonLogic.FormCanBeDangerousContent("ECheckBankABACode");
                    if (!eCheckABACode.StartsWith("*"))
                    {
                        theAddress.ECheckBankABACode = CommonLogic.FormCanBeDangerousContent("ECheckBankABACode");
                    }

                    string eCheckBankAccountNumber = CommonLogic.FormCanBeDangerousContent("ECheckBankAccountNumber");
                    if (!eCheckBankAccountNumber.StartsWith("*"))
                    {
                        theAddress.ECheckBankAccountNumber = CommonLogic.FormCanBeDangerousContent("ECheckBankAccountNumber");
                    }

                    theAddress.ECheckBankName        = CommonLogic.FormCanBeDangerousContent("ECheckBankName");
                    theAddress.ECheckBankAccountName = CommonLogic.FormCanBeDangerousContent("ECheckBankAccountName");
                    theAddress.ECheckBankAccountType = CommonLogic.FormCanBeDangerousContent("ECheckBankAccountType");
                }
                if (theAddress.PaymentMethodLastUsed == AppLogic.ro_PMCreditCard)
                {
                    theAddress.CardName = CommonLogic.FormCanBeDangerousContent("CardName");
                    theAddress.CardType = CommonLogic.FormCanBeDangerousContent("CardType");

                    string tmpS = CommonLogic.FormCanBeDangerousContent("CardNumber");
                    if (!tmpS.StartsWith("*"))
                    {
                        theAddress.CardNumber = tmpS;
                    }
                    theAddress.CardExpirationMonth = CommonLogic.FormCanBeDangerousContent("CardExpirationMonth");
                    theAddress.CardExpirationYear  = CommonLogic.FormCanBeDangerousContent("CardExpirationYear");
                }
            }
            theAddress.UpdateDB();

            string RETURNURL = "";

            if (ViewState["RETURNURL"] != null)
            {
                RETURNURL = "&ReturnUrl=" + ViewState["RETURNURL"].ToString();
            }
            if (UseValidationService)
            {
                Address StandardizedAddress = new Address();
                String  validateResult      = AddressValidation.RunValidate(theAddress, out StandardizedAddress);
                theAddress = StandardizedAddress;
                theAddress.UpdateDB();

                if (validateResult != AppLogic.ro_OK)
                {
                    validateResult = "address.validation.errormsg".StringResource() + validateResult;
                    Session["ErrorMsgLabelText"] = System.Web.HttpUtility.HtmlEncode(validateResult);
                    Response.Redirect("editaddress.aspx?Checkout=" + Checkout.ToString() + "&AddressType=" + AddressType.ToString() + "&AddressID=" + AddressID.ToString() + RETURNURL);
                }
            }

            Response.Redirect(String.Format("selectaddress.aspx?Checkout={0}&AddressType={1}" + RETURNURL, Checkout.ToString(), AddressType));
        }
Example #4
0
        protected void btnNewAddress_Click(object sender, EventArgs e)
        {
            AddressControl ctrlNewAddress = pnlContent.FindControl("ctrlNewAddress") as AddressControl;

            if (ctrlNewAddress != null)
            {
                ctrlNewAddress.CountryIDToValidateZipCode = AppLogic.GetCountryID(ctrlNewAddress.Country);
            }

            Page.Validate("AddAddress");

            if (Page.IsValid)
            {
                AddressTypes addressType = AddressMode;
                bool         AllowShipToDifferentThanBillTo = AppLogic.AppConfigBool("AllowShipToDifferentThanBillTo") &&
                                                              !AppLogic.AppConfigBool("SkipShippingOnCheckout");

                if (!AllowShipToDifferentThanBillTo)
                {
                    //Shipping and Billing address must be the same so save both
                    addressType = AddressTypes.Billing | AddressTypes.Shipping;
                }

                AspDotNetStorefrontCore.Address anyAddress = new AspDotNetStorefrontCore.Address();

                if (ctrlNewAddress != null)
                {
                    anyAddress.CustomerID    = ThisCustomer.CustomerID;
                    anyAddress.NickName      = ctrlNewAddress.NickName;
                    anyAddress.FirstName     = ctrlNewAddress.FirstName;
                    anyAddress.LastName      = ctrlNewAddress.LastName;
                    anyAddress.Company       = ctrlNewAddress.Company;
                    anyAddress.Address1      = ctrlNewAddress.Address1;
                    anyAddress.Address2      = ctrlNewAddress.Address2;
                    anyAddress.Suite         = ctrlNewAddress.Suite;
                    anyAddress.City          = ctrlNewAddress.City;
                    anyAddress.State         = ctrlNewAddress.State;
                    anyAddress.Zip           = ctrlNewAddress.ZipCode;
                    anyAddress.Country       = ctrlNewAddress.Country;
                    anyAddress.Phone         = ctrlNewAddress.PhoneNumber;
                    anyAddress.ResidenceType = (ResidenceTypes)addressType;

                    anyAddress.InsertDB();

                    int addressID = anyAddress.AddressID;

                    if (ThisCustomer.PrimaryBillingAddressID == 0)
                    {
                        DB.ExecuteSQL("Update Customer set BillingAddressID=" + addressID + " where CustomerID=" + ThisCustomer.CustomerID.ToString());
                    }
                    if (ThisCustomer.PrimaryShippingAddressID == 0)
                    {
                        DB.ExecuteSQL("Update Customer set ShippingAddressID=" + addressID + " where CustomerID=" + ThisCustomer.CustomerID.ToString());
                        ThisCustomer.SetPrimaryShippingAddressForShoppingCart(ThisCustomer.PrimaryShippingAddressID, addressID);
                    }

                    if (AppLogic.AppConfig("VerifyAddressesProvider") != "")
                    {
                        AspDotNetStorefrontCore.Address standardizedAddress = new AspDotNetStorefrontCore.Address();
                        String VerifyResult        = AddressValidation.RunValidate(anyAddress, out standardizedAddress);
                        bool   verifyAddressPrompt = (VerifyResult != AppLogic.ro_OK);

                        if (verifyAddressPrompt)
                        {
                            anyAddress = standardizedAddress;
                            anyAddress.UpdateDB();
                        }
                    }

                    String sURL = CommonLogic.ServerVariables("URL") + CommonLogic.IIF(CommonLogic.ServerVariables("QUERY_STRING") != "", "?" + CommonLogic.ServerVariables("QUERY_STRING"), "");

                    if (!CommonLogic.IsStringNullOrEmpty(sURL))
                    {
                        Response.Redirect(sURL);
                    }
                }
            }
        }
Example #5
0
        protected void dlAddress_UpdateCommand(object sender, DataListCommandEventArgs e)
        {
            CreditCardPanel ctrlCreditCard = e.Item.FindControl("ctrlCreditCard") as CreditCardPanel;
            Panel           pnlCCData      = e.Item.FindControl("pnlCCData") as Panel;
            Panel           pnlECData      = e.Item.FindControl("pnlECData") as Panel;

            AddressControl ctrlAddress = e.Item.FindControl("ctrlAddress") as AddressControl;

            if (ctrlAddress != null)
            {
                ctrlAddress.CountryIDToValidateZipCode = AppLogic.GetCountryID(ctrlAddress.Country);
            }
            Page.Validate("EditAddress");

            if (AddressMode == AddressTypes.Billing && pnlCCData.Visible)
            {
                if (ctrlCreditCard.CreditCardType == AppLogic.GetString("address.cs.32", SkinID, ThisCustomer.LocaleSetting))
                {
                    pnlCCTypeErrorMsg.Visible = true;
                }
                else
                {
                    pnlCCTypeErrorMsg.Visible = false;
                }
                if (ctrlCreditCard.CardExpMonth == AppLogic.GetString("address.cs.34", SkinID, ThisCustomer.LocaleSetting))
                {
                    pnlCCExpMonthErrorMsg.Visible = true;
                }
                else
                {
                    pnlCCExpMonthErrorMsg.Visible = false;
                }
                if (ctrlCreditCard.CardExpYr == AppLogic.GetString("address.cs.35", 1, ThisCustomer.LocaleSetting))
                {
                    pnlCCExpYrErrorMsg.Visible = true;
                }
                else
                {
                    pnlCCExpYrErrorMsg.Visible = false;
                }

                CardType            Type      = CardType.Parse(ctrlCreditCard.CreditCardType);
                CreditCardValidator validator = new CreditCardValidator(ctrlCreditCard.CreditCardNumber, Type);
                bool isValid = validator.Validate();

                if (!isValid && AppLogic.AppConfigBool("ValidateCreditCardNumbers"))
                {
                    ctrlCreditCard.CreditCardNumber = string.Empty;
                    // clear the card extra code
                    AppLogic.StoreCardExtraCodeInSession(ThisCustomer, string.Empty);
                    pnlCCNumberErrorMsg.Visible = true;
                }
                else
                {
                    pnlCCNumberErrorMsg.Visible = false;
                }
            }

            bool isValidCCDropdown = !(pnlCCTypeErrorMsg.Visible || pnlCCExpMonthErrorMsg.Visible ||
                                       pnlCCExpYrErrorMsg.Visible || pnlCCNumberErrorMsg.Visible);

            if (dlAddress != null && Page.IsValid && isValidCCDropdown)
            {
                AspDotNetStorefrontCore.Address anyAddress = new AspDotNetStorefrontCore.Address();
                Echeck ctrlECheck = e.Item.FindControl("ctrlECheck") as Echeck;

                if (ctrlAddress != null)
                {
                    anyAddress.AddressID     = int.Parse((e.Item.FindControl("hfAddressID") as HiddenField).Value);
                    anyAddress.CustomerID    = ThisCustomer.CustomerID;
                    anyAddress.NickName      = ctrlAddress.NickName;
                    anyAddress.FirstName     = ctrlAddress.FirstName;
                    anyAddress.LastName      = ctrlAddress.LastName;
                    anyAddress.Phone         = ctrlAddress.PhoneNumber;
                    anyAddress.Company       = ctrlAddress.Company;
                    anyAddress.AddressType   = AddressMode;
                    anyAddress.ResidenceType = (ResidenceTypes)Enum.Parse(typeof(ResidenceTypes), ctrlAddress.ResidenceType, true);
                    anyAddress.Address1      = ctrlAddress.Address1;
                    anyAddress.Address2      = ctrlAddress.Address2;
                    anyAddress.City          = ctrlAddress.City;
                    anyAddress.Suite         = ctrlAddress.Suite;
                    anyAddress.Zip           = ctrlAddress.ZipCode;
                    anyAddress.Country       = ctrlAddress.Country;
                    anyAddress.State         = ctrlAddress.State;

                    if (CustomerCCRequired && AddressMode == AddressTypes.Billing)
                    {
                        Address BillingAddress = new Address();
                        BillingAddress.LoadByCustomer(ThisCustomer.CustomerID, ThisCustomer.PrimaryBillingAddressID, AddressTypes.Billing);

                        if (ctrlCreditCard != null)
                        {
                            anyAddress.CardName = ctrlCreditCard.CreditCardName;

                            if (!ctrlCreditCard.CreditCardNumber.StartsWith("*"))
                            {
                                anyAddress.CardNumber = ctrlCreditCard.CreditCardNumber;
                            }
                            else
                            {
                                anyAddress.CardNumber = BillingAddress.CardNumber;
                            }

                            anyAddress.CardType            = ctrlCreditCard.CreditCardType;
                            anyAddress.CardExpirationMonth = ctrlCreditCard.CardExpMonth;
                            anyAddress.CardExpirationYear  = ctrlCreditCard.CardExpYr;

                            if (AppLogic.AppConfigBool("ShowCardStartDateFields"))
                            {
                                string cardStartDate = "";
                                if (ctrlCreditCard.CardExpMonth != AppLogic.GetString("address.cs.34", SkinID, ThisCustomer.LocaleSetting))
                                {
                                    cardStartDate = ctrlCreditCard.CardStartMonth;
                                }
                                if (ctrlCreditCard.CardExpYr != AppLogic.GetString("address.cs.35", SkinID, ThisCustomer.LocaleSetting))
                                {
                                    cardStartDate += ctrlCreditCard.CardStartYear;
                                }
                                anyAddress.CardStartDate = cardStartDate;
                            }
                            if (AppLogic.AppConfigBool("CardExtraCodeIsOptional"))
                            {
                                anyAddress.CardIssueNumber = ctrlCreditCard.CreditCardIssueNumber;
                            }
                        }

                        if (ShowEcheck && ctrlECheck != null)
                        {
                            anyAddress.ECheckBankAccountName = ctrlECheck.ECheckBankAccountName;
                            anyAddress.ECheckBankName        = ctrlECheck.ECheckBankName;

                            if (!ctrlECheck.ECheckBankABACode.StartsWith("*"))
                            {
                                anyAddress.ECheckBankABACode = ctrlECheck.ECheckBankABACode;
                            }
                            else
                            {
                                anyAddress.ECheckBankABACode = BillingAddress.ECheckBankABACode;
                            }

                            if (!ctrlECheck.ECheckBankAccountNumber.StartsWith("*"))
                            {
                                anyAddress.ECheckBankAccountNumber = ctrlECheck.ECheckBankAccountNumber;
                            }
                            else
                            {
                                anyAddress.ECheckBankAccountNumber = BillingAddress.ECheckBankAccountNumber;
                            }

                            anyAddress.ECheckBankAccountType = ctrlECheck.ECheckBankAccountType;
                        }

                        if (pnlCCData.Visible)
                        {
                            anyAddress.PaymentMethodLastUsed = AppLogic.ro_PMCreditCard;
                        }
                        else if (pnlECData.Visible)
                        {
                            anyAddress.PaymentMethodLastUsed = AppLogic.ro_PMECheck;
                        }
                        else
                        {
                            anyAddress.PaymentMethodLastUsed = BillingAddress.PaymentMethodLastUsed;
                        }
                    }

                    anyAddress.UpdateDB();

                    if (AppLogic.AppConfig("VerifyAddressesProvider") != "")
                    {
                        AspDotNetStorefrontCore.Address standardizedAddress = new AspDotNetStorefrontCore.Address();
                        string validateResult = AddressValidation.RunValidate(anyAddress, out standardizedAddress);
                        anyAddress = standardizedAddress;
                        anyAddress.UpdateDB();

                        if (validateResult != AppLogic.ro_OK)
                        {
                        }
                    }

                    dlAddress.EditItemIndex = -1;
                    LoadData();
                }
            }
        }
Example #6
0
        private void CreateAccount()
        {
            ThisCustomer.RequireCustomerRecord();
            GatewayCheckoutByAmazon.CheckoutByAmazon checkoutByAmazon = new GatewayCheckoutByAmazon.CheckoutByAmazon();

            if (checkoutByAmazon.IsEnabled && checkoutByAmazon.IsCheckingOut && checkoutByAmazon.GetDefaultShippingAddress() == null)
            {
                lblErrorMessage.Text = "gw.checkoutbyamazon.display.3".StringResource();
                pnlErrorMsg.Visible  = true;
                return;
            }

            if (checkoutByAmazon.IsEnabled && checkoutByAmazon.IsCheckingOut && ThisCustomer.IsRegistered)
            {
                checkoutByAmazon.BeginCheckout(new Guid(ThisCustomer.CustomerGUID), false, false);
                Response.Redirect("checkoutshipping.aspx");
            }
            else if (checkoutByAmazon.IsEnabled && checkoutByAmazon.IsCheckingOut)
            {
                checkoutByAmazon.BeginCheckout(new Guid(ThisCustomer.CustomerGUID), false, false);
            }

            SetPasswordFields();

            string AccountName = (ctrlAccount.FirstName.Trim() + " " + ctrlAccount.LastName.Trim()).Trim();

            if (SkipRegistration)
            {
                AccountName = String.Format("{0} {1}", ctrlBillingAddress.FirstName.Trim(), ctrlBillingAddress.LastName.Trim()).Trim();

                if (checkoutByAmazon.IsEnabled && checkoutByAmazon.IsCheckingOut)
                {
                    AccountName = "Anonymous Amazon Customer";
                }
            }

            if (SkipRegistration)
            {
                Page.Validate("skipreg");
            }
            else
            {
                if (ctrlAccount.Password.Contains('\xFF') || ctrlAccount.Password.Length == 0)
                {
                    ctrlAccount.PasswordValidate = ViewState["custpwd"].ToString();
                }
                else
                {
                    ctrlAccount.PasswordValidate = ctrlAccount.Password;
                }

                if (ctrlAccount.PasswordConfirm.Contains('\xFF') || ctrlAccount.PasswordConfirm.Length == 0)
                {
                    ctrlAccount.PasswordConfirmValidate = ViewState["custpwd2"].ToString();
                }
                else
                {
                    ctrlAccount.PasswordConfirmValidate = ctrlAccount.PasswordConfirm;
                }

                ctrlAccount.Over13 = ctrlAccount.Over13;
                if ((!ThisCustomer.IsRegistered) && !checkoutByAmazon.IsCheckingOut && (ctrlAccount.Password.Length == 0 || ctrlAccount.PasswordConfirm.Length == 0))
                {
                    lblErrorMessage.Text = "createaccount.aspx.6".StringResource();
                    ResetScrollPosition();
                    pnlErrorMsg.Visible = true;
                    return;
                }

                ctrlBillingAddress.CountryIDToValidateZipCode  = AppLogic.GetCountryID(ctrlBillingAddress.Country);
                ctrlShippingAddress.CountryIDToValidateZipCode = AppLogic.GetCountryID(ctrlShippingAddress.Country);

                Page.Validate("registration");

                if (RequireSecurityCode)
                {
                    if (Session["SecurityCode"] != null)
                    {
                        String  sCode     = Session["SecurityCode"].ToString();
                        String  fCode     = ctrlAccount.txtSecurityCode.Text;
                        Boolean codeMatch = false;

                        if (AppLogic.AppConfigBool("Captcha.CaseSensitive"))
                        {
                            if (fCode.Equals(sCode))
                            {
                                codeMatch = true;
                            }
                        }
                        else
                        {
                            if (fCode.Equals(sCode, StringComparison.InvariantCultureIgnoreCase))
                            {
                                codeMatch = true;
                            }
                        }

                        if (!codeMatch)
                        {
                            lblErrorMessage.Text                         = string.Format(AppLogic.GetString("lat_signin_process.aspx.5", SkinID, ThisCustomer.LocaleSetting), sCode, fCode);
                            ctrlAccount.txtSecurityCode.Text             = String.Empty;
                            ctrlAccount.imgAccountSecurityImage.ImageUrl = "~/Captcha.ashx?id=1";
                            ResetScrollPosition();
                            pnlErrorMsg.Visible = true;
                            return;
                        }
                    }
                    else
                    {
                        lblErrorMessage.Text                         = string.Format(AppLogic.GetString("lat_signin_process.aspx.5", SkinID, ThisCustomer.LocaleSetting), "", ctrlAccount.txtSecurityCode.Text);
                        ctrlAccount.txtSecurityCode.Text             = String.Empty;
                        ctrlAccount.imgAccountSecurityImage.ImageUrl = "~/Captcha.ashx?id=1";
                        ResetScrollPosition();
                        pnlErrorMsg.Visible = true;
                        return;
                    }
                }

                if (!Page.IsValid && RequireSecurityCode)
                {
                    Session["SecurityCode"] = CommonLogic.GenerateRandomCode(6);
                }
            }



            Page.Validate("createacccount");


            if (Page.IsValid && AccountName.Length > 0)
            {
                String EMailField = CommonLogic.IIF(SkipRegistration, txtSkipRegEmail.Text.ToLowerInvariant().Trim(), ctrlAccount.Email.ToLowerInvariant().Trim());

                bool NewEmailAllowed = Customer.NewEmailPassesDuplicationRules(EMailField, ThisCustomer.CustomerID, SkipRegistration);

                String   PWD    = ViewState["custpwd"].ToString();
                Password p      = new Password(PWD);
                String   newpwd = p.SaltedPassword;
                System.Nullable <int> newsaltkey = p.Salt;

                Password blankpwd = new Password("", ThisCustomer.SaltKey);
                if (!(ThisCustomer.Password == "" || ThisCustomer.Password == blankpwd.SaltedPassword))
                {
                    // do NOT allow passwords to be changed on this page. this is only for creating an account.
                    // if they want to change their password, they must use their account page
                    newpwd     = null;
                    newsaltkey = null;
                }
                if (NewEmailAllowed)
                {
                    AppLogic.eventHandler("CreateAccount").CallEvent("&CreateAccount=true");

                    string strDOB = null;
                    if (AppLogic.AppConfigBool("Account.ShowBirthDateField"))
                    {
                        strDOB = ctrlAccount.DOBMonth + "/" + ctrlAccount.DOBDay + "/" + ctrlAccount.DOBYear;
                        //DOB defaults to 0/0/0 when doing anonymous checkout and blows up dbo.aspdnsf_updCustomer, preventing checkout
                        strDOB = (strDOB.Equals("0/0/0", StringComparison.Ordinal)) ? null : strDOB;
                    }

                    var defaultCustomerLevel_Public = (int)UserType.PUBLIC;

                    ThisCustomer.UpdateCustomer(
                        /*CustomerLevelID*/ defaultCustomerLevel_Public,
                        /*EMail*/ EMailField,
                        /*SaltedAndHashedPassword*/ newpwd,
                        /*SaltKey*/ newsaltkey,
                        /*DateOfBirth*/ strDOB,
                        /*Gender*/ null,
                        /*FirstName*/ ctrlAccount.FirstName,
                        /*LastName*/ ctrlAccount.LastName,
                        /*Notes*/ null,
                        /*SkinID*/ null,
                        /*Phone*/ ctrlAccount.Phone,
                        /*AffiliateID*/ null,
                        /*Referrer*/ null,
                        /*CouponCode*/ null,
                        /*OkToEmail*/ CommonLogic.IIF(ctrlAccount.OKToEmailYes, 1, 0),
                        /*IsAdmin*/ null,
                        /*BillingEqualsShipping*/ CommonLogic.IIF(AppLogic.AppConfigBool("AllowShipToDifferentThanBillTo"), 0, 1),
                        /*LastIPAddress*/ null,
                        /*OrderNotes*/ null,
                        /*SubscriptionExpiresOn*/ null,
                        /*RTShipRequest*/ null,
                        /*RTShipResponse*/ null,
                        /*OrderOptions*/ null,
                        /*LocaleSetting*/ null,
                        /*MicroPayBalance*/ null,
                        /*RecurringShippingMethodID*/ null,
                        /*RecurringShippingMethod*/ null,
                        /*BillingAddressID*/ null,
                        /*ShippingAddressID*/ null,
                        /*GiftRegistryGUID*/ null,
                        /*GiftRegistryIsAnonymous*/ null,
                        /*GiftRegistryAllowSearchByOthers*/ null,
                        /*GiftRegistryNickName*/ null,
                        /*GiftRegistryHideShippingAddresses*/ null,
                        /*CODCompanyCheckAllowed*/ null,
                        /*CODNet30Allowed*/ null,
                        /*ExtensionData*/ null,
                        /*FinalizationData*/ null,
                        /*Deleted*/ null,
                        /*Over13Checked*/ 1, //CommonLogic.IIF(ctrlAccount.Over13 || SkipRegOver13.Checked, 1, 0),
                        /*CurrencySetting*/ null,
                        /*VATSetting*/ null,
                        /*VATRegistrationID*/ null,
                        /*StoreCCInDB*/ CommonLogic.IIF(ctrlAccount.ShowSaveCC, ctrlAccount.SaveCC, true),
                        /*IsRegistered*/ CommonLogic.IIF(SkipRegistration, 0, 1),
                        /*LockedUntil*/ null,
                        /*AdminCanViewCC*/ null,
                        /*BadLogin*/ null,
                        /*Active*/ null,
                        /*PwdChangeRequired*/ null,
                        /*RegisterDate*/ null,
                        /*StoreId*/ AppLogic.StoreID()
                        );
                    if (ctrlAccount.OKToEmailYes)
                    {
                        AddToNewsletterList(ctrlAccount.FirstName, ctrlAccount.LastName, EMailField);
                    }
                    BillingAddress = ThisCustomer.PrimaryBillingAddress;
                    if (BillingAddress.AddressID == 0 && !checkoutByAmazon.IsCheckingOut)
                    {
                        if (pnlBillingInfo.Visible)
                        {
                            BillingAddress.NickName      = ctrlBillingAddress.NickName;
                            BillingAddress.LastName      = ctrlBillingAddress.LastName;
                            BillingAddress.FirstName     = ctrlBillingAddress.FirstName;
                            BillingAddress.Phone         = ctrlBillingAddress.PhoneNumber;
                            BillingAddress.Company       = ctrlBillingAddress.Company;
                            BillingAddress.ResidenceType = (ResidenceTypes)Enum.Parse(typeof(ResidenceTypes), ctrlBillingAddress.ResidenceType);
                            BillingAddress.Address1      = ctrlBillingAddress.Address1;
                            BillingAddress.Address2      = ctrlBillingAddress.Address2;
                            BillingAddress.Suite         = ctrlBillingAddress.Suite;
                            BillingAddress.City          = ctrlBillingAddress.City;
                            BillingAddress.State         = ctrlBillingAddress.State;
                            BillingAddress.Zip           = ctrlBillingAddress.ZipCode;
                            BillingAddress.Country       = ctrlBillingAddress.Country;

                            BillingAddress.InsertDB(ThisCustomer.CustomerID);
                            BillingAddress.MakeCustomersPrimaryAddress(AddressTypes.Billing);
                        }
                    }
                    else
                    {
                        BillingAddress.NickName  = String.Format("{0} {1}", ctrlAccount.FirstName, ctrlAccount.LastName);
                        BillingAddress.LastName  = ctrlAccount.FirstName;
                        BillingAddress.FirstName = ctrlAccount.LastName;
                        BillingAddress.Phone     = ctrlAccount.Phone;
                    }

                    ShippingAddress = ThisCustomer.PrimaryShippingAddress;
                    if (ShippingAddress.AddressID == 0 && !checkoutByAmazon.IsCheckingOut)
                    {
                        if (AllowShipToDifferentThanBillTo)
                        {
                            if (ctrlShippingAddress.Visible)
                            {
                                ShippingAddress.NickName      = ctrlBillingAddress.NickName;
                                ShippingAddress.LastName      = ctrlShippingAddress.LastName;
                                ShippingAddress.FirstName     = ctrlShippingAddress.FirstName;
                                ShippingAddress.Phone         = ctrlShippingAddress.PhoneNumber;
                                ShippingAddress.Company       = ctrlShippingAddress.Company;
                                ShippingAddress.ResidenceType = (ResidenceTypes)Enum.Parse(typeof(ResidenceTypes), ctrlShippingAddress.ResidenceType);
                                ShippingAddress.Address1      = ctrlShippingAddress.Address1;
                                ShippingAddress.Address2      = ctrlShippingAddress.Address2;
                                ShippingAddress.Suite         = ctrlShippingAddress.Suite;
                                ShippingAddress.City          = ctrlShippingAddress.City;
                                ShippingAddress.State         = ctrlShippingAddress.State;
                                ShippingAddress.Zip           = ctrlShippingAddress.ZipCode;
                                ShippingAddress.Country       = ctrlShippingAddress.Country;

                                ShippingAddress.InsertDB(ThisCustomer.CustomerID);
                                if (!String.IsNullOrEmpty(VerifyAddressesProvider))
                                {
                                    VerifyResult        = AddressValidation.RunValidate(ShippingAddress, out StandardizedAddress);
                                    VerifyAddressPrompt = (VerifyResult != AppLogic.ro_OK);
                                    if (VerifyAddressPrompt)
                                    {
                                        ShippingAddress = StandardizedAddress;
                                        ShippingAddress.UpdateDB();
                                    }
                                }
                                ShippingAddress.MakeCustomersPrimaryAddress(AddressTypes.Shipping);
                            }
                        }
                        else
                        {
                            if (!String.IsNullOrEmpty(VerifyAddressesProvider))
                            {
                                VerifyResult        = AddressValidation.RunValidate(BillingAddress, out StandardizedAddress);
                                VerifyAddressPrompt = (VerifyResult != AppLogic.ro_OK);
                                if (VerifyAddressPrompt)
                                {
                                    BillingAddress = StandardizedAddress;
                                    BillingAddress.UpdateDB();
                                }
                            }
                            BillingAddress.MakeCustomersPrimaryAddress(AddressTypes.Shipping);
                        }
                    }
                    else
                    {
                        ShippingAddress.NickName  = String.Format("{0} {1}", ctrlAccount.FirstName, ctrlAccount.LastName);
                        ShippingAddress.LastName  = ctrlAccount.FirstName;
                        ShippingAddress.FirstName = ctrlAccount.LastName;
                        ShippingAddress.Phone     = ctrlAccount.Phone;
                    }

                    if (AppLogic.AppConfigBool("Vat.Enabled") && ctrlAccount.VATRegistrationID.Length > 0)
                    {
                        String vtr = ctrlAccount.VATRegistrationID.Trim();

                        Exception vatServiceException = null;
                        if (AppLogic.VATRegistrationIDIsValid(ctrlBillingAddress.Country, vtr, out vatServiceException))
                        {
                            ThisCustomer.SetVATRegistrationID(vtr);
                        }
                        else
                        {
                            vtr = String.Empty;

                            if (vatServiceException != null && !String.IsNullOrEmpty(vatServiceException.Message))
                            {
                                if (vatServiceException.Message.Length > 255)
                                {
                                    lblErrorMessage.Text = Server.HtmlEncode(vatServiceException.Message.Substring(0, 255));
                                }
                                else
                                {
                                    lblErrorMessage.Text = Server.HtmlEncode(vatServiceException.Message);
                                }
                            }
                            else
                            {
                                lblErrorMessage.Text = "account.aspx.91".StringResource();
                            }
                            pnlErrorMsg.Visible = true;
                            return;
                        }
                    }
                    if (AppLogic.AppConfigBool("DynamicRelatedProducts.Enabled") ||
                        AppLogic.AppConfigBool("RecentlyViewedProducts.Enabled"))
                    {
                        ThisCustomer.ReplaceProductViewFromAnonymous();
                    }
                }
                if (Checkout)
                {
                    if (!NewEmailAllowed)
                    {
                        lblErrorMessage.Text = AppLogic.GetString("createaccount_process.aspx.1", 1, Localization.GetDefaultLocale());
                        InitializePageContent();
                    }
                    else
                    {
                        if (AppLogic.AppConfigBool("SendWelcomeEmail") && EMailField.IndexOf("@") != -1 && ThisCustomer.IsRegistered == true)
                        {
                            // don't let a simple welcome stop checkout!
                            try
                            {
                                string body = AppLogic.RunXmlPackage(AppLogic.AppConfig("XmlPackage.WelcomeEmail"),
                                                                     null,
                                                                     ThisCustomer,
                                                                     this.SkinID,
                                                                     "",
                                                                     "fullname=" + ctrlAccount.FirstName.Trim() + " " + ctrlAccount.LastName.Trim(),
                                                                     false,
                                                                     false,
                                                                     this.EntityHelpers);

                                AppLogic.SendMail(AppLogic.GetString("createaccount.aspx.79", ThisCustomer.SkinID, ThisCustomer.LocaleSetting),
                                                  body,
                                                  true,
                                                  AppLogic.AppConfig("MailMe_FromAddress"),
                                                  AppLogic.AppConfig("MailMe_FromName"),
                                                  EMailField,
                                                  ctrlAccount.FirstName.Trim() + " " + ctrlAccount.LastName.Trim(),
                                                  "",
                                                  AppLogic.MailServer());
                            }
                            catch { }
                        }
                        if (VerifyAddressPrompt)
                        {
                            if (AllowShipToDifferentThanBillTo)
                            {
                                Response.Redirect("address.aspx?Checkout=True&AddressType=Shipping&AddressID=" + Customer.GetCustomerPrimaryShippingAddressID(ThisCustomer.CustomerID).ToString() + "&NewAccount=true&prompt=" + VerifyResult + "&skipreg=" + SkipRegistration + "&returnURL=checkoutshipping.aspx?checkout=true");
                            }
                            else
                            {
                                Response.Redirect("address.aspx?Checkout=True&AddressType=Billing&AddressID=" + Customer.GetCustomerPrimaryShippingAddressID(ThisCustomer.CustomerID).ToString() + "&NewAccount=true&prompt=" + VerifyResult + "&skipreg=" + SkipRegistration + "&returnURL=checkoutshipping.aspx?checkout=true");
                            }
                        }
                        else
                        {
                            if (checkouttype == "ppec" || checkouttype == "ppbml" || checkouttype == "gc")
                            {
                                Response.Redirect("shoppingcart.aspx");
                            }
                            else
                            {
                                Response.Redirect("account.aspx?checkout=true");//checkoutshipping
                            }
                        }
                    }
                }
                else
                {
                    if (!NewEmailAllowed)
                    {
                        DB.ExecuteSQL("update customer set EMail='', IsRegistered = 0 where CustomerID=" + ThisCustomer.CustomerID);
                        lblErrorMessage.Text = AppLogic.GetString("createaccount_process.aspx.1", 1, Localization.GetDefaultLocale());
                        InitializePageContent();
                    }
                    else
                    {
                        if (AppLogic.AppConfigBool("SendWelcomeEmail") && EMailField.IndexOf("@") != -1 && ThisCustomer.IsRegistered == true)
                        {
                            // don't let a simple welcome stop checkout!
                            try
                            {
                                string body = AppLogic.RunXmlPackage(AppLogic.AppConfig("XmlPackage.WelcomeEmail"),
                                                                     null,
                                                                     ThisCustomer,
                                                                     this.SkinID,
                                                                     "",
                                                                     "",
                                                                     false,
                                                                     false,
                                                                     this.EntityHelpers);

                                AppLogic.SendMail(AppLogic.GetString("createaccount.aspx.79", ThisCustomer.SkinID, ThisCustomer.LocaleSetting),
                                                  body,
                                                  true,
                                                  AppLogic.AppConfig("MailMe_FromAddress"),
                                                  AppLogic.AppConfig("MailMe_FromName"),
                                                  EMailField,
                                                  ctrlAccount.FirstName.Trim() + " " + ctrlAccount.LastName.Trim(), "",
                                                  AppLogic.MailServer());
                            }
                            catch { }
                        }
                        if (VerifyAddressPrompt)
                        {
                            if (AllowShipToDifferentThanBillTo)
                            {
                                Response.Redirect("address.aspx?Checkout=False&AddressType=Shipping&AddressID=" + Customer.GetCustomerPrimaryShippingAddressID(ThisCustomer.CustomerID).ToString() + "&NewAccount=true&prompt=" + VerifyResult + "&skipreg=" + SkipRegistration);
                            }
                            else
                            {
                                Response.Redirect("address.aspx?Checkout=False&AddressType=Billing&AddressID=" + Customer.GetCustomerPrimaryShippingAddressID(ThisCustomer.CustomerID).ToString() + "&NewAccount=true&prompt=" + VerifyResult + "&skipreg=" + SkipRegistration);
                            }
                        }
                        else
                        {
                            Response.Redirect("JWMyAccount.aspx");
                        }
                    }
                }
            }
            else
            {
                foreach (IValidator aValidator in this.Validators)
                {
                    if (!aValidator.IsValid)
                    {
                        lblErrorMessage.Text = aValidator.ErrorMessage;
                        break;
                    }
                }
                ResetScrollPosition();
            }

            pnlErrorMsg.Visible = lblErrorMessage.Text.Length > 0;
        }
Example #7
0
        protected void btnNewAddress_Click(object sender, EventArgs e)
        {
            AddressControl ctrlNewAddress = pnlContent.FindControl("ctrlNewAddress") as AddressControl;

            if (ctrlNewAddress != null)
            {
                ctrlNewAddress.CountryIDToValidateZipCode = AppLogic.GetCountryID(ctrlNewAddress.Country);
            }

            Page.Validate("AddAddress");

            if (Page.IsValid)
            {
                AspDotNetStorefrontCore.Address anyAddress = new AspDotNetStorefrontCore.Address();

                if (ctrlNewAddress != null)
                {
                    anyAddress.CustomerID = ThisCustomer.CustomerID;
                    anyAddress.NickName   = ctrlNewAddress.NickName;
                    anyAddress.FirstName  = ctrlNewAddress.FirstName;
                    anyAddress.LastName   = ctrlNewAddress.LastName;
                    anyAddress.Company    = ctrlNewAddress.Company;
                    anyAddress.Address1   = ctrlNewAddress.Address1;
                    anyAddress.Address2   = ctrlNewAddress.Address2;
                    anyAddress.Suite      = ctrlNewAddress.Suite;
                    anyAddress.City       = ctrlNewAddress.City;
                    anyAddress.State      = ctrlNewAddress.State;
                    anyAddress.Zip        = ctrlNewAddress.ZipCode;
                    anyAddress.Country    = ctrlNewAddress.Country;
                    anyAddress.Phone      = ctrlNewAddress.PhoneNumber;
                    //anyAddress.ResidenceType = (ResidenceTypes)addressType;
                    anyAddress.ResidenceType = (ResidenceTypes)Enum.Parse(typeof(ResidenceTypes), ctrlNewAddress.ResidenceType, true);

                    anyAddress.InsertDB();

                    int addressID = anyAddress.AddressID;

                    if (ThisCustomer.PrimaryBillingAddressID == 0)
                    {
                        DB.ExecuteSQL("Update Customer set BillingAddressID=" + addressID + " where CustomerID=" + ThisCustomer.CustomerID.ToString());
                    }
                    if (ThisCustomer.PrimaryShippingAddressID == 0)
                    {
                        DB.ExecuteSQL("Update Customer set ShippingAddressID=" + addressID + " where CustomerID=" + ThisCustomer.CustomerID.ToString());
                        ThisCustomer.SetPrimaryShippingAddressForShoppingCart(ThisCustomer.PrimaryShippingAddressID, addressID);
                    }
                    if (AppLogic.AppConfig("VerifyAddressesProvider") != "")
                    {
                        AspDotNetStorefrontCore.Address standardizedAddress = new AspDotNetStorefrontCore.Address();
                        String validateResult = AddressValidation.RunValidate(anyAddress, out standardizedAddress);
                        validateResult = "address.validation.errormsg".StringResource() + validateResult;

                        if (validateResult != AppLogic.ro_OK)
                        {
                            Session["ErrorMsgLabelText"] = System.Web.HttpUtility.HtmlEncode(validateResult);
                        }
                        else
                        {
                            anyAddress = standardizedAddress;
                            anyAddress.UpdateDB();
                        }
                    }

                    String sURL = CommonLogic.ServerVariables("URL") + CommonLogic.IIF(CommonLogic.ServerVariables("QUERY_STRING").Length > 0, "?" + CommonLogic.ServerVariables("QUERY_STRING"), "");
                    if (!CommonLogic.IsStringNullOrEmpty(sURL))
                    {
                        Response.Redirect(sURL);
                    }
                }
            }
        }
        protected void btnNewAddress_Click(object sender, EventArgs e)
        {
            AddressControl ctrlNewAddress = pnlContent.FindControl("ctrlNewAddress") as AddressControl;

            if (ctrlNewAddress != null)
            {
                ctrlNewAddress.CountryIDToValidateZipCode = AppLogic.GetCountryID(ctrlNewAddress.Country);
            }
            //LovelyEcom Add
            string  VerifyResult0       = string.Empty;
            Address StandardizedAddress = null;

            lbAddressError.Text = "";
            if (AppLogic.AppConfig("VerifyAddressesProvider") != "")
            {
                Address Verifyaddress = new Address();
                Verifyaddress.Address1 = ctrlNewAddress.Address1;
                Verifyaddress.Address2 = ctrlNewAddress.Address2;
                Verifyaddress.City     = ctrlNewAddress.City;
                Verifyaddress.State    = ctrlNewAddress.State;
                Verifyaddress.Zip      = ctrlNewAddress.ZipCode;

                VerifyResult0 = AddressValidation.RunValidate(Verifyaddress, out StandardizedAddress);

                if (VerifyResult0 != AppLogic.ro_OK)
                {
                    lbAddressError.Text += VerifyResult0; //lovely Ecom Added
                    return;
                }
            }
            //LovelyEcom end
            Page.Validate("AddAddress");

            if (Page.IsValid)
            {
                AspDotNetStorefrontCore.Address anyAddress = new AspDotNetStorefrontCore.Address();

                if (ctrlNewAddress != null)
                {
                    anyAddress.CustomerID = ThisCustomer.CustomerID;
                    anyAddress.NickName   = ctrlNewAddress.NickName;
                    anyAddress.FirstName  = ctrlNewAddress.FirstName;
                    anyAddress.LastName   = ctrlNewAddress.LastName;
                    anyAddress.Company    = ctrlNewAddress.Company;
                    anyAddress.Address1   = ctrlNewAddress.Address1;
                    anyAddress.Address2   = ctrlNewAddress.Address2;
                    anyAddress.Suite      = ctrlNewAddress.Suite;
                    anyAddress.City       = ctrlNewAddress.City;
                    anyAddress.State      = ctrlNewAddress.State;
                    anyAddress.Zip        = ctrlNewAddress.ZipCode;
                    anyAddress.Country    = ctrlNewAddress.Country;
                    anyAddress.Phone      = ctrlNewAddress.PhoneNumber;
                    //anyAddress.ResidenceType = (ResidenceTypes)addressType;
                    anyAddress.ResidenceType = (ResidenceTypes)Enum.Parse(typeof(ResidenceTypes), ctrlNewAddress.ResidenceType, true);

                    anyAddress.InsertDB();

                    int addressID = anyAddress.AddressID;

                    if (ThisCustomer.PrimaryBillingAddressID == 0)
                    {
                        DB.ExecuteSQL("Update Customer set BillingAddressID=" + addressID + " where CustomerID=" + ThisCustomer.CustomerID.ToString());
                    }
                    if (ThisCustomer.PrimaryShippingAddressID == 0)
                    {
                        DB.ExecuteSQL("Update Customer set ShippingAddressID=" + addressID + " where CustomerID=" + ThisCustomer.CustomerID.ToString());
                        ThisCustomer.SetPrimaryShippingAddressForShoppingCart(ThisCustomer.PrimaryShippingAddressID, addressID);
                    }

                    if (AppLogic.AppConfig("VerifyAddressesProvider") != "")
                    {
                        AspDotNetStorefrontCore.Address standardizedAddress = new AspDotNetStorefrontCore.Address();
                        String VerifyResult        = AddressValidation.RunValidate(anyAddress, out standardizedAddress);
                        bool   verifyAddressPrompt = (VerifyResult != AppLogic.ro_OK);

                        if (verifyAddressPrompt)
                        {
                            anyAddress = standardizedAddress;
                            anyAddress.UpdateDB();
                        }
                    }

                    String sURL = CommonLogic.ServerVariables("URL") + CommonLogic.IIF(CommonLogic.ServerVariables("QUERY_STRING") != "", "?" + CommonLogic.ServerVariables("QUERY_STRING"), "");

                    if (!CommonLogic.IsStringNullOrEmpty(sURL))
                    {
                        Response.Redirect(sURL);
                    }
                }
            }
        }