留言板删除回复
protected
void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlDataSource1.SelectCommand = " select * from message where mrestore is not null";
Repeater1.DataSource = SqlDataSource1;
}
Label1.Text = "欢迎您留言
:" + Session[
"a"].ToString();
string connectionstring = "Data Source=.;Initial Catalog=upan;Integrated Security=True";
SqlConnection conn = new SqlConnection(connectionstring);
SqlDataAdapter adapter = new SqlDataAdapter();
SqlCommand comm = conn.CreateCommand();
comm.CommandText = "select * from message";
DataSet ds = new DataSet();
adapter.SelectCommand = comm;
ds.Clear();
adapter.Fill(ds, "message");
this.Repeater1.DataSource = ds.Tables[0].DefaultView;
this.DataBind();
}
protected void lbtDel_Click(object sender, EventArgs e)
{
LinkButton lb = (LinkButton)sender;
string mid = lb.CommandArgument;
SqlDataSource1.ConnectionString = "Data Source=.;Initial Catalog=upan;Integrated Security=True";
SqlDataSource1.DeleteCommand = string.Format(" delete message where mid={0}", mid);
SqlDataSource1.Delete();
SqlDataSource1.SelectCommand = "select * from message";
SqlDataSource1.Select(DataSourceSelectArguments.Empty);
Repeater1.DataSource = SqlDataSource1;
Repeater1.DataBind();
}
protected void lbtIns_Click(object sender, EventArgs e)
{
TextBox1.Focus();
LinkButton lb = (LinkButton)sender;
Session["mid"] = lb.CommandArgument;
TextBox2.Text = "";
TextBox1.Focus();
}
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlDataSource1.ConnectionString = "Data Source=.;Initial Catalog=upan;Integrated Security=True";
SqlDataSource1.UpdateCommand = string.Format("update message set mrestore='{0}'where mid={1}", TextBox1.Text, Session["mid"].ToString());
SqlDataSource1.Update();
SqlDataSource1.UpdateCommand = string.Format("update message set mtag='已回复
'where mid={1}",TextBox1.Text,Session[
"mid"].ToString());
SqlDataSource1.Update();
SqlDataSource1.SelectCommand = "select * from message";
SqlDataSource1.Select(DataSourceSelectArguments.Empty);
Repeater1.DataSource = SqlDataSource1;
Repeater1.DataBind();
}
登录代码
protected
void Button1_Click(object sender, EventArgs e)
{
string connectionstring = "Data Source=.;Initial Catalog=upan;Integrated Security=True";
SqlConnection conn = new SqlConnection(connectionstring);
if (conn.State == ConnectionState.Closed)
conn.Open();
SqlCommand comm = conn.CreateCommand();
comm.CommandText = "select count(*)from Users where username=@username and userpwd=@userpwd";
comm.Parameters.AddWithValue("@username",TextBox1.Text);
comm.Parameters.AddWithValue("@userpwd",TextBox2.Text);
Session["a"] = TextBox1.Text.ToString();
int i=(int)comm.ExecuteScalar();
if (i > 0)
{
string sql = "select tag from users where username=@username";
comm = new SqlCommand(sql,conn);
comm.Parameters.AddWithValue("@username",TextBox1.Text);
int o = Convert.ToInt16(comm.ExecuteScalar());
if (o == 1)
{
Response.Redirect("~/liuyan.aspx");
}
else
{
Response.Redirect("~/liuy.aspx");
}
}
else
{
Response.Write("<script>alert('用户名或密码输入错误
!请重新输入')</script>");
}
}
注册页面代码
protected
void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string connectionstring = "Data Source=.;Initial Catalog=upan;Integrated Security=True";
SqlConnection conn = new SqlConnection(connectionstring);
if(conn.State==ConnectionState.Closed)
//打开数据库连接
conn.Open();
string sql = "select count(*) as total from users where username=@username";
SqlCommand comm = new SqlCommand(sql, conn);
comm.Parameters.AddWithValue("@username",TextBox1.Text);
int i = (int)comm.ExecuteScalar();
if (i > 0)
{
Response.Write("<script>alert('不允许使用该用户
')</script>");
TextBox1.Text = "";
}
else
{
Response.Write("<script>alert('可以使用
')</script>");
}
}
protected void Button2_Click(object sender, EventArgs e)
{
string connectionstring = "Data Source=.;Initial Catalog=upan;Integrated Security=True";
SqlConnection conn = new SqlConnection(connectionstring);
if (conn.State == ConnectionState.Closed)
//打开数据库连接
conn.Open();
string sql = "insert into users(username,userpwd,sex,tel,email,qq,intro,postaladdress,postalcode) values (@username,@userpwd,@sex,@tel,@email,@qq,@intro,@postaladdress,@postalcode)";
SqlCommand comm = new SqlCommand(sql, conn);
comm.Parameters.AddWithValue("@username",TextBox1.Text);
comm.Parameters.AddWithValue("@userpwd",TextBox10.Text);
string xb = RadioButtonList1.SelectedItem.ToString();
comm.Parameters.AddWithValue("@sex",xb);
comm.Parameters.AddWithValue("@tel",TextBox2.Text);
comm.Parameters.AddWithValue("@email",TextBox3.Text);
comm.Parameters.AddWithValue("@qq",TextBox4.Text);
comm.Parameters.AddWithValue("@intro",TextBox5.Text);
comm.Parameters.AddWithValue("@postaladdress",TextBox7.Text);
comm.Parameters.AddWithValue("@postalcode",TextBox8.Text);
int i = comm.ExecuteNonQuery();
if (i > 0)
{
Response.Write("<script>alert('添加成功
!')</script>");
Response.Redirect("~/login.aspx");
}
else
{
Response.Write("<script>alert('添加失败
!')</script>");
}
}
protected void Button3_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
TextBox7.Text = "";
TextBox8.Text = "";
TextBox10.Text = "";
TextBox11.Text = "";
}