booking system: first time using dates
Hi everybody
This is the code ive written for a simple appointment booking system. Its the first time ive used dates so if somebody could point out any mistakes ive made that would be appreciated.
Ive not tried running the script yet as the servers here haven't been configued propery yet. issues with permissions and all that :(
everyday is broken into 5 slots and it displays 1 month from the current date (hopefully).
The function isWeekDay is at the bottom of the code
Cheers, oh if anybody wants to use any of this stuff, by all means go ahead. Just dont blame me if your head explodes ;)
Cheers
Andy
<%
Dim dtToday, dtMonth, dtYear, objRS, objConn, sSQL, dtApptDay
' Get the current (start) date and 1 month in the future (finish date)
dtSDate = Date()
dtFDate = DateAdd("m", 1, dtSDate)
'find the number of days between these 2 dates for use later
numDays = DateDiff("d", dtSDate, dtFDate)
'make the RS
Set objConn = CreateObject("ADODB.Connection")
objConn.Open conn
'im using access, this query seems to work ok
Set objRS = CreateObject("ADODB.RecordSet")
sSQL = "SELECT Slot_id, Slot_Num, Slot_Date, Name, Email FROM Slots" & _
"WHERE year(Slot_Date) = year(" & dtSDate & ") AND Month(Slot_Date) = Month(" & dtSDate & ") AND Month(Slot_Date) = Month(" & dtFDate & ")" & _
"ORDER BY Slot_Date, Slot_Num;"
objRS.Open sSQL, objConn
%>
<html>
<head>
<style>
.appointments {
border: 1px solid #000000;
border-collapse: collapse;
}
.appointments td {
padding: 0.3em;
}
.even td {
border-bottom: 1px solid #cccccc;
background-color: #000000;
color: #ffffff;
}
.vertical {
writing-mode: tb-rl;
font-size: 2em;
background-color: #cccccc;
}
</style>
</head>
<body>
<h1>IT Officer Appointments</h1>
<p> To make an appointment more than 1 month in advance please Call Andrew on ext: 313.</p>
<table class="appointments">
<tr>
<td> </td>
<th>09:10 - 10:20</th>
<td rowspan="6" class="vertical"> Break </td>
<th>10:40 - 11:50</th>
<th>11:50 - 13:00</th>
<td rowspan="6" class="vertical"> Lunch </td>
<th>14:00 - 15:10</th>
<th>15:10 - 16:20</th>
</tr>
<%
dtApptDay = dtSDate
For x = 0 to numDays
blWeekDay = isWeekDay(dtApptDay)
If blWeekDay = False Then
Response.Write "<tr><td> Weekend </td></tr>"
Else
Response.Write "<tr>"
Response.Write "<td>" & WeekDayName(WeekDay(dtApptDay)) & "</td>"
For i = 1 to 5
Response.Write "<td>"
if objRS("Slot_Num") = i AND CDate(objRS("Slot_Date")) = dtApptDay Then
' write data from RS
' objRS.MoveNext
Else
Response.Write "<a href=""appt_make.asp?slotNum=" & i & "&apptDate=" & dtApptDay & chr(34) & ">available</a>" ' Note: chr(34) is the speach mark character
End If
Response.Write "</td>"
Next
Response.Write "</tr>"
End If
dtApptDay = DateAdd("d", 1, dtApptDay)
Next
%>
</table>
</body>
</html>
<%
' -------- functions go below here ----------
' Untested: pass a date into the the function and response.write the result to screen. True = mon-fri, False = sat/Sun
Function isWeekDay(dDay)
dDay = weekday(dDay)
Select Case dDay
Case 1, 7
isWeekDay = False
Case else
isWeekDay = True
End Select
End Function
%>
|