Using ASP to implement Web data statistic, report and print skillfully

Source: Internet
Author: User
Tags dsn implement odbc variable
web| Printing | data | Statistics Abstract: This article elaborated one kind uses the ASP to realize the Web data statistics, the report the basic idea and the realization method, simultaneously provides one kind of clever call Word printing report the solution.

Keywords: ASP, data statistics, reports, printing, Word



1. Introduction

With the rapid development of Internet, the business application system based on Web development is more and more, such as office automation, electronic commerce and Management Information System (MIS). These web business application systems often involve statistics, reporting, and printing of data. ASP has great advantages in implementing dynamic interaction and generating dynamic pages, but it encounters a lot of trouble when dealing with complex data statistics, reports and printing. This paper expounds the basic idea and realization method of using ASP to realize web data statistic and report, and provides a solution to call Word Print report skillfully.



2. Application Example

If a company uses the network MIS system to manage the staff of the company, it will necessarily involve the staff statistics of each department. For simplicity's sake, suppose the final statistical report is as follows:



Company staff Statistics

Department
Total
Employee Name

Marketing Department
2
Tom



John doe

Research and Development Department
3
Harry



Zhao Liu



Liu Qi

Total Staff
5





Compared with the traditional stand-alone MIS system, using ASP to realize the above data statistics, report and print in the network MIS system will encounter the following problems:

(1) Data statistics need to be classified according to the Department of Statistics, at the same time to write down the specific list of employees in each department.

(2) When the report is generated, it is necessary to dynamically draw several rows of tables, while remaining blank in the appropriate place.

(3) Form printing can be simply printed on the page, but the effect is not good, and not easy to control.



3. Brief introduction of Implementation method

Web based business applications generally use a three-tier structure, the client is a common web browser, the intermediary business logic application layer is stored on the Web server, the database interface on the Web server to access the background database. The process of implementing Web data statistics, reports and printing using ASP is shown in the following illustration:


Browser

Html

VBScript

Statistics

Report

Word

Object

Web server

Business logic Implementation

Database

Access interface

Number

According

Library

Word print locally












(1) The client sends a data statistics request to the Web server.

(2) The Web server executes the SQL statement, obtains the statistic data from the backstage database, produces the report dynamically on the page.

(3) Run a script on the client and use the VBScript scripting function to create an instance of the Document object for Word createobject locally, by creating a Word document on the client, setting the table properties, and then filling the report data on the page into a local Word table. Finally, save the document and perform local word printing.



4, the Realization process analysis

(1) Database connection

First, the database (Data.mdb) is established, and the Simple Employee data table (personnel) structure is as follows:

personnel:department, text; name, text;

An ODBC data source (DSN) is then established and the DSN is used to point to the ODBC database.

(2) Program code Analysis (this only analyzes the statistical reporting program tongji.asp)

<%

sql = "Select Department,count (department) from personnel group by Department"///To classify records by department

Set Cnn = Server.CreateObject ("ADODB.") Connection ")//Connection database

Cnn.open "Data"

Set Rs = Server.CreateObject ("ADODB.") Recordset ")

Rs.cursortype = 3

Rs.locktype = 3

Rs.Open SQL, Cnn

If rs.eof Then//If no record is completed

Response.End

End If

%>


The table headers and output headers are shown below

<p align= "center" ><b><font size= "4" > Employee statistics </font></b></p>

<div align= "center" >

<table id= "Data" border= "1" width= "606" height= "cellpadding=" "0" cellspacing= "0" style= "Border-collapse: Collapse "bordercolor=" #111111 >/NOTE: The ID of the form is indicated here as data

<tr>

&LT;TD width= "height=" >

<p align= "center" ><font size= "2" > Department </font></td>

&LT;TD width= "height=" >

<p align= "center" ><font size= "2" > Total </font></td>

&LT;TD width= "413" height= ">"

<p align= "center" ><font size= "2" > Employee name </font></td>

</tr>



<%

Hj=0//Set Variable, total number of people total initial value is 0

The following while loop completes statistics and reports sequentially by department

while (not rs.eof)

Departmenttmp=rs ("department")//Set temporary variable, save current department name

Sqlstr= "SELECT * from personnel where department= '" &departmenttmp& ""//Find all employees in current department

Set conn = Server.CreateObject ("ADODB. Connection ")//Reconnect the database again

Conn. Open "Data"

Set RSS = Server.CreateObject ("ADODB.") Recordset ")

Rss. CursorType = 3

Rss. LockType = 3

Rss. Open SQLSTR, Conn

number=0//Set Variable, total number of current department totals initial value is 0

The following while loop calculates the total number of current departments

while (not rss.eof)

Rss.movenext

Number=number+1

Wend

The total number of hj=hj+number//is the sum of the number of departments

Rss.movefirst

flag=0//Set variable, flag is used to determine whether the current department appears for the first time, with an initial value of 0

The following while loop outputs the current departmental statistics and employee lists

while (not rss.eof)%>

<tr>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.