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 trade-Ins
  • Total Amounts Due
  • Numbers of cars processed
  • Total number of trade-ins
  • Average trade-ins
Item                                                           Price
Stereo System                                           425.76
Leather Interior                                         978.41  
Computer Navigation                                1741.23
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 tradeInAllowanceDecimal 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 totalTradeInDecimal As Decimal
    Private totalAmountDueDecimal As Decimal
    Private averageTradeInDecimal As Decimal
    Private summaryDataString As String
    Private StereoSystemDecimal As Decimal
    Private LeatherInteriorDecimal As Decimal
    Private ComputerNavigationDecimal 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

                'validate trade-In allowance

                If tradeInAllowanceTextBox.Text = "" Then
                    tradeInAllowanceTextBox.Text = "0.00"
                End If

                Try
                    tradeInAllowanceDecimal = Decimal.Parse(tradeInAllowanceTextBox.Text)
                    If tradeInAllowanceDecimal < 0 Or tradeInAllowanceDecimal >= 100000 Or tradeInAllowanceDecimal >= subtotalDecimal Then

                   
                        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)
                        With tradeInAllowanceTextBox
                            .Focus()
                            .SelectAll()
                            Exit Sub
                        End With

                    End If
               
                Catch tradeInAllowanceDecimal As FormatException
                    MessageBox.Show("Error!!! Trade-In Must be numeric .", "Data Entry Error", _
                     MessageBoxButtons.OK, MessageBoxIcon.Information)
                    With tradeInAllowanceTextBox
                        .Focus()
                        .SelectAll()

                    End With
                    Exit Sub
                End Try
                'calculate amount due

                amountDueDecimal = totalDecimal - tradeInAllowanceDecimal


            End If

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

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

        'disable input texboxes

        carSalesPriceTextBox.Enabled = False
        tradeInAllowanceTextBox.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

        If standartRadioButton.Checked Then
            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
                tradeInAllowanceTextBox.Enabled = True

            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

        If pearlizedRadioButton.Checked Then
            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
                tradeInAllowanceTextBox.Enabled = True

            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

        If cdRadioButton.Checked Then
            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
                tradeInAllowanceTextBox.Enabled = True

            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
            ComputerNavigationDecimal = CN_PRICEDECIMAL
        Else
            ComputerNavigationDecimal = 0
        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
            tradeInAllowanceTextBox.Enabled = True
        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
            ComputerNavigationDecimal = CN_PRICEDECIMAL
        Else
            ComputerNavigationDecimal = 0
        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
            tradeInAllowanceTextBox.Enabled = True
        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
            ComputerNavigationDecimal = CN_PRICEDECIMAL
        Else
            ComputerNavigationDecimal = 0
        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
            tradeInAllowanceTextBox.Enabled = True

        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()
            tradeInAllowanceTextBox.Clear()

            'clear output data

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


            'enable standartRadioButton

            standartRadioButton.Checked = True
            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
        tradeInAllowanceTextBox.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 &= "Total Trade-Ins:    " & totalTradeInDecimal.ToString("c")
        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
        summaryDataString &= "Average Trade-In:    " & averageTradeInDecimal.ToString("c")


        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 &= "Total Trade-Ins: " & totalTradeInDecimal.ToString("c")
            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
            summaryDataString &= "Average Trade-In: " & averageTradeInDecimal.ToString("c")
            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
            tradeInAllowanceTextBox.Text = "0"
            totalTradeInDecimal += tradeInAllowanceDecimal

            totalOfSubTotalDecimal += subtotalDecimal
            If tradeInAllowanceDecimal <> 0 Then
                tnotInteger += 1
            End If

            'acumulate number of cars processed

            numberofcarsprocessedInteger += 1

            ' Calculate the average and display the totals.

            averageTradeInDecimal = totalTradeInDecimal / numberofcarsprocessedInteger


            'display order time process

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


            'delate input data

            carSalesPriceTextBox.Clear()
            tradeInAllowanceTextBox.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()

            'enable/disable radio button and checkboxes

            standartRadioButton.Checked = True
            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

            'enable standartRadioButton

            standartRadioButton.Checked = True
            afLabel.Text = StandardPriceDecimal.ToString("c")

            'enable input textboxes

            carSalesPriceTextBox.Enabled = True
            tradeInAllowanceTextBox.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

No comments:

Post a Comment