/// <summary> /// Opens the Confirmation Form /// </summary> /// <param name="sender">event handler</param> /// <param name="e">event argument</param> private void confirmationToolStripMenuItem_Click(object sender, EventArgs e) { try { FormConfirmation myConfirmation = new FormConfirmation(); myConfirmation.ShowDialog(); } catch (Exception ex) { MessageBox.Show("No ordered Items"); } }
/// <summary> /// Submits a pizza order and takes the user to the confirmation screen. /// The users selections are used to create an Item that holds the customer's /// order information. Data is validated before the order Item is created. /// </summary> /// <param name="sender">control initiating event</param> /// <param name="e">event argument</param> private void buttonSubmit_Click(object sender, EventArgs e) { if (DataIsValid()) { //Item variable to hold the order information Item myItem = new Item(); //Checks the Size GroupBox and determines which RadioButton checked foreach (RadioButton rb in groupBoxSize.Controls) { if (rb.Checked) { //This is a bit hacky. Uses the Text property of the //RadioButton to set the value of Item Size Property. //Trims the string from the '$' to the end. //TODO: Develop a better method to handle this in future. myItem.Size = rb.Text.Remove(rb.Text.IndexOf("$")).Trim(); } } //Checks the Sauce GroupBox and determines which RadioButton checked foreach (RadioButton rb in groupBoxSauce.Controls) { if (rb.Checked) { //Determines if None RadioButton selected if (rb == radioButtonNone) { //formats sauce description if None selected description = "No sauce"; } else { //See hacky note above. Adds sauce to the end of the name //This information is passed to the description variable //defined above. Eventually added to the Item Description //Property below. description = rb.Text + " sauce"; } } } //Checks the Crust GroupBox and determines which RadioButton checked foreach (RadioButton rb in groupBoxCrust.Controls) { if (rb.Checked) { //Uses the RadioButton Text Property and passes the value //to the Item Crust Property. myItem.Crust = rb.Text; } } //If no topping CheckBox is not checked if (!checkBoxNoTop.Checked) { //Loops through the Toppings the customer has selected foreach (string topping in listBoxToppings.Items) { //Uses the Format Description method to create the description //assigns the value the Item Description Property. //See above for information about Format Description Method. myItem.Description = FormatDescription(topping); } } else { //assigns the sauce description to the Item Description Property. //This condition was implemented to solve a bug //where sauce data would not be assigned to the Item Description //if "No Toppings" was selected. //TODO: Develop better functionality in Format Description Method //to fix side effect and reduce the amount of code. myItem.Description = description; } //assigns the quantity amount entered to the Item's Quantity Property myItem.Quantity = int.Parse(textBoxQty.Text); //Calculates the total Price of the Item. //Calculate Price is defined in Item Class Documentation. //Calculate Topping Price is defined above. myItem.CalculatePrice(CalculateToppingsPrice (listBoxToppings.Items.Count)); //Calls overloaded Constructor of Confirmation Form //Takes an Item so data can be loaded into the Confirmation Form FormConfirmation myConfirmation = new FormConfirmation(myItem); myConfirmation.ShowDialog(); } }