With the development of web applications, web-based calendars are attracting more and more attention, and web calendars can be used to display important events. This article is wrong. New Technology Channel Editor introduces how to use ASP in IIS and SQL Server to create a very simple web-based calendar and allows you to share a calendar with others or manage a group of people's calendar.
Establish a SQL server
For the Web Calendar, we only need to save a text string indicating the nature of the event on the server side, and the string is up to 100 characters long. The design source code is as follows:
Calendar.sql
-- Create a table
create table Schedule
(
idSchedule smallint identity primary key,
dtDate smalldatetime not null,
vcEvent varchar(100) not null
)
go
--Stored Procedure
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
Designing an ASP client
The following figure is the main user interface of the Web calendar, where users can see which events are scheduled. Also, use the link at the bottom to flip around the calendar by month.
The implementation code of ASP is as follows:
header.asp
<@ LANGUAGE="VBSCRIPT"
ENABLESESSIONSTATE = False %>
<%
' Purpose: The header includes the files used to start all pages
' Also includes global functions
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" link="blue" vlink="blue">
<basefont face="Verdana, Arial">
<center><h1>Event Calendar</h1>
<h3><%= strTitle %></h3>
<%
end sub
function GetDataConnection()
dim oConn, strConn
Set oConn = Server.CreateObject("ADODB.Connection")
strConn = "Provider=SQLOLEDB; Data Source=adspm; Initial Catalog=TeamWeb; "
strConn = strConn && "User Id=TeamWeb; Password=x"
oConn.Open strConn
set GetDataConnection = oConn
end function
%>
With ADO, we can easily connect ASP pages to SQL databases. First we need to create a connection to the database. To obtain the record set, we call the Execute method of the Connection object, passing in the text string of the command you want to execute, and once the record set is available, we can loop in it. header.asp contains functions to get data connections, which means that if the data source changes, we only have one location to edit the connection information (server, user, and password). Note that as a result, we must use the set command to pass out a new connection at the end of the function.
Optimize performance
ASP makes it easy to build web pages, but if you want to build a site that can accommodate a large number of users, you need to think carefully about coding. Below, the author will introduce several methods to enhance the scalability of Web calendars, which can also be used to improve the performance of any ASP-based Web site.
1.SQL optimization
An easy way to improve site performance is to add an index to the date field of the Schedule table, so that it will look up between given dates, thus speeding up the stored procedure of GetEvents.
For small sites, we can install SQL and IIS on the same server. Once the site visits start to grow, we can move SQL to its own server. When the visits grow further, we can add multiple IIS servers that both point to the same SQL server. If the SQL server's traffic is excessively growing, we can also split the data to different servers, we can allocate odd months to one server and even months to another server, of course, this requires modifying GetDataConnection in header.asp so that it provides you with the correct connection based on this month.
2.ASP optimization
The main optimization method for ASP interpretation would be to leverage cached pages so that they are interpreted without needing to be interpreted every read. The easiest way to do this is by using the ASP Application object. To do this, you simply save the HTML into an application variable (e.g. Calendar07-2000) with the month and year names. Then, when the Event Calendar page is displayed, you first check to see if the calendar is already saved in the application variable, if so, just retrieve it, which greatly speeds up the query process of the website. The following code shows the working process:
<<do header>>
ShowCalendar(nMonth, nYear)
<<do Footer>>
sub ShowCalendar(nMonth, nYear)
if Application("Calendar" && nMonth && "-" && nYear) = "" then
<<Build Calendar>>
Application("Calendar" && nMonth && "-" && nYear) = <<Calendar>>
End if
Response.Write Application("Calendar" && nMonth && "-" && nYear)
End sub
Of course, when changing events for a month on the Events.asp page, you need to clear the application variables for that month to reflect the changes in those events.
Security
There are several ways to achieve security on this site. For intranet sites, Windows NT-based verification is the easiest to set up because your users will most likely be logged into the network. You can allow all users to view the Event Calendar page, but only administrators can access the Add/Remove Events page.
This article introduces the method of ASP and SQL to implement a web-based event calendar. I believe everyone understands it. If you want to learn more technical content, please continue to pay attention to the wrong new technology channel!