📄 post.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class post : System.Web.UI.Page
{
SqlConnection cn;
DataSet ds = new DataSet();
DataTable mytable = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
int id = int.Parse(Request.QueryString["id"]);
cn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["cn"]);
cn.Open();
SqlDataAdapter da = new SqlDataAdapter("select* from meeting where id=" + id, cn);
da.Fill(ds, "meeting");
mytable = ds.Tables["meeting"];
this.txttouser.Text = Convert.ToString(mytable .Rows [0]["builder"]);
this.txtfromuser.Text = Convert.ToString(Session ["username"]);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
this.txtcontent.Text = "";
this.txtcontent.Focus();
this.Label1.Text = "";
this.Labmessage.Text = "";
}
protected void Button2_Click(object sender, EventArgs e)
{
int id = int.Parse(Request.QueryString["id"]);
cn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["cn"]);
cn.Open();
SqlCommand cmd = new SqlCommand("select * from message where touser='" +this.txttouser .Text .Trim () + "'and fromuser='"+this.txtfromuser .Text .Trim ()+"'and content='"+this.txtcontent .Text .Trim ()+"'", cn);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Session["touser"] = dr["touser"].ToString();
Session["fromuser"] = dr["fromuser"].ToString();
Session["content"] = dr["content"].ToString();
this.Label1.Visible = true;
}
else
{
dr.Close();
SqlCommand cmd1 = new SqlCommand("insert into message(fromuser,touser,content,mid)values('" + this.txtfromuser.Text.Trim() + "','" + this.txttouser.Text.Trim() + "','" + this.txtcontent.Text.Trim().ToString() + "','" + id + "')", cn);
cmd1 .ExecuteNonQuery ();
this .Labmessage .Text ="发表留言成功";
this.LinkButton1 .Visible =true ;
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("Message.aspx?id="+Request .QueryString ["id"]);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -