File-Based Applications: |
|
|
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: Processing Cars |
|
<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 |
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: Creating a Serializable Class |
(Name) | Text | TextAlign | Width |
colCategory | Category | 90 | |
colDaily | Daily | Right | |
colWeekly | Weekly | Right | |
colMonthly | Monthly | Right | |
colWeekend | Weekend | Right |
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 |
<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 |
|
Imports System.IO Imports System.Runtime.Serialization.Formatters.Soap Public Class RentalOrders Inherits System.Windows.Forms.Form Private lstRentalOrders As ArrayList |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
|
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 |
Private Sub btnClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClose.Click End End Sub |
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 |
Private Sub btnClose_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClose.Click Close() End Sub |
|
||
Previous | Copyright © 2005-2016, FunctionX | Next |
|