Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

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

.pdf
Скачиваний:
475
Добавлен:
12.02.2016
Размер:
14.7 Mб
Скачать
Creating the

458 Project 4 CREATING AN AIRLINE RESERVATION PORTAL

Creating the dtReservations Table

The dtReservations table is used to reserve seats for passengers on each flight. The SQL script that generates this table is given as follows:

CREATE TABLE [dbo].[dtReservations]

(

 

 

[TicketNo] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,

 

[FltNo] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,

 

[DateOfJourney] [datetime] NOT NULL ,

 

 

[ClassOfRes] [char] (10) COLLATE SQL Latin1 General_CP1_CI_AS NOT NULL ,

 

[Name] [char] (20) COLLATE SQL Latin1 General CP1_CI_AS NOT NULL ,

 

[EMail] [char] (50)

COLLATE

SQL atin1 General CP1_CI_AS NULL ,

 

[Fare] [int] NOT NULL ,

 

 

Y

 

 

L

 

[Status] [int] NOT NULL ,

 

F

 

 

 

 

 

 

[ReservedBy] [char] (15) COLL TE SQL Latin1_General_CP1_CI_AS NOT NULL ,

 

[DateOfRes] [datetime] NOT NULL ,

 

 

 

 

 

M

 

 

[TicketConfirmed] [bit] NULL

 

 

) ON [PRIMARY]

 

A

 

GO

 

E

 

 

 

 

 

 

 

 

T

 

 

 

dtFltStatus Table

The dtFltStatus table stores the latest ticket availability status. The data in this table is updated in tandem with any new record added to the dtReservations or dtCancellations table. The script that generates the dtFltStatus table is given as follows:

CREATE TABLE [dbo].[dtFltStatus] (

[FltNo] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [StatusDate] [datetime] NOT NULL ,

[StatusClass] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [Status] [int] NOT NULL

) ON [PRIMARY] GO

Team-Fly®

DESIGNING THE APPLICATION

Chapter 20

459

 

 

 

 

Creating the dtCancellations Table

All cancellations made in the dtReservations table are recorded in the dtCancellations table.The query for creating the dtCancellations table is given as follows:

CREATE TABLE [dbo].[dtCancellations] (

[TicketNo] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [Refund] [int] NOT NULL ,

[ProcessedBy] [char] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [CancellationDate] [datetime] NOT NULL

) ON [PRIMARY] GO

Creating the dtDepartedFlights Table

The dtDepartedFlights table is similar to the dtReservations table. After flight departure, data pertaining to the flight is moved from the dtReservations table to the dtDepartedFlights table. The script that generates the dtDepartedFlights table is given as follows:

CREATE TABLE [dbo].[dtDepartedFlights] (

[TicketNo] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [FltNo] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [DateOfJourney] [datetime] NOT NULL ,

[ClassOfRes] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [Name] [char] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [EMail] [char] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,

[Fare] [int] NOT NULL , [Status] [int] NOT NULL ,

[ReservedBy] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [DateOfRes] [datetime] NOT NULL ,

[TicketConfirmed] [bit] NULL ) ON [PRIMARY]

GO

460 Project 4 CREATING AN AIRLINE RESERVATION PORTAL

Creating the dtPassengerDetails Table

The dtPassengerDetails table is used for storing data pertaining to passengers who have a valid e-mail address.The table is used to make discounts available for the frequent fliers program. To create the dtPassengerDetails table, execute the following script:

CREATE TABLE [dbo].[dtPassengerDetails] (

[EMail] [char] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [FareCollected] [int] NOT NULL ,

[TotalTimesFlown] [int] NOT NULL ) ON [PRIMARY]

GO

Creating the dtFrequentFliers Table

The dtFrequentFliers table is used to store a list of passengers eligible for the frequent fliers program. The list is retrieved from the dtPassengerDetails table on the basis of a query specified by business managers. To create the dtFrequentFliers table, run the following script:

CREATE TABLE [dbo].[dtFrequentFliers] (

[EMail] [char] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [Discount] [int] NOT NULL

) ON [PRIMARY] GO

Now that you have created all the tables, the next step is to set primary keys and specify relationships between tables. You do that in the next section.

Managing Primary Keys and Relationships

Primary keys are used to ensure that the records in a table are unique. The primary keys for all database tables are listed in Table 20-1.

DESIGNING THE APPLICATION

Chapter 20

461

 

 

 

 

Table 20-1 Primary Key Fields in Tables

Table Name

Primary Key Field

dtUsers

Username

dtFltDetails

FltNo

dtReservations

TicketNo

dtCancellations

TicketNo

dtDepartedFlights

TicketNo

dtPassengerDetails

EMail

dtFrequentFliers

EMail

 

 

To specify primary keys for tables, run the following script:

ALTER TABLE [dbo].[dtCancellations] WITH NOCHECK ADD

CONSTRAINT [PK_dtCancellation] PRIMARY KEY CLUSTERED

(

[TicketNo] ) ON [PRIMARY]

GO

ALTER TABLE [dbo].[dtDepartedFlights] WITH NOCHECK ADD

CONSTRAINT [PK_dtDepartedFlights] PRIMARY KEY CLUSTERED

(

[TicketNo] ) ON [PRIMARY]

GO

ALTER TABLE [dbo].[dtFltDetails] WITH NOCHECK ADD

CONSTRAINT [PK_dtFltDetails] PRIMARY KEY CLUSTERED

(

[FltNo]

) ON [PRIMARY]

GO

ALTER TABLE [dbo].[dtFrequentFliers] WITH NOCHECK ADD

CONSTRAINT [PK_dtFrequentFlier] PRIMARY KEY CLUSTERED

(

[EMail]

) ON [PRIMARY]

GO

462 Project 4 CREATING AN AIRLINE RESERVATION PORTAL

ALTER TABLE [dbo].[dtPassengerDetails] WITH NOCHECK ADD

CONSTRAINT [PK_dtAllCustomers] PRIMARY KEY CLUSTERED

(

[EMail]

) ON [PRIMARY]

GO

ALTER TABLE [dbo].[dtReservations] WITH NOCHECK ADD

CONSTRAINT [PK_dtReservations] PRIMARY KEY CLUSTERED

(

[TicketNo] ) ON [PRIMARY]

GO

ALTER TABLE [dbo].[dtUsers] WITH NOCHECK ADD

CONSTRAINT [PK_dtUsers] PRIMARY KEY CLUSTERED

(

[Username] ) ON [PRIMARY]

GO

After creating the tables and setting the primary keys, you need to create relationships between tables. Relationships between tables are discussed in Table 18-8 of Chapter 18. To create relationships between tables, run the following code:

ALTER TABLE [dbo].[dtCancellations] ADD

CONSTRAINT [FK_dtCancellation_dtUsers] FOREIGN KEY

(

[ProcessedBy]

) REFERENCES [dbo].[dtUsers] ( [Username]

)

GO

ALTER TABLE [dbo].[dtDepartedFlights] ADD

CONSTRAINT [FK_dtDepartedFlights_dtPassengerDetails] FOREIGN KEY

(

[EMail]

) REFERENCES [dbo].[dtPassengerDetails] ( [EMail]

) NOT FOR REPLICATION

DESIGNING THE APPLICATION

Chapter 20

463

 

 

 

 

GO

ALTER TABLE [dbo].[dtDepartedFlights] nocheck constraint [FK_dtDepartedFlights_dtPassengerDetails]

GO

ALTER TABLE [dbo].[dtFltStatus] ADD

CONSTRAINT [FK_dtFlightStatus_dtFltDetails] FOREIGN KEY

(

[FltNo]

) REFERENCES [dbo].[dtFltDetails] ( [FltNo]

)

GO

ALTER TABLE [dbo].[dtFrequentFliers] ADD

CONSTRAINT [FK_dtFrequentFlier_dtAllCustomers] FOREIGN KEY

(

[EMail]

) REFERENCES [dbo].[dtPassengerDetails] ( [EMail]

)

GO

ALTER TABLE [dbo].[dtReservations] ADD

CONSTRAINT [FK_dtReservations_dtFltDetails] FOREIGN KEY

(

[FltNo]

) REFERENCES [dbo].[dtFltDetails] ( [FltNo]

),

CONSTRAINT [FK_dtReservations_dtUsers] FOREIGN KEY

(

[ReservedBy]

) REFERENCES [dbo].[dtUsers] ( [Username]

)

GO

464 Project 4 CREATING AN AIRLINE RESERVATION PORTAL

Viewing the Database Schema

After you run all the preceding scripts, the database schema is ready. You can view the structure of database tables and their relationships in Enterprise Manager. To view the database schema, follow these steps:

1.Open SQL Ser ver Enterprise Manager.

2.Navigate to the SkyShark database.

3.Right-click on Diagrams in SkyShark and select New Database Diagram.The Create Database Diagram Wizard will appear.

4.In the Welcome screen of the wizard, click on Next. The Select Tables to be Added screen of the wizard will appear. This screen is shown in Figure 20-3.

5.Select all database tables that you created in the previous section and click on Next. The Completing the Create Database Diagram Wizard screen of the wizard will appear.

6.Click Finish to complete the wizard.

After you complete the task by using the wizard, the database schema appears.

FIGURE 20-3 The Select Tables to be Added screen

DESIGNING THE APPLICATION

Chapter 20

465

 

 

 

 

Designing Application Forms

The application provides different forms for users in different roles. For example, business managers are provided with four forms: AddFl.aspx, RequestID.aspx, Reports.aspx, and FreqFl.aspx. All forms pertaining to different roles were discussed in Chapter 18.

In this section, I explain the controls that you need to add to each Web form and the properties of Web forms that you need to configure. After this section, all Web forms for the application will be ready.

Standardizing the Interface of the Application

All Web forms for the SkyShark Airlines application have a standard interface, which is derived by adding a banner to a header.htm file and including the file on each Web page. Next, I have added a menu bar, which resembles a tab control, on top of each Web form. To do this, I created four similar images with different tabs selected and showing the images at the same position on each Web form. A collage of these images is shown in Figure 20-4.

FIGURE 20-4 Creating a menu bar for the application

Now, when a user selects different screens, distinct images are displayed but give the impression that the same screen contains several tabs.

Common Forms in the Application

There are a number of common forms used by employees at all positions in SkyShark Airlines. In this section, I will explain the design of these forms.

466 Project 4 CREATING AN AIRLINE RESERVATION PORTAL

Default.aspx

The default.aspx form is the first form displayed when a user visits a Web site. The default.aspx form is the logon form for the Web application. When users visit the Web application, they need to log on by specifying their logon credentials in the default.aspx form. Subsequently, depending upon the position of the user, the user is redirected to other forms of the Web application.

You can change the form WebForm1.aspx, added to the Web application by default, to make the form the default.aspx page. To do so, follow these steps:

1.Right-click on WebForm1.aspx in Solution Explorer and select Rename.

2.Type the name of the form as default.aspx.

3.Double-click on default.aspx to open the code-behind file in the Code Editor window.

4.Change the name of the class to WebLogonForm.

5.Return to the design view of the default.aspx form.

6.In the design view of the form, in the @ Page directive in the first line, change the name of the class to WebLogonForm. The new @ Page directive is given as follows:

<%@ Page language=”c#” Codebehind=”default.aspx.cs” AutoEventWireup=”false”

Inherits=”SkyShark.WebLogonForm” %>

NOTE

By performing these steps, you have changed the name and the default class associated with the Web form.These steps need to be carried out for all Web forms that you will add to the project. However, I will not repeat these steps separately for each Web form.

To design the default.aspx form, add controls to it and change their properties as shown in Table 20-2.

 

DESIGNING THE APPLICATION

Chapter 20

467

Table 20-2 Controls in the Default.aspx Form

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Control Type

ID

Properties Changed

 

 

 

 

 

 

 

 

 

 

 

TextBox

txtUserName

None

 

 

 

 

TextBox

txtPassword

TextMode=Password

 

 

 

 

Button

btnSubmit

Text=Submit

 

 

 

 

Label

lblMessage

ForeColor=Red

 

 

 

 

 

 

Text=""

 

 

 

 

 

 

Font:Bold=True

 

 

 

 

RequiredFieldValidator

RequiredFieldValidator

ControlToValidate=txtUserName

 

 

 

ErrorMessage=Please specify a valid

 

 

 

user name.

 

 

 

 

RequiredFieldValidator

RequiredFieldValidator2

ControlToValidate=txtPassword

 

 

 

ErrorMessage=Please specify a valid

 

 

 

password.

 

 

 

 

 

 

 

 

 

 

 

In the preceding table, I have not included the details of the User Name and Password labels. You need to add these controls to the form as well. The completed default.aspx form is shown in Figure 20-5.

FIGURE 20-5 The default.aspx page