Ejemplo n.º 1
0
 protected override void Render(HtmlTextWriter writer)
 {
     CartBL cartBL = new CartBL();
     lblProductCount.Text = cartBL.GetProductsCount(Session["cartID"].ToString()).ToString();
     lblCartPrice.Text = string.Format("{0:N2}", cartBL.GetTotal(Session["cartID"].ToString()));
     base.Render(writer);
 }
Ejemplo n.º 2
0
 protected void btnDeleteCoupon_Click(object sender, EventArgs e)
 {
     ViewState["discount"] = 0;
     calculateCart();
     CartBL cartBL = new CartBL();
     cartBL.SaveCartCoupon(Session["cartID"].ToString(), -1);
     btnDeleteCoupon.Visible = false;
 }
Ejemplo n.º 3
0
        protected override void Render(HtmlTextWriter writer)
        {
            CartBL cartBL = new CartBL();
            lblProductCount.Text = cartBL.GetProductsCount(Session["cartID"].ToString()).ToString();
            lblCartPrice.Text = string.Format("{0:N2}", cartBL.GetTotal(Session["cartID"].ToString()));

            lblWishListCount.Text = (Page.User.Identity.IsAuthenticated) ? new WishListBL().GetWishListProducts(int.Parse(Membership.GetUser().ProviderUserKey.ToString())).Count().ToString() : "0";

            base.Render(writer);
        }
Ejemplo n.º 4
0
 public void LoadCart()
 {
     CartBL cartBL = new CartBL();
     dgvCart.DataSource = cartBL.GetProducts(Session["cartID"].ToString());
     dgvCart.DataBind();
     ViewState.Add("discount", cartBL.GetCartDiscount(Session["cartID"].ToString()));
     calculateCart();
     if (dgvCart.Rows.Count == 0)
     {
         lblStatus.Text = "Nemate proizvoda u korpi";
         lblStatus.Visible = true;
     }
 }
Ejemplo n.º 5
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.º 6
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);
        }
Ejemplo n.º 7
0
 protected void dgvCart_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     switch (e.CommandName)
     {
         case "UpdateQuantity":
             {
                 GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
                 int productID = int.Parse(((Label)row.Cells[0].FindControl("lblProductID")).Text);
                 double productPrice = double.Parse(((Label)row.Cells[0].FindControl("lblProductPrice")).Text);
                 double userPrice = double.Parse(((Label)row.Cells[0].FindControl("lblUserPrice")).Text);
                 int quantity;
                 if (!int.TryParse(((TextBox)row.Cells[0].FindControl("txtQuantity")).Text, out quantity))
                 {
                     Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('wrong')</SCRIPT>");
                     break;
                 }
                 else
                 {
                     CartBL cartBL = new CartBL();
                     cartBL.UpdateCartProduct(Session["cartID"].ToString(), productID, quantity, productPrice, userPrice);
                     calculateItem(row.RowIndex, userPrice * quantity);
                     calculateTotal();
                 }
                 break;
             }
     }
 }
Ejemplo n.º 8
0
        private void calculateCart()
        {
            double price;
            double discount = (ViewState["discount"] != null) ? double.Parse(ViewState["discount"].ToString()) : 0;
            CartBL cartBL = new CartBL();

            foreach (GridViewRow row in dgvCart.Rows)
            {
                //if (double.Parse(((Label)row.FindControl("lblProductPrice")).Text) == double.Parse(((Label)row.FindControl("lblUserPrice")).Text))
                //{
                    price = double.Parse(((Label)row.FindControl("lblProductPrice")).Text);
                    double discountPrice = price * (1 - ((double)discount) / 100);
                    double quantity = double.Parse(((TextBox)row.FindControl("txtQuantity")).Text);
                    int productID = int.Parse(((Label)row.FindControl("lblProductID")).Text);
                    ((Label)row.FindControl("lblUserPrice")).Text = string.Format("{0:N2}", discountPrice);
                    ((Label)row.FindControl("lblSum")).Text = string.Format("{0:N2}", (discountPrice * quantity));
                    cartBL.UpdateCartProduct(Session["cartID"].ToString(), productID, quantity, price, discountPrice);
                //}

            }
            calculateTotal();
        }
Ejemplo n.º 9
0
 protected void dgvCart_RowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     if (dgvCart.Rows.Count > 0)
     {
         CartBL cartBL = new CartBL();
         int status = cartBL.DeleteProductFromCart(int.Parse(dgvCart.DataKeys[e.RowIndex].Values[0].ToString()), Session["cartID"].ToString());
         //setValues();
         //Response.Redirect("/cart.aspx");
         loadCart();
         //((CartFirstPage)Page.Master.FindControl("CartFirstPage1")).ProductsCount = dgvCart.Rows.Count;
     }
 }
Ejemplo n.º 10
0
 public static string AddToCart(int productID, double webPrice)
 {
     CartBL cartBL = new CartBL();
     cartBL.AddProductToCart(productID, System.Web.HttpContext.Current.Session["cartID"].ToString(), 1, webPrice, webPrice);
     return JsonConvert.SerializeObject((cartBL.GetProductsCount(System.Web.HttpContext.Current.Session["cartID"].ToString()).ToString() + "|" + string.Format("{0:N2}", cartBL.GetTotal(System.Web.HttpContext.Current.Session["cartID"].ToString()))).Split('|'));
 }
Ejemplo n.º 11
0
 protected void btnCart_Click(object sender, EventArgs e)
 {
     CartBL cartBL = new CartBL();
     cartBL.AddProductToCart(lblProductID.Value.Contains(',') ? int.Parse(lblProductID.Value.Substring(0, lblProductID.Value.IndexOf(','))) : int.Parse(lblProductID.Value), Session["cartID"].ToString(), 1, double.Parse(lblWebPrice.Text), double.Parse(lblWebPrice.Text));
     //Response.Redirect("/korpa");
 }
Ejemplo n.º 12
0
        private Order createOrder(int userID)
        {
            Order order = new Order();
            order.Date = DateTime.Now.AddHours(9);
            order.Firstname = txtFirstname.Text;
            order.Lastname = txtLastname.Text;
            order.Address = txtAddress.Text;
            order.City = txtCity.Text;
            order.Phone = txtPhone.Text;
            order.Email = txtEmail.Text;
            order.Items = getItems();
            order.User = new User(userID, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, null, string.Empty, string.Empty);
            order.Name = (rdbUserType.SelectedValue == "2") ? txtCompanyName.Text : string.Empty;
            order.Pib = (rdbUserType.SelectedValue == "2") ? txtPib.Text : string.Empty;
            order.Payment = (order.Name != string.Empty) ? new Payment(int.Parse(rdbPaymentCompany.SelectedValue), rdbPaymentCompany.SelectedItem.Text) : new Payment(int.Parse(rdbPayment.SelectedValue.ToString()), rdbPayment.SelectedItem.Text);
            order.Delivery = new Delivery(int.Parse(rdbDelivery.SelectedValue.ToString()), rdbDelivery.SelectedItem.Text);
            CartBL cartBL = new CartBL();
            order.Coupon = new Coupon(cartBL.GetCartCoupon(Session["cartID"].ToString()), string.Empty, 0, string.Empty);
            order.OrderStatus = new OrderStatus(1, string.Empty);
            order.Zip = txtZip.Text;
            order.Comment = txtRemark.Text;
            order.CartID = Session["cartID"].ToString();

            OrderBL orderBL = new OrderBL();
            orderBL.SaveOrder(order);
            return order;
        }
Ejemplo n.º 13
0
        private List<OrderItem> getItems()
        {
            CartBL cartBL = new CartBL();
            DataTable cartItems = cartBL.GetProducts(Session["cartID"].ToString());

            List<OrderItem> items = new List<OrderItem>();
            for (int i = 0; i < cartItems.Rows.Count; i++)
            {
                items.Add(new OrderItem(-1, -1, int.Parse(cartItems.Rows[i]["productID"].ToString()), double.Parse(cartItems.Rows[i]["productPrice"].ToString()), double.Parse(cartItems.Rows[i]["userPrice"].ToString()), double.Parse(cartItems.Rows[i]["quantity"].ToString())));
            }
            return items;
        }
Ejemplo n.º 14
0
 private void loadCheckout()
 {
     CartBL cartBL = new CartBL();
     //checkoutInfo1.CartItems = cartBL.GetProducts(Session["cartID"].ToString());
 }