reply2.aspx.cs
资源名称:Visual.rar [点击查看]
上传用户:yiyuerguo
上传日期:2014-09-27
资源大小:3781k
文件大小:4k
源码类别:
C#编程
开发平台:
Others
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Web;
- using System.Web.SessionState;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.HtmlControls;
- using System.Data.OleDb;
- namespace mbord5
- {
- /// <summary>
- /// reply2 的摘要说明。
- /// </summary>
- public class reply2 : System.Web.UI.Page
- {
- protected System.Web.UI.WebControls.Label errmess;
- protected System.Web.UI.WebControls.TextBox message;
- protected System.Web.UI.WebControls.TextBox subject;
- protected System.Web.UI.WebControls.TextBox email;
- protected System.Web.UI.WebControls.Button Button1;
- protected System.Web.UI.WebControls.TextBox name;
- public DataSet ds ,rs;
- public DataRow dr ,rd ;
- public string postid ;
- private void Page_Load(object sender, System.EventArgs e)
- {
- if(!Page.IsPostBack)
- {
- postid = Request.Params["postid"] ;
- if(postid!=null)
- {
- string strConn=@"Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source="+Server.MapPath("board.mdb") ;
- OleDbConnection myConn = new OleDbConnection(strConn) ;
- //选出主题记录
- string strCon ="SELECT subject, name, email, message ,date FROM newpost WHERE postid="+postid ;
- OleDbDataAdapter myCommand =new OleDbDataAdapter(strCon,myConn);
- ds = new DataSet();
- myConn.Open();
- myCommand.Fill(ds,"newpost") ;
- dr = ds.Tables["newpost"].Rows[0] ;
- subject.Text="Re:"+dr["subject"].ToString() ;
- //选出对该主题的回复记录
- strCon ="SELECT name , email, subject, message ,date FROM reply WHERE postid="+postid ;
- OleDbDataAdapter myCommand2 =new OleDbDataAdapter(strCon,myConn);
- //建立第二个dataset的目的是 填充reply表
- rs = new DataSet() ;
- myCommand2.Fill(rs, "reply") ;
- strCon ="SELECT views FROM newpost WHERE postid = "+postid ;
- OleDbCommand vicomm = new OleDbCommand(strCon, myConn) ;
- OleDbDataReader reader ;
- reader = vicomm.ExecuteReader();
- //建立一个reader 目的就是为了读取postid上一次的点击次数 views
- reader.Read() ;
- //转化为整数
- int i = reader.GetInt32(0) ;
- i++ ;
- reader.Close() ;
- //更新该主题的点击次数
- //列出对主题的所有回复记录
- strCon ="UPDATE newpost SET views = "+i+" WHERE (postid= "+postid+")" ;
- vicomm.CommandText = strCon ;
- vicomm.ExecuteNonQuery() ;
- myConn.Close();
- }
- }
- }
- #region Web 窗体设计器生成的代码
- override protected void OnInit(EventArgs e)
- {
- //
- // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
- //
- InitializeComponent();
- base.OnInit(e);
- }
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.Button1.Click += new System.EventHandler(this.Button1_Click);
- this.Load += new System.EventHandler(this.Page_Load);
- }
- #endregion
- private void Button1_Click(object sender, System.EventArgs e)
- {
- postid = Request.Params["postid"] ;
- if(Page.IsValid&&name.Text!=""&&subject.Text!=""&&email.Text!="")
- {
- //将对该主题的回复提交到postmessage1.aspx页面
- DateTime now = DateTime.Now ;
- errmess.Text="" ;
- string req = "name="+System.Web.HttpUtility.UrlEncode(name.Text, System.Text.Encoding.UTF8);
- req+="&&email="+System.Web.HttpUtility.UrlEncode(email.Text, System.Text.Encoding.UTF8);
- req+="&&subject="+System.Web.HttpUtility.UrlEncode(subject.Text, System.Text.Encoding.UTF8);
- req+="&&ip="+System.Web.HttpUtility.UrlEncode(Request.UserHostAddress.ToString(), System.Text.Encoding.UTF8);
- req+="&&date="+System.Web.HttpUtility.UrlEncode(now.ToString(), System.Text.Encoding.UTF8);
- req+="&&newpost="+System.Web.HttpUtility.UrlEncode("no", System.Text.Encoding.UTF8);
- req+="&&previd="+ System.Web.HttpUtility.UrlEncode(postid, System.Text.Encoding.UTF8);
- req+="&&message="+ System.Web.HttpUtility.UrlEncode(message.Text, System.Text.Encoding.UTF8);
- Response.Redirect("postmessage2.aspx?" + req);
- }
- else
- {
- errmess.Text="你还有一些内容没填 !" ;
- }
- }
- }
- }