>using System; >using System.Collections.Generic; >using System.ComponentModel; >using System.Data; >using System.Drawing; >using System.Text; >using System.Windows.Forms; > >namespace CarCareCenter >{ > public partial class CarCareForm : Form > { > private const decimal > decStereoSystem = 425.76M, > decLeatherInterior = 987.41M, > decComputerNavigation = 1741.23M, > decStandardFinish = 0M, > decPearlizeFinish = 345.72M, > decCustomizedDetailing = 599.99M, > decTaxRate = 0.08M; > > private decimal decTradeInAllowance = 0, decSubTotal = 0, > decSalesTax = 0, decAmountDue = 0, decAccessoriesTotal = 0; > > public CarCareForm() > { > InitializeComponent(); > } > > private void CarCareForm_Load(object sender, EventArgs e) > { > > } > > private void exitButton_Click(object sender, EventArgs e) > { > this.Close(); > } > > private void clearButton_Click(object sender, EventArgs e) > { > this.accessoriesLabel.Text = ""; > this.salesTaxLabel.Text = ""; > this.basePriceTextBox.Text = ""; > this.tradeInAllowanceTextBox.Text = ""; > this.stereoCheckBox.Checked = false; > this.leatherInteriorCheckBox.Checked = false; > this.computerNavigationCheckBox.Checked = false; > this.subTotalLabel.Text = ""; > this.amountDueLabel.Text = ""; > //Clear variables. > decSubTotal = 0; > decAccessoriesTotal = 0; > decAmountDue = 0; > decSalesTax = 0; > decTradeInAllowance = 0; > disableControls(); > //Put the focus on the first text box. > this.basePriceTextBox.Focus(); > } > > private void calculateButton_Click(object sender, EventArgs e) > { > string strMessageString=""; > > //Calculate the cost of the vehicle. > if (this.basePriceTextBox.Text != "") > { > //Convert from Text to Decimal value. > decSubTotal = decimal.Parse(this.basePriceTextBox.Text); > // Types of Interiors using check boxes. See which ones were checked. > if (this.stereoCheckBox.Checked) > { > decAccessoriesTotal += decStereoSystem; > } > if (this.leatherInteriorCheckBox.Checked) > { > decAccessoriesTotal += decLeatherInterior; > } > if (this.computerNavigationCheckBox.Checked) > { > decAccessoriesTotal += decComputerNavigation; > } > decSubTotal += decAccessoriesTotal; > > //Types of Finishes. See which Radio Button is checked. > if (this.standardFinishRadioButton.Checked) > { > decSubTotal += decStandardFinish; > } > else if (this.pearlizedFinishRadioButton.Checked) > { > decSubTotal += decPearlizeFinish; > } > else if (this.customizedDetailingRadioButton.Checked) > { > decSubTotal += decCustomizedDetailing; > } > // Determine the taxes prior to deducting the trade-in value. > decSalesTax = (decSubTotal * decTaxRate); > //Add the sales tax to the subTotal variable. > decSubTotal += decSalesTax; > > //See if the Buyer has a trade-in. Enter the value. > if (this.tradeInAllowanceTextBox.Text != "") > { > decTradeInAllowance = > decimal.Parse(this.tradeInAllowanceTextBox.Text); > decAmountDue = (decSubTotal - decTradeInAllowance); > } > //In the case that there is no value in the Trade-In Allowance textbox. > else > { > decAmountDue += decSubTotal; > } > > //Now, display the results in the Labels. > this.accessoriesLabel.Text = decAccessoriesTotal.ToString("C"); > this.salesTaxLabel.Text = decSalesTax.ToString("C"); > this.subTotalLabel.Text = decSubTotal.ToString("C"); > this.amountDueLabel.Text = decAmountDue.ToString("C"); > this.calculateButton.Enabled = false; > } > } > > private void basePriceTextBox_Leave(object sender, EventArgs e) > { > string strMessageForBasePrice=""; > try > { > if (decimal.Parse(this.basePriceTextBox.Text) >= 1) > { > enableControls(); > this.tradeInAllowanceTextBox.Focus(); > } > if (decimal.Parse(this.basePriceTextBox.Text) < 1) > { > disableControls(); > } > } > catch (FormatException err) > { > strMessageForBasePrice = > "Non-numeric value was entered for Base Price"; > MessageBox.Show(strMessageForBasePrice + ". " + err.Message, > "Data Entry Error", > MessageBoxButtons.OK, MessageBoxIcon.Information); > } > } > //Rather than repeat the below code several times, I decided to create a method. > private void disableControls() > { > this.stereoCheckBox.Enabled = false; > this.leatherInteriorCheckBox.Enabled = false; > this.computerNavigationCheckBox.Enabled = false; > this.standardFinishRadioButton.Enabled = false; > this.pearlizedFinishRadioButton.Enabled = false; > this.customizedDetailingRadioButton.Enabled = false; > this.tradeInAllowanceTextBox.Enabled = false; > this.calculateButton.Enabled = false; > } > > private void enableControls() > { > this.stereoCheckBox.Enabled = true; > this.leatherInteriorCheckBox.Enabled = true; > this.computerNavigationCheckBox.Enabled = true; > this.standardFinishRadioButton.Enabled = true; > this.pearlizedFinishRadioButton.Enabled = true; > this.customizedDetailingRadioButton.Enabled = true; > this.tradeInAllowanceTextBox.Enabled = true; > this.calculateButton.Enabled = true; > } > } >} >