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 bianjiue : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            string btn = Request.QueryString["m"];
            string[] arry = btn.Split(',');
            string btname = arry[0];
            btnLogin.Text = btname;
            if (btname == "修改"&&!IsPostBack)
            {
                
                string btid = arry[1];
                DataTable dt = (bw.select("userid=" +"'"+ btid+"'")).Tables[0];
                userzhiwei.Text = dt.Rows[0][4].ToString();
                userschool.Text = dt.Rows[0][5].ToString();
                usertel.Text=dt.Rows[0][6].ToString();
                Textid.Text = dt.Rows[0][0].ToString();
                Textname.Text = dt.Rows[0][1].ToString();
                usersex.Text = dt.Rows[0][2].ToString();
                userbir.Text = Convert.ToDateTime(dt.Rows[0][3].ToString()).ToShortDateString();
            }
        }
              BLL.worker bw = new BLL.worker();
              model.worker mw = new model.worker();
        bool f = false;
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if (btnLogin.Text == "添加")
            {

                if (Textid.Text != "")
                {
                    if (Textname.Text != "")
                    {
                        if (userbir.Text != "")
                        {
                            if (Textid.Text.Length <= 6)
                            {
                                mw.userid = Textid.Text;
                                mw.username = Textname.Text;
                                mw.usersex = usersex.Text;
                                mw.userbirthday = userbir.Text;
                                mw.userzhiwei = userzhiwei.Text;
                                mw.userschool = userschool.Text;
                                mw.usertel = usertel.Text;
                                f = bw.inserus(mw);
                                if (f)
                                {
                                    Response.Write("<script>alert(' 添加成功')</script>");
                                    Textid.Text = "";
                                    Textname.Text = "";
                                    userbir.Text = "";
                                    userzhiwei.Text = "";
                                    userschool.Text = "";
                                    usertel.Text = "";
                                }
                                else
                                {
                                    Response.Write("<script>alert(' 添加失败')</script>");
                                }
                            }
                            else
                            {
                                Response.Write("<script>alert(' 编号不能超出六位数！')</script>");
                            }
                        }
                        else
                        {
                            Response.Write("<script>alert(' 出生日期不能为空')</script>");
                        }

                    }
                    else
                    {
                        Response.Write("<script>alert('员工姓名不能为空')</script>");
                    }
                }
                else
                {
                    Response.Write("<script>alert('员工编号不能空')</script>");
                }
            }
            if (btnLogin.Text == "修改")
            {

                string btn = Request.QueryString["m"];
                string[] arry = btn.Split(',');
                string olduserid=arry[1];
                mw.userid =  Textid.Text;
                mw.username = Textname.Text;
                mw.usersex = usersex.Text;
                mw.userbirthday = userbir.Text;
                mw.userzhiwei = userzhiwei.Text;
                mw.userschool = userschool.Text;
                mw.usertel = usertel.Text;
               f= bw.update(mw, olduserid);
               if (f)
               {
                   Response.Write("<script>alert(' 修改成功')</script>");
               }
               else
               {
                   Response.Write("<script>alert(' 修改失败')</script>");
               }
            }
        }

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