protected void Page_PreRender(object sender, EventArgs e) { // Do we have an existing Main Address ? CustomerAddressInfo customerAddress = Controller.GetCustomerMainAddress(this.MainControl.CustomerId); if (customerAddress == null) { List <CustomerAddressInfo> customerSecondaryAddresses = Controller.GetCustomerAddresses(this.MainControl.CustomerId); if (customerSecondaryAddresses.Count > 0) { customerAddress = customerSecondaryAddresses[0]; customerAddress.IsDefault = true; Controller.UpdateCustomerAddress(customerAddress); } else { // Create New Address customerAddress = new CustomerAddressInfo(); UserInfo usr = UserController.GetUserById(PortalId, UserId); if (usr == null) { throw new Exception("Userdata not found"); } customerAddress.CustomerId = this.MainControl.CustomerId; customerAddress.PortalId = PortalId; customerAddress.Company = (usr.Profile.GetPropertyValue("Company") ?? ""); customerAddress.Prefix = (usr.Profile.GetPropertyValue("Prefix") ?? ""); customerAddress.Firstname = (usr.FirstName ?? ""); customerAddress.Middlename = (usr.Profile.GetPropertyValue("Middlename") ?? ""); customerAddress.Lastname = (usr.LastName ?? ""); customerAddress.Suffix = (usr.Profile.GetPropertyValue("Suffix") ?? ""); customerAddress.Unit = (usr.Profile.GetPropertyValue("Unit") ?? ""); customerAddress.Street = (usr.Profile.Street ?? ""); customerAddress.Region = (usr.Profile.GetPropertyValue("Region") ?? ""); customerAddress.PostalCode = (usr.Profile.PostalCode ?? ""); customerAddress.City = (usr.Profile.City ?? ""); customerAddress.Suburb = (usr.Profile.GetPropertyValue("Suburb") ?? ""); customerAddress.Country = (usr.Profile.Country ?? ""); customerAddress.CountryCode = GetCountryCode(customerAddress.Country); customerAddress.Cell = (usr.Profile.Cell ?? ""); customerAddress.Telephone = (usr.Profile.Telephone ?? ""); customerAddress.Fax = (usr.Profile.Fax ?? ""); customerAddress.Email = (usr.Email ?? ""); customerAddress.IsDefault = true; customerAddress.CustomerAddressId = Controller.NewCustomerAddress(customerAddress); // Add this address to all mandatory subscriberaddresstypes foreach (var addressType in _addressTypes) { if (addressType.Mandatory) { CartAddressInfo cartAddress = new CartAddressInfo() { CartID = this.MainControl.CartId, CustomerAddressId = customerAddress.CustomerAddressId, SubscriberAddressTypeId = addressType.SubscriberAddressTypeId }; Controller.NewCartAddress(cartAddress); } } // Edit this address Response.Redirect(Globals.NavigateURL(TabId, "", "action=adredit", "adrid=" + customerAddress.CustomerAddressId.ToString())); } } // Now lets retrieve all adresses of the customer List <CustomerAddressInfo> customerAddresses = Controller.GetCustomerAddresses(this.MainControl.CustomerId); // Check if all adresses meet the requirements foreach (CustomerAddressInfo customerCheckAddress in customerAddresses) { if ((Settings["MandCompany"] != null && Convert.ToBoolean(Settings["MandCompany"]) && String.IsNullOrEmpty(customerCheckAddress.Company)) || (Settings["MandPrefix"] != null && Convert.ToBoolean(Settings["MandPrefix"]) && String.IsNullOrEmpty(customerCheckAddress.Prefix)) || (Settings["MandFirstName"] != null && Convert.ToBoolean(Settings["MandFirstName"]) && String.IsNullOrEmpty(customerCheckAddress.Firstname)) || (Settings["MandMiddleName"] != null && Convert.ToBoolean(Settings["MandMiddleName"]) && String.IsNullOrEmpty(customerCheckAddress.Middlename)) || (Settings["MandLastName"] != null && Convert.ToBoolean(Settings["MandLastName"]) && String.IsNullOrEmpty(customerCheckAddress.Lastname)) || (Settings["MandSuffix"] != null && Convert.ToBoolean(Settings["MandSuffix"]) && String.IsNullOrEmpty(customerCheckAddress.Suffix)) || (Settings["MandStreet"] != null && Convert.ToBoolean(Settings["MandStreet"]) && String.IsNullOrEmpty(customerCheckAddress.Street)) || (Settings["MandUnit"] != null && Convert.ToBoolean(Settings["MandUnit"]) && String.IsNullOrEmpty(customerCheckAddress.Unit)) || (Settings["MandRegion"] != null && Convert.ToBoolean(Settings["MandRegion"]) && String.IsNullOrEmpty(customerCheckAddress.Region)) || (Settings["MandPostalCode"] != null && Convert.ToBoolean(Settings["MandPostalCode"]) && String.IsNullOrEmpty(customerCheckAddress.PostalCode)) || (Settings["MandCity"] != null && Convert.ToBoolean(Settings["MandCity"]) && String.IsNullOrEmpty(customerCheckAddress.City)) || (Settings["MandSuburb"] != null && Convert.ToBoolean(Settings["MandSuburb"]) && String.IsNullOrEmpty(customerCheckAddress.Suburb)) || (Settings["MandCountry"] != null && Convert.ToBoolean(Settings["MandCountry"]) && String.IsNullOrEmpty(customerCheckAddress.Country)) || (Settings["MandTelephone"] != null && Convert.ToBoolean(Settings["MandTelephone"]) && String.IsNullOrEmpty(customerCheckAddress.Telephone)) || (Settings["MandCell"] != null && Convert.ToBoolean(Settings["MandCell"]) && String.IsNullOrEmpty(customerCheckAddress.Cell)) || (Settings["MandFax"] != null && Convert.ToBoolean(Settings["MandFax"]) && String.IsNullOrEmpty(customerCheckAddress.Fax)) || (Settings["MandEmail"] != null && Convert.ToBoolean(Settings["MandEmail"]) && String.IsNullOrEmpty(customerCheckAddress.Email))) { Response.Redirect(Globals.NavigateURL(TabId, "", "action=adredit", "adrid=" + customerCheckAddress.CustomerAddressId.ToString())); } } customerAddresses.Add(new CustomerAddressInfo()); //if (customerAddresses.Count > 0) { lstCustomerAddresses.Visible = true; lstCustomerAddresses.DataSource = customerAddresses; lstCustomerAddresses.DataBind(); } //else //{ // lstCustomerAddresses.Visible = false; //} }
protected void lstCustomerAddresses_ItemDataBound(object sender, ListViewItemEventArgs e) { if (e.Item.ItemType == ListViewItemType.DataItem) { ListViewDataItem dataItem = (ListViewDataItem)e.Item; CustomerAddressInfo lstCustomerAddress = dataItem.DataItem as CustomerAddressInfo; HtmlTableCell cellAddress = e.Item.FindControl("cellAddress") as HtmlTableCell; cellAddress.Style.Add("width", (100 / lstCustomerAddresses.GroupItemCount).ToString() + "%"); Label lblAdress = e.Item.FindControl("lblAddress") as Label; ImageButton imgAdrEditlst = e.Item.FindControl("imgAdrEditlst") as ImageButton; LinkButton cmdAdrEditlst = e.Item.FindControl("cmdAdrEditlst") as LinkButton; ImageButton imgAdrDeletelst = e.Item.FindControl("imgAdrDeletelst") as ImageButton; LinkButton cmdAdrDeletelst = e.Item.FindControl("cmdAdrDeletelst") as LinkButton; ImageButton imgAdrNewlst = e.Item.FindControl("imgAdrNewlst") as ImageButton; LinkButton cmdAdrNewlst = e.Item.FindControl("cmdAdrNewlst") as LinkButton; CheckBoxList lstAddressType = e.Item.FindControl("lstAddresstype") as CheckBoxList; HiddenField hidCustomerAddressId = e.Item.FindControl("hidCustomerAddressId") as HiddenField; string template = Localization.GetString("AddressTemplate.Text", this.LocalResourceFile.Replace("ViewCartSelectAddresses", "ViewCartAddressEdit")); lblAdress.Text = lstCustomerAddress.ToHtml(template, true); string strCustomerAddressId = lstCustomerAddress.CustomerAddressId.ToString(); hidCustomerAddressId.Value = strCustomerAddressId; imgAdrEditlst.CommandArgument = strCustomerAddressId; cmdAdrEditlst.CommandArgument = strCustomerAddressId; imgAdrDeletelst.CommandArgument = strCustomerAddressId; cmdAdrDeletelst.CommandArgument = strCustomerAddressId; lstAddressType.DataSource = _addressTypes; lstAddressType.DataBind(); List <CartAddressInfo> adresses = Controller.GetCartAddressesByAddressId(this.MainControl.CartId, lstCustomerAddress.CustomerAddressId); bool isSelected = false; foreach (CartAddressInfo cartAddressInfo in adresses) { foreach (ListItem chk in lstAddressType.Items) { if (chk.Value == cartAddressInfo.SubscriberAddressTypeId.ToString()) { chk.Selected = true; isSelected = true; break; } } } if (lstCustomerAddress.CustomerAddressId > -1) { if (isSelected || Controller.HasOrderAddress(lstCustomerAddress.CustomerAddressId)) { imgAdrDeletelst.Visible = false; cmdAdrDeletelst.Visible = false; } imgAdrNewlst.Visible = false; cmdAdrNewlst.Visible = false; } else { lstAddressType.Enabled = false; imgAdrDeletelst.Visible = false; cmdAdrDeletelst.Visible = false; imgAdrEditlst.Visible = false; cmdAdrEditlst.Visible = false; imgAdrNewlst.Visible = true; cmdAdrNewlst.Visible = true; } } }
protected void Page_Load(object sender, EventArgs e) { cmdAdrEditCancel.CssClass = (string)Settings["ShoppingButtonCssClass"] ?? ""; cmdAdrEditSave.CssClass = (string)Settings["CheckoutButtonCssClass"] ?? ""; // Is he logged in ? if (!Request.IsAuthenticated) { // Attention ! returnUrl must be relative path (cross-site-scripting denying) string returnUrl = HttpContext.Current.Request.RawUrl; returnUrl = HttpUtility.UrlEncode(returnUrl); Response.Redirect(Globals.NavigateURL(TabId, "", "action=login", "returnurl=" + returnUrl)); } if (true) { lblIntro.Text = LocalizeString("Intro.Message"); // Lets retrieve the CustomerAdressId and the CustomerAdress from Database hidAdrEditCustomerAddressId.Value = (Request.QueryString["adrid"] != null ? Request.QueryString["adrid"].ToString() : "-1"); string form = GenerateForm(); Control ctrl = ParseControl(form); string selectedCountryCode = ""; ddlCountry = FindControlRecursive(ctrl, "ddlCountry") as DropDownList; if (ddlCountry != null) { ListController ListController = new ListController(); ListEntryInfoCollection Countries = ListController.GetListEntryInfoCollection("Country"); ddlCountry.DataSource = Countries; ddlCountry.DataTextField = "Text"; ddlCountry.DataValueField = "Value"; ddlCountry.DataBind(); if (!String.IsNullOrEmpty((string)StoreSettings["VendorCountry"])) { selectedCountryCode = (string)StoreSettings["VendorCountry"]; } } txtAdrEditCompany = FindControlRecursive(ctrl, "txtAdrEditCompany") as TextBox; txtAdrEditPrefix = FindControlRecursive(ctrl, "txtAdrEditPrefix") as TextBox; txtAdrEditFirstname = FindControlRecursive(ctrl, "txtAdrEditFirstname") as TextBox; txtAdrEditMiddlename = FindControlRecursive(ctrl, "txtAdrEditMiddlename") as TextBox; txtAdrEditLastname = FindControlRecursive(ctrl, "txtAdrEditLastname") as TextBox; txtAdrEditSuffix = FindControlRecursive(ctrl, "txtAdrEditSuffix") as TextBox; txtAdrEditUnit = FindControlRecursive(ctrl, "txtAdrEditUnit") as TextBox; txtAdrEditStreet = FindControlRecursive(ctrl, "txtAdrEditStreet") as TextBox; txtAdrEditRegion = FindControlRecursive(ctrl, "txtAdrEditRegion") as TextBox; txtAdrEditPostalCode = FindControlRecursive(ctrl, "txtAdrEditPostalCode") as TextBox; txtAdrEditCity = FindControlRecursive(ctrl, "txtAdrEditCity") as TextBox; txtAdrEditSuburb = FindControlRecursive(ctrl, "txtAdrEditSuburb") as TextBox; txtAdrEditPhone = FindControlRecursive(ctrl, "txtAdrEditPhone") as TextBox; txtAdrEditFax = FindControlRecursive(ctrl, "txtAdrEditFax") as TextBox; txtAdrEditCell = FindControlRecursive(ctrl, "txtAdrEditCell") as TextBox; txtAdrEditEmail = FindControlRecursive(ctrl, "txtAdrEditEmail") as TextBox; phAddressEdit.Controls.Add(ctrl); if (hidAdrEditCustomerAddressId.Value != "-1") { int CustomerAddressId; if (Int32.TryParse(hidAdrEditCustomerAddressId.Value, out CustomerAddressId)) { CustomerAddressInfo CustomerAddress = Controller.GetCustomerAddress(CustomerAddressId); if (CustomerAddress != null && CustomerAddress.CustomerId == this.MainControl.CustomerId) { if (txtAdrEditCompany != null) { txtAdrEditCompany.Text = CustomerAddress.Company.Trim(); } if (txtAdrEditPrefix != null) { txtAdrEditPrefix.Text = CustomerAddress.Prefix.Trim(); } if (txtAdrEditFirstname != null) { txtAdrEditFirstname.Text = CustomerAddress.Firstname.Trim(); } if (txtAdrEditMiddlename != null) { txtAdrEditMiddlename.Text = CustomerAddress.Middlename.Trim(); } if (txtAdrEditLastname != null) { txtAdrEditLastname.Text = CustomerAddress.Lastname.Trim(); } if (txtAdrEditSuffix != null) { txtAdrEditSuffix.Text = CustomerAddress.Suffix.Trim(); } if (txtAdrEditUnit != null) { txtAdrEditUnit.Text = CustomerAddress.Unit.Trim(); } if (txtAdrEditStreet != null) { txtAdrEditStreet.Text = CustomerAddress.Street.Trim(); } if (txtAdrEditRegion != null) { txtAdrEditRegion.Text = CustomerAddress.Region.Trim(); } if (txtAdrEditPostalCode != null) { txtAdrEditPostalCode.Text = CustomerAddress.PostalCode.Trim(); } if (txtAdrEditCity != null) { txtAdrEditCity.Text = CustomerAddress.City.Trim(); } if (txtAdrEditSuburb != null) { txtAdrEditSuburb.Text = CustomerAddress.Suburb.Trim(); } if (txtAdrEditPhone != null) { txtAdrEditPhone.Text = CustomerAddress.Telephone.Trim(); } if (txtAdrEditFax != null) { txtAdrEditFax.Text = CustomerAddress.Fax.Trim(); } if (txtAdrEditCell != null) { txtAdrEditCell.Text = CustomerAddress.Cell.Trim(); } if (txtAdrEditEmail != null) { txtAdrEditEmail.Text = CustomerAddress.Email.Trim(); } selectedCountryCode = CustomerAddress.CountryCode; } else { hidAdrEditCustomerAddressId.Value = "-1"; } } else { hidAdrEditCustomerAddressId.Value = "-1"; } } if (ddlCountry != null && selectedCountryCode != string.Empty) { ListItem itemToSelect = ddlCountry.Items.FindByValue(selectedCountryCode.Trim()); if (itemToSelect != null) { ddlCountry.SelectedIndex = ddlCountry.Items.IndexOf(itemToSelect); } } } }
protected void cmdAdrEditSave_Click(object sender, EventArgs e) { int customerAddressId = -1; Int32.TryParse(hidAdrEditCustomerAddressId.Value, out customerAddressId); CustomerAddressInfo CustomerAddress = new CustomerAddressInfo(); bool IsNewAddress; if (customerAddressId > 0) { CustomerAddress = Controller.GetCustomerAddress(customerAddressId); } if (CustomerAddress.CustomerId != this.MainControl.CustomerId) { CustomerAddress = new CustomerAddressInfo(); CustomerAddress.CustomerId = this.MainControl.CustomerId; IsNewAddress = true; CustomerAddress.PortalId = PortalId; } else { IsNewAddress = false; } if (txtAdrEditCompany != null) { CustomerAddress.Company = txtAdrEditCompany.Text.Trim(); } if (txtAdrEditPrefix != null) { CustomerAddress.Prefix = txtAdrEditPrefix.Text.Trim(); } if (txtAdrEditFirstname != null) { CustomerAddress.Firstname = txtAdrEditFirstname.Text.Trim(); } if (txtAdrEditMiddlename != null) { CustomerAddress.Middlename = txtAdrEditMiddlename.Text.Trim(); } if (txtAdrEditLastname != null) { CustomerAddress.Lastname = txtAdrEditLastname.Text.Trim(); } if (txtAdrEditSuffix != null) { CustomerAddress.Suffix = txtAdrEditSuffix.Text.Trim(); } if (txtAdrEditUnit != null) { CustomerAddress.Unit = txtAdrEditUnit.Text.Trim(); } if (txtAdrEditStreet != null) { CustomerAddress.Street = txtAdrEditStreet.Text.Trim(); } if (txtAdrEditRegion != null) { CustomerAddress.Region = txtAdrEditRegion.Text.Trim(); } if (txtAdrEditPostalCode != null) { CustomerAddress.PostalCode = txtAdrEditPostalCode.Text.Trim(); } if (txtAdrEditCity != null) { CustomerAddress.City = txtAdrEditCity.Text.Trim(); } if (txtAdrEditSuburb != null) { CustomerAddress.Suburb = txtAdrEditSuburb.Text.Trim(); } if (ddlCountry != null) { CustomerAddress.Country = ddlCountry.SelectedItem.Text; CustomerAddress.CountryCode = ddlCountry.SelectedItem.Value; } if (txtAdrEditPhone != null) { CustomerAddress.Telephone = txtAdrEditPhone.Text.Trim(); } if (txtAdrEditFax != null) { CustomerAddress.Fax = txtAdrEditFax.Text.Trim(); } if (txtAdrEditCell != null) { CustomerAddress.Cell = txtAdrEditCell.Text.Trim(); } if (txtAdrEditEmail != null) { CustomerAddress.Email = txtAdrEditEmail.Text.Trim(); } if (IsNewAddress) { Controller.NewCustomerAddress(CustomerAddress); } else { Controller.UpdateCustomerAddress(CustomerAddress); } Response.Redirect(Globals.NavigateURL(TabId, "", "action=checkout")); }
public abstract void UpdateCustomerAddress(CustomerAddressInfo CustomerAddress);
public abstract int NewCustomerAddress(CustomerAddressInfo CustomerAddress);