//search button click private void button1_Click(object sender, EventArgs e) { //data validation //check if the field is empty if (textBox1.Text == "") { MessageBox.Show("Please input a Booking ID", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //https://msdn.microsoft.com/en-us/library/system.windows.forms.messageboxicon(v=vs.110).aspx textBox1.Focus(); //focuses on text box with error return; } //if the guest doesnt exist else if (bookingController.FindByBookingID(textBox1.Text) == null) { MessageBox.Show("Booking not found", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox1.Text = ""; textBox1.Focus(); return; } else { //populate textboxes with relevenat booking details Booking temp = bookingController.FindByBookingID(textBox1.Text); //if the booing has passed if ((DateTime.Today.Date) >= Convert.ToDateTime(temp.StartDate).Date) { if (myState == thisFormState.Delete) { if ((DateTime.Today.Date) > Convert.ToDateTime(temp.EndDate).Date) { MessageBox.Show("Booking cannot be deleted it as it has already lapsed", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox1.Text = ""; textBox1.Focus(); return; } else { MessageBox.Show("Booking cannot be deleted as it is in progress", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox1.Text = ""; textBox1.Focus(); return; } } else { if ((DateTime.Today.Date) > Convert.ToDateTime(temp.EndDate).Date) { MessageBox.Show("Booking cannot be editted it as it has already lapsed", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox1.Text = ""; textBox1.Focus(); return; } else { MessageBox.Show("Booking cannot be editted as it is in progress", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox1.Text = ""; textBox1.Focus(); return; } } } //if the guest exists //toggle search functionality off ToggleSearchFunctionality(false); //show all the controll and button 3 ShowTextFieldsAndLabels(true); button3.Visible = true; textBox2.Text = temp.BookingID; textBox3.Text = temp.GuestID; textBox4.Text = temp.RoomNumber; textBox5.Text = temp.ReservationDate; textBox6.Text = temp.StartDate; textBox7.Text = temp.EndDate; textBox8.Text = temp.NoOfGuests; textBox9.Text = temp.Price.ToString(); textBox10.Text = temp.DepositAmount.ToString(); textBox11.Text = temp.DepositPaid.ToString(); if (myState == thisFormState.Delete) { //change relevant labels name label2.Text = "Delete Booking with BookingID: "; button3.Text = "Delete"; //toggle enabled off ToggleTextBoxesEnabled(false); } if (myState == thisFormState.Edit) { //change relevant labels name label2.Text = "Edit Booking with BookingID: "; button3.Text = "Save"; //toggle enabled on ToggleTextBoxesEnabled(true); //set relevenat text boxes to false textBox2.Enabled = false; textBox3.Enabled = false; textBox4.Enabled = false; textBox5.Enabled = false; textBox6.Visible = false; textBox7.Visible = false; textBox8.Visible = false; textBox9.Enabled = false; textBox10.Enabled = false; textBox11.Enabled = false; dateTimePicker1.Value = (Convert.ToDateTime(textBox6.Text)).Date; dateTimePicker2.Value = (Convert.ToDateTime(textBox7.Text)).Date; dateTimePicker1.Visible = true; dateTimePicker2.Visible = true; comboBox1.Visible = true; comboBox1.Text = textBox8.Text; } } }