// Button 'Check out' in the room section // Validation: Room is marked as checked in > Date for checkout is today -> Guest has active messages // Checkout procedure: Potential reimbursement -> Payment process -> // Mark folio with paid or due date -> Mark room for housekeeping -> Mark room reservation as checked out and inactive private void buttonCheckoutRoom_Click(object sender, EventArgs e) { // Make sure datagridview has selection if (dataGridViewRoom.SelectedRows.Count > 0 && dataGridViewRoom.CurrentRow != null) { // Validation variables Boolean checkedout = false; Boolean checkoutdate = true; Boolean message = false; // Reference variables int roomid = Convert.ToInt32(dataGridViewRoom.CurrentRow.Cells[3].Value); int reservationid = Convert.ToInt32(dataGridViewRoom.CurrentRow.Cells[0].Value); // Confirm checkout DialogResult confirmCheckout = MessageBox.Show("Checking out roomnumber " + roomid + "\nAre you sure you want to continue?", "Check out", MessageBoxButtons.YesNo); if (confirmCheckout == DialogResult.Yes) { // Check that reservation checkout date is today MySqlDataReader getRoomCheckoutDate = DBGetData.GetRoomCheckoutDate(reservationid); if (getRoomCheckoutDate.Read()) { DateTime date = Convert.ToDateTime(getRoomCheckoutDate[0]); if (date != DateTime.Today) { checkoutdate = false; } if (!checkoutdate) { new StatusMessage("Room reservation not marked for checkout today."); } } getRoomCheckoutDate.Dispose(); // Yes/no continue dialogue if checkout is early if (!checkoutdate) { DialogResult continueCheckout = MessageBox.Show( "Room is not flagged for checkout today" + "\nAre you sure you want to continue?", "Warning!", MessageBoxButtons.YesNo); if (continueCheckout == DialogResult.Yes) { checkoutdate = true; } } // Check that reservation is checked in if (DBGetData.GetRoomCheckedin(reservationid) < 1) { checkedout = true; } if (checkedout) { new StatusMessage("Room reservation has not checked in or already checked out."); } if (!checkedout && checkoutdate) { // Check if guest has undelivered messages MySqlDataReader getRoomMessages = DBGetData.GetRoomMessages(reservationid); while (getRoomMessages.Read()) { message = true; MessageBox.Show("Date recieved: " + getRoomMessages.GetDateTime(0) + "\nFrom: " + getRoomMessages.GetString(1) + "\n\n" + getRoomMessages.GetString(2), "Message to guest"); } getRoomMessages.Dispose(); // Mark messages as inactive if any if (message) { DBSetData.RoomreservationUpdateMessages(reservationid); } // Check if guest has more than one room reservation checked in int roomcount = DBGetData.GetRoomCount(reservationid); // Do checkout process DBSetData.RoomreservationCheckout(reservationid); DisplayDefaultRoom(); this.Refresh(); new StatusMessage("Room reservation for room " + roomid + " has been flagged for housekeeping and checked out."); // Print customer folio total for the last room checkout if (roomcount == 1) { MySqlDataReader getFolioTotal = DBGetData.GetRoomCheckoutTotal(reservationid); if (getFolioTotal.Read()) { Decimal foliototal = getFolioTotal.GetDecimal(0); // Payment options // Yes -> Cash/card, No -> Invoice bill DialogResult paymentCheckout = MessageBox.Show("Payment total: " + foliototal + "\n\n'Yes' for immidiate payment with cash or creditcard," + "\n'No' for invoice with due date 3 weeks from today.", "Payment options", MessageBoxButtons.YesNo); // Mark folio as paid if (paymentCheckout == DialogResult.Yes) { DBSetData.RoomreservationFolioPaid(reservationid); } // Mark folio with duedate else if (paymentCheckout == DialogResult.No) { DBSetData.RoomreservationFolioDue(reservationid); } } getFolioTotal.Dispose(); } } } } }