private AddressInfo GetLastUsedAddress() { ObjectQuery <AddressInfo> lastAddress = null; switch (AddressType) { case BILLING: // Get last modified billing addresses lastAddress = AddressInfoProvider.GetAddresses(ShoppingCart.ShoppingCartCustomerID, true, false, false, true).TopN(1).OrderByDescending("AddressLastModified"); break; case SHIPPING: lastAddress = AddressInfoProvider.GetAddresses(ShoppingCart.ShoppingCartCustomerID, false, true, false, true).TopN(1).OrderByDescending("AddressLastModified"); break; case COMPANY: lastAddress = AddressInfoProvider.GetAddresses(ShoppingCart.ShoppingCartCustomerID, false, false, true, true).TopN(1).OrderByDescending("AddressLastModified"); break; } // Load last used address if there is one if (!DataHelper.DataSourceIsEmpty(lastAddress)) { return(lastAddress.FirstObject); } return(null); }
/// <summary> /// Gets target shipping address /// </summary> /// <returns></returns> private static AddressDto GetTargetAddress() { try { var distributorID = Cart.GetIntegerValue("ShoppingCartDistributorID", default(int)); var distributorAddress = AddressInfoProvider.GetAddresses().WhereEquals("AddressID", distributorID).FirstOrDefault(); var addressLines = new[] { distributorAddress.GetStringValue("AddressLine1", string.Empty), distributorAddress.GetStringValue("AddressLine2", string.Empty) }.Where(a => !string.IsNullOrWhiteSpace(a)).ToList(); var country = CountryInfoProvider.GetCountries().WhereEquals("CountryID", distributorAddress.GetStringValue("AddressCountryID", string.Empty)) .Column("CountryTwoLetterCode").FirstOrDefault(); var state = StateInfoProvider.GetStates().WhereEquals("StateID", distributorAddress.GetStringValue("AddressStateID", string.Empty)).Column("StateCode").FirstOrDefault(); return(new AddressDto() { City = distributorAddress.GetStringValue("AddressCity", string.Empty), Country = country?.CountryTwoLetterCode, Postal = distributorAddress.GetStringValue("AddressZip", string.Empty), State = state?.StateCode, StreetLines = addressLines }); } catch (Exception ex) { EventLogProvider.LogInformation("ShoppingCartHelper", "GetTargetAddress", ex.Message); return(null); } }
/// <summary> /// Binds the address data to controls /// </summary> /// <param name="itemID">item id of the address data</param> private void BindAddressData(int itemID) { try { AddressInfo addressData = AddressInfoProvider.GetAddresses() .WhereEquals("AddressID", itemID) .FirstOrDefault(); if (!DataHelper.DataSourceIsEmpty(addressData)) { txtAddressLine1.Text = addressData.AddressLine1; txtAddressLine2.Text = addressData.AddressLine2; txtCity.Text = addressData.AddressCity; txtZipcode.Text = addressData.AddressZip; txtName.Text = addressData.AddressPersonalName; txtTelephone.Text = addressData.AddressPhone; uniSelectorCountry.Value = addressData.AddressCountryID; uniSelectorState.Value = addressData.AddressStateID; txtEmail.Text = addressData.GetStringValue("Email", string.Empty); txtComapnyName.Text = addressData.GetStringValue("CompanyName", string.Empty); ddlAddressType.Value = addressData.GetStringValue("AddressTypeID", string.Empty); if (addressData.AddressStateID <= 0) { uniSelectorState.Enabled = false; } } } catch (Exception ex) { EventLogProvider.LogException("CreateAddress.ascx.cs", "BindAddressData()", ex); } }
/// <summary> /// Gets target shipping address /// </summary> /// <returns></returns> private static AddressDTO GetBillingAddress() { try { var distributorID = Cart.GetIntegerValue("ShoppingCartDistributorID", default(int)); var distributorAddress = AddressInfoProvider.GetAddresses().WhereEquals("AddressID", distributorID).FirstOrDefault(); var country = CountryInfoProvider.GetCountries().WhereEquals("CountryID", distributorAddress.GetStringValue("AddressCountryID", string.Empty)).FirstOrDefault(); var state = StateInfoProvider.GetStates().WhereEquals("StateID", distributorAddress.GetStringValue("AddressStateID", string.Empty)).FirstOrDefault(); return(new AddressDTO() { KenticoAddressID = distributorAddress.AddressID, AddressLine1 = distributorAddress.AddressLine1, AddressLine2 = distributorAddress.AddressLine2, City = distributorAddress.AddressCity, State = state.StateCode, Zip = distributorAddress.GetStringValue("AddressZip", string.Empty), KenticoCountryID = distributorAddress.AddressCountryID, Country = country.CountryName, isoCountryCode = country.CountryTwoLetterCode, KenticoStateID = distributorAddress.AddressStateID, AddressPersonalName = distributorAddress.AddressPersonalName, AddressCompanyName = distributorAddress.GetStringValue("CompanyName", string.Empty) }); } catch (Exception ex) { EventLogProvider.LogInformation("ShoppingCartHelper", "GetBillingAddress", ex.Message); return(null); } }
private void InitializeAddress() { if (Customer == null) { return; } var addresses = AddressInfoProvider.GetAddresses(Customer.CustomerID).ToArray(); foreach (AddressInfo addr in addresses) { if (!this.IsPostBack) { var li = new ListItem(addr.AddressID.ToString()); li.Value = addr.AddressID.ToString(); this.hiddenAddressesList.Items.Add(li); li.Selected = CurrentCartAddress != null ? CurrentCartAddress.AddressID == addr.AddressID : addresses.FirstOrDefault().Equals(addr); } var transformation = TransformationInfoProvider.GetTransformation("kda.checkoutpage.ShippingAddress"); var resolver = MacroResolver.GetInstance(); resolver.SetNamedSourceData("ShippingAddress", addr); resolver.SetNamedSourceData("StateCode", addr.GetStateCode()); resolver.SetNamedSourceData("Checked", (CurrentCartAddress != null ? CurrentCartAddress.AddressID == addr.AddressID : addresses.FirstOrDefault().Equals(addr)) ? "checked":""); htmlContent.Text += resolver.ResolveMacros(transformation.TransformationCode); } }
private AddressInfo GetLastUsedAddress() { return(AddressInfoProvider.GetAddresses(ShoppingCart.ShoppingCartCustomerID) .OrderByDescending("AddressLastModified") .TopN(1) .FirstOrDefault()); }
/// <summary> /// Returns customer details /// </summary> /// <returns></returns> private static CustomerDTO GetCustomer() { try { var settingKeyValue = DIContainer.Resolve <IKenticoResourceService>().GetSettingsKey("KDA_SoldToGeneralInventory"); var distributorID = Cart.GetIntegerValue("ShoppingCartDistributorID", default(int)); var distributorAddress = AddressInfoProvider.GetAddresses().WhereEquals("AddressID", distributorID).FirstOrDefault(); var customer = CustomerInfoProvider.GetCustomerInfo(distributorAddress.AddressCustomerID); return(new CustomerDTO { FirstName = customer.CustomerFirstName, LastName = customer.CustomerLastName, KenticoCustomerID = customer.CustomerID, Email = customer.CustomerEmail, CustomerNumber = settingKeyValue, KenticoUserID = customer.CustomerUserID, Phone = customer.CustomerPhone }); } catch (Exception ex) { EventLogProvider.LogInformation("ShoppingCartHelper", "GetCustomer", ex.Message); return(null); } }
public DeliveryAddress[] GetCustomerShippingAddresses(int customerId) { var addresses = AddressInfoProvider.GetAddresses(customerId) .Where(a => a.GetStringValue("AddressType", string.Empty) == AddressType.Shipping) .ToArray(); return(_mapper.Map <DeliveryAddress[]>(addresses.ToArray())); }
private int GetLastUsedAddressId() { var lastAddress = AddressInfoProvider.GetAddresses(mCustomerId) .OrderByDescending("AddressLastModified") .TopN(1) .FirstOrDefault(); return((lastAddress != null) ? lastAddress.AddressID : 0); }
public DeliveryAddress[] GetCustomerAddresses(int customerId, AddressType addressType) { var query = AddressInfoProvider.GetAddresses(customerId); if (addressType != null) { query = query.Where($"AddressType ='{addressType}'"); } return(_mapper.Map <DeliveryAddress[]>(query.ToArray())); }
private List <AddressInfo> GetMyAddressBookList() { List <AddressInfo> myAddressList = new List <AddressInfo>(); CustomerInfo currentCustomer = CustomerInfoProvider.GetCustomerInfoByUserID(CurrentUser.UserID); if (!DataHelper.DataSourceIsEmpty(currentCustomer)) { myAddressList = AddressInfoProvider.GetAddresses(currentCustomer.CustomerID).Columns("AddressID", "AddressPersonalName").ToList(); } return(myAddressList); }
private void ReloadShippingAdresses() { //RptPickShippingAddress string where = string.Format("AddressCustomerID={0} AND AddressIsShipping=1", ECommerceContext.CurrentCustomer.CustomerID.ToString()); string orderby = "AddressID"; DataSet ds = AddressInfoProvider.GetAddresses(where, orderby); if (!DataHelper.DataSourceIsEmpty(ds)) { } RptPickShippingAddress.DataSource = ds; RptPickShippingAddress.DataBind(); }
/// <summary> /// Reloads the form data. /// </summary> protected void ReloadDataAdress() { CustomerInfo uc = ECommerceContext.CurrentCustomer; mCustomerId = uc.CustomerID; string where = "addressCustomerID = " + mCustomerId + " and AddressEnabled = 1"; DataSet ds = AddressInfoProvider.GetAddresses(where, null); if (!DataHelper.DataSourceIsEmpty(ds)) { rptAdress.DataSource = ds; rptAdress.DataBind(); } }
private AddressInfo GetLastUsedAddress() { return(CacheHelper.Cache(() => AddressInfoProvider.GetAddresses(ShoppingCart.ShoppingCartCustomerID) .OrderByDescending("AddressLastModified") .TopN(1) .FirstOrDefault(), new CacheSettings(ECommerceSettings.ProvidersCacheMinutes, "GetLastUsedAddressForCustomer", ShoppingCart.ShoppingCartCustomerID) { CacheDependency = CacheHelper.GetCacheDependency(new[] { AddressInfo.OBJECT_TYPE + "|all" }) })); }
//EndDocSection:DisplayDelivery //DocSection:DisplayDeliveryAddressSelector /// <summary> /// Displays the customer details checkout process step with an address selector for known customers. /// </summary> public ActionResult DeliveryDetailsAddressSelector() { // Gets the current user's shopping cart ShoppingCartInfo cart = shoppingService.GetCurrentShoppingCart(); // If the shopping cart is empty, redirects to the shopping cart view if (cart.IsEmpty) { return(RedirectToAction("ShoppingCart")); } // Gets all countries for the country selector SelectList countries = new SelectList(CountryInfoProvider.GetCountries(), "CountryID", "CountryDisplayName"); // Gets the current customer CustomerInfo customer = shoppingService.GetCurrentCustomer(); // Gets all customer billing addresses for the address selector IEnumerable <AddressInfo> customerAddresses = Enumerable.Empty <AddressInfo>(); if (customer != null) { customerAddresses = AddressInfoProvider.GetAddresses(customer.CustomerID).ToList(); } // Prepares address selector options SelectList addresses = new SelectList(customerAddresses, "AddressID", "AddressName"); // Gets all enabled shipping options for the shipping option selector SelectList shippingOptions = new SelectList(ShippingOptionInfoProvider.GetShippingOptions(SiteContext.CurrentSiteID, true).ToList(), "ShippingOptionID", "ShippingOptionDisplayName"); // Loads the customer details DeliveryDetailsViewModel model = new DeliveryDetailsViewModel { Customer = new CustomerViewModel(shoppingService.GetCurrentCustomer()), BillingAddress = new BillingAddressViewModel(shoppingService.GetBillingAddress(), countries, addresses), ShippingOption = new ShippingOptionViewModel(ShippingOptionInfoProvider.GetShippingOptionInfo(shoppingService.GetShippingOption()), shippingOptions) }; // Displays the customer details step return(View(model)); }
private void DeleteAddress() { // Prepare the parameters //string where = "AddressName LIKE 'My New%'"; // Get the address DataSet addresses = AddressInfoProvider.GetAddresses(null, null); if (!DataHelper.DataSourceIsEmpty(addresses)) { // Create object from DataRow AddressInfo updateAddress = new AddressInfo(addresses.Tables[0].Rows[0]); // Delete the address AddressInfoProvider.DeleteAddressInfo(updateAddress); // return true; } // return false; }
/// <summary> /// Initialize customer's addresses in billing and shipping drop-down lists. /// </summary> private void InitializeAddress() { if (Customer == null) { drpAddresses.Visible = false; lblAddress.Visible = false; return; } if (drpAddresses.Items.Count == 0) { // Specifies addresses to display for the given customer, select addresses associated with the given shopping cart DataSet ds = AddressInfoProvider.GetAddresses(Customer.CustomerID); if (!DataHelper.DataSourceIsEmpty(ds)) { drpAddresses.DataSource = ds; drpAddresses.DataBind(); // List item for the new item <(new), 0> item in the drop-down menu ListItem li = new ListItem(GetString("ShoppingCartOrderAddresses.NewAddress"), "0"); drpAddresses.Items.Insert(0, li); } } }
/// <summary> /// Reloads the form data. /// </summary> /// <summary> /// Page load. /// </summary> protected void Page_Load(object sender, EventArgs e) { // *** SERVRANX START*** ShowPaymentList(); if (!rdbVisa.Checked && !rdbMaestro.Checked && !rdbMastercard.Checked) { rdbVisa.Checked = true; rdoBtn_CheckedChanged(null, null); } ddlPaymentOption.SelectedValue = SessionHelper.GetValue("PaymentID").ToString(); ddlPaymentOption_SelectedIndexChanged(null, null); string where = string.Format("AddressCustomerID={0} AND AddressIsBilling=1", ECommerceContext.CurrentCustomer.CustomerID.ToString()); string orderby = "AddressID"; DataSet ds = AddressInfoProvider.GetAddresses(where, orderby); if (!DataHelper.DataSourceIsEmpty(ds)) { AddressInfo ai = new AddressInfo(ds.Tables[0].Rows[0]); lblBillingAddressFullName.Text = ai.AddressPersonalName; lblBillingAddressStreet.Text = string.IsNullOrEmpty(ai.AddressLine2) ? ai.AddressLine1 : string.Format("{0}, {1}", ai.AddressLine1, ai.AddressLine2); lblBillingAddressZipCode.Text = ai.AddressZip; lblBillingAddressCityCountry.Text = string.Format("{0}, {1}", ai.AddressCity, CountryInfoProvider.GetCountryInfo(ai.AddressCountryID).CountryDisplayName); ShoppingCart.ShoppingCartBillingAddressID = ai.AddressID; } where = string.Format("AddressCustomerID={0} AND AddressIsShipping=1", ECommerceContext.CurrentCustomer.CustomerID.ToString()); ds = AddressInfoProvider.GetAddresses(where, orderby); if (!DataHelper.DataSourceIsEmpty(ds)) { AddressInfo ai = new AddressInfo(ds.Tables[0].Rows[0]); lblShippingAddressFullName.Text = ai.AddressPersonalName; lblShippingAddressStreet.Text = string.IsNullOrEmpty(ai.AddressLine2) ? ai.AddressLine1 : string.Format("{0}, {1}", ai.AddressLine1, ai.AddressLine2); lblShippingAddressZipCode.Text = ai.AddressZip; lblShippingAddressCityCountry.Text = string.Format("{0}, {1}", ai.AddressCity, CountryInfoProvider.GetCountryInfo(ai.AddressCountryID).CountryDisplayName); ShoppingCart.ShoppingCartShippingAddressID = ai.AddressID; } else { // NO SHIPPING ADDRESS DEFINED- PICK FIRST BILLING ADDRESS AddressInfo ai_shipping = AddressInfoProvider.GetAddressInfo(ShoppingCart.ShoppingCartBillingAddressID); ai_shipping.AddressIsShipping = true; AddressInfoProvider.SetAddressInfo(ai_shipping); where = string.Format("AddressCustomerID={0} AND AddressIsShipping=1", ECommerceContext.CurrentCustomer.CustomerID.ToString()); ds = AddressInfoProvider.GetAddresses(where, orderby); if (!DataHelper.DataSourceIsEmpty(ds)) { AddressInfo ai = new AddressInfo(ds.Tables[0].Rows[0]); lblShippingAddressFullName.Text = ai.AddressPersonalName; lblShippingAddressStreet.Text = string.IsNullOrEmpty(ai.AddressLine2) ? ai.AddressLine1 : string.Format("{0}, {1}", ai.AddressLine1, ai.AddressLine2); lblShippingAddressZipCode.Text = ai.AddressZip; lblShippingAddressCityCountry.Text = string.Format("{0}, {1}", ai.AddressCity, CountryInfoProvider.GetCountryInfo(ai.AddressCountryID).CountryDisplayName); ShoppingCart.ShoppingCartShippingAddressID = ai.AddressID; } } ReloadData(); // *** SERVRANX END*** mCurrentSite = SiteContext.CurrentSite; //lblBillingTitle.Text = GetString("ShoppingCart.BillingAddress"); //lblShippingTitle.Text = GetString("ShoppingCart.ShippingAddress"); //lblCompanyAddressTitle.Text = GetString("ShoppingCart.CompanyAddress"); // Initialize labels. // LabelInitialize(); //this.TitleText = GetString("Order_new.ShoppingCartOrderAddresses.Title"); // Get customer ID from ShoppingCartInfoObj mCustomerId = ShoppingCart.ShoppingCartCustomerID; // Get customer info. CustomerInfo ci = CustomerInfoProvider.GetCustomerInfo(mCustomerId); if (ci != null) { // Display customer addresses if customer is not anonymous if (ci.CustomerID > 0) { if (!ShoppingCartControl.IsCurrentStepPostBack) { // Initialize customer billing and shipping addresses InitializeAddresses(); } } } // If shopping cart does not need shipping if (!ShippingOptionInfoProvider.IsShippingNeeded(ShoppingCart)) { // Hide title lblBillingTitle.Visible = false; // Change current checkout process step caption ShoppingCartControl.CheckoutProcessSteps[ShoppingCartControl.CurrentStepIndex].Caption = GetString("order_new.shoppingcartorderaddresses.titlenoshipping"); } }
public List <DeliveryAddress> GetAddressesByAddressIds(List <int> addressIds) { var addresses = AddressInfoProvider.GetAddresses().WhereIn("AddressID", addressIds).ToList(); return(mapper.Map <List <DeliveryAddress> >(addresses)); }
/// <summary> /// Page load. /// </summary> protected void Page_Load(object sender, EventArgs e) { mCurrentSite = SiteContext.CurrentSite; CountrySelector1.IsLiveSite = IsLiveSite; CountrySelector2.IsLiveSite = IsLiveSite; CountrySelector3.IsLiveSite = IsLiveSite; lblShippingTitle.Text = GetString("ShoppingCart.ShippingAddress"); lblCompanyAddressTitle.Text = GetString("ShoppingCart.CompanyAddress"); drpBillingAddr.SelectedIndexChanged += drpBillingAddr_SelectedIndexChanged; drpShippingAddr.SelectedIndexChanged += drpShippingAddr_SelectedIndexChanged; drpCompanyAddress.SelectedIndexChanged += drpCompanyAddress_SelectedIndexChanged; // Initialize labels. LabelInitialize(); //this.TitleText = GetString("Order_new.ShoppingCartOrderAddresses.Title"); // Get customer ID from ShoppingCartInfoObj mCustomerId = ShoppingCart.ShoppingCartCustomerID; // Get all addresses of the customer mCustomerAddresses = AddressInfoProvider.GetAddresses(mCustomerId); mLastUsedAddress = ECommerceHelper.GetLastUsedOrDefaultAddress(mCustomerId); // Display/ Hide company address panel with check box to display company address detail plcCompanyAll.Visible = ((mCurrentSite != null) && (ECommerceSettings.UseExtraCompanyAddress(mCurrentSite.SiteName))); // Get customer info. CustomerInfo ci = CustomerInfoProvider.GetCustomerInfo(mCustomerId); if (ci != null) { // Display customer addresses if customer is not anonymous if (ci.CustomerID > 0) { plhBillAddr.Visible = true; plhShippAddr.Visible = true; plcCompanyAddress.Visible = true; if (!ShoppingCartControl.IsCurrentStepPostBack) { // Initialize customer billing and shipping addresses InitializeAddresses(); } } } else { lblError.Visible = true; lblError.Text = GetString("Ecommerce.NoCustomerSelected"); // Hide forms when no customer selected plcCompanyAll.Visible = false; plcShippingAddress.Visible = false; plcBillingAddress.Visible = false; } // If shopping cart does not need shipping if (!ShoppingCart.IsShippingNeeded) { // Hide title headTitle.Visible = false; // Hide shipping address section plcShippingAddress.Visible = false; // Change current checkout process step caption ShoppingCartControl.CheckoutProcessSteps[ShoppingCartControl.CurrentStepIndex].Caption = GetString("order_new.shoppingcartorderaddresses.titlenoshipping"); } }
/// <summary> /// Returns an enumerable collection of a customer's addresses. /// </summary> /// <param name="customerId">Customer's identifier.</param> /// <returns>Collection of customer's addresses. See <see cref="CustomerAddress"/> for detailed information.</returns> public IEnumerable <CustomerAddress> GetByCustomerId(int customerId) { return(AddressInfoProvider.GetAddresses(customerId) .Select(info => new CustomerAddress(info)) .ToList()); }
public List <AddressData> GetAddressesList(int customerID) { var addressesList = AddressInfoProvider.GetAddresses(customerID).Columns("AddressID", "AddressPersonalName").WhereEquals("Status", true).ToList(); return(mapper.Map <List <AddressData> >(addressesList)); }
/// <summary> /// Returns an enumerable collection of a customer's addresses. /// </summary> /// <param name="customerId">Customer's identifier.</param> /// <returns>Collection of customer's addresses. See <see cref="AddressInfo"/> for detailed information.</returns> public IEnumerable <AddressInfo> GetByCustomerId(int customerId) { return(AddressInfoProvider.GetAddresses(customerId).ToList()); }
public Dictionary <int, string> GetAddressNames() { return(AddressInfoProvider.GetAddresses().ToDictionary(x => x.AddressID, x => x.AddressName)); }
public static List <AddressInfo> GetAdresses(bool billing, bool shipping, ShoppingCartInfo cart) { List <AddressInfo> Result = new List <AddressInfo>(); if (ECommerceContext.CurrentCustomer == null) { return(Result); } //if customer have no [AddressEnabled] int idCustomer = ECommerceContext.CurrentCustomer.CustomerID; SqlConnection con3 = new SqlConnection(ConfigurationManager.ConnectionStrings["CMSConnectionString"].ConnectionString); con3.Open(); var stringQuery = "select count(AddressID) as NbAdress from COM_Address WHERE COM_Address.AddressEnabled = 'true' AND COM_Address.AddressCustomerID = " + idCustomer; SqlCommand cmd3 = new SqlCommand(stringQuery, con3); int nb = (int)cmd3.ExecuteScalar(); if (nb == 0) { Result = null; return(Result); } string where = string.Empty, orderby = string.Empty; AddressInfo ai; DataSet ds, dsoi = null; if (billing) { ai = AddressInfoProvider.GetAddressInfo(cart.ShoppingCartBillingAddressID); if (ai == null) { where = string.Format("OrderCustomerID={0}", ECommerceContext.CurrentCustomer.CustomerID.ToString()); orderby = "OrderID DESC"; dsoi = OrderInfoProvider.GetOrderList(where, orderby); if (!DataHelper.DataSourceIsEmpty(dsoi)) { foreach (DataRow drow in dsoi.Tables[0].Rows) { OrderInfo oi = new OrderInfo(drow); AddressInfo bai = AddressInfoProvider.GetAddressInfo(oi.OrderBillingAddressID); if (bai.AddressEnabled && bai.AddressIsBilling) { ai = bai; cart.ShoppingCartBillingAddressID = bai.AddressID; break; } } } } if (ai == null) { where = string.Format("AddressCustomerID={0} AND AddressIsBilling=1", ECommerceContext.CurrentCustomer.CustomerID.ToString()); orderby = "AddressID"; ds = AddressInfoProvider.GetAddresses(where, orderby); if (!DataHelper.DataSourceIsEmpty(ds)) { ai = new AddressInfo(ds.Tables[0].Rows[0]); cart.ShoppingCartBillingAddressID = ai.AddressID; } } Result.Add(ai); } if (shipping) { ai = AddressInfoProvider.GetAddressInfo(cart.ShoppingCartShippingAddressID); if (ai == null) { if (DataHelper.DataSourceIsEmpty(dsoi)) { // where = string.Format("OrderCustomerID={0}", ECommerceContext.CurrentCustomer.CustomerID.ToString()); where = string.Format("OrderCustomerID={0} ", ECommerceContext.CurrentCustomer.CustomerID.ToString()); orderby = "OrderID DESC"; dsoi = OrderInfoProvider.GetOrderList(where, orderby); } if (!DataHelper.DataSourceIsEmpty(dsoi)) { foreach (DataRow drow in dsoi.Tables[0].Rows) { OrderInfo oi = new OrderInfo(drow); AddressInfo sai = AddressInfoProvider.GetAddressInfo(oi.OrderShippingAddressID); if (sai.AddressEnabled && sai.AddressIsShipping) { ai = sai; cart.ShoppingCartShippingAddressID = sai.AddressID; break; } } } } if (ai == null) { where = string.Format("AddressCustomerID={0} AND AddressIsShipping=1", ECommerceContext.CurrentCustomer.CustomerID.ToString()); orderby = "AddressID"; ds = AddressInfoProvider.GetAddresses(where, orderby); if (!DataHelper.DataSourceIsEmpty(ds)) { ai = new AddressInfo(ds.Tables[0].Rows[0]); cart.ShoppingCartShippingAddressID = ai.AddressID; } else { // NO SHIPPING ADDRESS DEFINED- PICK FIRST BILLING ADDRESS AddressInfo ai_shipping = AddressInfoProvider.GetAddressInfo(cart.ShoppingCartBillingAddressID); ai_shipping.AddressIsShipping = true; AddressInfoProvider.SetAddressInfo(ai_shipping); // where = string.Format("AddressCustomerID={0} AND AddressIsShipping=1", ECommerceContext.CurrentCustomer.CustomerID.ToString()); where = string.Format("AddressCustomerID={0} AND AddressIsShipping=1", ECommerceContext.CurrentCustomer.CustomerID.ToString()); ds = AddressInfoProvider.GetAddresses(where, orderby); if (!DataHelper.DataSourceIsEmpty(ds)) { ai = new AddressInfo(ds.Tables[0].Rows[0]); cart.ShoppingCartShippingAddressID = ai.AddressID; } } } Result.Add(ai); } return(Result); }
protected void rptAdressItemCommand(object source, RepeaterCommandEventArgs e) { // Get AddressId from the row int AddressId = ValidationHelper.GetInteger(e.CommandArgument, 0); // Delete selected address if (e.CommandName.Equals("Remove")) { int idShoppingCart = 0; // EventLogProvider ev = new EventLogProvider(); // test du nombre d'adresse int idCustomer = ECommerceContext.CurrentCustomer.CustomerID; string where, orderby; where = "AddressEnabled = 1 AND AddressCustomerID = " + idCustomer; orderby = "AddressID"; InfoDataSet <AddressInfo> listadresse = AddressInfoProvider.GetAddresses(where, orderby); if (listadresse.Tables[0].Rows.Count <= 1) { return; } else { // Delete AddressInfo object from database if address not used for order if ((OrderBillingAddress(AddressId) == 0) && (OrderShippingAddress(AddressId) == 0)) { SqlConnection con4 = new SqlConnection(ConfigurationManager.ConnectionStrings["CMSConnectionString"].ConnectionString); var query = "Select ShoppingCartID from COM_ShoppingCart where ShoppingCartShippingAddressID = " + AddressId; SqlCommand cmd2 = new SqlCommand(query, con4); // ev.LogEvent("I", DateTime.Now, "ds billig&shipping=0", "code"); con4.Open(); try { idShoppingCart = (int)cmd2.ExecuteScalar(); // ev.LogEvent("I", DateTime.Now, "dans try " + idShoppingCart, "code"); } catch (Exception ex) { } con4.Close(); if (idShoppingCart != 0) { var query2 = "Delete from COM_ShoppingCartSKU WHERE ShoppingCartID = " + idShoppingCart; SqlCommand cmd1 = new SqlCommand(query2, con4); cmd1.ExecuteScalar(); var stringQuery = "Delete from COM_ShoppingCart WHERE ShoppingCartShippingAddressID = " + AddressId; SqlCommand cmd3 = new SqlCommand(stringQuery, con4); cmd3.ExecuteScalar(); con4.Dispose(); } if (Session["newAddress"] != null) { int temp2 = Int32.Parse(Session["newAddress"].ToString()); if (temp2 != 0) { if (temp2 == AddressId) { Session["newAddress"] = null; } } } AddressInfoProvider.DeleteAddressInfo(AddressId); //ev.LogEvent("I", DateTime.Now, "button delete enabled true", "code"); // int id1 = ECommerceContext.CurrentCustomer.CustomerID; } // Disable AddressInfo object from database if address used for order else { SqlConnection con3 = new SqlConnection(ConfigurationManager.ConnectionStrings["CMSConnectionString"].ConnectionString); // con3.Open(); // ev.LogEvent("I", DateTime.Now, "iD = " + AddressId, "code"); var query = "Select ShoppingCartID from COM_ShoppingCart where ShoppingCartShippingAddressID = " + AddressId; SqlCommand cmd2 = new SqlCommand(query, con3); // ev.LogEvent("I", DateTime.Now, "test", "code"); con3.Open(); try { idShoppingCart = (int)cmd2.ExecuteScalar(); con3.Dispose(); } catch (Exception ex) { } con3.Close(); SqlConnection connect = new SqlConnection(ConfigurationManager.ConnectionStrings["CMSConnectionString"].ConnectionString); // ev.LogEvent("I", DateTime.Now, "idShoppingCart = " + idShoppingCart, "code"); if (idShoppingCart != 0) { connect.Open(); var query2 = "Delete from COM_ShoppingCartSKU WHERE ShoppingCartID = " + idShoppingCart; SqlCommand cmd1 = new SqlCommand(query2, connect); cmd1.ExecuteScalar(); var stringQuery = "Delete from COM_ShoppingCart WHERE ShoppingCartShippingAddressID = " + AddressId; SqlCommand cmd3 = new SqlCommand(stringQuery, connect); cmd3.ExecuteScalar(); connect.Close(); Response.Redirect("~/Special-Page/Mon-compte.aspx"); } // ev.LogEvent("I", DateTime.Now, "btn delet enabled false", "code"); AddressInfo UpdateAdress = AddressInfoProvider.GetAddressInfo(AddressId); CustomerInfo uc = ECommerceContext.CurrentCustomer; UpdateAdress.AddressEnabled = false; UpdateAdress.AddressCustomerID = mCustomerId; AddressInfoProvider.SetAddressInfo(UpdateAdress); AddressId = UpdateAdress.AddressID; } } ReloadDataAdress(); // PnlInsertAdress.Visible = false; } // Update selected adress if (e.CommandName.Equals("Update")) { // lblErrorAdress var lblErrorAdress = e.Item.FindControl("lblErrorAdress") as Label; // chkShippingAddr var chkShippingAddr = e.Item.FindControl("chkShippingAddr") as CheckBox; // chkBillingAddr var chkBillingAddr = e.Item.FindControl("chkBillingAddr") as CheckBox; if (!chkBillingAddr.Checked && !chkShippingAddr.Checked) { lblErrorAdress.Text = "V�rifier le type d'adresse"; lblErrorAdress.Visible = true; return; } int AddressID = Convert.ToInt32(e.CommandArgument); AddressInfo ai = AddressInfoProvider.GetAddressInfo(AddressID); string s = ai.AddressZip; // txtnumero var txtnumero = e.Item.FindControl("txtnumero") as TextBox; if (txtnumero != null) { ai.SetValue("AddressNumber", txtnumero.Text); } // txtadresse1 var txtadresse1 = e.Item.FindControl("txtadresse1") as TextBox; if (txtadresse1 != null) { ai.AddressLine1 = txtadresse1.Text; } // txtadresse2 var txtadresse2 = e.Item.FindControl("txtadresse2") as TextBox; if (txtadresse2 != null) { ai.AddressLine2 = txtadresse2.Text; } // txtcp TextBox txtcp = e.Item.FindControl("txtcp") as TextBox; if (txtcp != null) { ai.AddressZip = txtcp.Text; // Response.Write("<script>alert('This is Alert " + txtcp.Text + " " + DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt") + "');</script>"); } // txtville var txtville = e.Item.FindControl("txtville") as TextBox; if (txtville != null) { ai.AddressCity = txtville.Text; } // chkShippingAddr if (chkShippingAddr != null) { ai.AddressIsShipping = chkShippingAddr.Checked; } // chkBillingAddr if (chkBillingAddr != null) { ai.AddressIsBilling = chkBillingAddr.Checked; } CustomerInfo uc = ECommerceContext.CurrentCustomer; string mCustomerName = string.Format("{0} {1}", uc.CustomerFirstName, uc.CustomerLastName); // Set the properties ai.AddressName = string.Format("{0}, {4} {1} - {2} {3}", mCustomerName, ai.AddressLine1, ai.AddressZip, ai.AddressCity, ai.GetStringValue("AddressNumber", string.Empty)); AddressInfoProvider.SetAddressInfo(ai); // Update page here ReloadDataAdress(); } }
private string GetAndBulkUpdateAddresses(int aid, int cid, int oid) { // Prepare the parameters string where = "AddressID LIKE '" + aid + "'"; // Get the data DataSet addresses = AddressInfoProvider.GetAddresses(where, null); if (!DataHelper.DataSourceIsEmpty(addresses)) { // Loop through the individual items foreach (DataRow addressDr in addresses.Tables[0].Rows) { // Create object from DataRow AddressInfo modifyAddress = new AddressInfo(addressDr); // Update the properties modifyAddress.AddressName = modifyAddress.AddressName.ToUpper(); string a2 = modifyAddress.AddressLine2; if (!string.IsNullOrEmpty(a2)) { a2 = a2 + "<br/>"; } int pid = modifyAddress.AddressCountryID; string pays = string.Empty; string wherec = "CountryID LIKE'" + pid + "'"; DataSet country = CMS.Globalization.CountryInfoProvider.GetCountries(wherec, null); string customerv = string.Empty; string wherecu = "CustomerID LIKE '" + cid + "'"; string whereo = "OrderID LIKE '" + oid + "'"; string ordern = string.Empty; string invoice = string.Empty; CustomerInfo customer = null; //get order info DataSet orders = OrderInfoProvider.GetOrders(whereo, null); if (!DataHelper.DataSourceIsEmpty(orders)) { // Create object from DataRow OrderInfo order = new OrderInfo(orders.Tables[0].Rows[0]); // Update the property ordern = "Commande " + order.OrderID.ToString(); invoice = order.GetStringValue("facture", string.Empty); if (!string.IsNullOrEmpty(invoice)) { invoice = "Facture " + invoice + "<br/>"; } } // Get the customer DataSet customers = CustomerInfoProvider.GetCustomers(wherecu, null); if (!DataHelper.DataSourceIsEmpty(customers)) { // Create object from DataRow customer = new CustomerInfo(customers.Tables[0].Rows[0]); customerv = customer.CustomerLastName + " " + customer.CustomerFirstName; } if (!DataHelper.DataSourceIsEmpty(country)) { // Loop through the individual items foreach (DataRow countryDr in country.Tables[0].Rows) { CountryInfo ci = new CountryInfo(countryDr); pays = GetString(ci.CountryName); } } string result = "<br /><table border=\"0\" cellpadding=\"20\" cellspacing=\"0\" width=\"630px\"><tbody><tr><td valign=\"top\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tbody><tr><td><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"630px\"><tbody><tr><td align=\"left\" colspan=\"2\"><img src=\"http://www.servranx.com/App_Themes/Servranx/images/logonb.png\" width=\"300\" /><br /><div align=\"left\" style=\"font-size:13px ; border-left:3px solid black; padding-left:8px\"><p>Sprl Servranx<br />23-25, rue Gustave Biot - B-1050 Bruxelles<br />T�l. 00 32 (0)2 649 18 40<br />Fax 00 32 (0)2 649 12 10<br />[email protected]<br /><strong>www.servranx.com</strong><br />TVA BE 0450 834 519<br />Comptes bancaires :<br />ING 310-0529195-49<br />IBAN BE97 3100 5291 9549 <br />BIC : BBRUBEBB<br /> </p></div></td><td align=\"left\" style=\"text-align: left;\" width=\"351\"><div align=\"left\" style=\"border:2px solid black; padding:15px;font-weight:bold; font-size:17px;margin-top:50px\"><span style=\"font-size: 14px;text-transform:uppercase\">" + ordern + "<br/>" + invoice + " ADRESSE DE LIVRAISON<br/><br/><br/>" + customerv + "<br/>" + modifyAddress.GetValue("AddressNumber") + " " + modifyAddress.AddressLine1 + "<br/>" + a2 + modifyAddress.AddressZip + " " + modifyAddress.AddressCity + "<br/>" + pays + "</span></div></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table><br />"; return(result); // Update the address // AddressInfoProvider.SetAddressInfo(modifyAddress); } //return true; } return(string.Empty); }
private void SetupSelectedAddress() { AddressInfo address = CurrentCartAddress as AddressInfo; // Set DDL value only for classic load, CurrentCartAddress in postback is not ready yet if (!RequestHelper.IsPostBack()) { int addressId = 0; // In case of PropagateChangesOnPostback don't set address id, because in this mode null address is replaced with empty one in addressForm_OnAfterDataLoad if ((address != null) && !(PropagateChangesOnPostback && (address.AddressID == 0))) { addressId = address.AddressID; } else { // Get last modified customer address ObjectQuery <AddressInfo> lastAddress = null; switch (AddressType) { case BILLING: // Get last modified billing addresses lastAddress = AddressInfoProvider.GetAddresses(ShoppingCart.ShoppingCartCustomerID, true, false, false, true).TopN(1).OrderByDescending("AddressLastModified"); break; case SHIPPING: lastAddress = AddressInfoProvider.GetAddresses(ShoppingCart.ShoppingCartCustomerID, false, true, false, true).TopN(1).OrderByDescending("AddressLastModified"); break; case COMPANY: lastAddress = AddressInfoProvider.GetAddresses(ShoppingCart.ShoppingCartCustomerID, false, false, true, true).TopN(1).OrderByDescending("AddressLastModified"); break; } // Load last used address if there is one if (!DataHelper.DataSourceIsEmpty(lastAddress)) { address = lastAddress.FirstObject; addressId = address != null ? address.AddressID : 0; } } try { drpAddresses.SelectedValue = Convert.ToString(addressId); } // Eat exception in case of setting non-existing address in selector catch { } } // Do not init UIForm for new address, or there will be still old address after selecting "new" from address DDL selector if ((address != null) && (drpAddresses.SelectedValue != "0")) { addressForm.EditedObject = address; CurrentCartAddress = address; } // Do not reload data in postback, save action is postback, and reload will erase fields with changed data before saving into CurrentCartAddress if (!RequestHelper.IsPostBack()) { addressForm.ReloadData(); } }