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_employee_open : System.Web.UI.Page
{
	private readonly static string sqlcmd1 = "select name,TEL,MOBILE,ADDRESS from EMPLOYEE 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>");
        }
        if (!IsPostBack)
        {
            using (SqlConnection sqlconn = new SqlConnection(Tools.strConn))
            {
                SqlCommand cmd = new SqlCommand((sqlcmd1 + Request["id"]), sqlconn);
                sqlconn.Open();
				SqlDataReader sr = cmd.ExecuteReader();
				if(sr.Read())
				{
					this.name.Text = sr["NAME"].ToString();
					this.tel.Text = sr["TEL"].ToString();
					this.mobile.Text = sr["MOBILE"].ToString();
					this.address.Text = sr["ADDRESS"].ToString();
				}
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (Tools.validate(Request["name"].ToString()))
        {
            Response.Write("<script>alert('用户名中不能含有非法字符');history.back()</script>");
            Response.End();
        }
        if (Tools.validate(Request["tel"].ToString()))
        {
            Response.Write("<script>alert('电话号中不能含有非法字符');history.back()</script>");
            Response.End();
        }
        if (Tools.validate(Request["mobile"].ToString()))
        {
            Response.Write("<script>alert('手机号中不能含有非法字符');history.back()</script>");
            Response.End();
        }
        if (Tools.validate(Request["address"].ToString()))
        {
            Response.Write("<script>alert('地址中不能含有非法字符');history.back()</script>");
            Response.End();
        }
        using (SqlConnection sqlconn = new SqlConnection(Tools.strConn))
        {
            SqlCommand cmd = new SqlCommand("update EMPLOYEE set name= '" + Request["name"] + "',tel = '" + Request["tel"] + "',mobile = '"+Request["mobile"]+"',address='"+Request["address"]+"' where id = '" + Request["id"] + "'", sqlconn);
            sqlconn.Open();
            cmd.ExecuteNonQuery();
            Response.Write("<script>alert('员工信息修改成功');opener.location='EmployeeManage.aspx';window.close()</script>");
        }
    }
}
