コード例 #1
0
 public static void UpdateOrders(int Bookid, int quantity, decimal price)
 {
     using (ShopBooks entities = new ShopBooks())
     {
         Books bk = entities.Books.Where(b => b.BookID == Bookid).First <Books>();
         bk.Quantity = (quantity);
         bk.Price    = (price);
         entities.SaveChanges();
     }
 }
コード例 #2
0
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string    searchText = txtSearch.Text;
            ShopBooks context    = new ShopBooks();
            var       q          = from x in context.Books
                                   where x.BookTitle.Contains(searchText) || x.Author.Contains(searchText) || x.Category.Contains(searchText)
                                   select x;

            Repeater1.DataSource = q.ToList();
            Repeater1.DataBind();
        }
コード例 #3
0
        public static void AddDiscount(int Bookid, DateTime strtdate, DateTime enddate, int discount)
        {
            using (ShopBooks entities = new ShopBooks())
            {
                Discounts disk = new Discounts();
                disk.BookID    = Bookid;
                disk.StartDate = strtdate;
                disk.EndDate   = enddate;
                disk.Discount  = discount;
                entities.Discounts.Add(disk);

                entities.SaveChanges();
            }
        }
コード例 #4
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            ShopBooks context = new ShopBooks();
            Books     bok     = new Books();

            bok.BookTitle = txtBookTitle.Text;
            bok.Author    = txtAuthor.Text;
            bok.ISBN      = txtISBN.Text;
            bok.Price     = decimal.Parse(txtPrice.Text);
            bok.Publisher = txtPublisher.Text;
            bok.Category  = DropDownCategory.SelectedItem.Text;
            bok.Quantity  = int.Parse(txtQuantity.Text);

            context.Books.Add(bok);
            context.SaveChanges();
            Label1.Visible = true;
            Label1.Text    = "Book added Successfully!";
        }
コード例 #5
0
        public static void DeleteOrder(int bookid)
        {
            using (ShopBooks entities = new ShopBooks())
            {
                Discounts disk = entities.Discounts.Where(i => i.BookID == bookid).FirstOrDefault <Discounts>();

                if (disk != null)
                {
                    entities.Discounts.Remove(disk);
                    entities.SaveChanges();
                }
                //CartDetail cart = entities.CartDetails.Where(i => i.BookID == bookid).FirstOrDefault<CartDetail>();



                Books book = entities.Books.Where(p => p.BookID == bookid).First <Books>();
                entities.Books.Remove(book);
                entities.SaveChanges();
            }
        }
コード例 #6
0
        public static List <Books> ListBooksBy(string name)
        {
            string[] check = name.Split(' ');
            string   text  = "";

            for (int i = 0; i <= check.Length - 2; i++)
            {
                if (check.Length >= 3)
                {
                    text += check[i];
                    text += " ";
                }
                else
                {
                    text += check[i];
                }
            }

            if (check[check.Length - 1] == "Title")

            {
                using (ShopBooks entities = new ShopBooks())
                {
                    if (check.Length >= 3)
                    {
                        return(entities.Books.Where(o => o.BookTitle == text).ToList <Books>());
                    }
                    else
                    {
                        return(entities.Books.Where(o => o.BookTitle.Contains(text)).ToList <Books>());
                    }
                }
            }
            else if (check[check.Length - 1] == "Category")
            {
                using (ShopBooks entities = new ShopBooks())
                {
                    if (check.Length >= 3)
                    {
                        return(entities.Books.Where(o => o.Category == text).ToList <Books>());
                    }
                    else
                    {
                        return(entities.Books.Where(o => o.Category.Contains(text)).ToList <Books>());
                    }
                }
            }
            else
            {
                using (ShopBooks entities = new ShopBooks())
                {
                    if (check.Length >= 3)
                    {
                        return(entities.Books.Where(o => o.Author == text).ToList <Books>());
                    }
                    else
                    {
                        return(entities.Books.Where(o => o.Author.Contains(text)).ToList <Books>());
                    }
                }
            }
        }