private void button3_Click(object sender, EventArgs e) { Booking b = new Booking(); b.BookingID = textBox2.Text; b.GuestID = textBox3.Text; b.RoomNumber = textBox4.Text; b.ReservationDate = textBox5.Text; b.StartDate = textBox6.Text; b.EndDate = textBox7.Text; b.NoOfGuests = textBox8.Text; b.Price = Convert.ToDecimal(textBox9.Text); b.DepositAmount = Convert.ToDecimal(textBox10.Text); b.DepositPaid = textBox11.Text; if (myState == thisFormState.Delete) { DialogResult result = MessageBox.Show("Are you sure you want to delete booking", "Delete guest", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); //populate the text boxes if (result == DialogResult.Yes) { //we must delete the guest tell them guest has been successfully deleted bookingController.Delete(b); MessageBox.Show("Booking has been succesfully deleted", "Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Hide(); } else { //reset the controls ShowTextFieldsAndLabels(false); ResetTextBoxes(); button3.Visible = false; ToggleSearchFunctionality(true); } } if (myState == thisFormState.Edit) { //validate that start date less than end date if (dateTimePicker1.Value.Date > dateTimePicker2.Value.Date) { MessageBox.Show("Start date value cannot be greater than end date value", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Collection <Room> avail = bookingController.CheckAvailability(dateTimePicker1.Value, dateTimePicker2.Value, roomController.AllRooms, b); //ensure that the booking is actually available if (avail.Count == 0) { MessageBox.Show("New Dates are unvailable", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { //set the room Number b.RoomNumber = avail[0].RoomNumber; //set the start date b.StartDate = dateTimePicker1.Value.ToShortDateString(); //set the end date b.EndDate = dateTimePicker2.Value.ToShortDateString(); //set the price b.Price = bookingController.CalculateBookingPrice(dateTimePicker1.Value, dateTimePicker2.Value, roomRateController.AllRoomRates); //set the deposit b.DepositAmount = (b.Price / 10); //set the deposit paid to false b.DepositPaid = "false"; //set number of guests b.NoOfGuests = comboBox1.Text; bookingController.Edit(b); MessageBox.Show("Your booking has been successfully changed", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Hide(); return; } } }
private void button2_Click(object sender, EventArgs e) { //capture the booking details from the textboxes if (comboBox1.SelectedIndex == -1)//Nothing selected { MessageBox.Show("Please select number of guests from the drop down list", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); comboBox1.Focus(); return; } else if (dateTimePicker2.Value < dateTimePicker1.Value) { MessageBox.Show("Check out date should be a later date than the check in date", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); dateTimePicker1.Focus(); return; } else { //check the availability Collection <Room> Avail; Avail = bookingController.CheckAvailability(dateTimePicker1.Value.Date, dateTimePicker2.Value.Date, roomController.AllRooms); DialogResult result; Booking aBooking; //if there are bookings available if (Avail.Count() > 0) { result = MessageBox.Show("Booking for " + dateTimePicker1.Value.ToShortDateString() + " - " + dateTimePicker2.Value.ToShortDateString() + " is available\nClick yes to confirm", "Confirm Reservation", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (result == DialogResult.Yes) { this.Hide(); //make the booking with all the fields we currently have aBooking = new Booking(); aBooking.BookingID = bookingController.GenerateBookingID(); aBooking.ReservationDate = DateTime.Today.ToShortDateString(); aBooking.StartDate = dateTimePicker1.Value.ToShortDateString(); aBooking.EndDate = dateTimePicker2.Value.ToShortDateString(); aBooking.RoomNumber = Avail[0].RoomNumber; //assigned to the first available room aBooking.NoOfGuests = comboBox1.SelectedItem.ToString(); aBooking.Price = bookingController.CalculateBookingPrice(dateTimePicker1.Value, dateTimePicker2.Value, roomRateController.AllRoomRates); aBooking.DepositAmount = (aBooking.Price / 10); aBooking.DepositPaid = "false"; ReservationDetailsDisplayForm obj = new ReservationDetailsDisplayForm(bookingController, roomController, guestController, aBooking, paymentController); //this must change to the capture guest details obj.Show(); } if (result == DialogResult.No) //if they want to stay on this page { } } //if there are no bookings available else { result = MessageBox.Show("Reservation unavailable\nPlease select new dates", "Reservation Unvailable", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); //to select new dates if (result == DialogResult.OK) { } } } }