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_EmployeeManage : System.Web.UI.Page
{
    private readonly static string sqlcmd1 = "select * from EMPLOYEE order by id desc";

    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();
        }
    }

    public void Bind()
    {
        using (SqlConnection sqlconn=new SqlConnection(Tools.strConn))
        {
            sqlconn.Open();
            SqlDataAdapter sda = new SqlDataAdapter(sqlcmd1, sqlconn);
            DataSet ds = new DataSet("EMPLOYEE");
            sda.Fill(ds, "EMPLOYEE");
            GridView1.DataSource = ds.Tables["EMPLOYEE"];
            GridView1.DataKeyNames = new string[] { "id"};
            GridView1.DataBind();
        }
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        this.Bind();
    }

    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        string id = GridView1.DataKeys[e.NewEditIndex].Value.ToString();
        Response.Write("<script>window.open('employee_open.aspx?id=" + id + "','','width=450,height=250')</script>");
        Response.Write("<script>location='javascript:history.go(-1)'</script>");
    }

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

    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
        DataBaseDrHelp sqlhelp = new DataBaseDrHelp();
        sqlhelp.RunSql("delete from EMPLOYEE where id ='"+id+"'");
        this.Bind();
    }
}
