Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Microsoft C# Professional Projects - Premier Press.pdf
Скачиваний:
177
Добавлен:
24.05.2014
Размер:
14.65 Mб
Скачать

514 Project 4 CREATING AN AIRLINE RESERVATION PORTAL

lstClass.SelectedIndex=0; Cal1.SelectedDate=DateTime.Today; txtTNo.Text=””;

txtFare.Text=””; txtStatus.Text=””; txtOrg.Text=””; txtDest.Text=””; txtDepTime.Text=””; txtName.Text=””; txtEMail.Text=””; txtFltNo.Enabled=true; lstClass.Enabled=true; Cal1.Enabled=true;

Response.Redirect(“Ticket.aspx?TNo=” + TicketNo);

}

catch (Exception ex)

{

lblMessage.Text=ex.Message; sqlConnection1.Close(); txtFltNo.Enabled=true; lstClass.Enabled=true; Cal1.Enabled=true;

}

}

The CancelRes.aspx Form

The CancelRes.aspx form is used to perform cancellation of reservations. When a ticket is cancelled, the status of the flight needs to be updated in the dtFltStatus table. You also need to update the status of the passengers on the flight who are in the waiting list. In addition, you also need to compute the refund amount that is applicable to the passenger.

To perform cancellations, I have used a combination of stored procedures and programming logic. The steps to cancel a reservation are given as follows:

1.Retrieve the fare that the passenger had paid.

2.Compute the refund applicable to the customer, depending upon whether or not the flight has departed.

IMPLEMENTING THE BUSINESS LOGIC

Chapter 21

515

 

 

 

 

3.Update status of other passengers who might have been confirmed because of the cancellation of ticket.

4.Create a record in the dtCancellations table and delete the reservation of the passenger from the dtReservations table.

The first two tasks are performed by programming logic, the code for which is given as follows:

lblMessage.Text=””; dataSet51.Clear(); sqlConnection1.Open();

sqlDataAdapter1.SelectCommand.Parameters[0].Value=txtTNo.Text.Trim(); sqlDataAdapter1.Fill(dataSet51, “TicketDetails”); sqlConnection1.Close();

if (dataSet51.Tables[“TicketDetails”].Rows.Count==0)

{

lblMessage.Text=”Invalid ticket number”; return;

}

else

{

string ticketno, user, cancdate, journeydate; int refund, fare; ticketno=txtTNo.Text.Trim();

journeydate=dataSet51.Tables[“TicketDetails”].Rows[0][2].ToString(); fare=Convert.ToInt32(dataSet51.Tables[“TicketDetails”]. Rows[0][6].ToString()); if (Convert.ToDateTime(journeydate)<=DateTime.Today)

{

refund=fare-10;

}

else

{

refund=Convert.ToInt32(fare*0.8);

}

After the refund amount has been calculated, the details of the ticket that needs to be cancelled are passed to a stored procedure that updates the status of other customers booked on the flight and also deletes the customer record from the

516 Project 4 CREATING AN AIRLINE RESERVATION PORTAL

dtReservations database. The code for the DeleteReservations stored procedure, which accomplishes these tasks, is given as follows:

CREATE PROCEDURE DeleteReservations

@ticketno char(10), @user char(15), @cancdate datetime, @refund int AS

Declare @fltno char(10)

Declare @date datetime

Declare @class char(10)

Declare @status int

select @fltno=FltNo, @date=DateOfJourney, @class=ClassOfRes , @status=Status from dtReservations where TicketNo=@ticketno

Update dtReservations

set Status=Status+1 where FltNo=@fltno and DateOfJourney=@date and ClassOfRes=@class and Status<@status

Update dtFltStatus

set Status=Status+1 where FltNo=@fltno and StatusDate=@date and StatusClass=@class

INSERT into dtCancellations

values (@ticketno, @refund, @user, @cancdate) Delete dtReservations where TicketNo=@ticketno GO

The QueryStat.aspx Form

The QueryStat.aspx page is used for querying the status of flights and tickets. LOB executives can either use the flight number to query the status of a flight or use the ticket number to query the status of a ticket. In both the cases, an error message is displayed if the number specified is invalid. Otherwise, the status of the flight or ticket is retrieved and displayed to the user.

The following code is used for querying the status of a flight:

private void Button2_Click(object sender, System.EventArgs e)

{

dataSet41.Clear(); lblMessage.Text=””; lblStatus.Text=””;

if (txtFltNo.Text==”” || txtFltNo.Text==null)

IMPLEMENTING THE BUSINESS LOGIC

Chapter 21

517

 

 

 

 

{

lblMessage.Text=”Invalid flight number”; return;

}

else

{

sqlConnection1.Open(); sqlDataAdapter1.SelectCommand.Parameters[0].Value=txtFltNo.Text.Trim(); sqlDataAdapter1.SelectCommand.Parameters[1].Value=Cal1. SelectedDate

.ToShortDateString(); sqlDataAdapter1.SelectCommand.Parameters[2].Value= lstClass.SelectedItem

.Text;

sqlDataAdapter1.Fill(dataSet41, “FltStatus”); sqlConnection1.Close();

if (dataSet41.Tables[“FltStatus”].Rows.Count==0)

{

lblStatus.Text=”Status: Available”;

}

else

{

string strStatus; int status;

strStatus=dataSet41.Tables[“FltStatus”].Rows[0][0].ToString(); status=Convert.ToInt32(strStatus);

if (status >= 0)

{

lblStatus.Text=”Status: Available”;

}

else

{

lblStatus.Text=”Status: Overbooked (“ + strStatus + “)”;

}

}

}

}