Example #1
0
        /*
            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");
            }

        }