📄 delinfo.aspx.cs
字号:
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.SqlClient;
using System.Configuration;
namespace school.main
{
/// <summary>
/// delinfo 的摘要说明。
/// </summary>
public class delinfo : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataList dltBoard;
protected System.Web.UI.WebControls.Button btnOK;
protected System.Web.UI.WebControls.Button btnReturn;
SqlConnection cn;
SqlCommand cmd;
SqlDataReader dr;
SqlDataAdapter da;
DataSet ds;
int i;
string strConn,strSQL;
public string strClid;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(Session.Count==0) Page.Response.Redirect("default.aspx");
else
if(Session["uid"].ToString()=="") Page.Response.Redirect("default.aspx");
strConn = ConfigurationSettings.AppSettings["SQLConnectionString"];
cn=new SqlConnection(strConn);
cn.Open();
strSQL="select info_id,admin1,admin2,a.class_id from info a,class b where b.class_id=(select class_id from info where info_id="+Page.Request["msgid"].ToString()+") and info_id="+Page.Request["msgid"].ToString();
cmd=new SqlCommand(strSQL,cn);
dr=cmd.ExecuteReader();
while(dr.Read())
if(!(Session["uid"].ToString()==dr[0].ToString()|Session["uid"].ToString()==dr[1].ToString()|Session["uid"].ToString()==dr[2].ToString()))
{
strClid=dr["class_id"].ToString();
dr.Close();
cn.Close();
Page.Response.Redirect("info.aspx?clid="+strClid);
}
dr.Close();
strSQL="select info_title,id,class_id,info_cnt from info where info_id="+Page.Request["msgid"].ToString();
da=new SqlDataAdapter(strSQL,cn);
ds=new DataSet();
da.Fill(ds,"msg");
strClid=ds.Tables["msg"].Rows[0]["class_id"].ToString();// 取出所属于班级id,以便返回
ds.Tables["msg"].Columns.Add("name");
for(i=0;i<ds.Tables[0].Rows.Count;i++)
{
strSQL="select name from scuser where id="+ds.Tables[0].Rows[i]["id"].ToString();
cmd=new SqlCommand(strSQL,cn);
dr=cmd.ExecuteReader();
while(dr.Read())
ds.Tables[0].Rows[i]["name"]=dr[0].ToString();
cmd.Dispose();
dr.Close();
}
dltBoard.DataSource=ds.Tables["msg"].DefaultView;
dltBoard.DataBind();
ds.Dispose();
cn.Close();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
this.btnReturn.Click += new System.EventHandler(this.btnReturn_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnOK_Click(object sender, System.EventArgs e)
{
strConn = ConfigurationSettings.AppSettings["SQLConnectionString"];
strSQL="Update info SET del_flag='1' where info_id="+Page.Request["msgid"].ToString();
cn=new SqlConnection(strConn);
cn.Open();
cmd=new SqlCommand(strSQL,cn);
cmd.ExecuteNonQuery();
cmd.Dispose();
cn.Close();
Page.Response.Redirect("info.aspx?clid="+strClid);
}
private void btnReturn_Click(object sender, System.EventArgs e)
{
Page.Response.Redirect("info.aspx?clid="+strClid);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -