private void ItemForm_Load(object sender, EventArgs e) { switch (state) { case 0: comboBoxStallName.Enabled = true; textBoxFoodName.Enabled = true; comboBoxFoodType.Enabled = true; textBoxFoodDescription.Enabled = true; textBoxPrice.Enabled = true; SL = SQLServerConnection.GetStallList(); TL = SQLServerConnection.GetFoodTypeList(); foreach (TypeList tempList in TL) { comboBoxFoodType.Items.Add(tempList.FoodType); } foreach (StallList tempList in SL) { comboBoxStallName.Items.Add(tempList.StallName); } buttonItem.Text = "Add Item"; break; case 1: SL = SQLServerConnection.GetStallList(); TL = SQLServerConnection.GetFoodTypeList(); IL = SQLServerConnection.GetItemList(); foreach (TypeList tempList in TL) { comboBoxFoodType.Items.Add(tempList.FoodType); } foreach (StallList tempList in SL) { comboBoxStallName.Items.Add(tempList.StallName); } foreach (ItemList tempList in IL) { comboBoxFoodID.Items.Add(tempList.FoodID); } comboBoxFoodID.Enabled = true; buttonItem.Text = "Update Item"; break; case 2: SL = SQLServerConnection.GetStallList(); TL = SQLServerConnection.GetFoodTypeList(); IL = SQLServerConnection.GetItemList(); foreach (TypeList tempList in TL) { comboBoxFoodType.Items.Add(tempList.FoodType); } foreach (StallList tempList in SL) { comboBoxStallName.Items.Add(tempList.StallName); } foreach (ItemList tempList in IL) { comboBoxFoodID.Items.Add(tempList.FoodID); } comboBoxFoodID.Enabled = true; buttonItem.Text = "Delete Item"; break; default: Error("Unkown Error"); break; } }
private void comboBoxFoodID_SelectedIndexChanged(object sender, EventArgs e) { switch (state) { case 1: comboBoxStallName.Enabled = true; textBoxFoodName.Enabled = true; comboBoxFoodType.Enabled = true; textBoxFoodDescription.Enabled = true; textBoxPrice.Enabled = true; textBoxStallID.Text = IL[comboBoxFoodID.SelectedIndex].StallID.ToString(); textBoxFoodTypeID.Text = IL[comboBoxFoodID.SelectedIndex].FoodTypeID.ToString(); SL.Clear(); TL.Clear(); SL = SQLServerConnection.GetStallList(); TL = SQLServerConnection.GetFoodTypeList(); int x = 0; foreach (StallList tempList in SL) { if (tempList.StallID == Convert.ToInt32(textBoxStallID.Text)) { comboBoxStallName.SelectedIndex = x; } x++; } textBoxFoodName.Text = IL[comboBoxFoodID.SelectedIndex].FoodName; x = 0; foreach (TypeList tempList in TL) { if (tempList.FoodTypeID == Convert.ToInt32(textBoxFoodTypeID.Text)) { comboBoxFoodType.SelectedIndex = x; } x++; } textBoxFoodDescription.Text = IL[comboBoxFoodID.SelectedIndex].FoodDescription; textBoxPrice.Text = IL[comboBoxFoodID.SelectedIndex].FoodPrice.ToString("0.00"); break; case 2: textBoxStallID.Text = IL[comboBoxFoodID.SelectedIndex].StallID.ToString(); textBoxFoodTypeID.Text = IL[comboBoxFoodID.SelectedIndex].FoodTypeID.ToString(); SL.Clear(); TL.Clear(); SL = SQLServerConnection.GetStallList(); TL = SQLServerConnection.GetFoodTypeList(); int y = 0; foreach (StallList tempList in SL) { if (tempList.StallID == Convert.ToInt32(textBoxStallID.Text)) { comboBoxStallName.SelectedIndex = y; } y++; } textBoxFoodName.Text = IL[comboBoxFoodID.SelectedIndex].FoodName; y = 0; foreach (TypeList tempList in TL) { if (tempList.FoodTypeID == Convert.ToInt32(textBoxFoodTypeID.Text)) { comboBoxFoodType.SelectedIndex = y; } y++; } textBoxFoodDescription.Text = IL[comboBoxFoodID.SelectedIndex].FoodDescription; textBoxPrice.Text = IL[comboBoxFoodID.SelectedIndex].FoodPrice.ToString("0.00"); break; default: Error("Unkown Error"); break; } }