![]() |
File-Based Applications: |
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. |
|
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
<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 |
Imports System.IO Imports System.Runtime.Serialization.Formatters.Soap Public Class NewCar Inherits System.Windows.Forms.Form Private lstCars As ArrayList |
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 |
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 |
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 |
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 |
![]() |
![]() |
![]() |
![]() |
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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 |
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 |
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 |
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 |
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 |
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 |
Private Sub btnClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClose.Click Close() End Sub |
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 |
![]() |
![]() |
![]() |
![]() |
|
||
Previous | Copyright © 2005-2016, FunctionX | Next |
|