namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
int x;
int y;
for (x = 1; x < 11; x++)
{
if (x == 1)
{
listBox1.Items.Add (x + " person");
}
else
{
listBox1.Items.Add (x + " people");
}
}
string a;
string b;
int arraynumber = 0;
int addtime = 10;
for (x = 1; x < 3; x++)
{
for (y = 1; y < 3; y++)
{
if (y == 1)
{
a = ".00";
b = ".30";
globals.thetimes[arraynumber] = addtime + a + " - " + addtime + b;
}
else if (y == 2)
{
a = ".30";
b = ".00";
globals.thetimes[arraynumber] = addtime + a + " - " + (addtime + 1) + b;
}
arraynumber = arraynumber + 1;
}
addtime = addtime + 1;
}
label4.Text = "Bookings" + "\n";
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
int x;
listBox2.Items.Clear();
listBox3.Items.Clear();
if (listBox1.SelectedIndex < 5)
{
for (x = 1; x < 5; x++)
{
if (globals.roomtime1[x - 1] == "")
{
listBox2.Items.Add(globals.thetimes[x - 1]);
}
if (globals.roomtime2[x - 1] == "")
{
listBox3.Items.Add(globals.thetimes[x - 1]);
}
}
}
else if (listBox1.SelectedIndex > 4)
{
for (x = 1; x < 5; x++)
{
if (globals.roomtime2[x - 1] == "")
{
listBox3.Items.Add(globals.thetimes[x - 1]);
}
}
}
}
private void button1_Click(object sender, EventArgs e)
{
int x;
if (listBox1.SelectedIndex == -1)
{
MessageBox.Show ("Please select the number of people.");
return;
}
if (listBox1.SelectedIndex > -1 && listBox1.SelectedIndex < 5)
{
if (listBox2.SelectedIndex == -1 && listBox3.SelectedIndex == -1)
{
MessageBox.Show ("Please select either Room 1 or Room 2's time.");
return;
}
if (listBox2.SelectedIndex > -1 && listBox3.SelectedIndex > -1)
{
MessageBox.Show ("Please select either Room 1 or Room 2's time.");
listBox2.SelectedIndex = -1;
listBox3.SelectedIndex = -1;
return;
}
if (listBox2.SelectedIndex > -1)
{
for (x = 1; x < 5; x++)
{
if (listBox2.SelectedItem == globals.thetimes[x - 1])
{
globals.roomtime1[x - 1] = globals.thetimes[x - 1];
label4.Text = label4.Text + "\n" + listBox1.SelectedItem + " --- Room 1 - " + globals.roomtime1[x - 1];
}
}
globals.total = globals.total + 1;
}
else if (listBox3.SelectedIndex > -1)
{
for (x = 1; x < 5; x++)
{
if (listBox3.SelectedItem == globals.thetimes[x - 1])
{
globals.roomtime2[x - 1] = globals.thetimes[x - 1];
label4.Text = label4.Text + "\n" + listBox1.SelectedItem + " --- Room 2 - " + globals.roomtime2[x - 1];
}
}
globals.total = globals.total + 1;
}
}
else if (listBox1.SelectedIndex > 4 && listBox1.SelectedIndex < 10)
{
if (listBox3.SelectedIndex == -1)
{
MessageBox.Show ("Please select Room 2's time.");
return;
}
for (x = 1; x < 5; x++)
{
if (listBox3.SelectedItem == globals.thetimes[x - 1])
{
globals.roomtime2[x - 1] = globals.thetimes[x - 1];
label4.Text = label4.Text + "\n" + listBox1.SelectedItem + " --- Room 2 - " + globals.roomtime2[x - 1];
}
}
globals.total = globals.total + 1;
}
if (globals.total == 8)
{
listBox1.Items.Clear();
listBox1.Enabled = false;
listBox2.Enabled = false;
listBox3.Enabled = false;
button1.Enabled = false;
label4.Text = label4.Text + "\n\n" + "No more rooms available.";
}
listBox1.SelectedIndex = -1;
listBox2.Items.Clear();
listBox3.Items.Clear();
}
}
static class globals
{
public static string[] thetimes = {"", "", "", ""};
public static string[] roomtime1 = {"", "", "", ""};
public static string[] roomtime2 = {"", "", "", ""};
public static int total = 0;
}
}