?? default.aspx
字號:
<% @ Page language="vb" %>
<%--設置頁面腳本超時,請不要刪除,防止程序產生錯誤引起服務器崩潰--%>
<%server.scripttimeout=120%>
<%--導入名稱空間--%>
<% @ Import Namespace="System.Data" %>
<% @ Import Namespace="System.Data.OleDb" %>
<% @ Import Namespace="System.Xml" %>
<% @ Import Namespace="System.IO" %>
<%--
版權信息
程序名稱:互動.NET單用戶留言簿
程序版本: Ver2.0
數據庫:ACCESS2000
開發體系:Asp.Net
開發語言:Vb.Net
開發工具:EditPlus2.11,Dreamweaver MX
開發作者:小寶.NET
作者Email:webmaster@chinagz.net
作者主頁:http://aspx.chinagz.net 新開的ASP.NET專題站點,資源多多呵,大家賞臉去看一下呵:)
MSN:webmaster@chinagz.net
備注:這個已經最終版了,以后本人將不再開發后續版本了,但會繼續開發多用戶版的互動.NET留言簿以及C#開發的下載系統及文章管理系統,歡迎各位高手繼續開發及改善這個單用戶留言簿,本人只有唯一的要求就是這個留言簿的修改版必須提供免費下載就OK了!
--%>
<Script Runat="Server">
'初始化變量
Dim myconn As OleDbConnection
Dim RecordCount,PageCount,CurrentPage,i As integer
Dim codemessage As String
dim ds as new dataset()
Dim pagesize as integer
'以下是子程序,用以處理各種事件。
Public Sub Page_Load(obj As object,e As eventargs)
'連接數據庫
pagesize = ConfigurationSettings.AppSettings("每頁顯示留言數")
myconn= New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source="&server.MapPath(ConfigurationSettings.AppSettings("數據庫路徑")))
myconn.open()
'如果有提交信號,執行添加留言代碼。
if request.querystring("post") = "true" then
dim content as string=replace(request.form("content"),"<","<")
content=replace(content,">",">")
content=replace(content,chr(13),"<br>")
content=Trim(content)
content=replace(content," "," ")
content=replace(content,chr(39),"''")
If content="" Then content=":( 這家伙很懶,沒有發表任何內容"
Dim caption As String=replace(request.form("caption"),chr(39),"''")
caption=Trim(caption)
If caption="" Then caption="無主題"
Dim username=replace(request.form("username"),chr(39),"''")
username=Trim(username)
If username="" Then username="佚名"
Dim updatecomm As New oledbcommand("insert into guest (name,sex,qq,email,homepage,emot,content,face,caption,ip) values ('"& username &"','"& request.form("sex") &"','"& request.form("qq") &"','"& replace(request.form("email"),chr(39),"''") &"','"& replace(request.form("homepage"),chr(39),"''") &"','"& request.form("emot") &"','"& content &"','"& request.form("face") &"','"& caption &"','"& request.servervariables("remote_addr") &"')",myconn)
updatecomm.executenonquery()
myconn.close()
myconn.dispose()
response.redirect("default.aspx")
end if
'如果有刪除信號,執行刪除代碼。
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
'若頁面未被提交,初始化留言簿設置。
systemhome.text=ConfigurationSettings.AppSettings("網站名稱")
systemhome1.text=ConfigurationSettings.AppSettings("網站名稱")
systemname.text=ConfigurationSettings.AppSettings("管理員")
link.href="mailto:"+ConfigurationSettings.AppSettings("管理員郵箱")
link1.href=ConfigurationSettings.AppSettings("網站地址")
linkhome.navigateurl=ConfigurationSettings.AppSettings("網站地址")
logo.imageurl=ConfigurationSettings.AppSettings("留言簿logo")
'如果是管理員,執行代碼
if session("isadmin")<>"" then
goadmin.attributes("onclick")="MM_showHideLayers('setup','','show','postcontent','','hide','admin','','hide')"
setimage.imageurl="Images/button/setup.gif"
setimage.alternatetext="管理員高級設置"
Dim strfpath As string=server.mappath("web.config")
ds.readxml(strfpath)
setname.text=ds.Tables(1).Rows(0)(1)
sethomepage.text=ds.Tables(1).Rows(1)(1)
seturl.text=ds.Tables(1).Rows(2)(1)
setemail.text=ds.Tables(1).Rows(3)(1)
setpage.text=ds.Tables(1).Rows(5)(1)
setlogo.text=ds.Tables(1).Rows(6)(1)
setbgcolor.text=replace(ds.Tables(1).Rows(7)(1),"#","")
setlinebg.text=replace(ds.Tables(1).Rows(8)(1),"#","")
setline.text=replace(ds.Tables(1).Rows(9)(1),"#","")
setrebg.text=replace(ds.Tables(1).Rows(10)(1),"#","")
setlink.text=replace(ds.Tables(1).Rows(11)(1),"#","")
settext.text=replace(ds.Tables(1).Rows(12)(1),"#","")
setretext.text=replace(ds.Tables(1).Rows(13)(1),"#","")
setadmin.text=ds.Tables(1).Rows(14)(1)
setpassword.text=ds.Tables(1).Rows(15)(1)
mailserver.text=ds.Tables(1).Rows(16)(1)
replymail.text=ds.Tables(1).Rows(17)(1)
Dim j As integer
For j = 0 To ipinfo.Items.Count - 1
If ipinfo.Items(j).value=ds.Tables(1).Rows(18)(1) Then
ipinfo.Items(j).selected=true
End If
Next
ds.clear()
Else
goadmin.attributes("onclick")="MM_showHideLayers('admin','','show','postcontent','','hide')"
setimage.imageurl="Images/button/button2.gif"
setimage.alternatetext="管理登錄"
end if
'分頁設置
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
'初始化結束
End Sub
Public Sub DbListBind()
dim startindex As integer
'導入數據起始地址
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)'按鍵觸發的事件
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 =replace(search.text,chr(39),"''")
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
'數據邦定
DBListBindSearch()
End Sub
Public Sub DBListBindSearch()
dim startindex As integer
Dim searchkey As String =replace(search.text,chr(39),"''")
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)'處理頁面跳轉事件
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
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -