Click here to Skip to main content
13,004,397 members (76,356 online)
Rate this:
Please Sign up or sign in to vote.

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.

Posted 10-May-12 21:45pm
Updated 10-May-12 22:50pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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 the users only the rooms which are free ...
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.
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?
Mika Wendelius 11-May-12 18:03pm
I agree

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170627.1 | Last Updated 11 May 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100