Esempio n. 1
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            HiTechDBEntities4 hitech = new HiTechDBEntities4();
            int customerId           = Convert.ToInt32(txtCustomerId.Text);

            var totals = from order in hitech.Orders
                         where order.CustomerId == customerId
                         group order by order.CustomerId into g
                         select g.Sum(p => p.Total);


            Customer customer = new Customer();

            customer.CustomerId = customerId;
            string customerName = customer.SearchCustomer(customer);

            listView1.Items.Clear();
            foreach (var total in totals)
            {
                ListViewItem item = new ListViewItem(Convert.ToString(customerName));
                item.SubItems.Add(Convert.ToString("CAD " + total));


                listView1.Items.Add(item);
            }
        }
Esempio n. 2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            HiTechDBEntities4 hitech = new HiTechDBEntities4();
            Book book1    = new Book();
            int  bookIsbn = Convert.ToInt32(txtIsbn.Text);
            Book book2    = hitech.Books.Find(bookIsbn);

            if (book2 != null)
            {
                MessageBox.Show("Duplicated Id", "Error");
                ClearTextBox();
                return;
            }

            book1.Isbn        = Convert.ToInt32(txtIsbn.Text.Trim());
            book1.Title       = txtTitle.Text;
            book1.UnitPrice   = Convert.ToDouble(txtPrice.Text);
            book1.Year        = Convert.ToInt32(txtYear.Text);
            book1.QOH         = Convert.ToInt32(txtQOH.Text);
            book1.CategoryId  = Convert.ToInt32(txtCategoryId.Text);
            book1.AuthorId    = Convert.ToInt32(txtAuthorId.Text);
            book1.PublisherId = Convert.ToInt32(txtPublisherId.Text);
            hitech.Books.Add(book1);
            hitech.SaveChanges();
            MessageBox.Show("Book saved sucessfully");
            ClearTextBox();
        }
Esempio n. 3
0
        private void btnShow_Click(object sender, EventArgs e)
        {
            HiTechDBEntities4 hitech = new HiTechDBEntities4();


            var booksList = from book in hitech.Books
                            select book;

            if (booksList != null)
            {
                listView1.Items.Clear();

                foreach (var book in booksList)
                {
                    ListViewItem item = new ListViewItem(Convert.ToString(book.Isbn));
                    item.SubItems.Add(book.Title);
                    item.SubItems.Add(Convert.ToString(book.UnitPrice));
                    item.SubItems.Add(Convert.ToString(book.Year));
                    item.SubItems.Add(Convert.ToString(book.QOH));
                    item.SubItems.Add(Convert.ToString(book.CategoryId));
                    item.SubItems.Add(Convert.ToString(book.AuthorId));
                    item.SubItems.Add(Convert.ToString(book.PublisherId));
                    listView1.Items.Add(item);
                }
            }
            else
            {
                MessageBox.Show("No books listed!");
            }
        }
Esempio n. 4
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            HiTechDBEntities4 hitech = new HiTechDBEntities4();

            Book book = new Book();

            int ISBN = Convert.ToInt32(txtIsbn.Text);

            book = hitech.Books.Find(ISBN);

            if (book == null)
            {
                MessageBox.Show("Book does not exist", "Error");
                return;
            }

            book.Isbn        = Convert.ToInt32(txtIsbn.Text);
            book.Title       = txtTitle.Text;
            book.UnitPrice   = Convert.ToDouble(txtPrice.Text);
            book.Year        = Convert.ToInt32(txtYear.Text);
            book.QOH         = Convert.ToInt32(txtQOH.Text);
            book.CategoryId  = Convert.ToInt32(txtCategoryId.Text);
            book.AuthorId    = Convert.ToInt32(txtAuthorId.Text);
            book.PublisherId = Convert.ToInt32(txtPublisherId.Text);


            hitech.SaveChanges();

            MessageBox.Show("Book saved sucessfully");
            ClearTextBox();
        }
Esempio n. 5
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            HiTechDBEntities4 hitech = new HiTechDBEntities4();

            int ISBN = Convert.ToInt32(txtSearch.Text);
            var book = hitech.Books.Find(ISBN);

            if (book == null)
            {
                MessageBox.Show("Book does not exist", "Error");
                return;
            }

            var myBookList = from book1 in hitech.Books
                             where book1.Isbn == ISBN
                             select book1;

            listView1.Items.Clear();

            foreach (var book1 in myBookList)
            {
                ListViewItem item = new ListViewItem(Convert.ToString(book1.Isbn));
                item.SubItems.Add(book1.Title);
                item.SubItems.Add(Convert.ToString(book1.UnitPrice));
                item.SubItems.Add(Convert.ToString(book1.Year));
                item.SubItems.Add(Convert.ToString(book1.QOH));
                item.SubItems.Add(Convert.ToString(book1.CategoryId));
                item.SubItems.Add(Convert.ToString(book1.AuthorId));
                item.SubItems.Add(Convert.ToString(book1.PublisherId));
                listView1.Items.Add(item);
            }
        }
Esempio n. 6
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            HiTechDBEntities4 hitech = new HiTechDBEntities4();

            Order order = new Order();

            int   customerId = Convert.ToInt32(txtCustomerId.Text);
            Order order1     = hitech.Orders.Find(customerId);

            if (order1 != null)
            {
                MessageBox.Show("Duplicated Employee Id", "Error");
                ClearTextBox();
                return;
            }

            order.CustomerId = customerId;
            order.Isbn       = Convert.ToInt32(txtIsbn.Text);
            Book book = hitech.Books.Find(order.Isbn);

            order.Quantity  = Convert.ToInt32(txtQty.Text);
            order.Total     = book.UnitPrice * order.Quantity;
            order.OrderedBy = Convert.ToString(comboOrderedBy.SelectedItem);

            hitech.Orders.Add(order);
            hitech.SaveChanges();
            MessageBox.Show("Order saved");

            string bookName = book.Title;
        }
Esempio n. 7
0
        private void btnSearchOrder_Click(object sender, EventArgs e)
        {
            HiTechDBEntities4 hitech = new HiTechDBEntities4();

            int orderId = Convert.ToInt32(txtSearchByOrderID.Text);

            var orderList = from order in hitech.Orders
                            where order.OrderId == orderId
                            select order
            ;

            listView1.Items.Clear();
            if (orderList != null)
            {
                foreach (var order in orderList)
                {
                    ListViewItem item = new ListViewItem(Convert.ToString(order.CustomerId));
                    item.SubItems.Add(Convert.ToString(order.OrderId));
                    item.SubItems.Add(Convert.ToString(order.Isbn));
                    item.SubItems.Add(Convert.ToString(order.Quantity));
                    item.SubItems.Add(order.OrderedBy);
                    item.SubItems.Add(Convert.ToString(order.Total));
                    listView1.Items.Add(item);
                }
            }
            if (orderList == null)
            {
                MessageBox.Show("Order does not exist", "Error");
            }
        }
Esempio n. 8
0
        private void btnSearchByCID_Click(object sender, EventArgs e)
        {
            HiTechDBEntities4 hitech = new HiTechDBEntities4();
            int customerId           = Convert.ToInt32(txtSearchByCustID.Text);
            var orderList            = hitech.Orders.Where(x => x.CustomerId == customerId).ToList <Order>();

            if (orderList.Count != 0)
            {
                listView1.Items.Clear();
                foreach (var order in orderList)
                {
                    ListViewItem item = new ListViewItem(Convert.ToString(order.CustomerId));
                    item.SubItems.Add(Convert.ToString(order.OrderId));
                    item.SubItems.Add(Convert.ToString(order.Isbn));
                    item.SubItems.Add(Convert.ToString(order.Quantity));
                    item.SubItems.Add(order.OrderedBy);
                    item.SubItems.Add(Convert.ToString(order.Total));
                    listView1.Items.Add(item);
                }
            }
            else
            {
                MessageBox.Show("Custmer does not have orders", "Error");
            }
        }
Esempio n. 9
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            HiTechDBEntities4 hitech = new HiTechDBEntities4();
            Order             order  = new Order();
            int orderId = Convert.ToInt32(txtOrderId.Text);

            order = hitech.Orders.Find(orderId);
            if (order == null)
            {
                MessageBox.Show("Order does not exists", "Error");
                return;
            }
            hitech.Orders.Remove(order);
            hitech.SaveChanges();
            MessageBox.Show("Order removed successfully");
            ClearTextBox();
        }
Esempio n. 10
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            HiTechDBEntities4 hitech = new HiTechDBEntities4();

            int ISBN = Convert.ToInt32(txtIsbn.Text);
            var book = hitech.Books.Find(ISBN);

            if (book == null)
            {
                MessageBox.Show("Book does not exist", "Error");
                return;
            }
            hitech.Books.Remove(book);
            hitech.SaveChanges();

            MessageBox.Show("Book removed sucessfully");
            ClearTextBox();
        }
Esempio n. 11
0
        private void btnShowBooks_Click(object sender, EventArgs e)
        {
            HiTechDBEntities4 hitech = new HiTechDBEntities4();

            var orderList = from order in hitech.Orders
                            select order;

            listView1.Items.Clear();
            foreach (var order in orderList)
            {
                ListViewItem item = new ListViewItem(Convert.ToString(order.CustomerId));
                item.SubItems.Add(Convert.ToString(order.OrderId));
                item.SubItems.Add(Convert.ToString(order.Isbn));
                item.SubItems.Add(Convert.ToString(order.Quantity));
                item.SubItems.Add(order.OrderedBy);
                item.SubItems.Add(Convert.ToString(order.Total));
                listView1.Items.Add(item);
            }
        }
Esempio n. 12
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            HiTechDBEntities4 hitech = new HiTechDBEntities4();
            Order             order  = new Order();
            int orderId = Convert.ToInt32(txtOrderId.Text);

            order = hitech.Orders.Find(orderId);
            if (order == null)
            {
                MessageBox.Show("Order does not exists", "Error");
                return;
            }

            order.CustomerId = Convert.ToInt32(txtCustomerId.Text);
            order.Isbn       = Convert.ToInt32(txtIsbn.Text);
            order.OrderedBy  = Convert.ToString(comboOrderedBy.SelectedItem);
            order.Quantity   = Convert.ToInt32(txtQty.Text);
            Book book = hitech.Books.Find(order.Isbn);

            order.Total = book.UnitPrice * order.Quantity;
            hitech.SaveChanges();
            MessageBox.Show("Order updated sucessfully");
            ClearTextBox();
        }