Ejemplo n.º 1
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()) > 1)
                {
                    couponID = int.Parse(cart.Rows[i]["couponID"].ToString());
                }
            }

            if (couponID > 1)
            {
                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 > double.Parse(ConfigurationManager.AppSettings["freeDeliveryTotalValue"])) ? 0 : double.Parse(ConfigurationManager.AppSettings["deliveryCost"])) : 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);
        }
Ejemplo n.º 2
0
        private void setValues()
        {
            double     cartTotal        = 0;
            double     taxBase          = 0;
            double     tax              = 0;
            double     discount         = 0;
            double     delivery         = 0;
            double     total            = 0;
            double     userDiscount     = 0;
            CouponType discountType     = new CouponType(1, "Procentualni");
            double     totalForDiscount = 0;

            if (Page.User.Identity.IsAuthenticated)
            {
                eshopBE.User user = UserBL.GetUser(-1, Page.User.Identity.Name);
                userDiscount = user.Discount;
                discountType = new CouponBL().GetCouponType(user.DiscountTypeID);
            }

            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]["productPrice"].ToString()) * double.Parse(_cart.Rows[i]["quantity"].ToString()) - double.Parse(_cart.Rows[i]["total"].ToString());
                totalForDiscount += !bool.Parse(ConfigurationManager.AppSettings["userDiscountOnlyOnProductNotOnPromotion"]) || double.Parse(_cart.Rows[i]["productPrice"].ToString()) == double.Parse(_cart.Rows[i]["userPrice"].ToString()) ? double.Parse(_cart.Rows[i]["productPrice"].ToString()) * double.Parse(_cart.Rows[i]["quantity"].ToString()) : 0;
            }
            lblNumberOfProducts.Text = _cart.Rows.Count.ToString();


            double userDiscountValue = (discountType.CouponTypeID == 1) ? (totalForDiscount) * (userDiscount / 100) : userDiscount;

            double totalWithDiscount = cartTotal - discount - userDiscountValue;

            taxBase = (cartTotal - discount - userDiscountValue) / 1.2;
            tax     = cartTotal - discount - userDiscountValue - taxBase;



            delivery = (cartTotal - discount - userDiscountValue > double.Parse(ConfigurationManager.AppSettings["freeDeliveryTotalValue"])) ? 0 : double.Parse(ConfigurationManager.AppSettings["deliveryCost"]);



            total = cartTotal - discount + delivery - userDiscountValue;



            lblTaxBase.Text      = string.Format("{0:N2}", taxBase);
            lblPdv.Text          = string.Format("{0:N2}", tax);
            lblTotalWithTax.Text = string.Format("{0:N2}", cartTotal);
            double totalDiscount = discount + userDiscountValue;

            lblDiscount.Text          = string.Format("{0:N2}", (0 - totalDiscount));
            lblTotalWithDiscount.Text = string.Format("{0:N2}", totalWithDiscount);
            //lblDiscount.Text = "42423424";
            lblDelivery.Text = string.Format("{0:N2}", delivery);
            lblTotal.Text    = string.Format("{0:N2}", total);
        }
Ejemplo n.º 3
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;
            }
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
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;
         }
     }
 }