/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { // Check module permissions if (!ECommerceContext.IsUserAuthorizedToModifyCustomer()) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyCustomers"); } string errorMessage = ""; if ((txtCustomerCompany.Text.Trim() == "") && ((txtCustomerFirstName.Text.Trim() == "") || (txtCustomerLastName.Text.Trim() == ""))) { errorMessage = GetString("Customers_Edit.errorInsert"); } else if (ECommerceSettings.RequireCompanyInfo(CMSContext.CurrentSite.SiteName) && (txtCustomerCompany.Text.Trim() != "" || txtOraganizationID.Text.Trim() != "" || txtTaxRegistrationID.Text.Trim() != "")) { errorMessage = new Validator().NotEmpty(txtCustomerCompany.Text.Trim(), GetString("customers_edit.errorcompany")) .NotEmpty(txtOraganizationID.Text.Trim(), GetString("customers_edit.errororganizationid")) .NotEmpty(txtTaxRegistrationID.Text.Trim(), GetString("customers_edit.errortaxregid")).Result; } else if ((txtCustomerEmail.Text.Trim() != "") && !ValidationHelper.IsEmail(txtCustomerEmail.Text)) { errorMessage = GetString("Customers_Edit.errorEmail"); } if (chkHasLogin.Checked) { if (errorMessage == "") { errorMessage = new Validator().NotEmpty(txtUserName.Text.Trim(), GetString("Customer_Edit_Login_Edit.rqvUserName")) .NotEmpty(passStrength.Text, GetString("Customer_Edit_Login_Edit.rqvPassword1")) .NotEmpty(txtPassword2.Text, GetString("Customer_Edit_Login_Edit.rqvPassword2")).Result; } if ((errorMessage == "") && (passStrength.Text != txtPassword2.Text)) { errorMessage = GetString("Customer_Edit_Login_Edit.DifferentPasswords"); } // Check policy if ((errorMessage == "") && !passStrength.IsValid()) { errorMessage = UserInfoProvider.GetPolicyViolationMessage(CMSContext.CurrentSiteName); } // Check if user name is unique if (errorMessage == "") { UserInfo existingUser = UserInfoProvider.GetUserInfo(txtUserName.Text.Trim()); if (existingUser != null) { errorMessage = GetString("Customer_Edit_Login_Edit.UserExist"); } } } if (errorMessage == "") { CustomerInfo customerObj = CustomerInfoProvider.GetCustomerInfo(customerid); // If customer does not already exist, create new one if (customerObj == null) { customerObj = new CustomerInfo(); customerObj.CustomerSiteID = currentSiteId; customerObj.CustomerEnabled = true; } customerObj.CustomerEmail = txtCustomerEmail.Text.Trim(); customerObj.CustomerFax = txtCustomerFax.Text.Trim(); customerObj.CustomerLastName = txtCustomerLastName.Text.Trim(); customerObj.CustomerPhone = txtCustomerPhone.Text.Trim(); customerObj.CustomerFirstName = txtCustomerFirstName.Text.Trim(); customerObj.CustomerCompany = txtCustomerCompany.Text.Trim(); customerObj.CustomerCountryID = drpCountry.CountryID; customerObj.CustomerStateID = drpCountry.StateID; customerObj.CustomerOrganizationID = txtOraganizationID.Text.Trim(); customerObj.CustomerTaxRegistrationID = txtTaxRegistrationID.Text.Trim(); // Set customer's preferences customerObj.CustomerPreferredCurrencyID = drpCurrency.CurrencyID; customerObj.CustomerPreferredPaymentOptionID = drpPayment.PaymentID; customerObj.CustomerPreferredShippingOptionID = drpShipping.ShippingID; if (plcDiscounts.Visible && plcGlobalDiscount.Visible) { customerObj.CustomerDiscountLevelID = drpGlobalDiscountLevel.DiscountLevel; } // Only registered customer can be enabled/diabled if (customerObj.CustomerIsRegistered) { customerObj.CustomerEnabled = chkCustomerEnabled.Checked; } bool refreshHeader = true; using (CMSTransactionScope tr = new CMSTransactionScope()) { // Create user for customer if (chkHasLogin.Checked) { UserInfo ui = new UserInfo(); ui.UserName = txtUserName.Text.Trim(); ui.FullName = customerObj.CustomerFirstName + " " + customerObj.CustomerLastName; ui.IsGlobalAdministrator = false; ui.UserEnabled = true; UserInfoProvider.SetPassword(ui, passStrength.Text); UserInfoProvider.AddUserToSite(ui.UserName, CMSContext.CurrentSiteName); customerObj.CustomerEnabled = true; customerObj.CustomerUserID = ui.UserID; refreshHeader = true; } // Save customer CustomerInfoProvider.SetCustomerInfo(customerObj); // Enable/disable coresponding registered user if (customerObj.CustomerIsRegistered && !chkHasLogin.Checked) { UserInfo ui = UserInfoProvider.GetUserInfo(customerObj.CustomerUserID); // If the customer already has the record in the CMS_User table, update email if (ui != null) { ui.Email = customerObj.CustomerEmail; UserInfoProvider.SetUserInfo(ui); } // Save site specific values UserSiteInfo userSite = UserSiteInfoProvider.GetUserSiteInfo(customerObj.CustomerUserID, CMSContext.CurrentSiteID); if (userSite != null) { userSite.UserPreferredCurrencyID = drpCurrency.CurrencyID; userSite.UserPreferredPaymentOptionID = drpPayment.PaymentID; userSite.UserPreferredShippingOptionID = drpShipping.ShippingID; userSite.UserDiscountLevelID = drpDiscountLevel.DiscountLevel; UserSiteInfoProvider.SetUserSiteInfo(userSite); } } // Commit transaction tr.Commit(); } URLHelper.Redirect("Customer_Edit_General.aspx?customerid=" + Convert.ToString(customerObj.CustomerID) + "&saved=1&hidebreadcrumbs=" + QueryHelper.GetInteger("hidebreadcrumbs", 0) + "&siteId=" + SiteID + (refreshHeader ? "&refreshHeader=1" : "")); } else { lblError.Visible = true; lblError.Text = errorMessage; } }
/// <summary> /// On page load. /// </summary> protected void Page_Load(object sender, EventArgs e) { ScriptHelper.RegisterClientScriptBlock(this, this.GetType(), "showHide", ScriptHelper.GetScript(@" /* Shows and hides tables with forms*/ function showHideForm(obj, rad) { var tblSignInStat = ''; var tblRegistrationStat = ''; var tblAnonymousStat = ''; if( obj != null && obj != '' && rad != null) { switch(obj) { case 'tblSignIn': tblSignInStat = ''; tblRegistrationStat = 'none'; tblAnonymousStat = 'none'; break; case 'tblRegistration': tblSignInStat = 'none'; tblRegistrationStat = ''; tblAnonymousStat = 'none'; break; case 'tblAnonymous': tblSignInStat = 'none'; tblRegistrationStat = 'none'; tblAnonymousStat = ''; break; } if(document.getElementById('tblSignIn') != null) document.getElementById('tblSignIn').style.display = tblSignInStat; if(document.getElementById('tblRegistration') != null) document.getElementById('tblRegistration').style.display = tblRegistrationStat; if(document.getElementById('tblAnonymous') != null) document.getElementById('tblAnonymous').style.display = tblAnonymousStat; if(document.getElementById(rad) != null) document.getElementById(rad).setAttribute('checked','true'); } } function showElem(id) { style = document.getElementById(id).style; style.display = (style.display == 'block')?'none':'block'; return false; } function showHideChk(id) { var elem = document.getElementById(id); if(elem.style.display == 'block') { elem.style.display = 'none'; } else { elem.style.display = 'block'; } }")); SiteInfo si = CMSContext.CurrentSite; if (si != null) { this.mRequireOrgTaxRegIDs = ECommerceSettings.RequireCompanyInfo(si.SiteName); this.mShowOrganizationIDField = ECommerceSettings.ShowOrganizationID(si.SiteName); this.mShowTaxRegistrationIDField = ECommerceSettings.ShowTaxRegistrationID(si.SiteName); } this.PreRender += new EventHandler(CMSEcommerce_ShoppingCartCheckRegistration_PreRender); InitializeLabels(); LoadStep(false); // Initialize onclick events radSignIn.Attributes.Add("onclick", "showHideForm('tblSignIn','" + radSignIn.ClientID + "');"); radNewReg.Attributes.Add("onclick", "showHideForm('tblRegistration','" + radNewReg.ClientID + "');"); radAnonymous.Attributes.Add("onclick", "showHideForm('tblAnonymous','" + radAnonymous.ClientID + "');"); lnkPasswdRetrieval.Attributes.Add("onclick", "return showElem('" + pnlPasswdRetrieval.ClientID + "');"); //chkCorporateBody.Attributes.Add("onclick", "showHideChk('" + pnlCompanyAccount1.ClientID + "');"); //chkEditCorpBody.Attributes.Add("onclick", "showHideChk('" + pnlCompanyAccount2.ClientID + "');"); }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { string errorMessage = ""; string siteName = SiteContext.CurrentSiteName; if ((txtCustomerCompany.Text.Trim() == "" || !IsBusiness) && ((txtCustomerFirstName.Text.Trim() == "") || (txtCustomerLastName.Text.Trim() == ""))) { errorMessage = GetString("Customers_Edit.errorInsert"); } // At least company name has to be filled when company account is selected if (errorMessage == "" && IsBusiness) { errorMessage = new Validator().NotEmpty(txtCustomerCompany.Text, GetString("customers_edit.errorCompany")).Result; } // Check the following items if complete company info is required for company account if (errorMessage == "" && ECommerceSettings.RequireCompanyInfo(siteName) && IsBusiness) { errorMessage = new Validator().NotEmpty(txtOraganizationID.Text, GetString("customers_edit.errorOrganizationID")) .NotEmpty(txtTaxRegistrationID.Text, GetString("customers_edit.errorTaxRegID")).Result; } if (errorMessage == "") { errorMessage = new Validator().IsEmail(txtCustomerEmail.Text.Trim(), GetString("customers_edit.erroremailformat"), true) .MatchesCondition(txtCustomerPhone.Text.Trim(), k => k.Length < 50, GetString("customers_edit.errorphoneformat")).Result; } plcCompanyInfo.Visible = IsBusiness; if (errorMessage == "") { // If customer doesn't already exist, create new one if (mCustomer == null) { mCustomer = new CustomerInfo(); mCustomer.CustomerUserID = MembershipContext.AuthenticatedUser.UserID; } mCustomer.CustomerEmail = txtCustomerEmail.Text.Trim(); mCustomer.CustomerLastName = txtCustomerLastName.Text.Trim(); mCustomer.CustomerPhone = txtCustomerPhone.Text.Trim(); mCustomer.CustomerFirstName = txtCustomerFirstName.Text.Trim(); mCustomer.CustomerCreated = DateTime.Now; if (IsBusiness) { mCustomer.CustomerCompany = txtCustomerCompany.Text.Trim(); mCustomer.CustomerOrganizationID = txtOraganizationID.Text.Trim(); mCustomer.CustomerTaxRegistrationID = txtTaxRegistrationID.Text.Trim(); } else { mCustomer.CustomerCompany = ""; mCustomer.CustomerOrganizationID = ""; mCustomer.CustomerTaxRegistrationID = ""; } // Update customer data CustomerInfoProvider.SetCustomerInfo(mCustomer); // Update corresponding contact data int currentContactId = ModuleCommands.OnlineMarketingGetCurrentContactID(); ModuleCommands.OnlineMarketingCreateRelation(mCustomer.CustomerID, MembershipType.ECOMMERCE_CUSTOMER, currentContactId); ModuleCommands.OnlineMarketingUpdateContactFromExternalData( mCustomer, DataClassInfoProvider.GetDataClassInfo(CustomerInfo.TYPEINFO.ObjectClassName).ClassContactOverwriteEnabled, currentContactId); // Let others now that customer was created if (OnCustomerCrated != null) { OnCustomerCrated(); ShowChangesSaved(); } else { URLHelper.Redirect(URLHelper.AddParameterToUrl(RequestContext.CurrentURL, "saved", "1")); } } else { //Show error ShowError(errorMessage); } }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { string errorMessage = ""; string siteName = CMSContext.CurrentSiteName; if ((txtCustomerCompany.Text.Trim() == "" || !chkCompanyAccount.Checked) && ((txtCustomerFirstName.Text.Trim() == "") || (txtCustomerLastName.Text.Trim() == ""))) { errorMessage = GetString("Customers_Edit.errorInsert"); } // Check the following items if complete company info is required for company account if (errorMessage == "" && ECommerceSettings.RequireCompanyInfo(siteName) && chkCompanyAccount.Checked) { errorMessage = new Validator().NotEmpty(txtCustomerCompany.Text, GetString("customers_edit.errorCompany")) .NotEmpty(txtOraganizationID.Text, GetString("customers_edit.errorOrganizationID")) .NotEmpty(txtTaxRegistrationID.Text, GetString("customers_edit.errorTaxRegID")).Result; } if (errorMessage == "") { errorMessage = new Validator().IsEmail(txtCustomerEmail.Text.Trim(), GetString("customers_edit.erroremailformat")).Result; } plcCompanyInfo.Visible = chkCompanyAccount.Checked; if (errorMessage == "") { // If customer doesn't already exist, create new one if (mCustomer == null) { mCustomer = new CustomerInfo(); mCustomer.CustomerEnabled = true; mCustomer.CustomerUserID = CMSContext.CurrentUser.UserID; } int currencyId = selectCurrency.CurrencyID; if (ECommerceContext.CurrentShoppingCart != null) { ECommerceContext.CurrentShoppingCart.ShoppingCartCurrencyID = currencyId; } mCustomer.CustomerEmail = txtCustomerEmail.Text.Trim(); mCustomer.CustomerFax = txtCustomerFax.Text.Trim(); mCustomer.CustomerLastName = txtCustomerLastName.Text.Trim(); mCustomer.CustomerPhone = txtCustomerPhone.Text.Trim(); mCustomer.CustomerFirstName = txtCustomerFirstName.Text.Trim(); mCustomer.CustomerCountryID = drpCountry.CountryID; mCustomer.CustomerStateID = drpCountry.StateID; mCustomer.CustomerCreated = DateTime.Now; // Set customers's preferences mCustomer.CustomerPreferredCurrencyID = (currencyId > 0) ? currencyId : 0; mCustomer.CustomerPreferredPaymentOptionID = drpPayment.PaymentID; mCustomer.CustomerPreferredShippingOptionID = drpShipping.ShippingID; // Check if customer is registered if (mCustomer.CustomerIsRegistered) { // Find user-site binding UserSiteInfo userSite = UserSiteInfoProvider.GetUserSiteInfo(Customer.CustomerUserID, CMSContext.CurrentSiteID); if (userSite != null) { // Set user's preferences userSite.UserPreferredCurrencyID = mCustomer.CustomerPreferredCurrencyID; userSite.UserPreferredPaymentOptionID = mCustomer.CustomerPreferredPaymentOptionID; userSite.UserPreferredShippingOptionID = mCustomer.CustomerPreferredShippingOptionID; UserSiteInfoProvider.SetUserSiteInfo(userSite); } } if (chkCompanyAccount.Checked) { mCustomer.CustomerCompany = txtCustomerCompany.Text.Trim(); if (ECommerceSettings.ShowOrganizationID(siteName)) { mCustomer.CustomerOrganizationID = txtOraganizationID.Text.Trim(); } if (ECommerceSettings.ShowTaxRegistrationID(siteName)) { mCustomer.CustomerTaxRegistrationID = txtTaxRegistrationID.Text.Trim(); } } else { mCustomer.CustomerCompany = ""; mCustomer.CustomerOrganizationID = ""; mCustomer.CustomerTaxRegistrationID = ""; } // Update customer data CustomerInfoProvider.SetCustomerInfo(mCustomer); // Update corresponding user email UserInfo user = mCustomer.CustomerUser; if (user != null) { user.Email = mCustomer.CustomerEmail; UserInfoProvider.SetUserInfo(user); } // Update corresponding contact data ModuleCommands.OnlineMarketingUpdateContactFromExternalData(mCustomer, DataClassInfoProvider.GetDataClass(CustomerInfo.TYPEINFO.ObjectClassName).ClassContactOverwriteEnabled, ModuleCommands.OnlineMarketingGetCurrentContactID()); // Let others now that customer was created if (OnCustomerCrated != null) { OnCustomerCrated(); ShowChangesSaved(); } else { URLHelper.Redirect(URLHelper.AddParameterToUrl(URLRewriter.CurrentURL, "saved", "1")); } } else { //Show error ShowError(errorMessage); } }
public bool IsValid() { string firstName = txtCustomerFirstName.Text.Trim(); string lastName = txtCustomerLastName.Text.Trim(); string company = txtCustomerCompany.Text.Trim(); // Check if name or company information are filled if ((string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName)) && string.IsNullOrEmpty(company)) { ShowError(GetString("customers_edit.errorinsert")); return(false); } // Check company information if required else if (ECommerceSettings.RequireCompanyInfo(CMSContext.CurrentSite.SiteName) && (!string.IsNullOrEmpty(txtCustomerCompany.Text.Trim()) || !string.IsNullOrEmpty(txtOrganizationID.Text.Trim()) || !string.IsNullOrEmpty(txtTaxRegistrationID.Text.Trim()))) { string error = new Validator() .NotEmpty(txtCustomerCompany.Text.Trim(), GetString("customers_edit.errorcompany")) .NotEmpty(txtOrganizationID.Text.Trim(), GetString("customers_edit.errororganizationid")) .NotEmpty(txtTaxRegistrationID.Text.Trim(), GetString("customers_edit.errortaxregid")) .Result; if (!string.IsNullOrEmpty(error)) { ShowError(error); return(false); } } // Check email if (!string.IsNullOrEmpty(txtCustomerEmail.Text.Trim()) && !ValidationHelper.IsEmail(txtCustomerEmail.Text)) { ShowError(GetString("customers_edit.erroremail")); return(false); } // Validate user fields if (chkCreateLogin.Checked) { // Check validators string error = new Validator() .NotEmpty(txtUserName.Text.Trim(), GetString("customer_edit_login_edit.rqvusername")) .NotEmpty(passStrength.Text.Trim(), GetString("customer_edit_login_edit.rqvpassword1")) .NotEmpty(txtPassword2.Text.Trim(), GetString("customer_edit_login_edit.rqvpassword2")) .Result; if (!string.IsNullOrEmpty(error)) { // Disaply error message ShowError(error); return(false); } // Check policy if (!passStrength.IsValid()) { ShowError(AuthenticationHelper.GetPolicyViolationMessage(CMSContext.CurrentSiteName)); return(false); } // Compare passwords if (passStrength.Text != txtPassword2.Text) { ShowError(GetString("customer_edit_login_edit.differentpasswords")); return(false); } // Check if user already exists UserInfo existingUser = UserInfoProvider.GetUserInfo(txtUserName.Text.Trim()); if (existingUser != null) { ShowError(GetString("customer_edit_login_edit.userexist")); return(false); } } return(true); }