I have two comboBoxes, one that lists the 7 days of the week and the other with a set of times (7 different times, each as a string).
The problem i'm having is i want to be able to stop the user from being able to select certain items depending on the day/time selected.
An example being that on a Monday the 7-9am comboBox option should not be available due to it being "Pre-Booked", if that makes sense.
The days and times are used in relation to a 7x7 array, each index in the combo boxes relating to an element in the array so depending on the selected index in the combo boxes i can use the correct array element.
What would be the best way to go about it? I've tried a series of if statements but it got to a point where it would just slip through them and continue to process data when its not meant to.
EDIT:
Added example attempt for jmatthews3865
private void buttonOK_Click(object sender, EventArgs e)
{
if (comboBoxTime.SelectedIndex != 0 && comboBoxDay.SelectedIndex != 5 | comboBoxDay.SelectedIndex != 6)
{
if (comboBoxTime.SelectedIndex != 1 | comboBoxTime.SelectedIndex != 2 | comboBoxTime.SelectedIndex != 3
&& comboBoxDay.SelectedIndex != 0 | comboBoxDay.SelectedIndex != 1 | comboBoxDay.SelectedIndex != 2
| comboBoxDay.SelectedIndex != 3 | comboBoxDay.SelectedIndex != 4)
{
if (comboBoxTime.SelectedIndex != 5 | comboBoxTime.SelectedIndex != 6 && comboBoxDay.SelectedIndex != 5
| comboBoxDay.SelectedIndex != 6)
{
lock (this)
{
int date = this.comboBoxDay.SelectedIndex;
int time = this.comboBoxTime.SelectedIndex;
if (IsUser)
{
string fName = textBoxFName.Text;
string lName = textBoxLName.Text;
string pCode = textBoxPCode.Text;
AddUserBooking(date, time, fName, lName, pCode);
}
else
{
int mNo = int.Parse(textBoxMNo.Text);
AddMemberBooking(date, time, mNo);
}
}
CloseBookingForm();
}
}
}
else
{
MessageBox.Show("Select a valid Date/Time and try again");
}
}
It seems to work fine on the first if statement block, fails past that though.
If the selected day is Saturday/Sunday ([5],[6]) then the times [0] and [5],[6] are unavailable. From Monday to Friday the times including [1] to [3] are unavailable.
If it wasn't for my extremely short deadline and the lecturer who can't make a sensible assignment then i'd gladly refactor all of it.
EDIT2:
I've managed to implement a system that seems to be working fairly well. It's based on Steven Adams solution which essentially uses an if statament in a boolean method. I call the method before processing the booking and if it returns true then the booking can be made, otherwise a message box is shown with the appropiate error.