private void checkOutButton_Click(object sender, RoutedEventArgs e) { string paymentStr = paymentTxt.Text.Trim(); int payment; bool success = int.TryParse(paymentStr, out payment); if (!success) { errorLbl.Text = "Payment must be a number!"; } else if (totalPrice == 0 || tax == 0) { errorLbl.Text = "Please input Seat ID!"; } else { int change = (totalPrice + tax) - payment; if (change > 0) { errorLbl.Text = "Payment is not enough!"; } else if (change <= 0) { SeatMediator mediator = new SeatMediator(); OrderMediator omediator = new OrderMediator(); Order customerOrder = omediator.getOrderBySeat(seatID); changeTxt.Text = "Change = \t\tRp. " + Math.Abs(change).ToString(); RestaurantTransactionMediator tmediator = new RestaurantTransactionMediator(); RestaurantTransactionFactory tfactory = new RestaurantTransactionFactory(); RestaurantTransaction transaction = tmediator.addRestaurantTransaction(tfactory.createNewRestaurantTransaction(seatID)); if (tmediator.addDetailRestaurantTransaction(transaction.transactionID, customerOrder.orderID) == null) { MessageBox.Show("Checkout failed!"); } else { MessageBox.Show("Checkout success!"); } //update seat dan ordernya Seat customerSeat = mediator.getSeat(seatID); customerSeat.status = "Available"; customerSeat = mediator.updateSeat(seatID, customerSeat); customerOrder.status = "Finished"; customerOrder = omediator.updateOrder(customerOrder.orderID, customerOrder); } } }
private void Window_Loaded(object sender, RoutedEventArgs e) { SeatMediator mediator = new SeatMediator(); seatView.ItemsSource = mediator.getAllSeat(); }
private void submitBtn_Click(object sender, RoutedEventArgs e) { string seatIDStr = seatIDTxt.Text.Trim(); string foodIDStr = foodIDTxt.Text.Trim(); string quantityStr = quantityTxt.Text.Trim(); int seatID, foodID, quantity; bool success = int.TryParse(seatIDStr, out seatID); bool success2 = int.TryParse(foodIDStr, out foodID); bool success3 = int.TryParse(quantityStr, out quantity); if (!success) { errorLbl.Text = "Seat ID must be a number"; } else if (!success2) { errorLbl.Text = "Food ID must be a number"; } else if (!success3) { errorLbl.Text = "Quantity must be a number"; } else { OrderMediator mediator = new OrderMediator(); SeatMediator smediator = new SeatMediator(); FoodMediator fmediator = new FoodMediator(); OrderFactory factory = new OrderFactory(); Order order = mediator.getOrderBySeat(seatID); Seat seat = smediator.getSeat(seatID); Food food = fmediator.getFood(foodID); if (seat == null) { errorLbl.Text = "Seat doesn't exist"; return; } if (food == null) { errorLbl.Text = "Food doesn't exist"; return; } if (order == null) { mediator.addOrder(factory.createNewOrder(seatID)); seat.status = "Unavailable"; seat = smediator.updateSeat(seatID, seat); } order = mediator.getOrderBySeat(seatID); OrderDetail existingOrder = mediator.getOrderDetail(order.orderID, foodID); OrderDetail orderDetail; if (existingOrder == null) { orderDetail = mediator.addOrderDetail(factory.createNewOrderDetail(order.orderID, foodID, quantity)); } else { existingOrder.quantity += quantity; orderDetail = mediator.updateOrderDetail(order.orderID, existingOrder); } if (orderDetail == null) { MessageBox.Show("Input order failed!"); } else { MessageBox.Show("Input order success!"); } } }