Click here to Skip to main content
15,886,798 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello

I am developing a web form in which users can book rooms and I want to prevent another booking taking place on the same date. How would I prevent someone else from booking a room that has already been booked.

as a example i am booking a room for 10 may to 12 may then i want that any user can not book that room for 10 may to 12 may or any date upto 12 may becouse it is already booked for 10 to 12.
and i have to text boxes in which start date and and end date are being entered i want to put a check here.

Please provide logic or code in JavaScript, SQL or C# coding.

Thanks
Posted
Updated 10-May-12 22:50pm
v4

There are really a couple of parts to your question. The first part is how to prevent the user from choosing a room that has already been booked when they open up the page to choose the rooms they can book. If you know that a room has been booked, at this point, you would aim to let the user know that they can't book it by visually indicating that the room has been booked; perhaps by changing colours for that period. But you would also disable the buttons to save the booking if the user chooses that date.

The second part to your question is slightly more subtle, but is one that is often overlooked by people who forget that they are designing a multi-user system. What you are trying to prevent here is the user selecting a room that has been booked after the page has opened, or is being booked at the same time as they attempt to book that room. There's a simple trick to this - in your insert statement, use the date as part of the an insert test. You do this by using the ability to INSERT based off a selection, and you test to see if the room has been booked for that date (the big hint here is that this is your select criteria). If you can't insert the record, then you know the room has been booked.
 
Share this answer
 
u would have created the table room !!!...insert the column status and keep the default value as false ...when an user books it change the value to true ....with this u can check and prevent the already booked room ....show the users only the rooms which are free ...
 
Share this answer
 
Comments
Pete O'Hanlon 11-May-12 5:44am    
You have missed out a lot of steps here. What happens if the room is booked between the time the user looks at the rooms, and the time they select the room? It's always worth considering how a system should behave if there are multiple users attempting to perform the same operation at the same time.
Wendelius 11-May-12 18:03pm    
I agree
dharan1990 11-May-12 6:51am    
how to overcome that can u help me should we use lock and monitor concepts r some thing else?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900