using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace WebApplication1
{
    public partial class usermessage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bind();
            }
        }
        public static SqlConnection conn = null;
        public static SqlCommand cmd = null;
        public static string connstr = ConfigurationSettings.AppSettings["connstr"];

        public void bind()
        {
            BLL.worker bw = new BLL.worker();
            gvwDep.DataSource = bw.select("");
            gvwDep.DataKeyNames = new string[] { "userid" };
            gvwDep.DataBind();
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("bianjiue.aspx?m=" + btnAdd.Text);
        }



        protected void gvwDep_RowCommand(object sender, GridViewCommandEventArgs e)
        {

            string userid = e.CommandArgument.ToString();
            if (e.CommandName == "Edit")
            {
                Response.Redirect("bianjiue.aspx?m=" + "修改," +userid);
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            BLL.worker bw = new BLL.worker();
            if (TextBox2.Text != "")
            {
                DataSet d = bw.select("userid=" + "'" + TextBox2.Text + "'");
                try
                {
                    if (d.Tables[0].Rows[0].ToString() != "")
                    {
                        gvwDep.DataSource = d;
                        gvwDep.DataKeyNames = new string[] { "userid" };
                        gvwDep.DataBind();
                    }
                }
                catch
                {
                    Response.Write("<script>alert('您要查找的员工不存在',48)</script>");
                }
            }
            else
                bind();
        }

        protected void gvwDep_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            BLL.worker bw = new BLL.worker();
            if (bw.delete(gvwDep.DataKeys[e.RowIndex].Value.ToString()))
            {
                Response.Write("<script>alert(' 删除成功')</script>");
                bind();
            }
            else
                Response.Write("<script>alert(' 删除失败')</script>");
        }

    }
}
