Home

Microsoft Visual Basic Application: Georgetown Dry Cleaner

 

Introduction to Databases

A database is referred to as file-based or flat-file when its values are saved in a regular file. These types of applications used to be difficult to create because of issues related to file processing.

New libraries such as the .NET Framework have made it very easy to save the values of an application. File processing is extremely developed in both the .NET Framework and Microsoft Visual Basic's own library. In this example, we will review how to create a file-based database.

Practical Learning: Introducing File-Based Applications

  1. Start Microsoft Visual Basic and create a Windows Forms Application named GeorgetownDryCleaner1
  2. In the Solution Explorer, right-click Form1.cs and click Rename
  3. Type Central.cs and press Enter
  4. From the Menus & Toolbars section of the Toolbox, click MenuStrip and click the form
  5. While the menu strip is still selected, in the Properties window, click (Name) and type mnuMain
  6. Under the Properties window, click Insert Standard Items
  7. On the form, click Help and press Delete
  8. Click Tools and press Delete
  9. Click Edit and press Delete
  10. Click File, click Save As and press Delete
  11. Using the Properties window, change the names of the menu items as follows:
     
    Text New Name
    &File mnuFile
    &New mnuFileNew
    &Open mnuFileOpen
    &Save mnuFileSave
    &Print mnuFilePrint
    Print Pre&view mnuFilePrintPreview
  12. Design the form as follows:
     
    Georgetown Dry Cleaner
     
    Control Name Text Additional Properties
    GroupBox GroupBox   Order Identification  
    Label Label   &Receipt #:  
    TextBox TextBox txtReceiptNumber 1000 TextAlign: Right
    Label Label   Customer Name:  
    TextBox TextBox txtCustomerName    
    Label Label   Customer Phone:  
    TextBox TextBox txtCustomerPhone    
    Label Label   Date Left:  
    DateTimePicker DateTimePicker dtpDateLeft    
    Label Label   Time Left:  
    DateTimePicker Date Time Picker dtpTimeLeft   Format: Time
    Label Label   Date Expected:  
    DateTimePicker DateTimePicker dtpDateExpected    
    Label Label   Time Expected:  
    DateTimePicker DateTimePicker dtpTimeExpected   Format: Time
    Label Label   Order &Status:  
    ComboBox ComboBox cbxOrderStatus    
    Label Label   D&ate Picked Up:  
    DateTimePicker DateTimePicker dtpDatePickedUp    
    Label Label   Time Pic&kep Up:  
    DateTimePicker DateTimePicker dtpTimePickedUp    
    GroupBox GroupBox   Order Processing  
    Label Label   Item Type  
    Label Label   Unit Price  
    Label Label   Qty  
    Label Label   Sub Total  
    Label Label   Shirts  
    TextBox TextBox txtShirtsUnitPrice 1.25 TextAlign: Right
    TextBox TextBox txtShirtsQuantity 0 TextAlign: Right
    TextBox TextBox txtShirtsSubTotal 0.00 TextAlign: Right
    Label Label   Pants  
    TextBox TextBox txtPantsUnitPrice 1.95 TextAlign: Right
    TextBox TextBox txtPantsQuantity   TextAlign: Right
    TextBox TextBox txtPantsSubTotal 0.00 TextAlign: Right
    ComboBox ComboBox cbxItem1 None Items:
    None
    Women Suit
    Dress
    Regular Skirt
    Skirt With Hook
    Men's Suit 2Pc
    Men's Suit 3Pc
    Sweaters
    Silk Shirt
    Tie
    Coat
    Jacket
    Swede
    TextBox TextBox txtItem1UnitPrice 0.00 TextAlign: Right
    TextBox TextBox txtItem1Quantity 0 TextAlign: Right
    TextBox TextBox txtItem1SubTotal 0.00 TextAlign: Right
    ComboBox ComboBox cbxItem2 None Items:
    None
    Women Suit
    Dress
    Regular Skirt
    Skirt With Hook
    Men's Suit 2Pc
    Men's Suit 3Pc
    Sweaters
    Silk Shirt
    Tie
    Coat
    Jacket
    Swede
    TextBox TextBox txtItem2UnitPrice 0.00 TextAlign: Right
    TextBox TextBox txtItem2Quantity 0 TextAlign: Right
    TextBox TextBox txtItem2SubTotal 0.00 TextAlign: Right
    ComboBox ComboBox cbxItem3 None Items:
    None
    Women Suit
    Dress
    Regular Skirt
    Skirt With Hook
    Men's Suit 2Pc
    Men's Suit 3Pc
    Sweaters
    Silk Shirt
    Tie
    Coat
    Jacket
    Swede
    TextBox TextBox txtItem3UnitPrice 0.00 TextAlign: Right
    TextBox TextBox txtItem3Quantity 0 TextAlign: Right
    TextBox TextBox txtItem3SubTotal 0.00 TextAlign: Right
    ComboBox ComboBox cbxItem4 None Items:
    None
    Women Suit
    Dress
    Regular Skirt
    Skirt With Hook
    Men's Suit 2Pc
    Men's Suit 3Pc
    Sweaters
    Silk Shirt
    Tie
    Coat
    Jacket
    Swede
    TextBox TextBox txtItem4UnitPrice 0.00 TextAlign: Right
    TextBox TextBox txtItem4Quantity 0 TextAlign: Right
    TextBox TextBox txtItem4SubTotal 0.00 TextAlign: Right
    GroupBox GroupBox   Order Summary  
    Label Label   Cleaning Total:  
    TextBox TextBox txtCleaningTotal 0.00 TextAlign: Right
    Label Label   Tax Rate:  
    TextBox TextBox txtTaxRate 7.75 TextAlign: Right
    Label Label   %  
    Label Label   Tax Amount:  
    TextBox TextBox txtTaxAmount 0.00 TextAlign: Right
    Label Label   Net Total:  
    TextBox TextBox txtNetPrice 0.00 TextAlign: Right
  13. Double-click the Time Left control and implement its ValueChanged event as follows:
     
    Private Sub dtpTimeLeftValueChanged(ByVal sender As System.Object, 
                                             ByVal e As System.EventArgs) 
                                             Handles dtpTimeLeft.ValueChanged
            Dim DateLeft As Date = dtpDateLeft.Value
            Dim TimeLeft As Date = dtpTimeLeft.Value
            Dim Time9AM As Date = New DateTime(TimeLeft.Year, 
                                               TimeLeft.Month, 
                                               TimeLeft.Day, 9, 0, 0)
    
            ' If the customer leaves clothes before 9AM...
            If TimeLeft <= Time9AM Then
                ' ... then they should be ready the same day after 5PM
                dtpDateExpected.Value = DateLeft
                dtpTimeExpected.Value = New DateTime(DateLeft.Year, 
                                                     DateLeft.Month, 
                                                     DateLeft.Day, 17, 0, 0)
            Else
                ' If the clothes were left after 9AM,
                ' then they will be available 
    	    ' the following business morning at 8AM
                ' If the following day is Sunday,
                ' then they will be ready the following Monday
                If DateLeft.DayOfWeek = DayOfWeek.Saturday Then
                    dtpDateExpected.Value = DateLeft.AddDays(2D)
                    dtpTimeExpected.Value = New DateTime(DateLeft.Year, 
                                                         DateLeft.Month, 
                                                     DateLeft.Day + 2, 8, 0, 0)
                Else
                    dtpDateExpected.Value = New DateTime(DateLeft.Year, 
                                                         DateLeft.Month, 
                                                         DateLeft.Day + 1)
                    dtpTimeExpected.Value = New DateTime(DateLeft.Year, 
                                                         DateLeft.Month, 
                                                     DateLeft.Day + 1, 8, 0, 0)
                End If
            End If
    End Sub
  14. Return to the form
  15. In the top section of the file, type Imports System.IO and press Enter to have it on its own line
  16. Under the Class Central line, declare three variables as follows:
     
    Imports System.IO
    
    Public Class Central
    
        Private iFilename As Integer
        Private IsNewCleaningOrder As Boolean
        Private Filename As String
  17. In the Class Name combo box, select mnuFileNew
  18. 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
            ' We will store our files in the following folder
            Dim strDirectory As String = 
    		"C:\Georgetown Cleaning Services\Receipts"
    
            Dim DirInfo = Directory.CreateDirectory(strDirectory)
    
            ' Get the list of files, if any, from our directory
            Dim ListOfFiles() = DirInfo.GetFiles()
    
            ' If there is no file in the directory,
            ' then we will use 1000 as the first file name
            If ListOfFiles.Length = 0 Then
                iFilename = 1000
            Else ' If there was at least one file in the directory
                ' Get a reference to the last file
                Dim LastFile As FileInfo = ListOfFiles(ListOfFiles.Length - 1)
                ' Get the name of the last file without its extension
                Dim fwe As String = 
    		Path.GetFileNameWithoutExtension(LastFile.FullName)
                ' Increment the name of the file by 1
                Try
                    iFilename = CInt(fwe) + 1
                Catch Exc As FormatException
    
                End Try
            End If
    
            ' Update our global name of the file
            Filename = strDirectory + "\" + iFilename.ToString() + ".gcs"
            txtReceiptNumber.Text = iFilename.ToString()
    
            txtCustomerName.Text = ""
            txtCustomerPhone.Text = ""
            dtpDateLeft.Value = DateTime.Today
            dtpTimeLeft.Value = DateTime.Today
            dtpDateExpected.Value = DateTime.Today
            dtpTimeExpected.Value = DateTime.Today
    
            cbxStatus.Text = "Not Yet Ready"
            dtpDatePickedUp.Value = DateTime.Today
            dtpTimePickedUp.Value = DateTime.Today
    
            txtUnitPriceShirts.Text = "1.25"
            txtQuantityShirts.Text = "0"
            txtSubTotalShirts.Text = "0.00"
            txtUnitPricePants.Text = "1.95"
            txtQuantityPants.Text = "0"
            txtSubTotalPants.Text = "0.00"
            cbxItem1.Text = "None"
            txtUnitPriceItem1.Text = "0.00"
            txtQuantityItem1.Text = "0"
            txtSubTotalItem1.Text = "0.00"
            cbxItem2.Text = "None"
            txtUnitPriceItem2.Text = "0.00"
            txtQuantityItem2.Text = "0"
            txtSubTotalItem2.Text = "0.00"
            cbxItem3.Text = "None"
            txtUnitPriceItem3.Text = "0.00"
            txtQuantityItem3.Text = "0"
            txtSubTotalItem3.Text = "0.00"
            cbxItem4.Text = "None"
            txtUnitPriceItem4.Text = "0.00"
            txtQuantityItem4.Text = "0"
            txtSubTotalItem4.Text = "0.00"
    
            txtCleaningTotal.Text = "0.00"
            txtTaxRate.Text = "7.75"
            txtTaxAmount.Text = "0.00"
            txtCleaningTotal.Text = "0.00"
    
            txtCustomerName.Focus()
    End Sub
  19. Return to the form
  20. Under the previous End Sub line, define a sub procedure as follows:
     
    Private Sub SaveCleaningOrder()
            ' We will store our files in the following folder    
            Dim strDirectory As String = 
    		"C:\Georgetown Cleaning Services\Receipts"
            Dim dirInfo As DirectoryInfo = 
    		Directory.CreateDirectory(strDirectory)
    
            ' Get the list of files, if any, from our directory
            Dim ListOfFiles() As FileInfo = dirInfo.GetFiles()
    
            ' If this is a new cleaning order,
            ' get ready to create a name for the file
            If IsNewCleaningOrder = True Then
                ' If there is no file in the directory,
                ' then we will use 1000 as the first file name
                If ListOfFiles.Length = 0 Then
                    iFilename = 1000
                Else ' If there was at least one file in the directory
                    ' Get a reference to the last file
                    Dim LastFile As FileInfo = 
    			ListOfFiles(ListOfFiles.Length - 1)
                    ' Get the name of the last file without its extension
                    Dim fwe As String = 
    			Path.GetFileNameWithoutExtension(LastFile.FullName)
                    ' Increment the name of the file by 1
                    iFilename = CInt(fwe) + 1
                End If
    
                ' Update our global name of the file
                Filename = strDirectory + "\" + iFilename.ToString() + ".gcs"
                txtReceiptNumber.Text = iFilename.ToString()
    
                IsNewCleaningOrder = False
                ' If a cleaning order was already opened, 
    	    ' we will simply update it
            Else
                Filename = "C:\Georgetown Cleaning Services\Receipts\" & 
                txtReceiptNumber.Text & ".gcs"
            End If
    
            Dim stmGCS As StreamWriter = New StreamWriter(Filename)
    
            Try
                stmGCS.WriteLine(txtCustomerName.Text)
                stmGCS.WriteLine(txtCustomerPhone.Text)
                stmGCS.WriteLine(dtpDateLeft.Value.ToString("D"))
                stmGCS.WriteLine(dtpTimeLeft.Value.ToString("t"))
                stmGCS.WriteLine(dtpDateExpected.Value.ToString("D"))
                stmGCS.WriteLine(dtpTimeExpected.Value.ToString("t"))
    
                stmGCS.WriteLine(cbxStatus.Text)
                stmGCS.WriteLine(dtpDatePickedUp.Value.ToString("D"))
                stmGCS.WriteLine(dtpTimePickedUp.Value.ToString("t"))
    
                stmGCS.WriteLine(txtUnitPriceShirts.Text)
                stmGCS.WriteLine(txtQuantityShirts.Text)
                stmGCS.WriteLine(txtSubTotalShirts.Text)
                stmGCS.WriteLine(txtUnitPricePants.Text)
                stmGCS.WriteLine(txtQuantityPants.Text)
                stmGCS.WriteLine(txtSubTotalPants.Text)
    
                stmGCS.WriteLine(cbxItem1.Text)
                stmGCS.WriteLine(txtUnitPriceItem1.Text)
                stmGCS.WriteLine(txtQuantityItem1.Text)
                stmGCS.WriteLine(txtSubTotalItem1.Text)
    
                stmGCS.WriteLine(cbxItem2.Text)
                stmGCS.WriteLine(txtUnitPriceItem2.Text)
                stmGCS.WriteLine(txtQuantityItem2.Text)
                stmGCS.WriteLine(txtSubTotalItem2.Text)
    
                stmGCS.WriteLine(cbxItem3.Text)
                stmGCS.WriteLine(txtUnitPriceItem3.Text)
                stmGCS.WriteLine(txtQuantityItem3.Text)
                stmGCS.WriteLine(txtSubTotalItem3.Text)
    
                stmGCS.WriteLine(cbxItem4.Text)
                stmGCS.WriteLine(txtUnitPriceItem4.Text)
                stmGCS.WriteLine(txtQuantityItem4.Text)
                stmGCS.WriteLine(txtSubTotalItem4.Text)
    
                stmGCS.WriteLine(txtCleaningTotal.Text)
                stmGCS.WriteLine(txtTaxRate.Text)
                stmGCS.WriteLine(txtTaxAmount.Text)
                stmGCS.WriteLine(txtNetPrice.Text)
            Finally
                stmGCS.Close()
            End Try
    End Sub
  21. Under the above End Sub line, implement an event as follows:
     
    Private Sub ControlLeave(ByVal Sender As Object, ByVal e As EventArgs) 
                                 Handles txtUnitPriceShirts.Leave, 
                                         txtUnitPricePants.Leave, 
                                         txtUnitPriceItem1.Leave, 
                                         txtUnitPriceItem2.Leave, 
                                         txtUnitPriceItem3.Leave, 
                                         txtUnitPriceItem4.Leave, 
                                         txtQuantityShirts.Leave, 
                                         txtQuantityPants.Leave, 
                                         txtQuantityItem1.Leave, 
                                         txtQuantityItem2.Leave, 
                                         txtQuantityItem3.Leave, 
                                         txtQuantityItem4.Leave, 
                                         txtTaxRate.Leave
            Dim UnitPriceShirts As Double
            Dim UnitPricePants As Double
            Dim UnitPriceItem1 As Double
            Dim UnitPriceItem2 As Double
            Dim UnitPriceItem3 As Double
            Dim UnitPriceItem4 As Double
            Dim SubTotalShirts As Double
            Dim SubTotalPants As Double
            Dim SubTotalItem1 As Double
            Dim SubTotalItem2 As Double
            Dim SubTotalItem3 As Double
            Dim SubTotalItem4 As Double
            Dim QuantityShirts As Integer = 1
            Dim QuantityPants As Integer = 1
            Dim QuantityItem1 As Integer = 1
            Dim QuantityItem2 As Integer = 1
            Dim QuantityItem3 As Integer = 1
            Dim QuantityItem4 As Integer = 4
            Dim CleaningTotal As Double
            Dim TaxRate As Double
            Dim TaxAmount As Double
            Dim NetPrice As Double
    
            ' Retrieve the unit price of this item
            ' Just in case the user types an invalid value,
            ' we are using a try...catch
            Try
                unitPriceShirts = CDbl(txtUnitPriceShirts.Text)
            Catch Exc As FormatException
                MsgBox("The value you entered for the price of " & 
                                "shirts is not valid" & 
                                vbCrLf & "Please try again")
                Exit Sub
            End Try
    
            ' Retrieve the number of this item
            ' Just in case the user types an invalid value,
            ' we are using a try...catch
            Try
                QuantityShirts = CInt(txtQuantityShirts.Text)
            Catch Exc As FormatException
                MsgBox("The value you entered for the number of " & 
                                "shirts is not valid" & 
                                vbCrLf & "Please try again")
                Exit Sub
            End Try
    
            Try
                UnitPricePants = CDbl(txtUnitPricePants.Text)
            Catch Exc As FormatException
                MsgBox("The value you entered for the price of " & 
                                "pants is not valid" & 
                                vbCrLf & "Please try again")
                Exit Sub
            End Try
    
            Try
                QuantityPants = CInt(txtQuantityPants.Text)
            Catch Exc As FormatException
                MsgBox("The value you entered for the number of " & 
                                "pants is not valid" & 
                                vbCrLf & "Please try again")
                Exit Sub
            End Try
    
            If (cbxItem1.Text = "None") Or (cbxItem1.Text = "") Then
                QuantityItem1 = 0
                UnitPriceItem1 = 0.0
            Else
                Try
                    UnitPriceItem1 = CDbl(txtUnitPriceItem1.Text)
                Catch Exc As FormatException
                    MsgBox("The value you entered for the price is not valid" & 
                                vbCrLf & "Please try again")
                    Exit Sub
                End Try
    
                Try
                    QuantityItem1 = CInt(txtQuantityItem1.Text)
                Catch Exc As FormatException
                    MsgBox("The value you entered is not valid" & 
                                vbCrLf & "Please try again")
                    Exit Sub
                End Try
            End If
    
            If (cbxItem2.Text = "None") Or (cbxItem2.Text = "") Then
                QuantityItem2 = 0
                UnitPriceItem2 = 0.0
            Else
                Try
                    UnitPriceItem2 = CDbl(txtUnitPriceItem2.Text)
                Catch Exc As FormatException
                    MsgBox("The value you entered for " & 
               "the price is not valid" & 
                                    vbCrLf & "Please try again")
                    Exit Sub
                End Try
    
                Try
                    QuantityItem2 = CInt(txtQuantityItem2.Text)
                Catch Exc As FormatException
                    MsgBox("The value you entered is not valid" & 
                                vbCrLf & "Please try again")
                    Exit Sub
                End Try
            End If
    
            If (cbxItem3.Text = "None") Or (cbxItem3.Text = "") Then
                QuantityItem3 = 0
                UnitPriceItem3 = 0.0
            Else
                Try
                    UnitPriceItem3 = CDbl(txtUnitPriceItem3.Text)
                Catch Exc As FormatException
                    MsgBox("The value you entered for the " & 
               "price is not valid" & 
                                    vbCrLf & "Please try again")
                    Exit Sub
                End Try
    
                Try
                    QuantityItem3 = CInt(txtQuantityItem3.Text)
                Catch Exc As FormatException
                    MsgBox("The value you entered is not valid" & 
                                vbCrLf & "Please try again")
                    Exit Sub
                End Try
            End If
    
            If (cbxItem4.Text = "None") Or (cbxItem4.Text = "") Then
                QuantityItem4 = 0
                UnitPriceItem4 = 0.0
            Else
                Try
                    UnitPriceItem4 = CDbl(txtUnitPriceItem4.Text)
                Catch Exc As FormatException
                    MsgBox("The value you entered for the price is not valid" & 
                                "\nPlease try again")
                    Exit Sub
                End Try
                Try
                    QuantityItem4 = CInt(txtQuantityItem4.Text)
                Catch Exc As FormatException
                    MsgBox("The value you entered is not valid" & 
                                "\nPlease try again")
                    Exit Sub
                End Try
            End If
    
            ' Calculate the sub-total for this item
            SubTotalShirts = QuantityShirts * unitPriceShirts
            SubTotalPants = QuantityPants * UnitPricePants
            SubTotalItem1 = QuantityItem1 * UnitPriceItem1
            SubTotalItem2 = QuantityItem2 * UnitPriceItem2
            SubTotalItem3 = QuantityItem3 * UnitPriceItem3
            SubTotalItem4 = QuantityItem4 * UnitPriceItem4
    
            ' Calculate the total based on sub-totals
            CleaningTotal = SubTotalShirts + SubTotalPants + SubTotalItem1 + 
                            SubTotalItem2 + SubTotalItem3 + SubTotalItem4
    
            TaxRate = CDbl(txtTaxRate.Text)
            ' Calculate the amount owed for the taxes
            TaxAmount = cleaningTotal * TaxRate / 100
            ' Add the tax amount to the total order
            NetPrice = cleaningTotal + TaxAmount
    
            ' Display the sub-total in the corresponding text box
            txtSubTotalShirts.Text = FormatNumber(SubTotalShirts)
            txtSubTotalPants.Text = FormatNumber(SubTotalPants)
            txtSubTotalItem1.Text = FormatNumber(SubTotalItem1)
            txtSubTotalItem2.Text = FormatNumber(SubTotalItem2)
            txtSubTotalItem3.Text = FormatNumber(SubTotalItem3)
            txtSubTotalItem4.Text = FormatNumber(SubTotalItem4)
    
            txtCleaningTotal.Text = FormatNumber(CleaningTotal)
            txtTaxAmount.Text = FormatNumber(TaxAmount)
            txtNetPrice.Text = FormatNumber(NetPrice)
    
            SaveCleaningOrder()
    End Sub
  22. In the Class Name combo box, select mnuFileSave
  23. 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
            SaveCleaningOrder()
    End Sub
  24. Execute the application
  25. Create a cleaning order
     
    Georgetown Dry Cleaner
  26. Click New and create a few more cleaning orders
     
    Georgetown Dry Cleaner
  27. Close the form and return to your programming environment
  28. In the Class Name combo box, select mnuFileOpen
  29. In the Method Name combo box, select Click and implement the event as follows:
     
    Private Sub mnuFileOpenClick(ByVal sender As Object, 
                                      ByVal e As System.EventArgs) 
                                      Handles mnuFileOpen.Click
            If txtReceiptNumber.Text = "" Then
                Exit Sub
            Else
                Try
                    IsNewCleaningOrder = False
                    Filename = "C:\Georgetown Cleaning Services\Receipts\" & 
                    txtReceiptNumber.Text & ".gcs"
    
                    Dim rdrGCS As StreamReader = New StreamReader(Filename)
    
                    Try
                        txtCustomerName.Text = rdrGCS.ReadLine()
                        txtCustomerPhone.Text = rdrGCS.ReadLine()
                        dtpDateLeft.Value = DateTime.Parse(rdrGCS.ReadLine())
                        dtpTimeLeft.Value = DateTime.Parse(rdrGCS.ReadLine())
                        dtpDateExpected.Value = DateTime.Parse(rdrGCS.ReadLine())
                        dtpTimeExpected.Value = DateTime.Parse(rdrGCS.ReadLine())
    
                        cbxStatus.Text = rdrGCS.ReadLine()
                        dtpDatePickedUp.Value = DateTime.Parse(rdrGCS.ReadLine())
                        dtpTimePickedUp.Value = DateTime.Parse(rdrGCS.ReadLine())
    
                        txtUnitPriceShirts.Text = rdrGCS.ReadLine()
                        txtQuantityShirts.Text = rdrGCS.ReadLine()
                        txtSubTotalShirts.Text = rdrGCS.ReadLine()
                        txtUnitPricePants.Text = rdrGCS.ReadLine()
                        txtQuantityPants.Text = rdrGCS.ReadLine()
                        txtSubTotalPants.Text = rdrGCS.ReadLine()
    
                        cbxItem1.Text = rdrGCS.ReadLine()
                        txtUnitPriceItem1.Text = rdrGCS.ReadLine()
                        txtQuantityItem1.Text = rdrGCS.ReadLine()
                        txtSubTotalItem1.Text = rdrGCS.ReadLine()
    
                        cbxItem2.Text = rdrGCS.ReadLine()
                        txtUnitPriceItem2.Text = rdrGCS.ReadLine()
                        txtQuantityItem2.Text = rdrGCS.ReadLine()
                        txtSubTotalItem2.Text = rdrGCS.ReadLine()
    
                        cbxItem3.Text = rdrGCS.ReadLine()
                        txtUnitPriceItem3.Text = rdrGCS.ReadLine()
                        txtQuantityItem3.Text = rdrGCS.ReadLine()
                        txtSubTotalItem3.Text = rdrGCS.ReadLine()
    
                        cbxItem4.Text = rdrGCS.ReadLine()
                        txtUnitPriceItem4.Text = rdrGCS.ReadLine()
                        txtQuantityItem4.Text = rdrGCS.ReadLine()
                        txtSubTotalItem4.Text = rdrGCS.ReadLine()
    
                        txtCleaningTotal.Text = rdrGCS.ReadLine()
                        txtTaxRate.Text = rdrGCS.ReadLine()
                        txtTaxAmount.Text = rdrGCS.ReadLine()
                        txtNetPrice.Text = rdrGCS.ReadLine()
                    Finally
                        rdrGCS.Close()
                    End Try
                Catch Exc As FileNotFoundException
                    MsgBox("There is no cleaning order with that receipt number")
                End Try
            End If
    End Sub
  30. Execute the application
  31. Type 1001 for the receipt number and, on the main menu of the form, click File -> Open
  32. Close the form and return to your programming environment
  33. In the Class Name combo box, select (Central Events)
  34. In the Method Name combo box, select Load and implement the event as follows:
     
    Private Sub CentralLoad(ByVal sender As Object, 
                                 ByVal e As System.EventArgs) 
                                 Handles Me.Load
    
            mnuFileNewClick(sender, e)
    End Sub
  35. Save all
  36. From the Printing section of the Toolbox, click PrintDocument and click the form
  37. While the new control is still selected, in the Properties window, click the Properties button, click (Name), type docPrint and press Enter
  38. Under the form, double-click docPrint and implement its 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, 720, 90)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 60, 93, 720, 93)
    
            Dim strDisplay As String = "Georgetown Dry Cleaning Services"
            Dim fntString As System.Drawing.Font = New Font("Times New Roman", 
                                                            28, FontStyle.Bold)
            e.Graphics.DrawString(strDisplay, fntString, 
                    Brushes.Black, 80, 100)
    
            strDisplay = "Customer Cleaning Order"
            fntString = New System.Drawing.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, 720, 184)
            e.Graphics.DrawLine(New Pen(Color.Black, 2), 60, 188, 720, 188)
    
            fntString = New System.Drawing.Font("Times New Roman", 12, 
                    FontStyle.Bold)
            e.Graphics.DrawString("", fntString, 
                    Brushes.Black, 80, 200)
    
            fntString = New System.Drawing.Font("Times New Roman", 12, 
                    FontStyle.Bold)
            e.Graphics.DrawString("Customer Identification:  ", fntString, 
                    Brushes.Black, 100, 220)
            fntString = New System.Drawing.Font("Times New Roman", 12, 
                    FontStyle.Regular)
            e.Graphics.DrawString(txtCustomerName.Text & "  -  " & 
                                      txtCustomerPhone.Text, fntString, 
                                      Brushes.Black, 300, 220)
    
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 100, 240, 700, 240)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Date Left:        ", fntString, 
                                          Brushes.Black, 100, 260)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
    
            e.Graphics.DrawString(dtpDateLeft.Value.ToString("D"), fntString, 
                                      Brushes.Black, 300, 260)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 100, 280, 700, 280)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Time Left: ", fntString, 
                                      Brushes.Black, 500, 260)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
            e.Graphics.DrawString(dtpTimeLeft.Value.ToString("t"), fntString, 
                                      Brushes.Black, 620, 260)
    
            fntString = New System.Drawing.Font("Times New Roman", 
         12, FontStyle.Bold)
            e.Graphics.DrawString("Date Expected:    ", fntString, 
                    Brushes.Black, 100, 300)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
            e.Graphics.DrawString(dtpDateExpected.Value.ToString("D"), 
         fntString, Brushes.Black, 300, 300)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Time Expected: ", fntString, 
                                      Brushes.Black, 500, 300)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
            e.Graphics.DrawString(dtpTimeExpected.Value.ToString("t"), 
         fntString, Brushes.Black, 620, 300)
    
            e.Graphics.DrawLine(New Pen(Color.Black, 2), 100, 320, 700, 320)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Item Type", 
                                      fntString, Brushes.Black, 140, 350)
            e.Graphics.DrawString("Unit Price", 
                                      fntString, Brushes.Black, 300, 350)
            e.Graphics.DrawString("Quantity", 
                                      fntString, Brushes.Black, 405, 350)
            e.Graphics.DrawString("Sub-Total", 
                                      fntString, Brushes.Black, 500, 350)
    
            e.Graphics.DrawLine(New Pen(Color.Black, 2), 140, 370, 640, 370)
    
            Dim fmtString As StringFormat = New StringFormat
            fmtString.Alignment = StringAlignment.Far
    
            e.Graphics.DrawString("Shirts", 
                                      fntString, Brushes.Black, 150, 380)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
            e.Graphics.DrawString(txtUnitPriceShirts.Text, fntString, 
                    Brushes.Black, 350, 380, fmtString)
            e.Graphics.DrawString(txtQuantityShirts.Text, fntString, 
                    Brushes.Black, 440, 380, fmtString)
            e.Graphics.DrawString(txtSubTotalShirts.Text, fntString, 
                    Brushes.Black, 550, 380, fmtString)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 140, 400, 640, 400)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Pants", 
                                      fntString, Brushes.Black, 150, 410)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
            e.Graphics.DrawString(txtUnitPricePants.Text, fntString, 
                    Brushes.Black, 350, 410, fmtString)
            e.Graphics.DrawString(txtQuantityPants.Text, fntString, 
                    Brushes.Black, 440, 410, fmtString)
            e.Graphics.DrawString(txtSubTotalPants.Text, fntString, 
                    Brushes.Black, 550, 410, fmtString)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 140, 430, 640, 430)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString(cbxItem1.Text, 
                                      fntString, Brushes.Black, 150, 440)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
            e.Graphics.DrawString(txtUnitPriceItem1.Text, fntString, 
                    Brushes.Black, 350, 440, fmtString)
            e.Graphics.DrawString(txtQuantityItem1.Text, fntString, 
                    Brushes.Black, 440, 440, fmtString)
            e.Graphics.DrawString(txtSubTotalItem1.Text, fntString, 
                    Brushes.Black, 550, 440, fmtString)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 140, 460, 640, 460)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString(cbxItem2.Text, 
                                      fntString, Brushes.Black, 150, 470)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
            e.Graphics.DrawString(txtUnitPriceItem2.Text, fntString, 
                    Brushes.Black, 350, 470, fmtString)
            e.Graphics.DrawString(txtQuantityItem2.Text, fntString, 
                    Brushes.Black, 440, 470, fmtString)
            e.Graphics.DrawString(txtSubTotalItem2.Text, fntString, 
                    Brushes.Black, 550, 470, fmtString)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 140, 490, 640, 490)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString(cbxItem3.Text, 
                                      fntString, Brushes.Black, 150, 500)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
            e.Graphics.DrawString(txtUnitPriceItem3.Text, fntString, 
                    Brushes.Black, 350, 500, fmtString)
            e.Graphics.DrawString(txtQuantityItem3.Text, fntString, 
                    Brushes.Black, 440, 500, fmtString)
            e.Graphics.DrawString(txtSubTotalItem3.Text, fntString, 
                    Brushes.Black, 550, 500, fmtString)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 140, 520, 640, 520)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString(cbxItem4.Text, 
                    fntString, Brushes.Black, 150, 530)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
            e.Graphics.DrawString(txtUnitPriceItem4.Text, fntString, 
                    Brushes.Black, 350, 530, fmtString)
            e.Graphics.DrawString(txtQuantityItem4.Text, fntString, 
                    Brushes.Black, 440, 530, fmtString)
            e.Graphics.DrawString(txtSubTotalItem4.Text, fntString, 
                    Brushes.Black, 550, 530, fmtString)
            e.Graphics.DrawLine(New Pen(Color.Black, 2), 140, 550, 640, 550)
    
            fntString = New System.Drawing.Font("Times New Roman", 12, 
         FontStyle.Bold)
            e.Graphics.DrawString("Order Summary", fntString, 
                              Brushes.Black, 260, 600)
            e.Graphics.DrawLine(New Pen(Color.Black, 2), 220, 620, 560, 620)
    
            fntString = New System.Drawing.Font("Times New Roman", 
         10, FontStyle.Bold)
            e.Graphics.DrawString("Cleaning Total:", fntString, 
                              Brushes.Black, 260, 630)
            fntString = New System.Drawing.Font("Times New Roman", 
         10, FontStyle.Regular)
            e.Graphics.DrawString(txtCleaningTotal.Text, fntString, 
                              Brushes.Black, 440, 630, fmtString)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 
       220, 650, 520, 650)
    
            fntString = New System.Drawing.Font("Times New Roman", 
         10, FontStyle.Bold)
            e.Graphics.DrawString("Tax Rate:", fntString, 
                              Brushes.Black, 260, 660)
            fntString = New System.Drawing.Font("Times New Roman", 
         10, FontStyle.Regular)
            e.Graphics.DrawString(txtTaxRate.Text, fntString, 
                              Brushes.Black, 440, 660, fmtString)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 
       220, 680, 520, 680)
    
            fntString = New System.Drawing.Font("Times New Roman", 
         10, FontStyle.Bold)
            e.Graphics.DrawString("Tax Amount:", fntString, 
                              Brushes.Black, 260, 690)
            fntString = New System.Drawing.Font("Times New Roman", 
         10, FontStyle.Regular)
            e.Graphics.DrawString(txtTaxAmount.Text, fntString, 
                       Brushes.Black, 440, 690, fmtString)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 
       220, 710, 520, 710)
    
            fntString = New System.Drawing.Font("Times New Roman", 
         10, FontStyle.Bold)
            e.Graphics.DrawString("Net Price:", fntString, 
                    Brushes.Black, 260, 720)
            fntString = New System.Drawing.Font("Times New Roman", 
         10, FontStyle.Regular)
            e.Graphics.DrawString(txtNetPrice.Text, fntString, 
                    Brushes.Black, 440, 720, fmtString)
            e.Graphics.DrawLine(New Pen(Color.Black, 2), 
    			    200, 740, 560, 740)
    End Sub
  39. Return to the form
  40. From the Printing section of the Toolbox, click PrintDialog and click the form
  41. In the Properties window, change its Name to dlgPrint
  42. Still in the Properties windows, set its Document property to docPrint
  43. On the main menu of the form, click File and double-click Print
  44. Implement the event as follows:
     
    Private Sub mnuFilePrintClick(ByVal sender As Object, 
                                       ByVal e As System.EventArgs) 
                                       Handles mnuFilePrint.Click
            If dlgPrint.ShowDialog() = DialogResult.OK Then
                docPrint.Print()
            End If
    End Sub
  45. Return to the form
  46. From the Printing section of the Toolbox, click PrintPreviewDialog and click the form
  47. In the Properties window, change its Name to dlgPrintPreview
  48. Still in the Properties windows, set its Document property to docPrint
  49. On the main menu of the form, click File and double-click Print Preview
  50. Implement the event as follows:
     
    Private Sub mnuFilePrintPreviewClick(ByVal sender As Object, 
                                              ByVal e As System.EventArgs) 
                                              Handles mnuFilePrintPreview.Click
            dlgPrintPreview.ShowDialog()
    End Sub
  51. In the Class Name combo box, select mnuFileExit
  52. In the Method Name combo box, select Click and implement the event as follows:
     
    Private Sub mnuFileExitClick(ByVal sender As Object, 
                                      ByVal e As System.EventArgs) 
                                      Handles mnuFileExit.Click
            End
    End Sub
  53. Execute the application
  54. Open an existing cleaning order and print preview it
     
    Georgetown Dry Cleaner
  55. Close the form and return to your programming environment
 

Home Copyright © 2008-2016, FunctionX, Inc.