protected bool CreateVolumeDiscount() { // Prepare the parameters string where = "SKUName LIKE '12 �prouvettes'"; SKUInfo product = null; // Get the product DataSet products = SKUInfoProvider.GetSKUs(where, null); if (!DataHelper.DataSourceIsEmpty(products)) { product = new SKUInfo(products.Tables[0].Rows[0]); } if (product != null) { // Create new volume discount object VolumeDiscountInfo newDiscount = new VolumeDiscountInfo(); // Set the properties newDiscount.VolumeDiscountMinCount = 1; newDiscount.VolumeDiscountValue = 10; newDiscount.VolumeDiscountSKUID = product.SKUID; newDiscount.VolumeDiscountIsFlatValue = false; // Create the volume discount VolumeDiscountInfoProvider.SetVolumeDiscountInfo(newDiscount); return(true); } return(false); }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { if (sku == null) { return; } if (CheckProductPermissions(sku)) { // True if there is already same min count; bool isMinCountUnique = false; // Server side validation of user input string errorMessage = new Validator().NotEmpty(txtVolumeDiscountValue.Text, "product_edit_volumediscount_edit.volumediscountvaluelabel") .NotEmpty(txtVolumeDiscountMinCount.Text, "product_edit_volumediscount_edit.volumediscountmincountlabel").Result; // Discount value validation if (errorMessage == "") { // Relative if (radDiscountRelative.Checked && !ValidationHelper.IsInRange(0, 100, ValidationHelper.GetDouble(txtVolumeDiscountValue.Text.Trim(), -1))) { errorMessage = GetString("Com.Error.RelativeDiscountValue"); } // Absolute else if (radDiscountAbsolute.Checked && !ValidationHelper.IsPositiveNumber(ValidationHelper.GetDouble(txtVolumeDiscountValue.Text.Trim(), -1))) { errorMessage = GetString("Com.Error.AbsoluteDiscountValue"); } } if (errorMessage == "") { VolumeDiscountInfo volumeDiscountObj = VolumeDiscountInfoProvider.GetVolumeDiscountInfo(volumeDiscountID); // If volumeDiscount doesnt already exist, create new one if (volumeDiscountObj == null) { // Create new volume discount volumeDiscountObj = new VolumeDiscountInfo(); // When creating new one, set his SKUID to productID (obtained from URL) volumeDiscountObj.VolumeDiscountSKUID = ProductID; } // Set volumeDiscountObj values volumeDiscountObj.VolumeDiscountValue = Convert.ToDouble(txtVolumeDiscountValue.Text.Trim()); volumeDiscountObj.VolumeDiscountMinCount = Convert.ToInt32(txtVolumeDiscountMinCount.Text.Trim()); volumeDiscountObj.VolumeDiscountIsFlatValue = radDiscountAbsolute.Checked; // Set isMinCountUnique VolumeDiscountInfo vdi = VolumeDiscountInfoProvider.GetVolumeDiscountInfo(ProductID, volumeDiscountObj.VolumeDiscountMinCount); if (vdi == null) { isMinCountUnique = true; } else { isMinCountUnique = (vdi.VolumeDiscountMinCount != volumeDiscountObj.VolumeDiscountMinCount); } // Check if min count is unique or it is update of existing item if ((isMinCountUnique) || (vdi.VolumeDiscountID == volumeDiscountObj.VolumeDiscountID)) { string dialogString = ""; if (dialog) { dialogString = "&modaldialog=1"; } // Sets data to database VolumeDiscountInfoProvider.SetVolumeDiscountInfo(volumeDiscountObj); string redirectUrl = "Product_Edit_VolumeDiscount_Edit.aspx?VolumeDiscountID=" + volumeDiscountObj.VolumeDiscountID + "&siteId=" + SiteID + "&saved=1&productID=" + ProductID + dialogString; URLHelper.Redirect(AddNodeIDParameterToUrl(redirectUrl)); } else { // Show error message ShowError(GetString("product_edit_volumediscount_edit.minamountexists")); } } else { // Show error message ShowError(errorMessage); } } }