Exemplo n.º 1
0
        protected void CreateCustomerAddress(int customerID, UserDto userDto)
        {
            var country = FindCountry(userDto.Country);

            if (country == null)
            {
                EventLogProvider.LogInformation("Import users", "INFO", $"Skipping creation of address of user { userDto.Email }. Reason - invalid country.");
                return;
            }

            var state = FindState(userDto.State);

            var addressNameFields = new[] { $"{userDto.FirstName} {userDto.LastName}", userDto.AddressLine, userDto.AddressLine2, userDto.City }
            .Where(af => !string.IsNullOrWhiteSpace(af));
            var newAddress = new AddressInfo
            {
                AddressName         = string.Join(", ", addressNameFields),
                AddressLine1        = userDto.AddressLine ?? "",
                AddressLine2        = userDto.AddressLine2,
                AddressCity         = userDto.City ?? "",
                AddressZip          = userDto.PostalCode ?? "",
                AddressPersonalName = userDto.ContactName ?? $"{userDto.FirstName} {userDto.LastName}",
                AddressPhone        = userDto.PhoneNumber ?? "",
                AddressCustomerID   = customerID,
                AddressCountryID    = country.CountryID,
                AddressStateID      = state?.StateID ?? 0
            };

            newAddress.SetValue("AddressType", AddressType.Shipping.Code);

            AddressInfoProvider.SetAddressInfo(newAddress);
        }
        public void SaveShippingAddress(DeliveryAddress address)
        {
            var customer = ECommerceContext.CurrentCustomer;
            var info     = new AddressInfo
            {
                AddressID           = address.Id,
                AddressLine1        = address.Address1,
                AddressLine2        = address.Address2,
                AddressCity         = address.City,
                AddressStateID      = address.State.Id,
                AddressCountryID    = address.Country.Id,
                AddressZip          = address.Zip,
                AddressCustomerID   = customer.CustomerID,
                AddressPersonalName = $"{customer.CustomerFirstName} {customer.CustomerLastName}",
                AddressPhone        = address.Phone
            };

            info.AddressName = $"{info.AddressPersonalName}, {info.AddressLine1}, {info.AddressCity}";
            info.SetValue("AddressType", AddressType.Shipping.Code);
            info.SetValue("CompanyName", address.CustomerName);
            info.SetValue("Email", address.Email);

            AddressInfoProvider.SetAddressInfo(info);
            address.Id = info.AddressID;
        }
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (customerObj == null)
        {
            return;
        }

        if (!ECommerceContext.IsUserAuthorizedToModifyCustomer())
        {
            RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyCustomers");
        }

        if (customerId != 0)
        {
            string errorMessage = new Validator().NotEmpty(txtAddressLine1.Text, "Customer_Edit_Address_Edit.rqvLine")
                                  .NotEmpty(txtAddressCity.Text, "Customer_Edit_Address_Edit.rqvCity")
                                  .NotEmpty(txtAddressZip.Text, "Customer_Edit_Address_Edit.rqvZipCode")
                                  .NotEmpty(txtPersonalName.Text, "Customer_Edit_Address_Edit.rqvPersonalName").Result;

            // Check country presence
            if (errorMessage == "" && (ucCountrySelector.CountryID <= 0))
            {
                errorMessage = GetString("countryselector.selectedcountryerr");
            }

            if (errorMessage == "")
            {
                // Get object
                AddressInfo addressObj = AddressInfoProvider.GetAddressInfo(addressId);
                if (addressObj == null)
                {
                    addressObj = new AddressInfo();
                }

                addressObj.AddressIsBilling    = chkAddressIsBilling.Checked;
                addressObj.AddressIsShipping   = chkAddressIsShipping.Checked;
                addressObj.AddressZip          = txtAddressZip.Text.Trim();
                addressObj.AddressPhone        = txtAddressDeliveryPhone.Text.Trim();
                addressObj.AddressPersonalName = txtPersonalName.Text.Trim();
                addressObj.AddressLine1        = txtAddressLine1.Text.Trim();
                addressObj.AddressEnabled      = chkAddressEnabled.Checked;
                addressObj.AddressLine2        = txtAddressLine2.Text.Trim();
                addressObj.AddressCity         = txtAddressCity.Text.Trim();
                addressObj.AddressCountryID    = ucCountrySelector.CountryID;
                addressObj.AddressStateID      = ucCountrySelector.StateID;
                addressObj.AddressIsCompany    = chkAddressIsCompany.Checked;
                addressObj.AddressName         = AddressInfoProvider.GetAddressName(addressObj);
                addressObj.AddressCustomerID   = customerId;

                AddressInfoProvider.SetAddressInfo(addressObj);

                URLHelper.Redirect("Customer_Edit_Address_Edit.aspx?customerId=" + customerId + "&addressId=" + Convert.ToString(addressObj.AddressID) + "&saved=1");
            }
            else
            {
                lblError.Visible = true;
                lblError.Text    = errorMessage;
            }
        }
    }
Exemplo n.º 4
0
    /// <summary>
    /// On btnOK click, save edited or new created address.
    /// </summary>
    protected void btnOK_OnClick(object sender, EventArgs e)
    {
        if (mCustomerId != 0)
        {
            // Check field emptiness
            string errorMessage = new Validator().NotEmpty(txtAddressLine1.Text, "Customer_Edit_Address_Edit.rqvLine").NotEmpty(txtAddressCity.Text, "Customer_Edit_Address_Edit.rqvCity").NotEmpty(txtAddressZip.Text, "Customer_Edit_Address_Edit.rqvZipCode").NotEmpty(txtPersonalName.Text, "Customer_Edit_Address_Edit.rqvPersonalName").Result;

            // Check country presence
            if ((errorMessage == "") && (ucCountrySelector.CountryID <= 0))
            {
                errorMessage = GetString("countryselector.selectedcountryerr");
            }

            if (errorMessage == "")
            {
                AddressInfo ai = null;
                // Create new addressinfo or get the existing one
                if (AddressId == 0)
                {
                    ai = new AddressInfo();
                    ai.AddressEnabled    = true;
                    ai.AddressIsBilling  = true;
                    ai.AddressIsShipping = true;
                    ai.AddressIsCompany  = true;
                    ai.AddressCustomerID = mCustomerId;
                }
                else
                {
                    ai = AddressInfoProvider.GetAddressInfo(AddressId);
                }

                if (ai != null)
                {
                    ai.AddressPersonalName = txtPersonalName.Text;
                    ai.AddressLine1        = txtAddressLine1.Text;
                    ai.AddressLine2        = txtAddressLine2.Text;
                    ai.AddressCity         = txtAddressCity.Text;
                    ai.AddressZip          = txtAddressZip.Text;
                    ai.AddressCountryID    = ucCountrySelector.CountryID;
                    ai.AddressStateID      = ucCountrySelector.StateID;
                    ai.AddressPhone        = txtAddressDeliveryPhone.Text;
                    ai.AddressName         = AddressInfoProvider.GetAddressName(ai);
                    // Save addressinfo
                    AddressInfoProvider.SetAddressInfo(ai);
                    AddressId = ai.AddressID;

                    lblInfo.Visible = true;
                    lblAddress.Text = "> " + HTMLHelper.HTMLEncode(ai.AddressName);
                }
            }
            else
            {
                lblError.Visible = true;
                lblError.Text    = errorMessage;
            }
        }
    }
Exemplo n.º 5
0
        /// <summary>
        /// Updates business unit for distributor
        /// </summary>
        /// <param name="distributorID">Distributor ID</param>
        public static void UpdateDistributorsBusinessUnit(int distributorID)
        {
            AddressInfo distributor        = AddressInfoProvider.GetAddressInfo(distributorID);
            long        businessUnitNumber = ValidationHelper.GetLong(Cart.GetValue("BusinessUnitIDForDistributor"), default(long));

            if (distributor != null && businessUnitNumber != default(long))
            {
                distributor.SetValue("BusinessUnit", businessUnitNumber);
                AddressInfoProvider.SetAddressInfo(distributor);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Saves the address into the database.
        /// </summary>
        /// <param name="validate">Specifies whether the validation should be performed.</param>
        public void Save(bool validate = true)
        {
            if (validate)
            {
                var result = Validate();
                if (result.CheckFailed)
                {
                    throw new InvalidOperationException();
                }
            }

            OriginalAddress.AddressName = AddressInfoProvider.GetAddressName(OriginalAddress);
            AddressInfoProvider.SetAddressInfo(OriginalAddress);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Creates new address for a particular customer
 /// </summary>
 /// <param name="customerID">Customer id of the logged in user</param>
 private void CreateNewAddress(int customerID)
 {
     try
     {
         var objAddress = BindAddressObject(customerID);
         if (!DataHelper.DataSourceIsEmpty(objAddress) && objAddress != null)
         {
             AddressInfoProvider.SetAddressInfo(objAddress);
             CreateAddressRelatedBrands(objAddress.AddressID);
         }
     }
     catch (Exception ex)
     {
         EventLogProvider.LogException("CreateAddress.ascx.cs", "CreateNewAddress()", ex);
     }
 }
Exemplo n.º 8
0
 /// <summary>
 ///  Updates the existing address data
 /// </summary>
 /// <param name="itemID">item id of the address data</param>
 private void UpdateAddressData(int customerID)
 {
     try
     {
         var addressObj = BindAddressObject(customerID);
         if (!DataHelper.DataSourceIsEmpty(addressObj) && addressObj != null)
         {
             AddressInfoProvider.SetAddressInfo(addressObj);
             CreateAddressRelatedBrands(addressObj.AddressID);
         }
     }
     catch (Exception ex)
     {
         EventLogProvider.LogException("CreateAddress.ascx.cs", "UpdateAddressData()", ex);
     }
 }
        private AddressInfo GenerateAddress(int countryId, int customerId)
        {
            var addressObj = new AddressInfo
            {
                AddressName         = "Address " + rand.Next(300),
                AddressLine1        = "Main street " + rand.Next(300),
                AddressCity         = "City " + rand.Next(300),
                AddressZip          = new string(Enumerable.Repeat("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", 8).Select(s => s[rand.Next(s.Length)]).ToArray()),
                AddressCountryID    = countryId,
                AddressCustomerID   = customerId,
                AddressPersonalName = "Home address"
            };

            AddressInfoProvider.SetAddressInfo(addressObj);
            return(addressObj);
        }
    private IAddress SaveAddress(IAddress addressObject, CustomerInfo customer)
    {
        AddressInfo address = addressObject as AddressInfo;

        if (address == null)
        {
            return(null);
        }

        if (string.IsNullOrEmpty(address.AddressPersonalName))
        {
            address.AddressPersonalName = TextHelper.LimitLength(string.Format("{0} {1}", customer.CustomerFirstName, customer.CustomerLastName), 200);
        }

        address.AddressCustomerID = customer.CustomerID;
        address.AddressName       = AddressInfoProvider.GetAddressName(address);
        AddressInfoProvider.SetAddressInfo(address);

        return(address);
    }
    private void SetAdresseShipping(string adresse1, string cp1, string ville1, int cuid, int pays)
    {
        // Create new address object
        AddressInfo newAddress = new AddressInfo();

        // Set the properties
        newAddress.AddressName         = adresse1 + " " + cp1 + " " + ville1;
        newAddress.AddressLine1        = adresse1 + " " + cp1 + " " + ville1;
        newAddress.AddressLine2        = " ";
        newAddress.AddressCity         = ville1;
        newAddress.AddressZip          = cp1;
        newAddress.AddressIsBilling    = false;
        newAddress.AddressIsShipping   = true;
        newAddress.AddressEnabled      = true;
        newAddress.AddressPersonalName = CurrentUser.FullName;
        newAddress.AddressCustomerID   = cuid;
        newAddress.AddressCountryID    = pays;

        // Create the address
        AddressInfoProvider.SetAddressInfo(newAddress);
    }
 /// <summary>
 /// Saves a customer's address into the database.
 /// </summary>
 /// <param name="address"><see cref="AddressInfo"/> object representing a customer's address that is inserted.</param>
 public void Upsert(AddressInfo address)
 {
     AddressInfoProvider.SetAddressInfo(address);
 }
    /// <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");
        }
    }
    /// <summary>
    /// OK click handler (Proceed registration).
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        System.Globalization.CultureInfo currentUI = System.Globalization.CultureInfo.CurrentUICulture;

        if ((PageManager.ViewMode == ViewModeEnum.Design) || (HideOnCurrentPage) || (!IsVisible))
        {
            // Do not process
        }
        else
        {
            String siteName = SiteContext.CurrentSiteName;

            #region "Banned IPs"

            // Ban IP addresses which are blocked for registration
            if (!BannedIPInfoProvider.IsAllowed(siteName, BanControlEnum.Registration))
            {
                lblError.Visible = true;
                lblError.Text    = GetString("banip.ipisbannedregistration");
                return;
            }

            #endregion

            #region "Pr�nom"

            if (string.IsNullOrEmpty(txtFirstName.Text) || (txtFirstName.Text.ToLower() == "firstname") || (txtFirstName.Text.ToLower() == "pr�nom") || (txtFirstName.Text.ToLower() == "prenom"))
            {
                lblError.Visible = true;
                lblError.Text    = GetString("errornom");
                return;
            }

            #endregion

            #region "Nom"

            if (string.IsNullOrEmpty(txtLastName.Text) || (txtLastName.Text.ToLower() == "nom") || (txtLastName.Text.ToLower() == "lastname"))
            {
                lblError.Visible = true;
                lblError.Text    = GetString("errorprenom");
                return;
            }

            #endregion

            #region "T�l�phone"

            if (string.IsNullOrEmpty(txtTelephone.Text) || (txtTelephone.Text.ToLower() == "telephone"))
            {
                lblError.Visible = true;
                lblError.Text    = GetString("errortelephone");
                return;
            }

            #endregion


            #region Soci�t�
            if (rboui.Checked)
            {
                if ((txtnomsociete.Text == "") || (txtnomsociete.Text == "Nom soci�t�") || (txtnomsociete.Text == "Company Name"))
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("errornomsociete ");
                    return;
                }

                //if ((txtTva.Text == "") || (txtTva.Text == "TVA") || (txtTva.Text == "VAT"))
                //{
                //    lblError.Visible = true;
                //    lblError.Text = GetString("errortva ");
                //    return;
                //}

                //if (!EUVatChecker.Check(txtTva.Text))
                //{
                //    lblError.Visible = true;
                //    lblError.Text = GetString("errortva2 ");
                //    return;
                //}
            }
            #endregion

            #region "Captcha"

            // Check if captcha is required
            if (DisplayCaptcha)
            {
                // Verifiy captcha text
                if (!scCaptcha.IsValid())
                {
                    // Display error message if catcha text is not valid
                    lblError.Visible = true;
                    lblError.Text    = GetString("Webparts_Membership_RegistrationForm.captchaError");
                    return;
                }
                else
                {
                    // Generate new captcha
                    scCaptcha.GenerateNew();
                }
            }

            #endregion


            // Set password
            //UserInfoProvider.SetPassword(ui, passStrength.Text);

            // UserInfoProvider.SetPassword(ui, txtPassword.Text.Trim());
            if (!CurrentUser.IsAuthenticated())
            {
                // Set password
                //    UserInfoProvider.SetPassword(ui, txtPassword.Text.Trim());
            }
            else
            {
                #region "Modif User"
                //Update User
                UserInfo updateUser = CurrentUser;
                updateUser.PreferredCultureCode = "";
                updateUser.FirstName            = txtFirstName.Text.Trim();
                updateUser.FullName             = UserInfoProvider.GetFullName(txtFirstName.Text.Trim(), String.Empty, txtLastName.Text.Trim());
                updateUser.LastName             = txtLastName.Text.Trim();
                updateUser.MiddleName           = "";

                if (payement_option.SelectedValue != "0")
                {
                    updateUser.SetValue("Civilite", payement_option.SelectedValue);
                }

                //updateUser.SetValue("Telephone", txtTelephone.Text);
                updateUser.SetValue("Telephone", txtTelephone.Text);

                /*if ((txtPassword.Text != "Mot de passe") && (txtPassword.Text != "Password"))
                 * {
                 *  UserInfoProvider.SetPassword(updateUser, txtPassword.Text);
                 *  //updateUser.SetValue("UserPassword",txtPassword.Text);
                 * }*/
                UserInfoProvider.SetUserInfo(updateUser);

                //Update Customer
                CustomerInfo updateCustomer = ECommerceContext.CurrentCustomer;
                updateCustomer.CustomerUserID    = updateUser.UserID;
                updateCustomer.CustomerLastName  = txtLastName.Text.Trim();
                updateCustomer.CustomerFirstName = txtFirstName.Text.Trim();
                updateCustomer.CustomerEmail     = txtEmail.Text.Trim();
                //add update phone
                updateCustomer.CustomerPhone          = txtTelephone.Text.Trim();
                updateCustomer.CustomerEnabled        = true;
                updateCustomer.CustomerLastModified   = DateTime.Now;
                updateCustomer.CustomerSiteID         = CMSContext.CurrentSiteID;
                updateCustomer.CustomerOrganizationID = "";
                if (rboui.Checked)
                {
                    updateCustomer.CustomerCompany           = txtnomsociete.Text.Trim();
                    updateCustomer.CustomerTaxRegistrationID = txtTva.Text;
                }
                else
                {
                    updateCustomer.CustomerCompany           = string.Empty;
                    updateCustomer.CustomerTaxRegistrationID = string.Empty;
                }

                if ((rboui.Checked) && (txtTva.Text.Trim() != "TVA") && (txtTva.Text.Trim() != "VAT"))
                {
                    updateCustomer.CustomerTaxRegistrationID = txtTva.Text;
                    updateCustomer.CustomerCompany           = txtnomsociete.Text.ToString();
                }
                else
                {
                    updateCustomer.CustomerTaxRegistrationID = "";
                    updateCustomer.CustomerCompany           = "";
                }

                CustomerInfoProvider.SetCustomerInfo(updateCustomer);
                #endregion

                #region "Insert new adress / Update selected adress"
                //if (chkNewAddress.Checked)
                //{
                #region "n�"

                if ((txtnumero.Text == "") || (txtnumero.Text == "Numero") || (txtnumero.Text == "Number"))
                {
                    lblErrorAdress.Visible = true;
                    lblErrorAdress.Text    = GetString("errornumerorue");
                    return;
                }

                #endregion

                #region "adresse 1"

                if ((txtadresse1.Text == "") || (txtadresse1.Text == "Adresse 1") || (txtadresse1.Text == "Address 1"))
                {
                    lblErrorAdress.Visible = true;
                    lblErrorAdress.Text    = GetString("erroradresse1");
                    return;
                }

                #endregion

                #region "adresse 2"

                if ((txtadresse2.Text == "") || (txtadresse2.Text == "Adresse 2") || (txtadresse2.Text == "Address 2"))
                {
                    lblErrorAdress.Visible = true;
                    lblErrorAdress.Text    = GetString("erroradresse2");
                    return;
                }

                #endregion

                #region "CP"

                if ((txtcp.Text == "") || (txtcp.Text == "CP") || (txtcp.Text == "ZIP"))
                {
                    lblErrorAdress.Visible = true;
                    lblErrorAdress.Text    = GetString("errorcp");
                    return;
                }

                #endregion

                #region "Ville"

                if ((txtville.Text == "") || (txtville.Text == "Ville") || (txtville.Text == "City"))
                {
                    lblErrorAdress.Visible = true;
                    lblErrorAdress.Text    = GetString("errorville");
                    return;
                }

                #endregion

                #region "Pays"

                if ((ddlShippingCountry.Text == "Choose your country") || (ddlShippingCountry.Text == "Choisissez votre pays"))
                {
                    lblErrorAdress.Visible = true;
                    lblErrorAdress.Text    = GetString("errorchoixpays ");
                    return;
                }

                #endregion

                #region "Adresse"

                if ((chkShippingAddr.Checked == false) && (chkBillingAddr.Checked == false))
                {
                    lblErrorAdress.Visible = true;
                    lblErrorAdress.Text    = GetString("erroradressechek");
                    return;
                }

                #endregion

                if (txtIdAdresse.Text == "")
                {
                    #region "New adress"

                    // Create new address object
                    AddressInfo newAddress = new AddressInfo();

                    int          CountryID = ValidationHelper.GetInteger(ddlShippingCountry.SelectedValue, 0);
                    CustomerInfo uc        = ECommerceContext.CurrentCustomer;
                    mCustomerId = uc.CustomerID;
                    string mCustomerName = uc.CustomerFirstName + " " + uc.CustomerLastName;
                    // Set the properties
                    newAddress.AddressName  = mCustomerName + " , " + txtnumero.Text + " " + txtadresse1.Text + " - " + txtcp.Text + " " + txtville.Text;
                    newAddress.AddressLine1 = txtadresse1.Text;
                    newAddress.AddressLine2 = txtadresse2.Text;
                    newAddress.AddressCity  = txtville.Text;
                    newAddress.AddressZip   = txtcp.Text;
                    if (chkBillingAddr.Checked)
                    {
                        newAddress.AddressIsBilling = true;
                    }
                    else
                    {
                        newAddress.AddressIsBilling = false;
                    }
                    if (chkShippingAddr.Checked)
                    {
                        newAddress.AddressIsShipping = true;
                    }
                    else
                    {
                        newAddress.AddressIsShipping = false;
                    }
                    newAddress.AddressEnabled      = true;
                    newAddress.AddressPersonalName = mCustomerName;
                    newAddress.AddressCustomerID   = mCustomerId;
                    newAddress.AddressCountryID    = CountryID;
                    newAddress.SetValue("AddressNumber", txtnumero.Text);

                    // Create the address
                    AddressInfoProvider.SetAddressInfo(newAddress);
                    txtnumero.Text   = string.Empty;
                    txtadresse1.Text = string.Empty;
                    txtadresse2.Text = string.Empty;
                    txtcp.Text       = string.Empty;
                    txtville.Text    = string.Empty;
                    // PnlInsertAdress.Visible = false;
                    if (newAddress != null && newAddress.AddressIsShipping == true)
                    {
                        Session["newAddress"] = newAddress.AddressID;
                        //EventLogProvider eve = new EventLogProvider();
                        //eve.LogEvent("I", DateTime.Now, "id new address= " + Session["newAddress"], "code");
                    }

                    #endregion
                }

                else
                {
                    #region "Update selected adress"

                    /*
                     *  // Udpate selected adress object
                     *  int CountryID = ValidationHelper.GetInteger(ddlShippingCountry.SelectedValue, 0);
                     *  int AddressId = Convert.ToInt32(txtIdAdresse.Text);
                     *  AddressInfo UpdateAdress = AddressInfoProvider.GetAddressInfo(AddressId);
                     *  CustomerInfo uc = ECommerceContext.CurrentCustomer;
                     *  mCustomerId = uc.CustomerID;
                     *  string mCustomerName = uc.CustomerFirstName + " " + uc.CustomerLastName;
                     *  // Set the properties
                     *  UpdateAdress.AddressName = mCustomerName + " , " + txtnumero.Text + " " + txtadresse1.Text + " - " + txtcp.Text + " " + txtville.Text;
                     *  UpdateAdress.SetValue("AddressNumber", txtnumero.Text);
                     *  UpdateAdress.AddressLine1 = txtadresse1.Text;
                     *  UpdateAdress.AddressLine2 = txtadresse2.Text;
                     *  UpdateAdress.AddressCity = txtville.Text;
                     *  UpdateAdress.AddressZip = txtcp.Text;
                     *  UpdateAdress.AddressIsBilling = chkBillingAddr.Checked;
                     *  UpdateAdress.AddressIsShipping = chkShippingAddr.Checked;
                     *  UpdateAdress.AddressEnabled = true;
                     *  UpdateAdress.AddressPersonalName = mCustomerName;
                     *  UpdateAdress.AddressCustomerID = mCustomerId;
                     *  UpdateAdress.AddressCountryID = CountryID;
                     *
                     *  // Save addressinfo
                     *  AddressInfoProvider.SetAddressInfo(UpdateAdress);
                     *  AddressId = UpdateAdress.AddressID;
                     */
                    #endregion
                }

                ReloadDataAdress();

                //}
                #endregion
            }

            lblError.Visible = false;
            // PnlInsertAdress.Visible = false;
        }
    }
    /// <summary>
    /// Process valid values of this step.
    /// </summary>
    public override bool ProcessStep()
    {
        if (mCustomerId > 0)
        {
            // Clean the viewstate
            RemoveBillingTempValues();
            RemoveShippingTempValues();
            RemoveCompanyTempValues();

            // Check country presence
            if (CountrySelector1.CountryID <= 0)
            {
                lblError.Visible = true;
                lblError.Text    = GetString("countryselector.selectedcountryerr");
                return(false);
            }

            if (!CountrySelector1.StateSelectionIsValid)
            {
                lblError.Visible = true;
                lblError.Text    = GetString("countryselector.selectedstateerr");
                return(false);
            }

            // Process billing address
            //------------------------
            var ai = AddressInfoProvider.GetAddressInfo(ValidationHelper.GetInteger(drpBillingAddr.SelectedValue, 0)) ?? new AddressInfo();
            ai.AddressPersonalName = GetTruncatedTextBoxInput(txtBillingName);
            ai.AddressLine1        = GetTruncatedTextBoxInput(txtBillingAddr1);
            ai.AddressLine2        = GetTruncatedTextBoxInput(txtBillingAddr2);
            ai.AddressCity         = GetTruncatedTextBoxInput(txtBillingCity);
            ai.AddressZip          = GetTruncatedTextBoxInput(txtBillingZip);
            ai.AddressCountryID    = CountrySelector1.CountryID;
            ai.AddressStateID      = CountrySelector1.StateID;
            ai.AddressPhone        = GetTruncatedTextBoxInput(txtBillingPhone);
            ai.AddressCustomerID   = mCustomerId;
            ai.AddressName         = AddressInfoProvider.GetAddressName(ai);

            // Save address and set it's ID to ShoppingCartInfoObj
            AddressInfoProvider.SetAddressInfo(ai);

            // Update current contact's address
            MapContactAddress(ai);

            ShoppingCart.ShoppingCartBillingAddress = ai;

            // If shopping cart does not need shipping
            if (!ShoppingCart.IsShippingNeeded)
            {
                ShoppingCart.ShoppingCartShippingAddress = null;
            }
            // If shipping address is different from billing address
            else if (chkShippingAddr.Checked)
            {
                // Check country presence
                if (CountrySelector2.CountryID <= 0)
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("countryselector.selectedcountryerr");
                    return(false);
                }

                if (!CountrySelector2.StateSelectionIsValid)
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("countryselector.selectedstateerr");
                    return(false);
                }

                // Process shipping address
                //-------------------------
                ai = AddressInfoProvider.GetAddressInfo(Convert.ToInt32(drpShippingAddr.SelectedValue)) ?? new AddressInfo();
                ai.AddressPersonalName = GetTruncatedTextBoxInput(txtShippingName);
                ai.AddressLine1        = GetTruncatedTextBoxInput(txtShippingAddr1);
                ai.AddressLine2        = GetTruncatedTextBoxInput(txtShippingAddr2);
                ai.AddressCity         = GetTruncatedTextBoxInput(txtShippingCity);
                ai.AddressZip          = GetTruncatedTextBoxInput(txtShippingZip);
                ai.AddressCountryID    = CountrySelector2.CountryID;
                ai.AddressStateID      = CountrySelector2.StateID;
                ai.AddressPhone        = GetTruncatedTextBoxInput(txtShippingPhone);
                ai.AddressCustomerID   = mCustomerId;
                ai.AddressName         = AddressInfoProvider.GetAddressName(ai);

                // Save address and set it's ID to ShoppingCartInfoObj
                AddressInfoProvider.SetAddressInfo(ai);
                ShoppingCart.ShoppingCartShippingAddress = ai;
            }
            // Shipping address is the same as billing address
            else
            {
                ShoppingCart.ShoppingCartShippingAddress = ShoppingCart.ShoppingCartBillingAddress;
            }

            if (chkCompanyAddress.Checked)
            {
                // Check country presence
                if (CountrySelector3.CountryID <= 0)
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("countryselector.selectedcountryerr");
                    return(false);
                }

                if (!CountrySelector3.StateSelectionIsValid)
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("countryselector.selectedstateerr");
                    return(false);
                }

                // Process company address
                //-------------------------
                ai = AddressInfoProvider.GetAddressInfo(Convert.ToInt32(drpCompanyAddress.SelectedValue)) ?? new AddressInfo();
                ai.AddressPersonalName = GetTruncatedTextBoxInput(txtCompanyName);
                ai.AddressLine1        = GetTruncatedTextBoxInput(txtCompanyLine1);
                ai.AddressLine2        = GetTruncatedTextBoxInput(txtCompanyLine2);
                ai.AddressCity         = GetTruncatedTextBoxInput(txtCompanyCity);
                ai.AddressZip          = GetTruncatedTextBoxInput(txtCompanyZip);
                ai.AddressCountryID    = CountrySelector3.CountryID;
                ai.AddressStateID      = CountrySelector3.StateID;
                ai.AddressPhone        = GetTruncatedTextBoxInput(txtCompanyPhone);
                ai.AddressCustomerID   = mCustomerId;
                ai.AddressName         = AddressInfoProvider.GetAddressName(ai);

                // Save address and set it's ID to ShoppingCartInfoObj
                AddressInfoProvider.SetAddressInfo(ai);
                ShoppingCart.ShoppingCartCompanyAddress = ai;
            }
            // Company address is the same as billing address
            else
            {
                // Save information about company address or not (according to the site settings)
                if (ECommerceSettings.UseExtraCompanyAddress(mCurrentSite.SiteName))
                {
                    ShoppingCart.ShoppingCartCompanyAddress = ShoppingCart.ShoppingCartBillingAddress;
                }
                else
                {
                    ShoppingCart.ShoppingCartCompanyAddress = null;
                }
            }

            try
            {
                ShoppingCart.Evaluate();

                // Update changes in database only when on the live site
                if (!ShoppingCartControl.IsInternalOrder)
                {
                    ShoppingCartInfoProvider.SetShoppingCartInfo(ShoppingCart);
                }
                return(true);
            }
            catch (Exception ex)
            {
                // Show error message
                lblError.Visible = true;
                lblError.Text    = ex.Message;
                return(false);
            }
        }
        else
        {
            lblError.Visible = true;
            lblError.Text    = GetString("Ecommerce.NoCustomerSelected");
            return(false);
        }
    }
Exemplo n.º 16
0
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Check 'EcommerceModify' permission
        if (!ECommerceContext.IsUserAuthorizedForPermission("ModifyCustomers"))
        {
            RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyCustomers");
        }

        if (customerId != 0)
        {
            string errorMessage = new Validator().NotEmpty(txtAddressLine1.Text, "Customer_Edit_Address_Edit.rqvLine").NotEmpty(txtAddressCity.Text, "Customer_Edit_Address_Edit.rqvCity").NotEmpty(txtAddressZip.Text, "Customer_Edit_Address_Edit.rqvZipCode").NotEmpty(txtPersonalName.Text, "Customer_Edit_Address_Edit.rqvPersonalName").Result;

            // Check country presence
            if ((errorMessage == "") && (ucCountrySelector.CountryID <= 0))
            {
                errorMessage = GetString("countryselector.selectedcountryerr");
            }

            if ((errorMessage == "") && !ucCountrySelector.StateSelectionIsValid)
            {
                errorMessage = GetString("countryselector.selectedstateerr");
            }

            if (errorMessage == "")
            {
                AddressInfo addressObj = AddressInfoProvider.GetAddressInfo(addressId);

                // if address doesn't already exist, create new one
                if (addressObj == null)
                {
                    addressObj = new AddressInfo();
                    addressObj.AddressIsShipping = false;
                    addressObj.AddressIsBilling  = false;
                    addressObj.AddressIsCompany  = false;
                }

                switch (typeId)
                {
                // Shipping addres selection
                case 0:
                    addressObj.AddressIsShipping = true;
                    break;

                // Billing addres selection
                case 1:
                    addressObj.AddressIsBilling = true;
                    break;

                // Company addres selection
                case 2:
                    addressObj.AddressIsCompany = true;
                    break;

                default:
                    break;
                }

                // Set address object data
                addressObj.AddressZip          = txtAddressZip.Text.Trim();
                addressObj.AddressPhone        = txtAddressDeliveryPhone.Text.Trim();
                addressObj.AddressPersonalName = txtPersonalName.Text.Trim();
                addressObj.AddressLine1        = txtAddressLine1.Text.Trim();
                addressObj.AddressEnabled      = chkAddressEnabled.Checked;
                addressObj.AddressLine2        = txtAddressLine2.Text.Trim();
                addressObj.AddressCity         = txtAddressCity.Text.Trim();
                addressObj.AddressCountryID    = ucCountrySelector.CountryID;
                addressObj.AddressStateID      = ucCountrySelector.StateID;
                addressObj.AddressCustomerID   = customerId;
                addressObj.AddressName         = AddressInfoProvider.GetAddressName(addressObj);
                addressObj.SetValue("AddressNumber", txtnum.Text);

                AddressInfoProvider.SetAddressInfo(addressObj);

                ltlScript.Text = ScriptHelper.GetScript("if(wopener.AddressChange!=null){wopener.AddressChange('" + addressObj.AddressID + "');}CloseDialog();");
            }
            else
            {
                // Show error message
                ShowError(errorMessage);
            }
        }
    }
 /// <summary>
 /// Saves a customer's address into the database.
 /// </summary>
 /// <param name="address"><see cref="CustomerAddress"/> object representing a customer's address that is inserted.</param>
 public void Upsert(CustomerAddress address)
 {
     AddressInfoProvider.SetAddressInfo(address.OriginalAddress);
 }
Exemplo n.º 18
0
    /// <summary>
    /// Sets data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (customerObj == null)
        {
            return;
        }

        if (!ECommerceContext.IsUserAuthorizedToModifyCustomer())
        {
            RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyCustomers");
        }

        if (customerId != 0)
        {
            string errorMessage = new Validator().NotEmpty(txtAddressLine1.Text, "Customer_Edit_Address_Edit.rqvLine")
                                  .NotEmpty(txtAddressCity.Text, "Customer_Edit_Address_Edit.rqvCity")
                                  .NotEmpty(txtAddressZip.Text, "Customer_Edit_Address_Edit.rqvZipCode")
                                  .NotEmpty(txtPersonalName.Text, "Customer_Edit_Address_Edit.rqvPersonalName").Result;

            // Check country presence
            if (errorMessage == "" && (ucCountrySelector.CountryID <= 0))
            {
                errorMessage = GetString("countryselector.selectedcountryerr");
            }
            if (errorMessage == "" && (!string.IsNullOrEmpty(txtnum.Text)))
            {
                int result;
                if (int.TryParse(txtnum.Text, out result))
                {
                    //ok, do something
                }
                else
                {
                    errorMessage = "Number is not valid";
                }
            }
            if (errorMessage == "")
            {
                // Get object
                AddressInfo addressObj = AddressInfoProvider.GetAddressInfo(addressId);
                if (addressObj == null)
                {
                    addressObj = new AddressInfo();
                }

                // Set address object data
                addressObj.AddressIsBilling    = chkAddressIsBilling.Checked;
                addressObj.AddressIsShipping   = chkAddressIsShipping.Checked;
                addressObj.AddressZip          = txtAddressZip.Text.Trim();
                addressObj.AddressPhone        = txtAddressDeliveryPhone.Text.Trim();
                addressObj.AddressPersonalName = txtPersonalName.Text.Trim();
                addressObj.AddressLine1        = txtAddressLine1.Text.Trim();
                addressObj.AddressEnabled      = chkAddressEnabled.Checked;
                addressObj.AddressLine2        = txtAddressLine2.Text.Trim();
                addressObj.AddressCity         = txtAddressCity.Text.Trim();
                addressObj.AddressCountryID    = ucCountrySelector.CountryID;
                addressObj.AddressStateID      = ucCountrySelector.StateID;
                addressObj.AddressIsCompany    = chkAddressIsCompany.Checked;
                addressObj.AddressName         = AddressInfoProvider.GetAddressName(addressObj);
                addressObj.AddressCustomerID   = customerId;
                addressObj.SetValue("AddressNumber", txtnum.Text);

                AddressInfoProvider.SetAddressInfo(addressObj);

                // Redirect to editing UI
                URLHelper.Redirect("Customer_Edit_Address_Edit.aspx?customerId=" + customerId + "&addressId=" + Convert.ToString(addressObj.AddressID) + "&saved=1");
            }
            else
            {
                // Show error message
                ShowError(errorMessage);
            }
        }
    }
    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();
        }
    }
    public override bool ProcessStep()
    {
        string siteName = SiteContext.CurrentSiteName;

        if (IsExistingAccount())
        {
            // Sign in customer with existing account

            // Authenticate user
            //UserInfo ui = UserInfoProvider.GetUserInfo(txtLogin.Text);

            UserInfo ui = AuthenticationHelper.AuthenticateUser(txtLogin.Text.Trim(), txtMotDePasse.Text, SiteContext.CurrentSiteName);

            if (ui == null)
            {
                // ShowError(ResHelper.GetString("ShoppingCartCheckRegistration.LoginFailed"));
                return(false);
            }

            // Set current user
            MembershipContext.AuthenticatedUser = new CurrentUserInfo(ui, true);
            UserInfoProvider.SetPreferredCultures(ui);

            // Sign in
            FormsAuthentication.SetAuthCookie(ui.UserName, false);

            // Registered user has already started shopping as anonymous user -> Drop his stored shopping cart
            ShoppingCartInfoProvider.DeleteShoppingCartInfo(ui.UserID, siteName);

            // Assign current user to the current shopping cart
            ShoppingCart.User = ui;

            // Save changes to database // Already done in the end of this method
            if (!this.ShoppingCartControl.IsInternalOrder)
            {
                ShoppingCartInfoProvider.SetShoppingCartInfo(this.ShoppingCartInfObj);
            }

            //Create a customer for the user if do not yet exist
            CustomerInfo ci = CustomerInfoProvider.GetCustomerInfoByUserID(this.ShoppingCartControl.UserInfo.UserID);
            if (ci == null)
            {
                ci = new CustomerInfo();
                ci.CustomerUserID  = this.ShoppingCartControl.UserInfo.UserID;
                ci.CustomerEnabled = true;
            }

            // Old email address
            //string oldEmail = ci.CustomerEmail.ToLower(); ;

            ci.CustomerFirstName = ui.FirstName;
            ci.CustomerLastName  = ui.LastName;
            ci.CustomerEmail     = ui.Email;

            ci.CustomerCompany           = "";
            ci.CustomerOrganizationID    = "";
            ci.CustomerTaxRegistrationID = "";

            // Update customer data
            CustomerInfoProvider.SetCustomerInfo(ci);

            // Set the shopping cart customer ID
            this.ShoppingCart.ShoppingCartCustomerID = ci.CustomerID;
        }
        else if (IsNewAccount())
        {
            txtEmail2.Text             = txtEmail2.Text.Trim();
            pnlCompanyAccount1.Visible = chkCorporateBody.Checked;

            // Check if user exists
            UserInfo ui = UserInfoProvider.GetUserInfo(txtEmail2.Text);
            if (ui != null)
            {
                lblError.Visible = true;
                lblError.Text    = GetString("ShoppingCartUserRegistration.ErrorUserExists");
                return(false);
            }

            // Check all sites where user will be assigned
            string checkSites = (String.IsNullOrEmpty(ShoppingCartControl.AssignToSites)) ? SiteContext.CurrentSiteName : ShoppingCartControl.AssignToSites;
            if (!UserInfoProvider.IsEmailUnique(txtEmail2.Text.Trim(), checkSites, 0))
            {
                lblError.Visible = true;
                lblError.Text    = GetString("UserInfo.EmailAlreadyExist");
                return(false);
            }

            // Create new customer and user account and sign in
            // User



            ui = new UserInfo();


            ui.UserName  = txtEmailRegistration.Text.Trim();
            ui.Email     = txtEmailRegistration.Text.Trim();
            ui.FirstName = txtFirstName.Text.Trim();
            ui.FullName  = UserInfoProvider.GetFullName(txtFirstName.Text.Trim(), String.Empty, txtLastName.Text.Trim());
            ui.LastName  = txtLastName.Text.Trim();
            ui.Enabled   = true;
            ui.UserIsGlobalAdministrator = false;
            ui.UserURLReferrer           = MembershipContext.AuthenticatedUser.URLReferrer;
            ui.UserCampaign = AnalyticsHelper.Campaign;
            ui.UserSettings.UserRegistrationInfo.IPAddress = RequestContext.UserHostAddress;
            ui.UserSettings.UserRegistrationInfo.Agent     = HttpContext.Current.Request.UserAgent;

            try
            {
                UserInfoProvider.SetPassword(ui, txtMotDePasseRegistration.Text);

                string[] siteList;

                // If AssignToSites field set
                if (!String.IsNullOrEmpty(ShoppingCartControl.AssignToSites))
                {
                    siteList = ShoppingCartControl.AssignToSites.Split(';');
                }
                else // If not set user current site
                {
                    siteList = new string[] { siteName };
                }

                foreach (string site in siteList)
                {
                    UserInfoProvider.AddUserToSite(ui.UserName, site);

                    // Add user to roles
                    if (ShoppingCartControl.AssignToRoles != "")
                    {
                        AssignUserToRoles(ui.UserName, ShoppingCartControl.AssignToRoles, site);
                    }
                }

                // Log registered user
                AnalyticsHelper.LogRegisteredUser(siteName, ui);

                Activity activity = new ActivityRegistration(ui, DocumentContext.CurrentDocument, AnalyticsContext.ActivityEnvironmentVariables);
                if (activity.Data != null)
                {
                    activity.Data.ContactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui);
                    activity.Log();
                }
            }
            catch (Exception ex)
            {
                lblError.Visible = true;
                lblError.Text    = ex.Message;
                return(false);
            }

            // Customer
            CustomerInfo ci = new CustomerInfo();
            ci.CustomerFirstName = txtFirstName.Text.Trim();
            ci.CustomerLastName  = txtLastName.Text.Trim();
            ci.CustomerEmail     = txtEmailRegistration.Text.Trim();

            ci.CustomerCompany           = "";
            ci.CustomerOrganizationID    = "";
            ci.CustomerTaxRegistrationID = "";
            if (chkCorporateBody.Checked)
            {
                ci.CustomerCompany = txtCompany1.Text.Trim();
                if (mShowOrganizationIDField)
                {
                    ci.CustomerOrganizationID = txtOrganizationID.Text.Trim();
                }
                if (mShowTaxRegistrationIDField)
                {
                    ci.CustomerTaxRegistrationID = txtTaxRegistrationID.Text.Trim();
                }
            }

            ci.CustomerUserID  = ui.UserID;
            ci.CustomerSiteID  = 0;
            ci.CustomerEnabled = true;
            ci.CustomerCreated = DateTime.Now;
            CustomerInfoProvider.SetCustomerInfo(ci);

            // Track successful registration conversion
            string name = ShoppingCartControl.RegistrationTrackConversionName;
            ECommerceHelper.TrackRegistrationConversion(ShoppingCart.SiteName, name);

            // Log "customer registration" activity and update profile
            var activityCustomerRegistration = new ActivityCustomerRegistration(ci, MembershipContext.AuthenticatedUser, AnalyticsContext.ActivityEnvironmentVariables);
            if (activityCustomerRegistration.Data != null)
            {
                if (ContactID <= 0)
                {
                    activityCustomerRegistration.Data.ContactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui);
                }
                activityCustomerRegistration.Log();
            }

            // Sign in
            if (ui.UserEnabled)
            {
                CMSContext.AuthenticateUser(ui.UserName, false);
                ShoppingCart.User = ui;

                ContactID = ModuleCommands.OnlineMarketingGetUserLoginContactID(ui);
                Activity activity = new ActivityUserLogin(ContactID, ui, DocumentContext.CurrentDocument, AnalyticsContext.ActivityEnvironmentVariables);
                activity.Log();
            }

            ShoppingCart.ShoppingCartCustomerID = ci.CustomerID;

            // Send new registration notification email
            if (ShoppingCartControl.SendNewRegistrationNotificationToAddress != "")
            {
                SendRegistrationNotification(ui);
            }
            /**aadrresse*/
            // Process billing address
            //------------------------
            int         CountryID  = ValidationHelper.GetInteger(ddlShippingCountry.SelectedValue, 0);
            AddressInfo ai         = null;
            bool        newAddress = true;
            ai = new AddressInfo();
            string mCustomerName = ci.CustomerFirstName + " " + ci.CustomerLastName;
            // newAddress.AddressName = mCustomerName + " , " + txtAdresse.Text + " - " + txtCodePostale.Text + " " + txtVille.Text;


            ai.AddressPersonalName = mCustomerName + " , " + txtAdresse.Text + " - " + txtCodePostale.Text + " " + txtVille.Text;
            ai.AddressLine1        = txtAdresse.Text.Trim();
            ai.AddressLine2        = txtAdresse.Text.Trim();
            ai.AddressCity         = txtVille.Text.Trim();
            ai.AddressZip          = txtCodePostale.Text.Trim();
            ai.AddressCountryID    = CountryID;


            if (newAddress)
            {
                ai.AddressIsBilling  = true;
                ai.AddressIsShipping = !chkShippingAddr.Checked;
                ai.AddressEnabled    = true;
            }
            ai.AddressCustomerID = ci.CustomerID;
            ai.AddressName       = AddressInfoProvider.GetAddressName(ai);

            // Save address and set it's ID to ShoppingCartInfoObj
            AddressInfoProvider.SetAddressInfo(ai);

            // Update current contact's address
            ModuleCommands.OnlineMarketingMapAddress(ai, ContactID);

            ShoppingCart.ShoppingCartBillingAddressID = ai.AddressID;

            // If shopping cart does not need shipping
            if (!ShippingOptionInfoProvider.IsShippingNeeded(ShoppingCart))
            {
                ShoppingCart.ShoppingCartShippingAddressID = 0;
            }
            // If shipping address is different from billing address
            else if (chkShippingAddr.Checked)
            {
                //// Check country presence
                //if (CountrySelector2.CountryID <= 0)
                //{
                //    lblError.Visible = true;
                //    lblError.Text = GetString("countryselector.selectedcountryerr");
                //    return false;
                //}

                //if (!CountrySelector2.StateSelectionIsValid)
                //{
                //    lblError.Visible = true;
                //    lblError.Text = GetString("countryselector.selectedstateerr");
                //    return false;
                //}

                //newAddress = false;
                //// Process shipping address
                ////-------------------------
                //ai = AddressInfoProvider.GetAddressInfo(Convert.ToInt32(drpShippingAddr.SelectedValue));
                //if (ai == null)
                //{
                //    ai = new AddressInfo();
                //    newAddress = true;
                //}

                ai.AddressPersonalName = txtadresseshipping.Text.Trim();
                ai.AddressLine1        = txtadresseshipping.Text.Trim();
                ai.AddressLine2        = txtadresseshipping.Text.Trim();
                ai.AddressCity         = txtvilleshipping.Text.Trim();
                ai.AddressZip          = txtcpshipping.Text.Trim();
                ai.AddressCountryID    = CountryID;

                if (newAddress)
                {
                    ai.AddressIsShipping = true;
                    ai.AddressEnabled    = true;
                    ai.AddressIsBilling  = false;
                    ai.AddressIsCompany  = false;
                    ai.AddressEnabled    = true;
                }
                ai.AddressCustomerID = ci.CustomerID;
                ai.AddressName       = AddressInfoProvider.GetAddressName(ai);

                // Save address and set it's ID to ShoppingCartInfoObj
                AddressInfoProvider.SetAddressInfo(ai);
                ShoppingCart.ShoppingCartShippingAddressID = ai.AddressID;
            }
            // Shipping address is the same as billing address
            else
            {
                ShoppingCart.ShoppingCartShippingAddressID = ShoppingCart.ShoppingCartBillingAddressID;
            }
            /**finadrress*/
            this.ShoppingCartControl.ButtonNextClickAction();
        }

        try
        {
            if (!this.ShoppingCartControl.IsInternalOrder)
            {
                ShoppingCartInfoProvider.SetShoppingCartInfo(this.ShoppingCart);
            }
            return(true);
        }
        catch
        {
            return(false);
        }
    }
Exemplo n.º 21
0
    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);
    }