Problem of session state not being preserved
I'm developing a project in ASP.Net (C#). My project definition is Online Travels Booking System.
In my project there is a seating selection module. When I select a particular seat for a particular route u开发者_运维问答sing a check box, I create a session for the selected seat so that if I ever choose the same route, the selected seats should not be displayed.
The problem I am facing is when I select a different route, I get a selected seat which I hadn't selected previously.
You need to bind the seat occupancy to each route - you can use or define a special data-type-structure to hold this info. You can create your own struct or array which holds the information of each seat occupied by each route. You can store this data-structure into a session and use it as and when you need it. You will need to update the data-structure in session whenever a new seat is occupied or a pre-occupied seat is released.
You can also use the database to store the information which I guess would be a better option.
A dictionary might work well for your application
http://msdn.microsoft.com/en-us/library/xfhwa508.aspx
In psuedocode:
// Read the selected seats and store them
OnCheckChanged( ... )
{
Dictionary<Route,Seat> reservedSeats = Session["reservedSeats"] as Dictionary<Route,Seat>;
reservedSeats[Current Route] = Selected Seat;
Session["reservedSeats"] = reservedSeats;
}
// Show the selected seats when they come to a specific route
OnLoad(...)
{
Dictionary<Route,Seat> reservedSeats = Session["reservedSeats"] as Dictionary<Route,Seat>;
SetSeatSelection( reservedSeats[Current Route] );
}
Basically, you can store a dictionary object in the session with one entry for each route. Each session is particular to a specific user so this should suffice.
Although, you may want to just store it in a database if you want the selection to be remembered between visits etc.
精彩评论