Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 10-May-12 22:45pm
Edited 10-May-12 23:50pm
v4
Rate this: bad
good
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.
  Permalink  
Rate this: bad
good
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 ....show the users only the rooms which are free ...
  Permalink  
Comments
Pete O'Hanlon at 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.
Mika Wendelius at 11-May-12 18:03pm
   
I agree
dharan1990 at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 255
1 CHill60 240
2 Peter Leow 170
3 Richard MacCutchan 169
4 Zoltán Zörgő 150
0 Sergey Alexandrovich Kryukov 9,238
1 OriginalGriff 6,806
2 Peter Leow 4,432
3 Zoltán Zörgő 3,919
4 Richard MacCutchan 2,782


Advertise | Privacy | Mobile
Web02 | 2.8.150128.1 | Last Updated 11 May 2012
Copyright © CodeProject, 1999-2015
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