private void checkInBtn_Click(object sender, RoutedEventArgs e) { int roomID; string customerCardID = customerCardIDTxt.Text.Trim(); string roomIDStr = roomIDTxt.Text.Trim(); DateTime?checkInDate = checkInDatepicker.SelectedDate; DateTime?checkOutDate = checkOutDatepicker.SelectedDate; bool success = int.TryParse(roomIDStr, out roomID); MessageBox.Show(DateTime.Now.Hour.ToString()); if (!success) { errorLbl.Text = "Room ID must be a number"; } else if (DateTime.Now.Hour <= 10) { errorLbl.Text = "Check in time is 10 AM"; } else if (customerCardID == "" || !checkInDate.HasValue || !checkOutDate.HasValue) { errorLbl.Text = "Please input all field!"; } else { RoomMediator rmediator = new RoomMediator(); Room room = rmediator.getRoom(roomID); if (room == null || room.status == "Not Available") { errorLbl.Text = "Room is not available"; } else { CustomerMediator cmediator = new CustomerMediator(); Customer customer = cmediator.getCustomer(customerCardID); if (customer == null) { showField(); errorLbl.Text = "Please register customer!"; } else { ReservationMediator mediator = new ReservationMediator(); ReservationFactory factory = new ReservationFactory(); Reservation reservation = mediator.addReservation(factory.createNewReservation(customer.customerID, roomID, checkInDate, checkOutDate)); room.status = "Not Available"; room = rmediator.updateRoom(roomID, room); totalPriceTxt.Text = "Total Price = Rp. " + room.price; if (reservation == null) { MessageBox.Show("Reservation failed!"); } else { MessageBox.Show("Reservation success!"); } } } } }
private void checkOutBtn_Click(object sender, RoutedEventArgs e) { string reservationIDStr = reservationIDTxt.Text.Trim(); string damageCostStr = damageCostTxt.Text.Trim(); string paymentStr = paymentTxt.Text.Trim(); int reservationID, damageCost, payment; bool success = int.TryParse(reservationIDStr, out reservationID); bool success2 = int.TryParse(damageCostStr, out damageCost); bool success3 = int.TryParse(paymentStr, out payment); if (!success || !success2 || !success3) { errorLbl.Text = "Reservation ID, Damage Cost, Payment must be a number!"; } else if (DateTime.Now.Hour <= 8) { errorLbl.Text = "Check out time is 8 AM"; } else { int change = totalPrice - payment; if (change > 0) { errorLbl.Text = "Payment is not enough!"; } else if (change <= 0) { HotelTransactionMediator mediator = new HotelTransactionMediator(); RoomMediator romediator = new RoomMediator(); ReservationMediator rmediator = new ReservationMediator(); HotelTransactionFactory factory = new HotelTransactionFactory(); changeLbl.Text = "Change = Rp. " + Math.Abs(change).ToString(); Reservation reservation = rmediator.getReservation(reservationID); HotelTransaction transaction = mediator.addHotelTransaction(factory.createNewHotelTransaction((int)reservation.customerID, (int)reservation.roomID, reservation.checkInDate, reservation.checkOutDate)); if (transaction == null) { MessageBox.Show("Checkout failed!"); } else { MessageBox.Show("Checkout success!"); } reservation.status = "Finished"; reservation = rmediator.updateReservation(reservation.reservationID, reservation); Room room = romediator.getRoom((int)reservation.roomID); room.status = "Available"; room = romediator.updateRoom(room.roomID, room); } } }
private void checkPriceBtn_Click(object sender, RoutedEventArgs e) { string reservationIDStr = reservationIDTxt.Text.Trim(); string damageCostStr = damageCostTxt.Text.Trim(); int reservationID, damageCost = 0; bool success = int.TryParse(reservationIDStr, out reservationID); bool success2 = int.TryParse(damageCostStr, out damageCost); if (!success || !success2) { errorLbl.Text = "Reservation ID and Damage Cost must be a number!"; } else { RoomMediator mediator = new RoomMediator(); ReservationMediator rmediator = new ReservationMediator(); Reservation reservation = rmediator.getReservation(reservationID); Room room = mediator.getRoom((int)reservation.roomID); totalPrice = (int)room.price + damageCost; totalPriceLbl.Text = "Total Price = Rp. " + (totalPrice).ToString(); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { RoomMediator mediator = new RoomMediator(); roomView.ItemsSource = mediator.getAllRoom(); }