postmessage2.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>
- /// postmessage2 的摘要说明。
- /// </summary>
- public class postmessage2 : System.Web.UI.Page
- {
- protected System.Web.UI.WebControls.Label MessageLabel;
- protected System.Web.UI.WebControls.Label SubjectLabel;
- protected System.Web.UI.WebControls.Label EmailLabel;
- protected System.Web.UI.WebControls.Label NameLabel;
- protected System.Web.UI.WebControls.Label errmess;
- private void Page_Load(object sender, System.EventArgs e)
- {
- //if the page is called from another page
- if (!Page.IsPostBack)
- {
- //取出提交的各项值
- string name = Request.Params["name"] ;
- string email = Request.Params["email"] ;
- string subject = Request.Params["subject"] ;
- string ip = Request.Params["ip"] ;
- string date = Request.Params["date" ];
- string message = Request.Params["message"] ;
- bool newmess =true ;
- string previd ="1";
- //判断是新主题还是回复主题
- if(Request.Params["newpost"].Equals("no"))
- {
- //如果是回复主题,找出对那个主题进行回复
- newmess =false ;
- previd = Request.Params["previd"] ;
- }
- //如果是新主题,执行下面的程序
- if(newmess)
- {
- string strConn=@"Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source="+Server.MapPath("board.mdb") ;
- OleDbConnection myConn = new OleDbConnection(strConn) ;
- string strCom = "Select postid from newpost" ;
- OleDbCommand myCommand =new OleDbCommand(strCom,myConn);
- myConn.Open();
- OleDbDataReader reader;
- reader = myCommand.ExecuteReader();
- int i=1 ;
- //查找出一共有多少条记录,以确定新主题的主键
- while(reader.Read())
- {
- i++ ;
- }
- reader.Close() ;
- //将新主题插入到数据库中
- string insertStr =" INSERT INTO newpost VALUES ("
- +i +", '"
- +name+"', '"
- +email+"', '"
- +subject+"', '"
- +ip+"', '"
- +date+"', '"
- +message+"',0, 0)" ;
- myCommand.CommandText =insertStr ;
- myCommand.ExecuteNonQuery() ;
- myConn.Close() ;
- }
- else
- {
- //如果是回复主题,执行下面的代码
- string strConn=@"Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source="+Server.MapPath("board.mdb") ;
- OleDbConnection myConn = new OleDbConnection(strConn) ;
- string strCom = "Select replyid from reply" ;
- OleDbCommand myCommand =new OleDbCommand(strCom,myConn);
- myConn.Open();
- OleDbDataReader reader;
- reader = myCommand.ExecuteReader();
- int i=1 ;
- while(reader.Read())
- {
- i++ ;
- }
- reader.Close() ;
- //将回复主题插入到数据库中
- string insertStr =" INSERT INTO reply VALUES ("
- +i +", '"
- +name+"', '"
- +email+"', '"
- +subject+"', '"
- +ip+"', '"
- +date+"', '"
- +message+"', "
- +previd+")";
- myCommand.CommandText =insertStr ;
- myCommand.ExecuteNonQuery() ;
- string replyno = "SELECT replies FROM newpost WHERE postid ="+previd ;
- myCommand.CommandText =replyno ;
- reader = myCommand.ExecuteReader();
- reader.Read();
- int rep =reader.GetInt16(0) ;
- reader.Close() ;
- rep++ ;
- //更新主题的回复次数
- string updtStr ="UPDATE newpost SET replies = "+rep
- +" WHERE (postid = "+previd+")" ;
- myCommand.CommandText = updtStr;
- myCommand.ExecuteNonQuery();
- myConn.Close() ;
- }
- NameLabel.Text = name;
- EmailLabel.Text= email ;
- SubjectLabel.Text=subject;
- MessageLabel.Text=message ;
- }
- else
- {
- errmess.Text="页面错误<br>";
- }
- }
- // 在此处放置用户代码以初始化页面
- #region Web 窗体设计器生成的代码
- override protected void OnInit(EventArgs e)
- {
- //
- // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
- //
- InitializeComponent();
- base.OnInit(e);
- }
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.Load += new System.EventHandler(this.Page_Load);
- }
- #endregion
- }
- }