Exemplo n.º 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;
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
0
        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");
        }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
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();
        }