/// <summary> /// Method checks if the value input for monthly sales is a valid number. If is is the number /// is converted to a dollar figure else a message is shown that the information /// is not valid and the field is cleared. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TotalMonthlySalesTextBox_Leave(object sender, EventArgs e) { double TotalSales; if (TotalMonthlySalesTextBox.Text != "") { try { TotalSales = Convert.ToDouble(TotalMonthlySalesTextBox.Text); TotalMonthlySalesTextBox.Text = TotalSales.ToString("C2"); } catch (Exception exception) { try { TotalSales = double.Parse(TotalMonthlySalesTextBox.Text, NumberStyles.Currency); TotalMonthlySalesTextBox.Text = TotalSales.ToString("C2"); } catch { MessageBox.Show("Invalid Data Entered", "Input Error"); Debug.WriteLine(exception.Message); TotalMonthlySalesTextBox.Focus(); TotalMonthlySalesTextBox.Text = ""; TotalMonthlySalesTextBox.SelectAll(); } } } }
/// <summary> /// This method calculates the total sales bonus and displays the total on /// the form /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CalculateButton_Click(object sender, EventArgs e) { double PercentHoursWorked; double TotalHoursWorked; double TotalMonthlySales; double TotalBonusAmount; double SalesBonus; try { TotalHoursWorked = Convert.ToDouble(TotalHoursWorkedNumericUpDown.Value); PercentHoursWorked = TotalHoursWorked / 160; TotalMonthlySales = double.Parse(TotalMonthlySalesTextBox.Text, NumberStyles.Currency); TotalBonusAmount = TotalMonthlySales * 0.02; SalesBonus = PercentHoursWorked * TotalBonusAmount; SalesBonusTextBox.Text = SalesBonus.ToString("C2"); } catch (Exception exception) { MessageBox.Show("Invalid Monthly Sales Entered", "Input Error"); Debug.WriteLine(exception.Message); TotalMonthlySalesTextBox.Text = ""; TotalMonthlySalesTextBox.Focus(); } }