
C# ПІДРУЧНИКИ / c# / Premier Press - C# Professional Projects
.pdf

IMPLEMENTING THE BUSINESS LOGIC |
Chapter 21 |
519 |
|
|
|
|
|
sqlDataAdapter1.UpdateCommand.ExecuteNonQuery(); sqlConnection1.Close();
lblDetails.Text=”Ticket confirmed\n(“ + dataSet21.Tables [“TicketDetails”].Rows[0][4].ToString() +
“\n” + dataSet21.Tables[“TicketDetails”].Rows[0][2].ToString() + “)”; lblDetails.Visible=true;
}
}
}
Summary
This chapter provided the necessary code and explanations to implement the functionality for Web forms.The forms of the SkyShark Airlines application have a consistent interface that is created by using a header file and a consistent menu on all Web forms. Most forms of the SkyShark Airlines application include data controls that are used to exchange data with the SkyShark database. Additionally, each Web form includes an authentication mechanism to ensure that the user is authorized to view the Web forms.
This page intentionally left blank


522 Project 4 CREATING AN AIRLINE RESERVATION PORTAL
In the last chapter, you implemented the business logic for running the application and fulfilling the business requirements of SkyShark Airlines. In this chapter, you will design and create the customer transaction portal for the airline, which will help customers to view details of new flights launched by the company,
the status of their tickets, and the status of flights.
Designing the Form
The customer transaction portal is developed to enhance the experience of customers. This portal provides the following four options to a customer:
View New Flights. This option enables customers to view the five most recently launched flights.
View Ticket Status. This option enables customers to view the status of their tickets.
View Flight Status. This option enables customers to view the booking status of a flight.
Confirm Reservation. This option enables customers to confirm their reservation.
To provide these functionalities, you’ll create an ASP.NET Web application.This application will contain only one Web form named wbFrmSkyShark.aspx. This form will display the data corresponding to all four options by using a different set of controls. The design of the wbFrmSkyShark.aspx Web form is displayed in Figure 22-1.

CREATING THE CUSTOMER TRANSACTION PORTAL |
Chapter 22 |
523 |
|
|
|
|
|
FIGURE 22-1 The design of the wbFrmSkyShark.aspx Web form
The preceding figure does not show all the controls present on the Web form. This is because I’ve used only a single Web form for all the options. Controls corresponding to each option are organized in various Panels. Table 22-1 lists all these Panels and other controls present on the Web form.
Table 22-1 Controls in the wbFrmSkyShark.aspx Form
Controls |
Function |
Panel1 |
Contains controls to display all the options |
Panel2 |
Contains controls used for the View Flight Status option |
Panel3 |
Contains controls used for the View Ticket Status option |
Panel4 |
Contains controls used for the Confirm Reservation option |
DataGrid1 |
Displays the new flights |
LblStatus |
To display various messages to the user |
|
|

524 Project 4 CREATING AN AIRLINE RESERVATION PORTAL
Of these panels, Table 22-2 lists all the controls present in Panel1.
Table 22-2 Controls in Panel1
Control Type |
ID |
Properties Changed |
Hyperlink |
Hyperlink1 |
Text=View New Flights |
|
|
NavigateURL = wbFrmSkyShark.aspx?subform=VNF |
Hyperlink |
Hyperlink2 |
Text=View Ticket Status |
|
|
NavigateURL = wbFrmSkyShark.aspx?subform=VTS |
Hyperlink |
Hyperlink3 |
Text=View Flight Status |
|
|
NavigateURL = wbFrmSkyShark.aspx?subform=VFS |
Hyperlink |
Hyperlink4 |
Text=Confirm Reservation |
|
|
NavigateURL = wbFrmSkyShark.aspx?subform=CR |
Hyperlink |
Hyperlink5 |
Text=Home |
|
|
NavigateURL = wbFrmSkyShark.aspx?subform=H |
|
|
|
If you notice, each panel is placed in different locations on the form. However, at run time, only one panel will appear on the screen, depending on the choice of the user. Therefore, you should align each panel at the same location before loading the form. You can do so by changing the Left and Top attributes of the panels in the Load event of the Web form, as given in the code that follows:
private void Page_Load(object sender, System.EventArgs e)
{
Panel2.Style[“left”]=”222px”;
Panel2.Style[“Top”]=”152px”;
Panel3.Style[“left”]=”222px”;
Panel3.Style[“Top”]=”152px”;
Panel4.Style[“left”]=”222px”;
Panel4.Style[“Top”]=”152px”;
}
The wbFrmSkyShark.aspx uses the dtFltDetails table to retrieve the flight details. Before you write the code for the wbFrmSkyShark.aspx form, drag the dtFltDetails table from Server Explorer to the design view of the form. Visual

CREATING THE CUSTOMER TRANSACTION PORTAL |
Chapter 22 |
525 |
|
|
|
|
|
Studio .NET automatically configures SqlDataAdapter and SqlConnection controls for the form. You can read a description of these controls in Chapter 19, “Basics of ASP.NET Web Applications,” in the section “Coding the Application.”
After you add SqlDataAdapter and SqlConnection controls to the form, you can generate a dataset for the form. To generate the dataset, follow these steps:
1.Click anywhere on the form.
2.Click on the Data menu and select Generate Dataset.The Generate Dataset dialog box will appear.
3.In the Generate Dataset dialog box, click on the New option and in the corresponding box, enter dsFlight and click on OK.
4.A new DataSet control is added to your project.
All three data controls are visible in Component Designer in the Design view of the form, as you can see in Figure 22-1. I will now proceed with the implementation of the functionality that was discussed in the beginning of the chapter.
The View New Flights Option
This option displays the details of the five most recent flights launched by the SkyShark Airlines in a DataGrid control. To implement this functionality, create a procedure named Display_NewFlights(). The code for this procedure is given as follows.
public void Display_NewFlights()
{
string SelStr;
SelStr = “Select top 5 fltno, origin, destination, deptime, fareexec, farebn, launchdate from dtfltdetails order by launchdate”;
SqlCommand SelComm;
SelComm = new SqlCommand(SelStr, sqlConnection1); sqlDataAdapter1.SelectCommand = SelComm; sqlDataAdapter1.Fill(dsFlight1,”Details”);
DataView source= new DataView(dsFlight1.Tables[“Details”]);
DataGrid1.DataSource=source;
DataGrid1.DataBind();
DataGrid1.Visible = true;
}

526 Project 4 CREATING AN AIRLINE RESERVATION PORTAL
This procedure will retrieve the data stored in the fltno, origin, destination, dep-
time, fareexec, farebn, and launchdate columns of the dtFltDetails table. The
retrieved data is displayed in the DataGrid1 control. This procedure will be called from the Page_Load event of the wbFrmSkyShark.aspx page.
The View Ticket Status Option
This option will enable the customer to view the status of her ticket. To view the status,the customer needs to provide the ticket number and e-mail ID. These values are then validated against the values stored in the dtReservations table in the database. If either the ticket number or the e-mail ID provided is incorrect, then a suitable error will be displayed.
You will accept the values from the customer in the txtTicketNo and txtEMail text boxes contained on Panel3. Table 22-3 lists all the controls contained in Panel3.
Table 22-3 Controls in Panel3
Control Type |
ID |
Properties Changed |
TextBox |
txtTicketNo |
None |
TextBox |
txtEMail |
None |
Button |
btnSubmit |
Text=Submit |
|
|
|
The values entered in the text boxes are validated and the corresponding result is displayed on the click of the Submit button. The code for the Click event of the Submit button is given as follows.
private void btnSubmit_Click(object sender, System.EventArgs e)
{
string strSel; int status;
strSel = “Select email, status from dtReservations where TicketNo = @TN”; SqlCommand SelComm;
SelComm = new SqlCommand(strSel, sqlConnection1); sqlDataAdapter1.SelectCommand = SelComm; sqlDataAdapter1.SelectCommand.Parameters.Add(“@TN”, SqlDbType.Char, 10).Value
= txtTicketNo.Text ;

CREATING THE CUSTOMER TRANSACTION PORTAL |
Chapter 22 |
527 |
|
|
|
|
|
SqlDataReader rdrTicket; sqlConnection1.Open();
rdrTicket = sqlDataAdapter1.SelectCommand.ExecuteReader();
if( rdrTicket.Read())
{
if( rdrTicket.GetString(0).Trim() == txtEMail.Text )
{
status = rdrTicket.GetInt32(1);
}
else
{
lblStatus.ForeColor = Color.Red ; lblStatus.Text = “Incorrect EMail ID!!”; return;
}
}
else
{
lblStatus.ForeColor = Color.Red ; lblStatus.Text = “Incorrect Ticket Number!!”; return;
}
sqlConnection1.Close(); if(status >= 0)
{
lblStatus.ForeColor = Color.Blue ; lblStatus.Text = “Your ticket is confirmed”;
}
else
{
lblStatus.ForeColor = Color.Blue ;
lblStatus.Text = “Your ticket is overbooked by “ + Convert.ToString (status);
}
}