📄 conn.asp
字号:
<!--#include file="safe.asp"-->
<%
'Option Explicit
'代码开始
'数据库配置,这里针对access数据库
dim dbpath,dbpwd,url
dbpath = "database/db.mdb" '数据库位置
dbpwd = "" '数据库密码
'数据库操作类的使用
dim dbo,rs,sqlstr
Set dbo = new db '创建对象
dbo.Getdbpath = dbpath '取得配置
dbo.Getdbpwd = dbpwd '取得配置
dbo.Getconn() '打开数据库连接
sub ch()
if request.cookies("loginok")<>"ok" then response.redirect("error.asp?errid=2")
end sub
'定义类要使用的全局常量
Const Btn_First="<font face=webdings>9</font>" '定义第一页按钮显示样式
Const Btn_Prev="<font face=webdings>3</font>" '定义前一页按钮显示样式
Const Btn_Next="<font face=webdings>4</font>" '定义下一页按钮显示样式
Const Btn_Last="<font face=webdings>:</font>" '定义最后一页按钮显示样式
Const P_Align="Center" '定义分页信息对齐方式
Const P_Width="100%" '定义分页信息框大小
'数据库操作类开始
class db
'类的使用方法演示一
'dim dbpath,dbpwd
'dbpath = "data/db_name.mdb"
'dbpwd = "db_pwd"
'The database operating and initializing
'dim dbo,rs,sqlstr
'Set dbo = new db
'dbo.Getdbpath = dbpath
'dbo.Getdbpwd = dbpwd
'dbo.Getconn()
'set rs = dbo.Getrs()
'Response.Write header
'sqlstr = "select * from main order by id ASC"
'rs = dbo.query(sqlstr)
'Response.Write rs("title")
'Response.Write rs("content")
'dbo.dbclose()
'Response.Write booter
'response.end
'定义私有变量
private c_dbpath,c_dbpwd,c_rs,c_conn,c_sql,P_PageCount,P_PageSize,Str_errors,int_curpage,str_URL,int_totalPage,int_totalRecord
'属性的取得
Public Property Let Getdbpath(dbpath)
c_dbpath = dbpath
End Property
Public Property Let Getdbpwd(dbpwd)
c_dbpwd = dbpwd
End Property
Public Property Get Getconn()
dim connstr
set c_conn = Server.CreateObject("ADODB.Connection")
connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(c_dbpath)&";Jet OLEDB:Database Password="&c_dbpwd
c_conn.open connstr
set Getconn = c_conn
End Property
'取得记录集,用于分页
Public Property Get GetRs()
Set c_rs=Server.createobject("adodb.recordset")
c_rs.PageSize=PageSize
c_rs.Open c_sql,c_conn,1,1
If not(c_Rs.eof and c_RS.BOF) Then
If int_curpage>c_RS.PageCount Then
int_curpage=c_RS.PageCount
End If
c_Rs.AbsolutePage=int_curpage
End If
Set GetRs=c_rs
End Property
'取得记录集,用于非分页
Public Property Get GetRs1()
Set c_rs=Server.createobject("adodb.recordset")
c_rs.Open c_sql,c_conn,1,3
Set GetRs1=c_rs
End Property
'取得SQL查询
Public Property Let Getsql(sqlstr)
c_sql=sqlstr
End Property
Public Property Let PageSize(int_PageSize)
If IsNumeric(Int_Pagesize) Then
P_PageSize=CLng(int_PageSize)
Else
str_error=str_error & "PageSize的参数不正确"
ShowError()
End If
End Property
Public Property Get PageSize
If P_PageSize="" or (not(IsNumeric(P_PageSize))) Then
PageSize=10
Else
PageSize=P_PageSize
End If
End Property
'设定一些参数的黙认值
Private Sub Class_Initialize
P_PageSize=10 '设定分页的默认值为10
If request("page")="" Then
int_curpage=1
ElseIf not(IsNumeric(request("page"))) Then
int_curpage=1
ElseIf CInt(Trim(request("page")))<1 Then
int_curpage=1
Else
Int_curpage=CInt(Trim(request("page")))
End If
End Sub
'ShowPage 创建分页导航条
'有首页、前一页、下一页、末页、还有数字导航
Public Sub ShowPage()
Dim str_tmp
int_totalRecord=c_RS.RecordCount
If int_totalRecord<=0 Then
str_error=str_error & "总记录数为零,请输入数据"
Call ShowError()
End If
If int_totalRecord<pagesize Then
int_TotalPage=1
Else
If int_totalRecord mod PageSize =0 Then
int_TotalPage = CLng(int_TotalRecord / P_PageSize * -1)*-1
Else
int_TotalPage = CLng(int_TotalRecord / P_PageSize * -1)*-1+1
End If
End If
If Int_curpage>int_Totalpage Then
int_curpage=int_TotalPage
End If
'显示分页信息,各个模块根据自己要求更改显求位置
response.write "<table border=0 width="&P_Width&"><tr><td align="&P_Align&">"
str_tmp=ShowFirstPrv
response.write str_tmp
str_tmp=showNumBtn
response.write str_tmp
str_tmp=ShowNextLast
response.write str_tmp
str_tmp=ShowPageInfo
response.write str_tmp
response.write "</td></tr></table>"
End Sub
'ShowFirstPrv 显示首页、前一页
Private Function ShowFirstPrv()
Dim Str_tmp,int_prvpage
If int_curpage=1 Then
str_tmp=Btn_First&" "&Btn_Prev
Else
int_prvpage=int_curpage-1
str_tmp="<a href="&geturl&"1>"&Btn_First&"</a> <a href="&geturl & int_prvpage &">"& Btn_Prev&"</a>"
End If
ShowFirstPrv=str_tmp
End Function
'ShowNextLast 下一页、末页
Private Function ShowNextLast()
Dim str_tmp,int_Nextpage
If Int_curpage>=int_totalpage Then
str_tmp=Btn_Next & " " & Btn_Last
Else
Int_NextPage=int_curpage+1
str_tmp="<a href="& geturl & int_NextPage &">"&Btn_Next&"</a> <a href="&geturl & int_totalpage &">"& Btn_Last&"</a>"
End If
ShowNextLast=str_tmp
End Function
'ShowNumBtn 数字导航
Private Function showNumBtn()
Dim i,str_tmp
For i=1 to int_totalpage
str_tmp=str_tmp & "<a href="& geturl & i &">["&i&"]</a> "
Next
showNumBtn=str_tmp
End Function
'ShowPageInfo 分页信息
'更据要求自行修改
Private Function ShowPageInfo()
Dim str_tmp
str_tmp="页次:"&int_curpage&"/"&int_totalpage&"页 共"&int_totalrecord&"条记录 "&P_PageSize&"条/每页"
ShowPageInfo=str_tmp
End Function
'GetURL 得到当前的URL
'更据URL参数不同,获取不同的结果
Private Function GetURL()
Dim strurl,str_url,i,j,search_str,result_url
search_str="page="
strurl=Request.ServerVariables("URL")
Strurl=split(strurl,"/")
i=UBound(strurl,1)
str_url=strurl(i)'得到当前页文件名
str_params=Request.ServerVariables("QUERY_STRING")
If str_params="" Then
result_url=str_url & "?page="
Else
If InstrRev(str_params,search_str)=0 Then
result_url=str_url & "?" & str_params &"&page="
Else
j=InstrRev(str_params,search_str)-2
If j=-1 Then
result_url=str_url & "?page="
Else
str_params=Left(str_params,j)
result_url=str_url & "?" & str_params &"&page="
End If
End If
End If
GetURL=result_url
End Function
'ShowError 错误提示
Private Sub ShowError()
If str_Error <> "" Then
Response.Write("<font color=""#FF0000""><br><b>" & SW_Error & "</font>")
Response.End
End If
End Sub
public sub query(sqlstr)
c_conn.execute sqlstr
end sub
public sub dbclose()
c_conn.close
end sub
' 设置 Terminate 事件。
Private Sub Class_Terminate
c_rs.close
Set c_rs=nothing
End Sub
end class
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -