private void buttonDelLine_Click(object sender, EventArgs e) { orderLine newOrderLine = new orderLine(); int orId = Convert.ToInt32(comboBoxOrderId.Text.Trim()); comboBoxIsbn.Refresh(); string isbn = comboBoxIsbn.Text; orderLine or = dbEntities.orderLines.Find(orId, isbn); if (or != null) { DialogResult dialogResult = MessageBox.Show("Whould you realy like to permanent delete this Order Line?", "Some Title", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { var anOrderLine = dbEntities.orderLines.Find(orId, isbn); dbEntities.orderLines.Remove(anOrderLine); dbEntities.SaveChanges(); MessageBox.Show("Order Line Deleted successfully.", "Confirmation"); } } else { MessageBox.Show("The selected book, is not in the current order.\n" + "In this case, there is nothing to delete.", "Error"); return; } }
private void buttonAddItem_Click(object sender, EventArgs e) { orderLine newOrderLine = new orderLine(); //Check duplicate Emloyee ID int orId = Convert.ToInt32(textBoxOrderId.Text.Trim()); string isbn = comboBoxIsbn.Text.Trim(); orderLine or = dbEntities.orderLines.Find(orId, isbn); if (or != null) { MessageBox.Show("This Book already is in the order !\nYou are allowed to update the quantity only.\n" + "Otherwise delete the current Order Line and create a new one.", "Error"); comboBoxIsbn = null; return; } else { newOrderLine.OrderId = Convert.ToInt32(comboBoxOrderId.Text.Trim()); } newOrderLine.Isbn = comboBoxIsbn.Text.Trim(); newOrderLine.Quantity = Convert.ToInt32(textBoxQuantity.Text.Trim()); dbEntities.orderLines.Add(newOrderLine); dbEntities.SaveChanges(); MessageBox.Show("Order Line saved successfully", "Comformation"); }
private void buttonUpdateItem_Click(object sender, EventArgs e) { //===================================================== //Update Item by Entities Framework //===================================================== int orderId = Convert.ToInt32(comboBoxOrderId.Text.Trim()); string isbn = comboBoxIsbn.Text; orderLine updatedOrderLine = dbEntities.orderLines.Find(orderId, isbn); if (updatedOrderLine != null) { Order updatedOrder = dbEntities.Orders.Find(orderId); updatedOrderLine.Quantity = Convert.ToInt32(textBoxQuantity.Text.Trim()); updatedOrder.OrderUpdated = DateTime.Today; dbEntities.SaveChanges(); MessageBox.Show("Order updated successfully.", "Confirmation"); } else { MessageBox.Show("You are allowed to update quantity only.\n" + "Otherwise Delete the Order Line and create a new one.", "Error"); } }