用ASP和SQL实现基于Web的事件日历

本文介绍如何建立基于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>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/3627.html