/// <summary> /// Determines if the discount coupons are available for the current site. /// </summary> private bool AreDiscountCouponsAvailableOnSite() { string siteName = this.ShoppingCartInfoObj.SiteName; // Check site and global discount coupons string where = "DiscountCouponSiteID = " + SiteInfoProvider.GetSiteID(siteName); if (ECommerceSettings.AllowGlobalDiscountCoupons(siteName)) { where += " OR DiscountCouponSiteID IS NULL"; } // Coupons are available if found any DataSet ds = DiscountCouponInfoProvider.GetDiscountCoupons(where, null, -1, "count(DiscountCouponID)"); if (!DataHelper.DataSourceIsEmpty(ds)) { return(ValidationHelper.GetInteger(ds.Tables[0].Rows[0][0], 0) > 0); } return(false); }
/// <summary> /// Sets data to database. /// </summary> protected void btnOK_Click(object sender, EventArgs e) { // Check module permissions bool global = (editedSiteId <= 0); if (!ECommerceContext.IsUserAuthorizedToModifyDiscountCoupon(global)) { if (global) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceGlobalModify"); } else { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyDiscounts"); } } string errorMessage = new Validator().NotEmpty(txtDiscountCouponDisplayName.Text.Trim(), GetString("DiscounCoupon_Edit.errorDisplay")) .NotEmpty(txtDiscountCouponCode.Text.Trim(), GetString("DiscounCoupon_Edit.errorCode")) .IsCodeName(txtDiscountCouponCode.Text.Trim(), GetString("DiscounCoupon_Edit.errorCodeFormat")).Result; // Discount value validation if (errorMessage == "") { // Relative if (this.radPercentage.Checked && !ValidationHelper.IsInRange(0, 100, ValidationHelper.GetDouble(this.txtDiscountCouponValue.Text.Trim(), -1))) { errorMessage = GetString("Com.Error.RelativeDiscountValue"); } // Absolute else if (this.radFixed.Checked && !ValidationHelper.IsPositiveNumber(ValidationHelper.GetDouble(this.txtDiscountCouponValue.Text.Trim(), -1))) { errorMessage = GetString("Com.Error.AbsoluteDiscountValue"); } } // From/to date validation if (errorMessage == "") { if ((!dtPickerDiscountCouponValidFrom.IsValidRange()) || (!dtPickerDiscountCouponValidTo.IsValidRange())) { errorMessage = GetString("general.errorinvaliddatetimerange"); } if ((dtPickerDiscountCouponValidFrom.SelectedDateTime != DateTime.MinValue) && (dtPickerDiscountCouponValidTo.SelectedDateTime != DateTime.MinValue) && (dtPickerDiscountCouponValidFrom.SelectedDateTime >= dtPickerDiscountCouponValidTo.SelectedDateTime)) { errorMessage = GetString("General.DateOverlaps"); } } if (errorMessage == "") { // DiscountCoupon code name must to be unique DiscountCouponInfo discountCouponObj = null; string siteWhere = (editedSiteId > 0) ? " AND (DiscountCouponSiteID = " + editedSiteId + " OR DiscountCouponSiteID IS NULL)" : ""; DataSet ds = DiscountCouponInfoProvider.GetDiscountCoupons("DiscountCouponCode = '" + txtDiscountCouponCode.Text.Trim().Replace("'", "''") + "'" + siteWhere, null, 1, null); if (!DataHelper.DataSourceIsEmpty(ds)) { discountCouponObj = new DiscountCouponInfo(ds.Tables[0].Rows[0]); } // If discountCouponCode value is unique if ((discountCouponObj == null) || (discountCouponObj.DiscountCouponID == mDiscountId)) { // If discountCouponCode value is unique -> determine whether it is update or insert if ((discountCouponObj == null)) { // Get DiscountCouponInfo object by primary key discountCouponObj = DiscountCouponInfoProvider.GetDiscountCouponInfo(mDiscountId); if (discountCouponObj == null) { // Create new item -> insert discountCouponObj = new DiscountCouponInfo(); discountCouponObj.DiscountCouponSiteID = editedSiteId; } } discountCouponObj.DiscountCouponValue = ValidationHelper.GetDouble(txtDiscountCouponValue.Text.Trim(), 0.0); discountCouponObj.DiscountCouponCode = txtDiscountCouponCode.Text.Trim(); discountCouponObj.DiscountCouponIsFlatValue = true; if (radPercentage.Checked) { discountCouponObj.DiscountCouponIsFlatValue = false; } discountCouponObj.DiscountCouponDisplayName = txtDiscountCouponDisplayName.Text.Trim(); discountCouponObj.DiscountCouponValidFrom = dtPickerDiscountCouponValidFrom.SelectedDateTime; discountCouponObj.DiscountCouponValidTo = dtPickerDiscountCouponValidTo.SelectedDateTime; DiscountCouponInfoProvider.SetDiscountCouponInfo(discountCouponObj); URLHelper.Redirect("DiscountCoupon_Edit_General.aspx?discountid=" + Convert.ToString(discountCouponObj.DiscountCouponID) + "&saved=1&siteId=" + SiteID); } else { lblError.Visible = true; lblError.Text = GetString("DiscounCoupon_Edit.DiscountCouponCodeExists"); } } else { lblError.Visible = true; lblError.Text = errorMessage; } }