public decimal countprice(CartList cl)
        {
            List <Cart> cart       = cl.getCl();
            decimal     totalprice = 0;

            for (int i = 0; i < cart.Count; i++)
            {
                Cart    c = cart[i];
                decimal p = 0;
                p          = c.b.Price;
                totalprice = totalprice + p;
            }
            return(totalprice);
        }
        public CartList addItem(CartList cl, int id, string t, decimal p, int q)
        {
            Book b = new Book();

            b.BookId = id;
            b.Title  = t;
            b.Price  = p;
            int  quantity = q;
            Cart c        = new Cart(b, quantity);

            cl.add(c);
            CartList Cl = cl;

            return(Cl);
        }
示例#3
0
        protected void btnCheckOut_Click(object sender, EventArgs e)
        {
            //For Luke
            //if (Session["username"] == null)
            //{
            //    Response.Redirect("Login.aspx");
            //}

            CartList cart = (CartList)Session["cart"];

            cc.minusStock(cart);
            Session["cart"] = null;
            Response.Write("<script>alert('Update Successful!');window.location.href ='Webform1.aspx'</script>");

            Response.Redirect("~/CataloguePage.aspx");
        }
示例#4
0
        protected void btnAddToCart_Click(object sender, EventArgs e)
        {
            Session["BookTitle"] = txtTitle.Text;
            using (BookShop_EF2 BookShop = new BookShop_EF2())
            {
                shopController sc    = new shopController();
                string         title = (string)Session["booktitle"];
                //string title = "The Hate U Give";//For testing purpose
                Book b = sc.loadBook(title);

                // For Luke's login part
                //if (Session["username"] == null)
                //{
                //    Response.Redirect("Login.aspx");
                //}

                if (Session["cart"] != null)
                {
                    CartList cl = (CartList)Session["cart"];

                    int     id    = b.BookId;
                    decimal price = 0;
                    price = b.Price;
                    int quantity = Convert.ToInt32(txtQuantity.Text);

                    cartController cc = new cartController();
                    cl = cc.addItem(cl, id, title, price, quantity);
                    Session["cart"] = cl;
                }
                else
                {
                    CartList cl = new CartList();

                    int     id    = b.BookId;
                    decimal price = 0;
                    price = b.Price;
                    int            quantity = Convert.ToInt32(txtQuantity.Text);
                    cartController cc       = new cartController();
                    cl = cc.addItem(cl, id, title, price, quantity);
                    Session["cart"] = cl;
                }
                Response.Redirect("ViewCart.aspx");
            }
        }
        public void minusStock(CartList cl)
        {
            using (BookShop_EF2 bookshop = new BookShop_EF2())
            {
                List <Cart> cart = cl.getCl();

                for (int i = 0; i < cart.Count; i++)
                {
                    Cart c = cart[i];
                    Book b = bookshop.Books.Find(c.b.BookId);

                    int bookstock = 1;
                    bookstock = b.Stock - 1;

                    b.Stock = bookstock;
                    bookshop.SaveChanges();
                }
            }
        }
示例#6
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["cart"] != null)
     {
         CartList cart = (CartList)Session["cart"];
         this.GridViewCart.DataSource = cart.getCl();
         this.GridViewCart.DataBind();
         decimal totalprice = cc.countprice(cart);
         txtTotalPrice.Text = totalprice.ToString();
     }
     else
     {
         CartList cart = new CartList();
         this.GridViewCart.DataSource = cart.getCl();
         this.GridViewCart.DataBind();
         decimal totalprice = cc.countprice(cart);
         txtTotalPrice.Text = totalprice.ToString();
         Response.Write("<script>alert('Empty!')</script>");
     }
 }