<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type"
content="text/html; charset=big5">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
<title>日歷演示程序</title>
<style type="text/css">
<!--
td { font-family: "宋體"; font-size: 9pt; font-style: normal; font-weight: normal; color: #9999FF}
a:link { font-family: "宋體"; font-size: 9pt; font-style: normal; font-weight: normal; color: #cc3300;TEXT-DECORATION: none}
a:visited {font-family: "宋體"; font-size: 9pt; font-style: normal; font-weight: normal; color: #cc3300;TEXT-DECORATION: none}
a:hover {font-family: "宋體"; font-size: 9pt; font-style: normal; font-weight: normal; color: #cc3300;TEXT-DECORATION: underline
}
-->
</style>
<%
' 要調用的函數聲明
'根據年份及月份得到每月的總天數
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(dAnyDayInTheMonth)
Dim dTemp
dTemp = DateAdd("d", -(Day(dAnyDayInTheMonth) - 1), dAnyDayInTheMonth)
GetWeekdayMonthStartsOn = WeekDay(dTemp)
End Function
'得到當前一個月的上一個月.
Function SubtractOneMonth(dDate)
SubtractOneMonth = DateAdd("m", -1, dDate)
End Function
'得到當前一個月的下一個月.
Function AddOneMonth(dDate)
AddOneMonth = DateAdd("m", 1, dDate)
End Function
' 函數聲明結束
Dim dDate ' 日歷顯示的日期
Dim iDOW ' 每一月開始的日期
Dim iCurrent ' 當前日期
Dim iPosition ' 表格中的當前位置
' 得到選擇的日期并檢查日期的合法性
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 Len(Request.QueryString("month")) <> 0 Or Len(Request.QueryString("day")) <> 0 Or Len(Request.QueryString("year")) <> 0 Or Len(Request.QueryString("date")) <> 0 Then
Response.Write "您所選擇的日期格式不正確,系統會使用當前日期.<BR><BR>"
End If
End If
End If
'得到日期后我們先得到這個月的天數及這個月的起始日期.
iDIM = GetDaysInMonth(Month(dDate), Year(dDate))
iDOW = GetWeekdayMonthStartsOn(dDate)
%>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><form action=""
method="GET">
<p>
年<input type="text" size="3" name="year" value="<%if Request("year")="" then response.write year(now()) else response.write Request("year")%>">
月<select name="month" size="1">
<%for i =1 to 12%>
<option value="<%=i%>" <%if trim(i)=trim(Request("month")) then response.write "selected"%>><%=i%></option>
<%next%>
</select>
日<select name="day" size="1">
<%for j =1 to 31%>
<option value="<%=j%>" <%if trim(j)=trim(Request("day")) then response.write "selected"%>><%=j%></option>
<%next%>
</select>
<input type="submit" value="顯示日期"> </p>
</form>
</td>
</tr>
</table>
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td><table border="1" cellspacing="0" bgcolor="#FDF8D0">
<tr>
<td align="center" colspan="7" bgcolor="#000099"><table
border="0" cellpadding="0" cellspacing="0"
width="100%">
<tr>
<td align="right"><a
href="?date=<%= SubtractOneMonth(dDate) %>">上一月</a></td>
<td align="center"><font color="#FFFF00"><%= MonthName(Month(dDate)) & " " & Year(dDate) %></font></td>
<td><a
href="?date=<%= AddOneMonth(dDate) %>">下一月</a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center" bgcolor="#0000CC"><font
color="#FF0000">星期日</font>
<img src="images/spacer.gif" width="60"
height="1"></td>
<td align="center" bgcolor="#0000CC"><font
color="#FFFF00">星期一</font>
<img src="images/spacer.gif" width="60"
height="1"></td>
<td align="center" bgcolor="#0000CC"><font
color="#FFFF00">星期二</font>
<img src="images/spacer.gif" width="60"
height="1"></td>
<td align="center" bgcolor="#0000CC"><font
color="#FFFF00">星期三</font>
<img src="images/spacer.gif" width="60"
height="1"></td>
<td align="center" bgcolor="#0000CC"><font
color="#FFFF00">星期四</font>
<img src="images/spacer.gif" width="60"
height="1"></td>
<td align="center" bgcolor="#0000CC"><font
color="#FFFF00">星期五</font>
<img src="images/spacer.gif" width="60"
height="1"></td>
<td align="center" bgcolor="#0000CC"><font
color="#FF0000">星期六</font>
<img src="images/spacer.gif" width="60"
height="1"></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
' 繪制這個月的日歷
iCurrent = 1
iPosition = iDOW
Do While iCurrent <= iDIM
' 如果是一行的開頭就使用 TR 標記
If iPosition = 1 Then
Response.Write vbTab & "<TR>" & vbCrLf
End If
' 如果這一天是我們選擇的日期就高亮度顯示該日期.
If iCurrent = Day(dDate) Then
Response.Write vbTab & vbTab & "<TD BGCOLOR=#00FFFF><FONT SIZE=""-1"">" & iCurrent & "</FONT><BR><BR></TD>" & vbCrLf
Else
Response.Write vbTab & vbTab & "<TD><A HREF=""?date=" & Month(dDate) & "-" & iCurrent & "-" & Year(dDate) & """><FONT SIZE=""-1"">" & iCurrent & "</FONT></A><BR><BR></TD>" & vbCrLf
End If
' 如果滿一周的話表格就另起一行
If iPosition = 7 Then
Response.Write vbTab & "</TR>" & vbCrLf
iPosition = 0
End If
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>
</td>
</tr>
</table>
</body>
</html>