
May 27th, 2006, 05:05 AM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 8
Time spent in forums: 1 h 54 m 41 sec
Reputation Power: 0
|
|
|
ASP Booking System modifications
Hi, I have an ASP booking system for the computer rooms at our school. The thing is we now have a regular bookings on a bi-weekly basis; week1 and week2. Each day has 5 periods; so for example week1 Wednesday period 1 is always booked.
At the moment the only way to check for these bookings is to enter the entire years bookings into the database. Is there a way of altering the attached script so that as well as reading the database for 'one-off' bookings it'll also check for 'constant' bookings with one record representing one day, period and week for the entire year?
I hope this makes sense. Check the attachment as it'll be more obvious if you read the code. Email me or reply to this post if you have any questions.
Here is the script for one of the rooms...
Code:
<%
Dim bookroom
Bookroom = "IT1"
function weekstartdate()
Dim dt
dt = Date
While (Weekday(dt) <> 2)
dt = DateAdd("d",-1,dt)
Wend
weekstartdate = dt
end function
'End Of Function
mondaydate = dt
%>
<head>
<title>Online Booking Portal - IT1 Booking</title></head>
<h5 align="center" style="text-align: right"><font size="2">
<a style="font-size: 10pt" href="NextWeek/it1.asp">Next Week</a></font></h5>
<h2 align="center" style="text-align: left">Booking <%response.write bookroom %></h2>
<p align="center">For week Beginning: <font color="000000"><% response.write weekStartDate %> </font></p>
<br>
<div align="center">
<%
'/* when you're using the getrows method use "dim arrBookings" instead of the following: */
'/* dim arrBookings(2,5) '/* there are 6 bookings this week, each with 3 bits of information */
dim ii, colCounter, intPeriod
dim dtmToday, dtmMonday, dtmThis, mondate
'declare variables
Dim Connection, objRS
Dim sSQL, sConnString
'declare SQL statement that will query the database
sSQL="SELECT BookedOn as bookDate, bookPeriod, bookname from bookings WHERE bookitem = '" & Bookroom & "'"
'define the connection string, specify database
'driver and the location of database
sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("BookDB.mdb")
'create an ADO connection and recordset
Set connection = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")
'Open the connection to the database
connection.Open sConnString
'Open the recordset object, execute the SQL statement
objRS.Open sSQL, connection
'begin table creation and booking search
if not objRS.eof then
arrBookings = objRS.getrows
else
redim arrBookings(0,0)
arrBookings(0,0) = -1
end if
'/* if you have decided not to go with the bookName info (taken from your first post) then just drop all references to (2,ii)
mondate = weekstartdate
dtmToday = date '/* get a date corresponding to any day in the active week */
dtmMonday = dtmToday - ((datepart("w", dtmToday, vbMonday))-1) '/* then we get that week's Monday */
response.write( "<table border=""1"" cellpadding=""5"">" )
response.write( "<tr>" )
response.write( " <td> </td>" )
for ii = 1 to 5
response.write( "<td>Period " & ii & "</td>" )
next
response.write( "</tr>" &vbcrlf)
for rowCounter = 0 to 4 '/* loop through 5 days */
for colCounter = 1 to 5 '/* for each day, loop through 5 periods */
if (colCounter = 1) then
response.write( "<tr>" )
response.write( "<td> " & weekdayname(rowCounter+1,0,2) & "<br><font size=2 color=000000>" & mondate & "</font></td>" )
mondate = mondate + 1
end if
dtmThis = cdate(dtmMonday + rowCounter)
call checkIsBooked(dtmThis, colCounter, arrBookings)
if (colCounter = 5) then
response.write( "</tr>" & vbcrlf)
end if
next
next
response.write( "</table>" )
function checkisBooked(dtmInput, intPeriod, arrInput)
dim ii, blnIsBooked
blnIsBooked = false
if (arrInput(0,0) <> -1) then '/* no point searching the array if we know it's empty */
for ii = 0 to ubound(arrInput,2)
if (arrInput(0,ii) = dtmInput) and (arrInput(1,ii) = intPeriod) then
blnIsBooked = true
exit for '/* no point continuing now we know it's booked
end if
next
end if
if (blnIsBooked = true) then
response.write( "<td style=""background-color: #ff0000;"" width=100 height=50>" )
response.write( "<p style=""text-align: center""><font size=2 color=ffffff>Booked by:</font>")
response.write( "<br>")
response.write( "<font size=3 color=000000>" & arrBookings(2,ii) ) '/* print the booker */
response.write( "</p></td>" )
else
response.write( "<td style=""background-color: #ffffff;"" width=100 height=60>" )
response.write( "<p style=""text-align: center""><a href='#book' onClick=popupWin=window.open('book.asp?bookdate=" & dtminput & "&bookperiod=" & intperiod & "&Room=" & bookroom & "','remote','width=350,height=410,top=100,left=100' )>Book</a>" )
response.write( "</p></td>" )
end if
end function
%>
Much appreciated.
|