public override void OnClickOK(object sender, EventArgs e) { //Check if the user is sure CP_Popup_Sure popup = new CP_Popup_Sure(); popup.SetAsChangeStock(item.Name); popup.ShowDialog(); if (!(popup.DialogResult == DialogResult.OK)) { DialogResult = DialogResult.Cancel; Close(); } //Store the value of the input bool stockParsed = int.TryParse(CP_Popup_ChangeStock_txtStock.Text, out int stock); //Close the form if the parse fails if (!stockParsed) { Close(); } //Check whether to use the Dish or the drink Service if (item.GetType() == typeof(Dish)) { Dish_Service dishService = new Dish_Service(); //Modify the stock try { dishService.ModifyStock(item.Id, stock); } catch (Exception ex) { ErrorHandler.Instance.HandleError("Voorraad van " + item.Id + " kon niet aangepast worden!", "Voorraad niet aangepast", ex); //Tell the ControlPanel form that the action didn't succeed DialogResult = DialogResult.Cancel; } } else { Drink_Service drinkService = new Drink_Service(); //Modify the stock try { drinkService.ModifyStock(item.Id, stock); } catch (Exception ex) { ErrorHandler.Instance.HandleError("Voorraad van " + item.Id + " kon niet aangepast worden!", "Voorraad niet aangepast", ex); //Tell the ControlPanel form that the action didn't succeed DialogResult = DialogResult.Cancel; } } }
private void bestelBtn_Click(object sender, EventArgs e) { orderService = new Order_Service(); tableService = new Table_Service(); order.EmployeeId = employee.Id; billService = new Bill_Service(); try { bill = billService.GetBillByTableId(tafel.Number); } catch (Exception d) { orders = new List <Order>(); bill = new Bill(DateTime.Now, tafel, orders, employee, false); billService.AddBill(bill); MessageBox.Show("Bestelling is geplaatst.", "Attentie", MessageBoxButtons.OK, MessageBoxIcon.Information); orderService.AddOrderWhereBillIdIs(order, bill.Id); tafel.Occupied = true; tableService.ModifyTable(tafel); return; } if (bill.Payed == false) { orderService.AddOrderWhereBillIdIs(order, bill.Id); MessageBox.Show("Bestelling is geplaatst.", "Attentie", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { orders = new List <Order>(); bill = new Bill(DateTime.Now, tafel, orders, employee, false); billService.AddBill(bill); MessageBox.Show("Bestelling is geplaatst.", "Attentie", MessageBoxButtons.OK, MessageBoxIcon.Information); orderService.AddOrderWhereBillIdIs(order, bill.Id); tafel.Occupied = true; tableService.ModifyTable(tafel); } foreach (Dish dish in order.Dishes) { dishService = new Dish_Service(); dishService.ModifyStock(dish.Id, dish.Stock - 1); } foreach (Drink drink in order.Drinks) { drinkService = new Drink_Service(); drinkService.ModifyStock(drink.Id, drink.Stock - 1); } order = new Order(); }