McSqueeb
asked on
ASP Calendar, a monthly calendar that shows events/dates using an array.
I am developing a calendar that will allow users to see what date(s) my business is closed on, currently my app checks the database every time a new date is written (1 - 31 of a month) this isnt good use of a db connection.
I want to change this so that an array is built before I start printing the calendar therefor the script checks the array and not the database on average 30times for a given month.
I havent found any topics / samples that create an array (not visible to the user) from a access database, then allow a script to search through that array to find a match.
I want to change this so that an array is built before I start printing the calendar therefor the script checks the array and not the database on average 30times for a given month.
I havent found any topics / samples that create an array (not visible to the user) from a access database, then allow a script to search through that array to find a match.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I've created a calendar that displays events on a calendar....but I've never put holidays on the calendar...
Ok this is code I use to display a calendar. Dates with appointments are greyed out. I havent got time to go through this tonight, but if as I assume you store the dates in the db that you're closed you should be able to tie this in quite easily
<%
iDate=request("date")
If IsDate(iDate) Then iDate = CDate(iDate) Else iDate = date
monthstart=session("db_enc lose") & year(idate) & "/" & month(idate) & "/1" & session("db_enclose")
monthend=dateadd("d",-1,da teadd("m", 1,(year(id ate) & "/" & month(idate) & "/1")))
monthend=session("db_enclo se") & year(monthend) & "/" & month(monthend) & "/" & day(monthend) & session("db_enclose")
rs.open "select cal_date from calendar where cal_date between " & monthstart & " AND " & monthend & " ORDER by cal_date",session("conn")
iDIM = GetDaysInMonth(Month(iDate ), Year(iDate))
iDOW = GetWeekdayMonthStartsOn(iD ate) %>
<table width=98% height=100% cellspacing=0 cellpadding=0>
<TR><TD><%call bar(Session(191)&" - " & formatdatetime(iDate,vblon gdate))%>< /TD></TR>
<TR><TD class=xpboxbottom align=center valign=top height=100%>
<table><TR><TD align="center" valign="top">
<TABLE BORDER=5 CELLSPACING=0 CELLPADDING=1>
<TR><TD BGCOLOR=#000099 ALIGN="center" height=1 COLSPAN=7>
<TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=0 style="border-collapse: collapse" bordercolor="#111111">
<TR><TD align=right><A HREF="?page=calendar&date= <%= SubtractOneMonth(iDate)%>" style="text-decoration: none"><font color="#FFFFFF"><<</font>< /A></TD>
<TH><font color="#FFFFFF"><%=MonthNa me(Month(i Date)) & " " & Year(iDate)%></font></TD>
<TD><A HREF="?page=calendar&date= <%=AddOneM onth(iDate )%>" style="text-decoration: none"><font color="#FFFFFF">>></font>< /A></TD></ TR>
</TABLE></TD></TR><TR><TH> S</TH><TH> M</TH><TH> T</TH><TH> W</TH><TH> T</TH><TH> F</TH><TH> S</TH></TR ><%
If iDOW <> 1 Then
Response.Write "<TR>"
iPosition = 1
Do While iPosition < iDOW
Response.Write "<TD BGCOLOR=#99CCFF > </TD>"
iPosition = iPosition + 1
Loop
End If
iCurrent = 1
iPosition = iDOW
Do While iCurrent <= iDIM
if not rs.eof then tempdate=year(rs(0)) & "/" & month(rs(0)) & "/" & icurrent else tempdate="2000/1/1"
if not rs.eof then checkdate=year(rs(0)) & "/" & month(rs(0)) & "/" & day(rs(0)) else checkdate="1900/1/1"
If iPosition = 1 Then
Response.Write "<TR>"
End If
If iCurrent = Day(iDate) Then
Response.Write "<TD align=center style=""border-width:2;bor der-color: black"""
if tempdate=checkdate then %>
style="cursor:hand;cursor: pointer" BGCOLOR=#C0C0C0 onclick='location.href="?p age=calend ar&date=<% =year(iDat e)&"/"&mon th(iDate)& "/"&iCurre nt%>"'><%= iCurrent%> </TD><%
rs.movenext
else %>
style="cursor:hand;cursor: pointer" BGCOLOR=#E6F2FF onclick='location.href="?p age=calend ar&date=<% =year(iDat e)&"/"&mon th(iDate)& "/"&iCurre nt%>"'><%= iCurrent%> </TD><%
end if
Else
if tempdate=checkdate then %>
<TD bgcolor=#C0C0C0 style="cursor:hand;cursor: pointer" align=center onclick='location.href="?p age=calend ar&date=<% =year(iDat e)&"/"&mon th(iDate)& "/"&iCurre nt%>"'><%= iCurrent%> </TD><%
rs.movenext
else %>
<TD bgcolor=#E6F2FF style="cursor:hand;cursor: pointer" align=center onclick='location.href="?p age=calend ar&date=<% =year(iDat e)&"/"&mon th(iDate)& "/"&iCurre nt%>"'><%= iCurrent%> </TD><%
end if
End If
If iPosition = 7 Then
Response.Write "</TR>"
iPosition = 0
End If
iCurrent = iCurrent + 1
iPosition = iPosition + 1
Loop
rs.close
If iPosition <> 1 Then
Do While iPosition <= 7
Response.Write "<TD BGCOLOR=#99CCFF> </TD >"
iPosition = iPosition + 1
Loop
Response.Write "</TR>"
End If %>
</TABLE><BR><BR><%
call button(Session(192),"windo w.open('ca ltime.asp? date=" & iDate & "','caltime','width=350,he ight=340') ","add") %>
</TD><TD valign=top width=100%><%
sql="select * from calendar where cal_date=" & session("db_enclose") & year(iDate) & "/" & month(iDate) & "/" & day(iDate) & session("db_enclose")
rs.open sql & " and cal_userid=" & session("userid") & " Order by cal_time",session("conn")
dim calnotes(24,2)
bgcolor="#E7E8F9"
do while not rs.eof
temptime=rs("cal_time")
if minute(rs("cal_time"))=00 then minutes=0 else minutes=1
calnotes(hour(rs("cal_time ")),minute s)="<span onclick=""window.open('cal time.asp?c al_id=" & rs("cal_id") & "','caltime','width=350,he ight=340') "" style='cursor:pointer;curs or:hand;wi dth:100%;b ackground: " & bgcolor & "'>" & rs("cal_subject") & "</span><BR>" & calnotes(hour(rs("cal_time ")),minute s)
rs.movenext
if not rs.eof then if temptime=rs("cal_time") and bgcolor="#E7E8F9" then bgcolor="#CBCDFA" else bgcolor="#E7E8F9"
loop
rs.close %>
<table width=95% border=5 cellspacing="0" cellpadding=0 border="5"><%
for count=6 to 22 %>
<TR><TD width=20 align=right style="border-right:none;b order-bott om-color:# 666666" valign=top rowspan="2"><font size=3><B><%=count%></B></ font>  ;</TD>
<TD style="border-left:none;bo rder-botto m-color:#6 66666" valign=top width=1 rowspan=2><font size=1>00</font></TD>
<TD height=15 valign=top><%if calnotes(count,0)="" then response.write " " else response.write calnotes(count,0)%></TD></ TR>
<TR><TD valign=top style="border-bottom-color :#666666"> <%if calnotes(count,1)="" then response.write " " else response.write calnotes(count,1)%></TD></ TR><%
next %>
</table>
</TD></TR></TABLE><%
Function GetDaysInMonth(iMonth, iYear)
dTemp = DateAdd("d", -1, DateSerial(iYear, iMonth + 1, 1))
GetDaysInMonth = Day(dTemp)
End Function
Function GetWeekdayMonthStartsOn(dA nyDayInThe Month)
dTemp = DateAdd("d", -(Day(dAnyDayInTheMonth) - 1), dAnyDayInTheMonth)
GetWeekdayMonthStartsOn = WeekDay(dTemp)
End Function
Function SubtractOneMonth(iDate)
SubtractOneMonth = DateAdd("m", -1, iDate)
End Function
Function AddOneMonth(iDate)
AddOneMonth = DateAdd("m", 1, iDate)
End Function
%>
<%
iDate=request("date")
If IsDate(iDate) Then iDate = CDate(iDate) Else iDate = date
monthstart=session("db_enc
monthend=dateadd("d",-1,da
monthend=session("db_enclo
rs.open "select cal_date from calendar where cal_date between " & monthstart & " AND " & monthend & " ORDER by cal_date",session("conn")
iDIM = GetDaysInMonth(Month(iDate
iDOW = GetWeekdayMonthStartsOn(iD
<table width=98% height=100% cellspacing=0 cellpadding=0>
<TR><TD><%call bar(Session(191)&" - " & formatdatetime(iDate,vblon
<TR><TD class=xpboxbottom align=center valign=top height=100%>
<table><TR><TD align="center" valign="top">
<TABLE BORDER=5 CELLSPACING=0 CELLPADDING=1>
<TR><TD BGCOLOR=#000099 ALIGN="center" height=1 COLSPAN=7>
<TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=0 style="border-collapse: collapse" bordercolor="#111111">
<TR><TD align=right><A HREF="?page=calendar&date=
<TH><font color="#FFFFFF"><%=MonthNa
<TD><A HREF="?page=calendar&date=
</TABLE></TD></TR><TR><TH>
If iDOW <> 1 Then
Response.Write "<TR>"
iPosition = 1
Do While iPosition < iDOW
Response.Write "<TD BGCOLOR=#99CCFF > </TD>"
iPosition = iPosition + 1
Loop
End If
iCurrent = 1
iPosition = iDOW
Do While iCurrent <= iDIM
if not rs.eof then tempdate=year(rs(0)) & "/" & month(rs(0)) & "/" & icurrent else tempdate="2000/1/1"
if not rs.eof then checkdate=year(rs(0)) & "/" & month(rs(0)) & "/" & day(rs(0)) else checkdate="1900/1/1"
If iPosition = 1 Then
Response.Write "<TR>"
End If
If iCurrent = Day(iDate) Then
Response.Write "<TD align=center style=""border-width:2;bor
if tempdate=checkdate then %>
style="cursor:hand;cursor:
rs.movenext
else %>
style="cursor:hand;cursor:
end if
Else
if tempdate=checkdate then %>
<TD bgcolor=#C0C0C0 style="cursor:hand;cursor:
rs.movenext
else %>
<TD bgcolor=#E6F2FF style="cursor:hand;cursor:
end if
End If
If iPosition = 7 Then
Response.Write "</TR>"
iPosition = 0
End If
iCurrent = iCurrent + 1
iPosition = iPosition + 1
Loop
rs.close
If iPosition <> 1 Then
Do While iPosition <= 7
Response.Write "<TD BGCOLOR=#99CCFF> </TD
iPosition = iPosition + 1
Loop
Response.Write "</TR>"
End If %>
</TABLE><BR><BR><%
call button(Session(192),"windo
</TD><TD valign=top width=100%><%
sql="select * from calendar where cal_date=" & session("db_enclose") & year(iDate) & "/" & month(iDate) & "/" & day(iDate) & session("db_enclose")
rs.open sql & " and cal_userid=" & session("userid") & " Order by cal_time",session("conn")
dim calnotes(24,2)
bgcolor="#E7E8F9"
do while not rs.eof
temptime=rs("cal_time")
if minute(rs("cal_time"))=00 then minutes=0 else minutes=1
calnotes(hour(rs("cal_time
rs.movenext
if not rs.eof then if temptime=rs("cal_time") and bgcolor="#E7E8F9" then bgcolor="#CBCDFA" else bgcolor="#E7E8F9"
loop
rs.close %>
<table width=95% border=5 cellspacing="0" cellpadding=0 border="5"><%
for count=6 to 22 %>
<TR><TD width=20 align=right style="border-right:none;b
<TD style="border-left:none;bo
<TD height=15 valign=top><%if calnotes(count,0)="" then response.write " " else response.write calnotes(count,0)%></TD></
<TR><TD valign=top style="border-bottom-color
next %>
</table>
</TD></TR></TABLE><%
Function GetDaysInMonth(iMonth, iYear)
dTemp = DateAdd("d", -1, DateSerial(iYear, iMonth + 1, 1))
GetDaysInMonth = Day(dTemp)
End Function
Function GetWeekdayMonthStartsOn(dA
dTemp = DateAdd("d", -(Day(dAnyDayInTheMonth) - 1), dAnyDayInTheMonth)
GetWeekdayMonthStartsOn = WeekDay(dTemp)
End Function
Function SubtractOneMonth(iDate)
SubtractOneMonth = DateAdd("m", -1, iDate)
End Function
Function AddOneMonth(iDate)
AddOneMonth = DateAdd("m", 1, iDate)
End Function
%>
ASKER
i see, this calendar is to alert users to business closing dates for bank holidays and christmas holidays (ireland)
so instead of event 12/08/2004 BBQ
its more like Bank Holiday 02/05/2005 Christmas Holidays 24/12/2004 to 02/01/2005
im just having problems geting the script to loop until start & finish date are <>
I could just input the dates seperatly 24/12/2004 - 25/12/2004 - 26/12/2004 etc but that will make size of database huge.
so instead of event 12/08/2004 BBQ
its more like Bank Holiday 02/05/2005 Christmas Holidays 24/12/2004 to 02/01/2005
im just having problems geting the script to loop until start & finish date are <>
I could just input the dates seperatly 24/12/2004 - 25/12/2004 - 26/12/2004 etc but that will make size of database huge.
ASKER
thanks Gary will look over it now.
Ok, like Gary, I'll try and go through this as well......
First, change the line of code below to your query (its the line that's commented blatantly...). Your query has to have 2 fields, specifically, for this to run....[date of event] and [primary key].
Second, make sure that the connection object is changed too...
If you have any problems, let me know and I'll walk you through it.
Dan
-----
<!--#include virtual="/connections/conn ection.asp "-->
<%
if request("givenDate") = "" then
monthDate = Month(Now()) & "/1/2004"
else
monthDate = request("givenDate")
end if
monthEndDay = DatePart("d",DateAdd("d",- 1,DateAdd( "m",1,CDat e(monthDat e))))
firstDay = DatePart("w",monthDate) '1 = Sunday, 7 = Saturday
counter = 1
set rs = server.createObject("ADODB .RecordSet ")
'------------------------- ---------- ---------- ----CHANGE THIS -------------------------- ----------
rs.Open "SELECT * FROM [Calendar of Events - Populator] WHERE [date of event] >= '" & monthDate & " 12:00:01 AM' AND [date of event] <= '" & Month(monthDate) & "/" & monthEndDay & "/2004 11:59:59 PM' ORDER BY [date of event]",my_conn,3,3
'------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -------
%>
<form name="changer" method="POST">
<input type="hidden" name="givenDate" value="<%=monthDate%>">
</form>
<table cellspacing="1" cellpadding="0" width="560">
<tr>
<td align="left" style="border : 1px solid black;"><a href="javascript: document.changer.givenDate .value = '<%=DateAdd("m",-1,CDate(m onthDate)) %>'; document.changer.submit(); "><< </a></td>
<td colspan="5" align="center" style="border : 1px solid black;">
<%=MonthName(Month(monthDa te))%>&nbs p;<%=Year( monthDate) %>
</td>
<td align="right" style="border : 1px solid black;"><a href="javascript: document.changer.givenDate .value = '<%=DateAdd("m",1,CDate(mo nthDate))% >'; document.changer.submit(); ">>> </a></td>
</tr>
<tr>
<td style="border : 1px solid black;" width="80">
Sun.
</td>
<td style="border : 1px solid black;" width="80">
Mon.
</td>
<td style="border : 1px solid black;" width="80">
Tue.
</td>
<td style="border : 1px solid black;" width="80">
Wed.
</td>
<td style="border : 1px solid black;" width="80">
Thurs.
</td>
<td style="border : 1px solid black;" width="80">
Fri.
</td>
<td style="border : 1px solid black;" width="80">
Sat.
</td>
</tr>
<tr>
<%
for i=2 to firstDay
%>
<td> </td>
<%
next
%>
<%
for i=firstDay to 7
%>
<td style="border : 1px solid black;" onMouseOver="this.style.ba ckgroundCo lor = '#AAAAAA';" onMouseOut="this.style.bac kgroundCol or = '#FFFFFF';" id="day_<%=counter%>"><%=c ounter%>
<%
if not rs.eof then
Do
if rs.eof then
Exit Do
elseif DatePart("d",rs("date of event")) <> counter then
Exit Do
end if
%>
<a href="#<%=rs("primary key")%>"><img src="/common/images/calend ar_item_on line.gif" border="0"></a>
<script language="javascript">
document.getElementById("d ay_<%=coun ter%>").cl assName = "lightBlueCellSmall";
document.getElementById("d ay_<%=coun ter%>").on mouseover = null;
document.getElementById("d ay_<%=coun ter%>").on mouseout = null;
</script>
<%
rs.moveNext
Loop
end if
%>
<BR><BR><BR></td>
<%
counter = counter + 1
next
weekDayCounter = 1
%>
</tr>
<tr>
<%
while counter <= monthEndDay
if weekDayCounter > 7 then
%>
</tr>
<tr>
<%
weekDayCounter = 1
end if
%>
<td style="border : 1px solid black;" onMouseOver="this.style.ba ckgroundCo lor = '#AAAAAA';" onMouseOut="this.style.bac kgroundCol or = '#FFFFFF';" id="day_<%=counter%>"><%=c ounter%>
<%
if not rs.eof then
Do
if rs.eof then
Exit Do
elseif DatePart("d",rs("date of event")) <> counter then
Exit Do
end if
%>
<a href="#<%=rs("primary key")%>"><img src="/common/images/calend ar_item_on line.gif" border="0"></a>
<script language="javascript">
document.getElementById("d ay_<%=coun ter%>").cl assName = "lightBlueCellSmall";
document.getElementById("d ay_<%=coun ter%>").on mouseover = null;
document.getElementById("d ay_<%=coun ter%>").on mouseout = null;
</script>
<%
rs.moveNext
Loop
end if
%>
<BR><BR><BR></td>
<%
weekDayCounter = weekDayCounter + 1
counter = counter + 1
wend
for i=weekDayCounter to 7
%>
<td> </td>
<%
next
%>
</tr>
</table>
<%
rs.Close
set rs = Nothing
%>
First, change the line of code below to your query (its the line that's commented blatantly...). Your query has to have 2 fields, specifically, for this to run....[date of event] and [primary key].
Second, make sure that the connection object is changed too...
If you have any problems, let me know and I'll walk you through it.
Dan
-----
<!--#include virtual="/connections/conn
<%
if request("givenDate") = "" then
monthDate = Month(Now()) & "/1/2004"
else
monthDate = request("givenDate")
end if
monthEndDay = DatePart("d",DateAdd("d",-
firstDay = DatePart("w",monthDate) '1 = Sunday, 7 = Saturday
counter = 1
set rs = server.createObject("ADODB
'-------------------------
rs.Open "SELECT * FROM [Calendar of Events - Populator] WHERE [date of event] >= '" & monthDate & " 12:00:01 AM' AND [date of event] <= '" & Month(monthDate) & "/" & monthEndDay & "/2004 11:59:59 PM' ORDER BY [date of event]",my_conn,3,3
'-------------------------
%>
<form name="changer" method="POST">
<input type="hidden" name="givenDate" value="<%=monthDate%>">
</form>
<table cellspacing="1" cellpadding="0" width="560">
<tr>
<td align="left" style="border : 1px solid black;"><a href="javascript: document.changer.givenDate
<td colspan="5" align="center" style="border : 1px solid black;">
<%=MonthName(Month(monthDa
</td>
<td align="right" style="border : 1px solid black;"><a href="javascript: document.changer.givenDate
</tr>
<tr>
<td style="border : 1px solid black;" width="80">
Sun.
</td>
<td style="border : 1px solid black;" width="80">
Mon.
</td>
<td style="border : 1px solid black;" width="80">
Tue.
</td>
<td style="border : 1px solid black;" width="80">
Wed.
</td>
<td style="border : 1px solid black;" width="80">
Thurs.
</td>
<td style="border : 1px solid black;" width="80">
Fri.
</td>
<td style="border : 1px solid black;" width="80">
Sat.
</td>
</tr>
<tr>
<%
for i=2 to firstDay
%>
<td> </td>
<%
next
%>
<%
for i=firstDay to 7
%>
<td style="border : 1px solid black;" onMouseOver="this.style.ba
<%
if not rs.eof then
Do
if rs.eof then
Exit Do
elseif DatePart("d",rs("date of event")) <> counter then
Exit Do
end if
%>
<a href="#<%=rs("primary key")%>"><img src="/common/images/calend
<script language="javascript">
document.getElementById("d
document.getElementById("d
document.getElementById("d
</script>
<%
rs.moveNext
Loop
end if
%>
<BR><BR><BR></td>
<%
counter = counter + 1
next
weekDayCounter = 1
%>
</tr>
<tr>
<%
while counter <= monthEndDay
if weekDayCounter > 7 then
%>
</tr>
<tr>
<%
weekDayCounter = 1
end if
%>
<td style="border : 1px solid black;" onMouseOver="this.style.ba
<%
if not rs.eof then
Do
if rs.eof then
Exit Do
elseif DatePart("d",rs("date of event")) <> counter then
Exit Do
end if
%>
<a href="#<%=rs("primary key")%>"><img src="/common/images/calend
<script language="javascript">
document.getElementById("d
document.getElementById("d
document.getElementById("d
</script>
<%
rs.moveNext
Loop
end if
%>
<BR><BR><BR></td>
<%
weekDayCounter = weekDayCounter + 1
counter = counter + 1
wend
for i=weekDayCounter to 7
%>
<td> </td>
<%
next
%>
</tr>
</table>
<%
rs.Close
set rs = Nothing
%>
Just to add there's lots of code in there that you can remove, its just design code for my site. The code works based on just dates that have events, if a day doesnt have an event then there isnt a record for it to start with so the db could be just this
10/8/04 Appt 1
20/8/04 Appt 2
3/9/04 Appt 3
So there is no need to have a table with every date in it and theres just the one recordset holding the data. Hope you can follow it easily enough...
10/8/04 Appt 1
20/8/04 Appt 2
3/9/04 Appt 3
So there is no need to have a table with every date in it and theres just the one recordset holding the data. Hope you can follow it easily enough...
ASKER
if you have msn i will gladly give ya the files. your both good at replying very quick, thanks. trying to go through code now.
msn: mcsqueeb @ hotmail dot com
msn: mcsqueeb @ hotmail dot com
Can't buddy...no MSN allowed at work....:(
ASKER
I have uploaded it to a file server here is the link, must not be a busy day in work ah..... ;o)
http://s2.yousendit.com/d.aspx?id=AE2695BCE7CB6AFD0AD7492590CE9A35
thanks for your help.
http://s2.yousendit.com/d.aspx?id=AE2695BCE7CB6AFD0AD7492590CE9A35
thanks for your help.
You have an email...
ASKER
you should be brought to a page where u can download the file??? works here and on the pcs around me
I downloaded it....made the fixes to my script, and emailed you the working page...
Here's a listing of the entire file, in case your email/my email isn't working:
Put this file in the same directory as the Access db/connection file....
Put this file in the same directory as the Access db/connection file....
<!--#include file="connection.asp"-->
<%
if request("givenDate") = "" then
monthDate = Month(Now()) & "/1/2004"
else
monthDate = request("givenDate")
end if
monthEndDay = DatePart("d",DateAdd("d",- 1,DateAdd( "m",1,CDat e(monthDat e))))
firstDay = DatePart("w",monthDate) '1 = Sunday, 7 = Saturday
counter = 1
set rs = server.createObject("ADODB .RecordSet ")
rs.Open "SELECT CalID as [primary key], CalDateFrom as [date of event] FROM tblCalendar ORDER BY CalDateFrom",objConnNNC,3, 3
%>
<form name="changer" method="POST">
<input type="hidden" name="givenDate" value="<%=monthDate%>">
</form>
<table cellspacing="1" cellpadding="0" width="560">
<tr>
<td align="left" style="border : 1px solid black;"><a href="javascript: document.changer.givenDate .value = '<%=DateAdd("m",-1,CDate(m onthDate)) %>'; document.changer.submit(); "><< </a></td>
<td colspan="5" align="center" style="border : 1px solid black;">
<%=MonthName(Month(monthDa te))%>&nbs p;<%=Year( monthDate) %>
</td>
<td align="right" style="border : 1px solid black;"><a href="javascript: document.changer.givenDate .value = '<%=DateAdd("m",1,CDate(mo nthDate))% >'; document.changer.submit(); ">>> </a></td>
</tr>
<tr>
<td style="border : 1px solid black;" width="80">
Sun.
</td>
<td style="border : 1px solid black;" width="80">
Mon.
</td>
<td style="border : 1px solid black;" width="80">
Tue.
</td>
<td style="border : 1px solid black;" width="80">
Wed.
</td>
<td style="border : 1px solid black;" width="80">
Thurs.
</td>
<td style="border : 1px solid black;" width="80">
Fri.
</td>
<td style="border : 1px solid black;" width="80">
Sat.
</td>
</tr>
<tr>
<%
for i=2 to firstDay
%>
<td> </td>
<%
next
%>
<%
for i=firstDay to 7
%>
<td style="border : 1px solid black;" onMouseOver="this.style.ba ckgroundCo lor = '#AAAAAA';" onMouseOut="this.style.bac kgroundCol or = '#FFFFFF';" id="day_<%=counter%>"><%=c ounter%>
<%
if not rs.eof then
Do
if rs.eof then
Exit Do
elseif DatePart("d",rs("date of event")) <> counter then
Exit Do
end if
%>
<a href="#<%=rs("primary key")%>"><img src="/common/images/calend ar_item_on line.gif" border="0"></a>
<script language="javascript">
document.getElementById("d ay_<%=coun ter%>").cl assName = "lightBlueCellSmall";
document.getElementById("d ay_<%=coun ter%>").on mouseover = null;
document.getElementById("d ay_<%=coun ter%>").on mouseout = null;
</script>
<%
rs.moveNext
Loop
end if
%>
<BR><BR><BR></td>
<%
counter = counter + 1
next
weekDayCounter = 1
%>
</tr>
<tr>
<%
while counter <= monthEndDay
if weekDayCounter > 7 then
%>
</tr>
<tr>
<%
weekDayCounter = 1
end if
%>
<td style="border : 1px solid black;" onMouseOver="this.style.ba ckgroundCo lor = '#AAAAAA';" onMouseOut="this.style.bac kgroundCol or = '#FFFFFF';" id="day_<%=counter%>"><%=c ounter%>
<%
if not rs.eof then
Do
if rs.eof then
Exit Do
elseif DatePart("d",rs("date of event")) <> counter then
Exit Do
end if
%>
<a href="#<%=rs("primary key")%>"><img src="/common/images/calend ar_item_on line.gif" border="0"></a>
<script language="javascript">
document.getElementById("d ay_<%=coun ter%>").cl assName = "lightBlueCellSmall";
document.getElementById("d ay_<%=coun ter%>").on mouseover = null;
document.getElementById("d ay_<%=coun ter%>").on mouseout = null;
</script>
<%
rs.moveNext
Loop
end if
%>
<BR><BR><BR></td>
<%
weekDayCounter = weekDayCounter + 1
counter = counter + 1
wend
for i=weekDayCounter to 7
%>
<td> </td>
<%
next
%>
</tr>
</table>
<%
rs.Close
set rs = Nothing
%>
<%
if request("givenDate") = "" then
monthDate = Month(Now()) & "/1/2004"
else
monthDate = request("givenDate")
end if
monthEndDay = DatePart("d",DateAdd("d",-
firstDay = DatePart("w",monthDate) '1 = Sunday, 7 = Saturday
counter = 1
set rs = server.createObject("ADODB
rs.Open "SELECT CalID as [primary key], CalDateFrom as [date of event] FROM tblCalendar ORDER BY CalDateFrom",objConnNNC,3,
%>
<form name="changer" method="POST">
<input type="hidden" name="givenDate" value="<%=monthDate%>">
</form>
<table cellspacing="1" cellpadding="0" width="560">
<tr>
<td align="left" style="border : 1px solid black;"><a href="javascript: document.changer.givenDate
<td colspan="5" align="center" style="border : 1px solid black;">
<%=MonthName(Month(monthDa
</td>
<td align="right" style="border : 1px solid black;"><a href="javascript: document.changer.givenDate
</tr>
<tr>
<td style="border : 1px solid black;" width="80">
Sun.
</td>
<td style="border : 1px solid black;" width="80">
Mon.
</td>
<td style="border : 1px solid black;" width="80">
Tue.
</td>
<td style="border : 1px solid black;" width="80">
Wed.
</td>
<td style="border : 1px solid black;" width="80">
Thurs.
</td>
<td style="border : 1px solid black;" width="80">
Fri.
</td>
<td style="border : 1px solid black;" width="80">
Sat.
</td>
</tr>
<tr>
<%
for i=2 to firstDay
%>
<td> </td>
<%
next
%>
<%
for i=firstDay to 7
%>
<td style="border : 1px solid black;" onMouseOver="this.style.ba
<%
if not rs.eof then
Do
if rs.eof then
Exit Do
elseif DatePart("d",rs("date of event")) <> counter then
Exit Do
end if
%>
<a href="#<%=rs("primary key")%>"><img src="/common/images/calend
<script language="javascript">
document.getElementById("d
document.getElementById("d
document.getElementById("d
</script>
<%
rs.moveNext
Loop
end if
%>
<BR><BR><BR></td>
<%
counter = counter + 1
next
weekDayCounter = 1
%>
</tr>
<tr>
<%
while counter <= monthEndDay
if weekDayCounter > 7 then
%>
</tr>
<tr>
<%
weekDayCounter = 1
end if
%>
<td style="border : 1px solid black;" onMouseOver="this.style.ba
<%
if not rs.eof then
Do
if rs.eof then
Exit Do
elseif DatePart("d",rs("date of event")) <> counter then
Exit Do
end if
%>
<a href="#<%=rs("primary key")%>"><img src="/common/images/calend
<script language="javascript">
document.getElementById("d
document.getElementById("d
document.getElementById("d
</script>
<%
rs.moveNext
Loop
end if
%>
<BR><BR><BR></td>
<%
weekDayCounter = weekDayCounter + 1
counter = counter + 1
wend
for i=weekDayCounter to 7
%>
<td> </td>
<%
next
%>
</tr>
</table>
<%
rs.Close
set rs = Nothing
%>
ASKER
did you run my script and see the output?
Yeah, ran nice for me....I like the look of it
ASKER
Thanks, I like the look to ;o)
Currently the calendar displays only the CalDateFrom field, so if you go to December the 25th will be blue, but the christmas hols run to the 2nd of Jan 2005. I havent managed to figure a way of getting the sql / code to colour each square until both dates are <>
Looking at your code its nearly the same as mine, i just currently have the the database / sql inside the loop, i need to move it to before the loop.
SAMPLE SQL - with date range added
SELECT CalID, CalDateFrom, CalDateTo, CalType FROM tblCalendar WHERE CalDateFrom >= #" START OF MONTH "# AND CalDateTo <= #" END OF MONTH "# ORDER BY CalDateFrom DESC "
but when I introduce this code it dosent pick up the range and the script starts to fail ;o( its now 7pm here and im wrecked lol
Currently the calendar displays only the CalDateFrom field, so if you go to December the 25th will be blue, but the christmas hols run to the 2nd of Jan 2005. I havent managed to figure a way of getting the sql / code to colour each square until both dates are <>
Looking at your code its nearly the same as mine, i just currently have the the database / sql inside the loop, i need to move it to before the loop.
SAMPLE SQL - with date range added
SELECT CalID, CalDateFrom, CalDateTo, CalType FROM tblCalendar WHERE CalDateFrom >= #" START OF MONTH "# AND CalDateTo <= #" END OF MONTH "# ORDER BY CalDateFrom DESC "
but when I introduce this code it dosent pick up the range and the script starts to fail ;o( its now 7pm here and im wrecked lol
Don't bother....
Don't try to make the holidays like that, because, as you're no doubt finding out, its INSANELY difficult to do...
Instead, make each holiday one day long, and stretch the two (or more) of them together....it'll save you time and money...
Dan
Don't try to make the holidays like that, because, as you're no doubt finding out, its INSANELY difficult to do...
Instead, make each holiday one day long, and stretch the two (or more) of them together....it'll save you time and money...
Dan
ASKER
but that isnt good database practice :o( it also means the database will increase in size & searching will take longer with more cols/rows.
It also means the admin will have to input a new holiday a load of times which I dont think any client/user wants to do... any ideas?
It also means the admin will have to input a new holiday a load of times which I dont think any client/user wants to do... any ideas?
No, its not good database practice, but good database practice doesn't always make for good programming practice, so there has to be some consideration there too...
How often do you forsee > 1 day holidays taking place? Twice/three times a year? Now, think of all the time you're going to spend on buiding a much more complicated solution...in the end, you're better making it slightly less theoretically efficent to make it more efficient in practice...
How often do you forsee > 1 day holidays taking place? Twice/three times a year? Now, think of all the time you're going to spend on buiding a much more complicated solution...in the end, you're better making it slightly less theoretically efficent to make it more efficient in practice...
ASKER
granted there are only 8 bank holidays a year & 7/8 days of xmas but in the future they might want to add in events like meetings etc, i will keep this post open for now, you shall get a good load of points dwaldner whatever the outcome :o) if you think of anything please fire it at me, as you said i will prob just keep hols to 1 day max but I have spent this long trying I wouldnt mind finding out the proper outcome.
My only note would be the old maxim "Don't reinvent the wheel"....if you want an Outlook-esque calendar for scheduling meetings, use Outlook...
Glad to help...if you need anymore help, you've got my addy...feel free...
Dan
Glad to help...if you need anymore help, you've got my addy...feel free...
Dan
ASKER
For iWeek = 1 To iRows
Response.Write "<tr valign='top' class='PLAIN'>"
For iDay = 1 To iColumns
' Checks to see if there is a day this month on the date being written
If aCalendarDays((iWeek-1)*7 + iDay) > 0 then
dtOnDay = DateSerial(Year(dtCurrentD
' define what type of event it is
strHol = "Holiday"
strOcc = "Occasion"
' set up database connection & sql
Set objRS = Server.CreateObject("ADODB
strSQL = "SELECT CalID, CalDateFrom, CalDateTo, CalType FROM tblCalendar WHERE CalDateFrom >= #" & formatdatetime(dtOnDay, vbLongDate) & "#"
Set objRS = objConnNNC.Execute(strSQL)
' DO UNTIL NO RECORDS FOUND
If NOT objRS.EOF THEN
IF dtOnDay = dtToday THEN
IF dtOnDay = objRS("CalDateFrom") AND objRS("CalType") = strHol THEN
strTAB = "'CALENDER_CURRENT_HOL'"
ELSEIF dtOnDay = objRS("CalDateFrom") AND objRS("CalType") = strOcc THEN
strTAB = "'CALENDER_CURRENT_OCC'"
ELSE
strTAB = "'CALENDER_CURRENT_BLA'"
END IF
ELSEIF dtOnDay = objRS("CalDateFrom") AND objRS("CalType") = strHol THEN
strTAB = "'CALENDAR_Holiday'"
ELSEIF dtOnDay = objRS("CalDateFrom") AND objRS("CalType") = strOcc THEN
strTAB = "'CALENDAR_Occasion'"
ELSE
strTAB = "'CALENDAR_BLANK'"
END IF
ELSE
strTAB = "'CALENDAR_BLANK'"
END IF
Set objRS = Nothing
Response.Write ("<TD CLASS=" & strTAB & "> <span class='CALENDAR_DATE'><a href='calendar.asp?CID=" & dtOnDay & "'>" & aCalendarDays((iWeek-1)*7 + iDay) & "</a></span><BR> ")
Else
Response.Write ("<TD> ")
End IF
Response.Write "</TD>"
Next
Response.Write "</TR>"
Next
Has anyone created a calendar that displays dates (bank holidays / xmas hols) as a different coloured cell, i have searched the web and every calendar has txt links which im not looking for. Thanks to dwaldner & GaryC so far, im looking at GetRows() as we speak.