using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Model;

namespace ComResProSystem
{
    public partial class UserEdit :BasePage
    {
        BaseBLL bll = new BaseBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindUser();
            }
        }

        private void BindUser()
        {
            string ID = Request.QueryString["ID"];
            List<object> list = bll.SelectObject(typeof(User), "Users", "UserName,UserAge,UserBrith,UserPos,Part,UserTel,[PassWord],Sex,[Address]", "ID=" + ID);
            User user = (User)list[0];
            Tb_UserName.Text = user.UserName;
            Tb_UserAge.Text = user.UserAge;
            Tb_UserBrith.Text = user.UserBrith;
            Tb_UserTel.Text = user.UserTel;
            Tb_Address.Text = user.UserAddress;
            Dd_Part.Text = user.Part;
            Dd_UserPos.Text = user.UserPos;
            if (user.Sex == "True")
            {
                Rb_Man.Checked = true;
            }
            else
            {
                Rb_Women.Checked = true;
            }


        }
        protected void Ibt_Cancel_Click(object sender, ImageClickEventArgs e)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "close", "window.close()", true);
        }

        protected void Ibt_Submit_Click(object sender, ImageClickEventArgs e)
        {
            string ID = Request.QueryString["ID"];
            Dictionary<string, string> dic = base.FindControls(this.form1);
            dic.Add("UserPos", Dd_UserPos.Text);
            dic.Add("Part", Dd_Part.Text);
            dic.Add("Sex", Rb_Man.Checked == true ? "1" : "0");
            object obj = bll.CreateObject(typeof(User), dic);
            if (bll.UpdateObject(obj, "Users", "ID=" + ID) == 0)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "close", "alert('修改成功！');window.close()", true);
            }
        }
    }
}