Beispiel #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            HiTech_DBEntities4 hiTechEntity = new HiTech_DBEntities4();

            Order order      = new Order();
            int   customerId = Convert.ToInt32(txtCustomerrId.Text);

            Order order1 = hiTechEntity.Orders.Find(customerId);

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

            order.Customer_ID = customerId;
            order.ISBN        = Convert.ToInt32(txtISBN.Text);
            Book book = hiTechEntity.Books.Find(order.ISBN); // returns line from referred book table

            order.Qte       = Convert.ToInt32(txtQte.Text);
            order.total     = book.UnitPrice * order.Qte;
            order.OrderedBy = Convert.ToString(comboBoxOrderedBy.SelectedItem);

            hiTechEntity.Orders.Add(order);
            hiTechEntity.SaveChanges();
            MessageBox.Show("ORder saved sucessfully");

            string bookName = book.Title;
        }
Beispiel #2
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            HiTech_DBEntities4 HiTechEntitity = new HiTech_DBEntities4();
            int customerId = Convert.ToInt32(txtSearchOrderByCID.Text);
            var orderList  = HiTechEntitity.Orders.Where(x => x.Customer_ID == customerId).ToList <Order>();

            if (orderList.Count != 0)
            {
                listView1.Items.Clear();
                foreach (var order in orderList)
                {
                    ListViewItem item = new ListViewItem(Convert.ToString(order.Customer_ID));
                    item.SubItems.Add(Convert.ToString(order.order_ID));
                    item.SubItems.Add(Convert.ToString(order.ISBN));
                    item.SubItems.Add(Convert.ToString(order.Qte));
                    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");
            }
        }
Beispiel #3
0
        // WHy it doesnt go to the else??
        private void btnSearchOrder_Click_1(object sender, EventArgs e)
        {
            HiTech_DBEntities4 HiTechEntitity = new HiTech_DBEntities4();

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

            var orderList = from order in HiTechEntitity.Orders
                            where order.order_ID == orderId
                            select order
            ;

            listView1.Items.Clear();
            if (orderList != null)
            {
                foreach (var order in orderList)
                {
                    ListViewItem item = new ListViewItem(Convert.ToString(order.Customer_ID));
                    item.SubItems.Add(Convert.ToString(order.order_ID));
                    item.SubItems.Add(Convert.ToString(order.ISBN));
                    item.SubItems.Add(Convert.ToString(order.Qte));
                    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");
            }
        }
        private void btnShowBooks_Click(object sender, EventArgs e)
        {
            HiTech_DBEntities4 HiTechEntity = new HiTech_DBEntities4();


            var booksList = from book in HiTechEntity.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.YearPublished));
                    item.SubItems.Add(Convert.ToString(book.QOH));
                    item.SubItems.Add(book.Category);
                    item.SubItems.Add(Convert.ToString(book.Auhtor_Id));
                    item.SubItems.Add(Convert.ToString(book.Publisher_Id));
                    listView1.Items.Add(item);
                }
            }
            else
            {
                MessageBox.Show("No books listed!");
            }
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            HiTech_DBEntities4 HiTechEntity = new HiTech_DBEntities4();
            Book book1    = new Book();
            int  bookIsbn = Convert.ToInt32(txtBookISBN.Text);
            Book book2    = HiTechEntity.Books.Find(bookIsbn);

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

            book1.ISBN          = Convert.ToInt32(txtBookISBN.Text.Trim());
            book1.Title         = txtBookTitle.Text;
            book1.UnitPrice     = Convert.ToDouble(txtPrice.Text);
            book1.YearPublished = Convert.ToInt32(txtYear.Text);
            book1.QOH           = Convert.ToInt32(txtQOH.Text);
            book1.Category      = txtCategory.Text;
            book1.Auhtor_Id     = Convert.ToInt32(txtAuthorID.Text);
            book1.Publisher_Id  = Convert.ToInt32(txtPublisherID.Text);
            HiTechEntity.Books.Add(book1);
            HiTechEntity.SaveChanges();
            MessageBox.Show("Book saved sucessfully");
            clearText();
        }
        private void btnSearch_Click(object sender, EventArgs e)
        {
            HiTech_DBEntities4 HiTechEntity = new HiTech_DBEntities4();

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

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

            var myBookList = from book1 in HiTechEntity.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.YearPublished));
                item.SubItems.Add(Convert.ToString(book1.QOH));
                item.SubItems.Add(book1.Category);
                item.SubItems.Add(Convert.ToString(book1.Auhtor_Id));
                item.SubItems.Add(Convert.ToString(book1.Publisher_Id));
                listView1.Items.Add(item);
            }
        }
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            HiTech_DBEntities4 HiTechEntity = new HiTech_DBEntities4();

            Book book = new Book();

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

            book = HiTechEntity.Books.Find(ISBN);

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

            book.ISBN          = ISBN;
            book.Title         = txtBookTitle.Text;
            book.UnitPrice     = Convert.ToDouble(txtPrice.Text);
            book.YearPublished = Convert.ToInt32(txtYear.Text);
            book.QOH           = Convert.ToInt32(txtQOH.Text);
            book.Category      = txtCategory.Text;
            book.Auhtor_Id     = Convert.ToInt32(txtAuthorID.Text);
            book.Publisher_Id  = Convert.ToInt32(txtPublisherID.Text);

            HiTechEntity.SaveChanges();

            MessageBox.Show("Book saved sucessfully");
            clearText();
        }
Beispiel #8
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            HiTech_DBEntities4 HiTechEntitity = new HiTech_DBEntities4();

            var totals = from order in HiTechEntitity.Orders
                         group order by order.Customer_ID into g
                         select g.Sum(p => p.total);

            int customerId = Convert.ToInt32(txtCustID.Text);

            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));
                item.SubItems.Add(Convert.ToString("CAD " + total * 0.15));
                item.SubItems.Add(Convert.ToString("CAD " + (total + total * 0.15)));

                listView1.Items.Add(item);
            }
        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            HiTech_DBEntities4 HiTechEntity = new HiTech_DBEntities4();

            int ISBN = Convert.ToInt32(txtBookISBN.Text);
            var book = HiTechEntity.Books.Find(ISBN);

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

            MessageBox.Show("Book removed sucessfully");
        }
Beispiel #10
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            HiTech_DBEntities4 HiTechEntitity = new HiTech_DBEntities4();
            Order order   = new Order();
            int   orderId = Convert.ToInt32(txtOrderId.Text);

            order = HiTechEntitity.Orders.Find(orderId);
            if (order == null)
            {
                MessageBox.Show("Order does not exists", "Error");
                //Clear function
                return;
            }
            HiTechEntitity.Orders.Remove(order);
            HiTechEntitity.SaveChanges();
            MessageBox.Show("Order removed successfully");
            clearText();
        }
Beispiel #11
0
        private void btnShowBooks_Click(object sender, EventArgs e)
        {
            HiTech_DBEntities4 HiTechEntitity = new HiTech_DBEntities4();

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

            listView1.Items.Clear();
            foreach (var order in orderList)
            {
                //order.Customer_ID
                ListViewItem item = new ListViewItem(Convert.ToString(order.Customer_ID));
                item.SubItems.Add(Convert.ToString(order.order_ID));
                item.SubItems.Add(Convert.ToString(order.ISBN));
                item.SubItems.Add(Convert.ToString(order.Qte));
                item.SubItems.Add(order.OrderedBy);
                item.SubItems.Add(Convert.ToString(order.total));
                listView1.Items.Add(item);
            }
        }
Beispiel #12
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            HiTech_DBEntities4 HiTechEntitity = new HiTech_DBEntities4();
            Order order   = new Order();
            int   orderId = Convert.ToInt32(txtOrderId.Text);

            order = HiTechEntitity.Orders.Find(orderId);
            if (order == null)
            {
                MessageBox.Show("Order does not exists", "Error");
                //Clear function
                return;
            }
            order.Customer_ID = Convert.ToInt32(txtCustomerrId.Text);
            order.ISBN        = Convert.ToInt32(txtISBN.Text);
            order.OrderedBy   = Convert.ToString(comboBoxOrderedBy.SelectedItem);
            order.Qte         = Convert.ToInt32(txtQte.Text);
            Book book = HiTechEntitity.Books.Find(order.ISBN);

            order.total = order.Qte * book.UnitPrice;
            HiTechEntitity.SaveChanges();
            MessageBox.Show("Order updated sucessfully");
            clearText();
        }