Esempio n. 1
0
 protected void BindGrid()
 {
     using (Mybooks b = new Mybooks())
     {
         GridView1.DataSource = b.Books.ToList <Book>();
         GridView1.DataBind();
     }
 }
Esempio n. 2
0
 protected void LoadTable()
 {
     using (Mybooks b = new Mybooks())
     {
         GridView_Purchase_BookList.DataSource = b.Books.ToList <Book>();
         GridView_Purchase_BookList.DataBind();
     }
     ListBox_Cart_Title.Items.Clear();
     ListBox_Cart_Qty.Items.Clear();
 }
Esempio n. 3
0
        protected void GridView_Purchase_BookList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                int id = Convert.ToInt32(e.CommandArgument);
                if (e.CommandName == "AddToCart")
                {
                    string[] hdnValues = Request.Params["num"].ToString().Split(',');
                    Mybooks  b         = new Mybooks();
                    string   title     = b.Books.SingleOrDefault(a => a.BookID == id).Title;
                    int      stock     = b.Books.SingleOrDefault(a => a.BookID == id).Stock;

                    ListBox_Cart_Title.Visible = true;

                    if (!ListBox_Cart_Title.Items.Contains(new ListItem(title)))
                    {
                        if (Int32.Parse(hdnValues[id - 1]) > stock)
                        {
                            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + "Sorry for out of Stock!" + "');", true);
                        }
                        else if (Int32.Parse(hdnValues[id - 1]) != 0)
                        {
                            ListBox_Cart_Title.Items.Add(new ListItem(title));
                            ListBox_Cart_Qty.Items.Add(new ListItem(hdnValues[id - 1]));
                        }
                    }
                    else
                    {
                        int    idx      = ListBox_Cart_Title.Items.IndexOf(ListBox_Cart_Title.Items.FindByValue(title));
                        string quanStr  = ListBox_Cart_Qty.Items[idx].ToString();
                        int    oldCout  = Int32.Parse(quanStr);
                        int    newCount = Int32.Parse(hdnValues[id - 1]);
                        int    res      = oldCout + newCount;
                        if (res > stock)
                        {
                            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + "Sorry for out of Stock!" + "');", true);
                        }
                        else if (res != 0)
                        {
                            ListBox_Cart_Qty.Items.RemoveAt(idx);
                            ListBox_Cart_Qty.Items.Insert(idx, res.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Esempio n. 4
0
 protected void Button1_Click(object sender, EventArgs e)
 {
     ListItem[] titles = (ListItem[])Session["buyTitles"];
     ListItem[] quan   = (ListItem[])Session["buyQty"];
     for (int i = 0; i < titles.Length; i++)
     {
         string  title     = titles[i].Text;
         string  qty       = quan[i].Text;
         Mybooks b         = new Mybooks();
         Book    book      = b.Books.Where(x => x.Title == title).First();
         int     buyAmount = Convert.ToInt32(qty);
         book.Stock = book.Stock - buyAmount;
         b.SaveChanges();
     }
     Response.Redirect("BooksUser.aspx");
 }
Esempio n. 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            lblRedirect.Visible = false;


            if (!IsPostBack)
            {
                BindGrid();
            }
            decimal totalPrice = 0;

            blist = (List <Book>)Session["CartList"];
            Mybooks context = new Mybooks();
            //float discountPer=context.PercentageDiscount
            Discount discount = context.Discounts.ToList()[0];



            foreach (Book B in blist)
            {
                totalPrice += B.Price;
            }
            txtTotalAmount.Text = Convert.ToString((String.Format("{0:c}", totalPrice)));
            if (blist != null)
            {
                Button1.Visible = true;
                if (discount.PercentageDiscount != 0 && (DateTime.Today >= discount.StartDate && DateTime.Today <= discount.EndDate))
                {
                    lblDiscount.Text           = discount.PercentageDiscount + "% off your purchase!";
                    lblDiscount.Visible        = true;
                    txtDiscount.Text           = Convert.ToString(String.Format("{0:c}", (totalPrice * (Convert.ToDecimal(discount.PercentageDiscount)) / 100)));
                    txtFinalPrice.Text         = Convert.ToString(String.Format("{0:c}", (totalPrice * (100 - Convert.ToDecimal(discount.PercentageDiscount)) / 100)));
                    lblDiscountedPrice.Visible = true;
                    txtDiscount.Visible        = true;
                }
                else
                {
                    txtFinalPrice.Text = totalPrice.ToString();
                }
            }
            else
            {
                Button1.Visible = false;
            }
        }
Esempio n. 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            List <string> allTitles = new List <string>();

            ListItem[] titles = (ListItem[])Session["buyTitles"];

            List <Int32> allQty = new List <Int32>();

            ListItem[] quan = (ListItem[])Session["buyQty"];

            List <double> amount = new List <double>();
            double        cost   = 0.0;

            for (int idx = 0; idx < quan.Length; idx++)
            {
                string titleStr = titles[idx].ToString();
                allTitles.Add(titleStr);
                int quantity = Int32.Parse(quan[idx].ToString());
                allQty.Add(quantity);
                Mybooks b            = new Mybooks();
                Book    resultedBook = b.Books.Where(a => a.Title == titleStr).FirstOrDefault();
                double  price        = Decimal.ToDouble(resultedBook.Price);
                double  amt          = price * quantity;
                cost += amt;
                amount.Add(amt);
            }
            GridView1.DataSource = allTitles;
            GridView1.DataBind();

            GridView2.DataSource = allQty;
            GridView2.DataBind();

            GridView3.DataSource = amount;
            GridView3.DataBind();

            Label1.Text = "Total Cost is $" + cost;
        }