/// <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); }