Thursday, August 22, 2013

Visual Basic-Final Project




VB Auto Sales

This one is a modification of example 1, replacing all command buttons with the following menu structure(fig.1):



File                                   Edit                                                   Help

  Print                                    Calculate                                       About
                                              Clear
                                              Summary   
-------                                  -------------
  Exit                                      Color



If the user has any doubt about creating this form or any of its components, please fell free of contact me, thank you.
fig.1


For this project the user will have to create four forms(fig 2):



 
  • Splash Screen(fig.3)
  • Main processing screen
  • About screen(fig.4)
  • Summary screen(fig.5)
fig.2














fig.3-Splash Screen

fig.4-About Screen

fig.5-Summary Screen

Now the magic comes, let's start programming :

'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 projectwide variables

    Friend totalOfSubTotalDecimal, totalTradeInDecimal, accessoriesDecimal, totalAmountDueDecimal, averageTradeInDecimal As Decimal
    Friend numberofcarsprocessedInteger, tnotInteger As Integer




    'Declare Constants.

    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 exteriorFinishDecimal As Decimal
    Private carSalesPriceDecimal As Decimal
    Private tradeInAllowanceDecimal As Decimal
    Private subtotalDecimal As Decimal
    Private totalDecimal As Decimal
    Private amountDueDecimal As Decimal
    Private afDecimal 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 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

            PrintToolStripMenuItem.Enabled = False

            'validate trade-in

            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")

            'disable print button

            PrintToolStripMenuItem.Enabled = False

            'validate trade-in

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

    End Sub

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

        'calculate exterior finish

        If cdRadioButton.Checked Then
            CustomizedPriceDecimal = CUSTOMIZE_PRICEDECIMAL
            exteriorFinishDecimal = CustomizedPriceDecimal
            afDecimal = accessoriesDecimal + exteriorFinishDecimal
            afLabel.Text = afDecimal.ToString("c")

            'disable print button

            PrintToolStripMenuItem.Enabled = False

            'validate trade-in

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

    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

        CalculateToolStripMenuItem.Enabled = True

        'disable print button

        PrintToolStripMenuItem.Enabled = False

        'validate trade-in

        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

        CalculateToolStripMenuItem.Enabled = True

        'disable print button

        PrintToolStripMenuItem.Enabled = False

        'validate trade-in

        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

        CalculateToolStripMenuItem.Enabled = True

        'disable print button

        PrintToolStripMenuItem.Enabled = False

        'validate trade-in

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

        End If

    End Sub


    Private Sub SummaryToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SummaryToolStripMenuItem.Click

        'summary information

        SummaryForm1.ShowDialog()

    End Sub


    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.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
            'summarize data transaction
            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 PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.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

            ClearToolStripMenuItem.Enabled = False

            'disable print button

            PrintToolStripMenuItem.Enabled = False

            'enable summary button

            SummaryToolStripMenuItem.Enabled = True

            'enable calculate button

            CalculateToolStripMenuItem.Enabled = True

            'disable colorToolStrip

            ColorToolStripMenuItem.Enabled = False
            subTotalLabel.ForeColor = Color.Black
            totalLabel.ForeColor = Color.Black
            salesTLabel.ForeColor = Color.Black
            amountDueLabel.ForeColor = Color.Black
            afLabel.ForeColor = Color.Black

            '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()

            'enable exitmenustrip

            ExitToolStripMenuItem.Enabled = True

            'clear date and time data

            dateTimeLabel.Text = String.Empty

        Else

            'print form

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

        End If
       
    End Sub

    Private Sub ClearToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearToolStripMenuItem.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

            ClearToolStripMenuItem.Enabled = False

            'disable print button

            PrintToolStripMenuItem.Enabled = False

            'enable calculate button

            CalculateToolStripMenuItem.Enabled = True

            'disable colorToolStrip

            ColorToolStripMenuItem.Enabled = False
            subTotalLabel.ForeColor = Color.Black
            totalLabel.ForeColor = Color.Black
            salesTLabel.ForeColor = Color.Black
            amountDueLabel.ForeColor = Color.Black
            afLabel.ForeColor = Color.Black

            'enable input textboxes

            carSalesPriceTextBox.Enabled = True
            tradeInAllowanceTextBox.Enabled = True

            'enable exitmenustrip

            ExitToolStripMenuItem.Enabled = True

            'send focus to carSales Prices

            carSalesPriceTextBox.Focus()

        End If

    End Sub

    Private Sub CalculateToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateToolStripMenuItem.Click

        'Validate Car Sales Price Input 

        Dim amountDecimal As Decimal
        Dim taxDecimal As Decimal

        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 salestax

                amountDecimal = subtotalDecimal

                taxDecimal = salestax(amountDecimal)
                'round taxdecimal
                taxDecimal = Decimal.Round(taxDecimal, 2)
                'calculate total  
                totalDecimal = subtotalDecimal + taxDecimal
                '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 = taxDecimal.ToString("c")

        'display total

        totalLabel.Text = totalDecimal.ToString("c")

        'display amount due

        amountDueLabel.Text = amountDueDecimal.ToString("c")

        'enable print button

        PrintToolStripMenuItem.Enabled = True

        'enable clear button

        ClearToolStripMenuItem.Enabled = True

        'disable calculate button

        CalculateToolStripMenuItem.Enabled = False

        'enable colorToolStrip...

        ColorToolStripMenuItem.Enabled = True

        'disable exit-stripmenu

        ExitToolStripMenuItem.Enabled = False

    End Sub

    Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click

        'display the about message box

        AboutBox.ShowDialog()

        ' Dim messagestring As String
        'messagestring = "VB Auto Center" & Environment.NewLine &
        ' Environment.NewLine & "Programmed by Humberto Franyie"
        '  MessageBox.Show(messagestring, "About VB Auto Center", MessageBoxButtons.OK, MessageBoxIcon.Information)

    End Sub

    Private Sub ColorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColorToolStripMenuItem.Click

        'allow the user to select a new color for the output fields
        With ColorDialog1
            .ShowDialog()
            subTotalLabel.ForeColor = .Color
            totalLabel.ForeColor = .Color
            salesTLabel.ForeColor = .Color
            amountDueLabel.ForeColor = .Color
            afLabel.ForeColor = .Color

        End With

    End Sub

End Class

No comments:

Post a Comment