private void buttonSearchOL_Click(object sender, EventArgs e) { //OrderLineBook ol = dbEntities.OrderLineBooks.Find(Convert.ToInt32(maskedTextBoxSearchOLID.Text)); //if (ol != null) //{ // textBoxOLID.Text = ol.OlBooksId.ToString(); // comboBoxOrderID.Text = ol.OrderId.ToString(); // comboBoxBookID.Text = ol.BookId.ToString(); // textBoxOrderLineQuantity.Text = ol.OlQuantity.ToString(); //} //Solution using LINQ int idSearch = Convert.ToInt32(maskedTextBoxSearchOLID.Text); OrderLineBook search = (from num in dbEntities.OrderLineBooks where num.OlBooksId == idSearch select num).Single <OrderLineBook>(); if (search != null) { textBoxOLID.Text = search.OlBooksId.ToString(); comboBoxOrderID.Text = search.OrderId.ToString(); comboBoxBookID.Text = search.BookId.ToString(); textBoxOrderLineQuantity.Text = search.OlQuantity.ToString(); } else { MessageBox.Show("Order line ID not found"); } }
private void buttonDeleteOL_Click(object sender, EventArgs e) { OrderLineBook ol = dbEntities.OrderLineBooks.Find(Convert.ToInt32(textBoxOLID.Text)); dbEntities.OrderLineBooks.Remove(ol); dbEntities.SaveChanges(); MessageBox.Show("The order line was deleted."); }
private void buttonUpdateOL_Click(object sender, EventArgs e) { OrderLineBook ol = dbEntities.OrderLineBooks.Find(Convert.ToInt32(textBoxOLID.Text)); ol.OrderId = Convert.ToInt32(comboBoxOrderID.Text); ol.BookId = Convert.ToInt32(comboBoxBookID.Text); ol.OlQuantity = Convert.ToInt32(textBoxOrderLineQuantity.Text); dbEntities.SaveChanges(); MessageBox.Show("The order line was modified"); }
private void buttonSaveOL_Click(object sender, EventArgs e) { OrderLineBook bookOrder = new OrderLineBook(); bookOrder.OrderId = Convert.ToInt32(comboBoxOrderID.Text); bookOrder.BookId = Convert.ToInt32(comboBoxBookID.Text); bookOrder.OlQuantity = Convert.ToInt32(textBoxOrderLineQuantity.Text); dbEntities.OrderLineBooks.Add(bookOrder); dbEntities.SaveChanges(); MessageBox.Show("The order line was saved"); }