Ejemplo n.º 1
0
    protected void radFollowing_CheckedChanged(object sender, EventArgs e)
    {
        if (mDiscountCouponInfoObj != null)
        {
            // Check permissions
            if (!ECommerceContext.IsUserAuthorizedToModifyDiscountCoupon(mDiscountCouponInfoObj))
            {
                if (mDiscountCouponInfoObj.IsGlobal)
                {
                    RedirectToAccessDenied(ModuleName.ECOMMERCE, EcommercePermissions.ECOMMERCE_MODIFYGLOBAL);
                }
                else
                {
                    RedirectToAccessDenied(ModuleName.ECOMMERCE, "EcommerceModify OR ModifyDiscounts");
                }
            }

            mDiscountCouponInfoObj.DiscountCouponIsExcluded = radExcept.Checked;

            // Set discount
            DiscountCouponInfoProvider.SetDiscountCouponInfo(mDiscountCouponInfoObj);

            // Show message
            ShowChangesSaved();
        }
    }
    protected void radFollowing_CheckedChanged(object sender, EventArgs e)
    {
        if (mDiscountCouponInfoObj != null)
        {
            // Check permissions
            if (!ECommerceContext.IsUserAuthorizedToModifyDiscountCoupon(mDiscountCouponInfoObj))
            {
                if (mDiscountCouponInfoObj.IsGlobal)
                {
                    RedirectToAccessDenied("CMS.Ecommerce", "EcommerceGlobalModify");
                }
                else
                {
                    RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyDiscounts");
                }
            }

            mDiscountCouponInfoObj.DiscountCouponIsExcluded = radExcept.Checked;

            // Set discount
            DiscountCouponInfoProvider.SetDiscountCouponInfo(mDiscountCouponInfoObj);

            lblInfo.Visible = true;
            lblInfo.Text    = GetString("General.ChangesSaved");
        }
    }
    /// <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;
        }
    }