?? 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 + -