1

I am doing Airline Reservation System using GUI with ASP.NET in C#. What I want is assign seats for user, after a user assign that seats, that seat cannot be assigned by others again. I try to use increment do this but instead of 1+1 = 2(that means seat number 2 is the next to be assigned), the system gives me 1+1=11. How can I do what I want?

I have 5 interfaces for this, and I need this assigned value stored in whole running process. This is my code for the reservation button, I have 2 for it, First Class and Economy Class. Only 5 seats for First Class and 15 seats for Economy Class. How can I do ?

 protected void Button1_Click(object sender, EventArgs e) { Session["seats"] = "First Class"; if (firstseatnum > 5) { MessageBox.Show("Sorry, the first class seats was fully booked. Can you change to economy class?"); Response.Redirect("reservation.aspx"); } else { ++firstseatnum; totalseatnum1 = Convert.ToInt32(firstseatnum+seatnum); Response.Redirect("~/information.aspx?firstseatnum="+firstseatnum+"&seatnum="+totalseatnum1); } } protected void Button2_Click(object sender, EventArgs e) { Session["seats"] = "Economy Class"; if (economyseatnum > 20) { MessageBox.Show("Sorry, the economy class seats was fully booked. Can you change to first class?"); Response.Redirect("reservation.aspx"); } else { ++economyseatnum; totalseatnum2 = Convert.ToInt32(economyseatnum + seatnum); Response.Redirect("information.aspx?economyseatnum=" + economyseatnum + "&seatnum="+totalseatnum2); } } 

Please help me, thank you.

2 Answers 2

3

There are several ways to do it:

Query

// Set var myVariable = "MyData"; Response.Redirect("/NextPage?MyVariable=" + myVariable); // Get var data = Request.QueryString["MyVariable"]; 

Cookie

// Set var cookie = new HttpCookie("MyVariable"); cookie.Value = "NyData"; Response.Cookies.Add(cookie); Response.Redirect("/NextPage"); // Get var data = Request.Cookies["MyVariable"].Value; 

Session

// Set Session["MyVariable"] = "MyData"; Response.Redirect("/NextPage"); // Get var data = Session["MyVariable"]; 

Application (Store Entire Process)

// Set Application["MyVariable"] = "MyData"; Response.Redirect("/NextPage"); // Get var data = Application["MyVariable"]; 

Also check CodeProject article to see more examples and detailed explanation.

Sign up to request clarification or add additional context in comments.

4 Comments

We have not yet learn anything like this in the class I think, may I know how to achieve it with Session ? I have used that in my code to pass some values. Thank you.
@SilverArcher I'm adding code snippets, wait for it :)
Yes I have used Session method before, after first user input, the seat number 1 should be assigned so the second user should be assigned in seat number 2. But it gives me seat number 1 again.
@SilverArcher Store in Application then? It's global (process) storage.
1

Presumably seatnum is a string.

If so, try

totalseatnum1 = firstseatnum + Convert.ToInt32(seatnum); 

and

totalseatnum2 = economyseatnum + Convert.ToInt32(seatnum); 

6 Comments

when i run to that page, error message: An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code Additional information: Input string was not in a correct format.
If it possible that seatnum is null or empty to begin with?
If so, try totalseatnum1 = firstseatnum + (!string.IsNullOrWhiteSpace(seatnum) ? Convert.ToInt32(seatnum) : 0)
i didn't initialize seatnum, okay i will try this! Thank you!
It worked thank you !!!! But now I have another problem, because the first class cannot be exceed 5 seats, so I have to set if (seatnum > 5) then pop up message box. However, the seatnum is string, how can I do this ?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.