## Thursday, August 22, 2013

### Auto Center Using Buttons

Create a project that calculates the total amount due for a purchase of a vehicule. Provide text boxes for the base price of th car and trade -in allowance. Use a group box to hold the check boxes to indicate if the users desires additional accessories: stereo system, leather interior, and/ or computer navigation system. Use a group box for the esterior finish that will be determined with the use if radio buttons; Standart(default), Pearlized, or Customized detailing.

The base price must be at least \$5.000 and less than \$10.000. The trade - in allowance may be \$0(no trade-in) or if there is a trade -in allowance the in must be less than \$100.000 and less than the subtotal.
If no trade-in present, then display 0.00. Validate the input values and provide a message box for errors if necessary.

To calculate the Subtotal, add the price of the selected accessories and the exterior finish to the base price of the car. Calculate the sales tax base on the subtotal  %8. The total is the subtotal plus the sales tax. Subtract the trade -in allowance from the total to obtain the Amount Due.

Include Calculate, Clear, Exit, Print, and Summary buttons. Verify clearing of values before actually clearing. When the user decides to exit the program, display the summary information.

The Accessories & Finish amount must respond dynamically to a change in the Accessories or the Exterior Finish.

Provide for he following totals to be displayed in a message box:
• Total of Subtotals
• Total Amounts Due
• Numbers of cars processed
Item                                                           Price
Stereo System                                           425.76
Leather Interior                                         978.41
Standard                                                    Free
Pearlize                                                     345.72
Customize                                                  599.99

'Description: This Program Calculates the amount
'due by a costumer in a car purchase, make you able to print this transaction and summarise all
'information,   and the total added by accessories
'the operations done by the program .

Option Strict On

Public Class VBAutoCenter

'Declare Constants.

Const TAXDECIMAL As Decimal = 0.08D
Const SS_PRICEDECIMAL As Decimal = 425.76D
Const LI_PRICEDECIMAL As Decimal = 987.41D
Const CN_PRICEDECIMAL As Decimal = 1741.23D
Const STANDART_PRICEDECIMAL As Decimal = 0D
Const PEARLIZED_PRICEDECIMAL As Decimal = 345.72D
Const CUSTOMIZE_PRICEDECIMAL As Decimal = 599.99D

'Declare Variables for Summary Information

Private accessoriesDecimal As Decimal
Private exteriorFinishDecimal As Decimal
Private carSalesPriceDecimal As Decimal
Private subtotalDecimal As Decimal
Private salesTDecimal As Decimal
Private totalDecimal As Decimal
Private totalOfSubTotalDecimal As Decimal
Private amountDueDecimal As Decimal
Private afDecimal As Decimal
Private totalAmountDueDecimal As Decimal
Private summaryDataString As String
Private StereoSystemDecimal As Decimal
Private LeatherInteriorDecimal As Decimal
Private StandardPriceDecimal As Decimal
Private PearlizedPriceDecimal As Decimal
Private CustomizedPriceDecimal As Decimal

Private tnotInteger As Integer
Private numberofcarsprocessedInteger As Integer

Private Sub calculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click

'Validate Car Sales Price Input

Try
carSalesPriceDecimal = Decimal.Parse(carSalesPriceTextBox.Text)
If carSalesPriceDecimal < 5000 Or carSalesPriceDecimal >= 100000 Then
MessageBox.Show("Car Sales Price must be at least \$5,000 and less than \$100,000", "Data Entry Error", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
With carSalesPriceTextBox
.Focus()
.SelectAll()

End With
Exit Sub

Else

'calculate subtotal

subtotalDecimal = carSalesPriceDecimal + accessoriesDecimal + exteriorFinishDecimal

'calculate sales Tax at 8%

salesTDecimal = subtotalDecimal * TAXDECIMAL

'round sales tax

salesTDecimal = Decimal.Round(salesTDecimal, 2)

'calculate total

totalDecimal = subtotalDecimal + salesTDecimal

'calculate amount due

End If

Try

MessageBox.Show("Car Sales Price must be at least 0 and not more than \$100,000, less than the Subtotal and the Car Sales Price!!!.", "Data Entry Error", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
.Focus()
.SelectAll()
Exit Sub
End With

End If

MessageBox.Show("Error!!! Trade-In Must be numeric .", "Data Entry Error", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
.Focus()
.SelectAll()

End With
Exit Sub
End Try
'calculate amount due

End If

Catch carSalesPriceException As FormatException
MessageBox.Show("Error !!! Price Must be numeric.", "Data Entry Error", _
MessageBoxButtons.OK, MessageBoxIcon.Information)

With carSalesPriceTextBox
.Focus()
.SelectAll()
Exit Sub
End With
End Try

'disable input texboxes

carSalesPriceTextBox.Enabled = False

'display subtotal
subTotalLabel.Text = subtotalDecimal.ToString("c")

'display sales tax
salesTLabel.Text = salesTDecimal.ToString("c")

'display total
totalLabel.Text = totalDecimal.ToString("c")

'display amount due
amountDueLabel.Text = amountDueDecimal.ToString("c")

'enable print button
printButton.Enabled = True

'enable clear button
clearButton.Enabled = True

'disable calculate button
calculateButton.Enabled = False

'disable exit button
exitButton.Enabled = False

'send focus to print button
printButton.Focus()

End Sub

Private Sub standartRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles standartRadioButton.CheckedChanged

'calculate exterior finish

StandardPriceDecimal = STANDART_PRICEDECIMAL
exteriorFinishDecimal = STANDART_PRICEDECIMAL
afDecimal = accessoriesDecimal + exteriorFinishDecimal
afLabel.Text = afDecimal.ToString("C")

'disable print button

printButton.Enabled = False
If afDecimal + carSalesPriceDecimal < tradeInAllowanceDecimal = True Then
With carSalesPriceTextBox
.Enabled = True
.Focus()
.SelectAll()
End With

End If

End If

End Sub

Private Sub pearlizedRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pearlizedRadioButton.CheckedChanged

'calculate exterior finish

PearlizedPriceDecimal = PEARLIZED_PRICEDECIMAL
exteriorFinishDecimal = PearlizedPriceDecimal
afDecimal = accessoriesDecimal + exteriorFinishDecimal
afLabel.Text = afDecimal.ToString("C")
If afDecimal + carSalesPriceDecimal < tradeInAllowanceDecimal = True Then
With carSalesPriceTextBox
.Enabled = True
.Focus()
.SelectAll()
End With

End If

End If

'delete output textboxes

subTotalLabel.Text = String.Empty
salesTLabel.Text = String.Empty
totalLabel.Text = String.Empty
amountDueLabel.Text = String.Empty
'Enable Calculate button
calculateButton.Enabled = True
'disable print button
printButton.Enabled = False

End Sub

Private Sub cdRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cdRadioButton.CheckedChanged

CustomizedPriceDecimal = CUSTOMIZE_PRICEDECIMAL
exteriorFinishDecimal = CustomizedPriceDecimal
afDecimal = accessoriesDecimal + exteriorFinishDecimal
afLabel.Text = afDecimal.ToString("c")
If afDecimal + carSalesPriceDecimal < tradeInAllowanceDecimal = True Then
With carSalesPriceTextBox
.Enabled = True
.Focus()
.SelectAll()
End With

End If

End If

'delete output textboxes

subTotalLabel.Text = String.Empty
salesTLabel.Text = String.Empty
totalLabel.Text = String.Empty
amountDueLabel.Text = String.Empty
'Enable Calculate button
calculateButton.Enabled = True
'disable print button
printButton.Enabled = False

End Sub

Private Sub ssCheckBox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ssCheckBox.CheckedChanged

'calculate accessories

If ssCheckBox.Checked Then
StereoSystemDecimal = SS_PRICEDECIMAL
Else
StereoSystemDecimal = 0
End If

If liCheckBox.Checked Then
LeatherInteriorDecimal = LI_PRICEDECIMAL
Else
LeatherInteriorDecimal = 0
End If

If cnCheckBox.Checked Then
Else
End If

accessoriesDecimal = StereoSystemDecimal + LeatherInteriorDecimal + ComputerNavigationDecimal
afDecimal = accessoriesDecimal + exteriorFinishDecimal
afLabel.Text = afDecimal.ToString("c")

'Clear Output Textboxes

subTotalLabel.Text = String.Empty
salesTLabel.Text = String.Empty
totalLabel.Text = String.Empty
amountDueLabel.Text = String.Empty
'Enable Calculate button
calculateButton.Enabled = True
'disable print button
printButton.Enabled = False
If afDecimal + carSalesPriceDecimal < tradeInAllowanceDecimal = True Then
With carSalesPriceTextBox
.Enabled = True
.Focus()
.SelectAll()
End With
End If
End Sub

Private Sub liCheckBox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles liCheckBox.CheckedChanged

'calculate accessories.

If ssCheckBox.Checked Then
StereoSystemDecimal = SS_PRICEDECIMAL
Else
StereoSystemDecimal = 0
End If

If liCheckBox.Checked Then
LeatherInteriorDecimal = LI_PRICEDECIMAL
Else
LeatherInteriorDecimal = 0
End If

If cnCheckBox.Checked Then
Else
End If

accessoriesDecimal = StereoSystemDecimal + LeatherInteriorDecimal + ComputerNavigationDecimal
afDecimal = accessoriesDecimal + exteriorFinishDecimal
afLabel.Text = afDecimal.ToString("c")

'Clear Output Textboxes

subTotalLabel.Text = String.Empty
salesTLabel.Text = String.Empty
totalLabel.Text = String.Empty
amountDueLabel.Text = String.Empty
'Enable Calculate button
calculateButton.Enabled = True
'disable print button
printButton.Enabled = False
If afDecimal + carSalesPriceDecimal < tradeInAllowanceDecimal = True Then
With carSalesPriceTextBox
.Enabled = True
.Focus()
.SelectAll()
End With
End If
End Sub

Private Sub cnCheckBox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cnCheckBox.CheckedChanged

'calculate accessories

If ssCheckBox.Checked Then
StereoSystemDecimal = SS_PRICEDECIMAL
Else
StereoSystemDecimal = 0
End If

If liCheckBox.Checked Then
LeatherInteriorDecimal = LI_PRICEDECIMAL
Else
LeatherInteriorDecimal = 0
End If

If cnCheckBox.Checked Then
Else
End If

accessoriesDecimal = StereoSystemDecimal + LeatherInteriorDecimal + ComputerNavigationDecimal
afDecimal = accessoriesDecimal + exteriorFinishDecimal
afLabel.Text = afDecimal.ToString("c")

'Clear Output Textboxes

subTotalLabel.Text = String.Empty
salesTLabel.Text = String.Empty
totalLabel.Text = String.Empty
amountDueLabel.Text = String.Empty

'Enable Calculate button

calculateButton.Enabled = True

'disable print button

printButton.Enabled = False
If afDecimal + carSalesPriceDecimal < tradeInAllowanceDecimal = True Then
With carSalesPriceTextBox
.Enabled = True
.Focus()
.SelectAll()
End With

End If
End Sub

Private Sub clearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clearButton.Click

Dim messageString As String

' Confirm clear of current order.

messageString = "Are you sure you want to clear the information?"
If MessageBox.Show(messageString, "New Data", _
MessageBoxButtons.YesNo, MessageBoxIcon.Question, _
MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.Yes Then

'clear input textboxes

carSalesPriceTextBox.Clear()

'clear output data

afLabel.Text = String.Empty
subTotalLabel.Text = String.Empty
salesTLabel.Text = String.Empty
totalLabel.Text = String.Empty
amountDueLabel.Text = String.Empty

afLabel.Text = StandardPriceDecimal.ToString("c")

'disable checkboxes

ssCheckBox.Checked = False
liCheckBox.Checked = False
cnCheckBox.Checked = False

'disable clear button

clearButton.Enabled = False
'disable print button
printButton.Enabled = False

'enable calculate button

calculateButton.Enabled = True

'enable input textboxes

carSalesPriceTextBox.Enabled = True

'send focus to carSales Prices

carSalesPriceTextBox.Focus()
'enable exit button
exitButton.Enabled = True

End If

End Sub

Private Sub summaryButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles summaryButton.Click

Dim summaryDataString As String
'summary information

summaryDataString = "Total of Subtotal:    " & totalOfSubTotalDecimal.ToString("c")
summaryDataString &= ControlChars.NewLine & ControlChars.NewLine
summaryDataString &= ControlChars.NewLine & ControlChars.NewLine
summaryDataString &= "Total Amounts Due:    " & totalAmountDueDecimal.ToString("c")
summaryDataString &= ControlChars.NewLine & ControlChars.NewLine
summaryDataString &= "Numbers Of Cars Processed:    " & numberofcarsprocessedInteger.ToString
summaryDataString &= ControlChars.NewLine & ControlChars.NewLine
summaryDataString &= "Total Number of Trade-Ins:    " & tnotInteger.ToString
summaryDataString &= ControlChars.NewLine & ControlChars.NewLine

MessageBox.Show(summaryDataString, "Order Confirmation", MessageBoxButtons.OK)

End Sub

Private Sub exitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitButton.Click

'terminate program

Dim summaryDataString As String

If MessageBox.Show("Are you sure you want to exit!!!", "VB Auto Center", MessageBoxButtons.YesNo, MessageBoxIcon.Question, _
MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.Yes Then

summaryDataString = "Total of Subtotal:" & totalOfSubTotalDecimal.ToString("c")
summaryDataString &= ControlChars.NewLine & ControlChars.NewLine
summaryDataString &= ControlChars.NewLine & ControlChars.NewLine
summaryDataString &= "Total Amounts Due:" & totalAmountDueDecimal.ToString("c")
summaryDataString &= ControlChars.NewLine & ControlChars.NewLine
summaryDataString &= "Numbers Of Cars Processed:" & numberofcarsprocessedInteger.ToString("n")
summaryDataString &= ControlChars.NewLine & ControlChars.NewLine
summaryDataString &= "Total Number of Trade-Ins:" & tnotInteger.ToString("n")
summaryDataString &= ControlChars.NewLine & ControlChars.NewLine
MessageBox.Show(summaryDataString, "Coffee Sales summary", MessageBoxButtons.OK, MessageBoxIcon.Information)

Close()

End If

End Sub

Private Sub printButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles printButton.Click

Dim printMessageString As String
Dim printOrderMessageString As String

'comfirm order

printMessageString = "Do you want to print and finish this trasaction ?" &
Environment.NewLine & Environment.NewLine & "If you want to print and confirm your order, please press: Yes" &
Environment.NewLine & Environment.NewLine & "If don't, just press: NO"

If MessageBox.Show(printMessageString, "Order Confirmation", _
MessageBoxButtons.YesNo, MessageBoxIcon.Question, _
MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.Yes Then

'accumulate totals

totalAmountDueDecimal += amountDueDecimal

totalOfSubTotalDecimal += subtotalDecimal
tnotInteger += 1
End If

'acumulate number of cars processed

numberofcarsprocessedInteger += 1

' Calculate the average and display the totals.

'display order time process

dateTimeLabel.Text = "Order Completed on: " & Date.Now.ToString()
'print form
PrintForm1.Print()

'delate input data

carSalesPriceTextBox.Clear()

'delate output data

afLabel.Text = String.Empty
subTotalLabel.Text = String.Empty
salesTLabel.Text = String.Empty
totalLabel.Text = String.Empty
amountDueLabel.Text = String.Empty

'send focus to car sales price

carSalesPriceTextBox.Focus()

ssCheckBox.Checked = False
liCheckBox.Checked = False
cnCheckBox.Checked = False

'disable clear button

clearButton.Enabled = False
'disable print button

printButton.Enabled = False
'enable summary button

summaryButton.Enabled = True
'enable calculate button
calculateButton.Enabled = True

afLabel.Text = StandardPriceDecimal.ToString("c")

'enable input textboxes

carSalesPriceTextBox.Enabled = True

'send focus to carSalesPrice

carSalesPriceTextBox.Focus()

'clear date and time data

dateTimeLabel.Text = String.Empty

'enable exit button

exitButton.Enabled = True
Else

'print form

printOrderMessageString = "Your Order will just be printed !!!"
MessageBox.Show(printOrderMessageString, "Print Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information)

PrintForm1.Print()

'send focus to clear button

clearButton.Focus()

End If

End Sub

End Class