本文介紹如何建立基於Web的日曆,同時為不熟悉ActiveServerPages(ASP)、SQL和ADO的開發者提供建立Web站點的過程介紹,也為有經驗的開發者提供了Web站點可伸縮性方面的技巧。
隨著網絡應用的發展,基於Web的日曆越來越受到人們的重視,對於顯示諸如最後期限或日程安排之類的重要事件,或顯示誰在什麼時候休假,基於Web的日曆都是有用的。本文描述瞭如何使用IIS和SQLServer內的ASP建立一個非常簡單的基於Web的日曆,並允許你與其他人共享你的日程表或管理一組人員的日曆。
建立SQL服務器端
對Web日曆而言,我們在服務器端僅需保存表明事件性質的一個文本字符串即可,字符串最長為100個字符。設計源代碼如下:
Calendar.sql
--創建表
createtableSchedule
(
idSchedulesmallintidentityprimarykey,
dtDatesmalldatetimenotnull,
vcEventvarchar(100)notnull
)
go
--存儲過程
createprocedureGetSchedule(@nMonthtinyint,@nYearsmallint)
as
selectidSchedule,convert(varchar,datepart(dd,dtDate))'nDay',vcEvent
fromSchedule
wheredatepart(yy,dtDate)=@nYearanddatepart(mm,dtDate)=@nMonth
orderbydatepart(dd,dtDate)
go
createprocedureAddEvent(@vcDatevarchar(20),@vcEventvarchar(100))
as
insertSchedule
select@vcDate,@vcEvent
go
createprocedureDeleteEvent(@idSchedulesmallint)
as
deleteSchedulewhereidSchedule=@idSchedule
go
設計ASP客戶端
下圖是Web日曆的主要用戶界面,用戶可以看到哪些事件是已安排的。另外,使用底部的鏈接可以在日曆中按月前後翻動。
ASP的實現代碼如下:
header.asp
<@LANGUAGE="VBSCRIPT"
ENABLESESSIONSTATE=False%>
<%
'目的:表頭包括用來啟動所有頁的文件
'還包括全局函數
OptionExplicit
Response.Buffer=True
Response.Expires=0
subDoheader(strTitle)
%>
<html>
<head>
<METAHTTP-EQUIV="Content-Type"CONTENT="text/html;charset=gb2312">
<title>EventCalendar-<%=strTitle%></title>
</head>
<bodybgcolor="white"link="blue"alink="blue"vlink="blue">
<basefontface="Verdana,Arial">
<center><h1>EventCalendar</h1>