Home

Example Application: Bethesda Car Rental

 

Introduction

A data relationship is a type of relationship that is created between two tables so that information can flow from one object to another. This makes it possible and easy for effective data entry.

In this application, we explore some of the features of data relationships as they are implemented in the DataSet class of the .NET Framework. The application we create is a fictitious car rental company (Bethesda Car Rental) where customers can reserve, rent, and/or take possession of a car.

 

Practical LearningPractical Learning: Introducing the Application

  1. Start Microsoft Visual Basic and create a new Windows Forms Application named BethesdaCarRental2
  2. To add a new form to the project, in the Solution Explorer, right-click BethesdaCarRental2 -> Add -> Windows Form...
  3. Set the Name to OrderProcessing and press Enter
  4. Design the form as follows:
     
    Bethesda Car Rental: Order Processing
    Control Text Name Other Properties
    Label Processed By:   AutoSize: False
    BackColor: Gray
    BorderStyle: FixedSingle
    ForeColor: White
    TextAlign: MiddleLeft
    Label Employee #:    
    MaskedTextBox   cbxEmployeeID  
    Label Employee Name:    
    TextBox   txtEmployeeName  
    Label Processed For   AutoSize: False
    BackColor: Gray
    BorderStyle: FixedSingle
    ForeColor: White
    TextAlign: MiddleLeft
    Label Driver's Lic #:    
    TextBox   cbxCustomerID  
    Label Cust Name:    
    TextBox   txtCustomerName  
    Label Address:    
    TextBox   txtCustomerAddress  
    Label City:    
    TextBox   txtCustomerCity  
    Label State:    
    ComboBox   cbxCustomerStates DropDownStyle: DropDownList
    Sorted: True
    Items: AL, AK, AZ, AR, CA, CO, CT, DE, DC, FL, GA, HI, ID, IL, IN, IA, KS, KY, LA, ME, MD, MA, MI, MN, MS, MO, MT, NE, NV, NH, NJ, NM, NY, NC, ND, OH, OK, OR, PA, RI, SC, SD, TN, TX, UT, VT, VA, WA, WV, WI, WY
    Label ZIP Code    
    TextBox   txtCustomerZIPCode  
    Label Car Selected   AutoSize: False
    BackColor: Gray
    BorderStyle: FixedSingle
    ForeColor: White
    TextAlign: MiddleLeft
    Label Tag Number:    
    TextBox   cbxCarID  
    Label Car Condition:    
    ComboBox   cbxCarConditions Sorted: True
    Items:
    Needs Repair
    Drivable
    Excellent
    Label Make:    
    TextBox   txtMake  
    Label Model:    
    TextBox   txtModel  
    Label Year:    
    TextBox   txtCarYear  
    label Tank Level:    
    ComboBox   cbxTankLevels Empty
    1/4 Empty
    1/2 Full
    3/4 Full
    Full
    Label Mileage Start:    
    TextBox   txtMileageStart TextAlign: Right
    Label Mileage }:    
    TextBox   txtMileage} TextAlign: Right
    Label Order Timing   AutoSize: False
    BackColor: Gray
    BorderStyle: FixedSingle
    ForeColor: White
    TextAlign: MiddleLeft
    Label Start Date:    
    DateTimePicker   dtpStartDate  
    Label End Date:    
    DateTimePicker   dtpEndDate  
    Label Days:    
    TextBox 0 txtDays TextAlign: Right
    Label Order Status    
    ComboBox   cbxOrderStatus Items:
    Car On Road
    Car Returned
    Order Reserved
    Label Order Evaluation   AutoSize: False
    BackColor: Gray
    BorderStyle: FixedSingle
    ForeColor: White
    TextAlign: MiddleLeft
    Label Rate Applied:    
    TextBox 0.00 txtRateApplied TextAlign: Right
    Button Rental Rates btnRentalRates  
    Label Sub-Total:    
    TextBox 0.00 txtSubTotal TextAlign: Right
    Button Calculate btnCalculate  
    Label Tax Rate:    
    TextBox 7.75 txtTaxRate TextAlign: Right
    Label %    
    Button Save btnSave  
    Label Tax Amount:    
    TextBox 0.00 txtTaxAmount TextAlign: Right
    Button Print... btnPrint  
    Label Order Total:    
    TextBox 0.00 txtOrderTotal TextAlign: Right
    Button Print Preview... btnPrintPreview  
    Label Receipt #:    
    TextBox 0 txtReceiptNumber  
    Button Open btnOpen  
    Button New Rental Order/Reset btnNewRentalOrder  
    Button Close btnClose  
  5. Right-click the Order Processing form and click View Code
  6. Above the Start Date date time picker control
    Imports System.IO
    
    Public Class OrderProcessing
    
    End Class
  7. In the Class Name combo box, select dtpStartDate
  8. In the Method Name combo box, select ValueChanged and implement the event as follows:
    Imports System.IO
    
    Public Class OrderProcessing
    
        Private Sub dtpStartDateValueChanged(ByVal sender As Object, 
                                              ByVal e As System.EventArgs) 
                                              Handles dtpStartDate.ValueChanged
            dtpEndDate.Value = dtpStartDate.Value
        End Sub
    End Class
  9. In the Class Name combo box, select dtpEndDate
  10. In the Method Name combo box, select ValueChanged and implement the event as follows:
    ' This event approximately evaluates the number of days as a
    ' difference between the end date and the starting date
    Private Sub dtpEndDateValueChanged(ByVal sender As Object, 
                                        ByVal e As System.EventArgs) 
                                        Handles dtpEndDate.ValueChanged
        Dim Days As Integer
    
        Dim dteStart As DateTime = dtpStartDate.Value
        Dim dteEnd As DateTime = dtpEndDate.Value
    
        ' Let's calculate the difference in days
        Dim tme As TimeSpan = dteEnd - dteStart
        Days = tme.Days
    
        ' If the customer returns the car the same day, 
        ' we consider that the car was rented for 1 day
        If Days = 0 Then
            Days = 1
        End If
    
        txtDays.Text = Days
        ' At any case, we will let the clerk specify the actual number of days
    End Sub
  11. In the Class Name combo box, select btnCalculate
  12. In the Method Name combo box, select Click and implement the event as follows:
    Private Sub btnCalculateClick(ByVal sender As Object, 
                                       ByVal e As System.EventArgs) 
                                       Handles btnCalculate.Click
            Dim Days As Integer
            Dim RateApplied As Double
            Dim SubTotal As Double
            Dim TaxRate As Double
            Dim TaxAmount As Double
            Dim OrderTotal As Double
    
            Try
                Days = CInt(txtDays.Text)
            Catch Exc As FormatException
                MsgBox("Invalid Number of Days")
            End Try
    
            Try
                RateApplied = CDbl(txtRateApplied.Text)
            Catch Exc As FormatException
                MsgBox("Invalid Amount for Rate Applied")
            End Try
    
            SubTotal = Days * RateApplied
            txtSubTotal.Text = FormatNumber(SubTotal)
    
            Try
                TaxRate = CDbl(txtTaxRate.Text)
            Catch Exc As FormatException
                MsgBox("Invalid Tax Rate")
            End Try
    
            TaxAmount = SubTotal * TaxRate / 100
            txtTaxAmount.Text = FormatNumber(TaxAmount)
    
            OrderTotal = SubTotal + TaxAmount
            txtOrderTotal.Text = FormatNumber(OrderTotal)
    End Sub
  13. Return to the Order Processing form
  14. From the Printing section of the Toolbox, click PrintDocument and click the form
  15. In the Properties window, set its (Name) to docPrint and press Enter
  16. Right-click the form and click View Code
  17. In the Class Name combo box, select docPrint
  18. 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), 80, 90, 750, 90)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 80, 93, 750, 93)
    
            Dim strDisplay As String = "Bethesda Car Rental"
            Dim fntString As Font = New Font("Times New Roman", 28, 
                            FontStyle.Bold)
            e.Graphics.DrawString(strDisplay, fntString, 
                            Brushes.Black, 240, 100)
    
            strDisplay = "Car Rental Order"
            fntString = New System.Drawing.Font("Times New Roman", 22, 
                            FontStyle.Regular)
            e.Graphics.DrawString(strDisplay, fntString, 
                            Brushes.Black, 320, 150)
    
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 80, 187, 750, 187)
            e.Graphics.DrawLine(New Pen(Color.Black, 2), 80, 190, 750, 190)
    
            fntString = New System.Drawing.Font("Times New Roman", 12, 
                    FontStyle.Bold)
            e.Graphics.DrawString("Receipt #:  ", fntString, 
                    Brushes.Black, 100, 220)
            fntString = New System.Drawing.Font("Times New Roman", 12, 
                    FontStyle.Regular)
            e.Graphics.DrawString(txtReceiptNumber.Text, fntString, 
                                      Brushes.Black, 260, 220)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 100, 240, 380, 240)
    
            fntString = New System.Drawing.Font("Times New Roman", 12, 
                    FontStyle.Bold)
            e.Graphics.DrawString("Processed By:  ", fntString, 
                    Brushes.Black, 420, 220)
            fntString = New System.Drawing.Font("Times New Roman", 12, 
                    FontStyle.Regular)
            e.Graphics.DrawString(txtEmployeeName.Text, fntString, 
                                      Brushes.Black, 550, 220)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 420, 240, 720, 240)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
    
            e.Graphics.FillRectangle(Brushes.Gray, 
                                     New Rectangle(100, 260, 620, 20))
            e.Graphics.DrawRectangle(Pens.Black, 
                                     New Rectangle(100, 260, 620, 20))
    
            e.Graphics.DrawString("Customer", fntString, 
                                      Brushes.White, 100, 260)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Driver's License #: ", fntString, 
                                      Brushes.Black, 100, 300)
            e.Graphics.DrawString("Name: ", fntString, 
                                     Brushes.Black, 420, 300)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
            e.Graphics.DrawString(cbxCustomerID.Text, fntString, 
                                      Brushes.Black, 260, 300)
            e.Graphics.DrawString(txtCustomerName.Text, fntString, 
                                      Brushes.Black, 540, 300)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 100, 320, 720, 320)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Address: ", fntString, 
                                      Brushes.Black, 100, 330)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
            e.Graphics.DrawString(txtCustomerAddress.Text, fntString, 
                                      Brushes.Black, 260, 330)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 100, 350, 720, 350)
    
            strDisplay = txtCustomerCity.Text & " " & 
                                 cbxCustomerStates.Text & " " & 
                txtCustomerZIPCode.Text
            fntString = New System.Drawing.Font("Times New Roman", 
                                                12, FontStyle.Regular)
            e.Graphics.DrawString(strDisplay, fntString, 
                                      Brushes.Black, 260, 360)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 260, 380, 720, 380)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
    
            e.Graphics.FillRectangle(Brushes.Gray, 
                                     New Rectangle(100, 410, 620, 20))
            e.Graphics.DrawRectangle(Pens.Black, 
                                     New Rectangle(100, 410, 620, 20))
    
            e.Graphics.DrawString("Car Information", fntString, 
                                      Brushes.White, 100, 410)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Tag #: ", fntString, 
                                      Brushes.Black, 100, 450)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
            e.Graphics.DrawString(cbxCarID.Text, fntString, 
                                      Brushes.Black, 260, 450)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 100, 470, 380, 470)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Year: ", fntString, 
                                      Brushes.Black, 420, 450)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
            e.Graphics.DrawString(txtCarYear.Text, fntString, 
                                      Brushes.Black, 530, 450)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 420, 470, 720, 470)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Make: ", fntString, 
                                      Brushes.Black, 100, 480)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
            e.Graphics.DrawString(txtMake.Text, fntString, 
                                      Brushes.Black, 260, 480)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 100, 500, 380, 500)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Model: ", fntString, 
                                      Brushes.Black, 420, 480)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
            e.Graphics.DrawString(txtModel.Text, fntString, 
                                      Brushes.Black, 530, 480)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 420, 500, 720, 500)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Car Condition: ", fntString, 
                                      Brushes.Black, 100, 510)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
            e.Graphics.DrawString(cbxCarConditions.Text, fntString, 
                                      Brushes.Black, 260, 510)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 100, 530, 380, 530)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Tank Level: ", fntString, 
                                      Brushes.Black, 420, 510)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
            e.Graphics.DrawString(cbxTankLevels.Text, fntString, 
                                      Brushes.Black, 530, 510)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 420, 530, 720, 530)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Mileage Start:", fntString, 
                                      Brushes.Black, 100, 540)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
            e.Graphics.DrawString(txtMileageStart.Text, fntString, 
                                      Brushes.Black, 260, 540)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 
                                100, 560, 380, 560)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Mileage }:", fntString, 
                              Brushes.Black, 420, 540)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
            e.Graphics.DrawString(txtMileageEnd.Text, fntString, 
                              Brushes.Black, 530, 540)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 
                                420, 560, 720, 560)
    
            e.Graphics.FillRectangle(Brushes.Gray, 
                                     New Rectangle(100, 590, 620, 20))
            e.Graphics.DrawRectangle(Pens.Black, 
                                     New Rectangle(100, 590, 620, 20))
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Order Timing Information", fntString, 
                              Brushes.White, 100, 590)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Start Date:", fntString, 
                               Brushes.Black, 100, 620)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
            e.Graphics.DrawString(dtpStartDate.Value.ToString("D"), 
                                  fntString, Brushes.Black, 260, 620)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 
                                100, 640, 720, 640)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("End Date:", fntString, 
                              Brushes.Black, 100, 650)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
            e.Graphics.DrawString(dtpEndDate.Value.ToString("D"), fntString, 
                              Brushes.Black, 260, 650)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 
                                100, 670, 520, 670)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Days:", fntString, 
                              Brushes.Black, 550, 650)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
            e.Graphics.DrawString(txtDays.Text, fntString, 
                                      Brushes.Black, 640, 650)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 
                                550, 670, 720, 670)
    
            e.Graphics.FillRectangle(Brushes.Gray, 
                                     New Rectangle(100, 700, 620, 20))
            e.Graphics.DrawRectangle(Pens.Black, 
                                     New Rectangle(100, 700, 620, 20))
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Order Evaluation", fntString, 
                              Brushes.White, 100, 700)
    
            Dim fmtString As StringFormat = New StringFormat
            fmtString.Alignment = StringAlignment.Far
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Rate Applied:", fntString, 
                              Brushes.Black, 100, 740)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
            e.Graphics.DrawString(txtRateApplied.Text, fntString, 
                              Brushes.Black, 300, 740, fmtString)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 
                                100, 760, 380, 760)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Tax Rate:", fntString, 
                              Brushes.Black, 420, 740)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
            e.Graphics.DrawString(txtTaxRate.Text, fntString, 
                              Brushes.Black, 640, 740, fmtString)
            e.Graphics.DrawString("%", fntString, 
                              Brushes.Black, 640, 740)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 
                                420, 760, 720, 760)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Sub-Total:", fntString, 
                              Brushes.Black, 100, 770)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
            e.Graphics.DrawString(txtSubTotal.Text, fntString, 
                              Brushes.Black, 300, 770, fmtString)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 
                                100, 790, 380, 790)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Tax Amount:", fntString, 
                                      Brushes.Black, 420, 770)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
            e.Graphics.DrawString(txtTaxAmount.Text, fntString, 
                              Brushes.Black, 640, 770, fmtString)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 
                                420, 790, 720, 790)
    
            fntString = New Font("Times New Roman", 12, FontStyle.Bold)
            e.Graphics.DrawString("Order Total:", fntString, 
                                      Brushes.Black, 420, 800)
            fntString = New Font("Times New Roman", 12, FontStyle.Regular)
            e.Graphics.DrawString(txtOrderTotal.Text, fntString, 
                              Brushes.Black, 640, 800, fmtString)
            e.Graphics.DrawLine(New Pen(Color.Black, 1), 
                                420, 820, 720, 820)
    End Sub
  19. Return to the Order Processing form
  20. From the Printing section of the Toolbox, click PrintDialog and click the form
  21. In the Properties window, change its Name to dlgPrint
  22. Still in the Properties windows, set its Document property to docPrint
  23. Right-click the Order Processing form and click View Code
  24. In the Class Name combo box, select btnPrint
  25. In the Method name combo box, select Click and implement the event as follows:
    Private Sub btnPrintClick(ByVal sender As Object, 
                                   ByVal e As System.EventArgs) 
                                   Handles btnPrint.Click
        If dlgPrint.ShowDialog() = DialogResult.OK Then
            docPrint.Print()
        End If
    End Sub
  26. Return to the Order Processing form
  27. From the Printing section of the Toolbox, click PrintPreviewDialog and click the form
  28. In the Properties window, change its (Name) to dlgPrintPreview
  29. Still in the Properties windows, set its Document property to docPrint
  30. Right-click the Order Processing form and click View Code
  31. In the Class name combo box, select btnPrintPreview
  32. In the Method name combo box, select Click and implement the event as follows:
    Private Sub btnPrintPreviewClick(ByVal sender As Object, 
                                          ByVal e As System.EventArgs) 
                                          Handles btnPrintPreview.Click
        dlgPrintPreview.ShowDialog()
    End Sub
  33. In the Class name combo box, select btnNewRentalOrder
  34. In the Method Name combo box, select Click and implement the event as follows:
    Private Sub btnNewRentalOrderClick(ByVal sender As Object, 
                                            ByVal e As System.EventArgs) 
                                            Handles btnNewRentalOrder.Click
            cbxEmployeeID.SelectedIndex = -1
            txtEmployeeName.Text = ""
            cbxCustomerID.SelectedIndex = -1
            txtCustomerName.Text = ""
            txtCustomerAddress.Text = ""
            txtCustomerCity.Text = ""
            cbxCustomerStates.Text = "DC"
            txtCustomerZIPCode.Text = ""
            cbxCarID.SelectedIndex = -1
            cbxCarConditions.SelectedIndex = 2
            txtMake.Text = ""
            txtModel.Text = ""
            txtCarYear.Text = ""
            cbxTankLevels.SelectedIndex = 0
            txtMileageStart.Text = "0"
            txtMileageEnd.Text = "0"
            dtpDateProcessed.Value = DateTime.Today
            dtpStartDate.Value = DateTime.Today
            dtpEndDate.Value = DateTime.Today
            txtDays.Text = "1"
            txtRateApplied.Text = "0.00"
            txtSubTotal.Text = "0.00"
            txtTaxAmount.Text = "0.00"
            txtOrderTotal.Text = "0.00"
            cbxOrderStatus.SelectedIndex = 0
    End Sub
  35. In the Solution Explorer, right-click Form1.vb and click Rename
  36. Type Central.vb and press Enter
  37. Design the form as follows:
     
    Bethesda Car Rental
    Control Text Name
    Button Order Processing... btnOrderProcessing
    Button Customers... btnCustomers
    Button Car Editor... btnCarEditor
    Button Employees btnEmployees
    Button Close btnClose
  38. Right-click the form and click View Code
  39. Above the Public Class Central line, import the System.IO namespace
     
    Imports System.IO
    
    Public Class Central
    
    End Class
  40. In the Class Name combo box, select (Central Events)
  41. In the Method Name combo box, select Load and implement the event as follows:
     
    Imports System.IO
    
    Public Class Central
    
        Private Sub CentralLoad(ByVal sender As Object, 
                                 ByVal e As System.EventArgs) 
                                 Handles Me.Load
            ' If this directory doesn't exist, create it
            Directory.CreateDirectory("C:\Bethesda Car Rental1")
        End Sub
    End Class
  42. In the Class Name combo box, select btnOrderProcessing
  43. In the Method Name combo box, select Click and implement the event as follows:
     
    Private Sub btnOrderProcessingClick(ByVal sender As Object, 
                                             ByVal e As System.EventArgs) 
                                             Handles btnOrderProcessing.Click
        Dim Order As OrderProcessing = New OrderProcessing
        Order.ShowDialog()
    End Sub
  44. To add a new form to the project, in the Solution Explorer, right-click BethesdaCarRental2 -> Add -> Windows Form...
  45. Set the Name to RentalRates and press Enter
  46. Add a ListView to the form and create its Columns as follows:
     
    (Name) Text TextAlign Width
    colCategory Category   90
    colDaily Daily Right  
    colWeekly Weekly Right  
    colMonthly Monthly Right  
    colWeek} Week} Right  
  47. Create its Items as follows:
     
    ListViewItem SubItems SubItems SubItems SubItems
      Text Text Text Text
    Economy 35.95 32.75 28.95 24.95
    Compact 39.95 35.75 32.95 28.95
    Standard 45.95 39.75 35.95 32.95
    Full Size 49.95 42.75 38.95 35.95
    Mini Van 55.95 50.75 45.95 42.95
    SUV 55.95 50.75 45.95 42.95
    Truck 42.75 38.75 35.95 32.95
    Van 69.95 62.75 55.95 52.95
  48. Complete the design of the form as follows:
     
    Rental Rates
  49. In the Solution Explorer, right-click OrderProcessing.vb and click View Code
  50. In the Class Name combo box, select btn Rental Rates
  51. In the Method Name combo box, select Click and implement its event as follows:
     
    Private Sub btnRentalRatesClick(ByVal sender As Object, 
                                         ByVal e As System.EventArgs) 
                                         Handles btnRentalRates.Click
        Dim WindowRates As RentalRates = New RentalRates
        WindowRates.Show()
    End Sub
  52. To add a new form to the application, in the Solution Explorer, right-click BethesdaCarRental2 -> Add -> Windows Form...
  53. Set the Name to Employees and click Add
  54. From the Data section of the Toolbox, click DataSet and click the form
  55. Click Untyped Dataset and click OK
  56. In the Properties window, change the following characteristics:
    DataSetName: Employees
    (Name): dsEmployees
  57. Click Tables and click its button
  58. Click Add and change the following characteristics:
    TableName: Employee
    (Name) tblEmployee
  59. Click Columns and click its button
  60. In the Columns Collection Editor, click Add change the characteristics as follows:
    ColumnName: EmployeeID
    (Name): colEmployeeID

Practical LearningPractical Learning: Introducing Data Relationships

  1. While the EmployeeID member is selected, in the Properties list, double-click AutoIncrement to set its value to True
  2. Click AutoIncrementSeed and type 1
  3. Click Add continuously and create the following columns:
     
    AllowDBNull ColumnName (Name) Expression
    False EmployeeNumber colEmployeeNumber  
      FirstName colFirstName  
    False LastName colLastName  
      FullName colFullName LastName + ', ' + FirstName
      Title colTitle  
  4. Click Close and click Close
  5. Design the form as follows:
     
    Bethesda Car Rental
     
    Control Text Name Other Properties
    DataGridView   dgvEmployees DataSource: dsEmployees
    DataMember: Employee
    Button Close btnClose  
    Data Grid Columns
     
    DataPropertyName HeaderText Width
    EmployeeID Empl ID 50
    EmployeeNumber Empl # 65
    FirstName First Name 70
    LastName Last Name 70
    FullName Full Name 120
    Title   110
  6. Right-click the form and click View Code
  7. Above the Public Class Employees line, import the System.IO namespace
     
    Imports System.IO
    
    Public Class Employees
    
    End Class
  8. In the Class Name combo box, select (Employees Events)
  9. In the Method Name combo box, select Load and implement the event as follows:
     
    Imports System.IO
    
    Public Class Employees
    
        Private Sub EmployeesLoad(ByVal sender As Object, 
                                   ByVal e As System.EventArgs) 
                                   Handles Me.Load
            Dim Filename As String = "C:\Bethesda Car Rental1\employees.xml"
    
            If File.Exists(Filename) Then
                dsEmployees.ReadXml(Filename)
            End If
        End Sub
    End Class
  10. In the Class Name combo box, select (Employees Events)
  11. In the Method name combo box, select FormClosing and implement the event as follows:
     
    Private Sub EmployeesFormClosing(ByVal sender As Object, 
                     ByVal e As System.Windows.Forms.FormClosingEventArgs) 
                                          Handles Me.FormClosing
        dsEmployees.WriteXml("C:\Bethesda Car Rental1\employees.xml")
    End Sub
  12. In the Class Name combo box, select btnClose
  13. In the Method Name combo box, select Click and implement the event as follows:
     
    Private Sub btnCloseClick(ByVal sender As Object, 
                               ByVal e As System.EventArgs) 
                               Handles btnClose.Click
        Close()
    End Sub
  14. In the Solution Explorer, right-click Central.vb and click View Code
  15. In the Class Name combo box, select btnEmployees
  16. In the Method Name combo box, select Click and implement the event as follows:
     
    Private Sub btnEmployeesClick(ByVal sender As Object, 
                                   ByVal e As System.EventArgs) 
                                   Handles btnEmployees.Click
        Dim frmEmployees As Employees = New Employees
        frmEmployees.ShowDialog()
    End Sub
  17. Execute the application
  18. On the Central form, click the Employees button
  19. Create a few employees as follows:
     
    Employee # First Name Last Name Title
    62-845 Patricia Katts General Manager
    92-303 Henry Larson Sales Representative
    25-947 Gertrude Monay Sales Representative
    73-947 Helene Sandt Intern
    40-508 Melanie Karron Sales Representative
    22-580 Ernest Chisen Sales Manager
    20-308 Melissa Roberts Administrative Assistant
  20. Close the forms and return to your programming environment
  21. To add a new form to the application, in the Solution Explorer, right-click BethesdaCarRental2 -> Add -> Windows Form...
  22. Set the Name to Customers and click Add
  23. From the Data section of the Toolbox, click DataSet and click the form
  24. Click Untyped Dataset and click OK
  25. In the Properties window, change the following characteristics:
    DataSetName: Customers
    (Name): dsCustomers
  26. Click Tables and click its button
  27. Click Add and change the following characteristics:
    TableName: Customer
    (Name) tblCustomer
  28. Click Columns and click its button
  29. In the Columns Collection Editor, click Add continuously and create the following columns:
     
    ColumnName (Name) Additional Properties
    CustomerID colCustomerID AutoIncrement: True
    AutoIncrementSeed: 1
    DrvLicNumber colDrvLicNumber AllowDBNull: False
    Unique: True
    FullName colFullName AllowDBNull: False
    Address colAddress  
    City colCity  
    State colState  
    ZIPCode colZIPCode  
  30. Click Close and click Close
  31. Design the form as follows:
     
    Bethesda Car Rental: Customers
     
    Control Text Name Other Properties
    DataGridView   dgvCustomers DataSource: dsCustomers
    DataMember: Customer
    Button Close btnClose  
    Data Grid Columns
    DataPropertyName HeaderText Width
    CustomerID Cust ID 50
    DrvLicNumber Drv Lic # 80
    FullName Full Name  
    Address    
    City   80
    State   45
    ZIPCode ZIP Code 60
  32. Right-click the form and click View Code
  33. Above the Public Class Customers line, import the System.IO namespace
     
    Imports System.IO
    
    Public Class Customers
    
    End Class
  34. In the Class Name combo box, select (Customers Events)
  35. In the Method Name combo box, select Load and implement the event as follows:
     
    Imports System.IO
    
    Public Class Customers
    
        Private Sub CustomersLoad(ByVal sender As Object, 
                                   ByVal e As System.EventArgs) 
                                   Handles Me.Load
            Dim Filename As String = "C:\Bethesda Car Rental1\customers.xml"
    
            If File.Exists(Filename) Then
                dsCustomers.ReadXml(Filename)
            End If
        End Sub
    End Class
  36. In the Method Name combo box, select FormClosing and implement the event as follows:
     
    Private Sub CustomersFormClosing(ByVal sender As Object, 
                     ByVal e As System.Windows.Forms.FormClosingEventArgs) 
                                      Handles Me.FormClosing
        dsCustomers.WriteXml("C:\Bethesda Car Rental1\customers.xml")
    End Sub
  37. In the Class name combo box, select btnClose
  38. In the Method Name combo box, select Click and implement the event as follows:
     
    Private Sub btnCloseClick(ByVal sender As Object, 
                                   ByVal e As System.EventArgs) 
                                   Handles btnClose.Click
        Close()
    End Sub
  39. In the Solution Explorer, right-click Central.vb and click View Code
  40. In the Class name combo box, select btnCustomers 
  41. In the Method Name combo box, select Click and implement the event as follows:
     
    Private Sub btnCustomersClick(ByVal sender As Object, 
                                   ByVal e As System.EventArgs) 
                                   Handles btnCustomers.Click
        Dim frmCustomers As Customers = New Customers
        frmCustomers.ShowDialog()
    End Sub
  42. Execute the application
  43. Click the Customers button and create a few customers as follows:
     
    Driver's Lic. # State Full Name Address City ZIP Code
    M-505-862-575 MD Lynda Melman 4277 Jamison Avenue Silver Spring 20904
    379-82-7397 DC John Villard 108 Hacken Rd NE Washington 20012
    J-938-928-274 MD Chris Young 8522 Aulage Street Rockville 20852
    497-22-0614 PA Pamela Ulmreck 12075 Famina Rd Blain 17006
    922-71-8395 VA Helene Kapsco 806 Hyena Drive Alexandria 22231
    C-374-830-422 MD Hermine Crasson 6255 Old Georgia Ave Silver Spring 20910
    836-55-2279 NY Alan Pastore 4228 Talion Street Amherst 14228
    397-59-7487 TN Phillis Buster 724 Cranston Circle Knoxville 37919
    115-80-2957 FL Elmus Krazucki 808 Rasters Ave Orlando 32810
    294-90-7744 VA Helena Weniack 10448 Great Pollard Hwy Arlington 22232
  44. Close the Customers form
  45. To add a new form to the application, in the Solution Explorer, right-click BethesdaCarRental2 -> Add -> Windows Form...
  46. Set the Name to CarEditor and click Add
  47. Design the form as follows: 
     
    Bethesda Car Rental - Car Editor
    Control Text Name Other Properties
    Label Text #    
    TextBox   txtTagNumber  
    Label Make:    
    TextBox   txtMake  
    Label Model:    
    TextBox   txtModel  
    Label Year:    
    TextBox   txtYear  
    Label Category:    
    ComboBox   cboCategories DropDownStyle: DropDownList
    Items: Economy
    Compact
    Standard
    Full Size
    Mini Van
    SUV
    Truck
    Van
    PictureBox   pbxCar SizeMode: Zoom
    CheckBox CD Player chkCDPlayer CheckAlign: MiddleRight
    CheckBox DVD Player chkDVDPlayer CheckAlign: MiddleRight
    Button Select Car Picture... btnSelectPicture  
    CheckBox Available chkAvailable CheckAlign: MiddleRight
    Label Picture Name lblPictureName  
    Button Submit btnSubmit  
    Button Close btnClose DialogResult: Cancel
    OpenFileDialog (Name): dlgOpen
    Title: Select Item Picture
    DefaultExt: jpg
    Filter: JPEG Files (*.jpg,*.jpeg)|*.jpg|GIF Files (*.gif)|*.gif|Bitmap Files (*.bmp)|*.bmp|PNG Files (*.png)|*.png
    Form     FormBorderStyle: FixedDialog
    MaximizeBox: False
    MinimizeBox: False
    ShowInTaskbar: False
  48. Right-click the form and click View Code
  49. Above the Public Class CarEditor line, import the System.IO namespace
     
    Imports System.IO
    
    Public Class CarEditor
    
    End Class
  50. In the Class Name combo box, select btnSelectPicture
  51. In the Method Name combo box, select Click and implement the event as follows:
     
    Imports System.IO
    
    Public Class CarEditor
    
        Private Sub btnSelectPictureClick(ByVal sender As Object, 
                                           ByVal e As System.EventArgs) 
                                           Handles btnSelectPicture.Click
            If dlgPicture.ShowDialog() = DialogResult.OK Then
                lblPictureName.Text = dlgPicture.FileName
                pbxCar.Image = Image.FromFile(lblPictureName.Text)
            End If
        End Sub
    End Class
  52. Return to the Car Editor form
  53. From the Data section of the Toolbox, click DataSet and click the form
  54. Click Untyped Dataset and click OK
  55. In the Properties window, change the following characteristics:
    DataSetName: Cars
    (Name): dsCars
  56. Click Tables and click its button
  57. Click Add and change the following characteristics:
    TableName: Car
    (Name) tblCar
  58. Click Columns and click its button
  59. In the Columns Collection Editor, click Add continuously and create the following columns:
     
    ColumnName (Name) Additional Properties
    CarID colCarID AutoIncrement: True
    AutoIncrementSeed: 1
    TagNumber colTagNumber AllowDBNull: False
    Unique: True
    Make colMake  
    Model colModel  
    Year colYear DataType: System.UInt16
    Category colCategory  
    CDPlayer colCDPlayer DataType: System.Boolean
    DVDPlayer colDVDPlayer DataType: System.Boolean
    Available colAvailable DataType: System.Boolean
  60. Click Close and click Close
  61. Right-click the form and click View Code
  62. In the Class name com box, select btnSubmit
  63. In the Method Name combo box, select Click and implement the event as follows:
     
    Private Sub btnSubmitClick(ByVal sender As Object, 
                                    ByVal e As System.EventArgs) 
                                    Handles btnSubmit.Click
            If txtTagNumber.Text.Length = 0 Then
                MsgBox("You must enter the car's tag number")
                Exit Sub
            End If
    
            If txtMake.Text.Length = 0 Then
                MsgBox("You must specify the car's manufacturer")
                Exit Sub
            End If
    
            If txtModel.Text.Length = 0 Then
                MsgBox("You must enter the model of the car")
                Exit Sub
            End If
    
            If txtYear.Text.Length = 0 Then
                MsgBox("You must enter the year of the car")
                Exit Sub
            End If
    
            Dim CarRecord As DataRow = tblCar.NewRow()
    
            CarRecord("TagNumber") = txtTagNumber.Text
            CarRecord("Make") = txtMake.Text
            CarRecord("Model") = txtModel.Text
            CarRecord("CarYear") = txtYear.Text
            CarRecord("Category") = cbxCategories.Text
            CarRecord("CDPlayer") = chkCDPlayer.Checked
            CarRecord("DVDPlayer") = chkDVDPlayer.Checked
            CarRecord("Available") = chkAvailable.Checked
            tblCar.Rows.Add(CarRecord)
    
            dsCars.WriteXml("C:\Bethesda Car Rental1\cars.xml")
    
            If lblPictureName.Text.Length <> 0 Then
                Dim flePicture As FileInfo = New FileInfo(lblPictureName.Text)
                flePicture.CopyTo("C:\Bethesda Car Rental1\" & 
                                  txtTagNumber.Text & flePicture.Extension)
            End If
    
            txtTagNumber.Text = ""
            txtMake.Text = ""
            txtModel.Text = ""
            txtYear.Text = ""
            cbxCategories.Text = "Economy"
            chkCDPlayer.Checked = False
            chkDVDPlayer.Checked = False
            chkAvailable.Checked = False
            lblPictureName.Text = "."
            pbxCar.Image = Nothing
    End Sub
  64. In the Class name combo box, select btnClose
  65. In the Method name combo box, select Click and implement the event as follows:
     
    Private Sub btnCloseClick(ByVal sender As Object, 
                               ByVal e As System.EventArgs) 
                               Handles btnClose.Click
        Close()
    End Sub
  66. In the Solution Explorer, right-click Central.vb and click View Code
  67. In the Class name combo box, select btn Car Editor
  68. In the Method name combo box, select Click and implement the as follows:
     
    Private Sub btnCarEditorClick(ByVal sender As Object, 
                                   ByVal e As System.EventArgs) 
                                   Handles btnCarEditor.Click
        Dim Editor As CarEditor = New CarEditor
        Editor.ShowDialog()
    End Sub
  69. Copy the following pictures to any folder somewhere on your computer:
     
    BMW 335i Chevrolet Avalanche
    BMW: 335i Chevrolet Avalanche
    Mazda Miata
    Honda Accord Mazda Miata
    Chevrolet Aveo Ford E150XL
    Chevrolet Aveo Ford E150XL
    Buick LaCrosse Honda Civic
    Buick Lacrosse Honda Civic
    Ford F-150 Mazda Mazda5
    Ford F-150 Mazda Mazda5
    Volvo S40 Land Rover LR3
    Volvo S40 Land Rover LR3
  70. Execute the application
  71. Click the Car Editor button and create the cars
     
    Bethesda Car Rental - Car Editor
  72. Close the Car Editor form and return to your programming environment
  73. In the Solution Explorer, double-click OrderProcessing.vb
  74. From the Data section of the Toolbox, click DataSet and click the form
  75. Click Untyped Dataset and click OK
  76. In the Properties window, change the following characteristics:
    DataSetName: RentalOrders
    (Name): dsRentalOrders
  77. Click Tables and click its button
  78. Click Add and change the following characteristics:
    TableName: RentalOrder
    (Name) tblRentalOrder
  79. Click Columns and click its ellipsis button
  80. In the Columns Collection Editor, click Add twice and create the following columns:
     
    ColumnName (Name) Additional Properties
    RentalOrderID colRentalOrderID AutoIncrement: True
    AutoIncrementSeed: 1000
    DateProcessed colDateProcessed DataType: System.DateTime
  81. Click Close

Practical LearningPractical Learning: Creating a Primary Key

  1. While the RentalOrder table is still selected in the Members list, in the Properties list, click Constraints and click its button
  2. In the Constraints Collection Editor, click Add -> Unique Constraint
     
    Constraint
  3. Set the Name to PKRentalOrders
  4. Click the check box of RentalOrderID and click the Primary Key check box
     
    Constraint
  5. Click OK and click Close
  6. Click Columns and create the following columns:
     
    ColumnName (Name) Other Properties
    RentalOrderID colRentalOrderID  
    DateProcessed colDateProcessed  
    EmployeeID colEmplID DataType: System.Int32
    EmployeeName colEmployeeName  
    CustomerID colCustID DataType: System.Int32
    CustomerName colCustomerName  
    CustomerAddress colCustomerAddress  
    CustomerCity colCustomerCity  
    CustomerState colCustomerState  
    CustomerZIPCode colCustomerZIPCode  
    CarID colVehicleID DataType: System.Int32
    Make colCarMake  
    Model colCarModel  
    Year colCarYear DataType: System.UInt16
    Condition colCarCondition  
    TankLevel colTankLevel  
    MileageStart colMileageStart DataType: System.UInt32
    Mileage} colMileage} DataType: System.UInt32
    RentStartDate colRentStartDate DataType: System.DateTime
    RendependDate colRendependDate DataType: System.DateTime
    Days colDays DataType: System.UInt16
    RateApplied colRateApplied DataType: System.Double
    SubTotal colSubTotal DataType: System.Double
    TaxRate colTaxRate DataType: System.Double
    TaxAmount colTaxAmount DataType: System.Double
    OrderTotal colOrderTotal DataType: System.Double
    OrderStatus colOrderStatus  
  7. Click Close
  8. While the RentalOrder table is selected, in the RentalOder Properties list, click PrimaryKey and click the arrow of its combo box.
    Notice the check box on RentalOrderID
     
  9. In the Tables Collection Editor, click Add and change the following characteristics:
    TableName: Car
    (Name) tblCar
  10. Click Columns and click its button
  11. In the Columns Collection Editor, click Add continuously and create the following columns:
     
    ColumnName (Name) Additional Properties
    CarID colCarID AutoIncrement: True
    AutoIncrementSeed: 1
    TagNumber colTagNumber AllowDBNull: False
    Unique: True
    Make colMake  
    Model colModel  
    Year colYear DataType: System.UInt16
    Category colCategory  
    CDPlayer colCDPlayer DataType: System.Boolean
    DVDPlayer colDVDPlayer DataType: System.Boolean
    Available colAvailable DataType: System.Boolean
  12. Click Close
  13. While the Car table is selected, in the Properties list, click Constraints and its button
  14. In the Constraints Collection Editor, if Constraint1 is selected, click Edit (otherwise, click Add -> Unique Constraint)
  15. Set the Name to PKCars
  16. Click the check box of CarID and click the Primary Key check box:
     
    Constraint
  17. Click OK and click Close
  18. In the Tables Collection Editor, click Add and change the following characteristics:
    TableName: Customer
    (Name) tblCustomer
  19. Click Columns and click its button
  20. In the Columns Collection Editor, click Add continuously and create the following columns:
     
    ColumnName (Name) Additional Properties
    CustomerID colCustomerID AutoIncrement: True
    AutoIncrementSeed: 1
    DrvLicNumber colDrvLicNumber AllowDBNull: False
    Unique: True
    FullName colFullName AllowDBNull: False
    Address colAddress  
    City colCity  
    State colState  
    ZIPCode colZIPCode  
  21. Click Close
  22. Click Constraints and click its button
  23. In the Constraints Collection Editor, if Constraint1 is selected, click Edit (otherwise, click Add -> Unique Constraint)
  24. Set the Name to PKCustomers
  25. Click the check box of CustomerID and click the Primary Key check box (clear any other check box)
  26. Click OK and click Close
  27. In the Tables Collection Editor, click Add and change the following characteristics:
    TableName: Employee
    (Name) tblEmployee
  28. Click Columns and click its button
  29. In the Columns Collection Editor, click Add continuously and create the following columns:
     
    ColumnName (Name) Additional Properties
    EmployeeID colEmployeeID AutoIncrement: True
    AutoIncrementSeed: 1
    EmployeeNumber colEmployeeNumber AllowDBNull: False
    Unique: True
    FirstName colFirstName AllowDBNull: False
    LastName colLastName  
    FullName colEmplFullName  
    Title colTitle  
  30. Click Close
  31. Click Constraints and click its button
  32. In the Constraints Collection Editor, if Constraint1 is selected, click Edit (otherwise, click Add -> Unique Constraint)
  33. Set the Name to PKEmployees
  34. Click the check box of EmployeeID and click the Primary Key check box (clear any other check box)
  35. Click OK and click Close
  36. Right-click the form and click View Code

Practical LearningPractical Learning: Using the Relationships

  1. In the Class Name combo box, select (OrderProcessing Events)
  2. In the Method Name combo box, select Load event and implement the event as follows:
     
    Private Sub OrderProcessingLoad(ByVal sender As Object, 
                                     ByVal e As System.EventArgs) 
                                     Handles Me.Load
            Dim Filename As String = "C:\Bethesda Car Rental\employees.xml"
    
            If File.Exists(Filename) Then
                dsRentalOrders.ReadXml(Filename)
            End If
    
            Filename = "C:\Bethesda Car Rental\customers.xml"
    
            If File.Exists(Filename) Then
                dsRentalOrders.ReadXml(Filename)
            End If
    
            Filename = "C:\Bethesda Car Rental\cars.xml"
    
            If File.Exists(Filename) Then
                dsRentalOrders.ReadXml(Filename)
            End If
    End Sub
  3. Return to the Order Processing form and click the Employee # combo box
  4. In the Properties window, change the following characteristics:
    DataSource: dsRentalOrders
    DisplayMember: Employee.EmployeeNumber
  5. Right-click the form and click View Code
  6. In the Class Name combo box, select cbxEmployeeID
  7. In the Method Name combo box, select SelectedIndexChanged and implement the event as follows:
     
    Private Sub cbxEmployeeIDSelectedIndexChanged(ByVal sender As Object, 
                                                   ByVal e As System.EventArgs) 
                                       Handles cbxCustomerID.SelectedIndexChanged
        For Each Record As DataRow In tblEmployee.Rows
            If cbxEmployeeID.Text = Record("EmployeeNumber") Then
                txtEmployeeName.Text = Record("FullName")
            End If
        Next
    End Sub
  8. Return to the form and click the Driver's Lic # combo box
  9. In the Properties window, change the following characteristics:
    DataSource: dsRentalOrders
    DisplayMember: Customer.DrvLicNumber
  10. Right-click the form and click View Code
  11. In the Class Name combo box, select cbxCustomerID
  12. In the Method Name combo box, select SelectedIndexChanged and implement the event as follows:
      
    Private Sub cbxCustomerIDSelectedIndexChanged(ByVal sender As Object, 
                                                   ByVal e As System.EventArgs) 
                                       Handles cbxCustomerID.SelectedIndexChanged
            For Each Record As DataRow In tblCustomer.Rows
                If cbxCustomerID.Text = Record("DrvLicNumber") Then
                    txtCustomerName.Text = Record("FullName")
                    txtCustomerAddress.Text = Record("Address")
                    txtCustomerCity.Text = Record("City")
                    cbxCustomerStates.Text = Record("State")
                    txtCustomerZIPCode.Text = Record("ZIPCode")
                End If
            Next
    End Sub
  13. Return to the form and click the Tag Number combo box
  14. In the Properties window, change the following characteristics:
    DataSource: dsRentalOrders
    DisplayMember: Car.TagNumber
  15. Right-click the form and click View Code
  16. In the Class Name combo box, select cbxCarID
  17. In the Method Name combo box, select SelectedIndexChanged and implement the event as follows:
     
    Private Sub cbxCarIDSelectedIndexChanged(ByVal sender As Object, 
                                              ByVal e As System.EventArgs) 
                                       Handles cbxCarID.SelectedIndexChanged
        For Each Record As DataRow In tblCar.Rows
            If cbxCarID.Text = Record("TagNumber") Then
                txtMake.Text = Record("Make")
                txtModel.Text = Record("Model")
                txtCarYear.Text = Record("Year")
            End If
        Next
    End Sub
  18. Return to the OrderProcessing form
  19. From the Data section of the Toolbox, click DataSet and click the form
  20. Click Untyped Dataset and click OK
  21. In the Properties window, change the following characteristics:
    DataSetName: OrderProcessing
    (Name):dsOrderProcessing
  22. Click the ellipsis button of the Tables field
  23. In the Tables Collection Editor, click Add and change the characteristics as follows:
    TableName: RentalOrder
    (Name): tblRental
  24. Click the ellipsis button of the Columns field
  25. In the Columns Collection Editor, click Add continuously and create the following columns:
     
    ColumnName (Name) Other Properties
    ReceiptNumber colReceiptNumber AutoIncrement: True
    AutoIncrementSeed: 1001
    DateProcessed colProcessedDate  
    OrderStatus colStatus  
    EmployeeNumber colEmplNumber  
    EmployeeName colEmplName  
    CustomerDrvLicNbr colDrvLicNbr  
    CustomerName colCustName  
    CustomerAddress colCustAddress  
    CustomerCity colCustCity  
    CustomerState colCustState  
    CustomerZIPCode colCustZIPCode  
    CarTagNumber colCarTagNumber  
    CarMake colMake  
    CarModel colVehicleModel  
    CarYear colVehicleYear  
    CarCondition colCondition  
    CarTankLevel colCarTankLevel  
    MileageStart colCarMileageStart  
    MileageEnd colCarMileageEnd  
    RentStartDate colStartDate  
    RendependDate colEndDate  
    TotalDays colTotalDays  
    RateApplied colAppliedRate  
    SubTotal colTotalSub  
    TaxRate colRateTax  
    TaxAmount colAmountTax  
    OrderTotal colTotalOrder  
  26. Click Close and click Close
  27. Right-click t he form and click View Code
  28. In the Class Name combo box, select btnSave
  29. In the Method Name combo box, select Click and implement the event as follows:
     
    Private Sub btnSaveClick(ByVal sender As Object, 
                                  ByVal e As System.EventArgs) 
                                  Handles btnSave.Click
            ' Don't save this rental order if we don't
            ' know who processed it
            If cbxEmployeeID.SelectedIndex < 0 Then
                MsgBox("You must select the employee number or " & 
                                "the clerk who processed this order.")
                Exit Sub
            End If
    
            ' Don't save this rental order if we don't
            ' know who is renting the car
            If cbxCustomerID.SelectedIndex < 0 Then
                MsgBox("You must select the driver's license number " & 
                                "of the customer who is renting the car")
                Exit Sub
            End If
    
            ' Don't save the rental order if we don't
            ' know what car is being rented
            If cbxCarID.SelectedIndex < 0 Then
                MsgBox("You must select the tag number " & 
                                "of the car that is being rented")
                Exit Sub
            End If
    
            ' This variable will allow us to know whether 
            ' we are only updating a rental order
            Dim Found As Boolean = False
            ' This is the XML file that holds the rental orders
            Dim Filename As String = "C:\Bethesda Car Rental1\RentalOrders.xml"
    
            ' This is the stream that holds the file
            Dim bcrStream As FileStream = New FileStream(Filename, 
                                                     FileMode.OpenOrCreate, 
                                                     FileAccess.ReadWrite, 
                                                     FileShare.ReadWrite)
    
            ' Check the rental orders
            For Each Record As DataRow In tblRental.Rows
                ' Find out if there is already a rental
                ' order with the current receipt number
                If Record("ReceiptNumber") = txtReceiptNumber.Text Then
                    ' Since the rental order was found, make note
                    Found = True
    
                    ' Get ready to update the rental order
                    Record("DateProcessed") = dtpDateProcessed.Value.ToString("d")
                    Record("EmployeeNumber") = cbxEmployeeID.Text
                    Record("EmployeeName") = txtEmployeeName.Text
                    Record("CustomerDrvLicNbr") = cbxCustomerID.Text
                    Record("CustomerName") = txtCustomerName.Text
                    Record("CustomerAddress") = txtCustomerAddress.Text
                    Record("CustomerCity") = txtCustomerCity.Text
                    Record("CustomerState") = cbxCustomerStates.Text
                    Record("CustomerZIPCode") = txtCustomerZIPCode.Text
                    Record("CarTagNumber") = cbxCarID.Text
                    Record("CarMake") = txtMake.Text
                    Record("CarModel") = txtModel.Text
                    Record("CarYear") = txtCarYear.Text
                    Record("CarCondition") = cbxCarConditions.Text
                    Record("CarTankLevel") = cbxTankLevels.Text
                    Record("MileageStart") = txtMileageStart.Text
                    Record("Mileage}") = txtMileageEnd.Text
                    Record("RentStartDate") = dtpStartDate.Value.ToString("d")
                    Record("RendependDate") = dtpEndDate.Value.ToString("d")
                    Record("TotalDays") = txtDays.Text
                    Record("RateApplied") = txtRateApplied.Text
                    Record("SubTotal") = txtSubTotal.Text
                    Record("TaxRate") = txtTaxRate.Text
                    Record("TaxAmount") = txtTaxAmount.Text
                    Record("OrderTotal") = txtOrderTotal.Text
                    Record("OrderStatus") = cbxOrderStatus.Text
                    ' STOP!!!
                    Exit For
                End If
            Next
    
            ' If the receipt number was not found,
            ' then prepare to create a new rental order
            If Found = False Then
                Dim Record As DataRow = tblRental.NewRow()
                Record("DateProcessed") = dtpDateProcessed.Value.ToString("d")
                Record("EmployeeNumber") = cbxEmployeeID.Text
                Record("EmployeeName") = txtEmployeeName.Text
                Record("CustomerDrvLicNbr") = cbxCustomerID.Text
                Record("CustomerName") = txtCustomerName.Text
                Record("CustomerAddress") = txtCustomerAddress.Text
                Record("CustomerCity") = txtCustomerCity.Text
                Record("CustomerState") = cbxCustomerStates.Text
                Record("CustomerZIPCode") = txtCustomerZIPCode.Text
                Record("CarTagNumber") = cbxCarID.Text
                Record("CarMake") = txtMake.Text
                Record("CarModel") = txtModel.Text
                Record("CarYear") = txtCarYear.Text
                Record("CarCondition") = cbxCarConditions.Text
                Record("CarTankLevel") = cbxTankLevels.Text
                Record("MileageStart") = txtMileageStart.Text
                Record("Mileage}") = txtMileageEnd.Text
                Record("RentStartDate") = dtpStartDate.Value.ToString("d")
                Record("RendependDate") = dtpEndDate.Value.ToString("d")
                Record("TotalDays") = txtDays.Text
                Record("RateApplied") = txtRateApplied.Text
                Record("SubTotal") = txtSubTotal.Text
                Record("TaxRate") = txtTaxRate.Text
                Record("TaxAmount") = txtTaxAmount.Text
                Record("OrderTotal") = txtOrderTotal.Text
                Record("OrderStatus") = cbxOrderStatus.Text
                tblRental.Rows.Add(Record)
            End If
    
            ' Now that the rental order is ready, ...
            Try
                ' ... save it
                dsOrderProcessing.WriteXml(bcrStream)
            Finally
                bcrStream.Close()
            End Try
    End Sub
  30. In the Class Name combo box, select btnOpen
  31. In the Method Name combo box, select Click and implement the event as follows:
     
    Private Sub btnOpenClick(ByVal sender As Object, 
                                  ByVal e As System.EventArgs) 
                                  Handles btnOpen.Click
        Dim Found As Boolean = False
    
        Try
            Dim Filename As String = "C:\Bethesda Car Rental1\RentalOrders.xml"
    
            If File.Exists(Filename) Then
                dsOrderProcessing.ReadXml(Filename)
    
                For Each Record As DataRow In tblRental.Rows
                    If Record("ReceiptNumber") = txtReceiptNumber.Text Then
                        Found = True
    
                      dtpDateProcessed.Value = DateTime.Parse(Record("DateProcessed"))
                        cbxEmployeeID.Text = Record("EmployeeNumber")
                        txtEmployeeName.Text = Record("EmployeeName")
                        cbxCustomerID.Text = Record("CustomerDrvLicNbr")
                        txtCustomerName.Text = Record("CustomerName")
                        txtCustomerAddress.Text = Record("CustomerAddress")
                        txtCustomerCity.Text = Record("CustomerCity")
                        cbxCustomerStates.Text = Record("CustomerState")
                        txtCustomerZIPCode.Text = Record("CustomerZIPCode")
                        cbxCarID.Text = Record("CarTagNumber")
                        txtMake.Text = Record("CarMake")
                        txtModel.Text = Record("CarModel")
                        txtCarYear.Text = Record("CarYear")
                        cbxCarConditions.Text = Record("CarCondition")
                        cbxTankLevels.Text = Record("CarTankLevel")
                        txtMileageStart.Text = Record("MileageStart")
                        txtMileageEnd.Text = Record("MileageEnd")
                        dtpStartDate.Value = DateTime.Parse(Record("RentStartDate"))
                        dtpEndDate.Value = DateTime.Parse(Record("RendependDate"))
                        txtDays.Text = Record("TotalDays")
                            txtRateApplied.Text = Record("RateApplied")
                            txtSubTotal.Text = Record("SubTotal")
                            txtTaxRate.Text = Record("TaxRate")
                            txtTaxAmount.Text = Record("TaxAmount")
                            txtOrderTotal.Text = Record("OrderTotal")
                            cbxOrderStatus.Text = Record("OrderStatus")
                            Exit For
                        End If
                    Next
                Else
                    MsgBox("There is no cleaning order to open")
                End If
            Catch Exc As ConstraintException
    
            End Try
    
            If Found = False Then
                MsgBox("There is no rental order with that receipt number")
            End If
    End Sub
  32. In the Class Name combo box, select btnClose
  33. In the Method Name combo box, select Click and implement the event as follows:
     
    Private Sub btnCloseClick(ByVal sender As Object, 
                               ByVal e As System.EventArgs) 
                               Handles btnClose.Click
        Close
    End Sub
  34. In the Solution Explorer, right-click Central.vb and click View Code
  35. In the Class Name combo box, select btnClose
  36. In the Method Name combo box, select Click and implement the event as follows:
     
    Private Sub btnCloseClick(ByVal sender As Object, 
                               ByVal e As System.EventArgs) 
                               Handles btnClose.Click
        End
    End Sub
  37. Execute the application
 

Home Copyright © 2008-2016, FunctionX, Inc.