This article describes how to create a web-based calendar and how to create a web site for developers who are not familiar with Active Server Pages (ASP), SQL, and ADO, it also provides experienced developers with Web site scalability skills.
With the development of network applications, Web-based calendars are becoming more and more important. For important events such as the deadline or schedule, or who is on vacation, web-based calendars are useful. This article describes how to use ASP in IIS and SQL Server to create a simple web-based calendar and allow you to share your calendar with others or manage the calendar of a group of people.
Create an SQL Server
For a web calendar, you only need to save a text string indicating the event nature on the server side. The string can contain a maximum of 100 characters. DesignSource codeAs 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
Design ASP Client
Is the main user interface of the Web calendar. You can see which events have been scheduled. In addition, you can use the link at the bottom to flip back and forth on a calendar month.
ASP implementationCodeAs follows:
Header. asp
<@ Language = "VBScript"
Enablesessionstate = false %>
<%
'Purpose: the header contains 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" alink = "blue" vlink = "blue">
<Basefont face = "verdana, Arial">
<Center> <H3> <% = strtitle %>
<%
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 need to call the execute method of the connection object and pass in the text string of the command to be executed. Once the record set is available, we can loop through it. Header. asp contains the function for getting 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 at the end of the function to output a new connection.
Optimized Performance
ASP makes it easy to create web pages, but if you want to create a site that can adapt to a large number of users, You need to carefully consider encoding. The following describes several methods to enhance web calendar-based scalability. These methods can also be used to improve the performance of any ASP-based Web site.
1. SQL Optimization
An easy way to improve the site performance is to add an index to the date field of the Schedule table. In this way, it searches between given dates and thus accelerates the getevents storage process.
For small websites, we can install SQL and IIS on the same server. Once the site traffic begins to grow, we can move SQL to its own server. When the traffic increases further, we can add multiple IIS servers that all point to the same SQL Server. If the SQL server's traffic increases excessively, it can also split the data into different servers. We can allocate an odd number of months to one server and an even number of months to another server, of course, you need to modify the header. getdataconnection in ASP, so that it provides you with the correct connection based on this month.
2. asp Optimization
The main Optimization Method of ASP interpretation will be to use cache pages so that they do not need to be explained every time they are read. The simplest way to do this is to use the ASP application object. To do this, you only need to save the HTML to an application containing the month and year names.ProgramIn a variable, such as a Calendar07-2000. Then, when the event calendar page is displayed, first check whether the calendar is saved in the application variable. If yes, you only need to retrieve it, this method will greatly speed up the website Query Process. The following code shows the 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 you change events of a month on the events. ASP page, you need to clear the Application variables of the month to reflect the changes of these events.
Security
There are several methods to achieve security on the site. For Intranet sites, Windows NT-based authentication is the easiest to set, because your users are likely to have logged on to the network. You can have all users view the event calendar page, but only the administrator can access the Add/Remove Events page.