|
| |
|
|
fredecd
Posts: 312 Joined: 12/3/2003 From: Louisiana, USA Status: offline
|
ASP Calendar Help - 3/30/2005 10:39:27
I have looked all over the net for an answer to this. Just wondering if anyone would have an idea on how to attack this: I am wanting to display a working shift calendar for shift workers at my work site. I already have the calendar working, but would like to add more functionality. Here is a typical rotating 2 week work cycle. I would like to edit my asp calendar so that I color the days with Shift A working a different color than days where Shift B is working. Week 1: Mon/Tues - Shift A, Wed/Thurs - Shift B, Fri/Sat/Sun- Shift A Week 2: Mon/Tues - Shift B, Wed/Thurs - Shift A, Fri/Sat/Sun Shift B Any ideas, or is anyone aware of a similar program that exists? Thanks in Advance,
_____________________________
Chris http://www.sightbysite.net
|
|
|
|
dzirkelb1
Posts: 1300 Joined: 10/5/2004 From: Cedar Rapids, Iowa Status: offline
|
RE: ASP Calendar Help - 3/30/2005 10:53:20
Are you hard coding the shifts in the calander or pulling it from a database? It would be something like this: <% if fp_field(fp_rs,"shift")="shift a" then%> html code to make color <%end if%> thats if you are pulling it from some sort of database...can you post the code / page?
|
|
|
|
fredecd
Posts: 312 Joined: 12/3/2003 From: Louisiana, USA Status: offline
|
RE: ASP Calendar Help - 3/30/2005 11:15:51
That's just it. I want to make the calendar show the different shift days into the future even if there are no records for that day in the database. Here is the sample code for displaying the calendar. I got this from the ASP 101 web site. There are several included files that go along with this application to make it fully functional, but the code below shows how the calendar is layed out.
Dim dDate ' Date we're displaying calendar for
Dim iDIM ' Days In Month
Dim iDOW ' Day Of Week that month starts on or the Day of Week were on.
Dim iCurrent ' Variable we use to hold current day of month as we write table
Dim ld_loopDate ' holds the loop position date as we loop thru the calender
Dim lb_eventsFound ' boolean true events were found for the loop date
DIM rstemp ' the recordset
'get the events for this month and keep them in the recordset
open_calender_connection()
Set rstemp = Server.CreateObject( "ADODB.Recordset" )
set rstemp=connCalender.execute( "select * from calender_event" )
' Call function to get the selected date
dDate = GetSelectedDate()
' write out the calender
With Response
' first (Outer) Table is simply to get the pretty border
.Write "<table BORDER='8' CELLSPACING='0' CELLPADDING='0'>"
.Write "<tr>"
.Write "<td>"
.Write "<table BORDER='1' CELLSPACING='0' CELLPADDING='1' bgcolor='#ffffff'>"
.Write "<tr>"
.Write "<td ALIGN='center' COLSPAN='7' class='month'>"
.Write "<table WIDTH='100%' BORDER='0' CELLSPACING='0' CELLPADDING='0'>"
.Write "<tr>"
.Write "<td class='month' ALIGN='right'><a HREF='default.asp?date=" & SubtractOneMonth(dDate) & "'><<</a></td>"
.Write "<td class='month' ALIGN='center'>" & MonthName(Month(dDate)) & " " & Year(dDate) & "</td>"
.Write "<td class='month' ALIGN='left'><a HREF='default.asp?date=" & AddOneMonth(dDate) & "'>>></a></td>"
.Write "</tr>"
.Write "</table>"
.Write "</td>"
.Write "</tr>"
.Write "<tr>"
.Write "<td WIDTH='80' ALIGN='center' class='weekday'>Sun<br></td>"
.Write "<td WIDTH='80' ALIGN='center' class='weekday'>Mon<br></td>"
.Write "<td WIDTH='80' ALIGN='center' class='weekday'>Tue<br></td>"
.Write "<td WIDTH='80' ALIGN='center' class='weekday'>Wed<br></td>"
.Write "<td WIDTH='80' ALIGN='center' class='weekday'>Thu<br></td>"
.Write "<td WIDTH='80' ALIGN='center' class='weekday'>Fri<br></td>"
.Write "<td WIDTH='80' ALIGN='center' class='weekday'>Sat<br></td>"
.Write "</tr>"
'Get day of the week the month starts on.
iDOW = GetWeekdayMonthStartsOn(dDate)
' Write spacer cells at beginning of first row if month doesn't start on a Sunday.
.Write vbTab & "<TR>" & vbCrLf
For iCurrent = 1 to iDOW - 1
.Write vbTab & vbTab & "<TD class='notaDay'> </TD>" & vbCrLf
Next
' Write days of month in proper day slots
For iCurrent = 1 to GetDaysInMonth(Month(dDate), Year(dDate))
' set the current date, were going to use it twice later on
ld_loopDate = cdate( Month(dDate) & "/" & iCurrent & "/" & Year(dDate) )
' If we're at the begginning of a row then write TR
If iDOW = 1 Then
.Write vbTab & "<TR>" & vbCrLf
End If
' If the day we're writing is the selected day then highlight it somehow.
If iCurrent = Day(dDate) Then
.Write vbTab & vbTab & "<TD class='selectedDay'><FONT SIZE=""-1""><B>"
.Write iCurrent & "</B></FONT><BR>"
Else
.Write vbTab & vbTab & "<TD class='day' valign=top>"
.Write "<A HREF=""default.asp?date=" & replace( cstr( ld_loopDate ), "/", "-" ) & """>"
.Write "<FONT SIZE=""-1"">" & iCurrent & "</FONT></A><br>" & vbCrLf
End If
' write out events for the current day filtering the recordset and calling a function
rstemp.Filter = "start_dt <= " & ld_loopDate & " and end_dt >= " & ld_loopDate ' filter the recordset
lb_eventsFound = WriteEventLabelsForRecordset( rstemp )
rstemp.Filter = 0
If not lb_eventsFound then ' give the cell some height
.Write "<br><br>"
End If
lb_eventsFound = false ' reset the flag
' close up the current day
.Write "</TD>"
' If we're at the endof a row then close it up
If iDOW = 7 Then
.Write vbTab & "</TD>" & vbCrLf
iDOW = 0
End If
' Increment the days of the week
iDOW = iDOW + 1
Next
' Write spacer cells at end of last row if month doesn't end on a Saturday.
If iDOW <> 1 Then
Do While iDOW <= 7
.Write vbTab & vbTab & "<TD class='notaDay'> </TD>" & vbCrLf
iDOW = iDOW + 1
Loop
.Write vbTab & "</TR>" & vbCrLf
End If
' close up both the tables
.Write "</table>"
.Write "</td>"
.Write "</tr>"
.Write "</table>"
.Write "<br>"
' call function that writes the date select form, and show events for the selected date
Call WriteSelectDateForm()
rstemp.Filter = "start_dt <= " & dDate & " and end_dt >= " & dDate ' filter the recordset
Call WriteEventsForRecordset( rstemp ) 'write the events for the recordset
' the add new event link
.Write "<a href='event_maint.asp'>Add a new event</a><br>"
.Write "<a href='delete_select.asp'>Delete an event</a><br>"
End With
' Close the calender connection
close_calender_connection()
set rstemp = nothing
%> I would like the employees on Shift A to be able to look into the calendar in the future to see if there shift will be scheduled to work on a specific day in the future, because the shift rotation never changes from the sequence that I listed above. I would like to tell the system to begin the two week rotating schedule on March 14, 2005, then project the color coding perpetually forward. Does that make sense?
_____________________________
Chris http://www.sightbysite.net
|
|
|
|
dzirkelb1
Posts: 1300 Joined: 10/5/2004 From: Cedar Rapids, Iowa Status: offline
|
RE: ASP Calendar Help - 3/30/2005 11:28:59
It makes perfect sense...basically, the calander would look something like: Monday 1st=red Monday 8th=blue Monday 15th=red Monday 22nd=blue Monday 29th=red Monday 6th(depending on month)=blue Unfortuntaley, thats beyond what I can think of besides the obviousof adding 7 to the date and coloring accordingly; however, that doesn't take in account the differning months. I guess you could do a loop for the first monday to the last monday of each month. You would have to do this loop 12 times, however, which is why it isn't the best...but, should work. Lets use march for example: Jan <% For i=3 to 31 step 7%> code to make colored <%next%> Feb <% for i=7 to 28 step 7%> code to make colored <%next%> Mar <% for i=7 to 31 step 7%> code to make colored <%next%> If you wanted to do this for years (05 to 06), then easiest would be to define each first monday of the date and have it add 1 (I believe, pending leap year) and run loops again. again, not best way, but should work
|
|
|
|
fredecd
Posts: 312 Joined: 12/3/2003 From: Louisiana, USA Status: offline
|
RE: ASP Calendar Help - 3/30/2005 16:06:40
Thanks for the reply. I am fairly new to the VB scripting, and I appreciate the help. Here is the code from a different page, but the same function with a simpler script. It also pulls results from a database. I added a variable called iDayofCycle, thinking that I could set up something with the repeating 14 day cycle. <%@ LANGUAGE=VBSCRIPT %>
<%Option Explicit%>
<!--#include file="adovbs.inc"-->
<%
If Request.Form("AddEvent") = "Add Event" Then
Response.Redirect("add_event.asp")
End If
If Request.Form("EditEvent") = "Edit Event" Then
Response.Redirect("edit_event.asp")
End If
Dim DB_CONNECTIONSTRING
Dim objRecordset
DB_CONNECTIONSTRING = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.Mappath("../fpdb/users.mdb") & ";"
Set objRecordset = Server.CreateObject("ADODB.Recordset")
objRecordset.Open "calendar", DB_CONNECTIONSTRING, adOpenStatic, adLockPessimistic, adCmdTable
%>
<%
Function GetDaysInMonth(iMonth, iYear)
Select Case iMonth
Case 1, 3, 5, 7, 8, 10, 12
GetDaysInMonth = 31
Case 4, 6, 9, 11
GetDaysInMonth = 30
Case 2
If IsDate("February 29, " & iYear) Then
GetDaysInMonth = 29
Else
GetDaysInMonth = 28
End If
End Select
End Function
Function GetWeekdayMonthStartsOn(iMonth, iYear)
GetWeekdayMonthStartsOn = WeekDay(CDate(iMonth & "/1/" & iYear))
End Function
Function SubtractOneMonth(dDate)
Dim iDay, iMonth, iYear
iDay = Day(dDate)
iMonth = Month(dDate)
iYear = Year(dDate)
If iMonth = 1 Then
iMonth = 12
iYear = iYear - 1
Else
iMonth = iMonth - 1
End If
If iDay > GetDaysInMonth(iMonth, iYear) Then iDay = GetDaysInMonth(iMonth, iYear)
SubtractOneMonth = CDate(iMonth & "-" & iDay & "-" & iYear)
End Function
Function AddOneMonth(dDate)
Dim iDay, iMonth, iYear
iDay = Day(dDate)
iMonth = Month(dDate)
iYear = Year(dDate)
If iMonth = 12 Then
iMonth = 1
iYear = iYear + 1
Else
iMonth = iMonth + 1
End If
If iDay > GetDaysInMonth(iMonth, iYear) Then iDay = GetDaysInMonth(iMonth, iYear)
AddOneMonth = CDate(iMonth & "-" & iDay & "-" & iYear)
End Function
Dim dDate ' Date we're displaying calendar for
Dim iDIM ' Days In Month
Dim iDOW ' Day Of Week that month starts on
Dim iCurrent ' Variable we use to hold current day of month as we write table
Dim iPosition ' Variable we use to hold current position in table
Dim iDayofCycle 'Variable to hold current shift
If IsDate(Request.QueryString("date")) Then
dDate = CDate(Request.QueryString("date"))
Else
If IsDate(Request.QueryString("month") & "-" & Request.QueryString("day") & "-" & Request.QueryString("year")) Then
dDate = CDate(Request.QueryString("month") & "-" & Request.QueryString("day") & "-" & Request.QueryString("year"))
Else
dDate = Date()
If Request.QueryString.Count <> 0 Then
Response.Write "The date you picked was not a valid date. The calendar was set to today's date.<BR><BR>"
End If
End If
End If
iDIM = GetDaysInMonth(Month(dDate), Year(dDate))
iDOW = GetWeekdayMonthStartsOn(Month(dDate), Year(dDate))
%>
<html>
<center>
<table border="1" cellspacing="0" cellpadding="1">
<tr>
<td bgcolor="blue" align="center" colspan="7">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="right"><b><A HREF="calendar.asp?date=<%= SubtractOneMonth(dDate) %>" style="color: #FFFFFF"><--</A></b></TD>
<td align="center"><font color="#FFFFFF"><B><%= MonthName(Month(dDate)) & " " & Year(dDate) %></B></font></TD>
<td align="left"><b><A HREF="calendar.asp?date=<%= AddOneMonth(dDate) %>" style="color: #FFFFFF">--></A></b></TD>
<td align="right" valign="top"><a href="http://www.4guysfromrolla.com"><img src="close.gif" border="0"></a></td>
</tr>
</TABLE>
</td>
</tr>
<tr bgcolor="blue">
<td ALIGN="center" width="80"><B><font color="#FFFFFF">Sun</font></B></TD>
<td ALIGN="center" width="80"><B><font color="#FFFFFF">Mon</font></B></TD>
<td ALIGN="center" width="80"><B><font color="#FFFFFF">Tue</font></B></TD>
<td ALIGN="center" width="80"><B><font color="#FFFFFF">Wed</font></B></TD>
<td ALIGN="center" width="80"><B><font color="#FFFFFF">Thu</font></B></TD>
<td ALIGN="center" width="80"><B><font color="#FFFFFF">Fri</font></B></TD>
<td ALIGN="center" width="80"><B><font color="#FFFFFF">Sat</font></B></TD>
</tr>
<%
If iDOW <> 1 Then
Response.Write(vbTab & "<tr>" & vbCrLf)
iPosition = 1
Do While iPosition < iDOW
Response.Write(vbTab & vbTab & "<td> </td>" & vbCrLf)
iPosition = iPosition + 1
Loop
End If
'-- Write days of month in proper day slots --
iCurrent = 1
iPosition = iDOW
iDayofCycle= icurrent
Do While iCurrent <= iDIM
'-- open the table row --
If iPosition = 1 Then
Response.Write(vbTab & "<tr>" & vbCrLf)
End If
'-- Write the date and subject --
If iPosition = 2 and iCurrent < 8 Then
Response.Write(vbTab & vbTab & "<td align=left valign=top height=60 bgcolor=#FFFFCC><b>" & iCurrent & "</b>")
Else
Response.Write(vbTab & vbTab & "<td align=left valign=top height=60 bgcolor=#FFFFFF><b>" & iCurrent & "</b>")
End If
If Not objRecordset.BOF Then
objRecordset.MoveFirst
Do Until objRecordset.EOF
If objRecordset.Fields("Year") = Year(dDate) Then
If objRecordset.Fields("Month") = Month(dDate) Then
If objRecordset.Fields("Day") = iCurrent Then
Response.Write("<br><font size=2><a href=" & Chr(34) & "display_event.asp?ID=" & objRecordset.Fields("ID") & Chr(34) & ">" & objRecordset.Fields("Subject") & "</a></font><br>")
End If
End If
End If
objRecordset.MoveNext
Loop
End If
Response.Write("</td>" & vbCrLf)
'-- Close the table row --
If iPosition = 7 Then
Response.Write vbTab & "</tr>" & vbCrLf
iPosition = 0
End If
'-- Increment variables --
iCurrent = iCurrent + 1
iPosition = iPosition + 1
Loop
If iPosition <> 1 Then
Do While iPosition <= 7
Response.Write(vbTab & vbTab & "<td> </td>" & vbCrLf)
iPosition = iPosition + 1
Loop
Response.Write vbTab & "</TR>" & vbCrLf
End If
%>
</table>
<%
objRecordset.Close
Set objRecordset = Nothing
%>
<%
Response.Write("<form action=" & Chr(34) & "calendar.asp" & Chr(34) & " method=" & Chr(34) & "post" & Chr(34) & ">" & Chr(10))
Response.Write("<input type=" & Chr(34) & "submit" & Chr(34) & " name=" & Chr(34) & "AddEvent" & Chr(34) & " value=" & Chr(34) & "Add Event" & Chr(34) & ">" & " ")
Response.Write("</form>")
%>
</center>
</html> Question: Since this is a two week cycle, can I add a statement something like For iDayofCycle= 1 to 14 and create a looping effect within the calendar that cycles every 14 days? Then I could assign the affect based on days of the work cycle I am just struggling on how to start it, then how to get it to roll over into the other months. If this sparks any ideas, I would love to hear them.
_____________________________
Chris http://www.sightbysite.net
|
|
|
|
dzirkelb1
Posts: 1300 Joined: 10/5/2004 From: Cedar Rapids, Iowa Status: offline
|
RE: ASP Calendar Help - 3/30/2005 16:24:03
Ya, 14 days, not 7...my bad on the first. Well, you could do something once, then loop it once... You could assign numbers running from 1-365, then do the loop for 14 day...but, you would have to change your calender. meaning, day32 would be feb1st. However, I don't think any of this will work with you script as its beyond my scope and I really don't understand it :( but, the loop would be something like you said
|
|
|
|
rdouglass
Posts: 9205 From: Biddeford, ME USA Status: offline
|
RE: ASP Calendar Help - 3/30/2005 16:26:50
Don't want to throw anyone offtrack but have you considered using DATEPART and MOD in conjunction? If you're doing a simple 2 week rotation, I envision a function that does something like: FUNCTION colorizeDate(dateToColorize) IF (DATEPART(week,dateToColorize) MOD 4 = 0) OR (DATEPART(week,dateToColorize) MOD 4 = 1) THEN colorize = "<font color="blue">" & dateToColorize & "</font>" ELSE colorize = "<font color="red">" & dateToColorize & "</font>" END IF END FUNCTION Then you could just pass each of the dates to the function and it would return them with the proper color. IMO seems a lot less overhead than determining what each day is by disecting the day. If the weeks don't match to your current schedule, adjust 'em by adding 1, 2, or 3 here: IF ((DATEPART(week,dateToColorize)+x) MOD 4 = 0) OR ((DATEPART(week,dateToColorize)+x) MOD 4 = 1) THEN where "x" is 1,2, or 3 depending on how much adjustment is needed. Just my $.02
_____________________________
Don't take you're eye off your final destination. ASP Checkbox Function Tutorial.
|
|
|
|
fredecd
Posts: 312 Joined: 12/3/2003 From: Louisiana, USA Status: offline
|
RE: ASP Calendar Help - 3/30/2005 16:28:03
Is there a function that will tell me the numerical value of a day. example: Is there a value that I can pull to say that February 5th is day 36 of the year?
_____________________________
Chris http://www.sightbysite.net
|
|
|
|
fredecd
Posts: 312 Joined: 12/3/2003 From: Louisiana, USA Status: offline
|
RE: ASP Calendar Help - 3/30/2005 16:30:12
I am open to using any advice. I am in the early phase of design here, so I won't lose anything by trying your suggestion. Thanks for the info. I will post back if I get it working.
_____________________________
Chris http://www.sightbysite.net
|
|
|
|
fredecd
Posts: 312 Joined: 12/3/2003 From: Louisiana, USA Status: offline
|
RE: ASP Calendar Help - 3/30/2005 17:11:44
The only reference is for using this in SQL. Can I generate it as a variable?
_____________________________
Chris http://www.sightbysite.net
|
|
|
|
fredecd
Posts: 312 Joined: 12/3/2003 From: Louisiana, USA Status: offline
|
RE: ASP Calendar Help - 3/31/2005 9:57:06
I am running Access 2000 for my DB, and I cannot get the Day of Year to work as a Datepart function. Does Access 2000 do this?
_____________________________
Chris http://www.sightbysite.net
|
|
|
|
rdouglass
Posts: 9205 From: Biddeford, ME USA Status: offline
|
RE: ASP Calendar Help - 3/31/2005 10:52:29
Can you post the exact code you're using in terms of DatePart? My suggestion was not using DatePart in the DB query but in the display portion which is just VBScript.
_____________________________
Don't take you're eye off your final destination. ASP Checkbox Function Tutorial.
|
|
|
|
fredecd
Posts: 312 Joined: 12/3/2003 From: Louisiana, USA Status: offline
|
RE: ASP Calendar Help - 3/31/2005 13:15:08
Here is the code for the page, but to tell you the truth, I do not understand where I would use the DatePart in order to manipulate my calendar. <%
Dim dDate ' Date we're displaying calendar for
Dim iDIM ' Days In Month
Dim iDOW ' Day Of Week that month starts on or the Day of Week were on.
Dim iCurrent ' Variable we use to hold current day of month as we write table
Dim ld_loopDate ' holds the loop position date as we loop thru the calender
Dim lb_eventsFound ' boolean true events were found for the loop date
DIM rstemp ' the recordset
Dim myDate ' the date number for a selected date (day of the year)
'get the events for this month and keep them in the recordset
open_calender_connection()
Set rstemp = Server.CreateObject( "ADODB.Recordset" )
set rstemp=connCalender.execute( "select * from calender_event" )
' Call function to get the selected date
dDate = GetSelectedDate()
' write out the calender
With Response
' first (Outer) Table is simply to get the pretty border
.Write "<table BORDER='8' CELLSPACING='0' CELLPADDING='0'>"
.Write "<tr>"
.Write "<td>"
.Write "<table BORDER='1' CELLSPACING='0' CELLPADDING='1' bgcolor='#ffffff'>"
.Write "<tr>"
.Write "<td ALIGN='center' COLSPAN='7' class='month'>"
.Write "<table WIDTH='100%' BORDER='0' CELLSPACING='0' CELLPADDING='0'>"
.Write "<tr>"
.Write "<td class='month' ALIGN='right'><a HREF='default.asp?date=" & SubtractOneMonth(dDate) & "'><<</a></td>"
.Write "<td class='month' ALIGN='center'>" & MonthName(Month(dDate)) & " " & Year(dDate) & "</td>"
.Write "<td class='month' ALIGN='left'><a HREF='default.asp?date=" & AddOneMonth(dDate) & "'>>></a></td>"
.Write "</tr>"
.Write "</table>"
.Write "</td>"
.Write "</tr>"
.Write "<tr>"
.Write "<td WIDTH='80' ALIGN='center' class='weekday'>Sun<br></td>"
.Write "<td WIDTH='80' ALIGN='center' class='weekday'>Mon<br></td>"
.Write "<td WIDTH='80' ALIGN='center' class='weekday'>Tue<br></td>"
.Write "<td WIDTH='80' ALIGN='center' class='weekday'>Wed<br></td>"
.Write "<td WIDTH='80' ALIGN='center' class='weekday'>Thu<br></td>"
.Write "<td WIDTH='80' ALIGN='center' class='weekday'>Fri<br></td>"
.Write "<td WIDTH='80' ALIGN='center' class='weekday'>Sat<br></td>"
.Write "</tr>"
'Get day of the week the month starts on.
iDOW = GetWeekdayMonthStartsOn(dDate)
' Write spacer cells at beginning of first row if month doesn't start on a Sunday.
.Write vbTab & "<TR>" & vbCrLf
For iCurrent = 1 to iDOW - 1
.Write vbTab & vbTab & "<TD class='notaDay'> </TD>" & vbCrLf
Next
' Write days of month in proper day slots
For iCurrent = 1 to GetDaysInMonth(Month(dDate), Year(dDate))
' set the current date, were going to use it twice later on
ld_loopDate = cdate( Month(dDate) & "/" & iCurrent & "/" & Year(dDate) )
' If we're at the beginning of a row then write TR
If iDOW = 1 Then
.Write vbTab & "<TR>" & vbCrLf
End If
'display the information in the box
.Write vbTab & vbTab & "<TD class='day' valign=top>"
.Write "<A HREF=""default.asp?date=" & replace( cstr( ld_loopDate ), "/", "-" ) & """>"
.Write "<FONT SIZE=""-1"">" & iCurrent & "</FONT></A><br>" & vbCrLf
' write out events for the current day filtering the recordset and calling a function
rstemp.Filter = "start_dt <= " & ld_loopDate & " and end_dt >= " & ld_loopDate ' filter the recordset
lb_eventsFound = WriteEventLabelsForRecordset( rstemp )
rstemp.Filter = 0
If not lb_eventsFound then ' give the cell some height
.Write "<br><br>"
End If
lb_eventsFound = false ' reset the flag
' close up the current day
.Write "</TD>"
' If we're at the endof a row then close it up
If iDOW = 7 Then
.Write vbTab & "</TD>" & vbCrLf
iDOW = 0
End If
' Increment the days of the week
iDOW = iDOW + 1
Next
' Write spacer cells at end of last row if month doesn't end on a Saturday.
If iDOW <> 1 Then
Do While iDOW <= 7
.Write vbTab & vbTab & "<TD class='notaDay'> </TD>" & vbCrLf
iDOW = iDOW + 1
Loop
.Write vbTab & "</TR>" & vbCrLf
End If
' close up both the tables
.Write "</table>"
.Write "</td>"
.Write "</tr>"
.Write "</table>"
.Write "<br>"
' call function that writes the date select form, and show events for the selected date
Call WriteSelectDateForm()
rstemp.Filter = "start_dt <= " & dDate & " and end_dt >= " & dDate ' filter the recordset
Call WriteEventsForRecordset( rstemp ) 'write the events for the recordset
' the add new event link
.Write "<a href='event_maint.asp'>Add a new event</a><br>"
.Write "<a href='delete_select.asp'>Delete an event</a><br>"
End With
' Close the calender connection
close_calender_connection()
set rstemp = nothing
%>
_____________________________
Chris http://www.sightbysite.net
|
|
|
|
rdouglass
Posts: 9205 From: Biddeford, ME USA Status: offline
|
RE: ASP Calendar Help - 4/1/2005 11:06:09
quote:
'display the information in the box .Write vbTab & vbTab & "<TD class='day' valign=top>" .Write "<A HREF=""default.asp?date=" & replace( cstr( ld_loopDate ), "/", "-" ) & """>" .Write "<FONT SIZE=""-1"">" & iCurrent & "</FONT></A><br>" & vbCrLf Well, without knowing your full application, I'd suggest doing it somewhere there. First, I'd put a function at the very top of all your ASP code like this: FUNCTION colorizeDate(myDate) IF (DATEPART(week,myDate) MOD 4 = 0) OR (DATEPART(week,myDate) MOD 4 = 1) THEN colorizeDate = " bgcolor='blue'" ELSE colorizeDate = " bgcolor='red'" END IF END FUNCTION and then change this line: .Write vbTab & vbTab & "<TD class='day' valign=top>" to this: .Write vbTab & vbTab & "<TD class='day' valign=top" & colorizeDate(ld_loopDate) & ">" That should give the full cell a background color with alternating colors every two weeks. See, the code really doesn't care what the DB has in it, just what date you're passing. At least that's how I'd attempt it. That any help?
_____________________________
Don't take you're eye off your final destination. ASP Checkbox Function Tutorial.
|
|
|
|
fredecd
Posts: 312 Joined: 12/3/2003 From: Louisiana, USA Status: offline
|
RE: ASP Calendar Help - 4/1/2005 14:02:49
Okay. I think that I need to clarify what I am trying to do. I want to follow a two week pattern of work as listed in my original message. The green days would mean that Shift A is working, and the gray days would mean that Shift B is working. Here is a link to the page with the script. So far, I have created a case statement that uses days of the month in order to color the backgrounds. The problem is that I do not know how to successfully connect one month to the next. http://sightbysite.net/calendar/calendar.asp Here is the code for the link above: <%@ LANGUAGE=VBSCRIPT %>
<%Option Explicit%>
<!--#include file="adovbs.inc"-->
<%
If Request.Form("AddEvent") = "Add Event" Then
Response.Redirect("add_event.asp")
End If
If Request.Form("EditEvent") = "Edit Event" Then
Response.Redirect("edit_event.asp")
End If
Dim DB_CONNECTIONSTRING
Dim objRecordset
Dim d
DB_CONNECTIONSTRING = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.Mappath("../fpdb/users.mdb") & ";"
Set objRecordset = Server.CreateObject("ADODB.Recordset")
objRecordset.Open "calendar", DB_CONNECTIONSTRING, adOpenStatic, adLockPessimistic, adCmdTable
%>
<%
Function GetDaysInMonth(iMonth, iYear)
Select Case iMonth
Case 1, 3, 5, 7, 8, 10, 12
GetDaysInMonth = 31
Case 4, 6, 9, 11
GetDaysInMonth = 30
Case 2
If IsDate("February 29, " & iYear) Then
GetDaysInMonth = 29
Else
GetDaysInMonth = 28
End If
End Select
End Function
Function GetWeekdayMonthStartsOn(iMonth, iYear)
GetWeekdayMonthStartsOn = WeekDay(CDate(iMonth & "/1/" & iYear))
End Function
Function SubtractOneMonth(dDate)
Dim iDay, iMonth, iYear
iDay = Day(dDate)
iMonth = Month(dDate)
iYear = Year(dDate)
If iMonth = 1 Then
iMonth = 12
iYear = iYear - 1
Else
iMonth = iMonth - 1
End If
If iDay > GetDaysInMonth(iMonth, iYear) Then iDay = GetDaysInMonth(iMonth, iYear)
SubtractOneMonth = CDate(iMonth & "-" & iDay & "-" & iYear)
End Function
Function AddOneMonth(dDate)
Dim iDay, iMonth, iYear
iDay = Day(dDate)
iMonth = Month(dDate)
iYear = Year(dDate)
If iMonth = 12 Then
iMonth = 1
iYear = iYear + 1
Else
iMonth = iMonth + 1
End If
If iDay > GetDaysInMonth(iMonth, iYear) Then iDay = GetDaysInMonth(iMonth, iYear)
AddOneMonth = CDate(iMonth & "-" & iDay & "-" & iYear)
End Function
Function ColorShiftDays(iCurrent)
select case iCurrent
case 1,2,5,6,7,10,11, 15, 16, 19, 20, 21, 24, 25, 29, 30
ColorShiftDays = " bgcolor=green "
case else
ColorShiftDays = " bgcolor=#EBEBEB "
end select
End Function
Dim dDate ' Date we're displaying calendar for
Dim iDIM ' Days In Month
Dim iDOW ' Day Of Week that month starts on
Dim iCurrent ' Variable we use to hold current day of month as we write table
Dim iPosition ' Variable we use to hold current position in table
Dim iDayofCycle 'Variable to hold current shift
DIM MyDate ' Holds the current full date for the day in the calendar
Dim iGetColors ' Gets colors for background of days in calendar
If IsDate(Request.QueryString("date")) Then
dDate = CDate(Request.QueryString("date"))
Else
If IsDate(Request.QueryString("month") & "-" & Request.QueryString("day") & "-" & Request.QueryString("year")) Then
dDate = CDate(Request.QueryString("month") & "-" & Request.QueryString("day") & "-" & Request.QueryString("year"))
Else
dDate = Date()
If Request.QueryString.Count <> 0 Then
Response.Write "The date you picked was not a valid date. The calendar was set to today's date.<BR><BR>"
End If
End If
End If
iDIM = GetDaysInMonth(Month(dDate), Year(dDate))
iDOW = GetWeekdayMonthStartsOn(Month(dDate), Year(dDate))
%>
<html>
<center>
<table border="1" cellspacing="0" cellpadding="1">
<tr>
<td bgcolor="blue" align="center" colspan="7">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="right"><b><A HREF="calendar.asp?date=<%= SubtractOneMonth(dDate) %>" style="color: #FFFFFF"><--</A></b></TD>
<td align="center"><font color="#FFFFFF"><B><%= MonthName(Month(dDate)) & " " & Year(dDate) %></B></font></TD>
<td align="left"><b><A HREF="calendar.asp?date=<%= AddOneMonth(dDate) %>" style="color: #FFFFFF">--></A></b></TD>
<td align="right" valign="top"><a href="http://www.4guysfromrolla.com"><img src="close.gif" border="0"></a></td>
</tr>
</TABLE>
</td>
</tr>
<tr bgcolor="blue">
<td ALIGN="center" width="80"><B><font color="#FFFFFF">Sun</font></B></TD>
<td ALIGN="center" width="80"><B><font color="#FFFFFF">Mon</font></B></TD>
<td ALIGN="center" width="80"><B><font color="#FFFFFF">Tue</font></B></TD>
<td ALIGN="center" width="80"><B><font color="#FFFFFF">Wed</font></B></TD>
<td ALIGN="center" width="80"><B><font color="#FFFFFF">Thu</font></B></TD>
<td ALIGN="center" width="80"><B><font color="#FFFFFF">Fri</font></B></TD>
<td ALIGN="center" width="80"><B><font color="#FFFFFF">Sat</font></B></TD>
</tr>
<%
If iDOW <> 1 Then
Response.Write(vbTab & "<tr>" & vbCrLf)
iPosition = 1
Do While iPosition < iDOW
Response.Write(vbTab & vbTab & "<td> </td>" & vbCrLf)
iPosition = iPosition + 1
Loop
End If
'-- Write days of month in proper day slots --
iCurrent = 1
iPosition = iDOW
iDayofCycle=1
Do While iCurrent <= iDIM
iGetColors = ColorShiftDays(iCurrent)
'-- open the table row --
MyDate= cDate(Month(dDate) & "-" & iCurrent & "-" & Year(dDate)) ' get the entire date so that I can generate the DatePart / Day of Year in each block
If iPosition = 1 Then
Response.Write(vbTab & "<tr>" & vbCrLf)
End If
'-- Write the date and subject --
Response.Write(vbTab & vbTab & "<td " & iGetColors & " align=left valign=top height=60><b>" & iCurrent & "-" & DatePart("y",MyDate) & "</b>")
If Not objRecordset.BOF Then
objRecordset.MoveFirst
Do Until objRecordset.EOF
If objRecordset.Fields("Year") = Year(dDate) Then
If objRecordset.Fields("Month") = Month(dDate) Then
If objRecordset.Fields("Day") = iCurrent Then
Response.Write("<br><font size=2><a href=" & Chr(34) & "display_event.asp?ID=" & objRecordset.Fields("ID") & Chr(34) & ">" & objRecordset.Fields("Subject") & "</a></font><br>")
End If
End If
End If
objRecordset.MoveNext
Loop
End If
Response.Write("</td>" & vbCrLf)
'-- Close the table row --
If iPosition = 7 Then
Response.Write vbTab & "</tr>" & vbCrLf
iPosition = 0
End If
'-- Increment variables --
iCurrent = iCurrent + 1
iPosition = iPosition + 1
iDayofCycle= iDayofCycle + 1
Loop
If iPosition <> 1 Then
Do While iPosition <= 7
Response.Write(vbTab & vbTab & "<td> </td>" & vbCrLf)
iPosition = iPosition + 1
Loop
Response.Write vbTab & "</TR>" & vbCrLf
End If
%>
</table>
<%
objRecordset.Close
Set objRecordset = Nothing
%>
<%
Response.Write("<form action=" & Chr(34) & "calendar.asp" & Chr(34) & " method=" & Chr(34) & "post" & Chr(34) & ">" & Chr(10))
Response.Write("<input type=" & Chr(34) & "submit" & Chr(34) & " name=" & Chr(34) & "AddEvent" & Chr(34) & " value=" & Chr(34) & "Add Event" & Chr(34) & ">" & " ")
Response.Write("</form>")
%>
</center>
</html> and here is a link to an HTML hand coded page to let you know what the calendar would look like if I were successful in connecting the 14 day cycles: http://sightbysite.net/html_cal.htm As you can see, using the date of the month will not suffice, as each month starts on a different day of the week. The calendar also prints the day of the year, but the final product will not. I was just brainstorming to see if I could connect the months together using the day of the year, but have been unsuccessful. Thanks again.
_____________________________
Chris http://www.sightbysite.net
|
|
|
|
rdouglass
Posts: 9205 From: Biddeford, ME USA Status: offline
|
RE: ASP Calendar Help - 4/4/2005 16:15:34
I sent you an email but just in case you don't get it that way, here it is. Replace the current named function on your page with this one: Function ColorShiftDays(iCurrent) DIM myTempDate, myTempWeek, myTempDayOfWeek myTempDate=(Month(dDate) & "/" & iCurrent & "/" & Year(dDate)) myTempWeek=DatePart("ww",myTempDate) myTempDayOfWeek=DatePart("w",myTempDate) IF (myTempWeek MOD 2) = 0 THEN select case (myTempDayOfWeek) case 2,3,6,7 ColorShiftDays = " bgcolor=green " case else ColorShiftDays = " bgcolor=#EBEBEB " end select ELSE select case (myTempDayOfWeek) case 2,3,6,7 ColorShiftDays = " bgcolor=#EBEBEB " case else ColorShiftDays = " bgcolor=green " end select END IF End Function
_____________________________
Don't take you're eye off your final destination. ASP Checkbox Function Tutorial.
|
|
|
|
fredecd
Posts: 312 Joined: 12/3/2003 From: Louisiana, USA Status: offline
|
RE: ASP Calendar Help - 4/4/2005 16:39:27
Thanks a million!! I works great, and I really appreciate it. I hate to ask more of you at this point since you have been such a big help thus far. There is one thing that I see. When the year changes from 2005 to 2006, the pattern loses continuity in transitioning from December 31, 2005 to January 1, 2006. Is there a way to have it change depending on the year so that the patterns remain intact? I will continue to investigate and test on my own until I hear back. Thanks again.
_____________________________
Chris http://www.sightbysite.net
|
|
|
|
rdouglass
Posts: 9205 From: Biddeford, ME USA Status: offline
|
RE: ASP Calendar Help - 4/5/2005 15:25:15
I think I have it. AT the top of your page, add this DIM variable stuff: ... <!--#include file="adovbs.inc"--> <% DIM myBaseDate myBaseDate="01/01/2000" .... I just set an arbitrary date there. If you want to reverse the colors that show up, just set the base date a week later as in: myBaseDate="01/08/2000" Then, change the function I gave you to this version: Function ColorShiftDays(iCurrent) DIM myTempDate, myTempDayOfWeek, numberOfWeeksSinceBase myTempDate=(Month(dDate) & "/" & iCurrent & "/" & Year(dDate)) myTempDayOfWeek=DatePart("w",myTempDate) numberOfWeeksSinceBase = DateDiff("ww",myBaseDate,myTempDate) IF (numberOfWeeksSinceBase MOD 2) = 0 THEN select case (myTempDayOfWeek) case 2,3,6,7 ColorShiftDays = " bgcolor=green " case else ColorShiftDays = " bgcolor=#EBEBEB " end select ELSE select case (myTempDayOfWeek) case 2,3,6,7 ColorShiftDays = " bgcolor=#EBEBEB " case else ColorShiftDays = " bgcolor=green " end select END IF End Function That should do it. What it does is instead of making everything relative to the first week of the year (which my first code did), this one makes it all relative to a base date that I just so happen to choose Jan 1, 2000. Any date would work; it's just the one I chose. Hope it helps.
_____________________________
Don't take you're eye off your final destination. ASP Checkbox Function Tutorial.
|
|
|
|
fredecd
Posts: 312 Joined: 12/3/2003 From: Louisiana, USA Status: offline
|
RE: ASP Calendar Help - 4/5/2005 16:06:35
That helps very much. I now understand how it works in our example. I was thinking that the number was the answer to the division, not the remainder. Thanks.
_____________________________
Chris http://www.sightbysite.net
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|