DB rooms booking
|
|
Thread rating:  |
Paolo Galli - 25 Jun 2008 10:48 GMT Hi all I'm working on a rooms reservation system based on Access 2003 and then realize an ASP web page to manage it.
I need a little help in creating the DB since my ideas aren't so clear.
First of all what I need is very simple:
- I have two rooms and I have to let user reserve time slot of 15 minutes each - every day has 8 slot - a user can't book more than 1 slot per day
I thought to realize a DB with this structure
- 1 table with ID,DATE,ID-CUSTOMER - 1 table with ID,NAME,SURNAME,PHONE,ID-SLOT - 1 table with ID,SLOT
then I connect the first table with the second, and the second with the third...
but I'm not sure... am I in the right direction?
anyone can help me? thanks
McKirahan - 25 Jun 2008 13:54 GMT > Hi all > I'm working on a rooms reservation system based on Access 2003 and then [quoted text clipped - 19 lines] > > but I'm not sure... am I in the right direction? How about:
Customer table = CUST_ID,NAME,SURNAME,PHONE Reservation table = ROOM_ID,DATE,SLOT1,SLOT2, ... ,SLOT8
A SLOT# will contain a CUST_ID
Then you may want (though the values could be hardcoded):
Room table = ROOM_ID,DESCRIPTION,LOCATION,PHONE Slot table = SLOT_ID,START_TIME,DURATION
Not fully normalized but very easy to program and use: KISS.
Paolo Galli - 25 Jun 2008 14:28 GMT Uhm not sure... your solution has the limit that updating just a slot open also all the slots
I need a single record for the user reserving the slot
thx
>> Hi all >> I'm working on a rooms reservation system based on Access 2003 and then [quoted text clipped - 33 lines] > > Not fully normalized but very easy to program and use: KISS. McKirahan - 25 Jun 2008 15:43 GMT >>> - 1 table with ID,DATE,ID-CUSTOMER >>> - 1 table with ID,NAME,SURNAME,PHONE,ID-SLOT >>> - 1 table with ID,SLOT > > Uhm not sure... your solution has the limit that updating just a slot > open also all the slots Why is that an issue?
> I need a single record for the user reserving the slot Why do you "need a single record for the user ..."?
Anyway, how about:
Customer table = CUST_ID,NAME,SURNAME,PHONE Room table = ROOM_ID,DESCRIPTION,LOCATION,PHONE Slot table = SLOT_ID,START_TIME,DURATION Reservation table = ROOM_ID,DATE,SLOT_ID,CUST_ID
Paolo Galli - 25 Jun 2008 15:50 GMT Thanks... in effect I didn't focus my mind on your first advice and effectively is simpler to manage...
Paolo
> Anyway, how about: > > Customer table = CUST_ID,NAME,SURNAME,PHONE > Room table = ROOM_ID,DESCRIPTION,LOCATION,PHONE > Slot table = SLOT_ID,START_TIME,DURATION > Reservation table = ROOM_ID,DATE,SLOT_ID,CUST_ID McKirahan - 25 Jun 2008 16:11 GMT > Thanks... in effect I didn't focus my mind on your first advice and > effectively is simpler to manage... [quoted text clipped - 7 lines] > > Slot table = SLOT_ID,START_TIME,DURATION > > Reservation table = ROOM_ID,DATE,SLOT_ID,CUST_ID My thinking was that with this: Reservation table = ROOM_ID,DATE,SLOT1,SLOT2, ... ,SLOT8 then you'd be able to see all reservations by just listing the table.
With small projects I am more concerned about what I want out of the database rather than the "right" way to store the data.
Paolo Galli - 25 Jun 2008 16:22 GMT You're right, my only concern is that I don't have a customer DB
The DB will be filled when a user insert a resevation I don't want to have to manage subscription and loggin in
So the slot will link to the customer_id that will reserve that slot, even if he has already booked a slot in the past
does it work anyway in this way?
> My thinking was that with this: > Reservation table = ROOM_ID,DATE,SLOT1,SLOT2, ... ,SLOT8 > then you'd be able to see all reservations by just listing the table. > > With small projects I am more concerned about what I want out > of the database rather than the "right" way to store the data. McKirahan - 25 Jun 2008 16:51 GMT > You're right, my only concern is that I don't have a customer DB How do you identify a customer? Do they just enter their name?
If so, could I register one time slot for "Doug" and another one for "Douglas" for the same room and date even if I'm not supposed to? (Per the "- a user can't book more than 1 slot per day" requirement.)
> The DB will be filled when a user insert a resevation > I don't want to have to manage subscription and loggin in [quoted text clipped - 3 lines] > > does it work anyway in this way? I'm not sure what you're asking.
Paolo Galli - 25 Jun 2008 18:00 GMT this DB is aimed to a little business environment
customers are employees and I'm not expecting them insert false names...
I know that the best should be a more secure solution but what I need is a very simple and quick application to book - twice a week - 8 slot of 15 minutes for meeting
thanks
>> You're right, my only concern is that I don't have a customer DB > [quoted text clipped - 13 lines] > > I'm not sure what you're asking. McKirahan - 26 Jun 2008 00:33 GMT > this DB is aimed to a little business environment > [quoted text clipped - 3 lines] > a very simple and quick application to book - twice a week - 8 slot of > 15 minutes for meeting This is not what you want -- it doesn't use a database.
This simple page allows the entry (but not deletion) of 8 slots for each weekday (Monday thru Friday) for any week. The current week is displayed and the user can go forward or backward one week at a time. A name of up to 12 characters can be entered for any (time) slot. The slot names can be changed to "times"; that is, "Slot 1" might be changed to "8:00 - 8:15", etc. The data is stored in a text file which does not have to exist. Watch for word-wrap -- there are 236 lines. To test, save it as "slots.asp" on your Web server then visit its URL.
<%@ Language="VBScript" %> <% Option Explicit '**** '* Display and maintain a weekly matrix of reservation time slots. '**** '* '* Declare Constants '* Const cASP = "slots.asp" Const cTXT = "slots.txt" Const cDAZ = "Sun,Mon,Tue,Wed,Thu,Fri,Sat" Const cCHR = "^" Const cMAX = 8 '* '* Declare Globals '* Dim i, j, k Dim iDAY iDAY = Weekday(Date) Dim sRQS sRQS = Request.QueryString() Dim aSTR() ReDim aSTR(100) Dim iSTR iSTR = 0 Dim sSTR '* '* Declare Variables '* Dim arrDAT(5) arrDAT(0) = Date If IsDate(sRQS) Then arrDAT(0) = sRQS iDAY = Weekday(sRQS) End If If iDAY > vbSunday Then arrDAT(0) = DateAdd("d",-iDAY+1,arrDAT(0)) End If For i = 1 To UBound(arrDAT) arrDAT(i) = DateAdd("d",1,arrDAT(i-1)) Next Dim arrDAZ arrDAZ = Split(cDAZ,",") Dim arrWHO() ReDim arrWHO(5,cMAX) '* '* Declare Objects '* Dim objDIC Set objDIC = CreateObject("Scripting.Dictionary") '* '* Processing '* If Request.Form("Put") = "True" Then Slots("Get") Slots("Put") End If objDIC.RemoveAll Slots("Get") Call Table()
Sub Append(sSTR) '**** '* Appends strings to array entries ReDim as needed; (see "Concat()"). '**** sSTR = sSTR & "" If iSTR > UBound(aSTR) Then ReDim Preserve aSTR(UBound(aSTR) + 100) aSTR(iSTR) = sSTR & vbCrLf iSTR = iSTR + 1 End Sub
Function Concat() '**** '* Concatenates array entries into a single string; (see "Append()"). '**** Redim Preserve aSTR(iSTR) Concat = Replace(Join(aSTR,""),"`",Chr(34)) Erase aSTR ReDim aSTR(100) iSTR = 0 End Function
Sub Slots(Action) '**** '* Display and maintain reservation time slots. '**** '* '* Declare Variables '* Dim arrDAY Dim strDIC Dim strDIK Dim arrOTF Dim strOTF Dim arrPUT ReDim arrPUT(8) Dim strPUT '* '* Declare Objects '* Dim objFSO Set objFSO = CreateObject("Scripting.FileSystemObject") Dim objOTF '* '* Action? '* If Action = "Get" Then '* '* Read file '* If objFSO.FileExists(Server.MapPath(cTXT)) Then Set objOTF = objFSO.OpenTextFile(Server.MapPath(cTXT),1) If Not objOTF.AtEndOfStream Then strOTF = objOTF.ReadAll End If Set objOTF = Nothing End If '* '* Build dictionary and array '* arrOTF = Split(strOTF,vbCrLf) For k = 0 To UBound(arrOTF) If arrOTF(k) = "" Then Exit For arrDAY = Split(arrOTF(k),cCHR) strDIC = "_" & CStr(arrDAY(0)) objDIC.Add strDIC, arrOTF(k) '* For i = 1 To UBound(arrWHO,1) If CDate(arrDAY(0)) = CDate(arrDAT(i)) Then For j = 1 To UBound(arrWHO,2) arrWHO(i,j) = arrDAY(j) Next End If Next Next ElseIf Action = "Put" Then '* '* Build/update dictionary '* For i = 1 To UBound(arrWHO,1) arrPUT(0) = Request.Form("WHO_" & i) strDIC = "_" & CStr(arrPUT(0)) For j = 1 To UBound(arrWHO,2) arrPUT(j) = Request.Form("WHO_" & i & "_" & j) Next strPUT = Join(arrPUT,cCHR) If Not objDIC.Exists(strDIC) Then objDIC.Add strDIC, strPUT Else objDIC.Item(strDIC) = strPUT End If Next '* '* Write file from dictionary '* Set objOTF = objFSO.OpenTextFile(Server.MapPath(cTXT),2,True) For Each strDIC in objDIC strDIK = objDIC.Item(strDIC) If strDIK <> String(8,cCHR) Then objOTF.WriteLine(strDIK) End If Next Set objOTF = Nothing End If '* '* Destroy Objects '* Set objFSO = Nothing End Sub
Sub Table() '**** '* Generate HTML table. '**** Append "<table align=`center` border=`0` width=`95%` class=`bord`>" Append "<tr>" Append " <th>" Append " <a href=`" & cASP & "?" & DateAdd("d",-7,arrDAT(0)) & "` title=`Last Week`><<</a>" Append " " Append " <a href=`" & cASP & "` title=`This Week`>Date</a>" Append " " Append " <a href=`" & cASP & "?" & DateAdd("d",+7,arrDAT(0)) & "` title=`Next Week`>>></a>" Append " <hr>" Append " </th>" For i = 1 To cMAX Append " <th>Slot " & i & "<hr></th>" Next Append "</tr>" For i = 1 To 5 Append "<tr height=`30`>" Append " <th>" Append " " & arrDAZ(i) & " -- " & arrDAT(i) Append " <input type=`hidden` name=`WHO_" & i & "` value=`" & arrDAT(i) & "`>" Append " </th>" For j = 1 To cMAX Append " <td>" If arrWHO(i,j) = "" Then Append " <input type=`text` name=`WHO_" & i & "_" & j & "` size=`12` maxlength=`12` class=`line`>" Else Append " <input type=`hidden` name=`WHO_" & i & "_" & j & "` value=`" & arrWHO(i,j) & "`>" Append " <b>" & arrWHO(i,j) & "</b>" End If Append " </td>" Next Append "</tr>" Next Append "</table>" End Sub %> <html> <head> <title>rooms.htm</title> <style type="text/css"> a { color:blue; text-decoration:none } body,td, th { font-family:Arial; font-size:9pt } .bord { border:solid 1px black } .butt { background:white; width:100px } .line { border:solid 1px white; border-bottom:solid 1px black } </style> </head> <body> <form action="<%=cASP%>" method="post"> <input type="hidden" name="Put" value="True"> <%=Concat()%> <br> <input type="submit" class="butt" value="Save"> <input type="button" class="butt" value="Reload" onclick="location.href='<%=cASP%>';"> <sup> "Save" changes before changing weeks via the <a>blue</a> controls. This facility does not yet support the removal of a slot's entry. </sup> </form> </body> </html>
Paolo Galli - 26 Jun 2008 07:16 GMT thanks a lot for your kindly support
Now it's time to have my hands dirty ;)
Paolo
>> this DB is aimed to a little business environment >> [quoted text clipped - 257 lines] > </body> > </html> Old Pedant - 26 Jun 2008 06:15 GMT Another easy approach to this:
Table: Slots slotDate : dateTime slotNumber : int (1 through 8) employeeID : int or whatever you use for employeeIDs
Then you PRE-FILL the ENTIRE Slots table ahead of time for a range of dates. Example: 6/23/2008 1 0 6/23/2008 2 0 6/23/2008 3 0 6/23/2008 4 0 6/23/2008 5 0 6/23/2008 6 0 6/23/2008 7 0 6/23/2008 8 0 6/23/2008 1 0 ... 8/31/2008 8 0
Okay, so now the employee comes in and you have a simple form: <FORM> <INPUT Name="employeeID"> <INPUT Name="slotdate"> </FORM>
And you use that info to make a query against the table: <% SQL = "SELECT slot FROM slots " _ & " WHERE slotDate = #" & Request("slotDate") & "# " _ & " AND slotNumber = 0 " _ & " ORDER BY slotNumber" Set RS = conn.Execute(SQL) If RS.EOF Then Response.Write "All slots on that date taken. Try another date." Response.End End IF
rows = RS.GetRows( ) empid = CInt( Request("employeeid")) okay = True
For row = 0 To UBound(rows) If rows(0,row) = empid Then okay = False Next If Not okay Then Response.Write "You have already reserved a slot on that date!" Response.End End If %> <form> <input type=Hidden name="employeeid" value="<%=empid%>" > <input type=Hidden name="slotdate" value="<%=Request("slotdate")%>"> <% For row = 0 To UBound(rows) slotnum = rows(0,row) %> <INPUT Type=Radio Name="slotNum" Value="<%=slotNum%>"> Reserve Slot #<%=slotNum%><br/> <% Next %> <input type=submit> </form>
***********
And now, when the user selects a slot and hits submit, the third page simply does
<% SQL = "UPDATE slots SET employeeID = " & Request("employeeid") _ & " WHERE slotDate = #" & Request("slotDate") & "# " _ & " AND slotNumber = " & Request("slotNumber") conn.Exeute SQL %>
Voila. ONE TABLE! Dirt simple code.
Only requirement is that you pre-load the table.
I use something like this in a *VERY* similar volunteer signup form. We have two shifts per day, except 3 on Thursday and 1 on Sunday. I would have gone nutso with the logic of that if I hadn't simply pre-filled the "Shifts" table ahead of time with about a year at a time. And, yes, it's all Access. And it has worked well for 4 years now.
K.I.S.S.
Old Pedant - 26 Jun 2008 06:21 GMT I should note that in my shift sign-up page, I actually display a calendar for the whole month with a button in each available shift with the person's name on it (because I made them sign-in already). So all they have to do is push the button to reserve that shift for themselves.
The page also shows *ALL* shifts and who is working them, so it's easy to see when your friends are working. And, finally, any shifts you are signed up for are highlighted in color.
Really really simple and effective user interface. It's for a bunch of artists who are decidedly lo-tech on average, and even the 70-year-old dingbat can use it.
With 8 slots per day, I don't think you want to show more than one or two weeks at a time, but other than that...
Hmmm???
Paolo Galli - 26 Jun 2008 07:15 GMT yes, I just need to show one day (two series of 8 slots) at a time
do you have some snippet of code regarding this calendar page? I'd like to do something like taht but based on a day view
thanks for the support
> I should note that in my shift sign-up page, I actually display a calendar > for the whole month with a button in each available shift with the person's [quoted text clipped - 13 lines] > > Hmmm??? Old Pedant - 26 Jun 2008 07:58 GMT So there are two rooms, each with 8 slots, for a given date??
Then you'd need to extend my suggested table just a tad:
Table: Slots slotDate : dateTime roomNumber : int or whatever slotNumber : int (1 through 8) employeeID : int or whatever you use for employeeIDs
And then you'd initialize all 8 slots on each date for each room.
And then it's pretty easy.
Again, first thing user does is enter his/her employeeid (or name or whatever you use) and the requested date (unless people can ONLY reserve for the next available date, of course, in which you don't need requested date but you do have to query the DB to find out what *is* the next date with slots...I'll leave it as a form field for demo purposes).
And so that <FORM> posts to code that does this:
<FORM ...> <TABLE border=1 cellpadding=10> <TR> <TH> <% empid = CInt( Request("employeeid") ) slotdate = CDate( Request("slotDate") )
SQL = "SELECT roomNumber, slotNumber, employeeID FROM slots " _ & " WHERE slotDate = #" & Request("slotDate") & "# " _ & " ORDER BY roomNumber, slotNumber" Set RS = conn.Execute(SQL)
priorroom = RS("roomNumber")
Do Until RS.EOF curroom = RS("roomNumber") If curroom <> priorroom Then Response.Write "</TH><TH>" & vbNewLine priorroom = curroom curslot = RS("slotnumber") curemp = RS("employeeID") rname = "R" & curroom & "_S" & curslot %> Room <%=curroom%>, slot <%=curslot%>: <% SELECT CASE curemp CASE 0 : ' nobody has it reserved %> <input type=button name="<%=rname%>" value="RESERVE" onclick="reserve(this);"> <% CASE empid : ' current employee has it already %> <input type=button name="<%=rname%>" style="background-color: pink;" value="UNRESERVE" onclick="unreserve(this);"> <!-- this says employee already has a slot on this date --> <input type=hidden name="TAKEN" value="any value" > <% CASE ELSE : ' somebody else has it %> <i>reserved by <%=curemp%></i> <% End Select RS.MoveNext Loop RS.Close conn.Close %> </TH></TR></TABLE> <input type=hidden name="empid" value="<%=empid%>"> <input type=hidden name="slotdate" value="<%=slotdate%>"> <input type=hidden name="RESERVE"> <input type=hidden name="UNRESERVE"> </form>
<script language=JavaScript> function unreserve(what) { var frm = document.forms[0]; if ( ! confirm("Are you sure you want to un-reserve this time slot?") ) { return; // user changed mind...do nothing } // this serves as command to next page frm.UNRESERVE.value = what.name; // name identifies room & slot! frm.submit( ); }
function reserve(what) { var frm = document.forms[0]; var temp = what.name.split("_"); // temp[0] will be Rxxx where xxx is roomnum if ( frm.TAKEN != null ) { alert("You have already reserved a slot on this date!"); return; } frm.RESERVE.value = what.name; // name identifies room & slot frm.submit( ); } </SCRIPT>
******************
WHEW. All off top of my head! I sure hope you meant the user can have only 1 slot per day, not one per day per room.
The sneaky trick here is generating the dummy TAKEN form field just to indicate that the employee *does* have a room reserved already. That makes the JS call to reserve( ) easy to code.
Because I wanted to be able to have the "unreserve" button, we show the full room and slot info, even though the user might have something reserved already on this date: So if nothing else, he/she can then unreserve their current choice.
I hope you can see that processing this form on the next page is really very easy.
You just have to parse R7_S3 or whatever to extract the room number and slot number and then use an UPDATE on the table to either reserve that room/slot on the slotDate for the empid or unreserve it (set empid back to zero).
Old Pedant - 26 Jun 2008 20:05 GMT <FORM Name="Reservations" Action="processReservation.asp" Method="Post"> <TABLE border=1 cellpadding=10> <TR> <TH>Slot#</TH> <TH>Room 1</TH> <TH>Room 2</TH> </TR> <% empid = CInt( Request("employeeid") ) slotdate = CDate( Request("slotDate") )
SQL = "SELECT roomNumber, slotNumber, employeeID FROM slots " _ & " WHERE slotDate = #" & Request("slotDate") & "# " _ & " ORDER BY slotNumber, roomNumber" Set RS = conn.Execute(SQL)
For curslot = 1 To 8 Response.Write "<TR><TH>" & curslot & "</TH>" & vbNewLine
For curroom = 1 To 2 If RS.EOF Then Response.Write "Unexpected EOF! Aborting!" Response.End End If If curslot <> RS("slotnumber") OR curroom <> RS("roomNumber") Then Response.Write "Unexpected data from DB! Aborting!" Response.End End If curemp = RS("employeeID") rname = "R" & curroom & "_S" & curslot SELECT CASE curemp CASE 0 : ' nobody has it reserved %> <TH> <i>Available</i><br/> <input type=button name="<%=rname%>" value="RESERVE" onclick="reserve(this);"> </TH> <% CASE empid : ' current employee has it already %> <TH> <i>Reserved by YOU</i><br/> <input type=button name="<%=rname%>" style="background-color: pink;" value="UNRESERVE" onclick="unreserve(this);"> <!-- this says employee already has a slot on this date --> <input type=hidden name="TAKEN" value="any value" > </TH> <% CASE ELSE : ' somebody else has it %> <TH> <i>reserved by <%=curemp%></i> </TH> <% End Select RS.MoveNext Next ' next room Response.Write "</TR>" & vbNewLine Next ' next slot RS.Close conn.Close %> </TH></TR></TABLE> <input type=hidden name="empid" value="<%=empid%>"> <input type=hidden name="slotdate" value="<%=slotdate%>"> <input type=hidden name="RESERVE"> <input type=hidden name="UNRESERVE"> </form>
<script language=JavaScript> function unreserve(what) { var frm = document.Reservations; if ( ! confirm("Are you sure you want to un-reserve this time slot?") ) { return; // user changed mind...do nothing } // this serves as command to next page frm.UNRESERVE.value = what.name; // name identifies room & slot! frm.submit( ); }
function reserve(what) { var frm = document.Reservations; if ( frm.TAKEN != null ) { alert("You have already reserved a slot on this date!"); return; } frm.RESERVE.value = what.name; // name identifies room & slot frm.submit( ); } </SCRIPT>
*************************************** This is the page that reserve/unreserve posts to
It simply grabs the info and executes the appropriate SQL request **************************************** <% ' PAGE: processReservation.asp
' create and open connection....
empid = CInt( Request("empid") ) slotDate = CDate( Request("slotdate") ) reserve = Trim( Request("RESERVE") ) unreserve = Trim( Request("UNRESERVE") ) If reserve <> "" Then ' if user asked to reserve a room and slot, get that request... roomAndSlot = Split( reserve, "_" ) ' and change the employeeid for the room and slot to user's empid eid = empid Else ' else must be unreserver...again get room and slot roomAndSlot = Split( unreserve, "_" ) ' but now change the employeeid for the room and slot back to zero! eid = 0 End If
' all done dirt simple thus: SQL = "UPDATE slots SET employeeID = " & eid _ & " WHERE slotDate = #" & slotDate & "# " _ & " AND roomNumber = " & CINT(Mid(roomAndSlot(0),2)) _ & " AND slotNumber = " & CINT(Mid(roomAndSlot(1),2)) conn.Execute SQL %>
|
|
|