Пример #1
0
        protected void dlAddress_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.EditItem)
            {
                AddressControl  ctrlAddress    = e.Item.FindControl("ctrlAddress") as AddressControl;
                CreditCardPanel ctrlCreditCard = e.Item.FindControl("ctrlCreditCard") as CreditCardPanel;
                Echeck          ctrlECheck     = e.Item.FindControl("ctrlECheck") as Echeck;
                int             addyID         = Convert.ToInt32(DataBinder.Eval(e.Item.DataItem, "AddressID"));
                PopulateAddressControlValues(ctrlAddress, ctrlCreditCard, ctrlECheck, e.Item.ItemIndex, addyID);

                if (CustomerCCRequired)
                {
                    TableRow trCCInformation = e.Item.FindControl("trCCInformation") as TableRow;
                    if (trCCInformation != null)
                    {
                        if (AddressMode == AddressTypes.Billing)
                        {
                            RadioButtonList rblPaymentMethodInfo = e.Item.FindControl("rblPaymentMethodInfo") as RadioButtonList;
                            Panel           pnlCCData            = e.Item.FindControl("pnlCCData") as Panel;
                            Panel           pnlECData            = e.Item.FindControl("pnlECData") as Panel;

                            if (rblPaymentMethodInfo.SelectedValue.Equals(AppLogic.ro_PMCreditCard,
                                                                          StringComparison.InvariantCultureIgnoreCase))
                            {
                                trCCInformation.Visible = true;
                                rblPaymentMethodInfo.Items[0].Enabled = true;
                                pnlCCData.Visible = true;
                            }
                            if (!ShowEcheck)
                            {
                                rblPaymentMethodInfo.Items.Remove(rblPaymentMethodInfo.Items[1]);
                            }

                            //Image for eCheck
                            if (ShowEcheck && ctrlECheck != null)
                            {
                                ctrlECheck = e.Item.FindControl("ctrlECheck") as Echeck;
                                ctrlECheck.ECheckBankABAImage1    = AppLogic.LocateImageURL(String.Format("~/App_Themes/skin_{0}/images/check_aba.gif", SkinID.ToString()));
                                ctrlECheck.ECheckBankABAImage2    = AppLogic.LocateImageURL(String.Format("~/App_Themes/skin_{0}/images/check_aba.gif", SkinID.ToString()));
                                ctrlECheck.ECheckBankAccountImage = AppLogic.LocateImageURL(String.Format("~/App_Themes/skin_{0}/images/check_account.gif", SkinID.ToString()));
                                ctrlECheck.ECheckNoteLabel        = string.Format(AppLogic.GetString("address.cs.48", SkinID, ThisCustomer.LocaleSetting), AppLogic.LocateImageURL("App_Themes/skin_" + SkinID.ToString() + "/images/check_micr.gif"));
                            }

                            //hide payment methods if storeccindb = false
                        }
                        else if (AddressMode == AddressTypes.Shipping)
                        {
                            trCCInformation.Visible = false;
                        }
                    }
                }
            }

            if (e.Item.ItemType == ListItemType.Footer)
            {
                LinkButton  lbAddNewAddress = e.Item.FindControl("lbAddNewAddress") as LinkButton;
                ImageButton ibAddNewAddress = e.Item.FindControl("ibAddNewAddress") as ImageButton;

                if (lbAddNewAddress != null)
                {
                    if (AddressMode == AddressTypes.Billing)
                    {
                        string billingText = AppLogic.GetString("address.cs.70", SkinID, ThisCustomer.LocaleSetting);
                        lbAddNewAddress.Text = billingText;
                        if (ibAddNewAddress != null)
                        {
                            ibAddNewAddress.ToolTip       = billingText;
                            ibAddNewAddress.AlternateText = billingText;
                        }
                    }
                    else if (AddressMode == AddressTypes.Shipping)
                    {
                        string shippingText = AppLogic.GetString("address.cs.71", SkinID, ThisCustomer.LocaleSetting);
                        lbAddNewAddress.Text = shippingText;
                        if (ibAddNewAddress != null)
                        {
                            ibAddNewAddress.ToolTip       = shippingText;
                            ibAddNewAddress.AlternateText = shippingText;
                        }
                    }
                }
            }

            if ((e.Item.ItemType == ListItemType.Item ||
                 e.Item.ItemType == ListItemType.AlternatingItem))
            {
                //Assign numbering for individual address
                (e.Item.FindControl("lblIndexOrder") as Label).Text = String.Format("{0}.", (e.Item.ItemIndex + 1).ToString());
                int itemAddressID = Int32.Parse((e.Item.FindControl("hfAddressID") as HiddenField).Value);
                int primaryID     = 0;

                ImageButton ibDelete = e.Item.FindControl("ibDelete") as ImageButton;
                ImageButton ibEdit   = e.Item.FindControl("ibEdit") as ImageButton;

                DisableEditButtonsForAddressWithOpenOrder(ibDelete, ibEdit, itemAddressID);


                ImageButton ibMakePrimaryAddress = e.Item.FindControl("ibMakePrimary") as ImageButton;
                //Check if the address mode from the querystring to know what will be the primary address
                if (AddressMode == AddressTypes.Billing)
                {
                    primaryID = AppLogic.GetPrimaryBillingAddressID(ThisCustomer.CustomerID);
                    ibMakePrimaryAddress.ToolTip  = AppLogic.GetString("account.aspx.87", SkinID, ThisCustomer.LocaleSetting);
                    ibMakePrimaryAddress.ImageUrl = String.Format("~/App_Themes/Skin_{0}/images/icons/check_disabled.png", SkinID);
                }
                else if (AddressMode == AddressTypes.Shipping)
                {
                    primaryID = AppLogic.GetPrimaryShippingAddressID(ThisCustomer.CustomerID);
                    ibMakePrimaryAddress.ToolTip  = AppLogic.GetString("account.aspx.88", SkinID, ThisCustomer.LocaleSetting);
                    ibMakePrimaryAddress.ImageUrl = String.Format("~/App_Themes/Skin_{0}/images/icons/check_disabled.png", SkinID);
                }

                if (itemAddressID == primaryID)
                {
                    Label AddressHTML = e.Item.FindControl("lblAddressHTML") as Label;

                    //Display the last payment method used
                    if (CustomerCCRequired && AddressMode == AddressTypes.Billing)
                    {
                        string paymentMethodDisplay = DisplayPaymentMethod(primaryID);
                        if (!CommonLogic.IsStringNullOrEmpty(paymentMethodDisplay))
                        {
                            AddressHTML.Text += paymentMethodDisplay;
                        }
                    }

                    AddressHTML.Style["font-weight"] = "bold";
                    if (AddressMode == AddressTypes.Billing)
                    {
                        ibMakePrimaryAddress.ToolTip = AppLogic.GetString("account.aspx.89", SkinID, ThisCustomer.LocaleSetting);
                    }
                    else if (AddressMode == AddressTypes.Shipping)
                    {
                        ibMakePrimaryAddress.ToolTip = AppLogic.GetString("account.aspx.90", SkinID, ThisCustomer.LocaleSetting);
                    }
                    ibMakePrimaryAddress.ImageUrl = String.Format("~/App_Themes/Skin_{0}/images/icons/check_enabled.png", SkinID);
                }

                //shows the footer where you can click add
                dlAddress.ShowFooter = !tblNewAddress.Visible;
            }
        }
Пример #2
0
        private void PopulateAddressControlValues(AddressControl ctrlAddress, CreditCardPanel ctrlCreditCard, Echeck ctrlEcheck, int Index, int?editAddressId)
        {
            Addresses allAddress = GetAddresses();

            if (editAddressId.HasValue)
            {
                for (int i = 0; i < allAddress.Count; i++)
                {
                    if (allAddress[i].AddressID == editAddressId)
                    {
                        Index = i;
                    }
                }
            }
            AspDotNetStorefrontCore.Address anyAddress = allAddress[Index];

            if (ctrlAddress != null)
            {
                ctrlAddress.NickName      = anyAddress.NickName;
                ctrlAddress.FirstName     = anyAddress.FirstName;
                ctrlAddress.LastName      = anyAddress.LastName;
                ctrlAddress.PhoneNumber   = anyAddress.Phone;
                ctrlAddress.Company       = anyAddress.Company;
                ctrlAddress.ResidenceType = anyAddress.ResidenceType.ToString();
                ctrlAddress.Address1      = anyAddress.Address1;
                ctrlAddress.Address2      = anyAddress.Address2;
                ctrlAddress.Suite         = anyAddress.Suite;
                ctrlAddress.City          = anyAddress.City;
                ctrlAddress.ZipCode       = anyAddress.Zip;
                CountryDropDownData(ctrlAddress);
                ctrlAddress.Country = anyAddress.Country;
                StateDropDownData(ctrlAddress, ThisCustomer.LocaleSetting);
                ctrlAddress.State   = anyAddress.State;
                ctrlAddress.ShowZip = AppLogic.GetCountryPostalCodeRequired(AppLogic.GetCountryID(ctrlAddress.Country));
            }

            if (CustomerCCRequired)
            {
                if (ctrlCreditCard != null)
                {
                    ctrlCreditCard.CreditCardName   = anyAddress.CardName;
                    ctrlCreditCard.CreditCardNumber = AppLogic.SafeDisplayCardNumber(anyAddress.CardNumber, "Address", anyAddress.AddressID);
                    ctrlCreditCard.CreditCardType   = anyAddress.CardType;
                    ctrlCreditCard.CardExpMonth     = anyAddress.CardExpirationMonth;
                    ctrlCreditCard.CardExpYr        = anyAddress.CardExpirationYear;
                    if (AppLogic.AppConfigBool("Misc.ShowCardStartDateFields"))
                    {
                        if (!CommonLogic.IsStringNullOrEmpty(anyAddress.CardStartDate))
                        {
                            if (anyAddress.CardStartDate.Length >= 6)
                            {
                                ctrlCreditCard.CardStartMonth = anyAddress.CardStartDate.Substring(0, 2);
                                ctrlCreditCard.CardStartYear  = anyAddress.CardStartDate.Substring(2, 4);
                            }
                        }
                    }
                    if (AppLogic.AppConfigBool("CardExtraCodeIsOptional"))
                    {
                        ctrlCreditCard.CreditCardIssueNumber = anyAddress.CardIssueNumber;
                    }
                }
            }

            if (ShowEcheck)
            {
                if (ctrlEcheck != null)
                {
                    ctrlEcheck.ECheckBankAccountName   = anyAddress.ECheckBankAccountName;
                    ctrlEcheck.ECheckBankName          = anyAddress.ECheckBankName;
                    ctrlEcheck.ECheckBankABACode       = AppLogic.SafeDisplayCardNumber(anyAddress.ECheckBankABACode, "Address", anyAddress.AddressID);
                    ctrlEcheck.ECheckBankAccountNumber = anyAddress.ECheckBankAccountNumberMasked;
                    ctrlEcheck.ECheckBankAccountType   = anyAddress.ECheckBankAccountType;
                }
            }
        }
Пример #3
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();
                }
            }
        }