Home

File-Based Applications:
Bethesda Car Rental

 

Customers

The essence of any business is to present or sell products to a customers. These are people or entities that buy what ever is on sale. In our application, we will create simple information about each customer. This information will be stored in a text file and be able to open it when needed. To make our assignment easy, we will use the same approach and steps we used for the employees.

 

Practical Learning Practical Learning: Creating Employees

  1. To add a new form to the application, on the main menu, click Project -> Add Windows Forms
  2. Set the Name to Customers and press Enter
  3. From the Toolbox, add a ListView to the form
  4. While the new list view is still selected, in the Properties window, click the ellipsis button of the Columns field and create the columns as follows:
     
    (Name) Text Width
    colDrvLicNbr Driver's Lic. # 100
    colFullName Full Name 100
    colAddress Address 160
    colCity City 100
    colState State 38
    colZIPCode ZIPCode  
    colCountry Country  
  5. Design the form as follows: 
     
     
    Control Text Name Other Properties
    ListView   lvwEmployees View: Details
    GridLines: True
    FullRowSelect: True
    Button New Customer btnNewCustomer  
    Button Close btnClose  
  6. To add another form to the application, on the main menu, click Project -> Add Windows Forms
  7. Set the Name to NewCustomer and press Enter
  8. Design the form as follows: 
     
     
    Control Text Name Properties
    Label Driver's Lic. #:    
    TextBox   txtDrvLicNbr Modifiers: Public
    Label Full Name:    
    TextBox   txtFullName Modifiers: Public
    Label Address:    
    TextBox   txtAddress Modifiers: Public
    Label City:    
    TextBox   txtCity Modifiers: Public
    Label State:    
    TextBox MD txtState Modifiers: Public
    Label ZIP Code:    
    TextBox   txtZIPCode Modifiers: Public
    Label Country:    
    TextBox USA txtCountry Modifiers: Public
    Button New Customer btnNewCustomer DialogResult: OK
    Button Close btnClose DialogResult: Cancel
    Form     AcceptButton: btnNewCustomer
    CancelButton: btnClose
    FormBorderStyle: FixedDialog
    MaximizeBox: False
    MinimizeBox: False
    ShowInTaskbar: False
  9. To add a new class to the project, on the main menu, click Project -> Add Class...
  10. Set the Class Name to Customer and click Finish
  11. Change the Customer.cs file as follows:
     
    <Serializable()> Public NotInheritable Class Customer
        Public DrvLicNbr As String
        Public FullName As String
        Public Address As String
        Public City As String
        Public State As String
        Public ZIPCode As String
        Public Country As String
    
        Public Sub New()
            DrvLicNbr = "A-000-000-000-000"
            FullName = "John Doe"
            Address = "123 Main Street"
            City = "Good City"
            State = "MD"
            ZIPCode = "20900"
            Country = "USA"
        End Sub
    
        Public Sub New(ByVal DrvLic As String, ByVal fName As String, _
                       ByVal adr As String, ByVal ct As String, _
                       ByVal ste As String, ByVal zip As String, _
    		   ByVal cty As String)
            DrvLicNbr = DrvLic
            FullName = fName
            Address = adr
            City = ct
            State = ste
            ZIPCode = zip
            Country = cty
        End Sub
    End Class
  12. Return to the Customers form. Right-click it and click View Code
  13. In the top section of the file, type:
     
    Imports System.IO
    Imports System.Runtime.Serialization.Formatters.Soap
    
    Public Class Customers
        Inherits System.Windows.Forms.Form
    
        Private lstCustomers As ArrayList
    
  14. Just before the End Class line, create a sub procedure as follows:
     
    Private Sub ShowCustomers()
            Dim bcrSoap As SoapFormatter = New SoapFormatter
            Dim strFilename As String = "Customers.bcr"
    
            If File.Exists(strFilename) Then
                Dim bcrStream As FileStream = New FileStream(strFilename, _
    				FileMode.Open, FileAccess.Read, FileShare.Read)
                Dim lstCust As ArrayList = bcrSoap.Deserialize(bcrStream)
                bcrStream.Close()
    
                Dim cust As Customer
    
                lvwCustomers.Items.Clear()
    
                For i As Integer = 0 To lstCust.Count - 1
                    cust = lstCust(i)
                    Dim lviCustomer As ListViewItem = New ListViewItem(cust.DrvLicNbr)
                    lviCustomer.Font = New Font("Georgia", 8, FontStyle.Bold)
    
                    If i Mod 2 = 0 Then
                        lviCustomer.BackColor = Color.Blue
                        lviCustomer.ForeColor = Color.White
                    Else
                        lviCustomer.BackColor = Color.LightBlue
                        lviCustomer.ForeColor = Color.Blue
                    End If
    
                    lviCustomer.SubItems.Add(cust.FullName)
                    lviCustomer.SubItems.Add(cust.Address)
                    lviCustomer.SubItems.Add(cust.City)
                    lviCustomer.SubItems.Add(cust.State)
                    lviCustomer.SubItems.Add(cust.ZIPCode)
                    lviCustomer.SubItems.Add(cust.Country)
                    lvwCustomers.Items.Add(lviCustomer)
                Next
            End If
    End Sub
  15. In the Class Name combo box, select (Customers Events)
  16. In the Method Name combo box, select Load and implement the event as follows:
     
    Private Sub Customers_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
    			Handles MyBase.Load
            lstCustomers = New ArrayList
            Dim bcrSoap As SoapFormatter = New SoapFormatter
            Dim strFilename As String = "Customers.bcr"
    
            If File.Exists(strFilename) Then
                Dim bcrStream As FileStream = New FileStream(strFilename, _
    				FileMode.Open, FileAccess.Read, FileShare.Read)
                lstCustomers = bcrSoap.Deserialize(bcrStream)
    
                bcrStream.Close()
            End If
    
            ShowCustomers()
    End Sub
  17. In the Class Name combo box, select btnNewCustomer
  18. In the Method Name combo box, select Click and implement the event as follows:
     
    Private Sub btnNewCustomer_Click(ByVal sender As Object, ByVal e As _
    				System.EventArgs) Handles btnNewCustomer.Click
            Dim dlgCust As NewCustomer = New NewCustomer
    
            If dlgCust.ShowDialog() = DialogResult.OK Then
                Dim strFilename As String = "Customers.bcr"
                Dim cust As Customer = New Customer
    
                cust.DrvLicNbr = dlgCust.txtDrvLicNbr.Text
                cust.FullName = dlgCust.txtFullName.Text
                cust.Address = dlgCust.txtAddress.Text
                cust.City = dlgCust.txtCity.Text
                cust.State = dlgCust.txtState.Text
                cust.ZIPCode = dlgCust.txtZIPCode.Text
                cust.Country = dlgCust.txtCountry.Text
    
                lstCustomers.Add(cust)
    
                Dim bcrStream As FileStream = New FileStream(strFilename, _
    		FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write)
                Dim bcrSoap As SoapFormatter = New SoapFormatter
                bcrSoap.Serialize(bcrStream, lstCustomers)
                bcrStream.Close()
    
                ShowCustomers()
            End If
    End Sub
  19. In the Class Name combo box, select btnClose
  20. In the Method Name combo box, select Click and implement the event as follows:
       
    Private Sub btnClose_Click(ByVal sender As Object, _
    		ByVal e As System.EventArgs) Handles btnClose.Click
            Close()
    End Sub
  21. Display the Switchboard form
  22. Add a Button to the form and change its properties as follows:
    (Name): btnCustomers
    Text: Customers
  23. Double-click the Employees button to generate its Click event
  24. Implement the event as follows:
     
    Private Sub btnCustomers_Click(ByVal sender As System.Object, _
    		ByVal e As System.EventArgs) Handles btnCustomers.Click
            Dim frmCust As Customers = New Customers
    
            frmCust.Show()
    End Sub
  25. Execute the application
  26. Create a few employees as follows:
     
    Driver's Lic. # Full Name Address City State ZIP Code
    M-505-862-575 Lynda Melman 4277 Jamison Ave Silver Spring   20904
    379-82-7397 John Villard 108 Hacken Rd NE Washington DC 20012
    J-938-928-274 Chris Youno 8522 Aulage Street Rockville   20852
    K-497-220-614 Pamela Ulmreck 12075 Famina Rd Hyattsville MD 20707
    922-71-8395 Helene Kapsco 806 Hyena Drive Alexandria VA 22231
    C-374-830-422 Hermine Crasson 6255 Old Georgia Ave Silver Spring   20910
    836-55-2279 Alan Pastore 4228 16th Street NW Washington DC 20004
    B-397-597-487 Phillis Buster 724 Cranston Circle College Park   20747
    K-115-802-957 Elmus Krazucki 808 Rasters Ave Chevy Chase MD 20854
    294-90-7744 Helena Weniack 10448 Great Pollard Hwy Arlington VA 22232
     
  27. Close the forms and return to your programming environment
  1. the form as follows: 
     
  2.  
  3.  
  4.   
  5.  
 

Cars

Cars are at the center of the rental transactions of our company. A car is the main reason a customer comes to the business. In our application, we will provide all the necessary information related to a car such as its make, model, year, picture, and whether it is available. Because we know that sometimes when renting or choosing a car, a customer may want to know the options available on a particular car, we will also list these basic pieces of information. Finally, we will mark a car as available or not. This will allow the clerk processing an order to know whether the customer can rent the car or not.

We will create two forms related to cars. One form will be used to enter a new car when the company acquires one. On the other hand, when interviewing a customer, if the clerk wants to see a list of the company cars, we will create a form that can help with this, allowing the clerk to navigate among cars for a review.

 

Practical Learning Practical Learning: Processing Cars

  1. Copy the following pictures to the bin sub-folder inside the main folder of the current project (Save them with their default names):
     
  2. Return to your programming environment
  3. To add a new form to the application, on the main menu, click Project -> Add Windows Forms
  4. Set the Name to NewCar and press Enter
  5. Design the form as follows: 
     
    Bethesda Car Rental - New Car
    Control Text Name Other Properties
    Label Text #    
    TextBox   txtTagNumber  
    Label Make:    
    TextBox   txtMake  
    Label Model:    
    TextBox   txtModel  
    Label Year:    
    TextBox   txtYear  
    Label Category:    
    ComboBox   cboCategory DropDownStyle: DropDownList
    Items: Economy
    Compact
    Standard
    Full Size
    Mini Van
    SUV
    Truck
    Van
    CheckBox Cassete Player chkK7Player CheckAlign: MiddleRight
    CheckBox DVD Player chkDVDPlayer CheckAlign: MiddleRight
    CheckBox CD Player chkCDPlayer CheckAlign: MiddleRight
    CheckBox Available chkAvailable CheckAlign: MiddleRight
    PictureBox   pctCar SizeMode: CenterImage
    Label Select Car Picture:    
    ComboBox none.gif cboPictures  
    Button Add Car btnAddCar  
    Button Close btnClose DialogResult: OK
    Form     FormBorderStyle: FixedDialog
    MaximizeBox: False
    MinimizeBox: False
    ShowInTaskbar: False
  6. To add a new class to the project, on the main menu, click Project -> Add Class...
  7. Set the Class Name to Car and click Open
  8. Access the Car.cs file and change it as follows:
     
    <Serializable()> Public NotInheritable Class Car
        Public TagNumber As String
        Public Make As String
        Public Model As String
        Public Year As Integer
        Public Category As String
        Public HasK7Player As Integer
        Public HasCDPlayer As Integer
        Public HasDVDPlayer As Integer
        Public PictureName As String
        Public IsAvailable As Integer
    
        Public Sub New()
            TagNumber = "000-000"
            Make = "Make"
            Model = "Model"
            Year = 1960
            Category = "Small"
            HasK7Player = 0
            HasCDPlayer = 0
            HasDVDPlayer = 0
            PictureName = ""
            IsAvailable = 0
        End Sub
    
        Public Sub New(ByVal tag As String, ByVal mk As String, _
                       ByVal mdl As String, ByVal yr As Integer, _
                       ByVal cat As String, ByVal k7 As Integer, _
                       ByVal cd As Integer, ByVal dvd As Integer, _
                       ByVal pct As String, ByVal avl As Integer)
    
            TagNumber = tag
            Make = mk
            Model = mdl
            Year = yr
            Category = cat
            HasK7Player = k7
            HasCDPlayer = cd
            HasDVDPlayer = dvd
            PictureName = pct
            IsAvailable = avl
        End Sub
    End Class
  9. Return to the Customers form. Right-click it and click View Code
  10. In the top section of the file, type:
     
    Imports System.IO
    Imports System.Runtime.Serialization.Formatters.Soap
    
    Public Class NewCar
        Inherits System.Windows.Forms.Form
    
        Private lstCars As ArrayList
    
  11. In the Class Name combo box, select (NewCar Events)
  12. In the Method Name combo box, select Load and implement its event as follows:
     
    Private Sub NewCar_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
            lstCars = New ArrayList
            Dim strFilename As String = "Cars.bcr"
            Dim bcrSoap As SoapFormatter = New SoapFormatter
    
            If File.Exists(strFilename) Then
                Dim bcrStream As FileStream = New FileStream(strFilename, FileMode.Open, FileAccess.Read, FileShare.Read)
                lstCars = bcrSoap.Deserialize(bcrStream)
                bcrStream.Close()
            Else
                Dim bcrStream As FileStream = New FileStream(strFilename, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write)
                bcrSoap.Serialize(bcrStream, lstCars)
                bcrStream.Close()
            End If
    
            ' Locate the director that contains the current application
            Dim dirInfo As DirectoryInfo = New DirectoryInfo(".\\")
    
            ' Get a reference to each file in that directory
            Dim lstFiles As FileInfo() = dirInfo.GetFiles()
    
            ' Display the names of the graphics files
            For Each fi As FileInfo In lstFiles
                If fi.Extension.Equals(".gif") Or _
                   fi.Extension.Equals(".jpeg") Or _
                   fi.Extension.Equals(".jpg") Or _
                   fi.Extension.Equals(".bmp") Or _
                   fi.Extension.Equals(".png") Then
                    cboPictures.Items.Add(fi.Name)
                End If
            Next
    
            cboPictures.Text = "none.gif"
    End Sub
  13. In the Class Name combo box, select cboPictures
  14. In the Method Name combo box, select SelectedIndexChanged and implement the event as follows:
     
    Private Sub cboPictures_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboPictures.SelectedIndexChanged
            Me.pctCar.Image = Image.FromFile(cboPictures.Text)
    End Sub
  15. In the Class name combo box, select btnAddCar
  16. In the Method Name combo box, select Click and implement it as follows:
     
    Private Sub btnAddCar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddCar.Click
            Dim vehicle As Car = New Car
    
            vehicle.TagNumber = Me.txtTagNumber.Text
            vehicle.Make = Me.txtMake.Text
            vehicle.Model = Me.txtModel.Text
            vehicle.Year = CInt(Me.txtYear.Text)
            vehicle.Category = Me.cboCategory.Text
            If Me.chkK7Player.Checked = True Then
                vehicle.HasK7Player = 1
            Else
                vehicle.HasK7Player = 0
            End If
    
            If Me.chkCDPlayer.Checked = True Then
                vehicle.HasCDPlayer = 1
            Else
                vehicle.HasCDPlayer = 0
            End If
    
            If Me.chkDVDPlayer.Checked = True Then
                vehicle.HasDVDPlayer = 1
            Else
                vehicle.HasDVDPlayer = 0
            End If
    
            vehicle.PictureName = cboPictures.Text
    
            If Me.chkAvailable.Checked = True Then
                vehicle.IsAvailable = 1
            Else
                vehicle.IsAvailable = 0
            End If
    
            lstCars.Add(vehicle)
    
            Dim strFilename As String = "Cars.bcr"
            Dim bcrSoap As SoapFormatter = New SoapFormatter
            Dim bcrStream As FileStream = New FileStream(strFilename, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write)
            bcrSoap.Serialize(bcrStream, lstCars)
            bcrStream.Close()
    
            Me.txtTagNumber.Text = ""
            Me.txtMake.Text = ""
            Me.txtModel.Text = ""
            Me.txtYear.Text = "1960"
            Me.cboCategory.SelectedIndex = 0
            Me.chkK7Player.Checked = False
            Me.chkCDPlayer.Checked = False
            Me.chkDVDPlayer.Checked = False
            cboPictures.Text = "none.gif"
            Me.chkAvailable.Checked = False
            Me.pctCar.Image = Image.FromFile("none.gif")
            Me.txtTagNumber.Focus()
    End Sub
  17. Display the first form, Switchboard.vb [Design]. Add a Button to the form and change its properties as follows:
    (Name): btnNewCar
    Text: New Car
  18. Double-click the New Car button to generate its Click event
  19. Implement the event as follows:
     
    Private Sub btnNewCar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewCar.Click
            Dim car As NewCar = New NewCar
            car.ShowDialog()
    End Sub
  20. Execute the application
  21. Create a few cars as follows:
     
  22. Close the forms and return to your programming environment
  23. To add a new form to the application, on the main menu, click Project -> Add Windows Forms
  24. Set the Name to Cars and press Enter
  25. Design the form as follows: 
     
    Control Text Name Other Properties
    Label Make:    
    TextBox   txtMake  
    Label Model:    
    TextBox   txtModel  
    Label Year:    
    TextBox   txtYear  
    Label Category:    
    TextBox   txtCategory  
    CheckBox Cassete Player chkK7Player CheckAlign: MiddleRight
    CheckBox DVD Player chkDVDPlayer CheckAlign: MiddleRight
    CheckBox CD Player chkCDPlayer CheckAlign: MiddleRight
    CheckBox Available chkAvailable CheckAlign: MiddleRight
    Label Tag #:    
    TextBox   txtTagNumber  
    PictureBox   pctCar  
    Button First btnFirst  
    Button Previous btnPrevious  
    Button Next btnNext  
    Button Last btnLast  
    Button Close btnClose  
    Form     MaximizeBox: False
    StartPosition: CenterScreen
  26. Right-click the form and click View Code
  27. In the top section of the file, type:
     
    Imports System.IO
    Imports System.Runtime.Serialization.Formatters.Soap
    
    Public Class Cars
        Inherits System.Windows.Forms.Form
    
        Private lstCars As ArrayList
        Private CurrentPosition As Integer
  28. In the Class Name combo box, select (Cars Events)
  29. In the Method Name combo box, select Load and implement the event as follows:
     
    Private Sub Cars_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
            lstCars = New ArrayList
            CurrentPosition = 0
    
            Dim strFilename As String = "Cars.bcr"
            Dim bcrSoap As SoapFormatter = New SoapFormatter
    
            If File.Exists(strFilename) Then
                Dim bcrStream As FileStream = New FileStream(strFilename, FileMode.Open, FileAccess.Read, FileShare.Read)
                lstCars = bcrSoap.Deserialize(bcrStream)
    
                bcrStream.Close()
                Me.btnFirst_Click(sender, e)
            End If
    End Sub
    
    Private Sub ShowCarInformation(ByVal vehicle As Car)
            Me.txtTagNumber.Text = vehicle.TagNumber
            Me.txtMake.Text = vehicle.Make
            Me.txtModel.Text = vehicle.Model
            Me.txtYear.Text = vehicle.Year.ToString()
            Me.txtCategory.Text = vehicle.Category
    
            If vehicle.HasK7Player = 1 Then
                Me.chkK7Player.Checked = True
            Else
                Me.chkK7Player.Checked = False
            End If
    
            If vehicle.HasCDPlayer = 1 Then
                Me.chkCDPlayer.Checked = True
            Else
                Me.chkCDPlayer.Checked = False
            End If
    
            If vehicle.HasDVDPlayer = 1 Then
                Me.chkDVDPlayer.Checked = True
            Else
                Me.chkDVDPlayer.Checked = False
            End If
            Dim strPictureName As String = vehicle.PictureName
    
            Try
                Me.pctCar.Image = Image.FromFile(vehicle.PictureName)
            Catch exc As OutOfMemoryException
                Me.pctCar.Image = Image.FromFile("none.gif")
            End Try
    
            If vehicle.IsAvailable = 1 Then
                Me.chkAvailable.Checked = True
            Else
                Me.chkAvailable.Checked = False
            End If
    End Sub
  30. In the Class Name combo box, select btnFirst
  31. In the Method Name combo box, select Click and implement the event as follows:
     
    Private Sub btnFirst_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFirst.Click
            If lstCars.Count = 0 Then Exit Sub
    
            CurrentPosition = 0
            Dim vehicle As Car = New Car
    
            vehicle = Me.lstCars(CurrentPosition)
    
            ShowCarInformation(vehicle)
    End Sub
  32. In the Class Name combo box, select btnPrevious
  33. In the Method Name combo box, select Click and implement the event as follows:
     
    Private Sub btnPrevious_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
            If lstCars.Count = 0 Then Exit Sub
    
            If CurrentPosition = 0 Then Exit Sub
    
            CurrentPosition = CurrentPosition - 1
            Dim vehicle As Car = New Car
    
            vehicle = lstCars(CurrentPosition)
    
            ShowCarInformation(vehicle)
    End Sub
  34. In the Class Name combo box, select btnNext
  35. In the Method Name combo box, select Click and implement the Click event as follows:
     
    Private Sub btnNext_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNext.Click
            If lstCars.Count = 0 Then Exit Sub
    
            If CurrentPosition = lstCars.Count - 1 Then
                Exit Sub
            Else
                CurrentPosition = CurrentPosition + 1
    
                Dim vehicle As Car = New Car
    
                vehicle = lstCars(CurrentPosition)
    
                ShowCarInformation(vehicle)
            End If
    End Sub
  36. In the Class Name combo box, select btnLast
  37. In the Method Name combo box, select Click and implement the Click event as follows:
     
    Private Sub btnLast_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLast.Click
            If lstCars.Count = 0 Then Exit Sub
    
            CurrentPosition = lstCars.Count - 1
            Dim vehicle As Car = New Car
    
            vehicle = Me.lstCars(CurrentPosition)
    
            ShowCarInformation(vehicle)
    End Sub
  38. Return to the Cars form. Double-click the Close button and implement its Click event as follows:
     
    Private Sub btnClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClose.Click
            Close()
    End Sub
  39. Display the first form, Switchboard.vb [Design]. Add a Button to the form and change its properties as follows:
    (Name): btnCarsReview
    Text: Car Review
  40. Double-click the New Car button to generate its Click event
  41. Implement the event as follows:
     
    Private Sub btnCarsReview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCarsReview.Click
            Dim frmCars As Cars = New Cars
            frmCars.Show()
    End Sub
  42. Execute the application and review the list of cars using the Cars form
     
  43. Close the forms and return to your programming environment
 

Rental Orders

To main purpose of a car rental company is to rent car. This is done by receiving orders from a customer and processing such an order. To proceed, a clerk would use a form to enter the customer and the car information. In our application, we will also make sure that name of the clerk who processed an order is specified. Other than than, we will enter as much information as possible to assist the user.

Practical Learning Practical Learning: Creating a Serializable Class

  1. To add a new form to the project, on the main menu, click Project -> Add Windows Form...
  2. Set the Name to RentalRates and press Enter
  3. 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  
    colWeekend Weekend Right  
  4. Create its Items as follows:
     
    ListViewItem ListViewSubItem ListViewSubItem ListViewSubItem ListViewSubItem
      Text Text Text Text
    Economy 32.95 29.75 22.95 19.95
    Compact 39.95 34.75 29.95 24.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
  5. Complete the design of the form as follows:
     
  6. To add a new class to the project, on the main menu, click Project -> Add Class...
  7. Set the Class Name to RentalOrder and press Enter
  8. Access the RentalOrder.h file and change it as follows:
     
    <Serializable()> Public NotInheritable Class RentalOrder
        Public ReceiptNumber As Integer
        Public ProcessedBy As String
        Public CarSelected As String
        Public Make As String
        Public Model As String
        Public Year As Integer
        Public CarCondition As String
        Public CustDrvLicNbr As String
        Public CustName As String
        Public CustAddress As String
        Public CustCity As String
        Public CustState As String
        Public CustZIPCode As String
        Public CustCountry As String
        Public TankLevel As String
        Public Mileage As Long
        Public StartDate As DateTime
        Public EndDate As DateTime
        Public Days As Integer
        Public RateApplied As Double
        Public SubTotal As Double
        Public TaxRate As Double
        Public TaxAmount As Double
        Public OrderTotal As Double
    
        Public Sub New()
    
        End Sub
    End Class
  9. To add a new form to the project, on the main menu, click Project -> Add Windows Form
  10. Set the Name to RentalOrders and press Enter
  11. Design the form as follows:
     
    Control Text Name Other Properties
    GroupBox Order Identification    
    Label Processed By:    
    ComboBox   cboEmployees  
    GroupBox Car Selected    
    ComboBox   cboCars  
    Label Make:    
    TextBox   txtMake  
    Label Model:    
    TextBox   txtModel  
    Label Year:    
    TextBox   txtCarYear  
    label Car Condition:    
    ComboBox   cboCarConditions  
    GroupBox Customer    
    ComboBox   cboCustomers  
    Label Name:    
    TextBox   txtCustName  
    Label Address:    
    TextBox   txtCustAddress  
    TextBox   txtCustCity  
    TextBox MD txtCustState  
    TextBox   txtCustZIPCode  
    TextBox USA txtCustCountry  
    GroupBox Order Evaluation    
  12. Right-click anywhere in the form and click View Code
  13. In the top section of the file, type:
     
    Imports System.IO
    Imports System.Runtime.Serialization.Formatters.Soap
    
    Public Class RentalOrders
        Inherits System.Windows.Forms.Form
    
        Private lstRentalOrders As ArrayList
  14. In the Class Name combo box, select (CleaningOrders Events)
  15. In the Method Name combo box, select Load and implement the event as follows:
     
    Private Sub RentalOrders_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
            lstRentalOrders = New ArrayList
            Dim lstEmployees As ArrayList = New ArrayList
            Dim bcrSoap As SoapFormatter = New SoapFormatter
            Dim strFilename As String = "Employees.bcr"
    
            If File.Exists(strFilename) Then
                Dim bcrStream As FileStream = New FileStream(strFilename, FileMode.Open, FileAccess.Read, FileShare.Read)
                lstEmployees = bcrSoap.Deserialize(bcrStream)
                bcrStream.Close()
    
                Dim firstName As String, lastName As String, title As String
    
                cboEmployees.Items.Clear()
    
                For Each empl As Employee In lstEmployees
                    firstName = empl.FirstName
                    lastName = empl.LastName
                    title = empl.Title
    
                    cboEmployees.Items.Add(lastName & ", " & firstName & " - " & title)
                Next
            End If
    
            strFilename = "Cars.bcr"
            Dim lstCars As ArrayList = New ArrayList
    
            If File.Exists(strFilename) Then
                Dim bcrStream As FileStream = New FileStream(strFilename, FileMode.Open, FileAccess.Read, FileShare.Read)
                lstCars = bcrSoap.Deserialize(bcrStream)
                bcrStream.Close()
    
                cboCars.Items.Clear()
    
                For Each vehicle As Car In lstCars
                    cboCars.Items.Add(vehicle.TagNumber)
                Next
            End If
    
            strFilename = "Customers.bcr"
            Dim lstCustomers As ArrayList = New ArrayList
    
            If File.Exists(strFilename) Then
                Dim bcrStream As FileStream = New FileStream(strFilename, FileMode.Open, FileAccess.Read, FileShare.Read)
                lstCustomers = bcrSoap.Deserialize(bcrStream)
                bcrStream.Close()
    
                cboCustomers.Items.Clear()
    
                For Each cust As Customer In lstCustomers
                    cboCustomers.Items.Add(cust.DrvLicNbr)
                Next
            End If
    End Sub
  16. In the Class Name combo box, select cboCars
  17. In the Method Name combo box, select SelectedIndexChanged and implement the event as follows:
     
    Private Sub cboCars_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboCars.SelectedIndexChanged
            Dim strFilename As String = "Cars.bcr"
            Dim lstCars As ArrayList = New ArrayList
            Dim bcrSoap As SoapFormatter = New SoapFormatter
    
            Dim bcrStream As FileStream = New FileStream(strFilename, FileMode.Open, FileAccess.Read, FileShare.Read)
            lstCars = bcrSoap.Deserialize(bcrStream)
            bcrStream.Close()
    
            For Each vehicle As Car In lstCars
                If vehicle.TagNumber = cboCars.Text Then
                    Me.txtMake.Text = vehicle.Make
                    Me.txtModel.Text = vehicle.Model
                    Me.txtCarYear.Text = vehicle.Year.ToString()
                    Exit Sub
                End If
            Next
    End Sub
  18. In the Class Name combo box, select cboCustomers
  19. In the Method Name combo box, select SelectedIndexChanged and implement the event as follows:
     
    Private Sub cboCustomers_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboCustomers.SelectedIndexChanged
            Dim strFilename As String = "Customers.bcr"
            Dim lstCustomers As ArrayList = New ArrayList
            Dim bcrSoap As SoapFormatter = New SoapFormatter
    
            Dim bcrStream As FileStream = New FileStream(strFilename, FileMode.Open, FileAccess.Read, FileShare.Read)
            lstCustomers = bcrSoap.Deserialize(bcrStream)
            bcrStream.Close()
    
            For Each cust As Customer In lstCustomers
                If cust.DrvLicNbr = cboCustomers.Text Then
                    Me.txtCustName.Text = cust.FullName
                    Me.txtCustAddress.Text = cust.Address
                    Me.txtCustCity.Text = cust.City
                    Me.txtCustState.Text = cust.State
                    Me.txtCustZIPCode.Text = cust.ZIPCode
                    Me.txtCustCountry.Text = cust.Country
                    Exit Sub
                End If
            Next
    End Sub
  20. In the Class Name combo box, select btnRateApplied
  21. In the Method Name combo box, select Click and implement the event as follows:
     
    Private Sub btnRateApplied_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRateApplied.Click
            Dim frmRates As RentalRates = New RentalRates
            frmRates.Show()
    End Sub
  22. In the Class Name combo box, select dtpEndDate
  23. In the Method Name combo box, select ValueChanged and implement the event as follows:
     
    Private Sub dtpEndDate_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtpEndDate.ValueChanged
            Dim dteStart As DateTime = Me.dtpStartDate.Value
            Dim dteEnd As DateTime = Me.dtpEndDate.Value
            Dim tme As TimeSpan = dteEnd.Subtract(dteStart)
            Dim days As Integer = tme.Days
    
            Me.txtDays.Text = CStr(days)
    End Sub
  24. In the Class Name combo box, select txtRateApplied
  25. In the Method Name combo box, select Leave and implement the event as follows:
     
    Private Sub txtRateApplied_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtRateApplied.Leave
            Dim days As Integer = CInt(Me.txtDays.Text)
            Dim rateApplied As Double = Decimal.Parse(Me.txtRateApplied.Text)
            Dim subTotal As Double = days * rateApplied
            Me.txtSubTotal.Text = subTotal.ToString("F")
            Dim taxRate As Double = Decimal.Parse(Me.txtTaxRate.Text)
            Dim taxAmount As Double = subTotal * taxRate / 100
            Me.txtTaxAmount.Text = taxAmount.ToString("F")
            Dim totalOrder As Double = subTotal + taxAmount
            Me.txtOrderTotal.Text = totalOrder.ToString("F")
    End Sub
  26. In the Class Name combo box, select btnSave
  27. In the Method Name combo box, select Click and implement the event as follows:
     
    Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
            Dim receiptNumber As Integer = 0
            Dim lstRentalOrders As ArrayList = New ArrayList
            Dim strFilename As String = "RentalOrders.bcr"
            Dim bcrSoap As SoapFormatter = New SoapFormatter
    
            If File.Exists(strFilename) Then
                Dim bcrStream As FileStream = New FileStream(strFilename, FileMode.Open, FileAccess.Read, FileShare.Read)
                lstRentalOrders = bcrSoap.Deserialize(bcrStream)
    
                Dim order As RentalOrder = lstRentalOrders(lstRentalOrders.Count - 1)
                receiptNumber = order.ReceiptNumber
                bcrStream.Close()
            Else
    
                Dim bcrStream As FileStream = New FileStream(strFilename, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write)
                bcrSoap.Serialize(bcrStream, lstRentalOrders)
                bcrStream.Close()
            End If
    
            Dim rntOrder As RentalOrder = New RentalOrder
    
            rntOrder.ReceiptNumber = receiptNumber + 1
            rntOrder.ProcessedBy = Me.cboEmployees.Text
            rntOrder.CarSelected = Me.cboCars.Text
            rntOrder.Make = Me.txtMake.Text
            rntOrder.Model = Me.txtModel.Text
            rntOrder.Year = CInt(Me.txtCarYear.Text)
            rntOrder.CarCondition = Me.cboCarConditions.Text
            rntOrder.CustDrvLicNbr = Me.cboCustomers.Text
            rntOrder.CustName = Me.txtCustName.Text
            rntOrder.CustAddress = Me.txtCustAddress.Text
            rntOrder.CustCity = Me.txtCustCity.Text
            rntOrder.CustState = Me.txtCustState.Text
            rntOrder.CustZIPCode = Me.txtCustZIPCode.Text
            rntOrder.CustCountry = Me.txtCustCountry.Text
            rntOrder.TankLevel = Me.cboTankLevels.Text
            rntOrder.Mileage = CLng(Me.txtMileage.Text)
            rntOrder.StartDate = Me.dtpStartDate.Value
            rntOrder.EndDate = Me.dtpEndDate.Value
            rntOrder.Days = CInt(Me.txtDays.Text)
            rntOrder.RateApplied = CDbl(Me.txtRateApplied.Text)
            rntOrder.SubTotal = CDbl(Me.txtSubTotal.Text)
            rntOrder.TaxRate = CDbl(Me.txtTaxRate.Text)
            rntOrder.TaxAmount = CDbl(Me.txtTaxAmount.Text)
            rntOrder.OrderTotal = CDbl(Me.txtOrderTotal.Text)
    
            lstRentalOrders.Add(rntOrder)
    
            Dim stmOrders As FileStream = New FileStream(strFilename, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write)
            bcrSoap.Serialize(stmOrders, lstRentalOrders)
            stmOrders.Close()
    
            Me.cboEmployees.Text = ""
            Me.cboCars.Text = ""
            Me.txtMake.Text = ""
            Me.txtModel.Text = ""
            Me.txtCarYear.Text = "2000"
            Me.cboCarConditions.Text = ""
            Me.cboCustomers.Text = ""
            Me.txtCustAddress.Text = ""
            Me.txtCustAddress.Text = ""
            Me.txtCustCity.Text = ""
            Me.txtCustState.Text = "MD"
            Me.txtCustZIPCode.Text = ""
            Me.txtCustCountry.Text = "USA"
            Me.cboTankLevels.Text = ""
            Me.txtMileage.Text = ""
            Me.dtpStartDate.Value = DateTime.Now
            Me.dtpEndDate.Value = DateTime.Now
            Me.txtDays.Text = "0"
            Me.txtRateApplied.Text = "24.95"
            Me.txtSubTotal.Text = "0.00"
            Me.txtTaxRate.Text = "7.75"
            Me.txtTaxAmount.Text = "0.00"
            Me.txtOrderTotal.Text = "0.00"
            Me.cboEmployees.Focus()
    End Sub
  28. Display the first form, Switchboard, and complete its design as follows:
     
    Control Name Text
    Button btnRentalOrders Rental Orders
    Button btnEmployees Employees
    Button btnCustomers Customers
  29. Double-click the Rental Orders button and implement its Click event as follows:
     
    Private Sub btnRentalOrders_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRentalOrders.Click
            Dim frmOrders As RentalOrders = New RentalOrders
            frmOrders.Show()
    End Sub
  30. In the Class Name combo box, select btnClose
  31. In the Method Name combo box, select Click and implement the event as follows:
     
    Private Sub btnClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClose.Click
            End
    End Sub
  32. Execute the application and create a few rental orders
     
  33. Close the forms and return to your programming environment
  34. Return to the RentalOrders form and double-click the Open button to implement its Click event as follows:
     
    Private Sub btnOpen_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOpen.Click
            Dim lstRentalOrders As ArrayList = New ArrayList
            Dim strFilename As String = "RentalOrders.bcr"
            Dim bcrSoap As SoapFormatter = New SoapFormatter
            Dim receiptNumber As Integer = CInt(Me.txtReceiptNumber.Text)
    
            If File.Exists(strFilename) Then
                Dim bcrStream As FileStream = New FileStream(strFilename, FileMode.Open, FileAccess.Read, FileShare.Read)
                lstRentalOrders = bcrSoap.Deserialize(bcrStream)
    
                bcrStream.Close()
    
                For Each order As RentalOrder In lstRentalOrders
                    If order.ReceiptNumber = receiptNumber Then
                        Me.cboEmployees.Text = order.ProcessedBy
                        Me.cboCars.Text = order.CarSelected
                        Me.txtMake.Text = order.Make
                        Me.txtModel.Text = order.Model
                        Me.txtCarYear.Text = CStr(order.Year)
                        Me.cboCarConditions.Text = order.CarCondition
                        Me.cboCustomers.Text = order.CustDrvLicNbr
                        Me.txtCustName.Text = order.CustName
                        Me.txtCustAddress.Text = order.CustAddress
                        Me.txtCustCity.Text = order.CustCity
                        Me.txtCustState.Text = order.CustState
                        Me.txtCustZIPCode.Text = order.CustZIPCode
                        Me.txtCustCountry.Text = order.CustCountry
                        Me.cboTankLevels.Text = order.TankLevel
                        Me.txtMileage.Text = CStr(order.Mileage)
                        Me.dtpStartDate.Value = order.StartDate
                        Me.dtpEndDate.Value = order.EndDate
                        Me.txtDays.Text = CStr(order.Days)
                        Me.txtRateApplied.Text = CStr(order.RateApplied)
                        Me.txtSubTotal.Text = CStr(order.SubTotal)
                        Me.txtTaxRate.Text = CStr(order.TaxRate)
                        Me.txtTaxAmount.Text = CStr(order.TaxAmount)
                        Me.txtOrderTotal.Text = CStr(order.OrderTotal)
                    End If
                Next
            Else
                MsgBox("There is no rental order with that receipt number!")
                Exit Sub
            End If
    End Sub
  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 btnClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClose.Click
            Close()
    End Sub
  37. Execute the application and try opening previous created orders
 

Previous Copyright © 2005-2012 FunctionX Next