当前位置:首页 > 网络编程 > WEB编程 > ASP.net > 用asp.net写的论坛程序--浏览贴子内容及回复

用asp.net写的论坛程序--浏览贴子内容及回复

点击次数:17 次 发布日期:2008-11-26 23:28:39 作者:源代码网
源代码网推荐 2) reply.aspx : The topic viewing and replying page</P><P><%@ Page Language="C#" EnableSessionState="False" Debug="True" %>
源代码网推荐 <%@ Import Namespace="System" %>
源代码网推荐 <%@ Assembly Name="System.Data" %>
源代码网推荐 <%@ Import Namespace="System.Data" %>
源代码网推荐 <%@ Import Namespace="System.Data.ADO" %>
源代码网推荐 <html><head>
源代码网推荐 <title>Post New Topic.</title>
源代码网推荐 <%-- These are the imported assemblies and namespaces needed --%>
源代码网推荐 <s cript Language="C#" runat="server">
源代码网推荐   DataSet ds ,rs;
源代码网推荐   DataRow dr ;
源代码网推荐   string postid ;
源代码网推荐   public void Page_Load(object sender , EventArgs e)
源代码网推荐   {
源代码网推荐      //Check if the page is Post Back
源代码网推荐      if(!Page.IsPostBack)
源代码网推荐     {
源代码网推荐        //Get the postid from the Query string
源代码网推荐        postid = Request.Params["postid"] ;
源代码网推荐        if(postid!=null)
源代码网推荐       {
源代码网推荐          //Database connection string. Change the path to the database file if you have some other path where
源代码网推荐          //you are saving your Database file
源代码网推荐          string strConn=@"Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source="+Server.MapPath(".dboard.mdb") ;
源代码网推荐          //Make a connection to the Database
源代码网推荐          ADOConnection myConn = new ADOConnection(strConn) ;
源代码网推荐          //string to select the records from the newpost table
源代码网推荐          string strCon ="SELECT subject, name, email, message ,date  FROM newpost WHERE postid="+postid ;
源代码网推荐           //set a ADODataSetCommand
源代码网推荐          ADODataSetCommand myCommand =new ADODataSetCommand(strCon,myConn);
源代码网推荐          ds = new DataSet();
源代码网推荐          //Don"t ever forget to open the Connection
源代码网推荐          myConn.Open();
源代码网推荐          //Fill the DataSet
源代码网推荐          myCommand.FillDataSet(ds,"newpost") ;
源代码网推荐          //Get the Row at position "0" and store it in a DataRow object
源代码网推荐          //Why row at position "0" ? Since there can only be one record with the given postid remember !!
源代码网推荐          //Why put into a DataRow ? Its easy to access data from a DataRow
源代码网推荐          dr = ds.Tables["newpost"].Rows[0] ;
源代码网推荐          //Get the "subject" from the DataRow and set it up in the post reply form"s subject field
源代码网推荐          subject.Text="Re:"+dr["subject"].ToString() ;
源代码网推荐          //Select the replies to the post from the reply table
源代码网推荐          strCon ="SELECT name , email, subject, message ,date FROM reply WHERE postid="+postid ;
源代码网推荐          //Make a new ADODataSetCommand and DataSet for the reply table
源代码网推荐          ADODataSetCommand myCommand2 =new ADODataSetCommand(strCon,myConn);
源代码网推荐          rs = new DataSet() ;
源代码网推荐          //fill the DataSet
源代码网推荐          myCommand2.FillDataSet(rs, "reply") ;
源代码网推荐          //Code to update the "views" field for the newpost Table
源代码网推荐          //Select the views field from the table for a given postid
源代码网推荐          strCon ="SELECT views FROM newpost WHERE postid = "+postid ;
源代码网推荐          //Make a ADOCommand here since we want a ADODataReader later
源代码网推荐          ADOCommand vicomm = new ADOCommand(strCon, myConn) ;
源代码网推荐          ADODataReader reader ;
源代码网推荐          //execute the statement and create a ADODataReader
源代码网推荐          vicomm.Execute(out reader) ;
源代码网推荐          //Read the First record (there can only be one record remember !)
源代码网推荐          reader.Read() ;
源代码网推荐          //Get a "Int32" value from the first Column (we have one column in the reader, check the select statement above)
源代码网推荐          int i = reader.GetInt32(0) ;
源代码网推荐          //Increase the views count
源代码网推荐          i++ ;
源代码网推荐          reader.Close() ;
源代码网推荐          //Update the newpost table with the new views value
源代码网推荐          strCon ="UPDATE newpost SET views = "+i+" WHERE (postid= "+postid+")" ;
源代码网推荐          //since we are using the same ADOCOmmand object for this statement too to set the CommandText property
源代码网推荐          vicomm.CommandText = strCon ;
源代码网推荐          //Since this statement will result in no output we use "ExecuteNonQuery()" method
源代码网推荐          vicomm.ExecuteNonQuery() ;
源代码网推荐          //close the connection
源代码网推荐          myConn.Close();
源代码网推荐       }
源代码网推荐     }
源代码网推荐   }
源代码网推荐    // This method is called when the submit button is clicked
源代码网推荐    public void Submit_Click(Object sender, EventArgs e)
源代码网推荐    {
源代码网推荐        //Get the postid
源代码网推荐        postid = Request.Params["postid"] ;
源代码网推荐       
源代码网推荐        //proceed only if all the required fields are filled-in
源代码网推荐        if(Page.IsValid&&name.Text!=""&&subject.Text!=""&&email.Text!=""){
源代码网推荐          DateTime now = DateTime.Now ;
源代码网推荐          errmess.Text="" ;
源代码网推荐         //We have to call the postmessage.aspx page with a query to post the data to the Database.
源代码网推荐         //Hence we have to first build the custom query from the Data posted by the user
源代码网推荐         //also since we are using a query we have to encode the data into UTF8 format
源代码网推荐          string req = "name="+ System.Web.HttpUtility.UrlEncodeToString(name.Text, System.Text.Encoding.UTF8);
源代码网推荐         req+="&&email="+ System.Web.HttpUtility.UrlEncodeToString(email.Text, System.Text.Encoding.UTF8);
源代码网推荐         req+="&&subject="+System.Web.HttpUtility.UrlEncodeToString(subject.Text, System.Text.Encoding.UTF8);
源代码网推荐 req+="&&ip="+System.Web.HttpUtility.UrlEncodeToString(Request.UserHostAddress.ToString(), System.Text.Encoding.UTF8);
源代码网推荐         req+="&&date="+ System.Web.HttpUtility.UrlEncodeToString(now.ToString(), System.Text.Encoding.UTF8);
源代码网推荐         req+="&&message="+ System.Web.HttpUtility.UrlEncodeToString(message.Text, System.Text.Encoding.UTF8);
源代码网推荐         //Encode "no" to indicate that the post is not a new post but its a reply to a earlier message
源代码网推荐         req+="&&newpost="+ System.Web.HttpUtility.UrlEncodeToString("no", System.Text.Encoding.UTF8);
源代码网推荐         req+="&&previd="+ System.Web.HttpUtility.UrlEncodeToString(postid, System.Text.Encoding.UTF8);
源代码网推荐          //Call the postmessage page with our custom query
源代码网推荐          Page.Navigate("postmessage.aspx?" + req);
源代码网推荐        }
源代码网推荐        else
源代码网推荐        {
源代码网推荐           errmess.Text="Fill in all the Required Fields !" ;
源代码网推荐         }
源代码网推荐     }
源代码网推荐 </s cript>
源代码网推荐 <LINK href="mystyle.css" type=text/css rel=stylesheet></head>
源代码网推荐 <body topmargin="0" leftmargin="0" rightmargin="0" marginwidth="0" marginheight="0">
源代码网推荐 <%-- Include a header file "header.inc" --%>
源代码网推荐 <!-- #Include File="header.inc" -->
源代码网推荐 <br>
源代码网推荐 <div align=center>
源代码网推荐 <table border=0 width=80% cellspacing=2>
源代码网推荐 <tr class=fohead><th width=20%>Author Name</th>
源代码网推荐 <th width=80%>Message</th></tr>
源代码网推荐 <%-- Below I am encapsulating the email of the author over the name of the author
源代码网推荐 so that when you click on the author a e-mail gets sent to him
源代码网推荐 Also I am geting the DateTime from the DataBase and Displaying the Date and Time separately --%>   
源代码网推荐 <tr class=folight><td rowspan=2 align="center"><%= "<a href=mailto:"+dr["email"]+">"+dr["name"]+"</a>" %><br>
源代码网推荐 <font size=1><%= dr["date"].ToString().ToDateTime().ToShortDateString()  %><br>
源代码网推荐 <%= dr["date"].ToString().ToDateTime().ToShortTimeString() %></font>
源代码网推荐 </td>
源代码网推荐 <td><b>Subject: </b><%=dr["subject"] %></td></tr>
源代码网推荐 <tr class=folight>
源代码网推荐 <td><pre><%=dr["message"] %></pre> </td>
源代码网推荐 </tr>
源代码网推荐 <%-- Get all the replies to the Original post and show them --%>
源代码网推荐 <% int no = rs.Tables["reply"].Rows.Count ;
源代码网推荐    if(no>0)
源代码网推荐    {
源代码网推荐       for(int j=0 ;j<no ; j++)
源代码网推荐       {
源代码网推荐           DataRow rd = rs.Tables["reply"].Rows[j] ;
源代码网推荐 %>
源代码网推荐 <tr class=fodark>
源代码网推荐 <td align="center"><%="<a href=mailto:"+rd["email"]+">"+rd["name"]+"</a>" %><br>
源代码网推荐 <font size=1><%= rd["date"].ToString().ToDateTime().ToShortDateString()  %><br>
源代码网推荐 <%= rd["date"].ToString().ToDateTime().ToShortTimeString() %></font>
源代码网推荐 </td>
源代码网推荐 <td><pre><%=rd["message"] %></pre> </td>
源代码网推荐 </tr>
源代码网推荐 <%
源代码网推荐         }
源代码网推荐     }
源代码网推荐 %>
源代码网推荐 </table>
源代码网推荐 </div>
源代码网推荐 <h3 align="center" class="fodark"><a href=forum.aspx>Click Here</a> to go to back to Forum.
源代码网推荐 <br>Reply to the Above Post.</h3>
源代码网推荐 <br>
源代码网推荐 <asp:label id="errmess" text="" style="COLOR:#ff0000" runat="server" />
源代码网推荐 <form runat="server">
源代码网推荐 <table border="0"  width="80%" align="center">
源代码网推荐 <tr >
源代码网推荐 <td class="fohead" colspan=2><b>Reply to the Post</b></td>
源代码网推荐 </tr>
源代码网推荐 <tr class="folight" >
源代码网推荐 <td>Name :</td>
源代码网推荐 <td ><asp:textbox text="" id="name" runat="server" />   <font color=#ff0000>*</font></td>
源代码网推荐 </tr>
源代码网推荐 <tr class="folight">
源代码网推荐 <td>E-Mail :</td>
源代码网推荐 <td><asp:textbox text="" id="email" runat="server"/>   <font color=#ff0000>*</font></td>
源代码网推荐 </tr>
源代码网推荐 <tr class="folight">
源代码网推荐 <td> Subject:</td>
源代码网推荐 <td><asp:textbox test="" id="subject" width=200 runat="server"/>   <font color=#ff0000>*</font>
源代码网推荐 </td></tr>
源代码网推荐 <tr class="folight">
源代码网推荐 <td>Message :</td>
源代码网推荐 <td>
源代码网推荐 <asp:TextBox id=message runat="server"
源代码网推荐 Columns="30" Rows="15" TextMode="MultiLine"></asp:TextBox></td>
源代码网推荐 </tr>
源代码网推荐 <tr class=folight>
源代码网推荐 <td colspan=2>
源代码网推荐 <asp:Button class=fodark id=write onClick=Submit_Click runat="server" Text="Submit"></asp:Button></td></tr>
源代码网推荐 </table>
源代码网推荐 </form><br>
源代码网推荐 <br><!-- #Include File="footer.inc" -->
源代码网推荐 </body></html>
源代码网推荐        
源代码网推荐        

源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华