用ASP和SQL實現基于Web的事件日歷
2024-05-04 11:02:55
供稿:網友
本文介紹如何建立基于Web的日歷,同時為不熟悉Active Server Pages(ASP)、SQL和ADO的開發者提供建立Web站點的過程介紹,也為有經驗的開發者提供了Web站點可伸縮性方面的技巧。
隨著網絡應用的發展,基于Web的日歷越來越受到人們的重視,對于顯示諸如最后期限或日程安排之類的重要事件,或顯示誰在什么時候休假,基于Web的日歷都是有用的。本文描述了如何使用IIS和SQL Server內的ASP建立一個非常簡單的基于Web的日歷,并允許你與其他人共享你的日程表或管理一組人員的日歷。
建立SQL服務器端
對Web日歷而言,我們在服務器端僅需保存表明事件性質的一個文本字符串即可,字符串最長為100個字符。設計源代碼如下:
Calendar.sql
-- 創建表
create table Schedule
(
idSchedule smallint identity primary key,
dtDate smalldatetime not null,
vcEvent varchar(100) not null
)
go
-- 存儲過程
create procedure GetSchedule (@nMonth tinyint, @nYear smallint)
as
select idSchedule, convert(varchar, datepart(dd, dtDate)) 'nDay', vcEvent
from Schedule
where datepart(yy, dtDate) = @nYear and datepart(mm, dtDate) = @nMonth
order by datepart(dd, dtDate)
go
create procedure AddEvent (@vcDate varchar(20), @vcEvent varchar(100))
as
insert Schedule
select @vcDate, @vcEvent
go
create procedure DeleteEvent (@idSchedule smallint)
as
delete Schedule where idSchedule = @idSchedule
go
設計ASP客戶端
下圖是Web日歷的主要用戶界面,用戶可以看到哪些事件是已安排的。另外,使用底部的鏈接可以在日歷中按月前后翻動。
ASP的實現代碼如下:
header.asp
<@ LANGUAGE="VBSCRIPT"
ENABLESESSIONSTATE = False %>
<%
' 目的:表頭包括用來啟動所有頁的文件
' 還包括全局函數
Option Explicit
Response.Buffer = True
Response.Expires = 0
sub Doheader(strTitle)
%>
<html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
<title>Event Calendar - <%= strTitle %></title>
</head>
<body bgcolor="white" link="blue" alink="blue" vlink="blue">
<basefont face="Verdana, Arial">
<center><h1>Event Calendar</h1>