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 SystemManage_SystemUserManage : System.Web.UI.Page
{
	/// <summary>
	/// 查询的所有系统用户
	/// </summary>
	private readonly static string sqlcmd1 = "select * from System_Users order by id desc";
	/// <summary>
	/// 删除一个系统用户
	/// </summary>
	private readonly static string sqlcmd2 = "delete from System_Users where id =";

    protected void Page_Load(object sender, EventArgs e)
    {
		if (Convert.ToString(Session["username"]) == "")
		{
			Response.Write("<script language=javascript>alert('请登录');location='../login.aspx'</script>");
			return;
		}
		if (!IsPostBack)
		{
			this.bind();
		}
    }
	protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		GridView1.PageIndex = e.NewPageIndex;
		this.bind();
	}
	protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
	{
		string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
		using (SqlConnection sqlconn = new SqlConnection(Tools.strConn))
		{
			sqlconn.Open();
			SqlCommand cmd = new SqlCommand((sqlcmd2 + id), sqlconn);
			cmd.ExecuteNonQuery();
			this.bind();
		}
	}
	protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
	{
		string id = GridView1.DataKeys[e.NewEditIndex].Value.ToString();
		Response.Write("<script>window.open('user_open.aspx?id=" + id + "','','width=450,height=250')</script>");
		Response.Write("<script>location='javascript:history.go(-1)'</script>");
	}
	public void bind()
	{
		using (SqlConnection sqlconn = new SqlConnection(Tools.strConn))
		{
			sqlconn.Open();
			SqlDataAdapter sad = new SqlDataAdapter(sqlcmd1, sqlconn);
			DataSet ds = new DataSet("System_Users");
			sad.Fill(ds, "System_Users");
			GridView1.DataSource = ds.Tables["System_Users"];
			GridView1.DataKeyNames = new string[] { "id"};
			GridView1.DataBind();
		}
	}

    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("AddUser.aspx");
    }
}
