Exemple #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                // Get localized default address description
                _addressDefaultDescription = Localization.GetString("AddressDefaultDescription", LocalResourceFile);
                // Get the navigation settings and AddressID
                _addressNav = new AddressNavigation(Request.QueryString);
                _addressID  = _addressNav.AddressID;

                if (!IsPostBack)
                {
                    // Get an Address controler
                    AddressController controller = new AddressController();

                    // Define default address settings
                    AddressSettings addressSettings = controller.GetAddressSettings(PortalId);
                    addressEdit.Settings = addressSettings;

                    // Edit Address
                    if (_addressID > 0)
                    {
                        plhGrid.Visible        = false;
                        plhEditAddress.Visible = true;

                        AddressInfo address        = (AddressInfo)controller.GetAddress(_addressID);
                        bool        authorizedUser = (address.UserID == UserId);

                        if (authorizedUser)
                        {
                            if (string.IsNullOrEmpty(address.Email))
                            {
                                address.Email = UserInfo.Email;
                            }
                            addressEdit.Address         = address;
                            addressEdit.ShowUserSaved   = false;
                            addressEdit.ShowDescription = true;
                            // Set delete confirmation
                            cmdDelete.Attributes.Add("onClick", "javascript:return confirm('" + Localization.GetString("DeleteItem") + "');");
                            cmdDelete.Visible = true;
                        }
                        else
                        {
                            ErrorMessage = Localization.GetString("ErrorLoading", LocalResourceFile);
                            // Someone is trying to steal an address!
                            // A log entry will be added in the parent control
                            InvokeSecurityProviderError();
                        }
                    }
                    // Add Address
                    else if (_addressID == 0)
                    {
                        plhGrid.Visible        = false;
                        plhEditAddress.Visible = true;
                        addressEdit.Address    = new AddressInfo {
                            UserSaved = true
                        };
                        addressEdit.ShowUserSaved   = false;
                        addressEdit.ShowDescription = true;
                    }
                    // Display user's addresses
                    else
                    {
                        List <AddressInfo> addresses = controller.GetAddresses <AddressInfo>(PortalId, UserId, _addressDefaultDescription);

                        if (addresses.Count > 0)
                        {
                            grdAddresses.DataSource = addresses;
                            grdAddresses.DataBind();
                        }

                        plhGrid.Visible        = true;
                        plhEditAddress.Visible = false;
                    }
                }
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //Load the billing address
                AddressController controller = new AddressController();
                ArrayList addresses = controller.GetAddresses(PortalId, UserId);

                lstBillAddress.DataSource = addresses;
                lstBillAddress.DataTextField = "Description";
                lstBillAddress.DataValueField = "AddressID";
                lstBillAddress.DataBind();
                lstBillAddress.Items.Insert(0, new ListItem(Localization.GetString("SelectBillingAddress", this.LocalResourceFile), "-1"));
                //lstBillAddress.ClearSelection();
                //lstBillAddress.Items[1].Selected = true;
                //lstBillAddress_SelectedIndexChanged(lstBillAddress, new EventArgs());

                lstShipAddress.DataSource = addresses;
                lstShipAddress.DataTextField = "Description";
                lstShipAddress.DataValueField = "AddressID";
                lstShipAddress.DataBind();
                lstShipAddress.Items.Insert(0, new ListItem(Localization.GetString("SelectShippingAddress", this.LocalResourceFile), "-1"));
                //populateShipAddress(int.Parse(lstBillAddress.SelectedValue));

                ShippingAddressSelectionEnabled = false;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            // Get default address description
            _addressDefaultDescription = Localization.GetString("AddressDefaultDescription", LocalResourceFile);

            if (!IsPostBack)
            {
                // Hide shipping address block if no delivery is defined
                fsShippingAddress.Visible = !NoDelivery;

                bool         addressChanged = false;
                IAddressInfo billingAddress = BillingAddress;
                if (billingAddress != null)
                {
                    int          billingAddressID  = billingAddress.AddressID;
                    IAddressInfo shippingAddress   = ShippingAddress;
                    int          shippingAddressID = shippingAddress.AddressID;

                    // If the user is logged
                    if (IsLogged)
                    {
                        //Get the user's addresses
                        List <AddressInfo> addresses = _controller.GetAddresses <AddressInfo>(PortalId, UserId, _addressDefaultDescription);

                        // Bind addresses lists
                        BindBillingAddressList(addresses);

                        // If billing address is not set
                        if (billingAddressID == Null.NullInteger)
                        {
                            // Search for the primary address
                            bool primaryAddressFound = false;
                            foreach (AddressInfo address in addresses)
                            {
                                if (address.PrimaryAddress)
                                {
                                    billingAddress      = address;
                                    primaryAddressFound = true;
                                    break;
                                }
                            }
                            // Define selected addresses
                            if (primaryAddressFound)
                            {
                                billingAddressID  = billingAddress.AddressID;
                                BillingAddress    = billingAddress;
                                shippingAddressID = billingAddressID;
                                ShippingAddress   = billingAddress;
                                addressChanged    = true;
                            }
                        }
                    }
                    else
                    {
                        rowListBillAddress.Visible = false;
                    }

                    // Update billing interface
                    UpdateBillingInterface();

                    // Define shipping mode then update shipping interface
                    if (shippingAddressID != Null.NullInteger && shippingAddressID != billingAddressID)
                    {
                        Shipping            = ShippingMode.Other;
                        radShipping.Checked = true;
                        DisplayShippingAddressSelection(true);
                    }
                    else
                    {
                        Shipping           = ShippingMode.SameAsBilling;
                        radBilling.Checked = true;
                        DisplayShippingAddressSelection(false);
                    }
                }
                // Callback Checkout control to save order with new addresses
                if (addressChanged)
                {
                    SendBillingAddressChangedEvent();
                }
            }
        }
        protected void Page_Load(object sender, System.EventArgs e)
        {
            try
            {
                // Get the navigation settings
                addressNav = new AddressNavigation(Request.QueryString);

                if (addressNav.AddressID.Length > 0)
                {
                    addressId = int.Parse(addressNav.AddressID);
                }
                else
                {
                    addressId = -1;
                }

                if (!Page.IsPostBack)
                {
                    AddressController controller = new AddressController();
                    ArrayList addresses = controller.GetAddresses(this.PortalId, this.UserId);

                    if (addresses.Count > 0)
                    {
                        grdAddresses.DataSource = addresses;
                        grdAddresses.DataBind();
                    }

                    // Set delete confirmation
                    cmdDelete.Attributes.Add("onClick", "javascript:return confirm('" + Localization.GetString("DeleteItem") + "');");

                    // Edit Address
                    if (addressId > 0)
                    {
                        plhGrid.Visible = false;
                        plhEditAddress.Visible = true;

                        lblEditTitle.Text = Localization.GetString("EditAddress", this.LocalResourceFile);

                        AddressInfo address = (AddressInfo)controller.GetAddress(addressId);

                        if (address != null)

                        {
                            //BUG: This does not work because the page_load event is called prior to the controls load event.
                            this.addressEdit.AddressInfo = address;
                            cmdDelete.Visible = true;
                            chkPrimary.Checked = address.PrimaryAddress;
                        }
                    }
                    // Add Address
                    else if (addressId == 0)
                    {
                        plhGrid.Visible = false;
                        plhEditAddress.Visible = true;

                        lblEditTitle.Text = Localization.GetString("AddAddress", this.LocalResourceFile);
                    }
                    // No Action
                    else
                    {
                        plhGrid.Visible = true;
                        plhEditAddress.Visible = false;

                        lblEditTitle.Text = Localization.GetString("Addresses", this.LocalResourceFile);
                    }
                }
            }
            catch(Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }