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 hqgl.user;
using WebMessageBox;
using hqgl.dept;
using HtmlTextFormat;
public partial class general_user_user_edit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //5/1-a/sp-x
        if (!Page.IsPostBack)
        { 
            deptchuli dpc = new deptchuli();
            ListItemCollection lic = dpc.Make_DropList();
            Select2.DataBind();
            foreach (ListItem li in lic)
                Select1.Items.Add(li);
            DataLoad();
           
        }
    }
    public void DataLoad()
    {
        string id = Request.QueryString["uid"];
        if (string.IsNullOrEmpty(id))
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetExpires(DateTime.Now.AddHours(-1));
            ClientScript.RegisterStartupScript(this.GetType(), "start", "history.back();");
        }
        else
        {
            userinfo uinfo;
            userchuli uch = new userchuli();
            uinfo = uch.user_getDetail(id);
            Text2.Value = uinfo.u_id;
            Text3.Value = uinfo.u_name;
            Text1.Value = uinfo.user_no;
            NOT_LOGIN.Checked = uinfo.not_login.ToLower() == "off" ? true : false;
            NOT_VIEW_TABLE.Checked = uinfo.not_view_table.ToLower() == "off" ? true : false;
            NOT_VIEW_USER.Checked = uinfo.not_view_user.ToLower() == "off" ? true : false;
            Select1.SelectedIndex = -1;
            Select2.SelectedIndex = -1;
            Select3.SelectedIndex = -1;
            Select4.SelectedIndex = -1;
            Select5.SelectedIndex = -1;
            foreach (ListItem lt in Select2.Items)
                if (lt.Value == uinfo.user_priv)
                {
                    lt.Selected = true;
                    break;
                }
            foreach (ListItem lt in Select1.Items)
                if (lt.Value == uinfo.dept_id)
                {
                    lt.Selected = true;
                    break;
                }
            foreach (ListItem lt in Select3.Items)
                if (lt.Value == uinfo.duty_type)
                {
                    lt.Selected = true;
                    break;
                }
            foreach (ListItem lt in Select4.Items)
                if (lt.Value == uinfo.sex)
                {
                    lt.Selected = true;
                    break;
                }
            foreach(ListItem lt in Select5.Items)
                if (lt.Value == uinfo.post_priv)
                {
                    lt.Selected = true;
                    break;
                }

        }
    }
    protected void Submit1_ServerClick(object sender, EventArgs e)
    {
        userinfo uinfo = new userinfo();
        userchuli uch = new userchuli();
        uinfo.u_id = Text2.Value;
        uinfo.u_name = Text3.Value;
        uinfo.user_no = Text1.Value;
        uinfo.not_login = NOT_LOGIN.Checked == true ? "off" : "on";
        uinfo.not_view_table = NOT_VIEW_TABLE.Checked == true ? "off" : "on";
        uinfo.not_view_user = NOT_VIEW_USER.Checked == true ? "off" : "on";
        uinfo.user_priv = Select2.Value;
        uinfo.dept_id =Select1.Value;
        uinfo.duty_type =Select3.Value;
        uinfo.sex =Select4.Value;
        uinfo.post_priv = Select5.Value;
        uinfo.birthday = "1988-12-28";
        uinfo.password = TextFormat.EncryptPassWord(Password1.Value);
        uch.user_edit(uinfo);
        MessageBox.Show("修改完成", "user_add.aspx");
    }
}
