/* Function name: calculateButton_Click() Version: 1 Author: Christopher Sigouin Description: Calculates the widgets workers total pay and displays a message to the user Inputs: object sender, EventArgs e Outputs: Messagebox Return value: N/A Change History: 2015.10.02 Original version by CJS */ private void calculateButton_Click(object sender, EventArgs e) { // Check for valid data entries if (IsValidInput()) { // Make a new worker object widgetWorker = new WidgetWorker(); // Make a new widget widget = new Widget(); try { // Pull the data from the fields and assign to the proper attributes widgetWorker.Name = nameTextBox.Text; widget.Quantity = Convert.ToInt32(widgetTextBox.Text); // Calculate the workers pay based on the price and quantity of the widget(s) widgetWorker.calculateWorkerPay(widget); // Enable the summary button for usage now if (summaryButton.Enabled != true) { summaryButton.Enabled = true; } // Calculate the average pay now with the entered data calculateAverageWorkerPay(); MessageBox.Show("Workers Pay: " + widgetWorker.TotalPay.ToString("C")); } catch (Exception) { MessageBox.Show("You entered invalid data. Please retry", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); nameTextBox.Clear(); widgetTextBox.Clear(); } } else { MessageBox.Show("You have fields that are empty. Please verify and try again"); } }
/* Function name: calculateWorkerPay() Version: 1 Author: Christopher Sigouin Description: Calculates the total pay for a single widget worker based on the number of widgets produced Inputs: Widget object Outputs: n/a Return value: Decimal Change History: 2015.10.02 Original version by CJS */ public decimal calculateWorkerPay(Widget widget) { totalPay = widget.Quantity * widget.Price; return totalPay; }
/* Function name: clearAllButton_Click Version: 1 Author: Christopher Sigouin Description: Requests the user to click OK or CANCEL to clear all values used in the application Inputs: object sender, EventArgs e Outputs: n/a Return value: N/A Change History: 2015.10.02 Original version by CJS */ private void clearAllButton_Click(object sender, EventArgs e) { // Confirm with the user before clearing anything DialogResult result = MessageBox.Show("Do you want to clear all data in the system?", "CLEAR ALL DATA", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if(result == DialogResult.OK) { nameTextBox.Clear(); widgetTextBox.Clear(); widgetWorker = null; widget = null; averagePay = totalWorkerPay = 0.0m; workerCount = totalWorkerWidgets = 0; // Disable the summary button again. No data present if (summaryButton.Enabled != false) { summaryButton.Enabled = false; } MessageBox.Show("All data has been cleared!"); } }
/* Function name: clearButton_Click Version: 1 Author: Christopher Sigouin Description: Clears current values and leaves any summary values untouched Inputs: object sender, EventArgs e Outputs: n/a Return value: N/A Change History: 2015.10.02 Original version by CJS */ private void clearButton_Click(object sender, EventArgs e) { nameTextBox.Clear(); widgetTextBox.Clear(); widgetWorker = null; widget = null; }