postmessage1.aspx

来自「《精通ASP.NET网络编程》附带实例」· ASPX 代码 · 共 125 行

ASPX
125
字号
<%@Page language="VB" debug="True" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<html>
<head>
<title>Thank You for Posting !</title>
<script language="VB" runat="server" >
  Sub Page_Load(Src As Object,E As EventArgs) 
     If Not Page.IsPostBack Then
       '取出提交的各项值
       Dim name As String= Request.Params("name")
       Dim email As String= Request.Params("email")
       Dim subject As String= Request.Params("subject")
       Dim ip As String= Request.Params("ip")
       Dim mydate As String= Request.Params("date")
       Dim message As String= Request.Params("message")
       Dim newmess As Boolean=true
       Dim previd As String="1"
       '判断是新主题还是回复主题
       If Request.Params("newpost").Equals("no")=true Then
          '如果是回复主题,找出对那个主题进行回复
          newmess =false
          previd = Request.Params("previd")
       End If
       '如果是新主题,执行下面的程序
       If newmess=true Then
         Dim strConn As String="Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source="+Server.MapPath("board.mdb")
          Dim myConn As OleDbConnection= new OleDbConnection(strConn)
          Dim strCom As String= "Select postid from newpost"
          Dim myCommand As OleDbCommand=new OleDbCommand(strCom,myConn)
          myConn.Open()
          Dim reader As OleDbDataReader
          reader = myCommand.ExecuteReader()
          Dim i As Integer=1
          '查找出一共有多少条记录,以确定新主题的主键
          While reader.Read()
              i+=1
          End While
          reader.Close()
          '将新主题插入到数据库中
          Dim insertStr As String=" INSERT INTO newpost VALUES ("+i.ToString()+", '"+name+"', '"+email+"', '"+subject+"', '"+ip+"', '"+mydate+"', '"+message+"',0,0)"
          myCommand.CommandText =insertStr
 
          myCommand.ExecuteNonQuery()

          myConn.Close()
       Else
          '如果是回复主题,执行下面的代码
          Dim strConn As String="Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source="+Server.MapPath("board.mdb")
          Dim myConn As OleDbConnection = new OleDbConnection(strConn)
          Dim strCom As String= "Select replyid from reply"
          Dim myCommand As OleDbCommand=new OleDbCommand(strCom,myConn)
          myConn.Open()
          Dim reader As OleDbDataReader
          reader = myCommand.ExecuteReader()
          Dim i As Integer=1
          While reader.Read()
               i+=1 
          End While
          reader.Close()
          '将回复主题插入到数据库中
          Dim insertStr As String=" INSERT INTO reply VALUES ("+i.ToString()+", '"+name+"', '"+email+"', '"+subject+"', '"+ip+"', '"+mydate+"','"+message+"',"+previd+")"
          myCommand.CommandText =insertStr
          myCommand.ExecuteNonQuery()
          Dim replyno As String= "SELECT replies FROM newpost WHERE postid ="+previd
          myCommand.CommandText =replyno
          reader = myCommand.ExecuteReader()
          reader.Read()
          Dim rep As Integer=reader.GetInt16(0)
          reader.Close()
          rep+=1
          '更新主题的回复次数
          Dim updtStr As String="UPDATE newpost SET replies = "+rep.ToString()+" WHERE (postid = "+previd+")"
          myCommand.CommandText = updtStr
          myCommand.ExecuteNonQuery()
          myConn.Close()
       End If
       NameLabel.Text = name
       EmailLabel.Text= email 
       SubjectLabel.Text=subject
       MessageLabel.Text=message
    Else
      errmess.Text="页面错误<br>"
    End If
  End Sub
</script>
<LINK href="mystyle.css" type=text/css rel=stylesheet>
</head>
<body topmargin="0" leftmargin="0" rightmargin="0" marginwidth="0" marginheight="0">
<!-- #Include File="header.inc" --> 
<center>
<asp:label id="errmess" text="" style="color:#FF0000" runat="server" />
  <h2 class="fodark"><b>谢谢,你的大作已经成功发表。</b></h2>
<table align=center width="60%" border="0" cellspacing="2" cellpadding="1" >
    <tr class="fohead">
      <td colspan="2">你发表的作品信息:</td>
    </tr>
    <tr class="folight">
      <td>大名 :</td>	
      <td><asp:label id="NameLabel" text="" runat="server" /></td>
    </tr>
    <tr class="folight">
      <td>E-Mail :</td>	
      <td><asp:label id="EmailLabel" text="" runat="server" /></td>
    </tr>
    <tr class="folight">
      <td>主题 :</td>
      <td><asp:label id="SubjectLabel" text="" runat="server" /></td>
    </tr>
    <tr class="folight">
      <td>内容 :</td>
      <td><asp:label id="MessageLabel" text="" runat="server" /></td>
    </tr>
</table>
<br>
  <h4 class="fodark"><a href="forum1.aspx">讨论区首页 </a> <br>
    <% if Request.Params("newpost").Equals("no")=true Then%> 
    <a href='reply1.aspx?postid=<%=Request.Params("previd") %>'> 返回 </a> 
    <% End If %> 
  </h4>
</center>
<!-- #Include File="footer.inc" --> 
</body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?