/// <summary> /// Handles clicking of the save button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { if (Editing) { //Update if (UpdateExistingCustomerLevel()) { ctrlAlertMessage.PushAlertMessage(AppLogic.GetString("admin.customer.level.UpdateSuccessful", SkinID, ThisCustomer.LocaleSetting), AlertMessage.AlertType.Success); } else { ctrlAlertMessage.PushAlertMessage(AppLogic.GetString("admin.customer.level.UpdateFailed", SkinID, ThisCustomer.LocaleSetting), AlertMessage.AlertType.Error); } } else { var temporaryCustomerLevelID = SaveNewCustomerLevel(); //Insert if (temporaryCustomerLevelID > 0) { CustomerLevelID = temporaryCustomerLevelID; ViewState["CustomerLevelID"] = CustomerLevelID; ctrlAlertMessage.PushAlertMessage(AppLogic.GetString("admin.customer.level.SaveNewSuccessful", SkinID, ThisCustomer.LocaleSetting), AlertMessage.AlertType.Success); } else { ctrlAlertMessage.PushAlertMessage(AppLogic.GetString("admin.customer.level.SaveNewFailed", SkinID, ThisCustomer.LocaleSetting), AlertMessage.AlertType.Error); } } SetPageValues(); NameLocaleField.BindData(); }
/// <summary> /// Updates Existing Customer Level /// </summary> /// <returns></returns> private bool UpdateExistingCustomerLevel() { bool saved = false; try { StringBuilder sql = new StringBuilder(); sql.Append("UPDATE CustomerLevel SET "); sql.AppendFormat("name={0},", DB.SQuote(NameLocaleField.GetTextFromFields())); sql.AppendFormat("LevelDiscountPercent={0},", string.IsNullOrEmpty(txtLevelDiscountPercent.Text.Trim()) ? "0" : Localization.DecimalStringForDB(Localization.ParseUSDecimal(txtLevelDiscountPercent.Text.Trim()))); sql.AppendFormat("LevelDiscountAmount={0},", string.IsNullOrEmpty(txtLevelDiscountAmount.Text.Trim()) ? "0" : Localization.CurrencyStringForDBWithoutExchangeRate(Localization.ParseUSDecimal(txtLevelDiscountAmount.Text.Trim()))); sql.AppendFormat("LevelHasFreeShipping={0},", LevelHasFreeShipping.SelectedValue); sql.AppendFormat("LevelAllowsQuantityDiscounts={0},", LevelAllowsQuantityDiscounts.SelectedValue); sql.AppendFormat("LevelAllowsPO={0},", LevelAllowsPO.SelectedValue); sql.AppendFormat("LevelHasNoTax={0},", LevelHasNoTax.SelectedValue); sql.AppendFormat("LevelAllowsCoupons={0},", LevelAllowsCoupons.SelectedValue); sql.AppendFormat("LevelDiscountsApplyToExtendedPrices={0} ", LevelDiscountsApplyToExtendedPrices.SelectedValue); sql.AppendFormat("WHERE CustomerLevelID={0}", CustomerLevelID.ToString()); DB.ExecuteSQL(sql.ToString()); Editing = true; saved = true; } catch { saved = false; } return(saved); }
/// <summary> /// Saves New Customer Level /// </summary> /// <returns></returns> private int SaveNewCustomerLevel() { int customerLevelID = 0; StringBuilder sql = new StringBuilder(); try { String NewGUID = DB.GetNewGUID(); sql.Append("INSERT INTO CUSTOMERLEVEL("); sql.Append("CustomerLevelGUID"); sql.Append(",Name"); sql.Append(",LevelDiscountPercent"); sql.Append(",LevelDiscountAmount"); sql.Append(",LevelHasFreeShipping"); sql.Append(",LevelAllowsQuantityDiscounts"); sql.Append(",LevelAllowsPO"); sql.Append(",LevelHasNoTax"); sql.Append(",LevelAllowsCoupons"); sql.Append(",LevelDiscountsApplyToExtendedPrices) "); sql.Append("VALUES("); sql.AppendFormat("{0},", DB.SQuote(NewGUID)); sql.AppendFormat("{0},", DB.SQuote(NameLocaleField.GetTextFromFields())); sql.AppendFormat("{0},", string.IsNullOrEmpty(txtLevelDiscountPercent.Text.Trim()) ? "0" : Localization.DecimalStringForDB(Localization.ParseUSDecimal(txtLevelDiscountPercent.Text.Trim()))); sql.AppendFormat("{0},", string.IsNullOrEmpty(txtLevelDiscountAmount.Text.Trim()) ? "0" : Localization.CurrencyStringForDBWithoutExchangeRate(Localization.ParseUSDecimal(txtLevelDiscountAmount.Text.Trim()))); sql.AppendFormat("{0},", LevelHasFreeShipping.SelectedValue); sql.AppendFormat("{0},", LevelAllowsQuantityDiscounts.SelectedValue); sql.AppendFormat("{0},", LevelAllowsPO.SelectedValue); sql.AppendFormat("{0},", LevelHasNoTax.SelectedValue); sql.AppendFormat("{0},", LevelAllowsCoupons.SelectedValue); sql.AppendFormat("{0})", LevelDiscountsApplyToExtendedPrices.SelectedValue); DB.ExecuteSQL(sql.ToString()); using (var dbconn = DB.dbConn()) { dbconn.Open(); using (var rs = DB.GetRS("SELECT CustomerLevelID FROM CustomerLevel WITH (NOLOCK) WHERE deleted=0 AND CustomerLevelGUID=" + DB.SQuote(NewGUID), dbconn)) { rs.Read(); customerLevelID = DB.RSFieldInt(rs, "CustomerLevelID"); if (customerLevelID > 0) { Editing = true; } } } } catch { customerLevelID = 0; } return(customerLevelID); }
SqlCommand CreateUpdateCommand() { var updateCommand = new SqlCommand( @"IF NOT EXISTS(SELECT ShippingMethodGUID FROM ShippingMethod WHERE ShippingMethodID = @ID) BEGIN INSERT INTO ShippingMethod(ShippingMethodGUID, [Name], DisplayName, ImageFileName) VALUES (@GUID, @Name, @DisplayName, @ImageFileName) SELECT @ID = ShippingMethodID FROM ShippingMethod WHERE ShippingMethodGUID = @GUID END ELSE BEGIN DECLARE @ISRtShipping tinyint SELECT @IsRtShipping = IsRTShipping FROM ShippingMethod WHERE ShippingMethodID = @ID UPDATE ShippingMethod SET [Name] = CASE WHEN @IsRtShipping = 1 Then [Name] ELSE @Name END, DisplayName = @DisplayName, ImageFileName = @ImageFileName WHERE ShippingMethodID = @ID END" ); updateCommand.Parameters.AddRange(new SqlParameter[] { new SqlParameter("@GUID", ShippingMethodGuid), new SqlParameter("@Name", NameLocaleField.GetTextFromFields()), new SqlParameter("@DisplayName", DisplayNameLocaleField.GetTextFromFields()), new SqlParameter("@ImageFileName", SqlDbType.Text) { Value = !string.IsNullOrEmpty(hdnImageFileName.Value) ? (object)hdnImageFileName.Value : DBNull.Value }, new SqlParameter("@ID", SqlDbType.Int) { Value = DBNull.Value, Direction = ParameterDirection.InputOutput } }); return(updateCommand); }
protected bool SaveShippingMethod() { bool saved = true; try { if (!Editing) { // ok to add: ShippingMethodGuid = new Guid(DB.GetNewGUID()); using (var updateCommand = CreateUpdateCommand()) { DB.ExecuteSQL(updateCommand); ShippingMethodID = (int)updateCommand.Parameters["@ID"].Value; } ViewState["ShippingMethodID"] = ShippingMethodID; } else { // ok to update: using (var updateCommand = CreateUpdateCommand()) { updateCommand.Parameters["@ID"].Value = ShippingMethodID; DB.ExecuteSQL(updateCommand); } } // for the store mapping if (ShippingMethodStoreFilteringEnabled) { DB.ExecuteSQL("DELETE ShippingMethodStore WHERE ShippingMethodId = @shippingMethodId", new[] { new SqlParameter("@shippingMethodId", ShippingMethodID) }); foreach (ListItem item in MappedStores.Items) { if (item.Selected) { DB.ExecuteSQL("INSERT INTO ShippingMethodStore(StoreId, ShippingMethodId) Values(@storeId, @shippingMethodId)", new[] { new SqlParameter("@storeId", item.Value), new SqlParameter("@shippingMethodId", ShippingMethodID), }); } } } BindPage(); NameLocaleField.BindData(); DisplayNameLocaleField.BindData(); AlertMessage.PushAlertMessage("Updated", AspDotNetStorefrontControls.AlertMessage.AlertType.Success); } catch (Exception exception) { AlertMessage.PushAlertMessage(exception.Message, AspDotNetStorefrontControls.AlertMessage.AlertType.Error); saved = false; } return(saved); }