Creating the Airlines Reservation Application


To create the Airlines Reservation application, you need to create the Airlines, Aircrafts, Reservation, Application Manager, and Confirm Reservation Information windows as well as the Shared module.

Creating the Shared Module

The Shared.vb file defines the Shared module that provides the main() function, which initializes the Airlines Reservation application. The Shared module also defines a Boolean variable, boolConfirmation, that stores the true or false values depending on the confirmation of reservation information in the Confirm Reservation Information window.

Listing 5-2 shows the code for the Shared.vb file that defines the Shared module:

Listing 5-2: The Shared.vb File
start example
 Imports System.Data.SqlClient Imports System.IO Module _Shared  Public boolConfirmation As Boolean  Public travelerId As Integer  Public sqlConnection As New SqlConnection  Public Sub main() 'Try to establish SQL connection to database airlines through SQL Connection object  Try  Try 'Read connectionstring from a text file, settings.txt, located in /bin folder of the application Dim sr As New StreamReader("Settings.txt") sqlConnection.ConnectionString = sr.ReadLine  sr.Close()  Catch ex As Exception sqlConnection.ConnectionString = "SERVER=localhost;UID=sa;PWD=sa;Initial Catalog=airlines"  End Try  sqlConnection.Open() Dim objApplicationManager As New ApplicationManager  objApplicationManager.ShowDialog()  Catch ex As Exception MsgBox("Error in establishing connection", MsgBoxStyle.OKOnly, "CONNECTION ERROR")  Exit Sub  End Try  End Sub End Module 
end example
 

Download this Listing .

In the above listing, the main() function establishes a connection with the airlines database through a SqlConnection object. If the connection is established successfully then the main() function invokes the Application Manager window.

Creating the Airlines Window

The Airlines class defines the Airlines window. The Airlines class displays the available airlines to the end user. The Airlines class also enables an end user to add and delete airlines.

Listing 5-3 shows the code for the frmAirlines.vb file that defines the Airlines class:

Listing 5-3: The frmAirlines.vb File
start example
 'This class allows the end user to add airlines, view existing airlines, and delete existing airlines information Imports System.Data.SqlClient Public Class Airlines    Inherits System.Windows.Forms.Form    Dim sqlCommand As SqlCommand    Dim sqlda As SqlDataAdapter    Dim ds As DataSet    Dim tempListViewItem As ListViewItem    Private Sub Airlines_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load       'Retrieve existing airlines in the database       Try          sqlCommand = New SqlCommand("select * from Airlines", sqlConnection)          sqlda = New SqlDataAdapter(sqlCommand)          ds = New DataSet          sqlda.Fill(ds)          Catch ex As Exception          MsgBox("Unable to retrieve Airlines.", MsgBoxStyle.OKOnly, "Retrieval Error")          Exit Sub       End Try       If Not ds.Tables(0).Rows.Count = 0 Then          Dim rowcount As Integer          For rowcount = 0 To ds.Tables(0).Rows.Count - 1          tempListViewItem = listviewExistingAirlines.Items.Add(ds.Tables(0).Rows(rowcount).Item(1))          tempListViewItem.SubItems.Add(ds.Tables(0).Rows(rowcount).Item(0))          Next       End If    End Sub    Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click       If Not txtAirlineCode.Text = "" And Not txtAirlineName.Text = "" Then          'Insert the new airlines information into table Airlines          Try             sqlCommand = New SqlCommand("insert into Airlines values('" & txtAirlineCode.Text _             & "','" & txtAirlineName.Text & "')", sqlConnection)             sqlCommand.ExecuteNonQuery()             tempListViewItem = listviewExistingAirlines.Items.Add(txtAirlineName.Text)             tempListViewItem.SubItems.Add(txtAirlineCode.Text)             Catch ex As Exception             'Check whether the exception has occurred due to UNIQUE KEY or PRIMARY KEY violation             Dim strExceptionMessage As String = ex.Message             Dim foundAt As Integer = strExceptionMessage.IndexOf("PRIMARY")             If foundAt > 0 Then             'Exception occurred due to PRIMARY KEY violation             MsgBox("Airline Code already exists.", MsgBoxStyle.OKOnly, "Please check the Airline Code")             Else             'Exception occurred due to UNIQUE KEY violation             MsgBox("Airline name already exists.", MsgBoxStyle.OKOnly, "Please check the Airline Name")             End If             Exit Sub          End Try          txtAirlineCode.Text = ""          txtAirlineName.Text = ""          txtAirlineName.Focus()       End If    End Sub    Private Sub listviewExistingAirlines_Click(ByVal sender As Object, ByVal e As _    System.EventArgs) Handles listviewExistingAirlines.Click       If Not listviewExistingAirlines.SelectedItems(0).Text = "" Then          txtAirlineName.Text = listviewExistingAirlines.SelectedItems(0).Text          txtAirlineCode.Text = listviewExistingAirlines.SelectedItems(0).SubItems(1).Text       End If    End Sub    Private Sub cmdDelete_Click(ByVal sender As System.Object, ByVal e As _    System.EventArgs) Handles cmdDelete.Click       If Not txtAirlineCode.Text = "" And Not txtAirlineName.Text = "" Then          'Delete the specified airlines from table Airlines          Dim rowsAffected As Integer             Try             sqlCommand = New SqlCommand("delete from Airlines where AirlineCode='" & _             txtAirlineCode.Text & "'", sqlConnection)             rowsAffected = sqlCommand.ExecuteNonQuery()             If Not rowsAffected = 0 Then             listviewExistingAirlines.Items.Remove(listviewExistingAirlines.SelectedItems(0))             End If             Catch ex As Exception             MsgBox("Unable to delete the specified Airlines.", MsgBoxStyle.OKOnly, "Please check the Airline Code")             Exit Sub          End Try          txtAirlineCode.Text = ""          txtAirlineName.Text = ""          txtAirlineName.Focus()       End If    End Sub    Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As _    System.EventArgs) Handles cmdClose.Click       Me.Close()    End Sub End Class 
end example
 

Download this Listing .

The above listing defines the following methods :

  • Aircrafts_Load() : Retrieves existing airlines from the Airlines table in the listviewExistingAirlines list view control.

  • cmdAdd_Click() : Executes when an end user specifies the information for the new airlines and clicks the Add Airline button to add the airlines into the Airlines table. This method inserts the new airlines into the Airlines table if the information conforms to the PRIMARY KEY and UNIQUE KEY constraints in the Airlines table in the database.

  • cmdDelete_Click() : Executes when an end user selects an airline and clicks the Delete Airlines button to delete the selected airline. This method deletes the selected airline.

Figure 5-5 shows the output of Listing 5-3:

click to expand: this figure shows the airlines window that displays existing airlines and enables and end user to add and delete airlines.
Figure 5-5: The Airlines Window

Creating the Aircrafts Window

The Aircrafts class defines the Aircrafts window. The Aircrafts class enables end users to view, add, and delete aircrafts for a particular airline.

Listing 5-4 shows the code for the frmAircrafts.vb file that defines the Aircrafts class:

Listing 5-4: The frmAircrafts.vb File
start example
 'This class allows the end user to add aircrafts information and view existing aircrafts information Imports System.Data.SqlClient Public Class Aircrafts    Inherits System.Windows.Forms.Form    Dim sqlCommand As sqlCommand    Dim sqlda As SqlDataAdapter    Dim ds As DataSet    Dim tempListViewItem As ListViewItem    Private Sub Aircrafts_Load(ByVal sender As System.Object, ByVal e _    As System.EventArgs) Handles MyBase.Load       'Retrieve existing airlines in the database       Try          sqlCommand = New SqlCommand("select * from Airlines", sqlConnection)          sqlda = New SqlDataAdapter(sqlCommand)          ds = New DataSet          sqlda.Fill(ds)          Catch ex As Exception          MsgBox("Unable to retrieve Airlines.", MsgBoxStyle.OKOnly, "Retrieval Error")          Exit Sub       End Try       If Not ds.Tables(0).Rows.Count = 0 Then          'Add the retrieved airlines in the airlinesCombo          Dim rowcount As Integer          For rowcount = 0 To ds.Tables(0).Rows.Count - 1          airlinesCombo.Items.Add(ds.Tables(0).Rows(rowcount).Item(0))          Next       End If       If Not airlinesCombo.Items.Count = 0 Then          airlinesCombo.SelectedIndex = 0       End If    End Sub    Private Sub airlinesCombo_SelectedIndexChanged(ByVal sender As Object, _    ByVal e As System.EventArgs) Handles airlinesCombo.SelectedIndexChanged       listviewExistingAircrafts.Items.Clear()       'Retrieve existing aircrafts information that belongs to the selected airline       If Not airlinesCombo.Text = "" Then          Try          sqlCommand = New SqlCommand("select AircraftId, AirlineName from Aircrafts, _          Airlines where Airlines.AirlineCode=Aircrafts.AirlineCode and Airlines.AirlineCode='" & _          airlinesCombo.Text & "'", sqlConnection)          sqlda = New SqlDataAdapter(sqlCommand)          ds = New DataSet          sqlda.Fill(ds)          Catch ex As Exception          MsgBox("Unable to retrieve Aircrafts.", MsgBoxStyle.OKOnly, "Retrieval Error")          Exit Sub          End Try          If Not ds.Tables(0).Rows.Count = 0 Then             txtAirlineName.Text = ds.Tables(0).Rows(0).Item(1)             Dim rowcount As Integer             For rowcount = 0 To ds.Tables(0).Rows.Count - 1             tempListViewItem = listviewExistingAircrafts.Items.Add(ds.Tables(0).Rows(rowcount).Item(0))             tempListViewItem.SubItems.Add(airlinesCombo.Text)             tempListViewItem.SubItems.Add(ds.Tables(0).Rows(rowcount).Item(1))             Next             Else             'Retrieve the airlines name             sqlCommand = New SqlCommand("select AirlineName from Airlines where AirlineCode='" _             & airlinesCombo.Text & "'", sqlConnection)             sqlda = New SqlDataAdapter(sqlCommand)             ds = New DataSet             sqlda.Fill(ds)             txtAirlineName.Text = ds.Tables(0).Rows(0).Item(0)          End If       End If    End Sub    Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click       If Not txtAircraftId.Text = "" And Not airlinesCombo.Text = "" Then          'Insert the new aircraft information into table Aircrafts          Try             sqlCommand = New SqlCommand("insert into Aircrafts values('" & _             txtAircraftId.Text & "','" & airlinesCombo.Text & "')", sqlConnection)             sqlCommand.ExecuteNonQuery()             tempListViewItem = listviewExistingAircrafts.Items.Add(txtAircraftId.Text)             tempListViewItem.SubItems.Add(airlinesCombo.Text)             tempListViewItem.SubItems.Add(txtAirlineName.Text)             Catch ex As Exception             'Check whether the exception has occurred due to FOREIGN KEY or PRIMARY KEY violation             Dim strExceptionMessage As String = ex.Message             Dim foundAt As Integer = strExceptionMessage.IndexOf("PRIMARY")             If foundAt > 0 Then             'Exception occurred due to PRIMARY KEY violation             MsgBox("Aircraft Id already exists.", MsgBoxStyle.OKOnly, "Please check the Aircraft Id")             Else             'Exception occurred due to FOREIGN KEY violation             MsgBox("Invalid Airline Code.", MsgBoxStyle.OKOnly, "Please check the Airline Code")             End If             Exit Sub          End Try          txtAircraftId.Text = ""          txtAircraftId.Focus()       End If    End Sub    Private Sub listviewExistingAircrafts_Click(ByVal sender As Object, ByVal e As _    System.EventArgs) Handles listviewExistingAircrafts.Click       If Not listviewExistingAircrafts.SelectedItems(0).Text = "" Then          txtAircraftId.Text = Trim(listviewExistingAircrafts.SelectedItems(0).Text)       End If    End Sub    Private Sub cmdDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDelete.Click       If Not airlinesCombo.Text = "" And Not txtAirlineName.Text = "" And Not txtAircraftId.Text = "" Then          'Delete the specified aircraft from table Aircrafts          Try             Dim rowsAffected As Integer             sqlCommand = New SqlCommand("delete from Aircrafts where AircraftId='" & _             txtAircraftId.Text & "'", sqlConnection)             rowsAffected = sqlCommand.ExecuteNonQuery()             If Not rowsAffected = 0 Then             listviewExistingAircrafts.Items.Remove(listviewExistingAircrafts.SelectedItems(0))             End If             Catch ex As Exception             MsgBox("Unable to delete the specified Aircraft.", MsgBoxStyle.OKOnly, "Database Error")             Exit Sub          End Try          txtAircraftId.Text = ""          txtAircraftId.Focus()       End If    End Sub    Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClose.Click       Me.Close()       End Sub End Class 
end example
 

Download this Listing .

The above listing defines the following methods:

  • Aircrafts_Load() : Retrieves available airlines.

  • cmdAdd_Click() : Executes when an end user selects an airline, specifies information, and clicks Add Aircraft to add an aircraft to a selected airline. This method inserts the aircraft information in the database if the information conforms to the PRIMARY KEY and FOREIGN KEY constraints in the Aircrafts table.

  • cmdDelete_Click() : Executes when an end user selects an aircraft and clicks the Delete Aircraft button to delete an aircraft. This method deletes the selected aircraft.

Figure 5-6 shows the output of Listing 5-4:

click to expand: this figure shows the aircrafts window where an end user can add, view, and delete aircraft information.
Figure 5-6: The Aircrafts Window

Creating the Reservation Window

The Reservation class defines the Reservation window. The Reservation window displays the seats in an aircraft and enables an end user to select a seat and allocate the seat to a traveler . A combination of the row number and the location in that row represents a seat.

Listing 5-5 shows the code for the frmReservation.vb file that defines the Reservation class:

Listing 5-5: The frmReservation.vb File
start example
 'This class allows an end user to reserve seats for aircrafts. Each button  'in a row of Seats group box represents a location in that row. Imports System.Data.SqlClient Imports System.IO Public Class Reservation    Inherits System.Windows.Forms.Form    Dim sqlCommand As sqlCommand    Dim sqlda As SqlDataAdapter    Dim ds As DataSet    Private Sub frmReservation_Load(ByVal sender As System.Object, ByVal e _    As System.EventArgs) Handles MyBase.Load       'Retrieve available Airlines from the database.       Try          sqlCommand = New SqlCommand("select * from Airlines", sqlConnection)          sqlda = New SqlDataAdapter(sqlCommand)          ds = New DataSet          sqlda.Fill(ds)          Catch ex As Exception          MsgBox("Unable to retrieve Airlines.", MsgBoxStyle.OKOnly, "Retrieval Error")          Exit Sub       End Try       If Not ds.Tables(0).Rows.Count = 0 Then          Dim rowcount As Integer          For rowcount = 0 To ds.Tables(0).Rows.Count - 1          airlinesCombo.Items.Add(ds.Tables(0).Rows(rowcount).Item(0))          Next       End If       If Not airlinesCombo.Items.Count = 0 Then          airlinesCombo.SelectedIndex = 0       End If    End Sub    Private Sub airlinesCombo_SelectedIndexChanged(ByVal sender As Object, ByVal e _    As System.EventArgs) Handles airlinesCombo.SelectedIndexChanged       aircraftCombo.Items.Clear()       If Not airlinesCombo.Text = "" Then          Try             sqlCommand = New SqlCommand("select AircraftId, AirlineName from Aircrafts, Airlines _              where Airlines.AirlineCode=Aircrafts.AirlineCode and Airlines.AirlineCode='" & _              airlinesCombo.Text & "'", sqlConnection)             sqlda = New SqlDataAdapter(sqlCommand)             ds = New DataSet             sqlda.Fill(ds)             Catch ex As Exception             MsgBox("Unable to retrieve Aircrafts.", MsgBoxStyle.OKOnly, "Retrieval Error")             Exit Sub          End Try          If Not ds.Tables(0).Rows.Count = 0 Then             txtAirlineName.Text = ds.Tables(0).Rows(0).Item(1)             Dim rowcount As Integer             For rowcount = 0 To ds.Tables(0).Rows.Count - 1             aircraftCombo.Items.Add(ds.Tables(0).Rows(rowcount).Item(0))             Next          End If          If Not aircraftCombo.Items.Count = 0 Then             aircraftCombo.SelectedIndex = 0          End If       End If    End Sub    Private Sub aircraftCombo_SelectedIndexChanged(ByVal sender As Object, _    ByVal e As System.EventArgs) Handles aircraftCombo.SelectedIndexChanged       If Not aircraftCombo.Text = "" Then          'Set the default color of the seats          defaultColor()          'Retrieve the reserved seats for the selected aircraft.           'A seat is defined by a combination of row number and location in that row.          Try             sqlCommand = New SqlCommand("select * from Seats where AircraftId='" & _             aircraftCombo.Text & "'", sqlConnection)             sqlda = New SqlDataAdapter(sqlCommand)             ds = New DataSet             sqlda.Fill(ds)             Catch ex As Exception             MsgBox("Unable to retrieve seats information.", MsgBoxStyle.OKOnly, "Retrieval Error")             Exit Sub          End Try          'If any seat that belongs to the selected aircraft is reserved, the back color _          'of the button corresponding to the reserved seat is changed to red          If Not ds.Tables(0).Rows.Count = 0 Then             Dim rowcount As Integer             'A string variable to hold the row number and location code combination to represent a seat             Dim strRowLocationCombination As String             For rowcount = 0 To ds.Tables(0).Rows.Count - 1             Dim tempString As String = ds.Tables(0).Rows(rowcount).Item(1)             strRowLocationCombination = ds.Tables(0).Rows(rowcount).Item(0) & _             Mid(tempString, Trim(aircraftCombo.Text).Length + 1)             Dim countOuterControl As Integer             'Iterate through the seatsGroupbox             For countOuterControl = 0 To seatsGroupBox.Controls.Count - 1             Dim countInnerControl As Integer             'Iterate through the row group boxes inside the seatsGroupbox             For countInnerControl = 0 To _             seatsGroupBox.Controls(countOuterControl).Controls.Count - 1             If seatsGroupBox.Controls(countOuterControl).Controls(countInnerControl).Name = _             "Seat" & strRowLocationCombination Then             'Highlight the reserved seat with red color             seatsGroupBox.Controls(countOuterControl).Controls(countInnerControl).BackColor = Color.Red             End If             Next             Next             Next          End If       End If    End Sub    Private Sub cmdReserve_Click(ByVal sender As System.Object, ByVal e As _    System.EventArgs) Handles cmdReserve.Click       If Not txtTravelerName.Text = "" And Not airlinesCombo.Text = "" And Not aircraftCombo.Text = "" Then          seatsGroupBox.Enabled = True          cmdReserve.Enabled = False          airlinesCombo.Enabled = False          aircraftCombo.Enabled = False       End If    End Sub    Private Sub onButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _    Seat11.Click, Seat12.Click, Seat13.Click, Seat14.Click, Seat15.Click, Seat16.Click, _    Seat21.Click, Seat22.Click, Seat23.Click, Seat24.Click, Seat25.Click, Seat26.Click, _    Seat31.Click, Seat32.Click, Seat33.Click, Seat34.Click, Seat35.Click, Seat36.Click, _    Seat41.Click, Seat42.Click, Seat43.Click, Seat44.Click, Seat45.Click, Seat46.Click       'A temporary Button control to refer to the actual button that has initiated this event       Dim tempButton As Button = sender       'Extracting the row number of the clicked button       Dim rowNumber As Integer = CInt(Mid(tempButton.Parent.Name, (Mid(tempButton.Parent.Name, 1, 4).Length), 1))       'Extracting the location of the clicked button       Dim seatLocation As Integer = CInt(tempButton.Text)       'The locationCode of the clicked button       Dim locationCode As String = Trim(aircraftCombo.Text) & seatLocation       'Create an instance of Confirmation class that displays the        'Confirm Reservation Information window       Dim objComfirmation As New Confirmation(txtAirlineName.Text, _       Trim(aircraftCombo.Text), txtTravelerName.Text, rowNumber, seatLocation)       objComfirmation.ShowDialog()       'If the end user clicks on the Confirm button in the Confirm Reservation Information window       If boolConfirmation = True Then          Dim objTransaction As SqlTransaction = sqlConnection.BeginTransaction          Try             'Inserting traveler information in the Travelers table             sqlCommand = New SqlCommand("insert into Travelers values(" & travelerId & _             ",'" & aircraftCombo.Text & "','" & txtTravelerName.Text & "')",  sqlConnection)             sqlCommand.Transaction = objTransaction             sqlCommand.ExecuteNonQuery()             'Inserting reservation information in the Seats table             sqlCommand = New SqlCommand("insert into Seats values(" & rowNumber & _             ",'" & locationCode & "'," & travelerId & ",'" & _             Trim(aircraftCombo.Text) & "')", sqlConnection)             sqlCommand.Transaction = objTransaction             sqlCommand.ExecuteNonQuery()             objTransaction.Commit()             tempButton.BackColor = Color.Red             txtTravelerName.Text = ""             Catch ex As Exception             'Check whether the exception has occurred due to PRIMARY KEY              'violation in Travelers or Seats table             Dim strExceptionMessage As String = ex.Message             Dim foundAt As Integer = strExceptionMessage.IndexOf("Travelers")             If foundAt > 0 Then             'Exception occurred due to PRIMARY KEY violation in Travelers table             MsgBox("Traveler Id already exists.", MsgBoxStyle.OKOnly, "Please check the Traveler Id")             Else             'Exception occurred due to PRIMARY KEY violation in Seats table             MsgBox("Seat already reserved.", MsgBoxStyle.OKOnly, "Please check the seat to be reserved")             End If             objTransaction.Rollback()          End Try       End If       seatsGroupBox.Enabled = False       cmdReserve.Enabled = True       airlinesCombo.Enabled = True       aircraftCombo.Enabled = True    End Sub    'This method sets the default color of the seats as Color.Gray when an aircraft id is selected    Private Sub defaultColor()       'An integer variable to iterate through the Row group box controls within seatsGroupBox       Dim countOuterControl As Integer       'An integer variable to iterate through the button controls within Row group boxes       Dim countInnerControl As Integer       For countOuterControl = 0 To seatsGroupBox.Controls.Count - 1          For countInnerControl = 0 To seatsGroupBox.Controls(countOuterControl).Controls.Count - 1          seatsGroupBox.Controls(countOuterControl).Controls(countInnerControl).BackColor = Color.Gray          Next       Next    End Sub    Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e _    As System.EventArgs) Handles cmdClose.Click       Me.Close()       End Sub End Class 
end example
 

Download this Listing .

The above listing defines the following methods:

  • Reservation_Load() : Retrieves a list of available airlines.

  • cmdReserve_Click() : Executes when an end user selects an airline and an aircraft, specifies the traveler name, and clicks the Reserve button to reserve a seat for the specified traveler. This method enables the seatsGroupBox group box control that enables an end user to select a seat.

  • OnButtonClick() : Handles the click event of every seat button and executes when an end user clicks a seat button in the seatsGroupBox group box control to reserve that seat for the specified traveler. This method invokes the Confirmation window that displays information, such as the seat selected, airlines, aircraft id, and traveler id. If the end user confirms the information in the Confirmation window, this method inserts the specified information in the database if the information conforms to the constraints in the Travelers and Seats tables. This method then changes the color of the button to Red, which represents a reserved seat.

Figure 5-7 shows the output of Listing 5-5:

click to expand: this figure shows the reservation window that displays the reserved seats for a particular aircraft and enables an end user to reserve seats for travelers.
Figure 5-7: The Reservation Window

Creating the Confirm Reservation Information Window

The Confirmation class defines the Confirm Reservation Information window. The Confirmation class displays the information specified by an end user in the Reservation window to reserve a seat.

Listing 5-6 shows the code for the frmConfirmation.vb file that defines the Confirmation class:

Listing 5-6: The frmConfirmation.vb File
start example
 'This class enables the end user to view the reservation information and  'confirm the reservation or cancel the reservation. Public Class Confirmation  Inherits System.Windows.Forms.Form  Dim strAirlines As String  Dim strAircraftId As String  Dim strTravelerName As String  Dim rowNumber As Integer  Dim seatlocation As Integer Public Sub New(ByVal strAirlines As String, ByVal strAircraftId As String, _ ByVal strTravelerName As String, ByVal rowNumber As Integer, ByVal locationCode As Integer)  MyBase.New()  InitializeComponent()  Me.strAirlines = strAirlines  Me.strAircraftId = strAircraftId  Me.strTravelerName = strTravelerName  Me.rownumber = rowNumber  Me.seatlocation = locationCode  End Sub Private Sub Confirmation_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load  'The Airlines name  lblAirlines.Text = strAirlines  'The Aircraft Id  lblaircraft.Text = strAircraftId  'The Traveler Name  lblTravelerName.Text = strTravelerName 'Location code is a combination of Aircraft Id and the location of the selected row Dim locationCode = strAircraftId & seatlocation 'The seat allotted is represented by combination of row number and location code lblSeat.Text = "Row number : " & rowNumber & vbCrLf & "Location code : " & locationCode  End Sub Private Sub cmdBack_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdBack.Click  boolConfirmation = False  Me.Close()  End Sub Private Sub cmdConfirm_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdConfirm.Click  boolConfirmation = True  travelerId = CInt(txtTravelerId.Text)  Me.Close()  End Sub End Class 
end example
 

Download this Listing .

The above listing defines the following methods:

  • Confirmation_Load() : Displays the reservation information specified by the end user in the Reservation window.

  • cmdConfirm_Click() : Executes when an end user specifies the traveler id and clicks the Confirm button to confirm the reservation information and reserve a seat. This method sets the value of a Boolean variable named boolConfirmation as true.

Figure 5-8 shows the output of Listing 5-6:

click to expand: this figure shows the confirmation window that displays the reservation information, which an end user specifies in the reservation window, and enables an end user to confirm that information.
Figure 5-8: The Confirmation Window

Creating the Application Manager Window

The ApplicationManager class defines the Application Manager window that enables an end user to invoke the Airlines, Aircrafts, and Reservation window.

Listing 5-7 shows the code for the frmApplicationManager.vb file that defines the Application Manager class:

Listing 5-7: The frmApplicationManager.vb File
start example
 Public Class ApplicationManager  Inherits System.Windows.Forms.Form Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click  Dim objReservation As New Reservation  objReservation.ShowDialog()  End Sub Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click  Dim objAirlines As New Airlines  objAirlines.ShowDialog()  End Sub Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click  Dim objAircrafts As New Aircrafts  objAircrafts.ShowDialog()  End Sub End Class 
end example
 

Download this Listing .

In the above listing, the ApplicationManager class provides functions to invoke the Airlines, Aircrafts, and Reservation windows. The end user selects the Airlines menu option to invoke the Airlines window. The end user selects the Aircrafts menu option to invoke the Aircrafts window. The end user selects the Reservation menu option to invoke the Reservation window.

Figure 5-9 shows the output of Listing 5-7:

click to expand: this figure shows the application manager window that displays the options to enable an end user to access the airlines, aircrafts, and reservation windows.
Figure 5-9: The Application Manager Window in Design View



NET InstantCode. UML with Visio and Visual Studio .NET
NET InstantCode. UML with Visio and Visual Studio .NET
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 49

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net