private void txtSelectSource_DoubleClick(object sender, EventArgs e) { UserInputTextBox.SelectAll(); }
//add to order button event handling private void AddToOrderButton_Click(object sender, EventArgs e) { //declaration int Identify; //gets the available stock for the choosen option AvailableStock = (StockList2DArray[GetMealSizeIndex, GetMealTypeIndex]); try { //tries to parse user input to an integer UserInputQuantity = int.Parse(UserInputTextBox.Text); if (UserInputQuantity > 0) //checks if the input is greater than zero { //if what the user enters is equal to or less than the avalable stock if (UserInputQuantity <= AvailableStock) { DisplayPrice.Text = (UserInputQuantity * Cost).ToString(); MealTypeChoosen.Add((MealTypeListBox.SelectedItem).ToString()); MealSizeChoosen.Add((MealSizeListBox.SelectedItem).ToString()); QuantityChoosen.Add(UserInputQuantity); PriceOfChoice.Add(decimal.Parse(DisplayPrice.Text)); RunningTotal += UserInputQuantity * Cost; TotalPriceLabel.Text = RunningTotal.ToString(); CompleteOrderButton.Enabled = true; ClearButton.Enabled = true; //------------------------------------- for (Identify = MealTypeChoosen.Count - 1; Identify != MealTypeChoosen.Count; Identify++) { OrderListBox.Items.Add(MealTypeChoosen.ElementAt(Identify) + "\t" + MealSizeChoosen.ElementAt(Identify) + "\t" + QuantityChoosen.ElementAt(Identify) + "\t" + Cost.ToString() + "\t" + PriceOfChoice.ElementAt(Identify).ToString("C")); (StockList2DArray[GetMealSizeIndex, GetMealTypeIndex]) = AvailableStock - UserInputQuantity;// this should work else i am in for it } //OrderListBox.ClearSelected(); MealTypeListBox.SelectedIndex = -1; MealSizeListBox.SelectedIndex = -1; DisplayPrice.Text = ""; UserInputTextBox.Text = ""; } else// if the user input doesn't meet the above conditions i.e, greater than the available stock { MessageBox.Show("the available stock is:" + AvailableStock, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); UserInputTextBox.Text = AvailableStock.ToString(); UserInputTextBox.Focus(); UserInputTextBox.SelectAll(); DisplayPrice.Text = ""; } } else { //if the user input is negative or inavlid MessageBox.Show("Please enter a valid quantity", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Warning); UserInputTextBox.Focus(); UserInputTextBox.SelectAll(); } } catch //if user input can't be parsed { MessageBox.Show("Please enter a quantity greater than 1", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); UserInputTextBox.Focus(); UserInputTextBox.SelectAll(); } }