Exemple #1
0
        protected void btnAddCoupon_Click(object sender, EventArgs e)
        {
            CouponBL couponBL = new CouponBL();
            Coupon coupon = couponBL.GetCoupon(txtCoupon.Text);

            if (coupon != null)
            {
                ViewState["discount"] = coupon.Discount;
                CartBL cartBL = new CartBL();
                cartBL.SaveCartCoupon(Session["cartID"].ToString(), coupon.CouponID);
                calculateCart();
                btnDeleteCoupon.Visible = true;
            }
        }
Exemple #2
0
        public void LoadCart()
        {
            DataTable cart = new CartBL().GetProducts(Session["cartID"].ToString());

            double cartTotal = 0;
            double taxBase = 0;
            double tax = 0;
            double discount = 0;
            double delivery = 0;
            double total = 0;
            double saving = 0;
            int couponID = -1;

            for(int i=0;i<cart.Rows.Count;i++)
            {
                cartTotal += double.Parse(cart.Rows[i]["productPrice"].ToString()) * double.Parse(cart.Rows[i]["quantity"].ToString());
                discount += double.Parse(cart.Rows[i]["userPrice"].ToString()) * double.Parse(cart.Rows[i]["quantity"].ToString());
                if (int.Parse(cart.Rows[i]["couponID"].ToString()) > 0)
                {
                    couponID = int.Parse(cart.Rows[i]["couponID"].ToString());

                }
            }

            if (couponID > 0)
                lblRemoveCoupon.Visible = true;
            else lblRemoveCoupon.Visible = false;

            lblProductCount.Text = cart.Rows.Count.ToString();
            taxBase = discount / 1.2;
            tax = discount - taxBase;

            delivery = rdbDelivery.SelectedValue == "2" ? (cartTotal > 5000) ? 0 : 200 : 0;

            total = discount + delivery;
            saving = cartTotal - discount;

            Coupon coupon = new CouponBL().GetCoupon(couponID);
            if (coupon != null)
                lblCoupon.Text = coupon.Code;
            else lblCoupon.Text = string.Empty;

            lblCartValue.Text = string.Format("{0:N2}", cartTotal);
            lblDeliveryPrice.Text = string.Format("{0:N2}", delivery);
            lblTotal.Text = string.Format("{0:N2}", total);
            lblDiscount.Text = string.Format("{0:N2}", saving);
        }
Exemple #3
0
        public void ApplyCoupon(string cartID)
        {
            Coupon coupon = new CouponBL().GetCoupon(GetCartCoupon(cartID));
            if (coupon != null)
            {
                DataTable cart = GetProducts(cartID);
                if (coupon.Objects != null && coupon.Objects.Count > 0)
                {
                    for (int i = 0; i < cart.Rows.Count; i++)
                    {
                        Product product = new ProductBL().GetProduct(int.Parse(cart.Rows[i]["productID"].ToString()), string.Empty, false);
                        bool[] couponObjectStatus = new bool[coupon.Objects.Count];
                        for (int j = 0; j < coupon.Objects.Count; j++)
                        {
                            //category
                            if (coupon.Objects[j].ObjectTypeID == 1)
                            {
                                List<Category> categories = new CategoryBL().GetAllSubCategories(coupon.Objects[j].ObjectID);
                                foreach(Category category in categories)
                                    if(category.CategoryID == product.Categories[0].CategoryID)
                                    {
                                        couponObjectStatus[j] = true;
                                        break;
                                    }
                            }
                            //brand
                            if (coupon.Objects[j].ObjectTypeID == 2 && product.Brand.BrandID == coupon.Objects[j].ObjectID)
                                couponObjectStatus[j] = true;
                            //product
                            if (coupon.Objects[j].ObjectTypeID == 3 && product.ProductID == coupon.Objects[j].ObjectID)
                                couponObjectStatus[j] = true;
                        }
                        bool status = true;
                        foreach (bool objectStatus in couponObjectStatus)
                            status = status && objectStatus;

                        if (status)
                        {
                            double productPrice = double.Parse(cart.Rows[i]["productPrice"].ToString());
                            double discountPrice = coupon.CouponType.CouponTypeID == 1 ? productPrice * (1 - coupon.Discount / 100) : productPrice - coupon.Discount;
                            UpdateCartProduct(cartID, product.ProductID, double.Parse(cart.Rows[i]["quantity"].ToString()), double.Parse(cart.Rows[i]["productPrice"].ToString()), discountPrice, coupon.CouponID);
                        }
                    }
                }
            }
        }
Exemple #4
0
        protected void btnCoupon_Click(object sender, EventArgs e)
        {
            if(txtCoupon.Text != null)
            {
                Coupon coupon = new CouponBL().GetCoupon(txtCoupon.Text);
                if(coupon != null)
                {
                    new CartBL().SaveCartCoupon(Session["cartID"].ToString(), coupon.CouponID);
                    new CartBL().ApplyCoupon(Session["cartID"].ToString());
                    LoadCart();
                    if (CouponApplied != null)
                        CouponApplied(this, null);
                    //Response.Redirect("/porucivanje");
                    lblRemoveCoupon.Visible = true;

                }
            }
        }
Exemple #5
0
        private void loadCoupon(int couponID)
        {
            Coupon coupon = new CouponBL().GetCoupon(couponID);
            txtName.Text = coupon.Name;
            txtCode.Text = coupon.Code;
            txtDateFrom.Text = coupon.DateFrom.ToString();
            txtDateTo.Text = coupon.DateTo.ToString();
            cmbCouponType.SelectedValue = coupon.CouponType.CouponTypeID.ToString();
            txtDiscount.Text = coupon.Discount.ToString();
            ViewState["objects"] = coupon.Objects;
            ViewState["couponID"] = coupon.CouponID;

            showObjects();
        }