?? default.aspx
字號:
<%--導(dǎo)入名稱空間--%>
<% @ Import Namespace="System.Data" %>
<% @ Import Namespace="System.Data.OleDb" %>
<% @ Import Namespace="System.Xml" %>
<% @ Import Namespace="System.IO" %>
<%server.scripttimeout=300 '設(shè)置頁面腳本超時,請不要刪除,防止程序產(chǎn)生錯誤引起服務(wù)器崩潰%>
<%--
版權(quán)信息
程序名稱:互動.NET單用戶留言簿
程序版本: Ver1.5
數(shù)據(jù)庫:ACCESS2000
開發(fā)體系:Asp.Net
開發(fā)語言:Vb.Net
開發(fā)工具:EditPlus2.11,Vs.Net
開發(fā)作者:小寶.NET
作者Email:webmaster@chinagz.net
作者主頁:http://asp.chinagz.net
MSN:webmaster@chinagz.net
備注:您可以免費使用本留言簿,也可任意對本留言簿作出修改,但請修改后Email原作者一份以作相互學(xué)習(xí)。
--%>
<Script Runat="Server">
'初始化變量
Dim myconn As OleDbConnection
Dim RecordCount,PageCount,CurrentPage,i As integer
Dim codemessage As String
dim ds as new dataset()
Dim dsxml As New dataset()
Dim pagesize as integer = ConfigurationSettings.AppSettings("每頁顯示留言數(shù)")
'本版本優(yōu)化了代碼,并且增加了代碼注釋。
'以下是子程序,用以處理各種事件。
Public Sub Page_Load(obj As object,e As eventargs)
'連接數(shù)據(jù)庫
myconn= New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source="&server.MapPath(ConfigurationSettings.AppSettings("數(shù)據(jù)庫路徑"))&"")
myconn.open()
'如果有提交信號,執(zhí)行添加留言代碼。
if request.querystring("post") = "true" then
dim content as string=replace(request.form("content"),"<","<")
content=replace(content,">",">")
content=replace(content,chr(13),"<br>")
content=replace(content," "," ")
Dim updatecomm As New oledbcommand("insert into guest (name,sex,qq,email,homepage,emot,content,face,caption,ip) values ('"& request.form("username") &"','"& request.form("sex") &"','"& request.form("qq") &"','"& request.form("email") &"','"& request.form("homepage") &"','"& request.form("emot") &"','"& content &"','"& request.form("face") &"','"& request.form("caption") &"','"& request.servervariables("remote_addr") &"')",myconn)
updatecomm.executenonquery()
myconn.close()
myconn.dispose()
response.redirect("default.aspx")
end if
'如果有刪除信號,執(zhí)行刪除代碼。
if request.querystring("del")<>"" and session("isadmin")<>"" then
Dim delcomm As New oledbcommand("delete * from guest where id="&request.querystring("del"),myconn)
delcomm.executenonquery()
myconn.close()
myconn.dispose()
response.redirect("default.aspx")
end if
If Not Ispostback then
'若頁面未被提交,初始化留言簿設(shè)置。
systemhome.text=ConfigurationSettings.AppSettings("網(wǎng)站名稱")
systemhome1.text=ConfigurationSettings.AppSettings("網(wǎng)站名稱")
systemname.text=ConfigurationSettings.AppSettings("管理員")
link.href="mailto:"+ConfigurationSettings.AppSettings("管理員郵箱")
link1.href=ConfigurationSettings.AppSettings("網(wǎng)站地址")
linkhome.navigateurl=ConfigurationSettings.AppSettings("網(wǎng)站地址")
logo.imageurl=ConfigurationSettings.AppSettings("留言簿logo")
'如果是管理員,執(zhí)行代碼
if session("isadmin")<>"" then
goadmin.attributes("onclick")="MM_showHideLayers('setup','','show','postcontent','','hide','admin','','hide')"
setimage.imageurl="Images/button/setup.gif"
setimage.alternatetext="管理員高級設(shè)置"
Dim strfpath As string=server.mappath("web.config")
dsxml.readxml(strfpath)
setname.text=dsxml.Tables(1).Rows(0)(1)
sethomepage.text=dsxml.Tables(1).Rows(1)(1)
seturl.text=dsxml.Tables(1).Rows(2)(1)
setemail.text=dsxml.Tables(1).Rows(3)(1)
setpage.text=dsxml.Tables(1).Rows(5)(1)
setlogo.text=dsxml.Tables(1).Rows(6)(1)
setbgcolor.text=replace(dsxml.Tables(1).Rows(7)(1),"#","")
setlinebg.text=replace(dsxml.Tables(1).Rows(8)(1),"#","")
setline.text=replace(dsxml.Tables(1).Rows(9)(1),"#","")
setrebg.text=replace(dsxml.Tables(1).Rows(10)(1),"#","")
setlink.text=replace(dsxml.Tables(1).Rows(11)(1),"#","")
settext.text=replace(dsxml.Tables(1).Rows(12)(1),"#","")
setretext.text=replace(dsxml.Tables(1).Rows(13)(1),"#","")
setadmin.text=dsxml.Tables(1).Rows(14)(1)
setpassword.text=dsxml.Tables(1).Rows(15)(1)
mailserver.text=dsxml.Tables(1).Rows(16)(1)
replymail.text=dsxml.Tables(1).Rows(17)(1)
dsxml.clear()
Else
goadmin.attributes("onclick")="MM_showHideLayers('admin','','show','postcontent','','hide')"
setimage.imageurl="Images/button/button2.gif"
setimage.alternatetext="管理登錄"
end if
'分頁設(shè)置
viewstate("state")="all"
CurrentPage=0
viewstate("pageindex")=0
Dim intcount
Dim mycomm As New oledbcommand("select count(*) as rs from guest",myconn)
Dim dr As oledbdatareader = mycomm.executereader()
If dr.read() then
intcount=dr("rs")
else
intcount=0
End if
dr.close()
'計算共有多少條記錄
recordcount = intcount
lblRecordCount.text=recordcount
'計算共有多少頁
if recordcount mod pagesize=0 then
PageCount = recordcount\PageSize
else
PageCount = recordcount\PageSize +1
end if
lblpagecount.text=pagecount.tostring()
viewstate("pagecount")=pagecount
DbListBind()
End If
'初始化結(jié)束
End Sub
Public Sub DbListBind()
dim startindex As integer
'導(dǎo)入數(shù)據(jù)起始地址
StartIndex = CurrentPage*PageSize
Dim strSel As string = "select * from guest order by redate desc"
Dim MyAdapter As New OleDbDataAdapter(strSel,myconn)
MyAdapter.Fill(ds,startindex,PageSize,"guest")
lbnnextpage.enabled=true
lbnprevpage.enabled=true
lbnnextpage.imageurl="images/button/down.gif"
lbnprevpage.imageurl="images/button/up.gif"
If currentpage>=pagecount-1 Then
lbnnextpage.enabled=false
lbnnextpage.imageurl="images/button/down0.gif"
End If
If currentpage=0 Then
lbnprevpage.enabled=false
lbnprevpage.imageurl="images/button/up0.gif"
End If
lblcurrentpage.text=currentpage+1
End Sub
Public Sub onclick(obj As object,e As commandeventargs)'按鍵觸發(fā)的事件
currentpage=viewstate("pageindex")
pagecount=viewstate("pagecount")
Dim cmd As string=e.commandname
Select Case cmd
Case "next"
If currentpage<pagecount-1 Then currentpage=currentpage+1
Case "prev"
If currentpage>0 Then currentpage=currentpage-1
End Select
viewstate("pageindex")=currentpage
If viewstate("state")="all" Then
DbListBind()
Else
DBListBindSearch()
End If
End Sub
Public Sub GoToSearch(obj As object,e As eventargs)'處理搜索事件
Dim searchkey As String =search.text
Dim searchcount As integer
viewstate("state")=searchkey
CurrentPage=0
viewstate("pageindex")=0
Dim mycomm As New oledbcommand("select count(*) as rs1 from guest where name like '%"& searchkey &"%' or caption like '%"& searchkey &"%' or content like '%"& searchkey &"%' or reply like '%"& searchkey &"%'",myconn)
Dim dr1 As oledbdatareader = mycomm.executereader()
If dr1.read() then
searchcount=dr1("rs1")
else
searchcount=0
End if
dr1.close()
'計算搜索共有多少條符合記錄
recordcount = searchcount
lblRecordCount.text=recordcount
'計算符合的記錄共有多少頁
if recordcount mod pagesize=0 then
PageCount = recordcount\PageSize
else
PageCount = recordcount\PageSize +1
end if
lblpagecount.text=pagecount.tostring()
viewstate("pagecount")=pagecount
'數(shù)據(jù)邦定
dim startindex1 As integer
StartIndex1 = CurrentPage*PageSize
Dim MyAdapter1 As New OleDbDataAdapter("select * from guest where name like '%"& searchkey &"%' or caption like '%"& searchkey &"%' or content like '%"& searchkey &"%' or reply like '%"& searchkey &"%' order by id desc",myconn)
MyAdapter1.Fill(ds,startindex1,PageSize,"guest")
lbnnextpage.enabled=true
lbnprevpage.enabled=true
lbnnextpage.imageurl="images/button/down.gif"
lbnprevpage.imageurl="images/button/up.gif"
If currentpage>=pagecount-1 Then
lbnnextpage.enabled=false
lbnnextpage.imageurl="images/button/down0.gif"
End If
If currentpage=0 Then
lbnprevpage.enabled=false
lbnprevpage.imageurl="images/button/up0.gif"
End If
lblcurrentpage.text=currentpage+1
End Sub
Public Sub DBListBindSearch()
dim startindex As integer
Dim searchkey As String =search.text
StartIndex = CurrentPage*PageSize
Dim strSel As string = "select * from guest where name like '%"& searchkey &"%' or caption like '%"& searchkey &"%' or content like '%"& searchkey &"%' or reply like '%"& searchkey &"%' order by id desc"
Dim MyAdapter As New OleDbDataAdapter(strSel,myconn)
MyAdapter.Fill(ds,startindex,PageSize,"guest")
lbnnextpage.enabled=true
lbnprevpage.enabled=true
lbnnextpage.imageurl="images/button/down.gif"
lbnprevpage.imageurl="images/button/up.gif"
If currentpage>=pagecount-1 Then
lbnnextpage.enabled=false
lbnnextpage.imageurl="images/button/down0.gif"
End If
If currentpage=0 Then
lbnprevpage.enabled=false
lbnprevpage.imageurl="images/button/up0.gif"
End If
lblcurrentpage.text=currentpage+1
End Sub
Public Sub GoToPage(obj As object,e As eventargs)'處理頁面跳轉(zhuǎn)事件
Dim number As integer =CheckNum(lblcurrentpage.text)
If number<=viewstate("pagecount") Then
CurrentPage=number-1
viewstate("pageindex")=currentpage
pagecount=viewstate("pagecount")
If viewstate("state")="all" Then
DbListBind()
Else
DBListBindSearch()
End If
else
CurrentPage=0
viewstate("pageindex")=currentpage
pagecount=viewstate("pagecount")
If viewstate("state")="all" Then
DbListBind()
Else
DBListBindSearch()
End If
End If
End Sub
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -