コード例 #1
0
        protected void btnGo_Click(object sender, EventArgs e)
        {
            /*Variable to find if the coupon is valid or not.
             * 0. Error
             * 1. Valid
             * 2. Invalid coupon: Already used.
             * 3. Invalid coupon: Coupon not applicable.
             * 4. Wrong coupon code.*/

            if (Session["Coupon"] != null)
            {
                lblCouponError.Text = "Only 1 coupon can be applied for each order";
            }
            else
            {
                int couponFlag = objBAL.CheckCouponCode(txtCouponCode.Text, Convert.ToString(Session["UserID"]));

                switch (couponFlag)
                {
                case 0:
                    lblCouponError.Text = "ERROR: Please try after sometime";
                    break;

                case 1:
                    lblCouponError.Text = "";
                    lblSign5.Visible    = true;
                    lblDiscount.Visible = true;

                    Coupon coupon = objBAL.GetCoupon(txtCouponCode.Text);

                    lblDiscount.Text  = coupon.Amount.ToString();
                    Session["Coupon"] = coupon;
                    break;

                case 2:
                    lblCouponError.Text = "Coupon already used";
                    break;

                case 3:
                    lblCouponError.Text = "Coupon is not applicable for you";
                    break;

                case 4:
                    lblCouponError.Text = "Invalid coupon code";
                    break;
                }

                txtCouponCode.Text = "";
            }
        }