ASP implementation of database remote control

Source: Internet
Author: User
Tags date exit copy count include reference trim
Guangzhou subway Operation Business Headquarters Computer Center Zhou Zhenxi Lully

With the development of computer application, more and more data are stored in the server of the center computer room, because some managers ' geographical location is not in the center room, so it brings the problem of remote management of data. Taking the Library management system of Guangzhou Metro operation headquarters As an example, this paper introduces the concrete methods and steps of using ASP technology to realize the remote control of the database.
The question of the proposed
The Guangzhou Metro Operation Business Headquarters has already realized the computer intranet, because the personal computer after the people after work all is in the shutdown state, in order to enable the staff to be able 24 hours through the networking local computer to know the real time status information of the book material, therefore puts the library data management database on the Computer center server Instead of the personal computer in the reference room. This leads to a remote management problem with the database.
Because only when there is still a copy can be borrowed, employees have to go to the reference room for borrowing procedures, and if no duplicate can be borrowed and I am in urgent need of use, but also can check the information of the borrower, so as to share with the borrower or please return it as soon as possible to borrow. Therefore, the company's reference room book data Management database must be able to query staff to provide copies of the total number of copies, the remaining copy, the borrower and other real-time status information.
To this end, in the operation of the Headquarters intranet home page to the librarian to provide a library of books and materials to manage the entrance. When the librarian entered, the authentication, with the user name and password into the Library information Lending Management page. For the librarian, the database is operated as if it were on the local computer.
The objects used in the operation of the network database are the connection, Response, CreateObject objects of the Request object and the ADO component, and the methods used are mainly the commands of SQL language such as SELECT, Update and so on. The request object is used to retrieve the parameter value from the address bar; The connection object is used to establish and manage a connection between the application and the ODBC database, which has a variety of properties and methods that you can use to open and close the database connection, and to issue a query request to update the information; SQL commands mainly implement the query and update of data records.
Here are the key codes and explanations for each of the main functional modules.
User Login (Login.asp)
<!--#include file= "Adovbs.inc"-->
<%
Get the IP address of the operation computer
Dim ipaddr
IPAddr = Request.ServerVariables ("REMOTE_ADDR")
Restrict access to library data database maintenance system only by computer (fixed IP address) of reference room
If ipaddr<> "172.16.1.56" and Paddr<> "172.16.1.58" and ipaddr<> "172.16.3.61" Then
Iperror=1
End If
Requires that the username and password be entered in double protection from the previous condition, and that the user name and password entered are compared to the user name and password in the user admin database, and if this user and the password are correct, continue
Name=trim (Request ("name"))
Password=trim (Request ("password"))
If name<> "" and password<> "" Then
Set conn=server.createobject ("ADODB. Connection ")
Set rs=server.createobject ("Adodb.recordset")
Sql= "SELECT * from user where username= '" &name& "' and passwd= '" &password& "'"
Set rs=conn.execute (SQL)
......
If not (rs.eof) then
Session ("Pass") =1
Session ("User") =name
Response.Redirect ("bmanage.asp")
......
End If
......
End If
%>
Create a user query interface (bmanage.asp)
Ensure that only people who are logged in can enter
<%
If session ("pass") <>1 Then
Response.Redirect ("Login.asp")
End If
%>
Create a form, give several categories (category number, borrow, title, publisher, editor), for optional query conditions
<form name= "Form_choice" action= "inq_modi.asp" >
<input type= "Radio" name= "Choice" value= "type" > category number
<input type= "Radio" name= "Choice" value= "borrow" checked> lending situation
<input type= "Radio" name= "Choice" value= "title" > title
<input type= "Radio" name= "Choice" value= "Press" > Publishers
<input type= "Radio" name= "Choice" value= "author" > Editor
<b> include: </b>
<input type= "text" name= "include" value= "<%=include%>" maxlength= ">"
<input type= "Submit" name= "submit" value= "Search" >
</form>
Perform query operations (inq_modi.asp)
<!--#include file= "rstomodi.asp"-->
<%
Use the value returned by request to query the database for corresponding records
Choice=request ("Choice")
Include=request ("include")
sql = "SELECT * FROM book directory"
Select Case Choice
Case "Borrow"
sql = SQL & "Where to borrow information like '%" & include & "%"
Titlestr= "Borrowing Situation"
......
End Select
Titlestr = Titlestr & "contains" & Include & "book catalogue"
sql = SQL & "ORDER by category number"
%>
Call rstomodi.asp Display Query results
<%
Set conn = Server.CreateObject ("ADODB. Connection ")
Conn.Open "Driver={microsoft Access driver (*.mdb)}; Dbq= "& Server.MapPath (" Books.mdb ")
Set RS = conn. Execute (SQL)
Rstomoditable RS
%>
Show query Results (rstomodi.asp)
<%
Sub rstomoditable (RS)
' Part I obtains the book serial number and the loan condition field value
For i=0 to Rs. Fields.count-1
Response.Write "<TD>" & Rs. Fields (i). Name & "</TD>"
If Rs. Fields (i). Name = "ordinal" Then
bookidfield= I
End If
If Rs. Fields (i). Name = "Borrow Situation" then
linkfield= I
End If
Next
' Partⅱ Create a loan situation link, call the loan situation to modify the page
While not Rs. Eof
For i=0 to Rs. Fields.count-1
If I <> Linkfield then
If i = Bookidfield Then
Bookidvalue = Rs. Fields (i). Value
End If
If Trim (Rs. Fields (i). Value) <> "" Then
Response.Write "<TD>" & Rs. Fields (i). Value & "</TD>"
Else
Response.Write "<TD>" & "-" & "</TD>"
End If
Else
Linkstr = "<a href=" & "" "&" Bookmodi.asp?bookid= "& Bookidvalue &" ""
Linkstr = linkstr & "target=" & "" "&" _blank "&" "" & ">"
Alignstr = "<p align=" & "" "&" Center "&" "" & ">"
If Trim (Rs. Fields (i). Value) <> "" Then
Response.Write "<TD>" & Alignstr & Linkstr & Rs. Fields (i). Value & "</a>" & "</TD>"
Else
Response.Write "<TD>" & Alignstr & Linkstr & "No" & "</a>" & "</TD>"
End If
End If
Next
Rs. MoveNext
Wend
End Sub
%>
Loan Situation Modification page (bookmodi.asp)
The record that corresponds to the serial number of the request is displayed on the page, and the number of books, borrowing, and borrowing date fields are modified.
<%
Bookid=request ("BookID")
DBPath = Server.MapPath ("Books.mdb")
Set conn = Server.CreateObject ("ADODB. Connection ")
Conn.Open "Driver={microsoft Access driver (*.mdb)}; Dbq= "& DBPath
sql = "SELECT * FROM book directory"
sql = SQL & "Where ordinal =" & BookID
Set RS = conn. Execute (SQL)
%>
Create a form that modifies the number of books, borrowing, and borrowing date fields
<form action= "Bookupdate. Asp? Bookid=<%=bookid%> "method=" POST ">
&LT;TD height= "width=" > Serial number </td>
......
&LT;TD height= "width=" ><%=rs ("serial number")%></td>
......
<input type=text name= "Bnumber" Value=<%=rs ("Number of albums")%> size= "3" >
<input type=text name= "Bperson" value=<%=rs ("borrowing situation")%> ></td>
<input type=text name= "bdate" Value=<%=rs ("borrowing date")%>>
<p><input type= "Submit" value= "Modify" name= "MODIFY" >
<input type= "button" value= "Exit" Name= "Exit" onclick= "Window.close ()" >
</p>
</form>
Save modification Results (bookupdate.asp)
<!--#include file= "Adovbs.inc"-->
<%
Bookid=request ("BookID")
DBPath = SERVER. MapPath ("Books.mdb")
Set conn = Server.CreateObject ("ADODB. Connection ")
Conn.Open "Driver={microsoft Access driver (*.mdb)}; Dbq= "& DBPath
B_number = Request ("Bnumber")
B_person = Request ("Bperson")
B_date = Request ("Bdate")
If Len (b_number) = 0 Then
B_number = 1
End If
If Len (b_person) = 0 Then
B_person = ""
End If
If Len (b_date) = 0 Then
B_date = ""
End If
Set Rs=server. CreateObject ("ADODB.") Recordset ")
Rs. Open "book catalogue", Conn, adOpenDynamic, adlockpessimistic
sql = "Update book catalog"
sql = SQL & "Set lending situation =" & "'" & B_person & ""
sql = SQL &, borrowing date = "&" "& B_date &" "
sql = SQL & ", number of albums =" & "" & B_number & ""
sql = SQL & "Where ordinal =" & BookID
Set RS = conn. Execute (SQL)
%>


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.