Home

Example Application: College Park Auto-Repair

 

College Park Auto Repair

Introduction

This application reviews and demonstrates the process of printing in a .NET Framework application. The application is for a car repair business. The user can register the customer, the parts used during the repair, and the types of jobs performed. The application also makes the necessary calculations.

Windows Controls:

     

Practical LearningPractical Learning: Creating the Application

  1. Start Microsoft Visual Basic
  2. Create a new Windows Application named CollegeParkAutoRepair1
  3. In the Solution Explorer, right-click Form1.vb and click Rename
  4. Type CollegeParkAutoRepair.vb and press Enter
  5. From the Menus & Toolbars section of the Toolbox, click MenuStrip and click the form
  6. Design the menu items as follows:
     
    MenuItem DropDownItems
    Text Name Text Name Image Shortcut
    &File mnuFile &New Repair Order mnuFileNew new.ico Ctrl+N
        &Open Existing Order... mnuFileOpen open.ico Ctrl+O
        &Save Current Order mnuFileSave save.ico Ctrl+S
        Separator      
        &Print mnuFilePrint printer.ico Ctrl+P
        Separator      
        E&xit mnuFileExit    
  7. Design the form as follows:
     
    College Park Auto Repair: Form Design
    Control Name Text Other Properties
    Group   Order Identification  
    Label   Customer Name:  
    TextBox txtCustomerName    
    Label   Address  
    TextBox txtAddress    
    Label   City:  
    TextBox txtCity    
    Label   State:  
    TextBox txtState    
    Label   ZIP Code:  
    TextBox txtZIPCode   TextAlign: Right
    Label   Make / Model:  
    TextBox txtMake    
    TextBox txtModel    
    Label   Year:  
    TextBox txtCarYear   TextAlign: Right
    Label   Problem Description:  
    TextBox txtProblem    
    GroupBox   Parts Used  
    Label   Part Name  
    Label   Unit Price  
    Label   Qty  
    Label   Sub Total  
    TextBox txtPartName1    
    TextBox txtUnitPrice1 0.00 TextAlign: Right
    TextBox txtQuantity1 0 TextAlign: Right
    TextBox txtSubTotal1 0.00 TextAlign: Right
    Enabled: False
    TextBox txtPartName2    
    TextBox txtUnitPrice2 0.00 TextAlign: Right
    TextBox txtQuantity2 0 TextAlign: Right
    TextBox txtSubTotal2 0.00 TextAlign: Right
    Enabled: False
    TextBox txtPartName3    
    TextBox txtUnitPrice3 0.00 TextAlign: Right
    TextBox txtQuantity3 0 TextAlign: Right
    TextBox txtSubTotal3 0.00 TextAlign: Right
    Enabled: False
    TextBox txtPartName4    
    TextBox txtUnitPrice4 0.00 TextAlign: Right
    TextBox txtQuantity4 0 TextAlign: Right
    TextBox txtSubTotal4 0.00 TextAlign: Right
    Enabled: False
    TextBox txtPartName5    
    TextBox txtUnitPrice5 0.00 TextAlign: Right
    TextBox txtQuantity5 0 TextAlign: Right
    TextBox txtSubTotal5 0.00 TextAlign: Right
    Enabled: False
    GroupBox   Jobs Performed  
    Label   Price  
    TextBox txtJobPerformed1    
    TextBox txtJobPrice1 0.00 TextAlign: Right
    TextBox txtJobPerformed2    
    TextBox txtJobPrice2 0.00 TextAlign: Right
    TextBox txtJobPerformed3    
    TextBox txtJobPrice3 0.00 TextAlign: Right
    TextBox txtJobPerformed4    
    TextBox txtJobPrice4 0.00 TextAlign: Right
    TextBox txtJobPerformed5    
    TextBox txtJobPrice5 0.00 TextAlign: Right
    GroupBox   Order Summary  
    Label   Total Parts:  
    TextBox txtTotalParts 0.00 TextAlign: Right
    Label   Total Labor:  
    TextBox txtTotalLabor 0.00 TextAlign: Right
    Label   Tax Rate:  
    TextBox txtTaxRate 7.75 TextAlign: Right
    Label   %  
    Label   Tax Amount:  
    TextBox txtTaxAmount 0.00 TextAlign: Right
    Label   Total Order:  
    TextBox txtTotalOrder 0.00 TextAlign: Right
    Label   Recommendations  
    TextBox txtRecommendations   Multiline: True
    ScrollBars: Vertical
  8. Right-click the form and click View Code
  9. Create a method named Calculate as follows:
      
    Imports System.IO
    
    Public Class CollegeParkAutoRepair
        Private Sub Calculate()
            Dim Part1UnitPrice As Double, Part2UnitPrice As Double
            Dim Part3UnitPrice As Double, Part4UnitPrice As Double
            Dim Part5UnitPrice As Double, Part1SubTotal As Double
            Dim Part2SubTotal As Double, Part3SubTotal As Double
            Dim Part4SubTotal As Double, Part5SubTotal As Double
            Dim Part1Quantity As Integer, Part2Quantity As Integer
            Dim Part3Quantity As Integer, Part4Quantity As Integer
            Dim Part5Quantity As Integer
            Dim Job1Price As Double, Job2Price As Double
            Dim Job3Price As Double, Job4Price As Double
            Dim Job5Price As Double
            Dim TotalParts As Double, TotalLabor As Double
            Dim TaxRate As Double, TaxAmount As Double
            Dim TotalOrder As Double, TotalPartsAndLabor As Double
    
            ' Don't charge a part unless it is clearly identified
            If txtPartName1.Text = "" Then
                txtUnitPrice1.Text = "0.00"
                txtQuantity1.Text = "0"
                txtSubTotal1.Text = "0.00"
                Part1UnitPrice = 0.0
            Else
    
                Try
                    Part1UnitPrice = CDbl(txtUnitPrice1.Text)
                Catch ex As Exception
                    MsgBox("Invalid Unit Price")
                    txtUnitPrice1.Text = "0.00"
                    txtUnitPrice1.Focus()
                End Try
    
                Try
                    Part1Quantity = CInt(txtQuantity1.Text)
                Catch ex As Exception
    
                    MsgBox("Invalid Quantity")
                    txtQuantity1.Text = ""
                    txtQuantity1.Focus()
                End Try
            End If
    
            If txtPartName2.Text = "" Then
                txtUnitPrice2.Text = "0.00"
                txtQuantity2.Text = "0"
                txtSubTotal2.Text = "0.00"
                Part2UnitPrice = 0.0
            Else
    
                Try
                    Part2UnitPrice = CDbl(txtUnitPrice2.Text)
                Catch ex As Exception
                    MsgBox("Invalid Unit Price")
                    txtUnitPrice2.Text = "0.00"
                    txtUnitPrice2.Focus()
                End Try
    
                Try
    
                    Part2Quantity = CInt(txtQuantity2.Text)
                    End
                Catch ex As Exception
    
                    MsgBox("Invalid Quantity")
                    txtQuantity2.Text = "0"
                    txtQuantity2.Focus()
                End Try
            End If
    
            If txtPartName3.Text = "" Then
                txtUnitPrice3.Text = "0.00"
                txtQuantity3.Text = "0"
                txtSubTotal3.Text = "0.00"
                Part3UnitPrice = 0.0
            Else
    
                Try
                    Part3UnitPrice = CDbl(txtUnitPrice3.Text)
                Catch ex As Exception
                    MsgBox("Invalid Unit Price")
                    txtUnitPrice3.Text = "0.00"
                    txtUnitPrice3.Focus()
                End Try
    
                Try
                    Part3Quantity = CInt(txtQuantity3.Text)
                Catch ex As Exception
                    MsgBox("Invalid Quantity")
                    txtQuantity3.Text = "0"
                    txtQuantity3.Focus()
                End Try
            End If
    
            If txtPartName4.Text = "" Then
                txtUnitPrice4.Text = "0.00"
                txtQuantity4.Text = "0"
                txtSubTotal4.Text = "0.00"
                Part4UnitPrice = 0.0
            Else
    
                Try
                    Part4UnitPrice = CDbl(txtUnitPrice4.Text)
                Catch ex As Exception
    
                    MsgBox("Invalid Unit Price")
                    txtUnitPrice4.Text = "0.00"
                    txtUnitPrice4.Focus()
                End Try
    
                Try
                    Part4Quantity = CInt(txtQuantity4.Text)
                Catch ex As Exception
                    MsgBox("Invalid Quantity")
                    txtQuantity4.Text = "0"
                    txtQuantity4.Focus()
                End Try
            End If
    
            If txtPartName5.Text = "" Then
                txtUnitPrice5.Text = "0.00"
                txtQuantity5.Text = "0"
                txtSubTotal5.Text = "0.00"
                Part5UnitPrice = 0.0
            Else
    
                Try
                    Part5UnitPrice = CDbl(txtUnitPrice5.Text)
                Catch ex As Exception
                    MsgBox("Invalid Unit Price")
                    txtUnitPrice5.Text = "0.00"
                    txtUnitPrice5.Focus()
                End Try
    
                Try
                    Part5Quantity = CInt(txtQuantity5.Text)
                Catch ex As Exception
                    MsgBox("Invalid Quantity")
                    txtQuantity5.Text = "0"
                    txtQuantity5.Focus()
                End Try
            End If
    
            ' Don't bill the customer for a job that is not specified
            If txtJobDescription1.Text = "" Then
                txtJobPrice1.Text = "0.00"
                Job1Price = 0.0
            Else
                Try
                    Job1Price = CDbl(txtJobPrice1.Text)
                Catch ex As Exception
                    MsgBox("Invalid Job Price")
                    txtJobPrice1.Text = "0.00"
                    txtJobPrice1.Focus()
                End Try
            End If
    
            If txtJobDescription2.Text = "" Then
                txtJobPrice2.Text = "0.00"
                Job2Price = 0.0
            Else
                Try
                    Job2Price = CDbl(txtJobPrice2.Text)
                Catch ex As Exception
                    MsgBox("Invalid Job Price")
                    txtJobPrice2.Text = "0.00"
                    txtJobPrice2.Focus()
                End Try
            End If
    
            If txtJobDescription3.Text = "" Then
                txtJobPrice3.Text = "0.00"
                Job3Price = 0.0
            Else
    
                Try
                    Job3Price = CDbl(txtJobPrice3.Text)
                Catch ex As Exception
                    MsgBox("Invalid Job Price")
                    txtJobPrice3.Text = "0.00"
                    txtJobPrice3.Focus()
                End Try
            End If
    
            If txtJobDescription4.Text = "" Then
                txtJobPrice4.Text = "0.00"
                Job4Price = 0.0
            Else
                Try
                    Job4Price = CDbl(txtJobPrice4.Text)
                Catch ex As Exception
                    MsgBox("Invalid Job Price")
                    txtJobPrice4.Text = "0.00"
                    txtJobPrice4.Focus()
                End Try
            End If
    
            If txtJobDescription5.Text = "" Then
    
                txtJobPrice5.Text = "0.00"
                Job5Price = 0.0
            Else
                Try
                    Job5Price = CDbl(txtJobPrice5.Text)
                Catch ex As Exception
                    MsgBox("Invalid Job Price")
                    txtJobPrice5.Text = "0.00"
                    txtJobPrice5.Focus()
                End Try
            End If
    
            Part1SubTotal = Part1UnitPrice * Part1Quantity
            Part2SubTotal = Part2UnitPrice * Part2Quantity
            Part3SubTotal = Part3UnitPrice * Part3Quantity
            Part4SubTotal = Part4UnitPrice * Part4Quantity
            Part5SubTotal = Part5UnitPrice * Part5Quantity
    
            txtSubTotal1.Text = FormatNumber(Part1SubTotal)
            txtSubTotal2.Text = FormatNumber(Part2SubTotal)
            txtSubTotal3.Text = FormatNumber(Part3SubTotal)
            txtSubTotal4.Text = FormatNumber(Part4SubTotal)
            txtSubTotal5.Text = FormatNumber(Part5SubTotal)
    
            TotalParts = Part1SubTotal + Part2SubTotal + Part3SubTotal + 
                    Part4SubTotal + Part5SubTotal
    
            TotalLabor = Job1Price + Job2Price + Job3Price + 
                            Job4Price + Job5Price
    
            Try
                TaxRate = CDbl(txtTaxRate.Text)
            Catch ex As Exception
                MsgBox("Invalid Tax Rate")
                txtTaxRate.Text = "7.75"
                txtTaxRate.Focus()
            End Try
    
            TotalPartsAndLabor = TotalParts + TotalLabor
            TaxAmount = TotalPartsAndLabor * TaxRate / 100
            TotalOrder = TotalPartsAndLabor + TaxAmount
    
            txtTotalParts.Text = FormatNumber(TotalParts)
            txtTotalLabor.Text = FormatNumber(TotalLabor)
            txtTaxAmount.Text = FormatNumber(TaxAmount)
            txtTotalOrder.Text = FormatNumber(TotalOrder)
        End Sub
    End Class
  10. In the Class Name combo box, select mnuFileNew
  11. In the Method Name combo box, select Click and implement the event as follows:
     
    Private Sub mnuFileNewClick(ByVal sender As Object, 
                                     ByVal e As System.EventArgs) 
                                     Handles mnuFileNew.Click
            txtCustomerName.Text = ""
            txtAddress.Text = ""
            txtCity.Text = ""
            txtState.Text = ""
            txtZIPCode.Text = ""
            txtMake.Text = ""
            txtModel.Text = ""
            txtCarYear.Text = ""
            txtProblem.Text = ""
    
            txtPartName1.Text = ""
            txtUnitPrice1.Text = "0.00"
            txtQuantity1.Text = "0"
            txtSubTotal1.Text = "0.00"
            txtPartName2.Text = ""
            txtUnitPrice2.Text = "0.00"
            txtQuantity2.Text = "0"
            txtSubTotal2.Text = "0.00"
            txtPartName3.Text = ""
            txtUnitPrice3.Text = "0.00"
            txtQuantity3.Text = "0"
            txtSubTotal3.Text = "0.00"
            txtPartName4.Text = ""
            txtUnitPrice4.Text = "0.00"
            txtQuantity4.Text = "0"
            txtSubTotal4.Text = "0.00"
            txtPartName5.Text = ""
            txtUnitPrice5.Text = "0.00"
            txtQuantity5.Text = "0"
            txtSubTotal5.Text = "0.00"
    
            txtJobDescription1.Text = ""
            txtJobPrice1.Text = "0.00"
            txtJobDescription2.Text = ""
            txtJobPrice2.Text = "0.00"
            txtJobDescription3.Text = ""
            txtJobPrice3.Text = "0.00"
            txtJobDescription4.Text = ""
            txtJobPrice4.Text = "0.00"
            txtJobDescription5.Text = ""
            txtJobPrice5.Text = "0.00"
    
            txtTotalParts.Text = "0.00"
            txtTotalLabor.Text = "0.00"
            txtTaxRate.Text = "7.75"
            txtTaxAmount.Text = "0.00"
            txtTotalOrder.Text = "0.00"
    
            txtRecommendations.Text = ""
            txtCustomerName.Focus()
    End Sub
  12. Under the above End Sub line, create the following common event:
     
    Private Sub SetAndLeave(ByVal sender As Object, 
                                ByVal e As EventArgs) 
                                Handles txtUnitPrice1.Leave, 
                                        txtUnitPrice2.Leave, 
                                        txtUnitPrice3.Leave, 
                                        txtUnitPrice4.Leave, 
                                        txtUnitPrice5.Leave, 
                                        txtQuantity1.Leave, 
                                        txtQuantity2.Leave, 
                                        txtQuantity3.Leave, 
                                        txtQuantity4.Leave, 
                                        txtQuantity5.Leave, 
                                        txtJobPrice1.Leave, 
                                        txtJobPrice2.Leave, 
                                        txtJobPrice3.Leave, 
                                        txtJobPrice4.Leave, 
                                        txtJobPrice5.Leave
            Calculate()
        End Sub
  13. Display the form
  14. From the Dialogs section of the Toolbox, click OpenFileDialog and click the form
  15. Change its properties as follows:
    Title: Open Existing Repair Order
    DefaultExt: rpr
    Filter: Repair Orders (*.rpr)|*.rpr|All Files|
    Name: dlgOpen
  16. From the Dialogs section of the Toolbox, click SaveFileDialog and click the form
  17. Change its properties as follows:
    Title: Save Current Repair Order
    DefaultExt: rpr
    Filter: Repair Orders (*.rpr)|*.rpr|All Files|
    Name: dlgSave
  18. On the form, click File and double-click Open Existing Order
  19. Implement the Click event as follows:
     
    Private Sub mnuFileOpenClick(ByVal sender As System.Object, 
                                      ByVal e As System.EventArgs) 
                                      Handles mnuFileOpen.Click
            dlgOpen.InitialDirectory = "C:\College Park Auto Repair"
    
            If dlgOpen.ShowDialog() = Windows.Forms.DialogResult.OK Then
    
                Dim fleCPAR As FileStream = New FileStream(dlgOpen.FileName, 
                           FileMode.Open, FileAccess.Read, FileShare.Read)
                Dim CPARReader As BinaryReader = New BinaryReader(fleCPAR)
    
                Try
                    txtCustomerName.Text = CPARReader.ReadString()
                    txtAddress.Text = CPARReader.ReadString()
                    txtCity.Text = CPARReader.ReadString()
                    txtState.Text = CPARReader.ReadString()
                    txtZIPCode.Text = CPARReader.ReadString()
                    txtMake.Text = CPARReader.ReadString()
                    txtModel.Text = CPARReader.ReadString()
                    txtCarYear.Text = CPARReader.ReadString()
                    txtProblem.Text = CPARReader.ReadString()
    
                    txtPartName1.Text = CPARReader.ReadString()
                    txtUnitPrice1.Text = CPARReader.ReadString()
                    txtQuantity1.Text = CPARReader.ReadString()
                    txtSubTotal1.Text = CPARReader.ReadString()
                    txtPartName2.Text = CPARReader.ReadString()
                    txtUnitPrice2.Text = CPARReader.ReadString()
                    txtQuantity2.Text = CPARReader.ReadString()
                    txtSubTotal2.Text = CPARReader.ReadString()
                    txtPartName3.Text = CPARReader.ReadString()
                    txtUnitPrice3.Text = CPARReader.ReadString()
                    txtQuantity3.Text = CPARReader.ReadString()
                    txtSubTotal3.Text = CPARReader.ReadString()
                    txtPartName4.Text = CPARReader.ReadString()
                    txtUnitPrice4.Text = CPARReader.ReadString()
                    txtQuantity4.Text = CPARReader.ReadString()
                    txtSubTotal4.Text = CPARReader.ReadString()
                    txtPartName5.Text = CPARReader.ReadString()
                    txtUnitPrice5.Text = CPARReader.ReadString()
                    txtQuantity5.Text = CPARReader.ReadString()
    
                    txtSubTotal5.Text = CPARReader.ReadString()
                    txtJobDescription1.Text = CPARReader.ReadString()
                    txtJobPrice1.Text = CPARReader.ReadString()
                    txtJobDescription2.Text = CPARReader.ReadString()
                    txtJobPrice2.Text = CPARReader.ReadString()
                    txtJobDescription3.Text = CPARReader.ReadString()
                    txtJobPrice3.Text = CPARReader.ReadString()
                    txtJobDescription4.Text = CPARReader.ReadString()
                    txtJobPrice4.Text = CPARReader.ReadString()
                    txtJobDescription5.Text = CPARReader.ReadString()
                    txtJobPrice5.Text = CPARReader.ReadString()
    
                    txtTotalParts.Text = CPARReader.ReadString()
                    txtTotalLabor.Text = CPARReader.ReadString()
                    txtTaxRate.Text = CPARReader.ReadString()
                    txtTaxAmount.Text = CPARReader.ReadString()
                    txtTotalOrder.Text = CPARReader.ReadString()
                    txtRecommendations.Text = CPARReader.ReadString()
                Finally
                    CPARReader.Close()
                    fleCPAR.Close()
                End Try
            End If
    End Sub
  20. In the Class Name combo box, select mnuFileSave
  21. In the Method Name combo box, select Click and implement the event as follows:
     
    Private Sub mnuFileSaveClick(ByVal sender As Object, 
                                      ByVal e As System.EventArgs) 
                                      Handles mnuFileSave.Click
            ' Just in case, calculate the order now
            Calculate()
            ' This number will be used to incrementally 
            ' create the files by their names
            Dim Incremental As Integer
            ' Check the above folder. If it exists, don't create it
            ' If it doesn't exist, then create it
            Dim FolderName As String = "C:\College Park Auto Repair"
            Dim FolderInformation As DirectoryInfo = 
                Directory.CreateDirectory(FolderName)
    
            ' Get the list of files, if any, from the above folder
            Dim CustomersOrders() As FileInfo = 
                FolderInformation.GetFiles()
    
            ' If there is no file in the directory, 
            ' then get ready to create the first file
            If CustomersOrders.Length = 0 Then
                ' Get ready to display it in the Save dialog box
                dlgSave.FileName = Incremental.ToString() & ".rpr"
            Else ' If there was at least one file in the directory
    
                ' Get a reference to the last file
                Dim LastCustomerOrder As FileInfo = 
                    CustomersOrders(CustomersOrders.Length - 1)
                ' Get the name of the last file without its extension
                Dim FilenameWithoutExtension As String = 
                    Path.GetFileNameWithoutExtension(LastCustomerOrder.FullName)
                ' Increment the name of the file by 1
                Incremental = CInt(FilenameWithoutExtension) + 1
                ' Get ready to display it in the Save dialog box
                dlgSave.FileName = Incremental.ToString() & ".rpr"
            End If
    
            ' For convenience, display the Save dialog box in the directory
            ' created above
            dlgSave.InitialDirectory = FolderInformation.FullName
    
            ' Find out if the user clicked OK after displaying the Save dialog box
            If dlgSave.ShowDialog() = Windows.Forms.DialogResult.OK Then
    
                ' Create a new file using the name of the Save dialog box
                Dim fleCPAR As FileStream = New FileStream(dlgSave.FileName, 
                               FileMode.Create, FileAccess.Write, FileShare.Write)
                Dim bnrCPAR As BinaryWriter = New BinaryWriter(fleCPAR)
    
                Try
                    ' Write each value in the file
                    bnrCPAR.Write(txtCustomerName.Text)
                    bnrCPAR.Write(txtAddress.Text)
                    bnrCPAR.Write(txtCity.Text)
                    bnrCPAR.Write(txtState.Text)
                    bnrCPAR.Write(txtZIPCode.Text)
                    bnrCPAR.Write(txtMake.Text)
                    bnrCPAR.Write(txtModel.Text)
                    bnrCPAR.Write(txtCarYear.Text)
                    bnrCPAR.Write(txtProblem.Text)
    
                    bnrCPAR.Write(txtPartName1.Text)
                    bnrCPAR.Write(txtUnitPrice1.Text)
                    bnrCPAR.Write(txtQuantity1.Text)
                    bnrCPAR.Write(txtSubTotal1.Text)
                    bnrCPAR.Write(txtPartName2.Text)
                    bnrCPAR.Write(txtUnitPrice2.Text)
                    bnrCPAR.Write(txtQuantity2.Text)
                    bnrCPAR.Write(txtSubTotal2.Text)
                    bnrCPAR.Write(txtPartName3.Text)
                    bnrCPAR.Write(txtUnitPrice3.Text)
                    bnrCPAR.Write(txtQuantity3.Text)
                    bnrCPAR.Write(txtSubTotal3.Text)
                    bnrCPAR.Write(txtPartName4.Text)
                    bnrCPAR.Write(txtUnitPrice4.Text)
                    bnrCPAR.Write(txtQuantity4.Text)
                    bnrCPAR.Write(txtSubTotal4.Text)
                    bnrCPAR.Write(txtPartName5.Text)
                    bnrCPAR.Write(txtUnitPrice5.Text)
                    bnrCPAR.Write(txtQuantity5.Text)
                    bnrCPAR.Write(txtSubTotal5.Text)
    
                    bnrCPAR.Write(txtJobDescription1.Text)
                    bnrCPAR.Write(txtJobPrice1.Text)
                    bnrCPAR.Write(txtJobDescription2.Text)
                    bnrCPAR.Write(txtJobPrice2.Text)
                    bnrCPAR.Write(txtJobDescription3.Text)
                    bnrCPAR.Write(txtJobPrice3.Text)
                    bnrCPAR.Write(txtJobDescription4.Text)
                    bnrCPAR.Write(txtJobPrice4.Text)
                    bnrCPAR.Write(txtJobDescription5.Text)
                    bnrCPAR.Write(txtJobPrice5.Text)
    
                    bnrCPAR.Write(txtTotalParts.Text)
                    bnrCPAR.Write(txtTotalLabor.Text)
                    bnrCPAR.Write(txtTaxRate.Text)
                    bnrCPAR.Write(txtTaxAmount.Text)
                    bnrCPAR.Write(txtTotalOrder.Text)
    
                    bnrCPAR.Write(txtRecommendations.Text)
    
                    mnuFileNewClick(sender, e)
                Finally
                    bnrCPAR.Close()
                    fleCPAR.Close()
                End Try
            End If
    End Sub
  22. Execute the application to test it
  23. Create a new record. Here is an example:
     
    College Park Auto Repair
  24. On the main menu of the form, click File -> Save Current Order...
  25. Accept the suggested name of the file and click Save
  26. Create another order, calculate it and save it
  27. Try opening a previously saved order
  28. Close the form and return to your programming environment
  29. From the Printing section of the Toolbox, click the PrintDialog button PrintDialog and click the form
  30. While the print control is still selected, in the Properties window, change its Name to dlgPrint 
  31. From the Printing section of the Toolbox, click the PrintDocument button PrintDocument and click the form
  32. While the print document control is still selected, in the Properties window, change its name to docPrint
  33. Under the form, click dlgPrint
  34. In the Properties window, click Document and select docPrint
  35. Right-click the form and click View Code
  36. In the Class Name combo box, select docPrint
  37. In the Method Name combo box, select PrintPage and implement the event as follows:
     
    Private Sub docPrintPrintPage(ByVal sender As Object, 
                        ByVal e As System.Drawing.Printing.PrintPageEventArgs) 
                        Handles docPrint.PrintPage
            e.Graphics.DrawLine(New Pen(Color.Black, 2), 
                                        60, 90, 680, 90)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 
                                60, 93, 680, 93)
    
            Dim strDisplay As String = "College Park Auto Repair"
            Dim fntString As Font = New Font("Times New Roman", 
                                28, FontStyle.Bold)
            e.Graphics.DrawString(strDisplay, fntString, 
    	     Brushes.Black, 160, 100)
    
            strDisplay = "Customer Car Repair Order"
            fntString = New Font("Times New Roman", 18, FontStyle.Bold)
            e.Graphics.DrawString(strDisplay, fntString, 
    	     Brushes.Black, 220, 150)
    
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 60, 184, 680, 184)
            e.Graphics.DrawLine(New Pen(Color.Black, 2), 60, 187, 680, 187)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Order Identification", fntString, 
                    Brushes.Black, 80, 200)
    
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 100, 250, 640, 250)
    
            fntString = New Font("Times New Roman", 10, FontStyle.Bold)
            e.Graphics.DrawString("Customer Name:", fntString, 
                    Brushes.Black, 100, 260)
            fntString = New Font("Times New Roman", 10, FontStyle.Regular)
            e.Graphics.DrawString(txtCustomerName.Text, fntString, 
                    Brushes.Black, 260, 260)
    
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 100, 280, 640, 280)
    
            fntString = New Font("Times New Roman", 10, FontStyle.Bold)
            e.Graphics.DrawString("Address:", fntString, 
    	     Brushes.Black, 100, 290)
            fntString = New Font("Times New Roman", 10, FontStyle.Regular)
            e.Graphics.DrawString(txtAddress.Text, fntString, 
    	     Brushes.Black, 260, 290)
    
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 100, 310, 640, 310)
    
            fntString = New Font("Times New Roman", 10, FontStyle.Regular)
            Dim Address As String = txtCity.Text.ToString() & ", " & 
                                    txtState.Text & " " & txtZIPCode.Text
            e.Graphics.DrawString(Address, fntString, Brushes.Black, 260, 320)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 100, 340, 640, 340)
    
            fntString = New Font("Times New Roman", 10, FontStyle.Bold)
            e.Graphics.DrawString("Car:", fntString, Brushes.Black, 100, 350)
            fntString = New Font("Times New Roman", 10, FontStyle.Regular)
            Dim Car As String = txtMake.Text & ", " & 
                        txtModel.Text & ", " & txtCarYear.Text
            e.Graphics.DrawString(Car, fntString, Brushes.Black, 260, 350)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 100, 370, 640, 370)
    
            fntString = New Font("Times New Roman", 10, FontStyle.Bold)
            e.Graphics.DrawString("Problem Description:", 
                        fntString, Brushes.Black, 100, 380)
            fntString = New Font("Times New Roman", 10, FontStyle.Regular)
            e.Graphics.DrawString(txtProblem.Text, fntString, Brushes.Black, 
                                  New RectangleF(260, 380, 420, 380))
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 100, 400, 640, 400)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Parts Used", fntString, 
    	     Brushes.Black, 80, 430)
    
            e.Graphics.DrawLine(New Pen(Color.Black, 2), 80, 450, 680, 450)
    
            e.Graphics.DrawString("Parts Name", fntString, 
    	     Brushes.Black, 100, 460)
            e.Graphics.DrawString("Unit Price", fntString, 
    	     Brushes.Black, 420, 460)
            e.Graphics.DrawString("Qty", fntString, Brushes.Black, 520, 460)
            e.Graphics.DrawString("Sub-Total", fntString, 
    	     Brushes.Black, 562, 460)
    
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 100, 480, 640, 480)
    
            fntString = New Font("Times New Roman", 10, FontStyle.Regular)
            Dim fmtString As StringFormat = New StringFormat()
            fmtString.Alignment = StringAlignment.Far
    
            e.Graphics.DrawString(txtPartName1.Text, fntString, 
    	     Brushes.Black, 100, 490)
            e.Graphics.DrawString(txtUnitPrice1.Text, fntString, 
    	    Brushes.Black, 480, 490, fmtString)
            e.Graphics.DrawString(txtQuantity1.Text, fntString, 
    	     Brushes.Black, 540, 490, fmtString)
            e.Graphics.DrawString(txtSubTotal1.Text, fntString, 
    	     Brushes.Black, 630, 490, fmtString)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 100, 510, 640, 510)
    
            e.Graphics.DrawString(txtPartName2.Text, fntString, 
    	     Brushes.Black, 100, 520)
            e.Graphics.DrawString(txtUnitPrice2.Text, fntString, 
    	     Brushes.Black, 480, 520, fmtString)
            e.Graphics.DrawString(txtQuantity2.Text, fntString, 
    	     Brushes.Black, 540, 520, fmtString)
            e.Graphics.DrawString(txtSubTotal2.Text, fntString, 
    	     Brushes.Black, 630, 520, fmtString)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 100, 540, 640, 540)
    
            e.Graphics.DrawString(txtPartName3.Text, fntString, 
    	     Brushes.Black, 100, 550)
            e.Graphics.DrawString(txtUnitPrice3.Text, fntString, 
    	     Brushes.Black, 480, 550, fmtString)
            e.Graphics.DrawString(txtQuantity3.Text, fntString, 
    	     Brushes.Black, 540, 550, fmtString)
            e.Graphics.DrawString(txtSubTotal3.Text, fntString, 
    	     Brushes.Black, 630, 550, fmtString)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 100, 570, 640, 570)
    
            e.Graphics.DrawString(txtPartName4.Text, fntString, 
    	     Brushes.Black, 100, 580)
            e.Graphics.DrawString(txtUnitPrice4.Text, fntString, 
    	     Brushes.Black, 480, 580, fmtString)
            e.Graphics.DrawString(txtQuantity4.Text, fntString, 
    	     Brushes.Black, 540, 580, fmtString)
            e.Graphics.DrawString(txtSubTotal4.Text, fntString, 
    	     Brushes.Black, 630, 580, fmtString)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 100, 600, 640, 600)
    
            e.Graphics.DrawString(txtPartName5.Text, fntString, 
    	     Brushes.Black, 100, 610)
            e.Graphics.DrawString(txtUnitPrice5.Text, fntString, 
    	     Brushes.Black, 480, 610, fmtString)
            e.Graphics.DrawString(txtQuantity5.Text, fntString, 
    	     Brushes.Black, 540, 610, fmtString)
            e.Graphics.DrawString(txtSubTotal5.Text, fntString, 
    	     Brushes.Black, 630, 610, fmtString)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 100, 630, 640, 630)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Jobs Performed", fntString, 
    	     Brushes.Black, 80, 650)
            e.Graphics.DrawLine(New Pen(Color.Black, 2), 80, 670, 680, 670)
    
            e.Graphics.DrawString("Job Name", fntString, 
    	     Brushes.Black, 100, 680)
            e.Graphics.DrawString("Price", fntString, Brushes.Black, 562, 680)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 100, 700, 640, 700)
    
            fntString = New Font("Times New Roman", 10, FontStyle.Regular)
    
            e.Graphics.DrawString(txtJobDescription1.Text, 
    	     fntString, Brushes.Black, 100, 710)
            e.Graphics.DrawString(txtJobPrice1.Text, fntString, 
    	     Brushes.Black, 600, 710, fmtString)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 100, 730, 640, 730)
    
            e.Graphics.DrawString(txtJobDescription2.Text, 
    	     fntString, Brushes.Black, 100, 740)
            e.Graphics.DrawString(txtJobPrice2.Text, fntString, 
    	     Brushes.Black, 600, 740, fmtString)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 100, 760, 640, 760)
    
            e.Graphics.DrawString(txtJobDescription3.Text, fntString, 
    	     Brushes.Black, 100, 770)
            e.Graphics.DrawString(txtJobPrice3.Text, fntString, 
    	     Brushes.Black, 600, 770, fmtString)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 100, 790, 640, 790)
    
            e.Graphics.DrawString(txtJobDescription4.Text, fntString, 
    	     Brushes.Black, 100, 800)
            e.Graphics.DrawString(txtJobPrice4.Text, fntString, 
    	     Brushes.Black, 600, 800, fmtString)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 100, 820, 640, 820)
    
            e.Graphics.DrawString(txtJobDescription5.Text, fntString, 
    	     Brushes.Black, 100, 830)
            e.Graphics.DrawString(txtJobPrice5.Text, fntString, 
    	     Brushes.Black, 600, 830, fmtString)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 100, 850, 640, 850)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Order Summary", fntString, 
    	     Brushes.Black, 80, 870)
            e.Graphics.DrawLine(New Pen(Color.Black, 2), 80, 890, 680, 890)
    
            fntString = New Font("Times New Roman", 10, FontStyle.Bold)
            e.Graphics.DrawString("Total Parts:", fntString, 
    	     Brushes.Black, 500, 900)
            fntString = New Font("Times New Roman", 10, FontStyle.Regular)
            e.Graphics.DrawString(txtTotalParts.Text, fntString,  
    	    Brushes.Black, 640, 900, fmtString)
    
            fntString = New Font("Times New Roman", 10, FontStyle.Bold)
            e.Graphics.DrawString("Total Labor:", fntString, 
    	     Brushes.Black, 500, 920)
            fntString = New Font("Times New Roman", 10, FontStyle.Regular)
            e.Graphics.DrawString(txtTotalLabor.Text, fntString, 
                    Brushes.Black, 640, 920, fmtString)
    
            fntString = New Font("Times New Roman", 10, FontStyle.Bold)
            e.Graphics.DrawString("Tax Rate:", fntString, 
    	     Brushes.Black, 500, 940)
            fntString = New Font("Times New Roman", 10, FontStyle.Regular)
            e.Graphics.DrawString(txtTaxRate.Text, fntString, 
                    Brushes.Black, 640, 940, fmtString)
    
            fntString = New Font("Times New Roman", 10, FontStyle.Bold)
            e.Graphics.DrawString("Tax Amount:", fntString, 
    	     Brushes.Black, 500, 960)
            fntString = New Font("Times New Roman", 10, FontStyle.Regular)
            e.Graphics.DrawString(txtTaxAmount.Text, fntString, 
                    Brushes.Black, 640, 960, fmtString)
    
            fntString = New Font("Times New Roman", 10, FontStyle.Bold)
            e.Graphics.DrawString("Repair Total:", fntString, 
    	     Brushes.Black, 500, 980)
            fntString = New Font("Times New Roman", 10, FontStyle.Regular)
            e.Graphics.DrawString(txtTotalOrder.Text, fntString, 
    	     Brushes.Black, 640, 980, fmtString)
    
            fntString = New Font("Times New Roman", 10, FontStyle.Bold)
            e.Graphics.DrawString("Recommendations:", fntString, 
    	     Brushes.Black, 100, 900)
            fntString = New Font("Times New Roman", 10, FontStyle.Regular)
            e.Graphics.DrawString(txtRecommendations.Text, 
    	     fntString, Brushes.Black, 
                                New RectangleF(100, 920, 350, 280))
    End Sub
  38. In the Class Name combo box, select mnuFilePrint
  39. In the Method Name combo box, select Click and implement the event as follows:
     
    Private Sub mnuFilePrintClick(ByVal sender As Object, 
                                       ByVal e As System.EventArgs) 
                                       Handles mnuFilePrint.Click
            If dlgPrint.ShowDialog() = Windows.Forms.DialogResult.OK Then
                docPrint.Print()
            End If
    End Sub
  40. Execute the application and open one of the previously saved orders
  41. On the main menu of the form, click File -> Print and click OK
  42. After using it, close the form and return to your programming environment
 

Home Copyright © 2008-2016, FunctionX, Inc.