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 Fm.Bussiness;
public partial class admin_user_sys_user_edit : BasePage
{
   
   
    protected void Page_Load(object sender, EventArgs e)
    { 
        
        //获取会员信息
        int u_id = 0;
        if (Request.QueryString["u_id"] != null)
        {
            u_id = int.Parse(Request.QueryString["u_id"].ToString());
        }
        if (!IsPostBack)
        {
            public_select ps = new public_select();
            DataView dv=ps.Getps("Fm_user_view","*","u_id="+u_id+"");
            
            //绑定用户组信息            
            drop_role.DataSource = ps.Getps("Fm_role","*","");
            drop_role.DataTextField = "r_name";
            drop_role.DataValueField = "r_id";
            drop_role.DataBind();

           
            //绑定会员信息 
            Lab_uname.Text = dv[0]["u_name"].ToString();
            txt_nichen.Text = dv[0]["u_nc"].ToString();
            txt_email.Text = dv[0]["u_mail"].ToString();
         

            foreach (ListItem i in drop_role.Items)
            {
                if (i.Value == dv[0]["r_id"].ToString())
                {
                    i.Selected = true;
                }
            }
        }
    }
    //保存修改的数据
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        public_select ps = new public_select();
        sys_user_user sys = new sys_user_user();
        int u_id=int.Parse(Request.QueryString["u_id"].ToString());
        DataView dv = ps.Getps("Fm_user_view", "*", "u_id=" + u_id + "");
        string pass = "";
       
        if(txt_newpass.Text.Trim()!=""&&txt_pass.Text.Trim()=="")
        {
            Response.Write("<script>alert('请输入原密码!');</script>");
        }
        else if (txt_pass.Text.Trim() != "" && dv[0]["u_pass"].ToString() != FormsAuthentication.HashPasswordForStoringInConfigFile(txt_pass.Text.Trim(), "MD5"))
        {
            Response.Write("<script>alert('请输入正确的原密码!');</script>");
        }
        else
        {
            //将获取的密码进行加密
            if (txt_newpass.Text != "")
            {
                pass = FormsAuthentication.HashPasswordForStoringInConfigFile(txt_newpass.Text.Trim(), "MD5");

            }
            else
            {
                pass = dv[0]["u_pass"].ToString();
            }
            //会员信息实体类
            Fm.EntityClass.User user = new Fm.EntityClass.User();
            user.u_name = Lab_uname.Text;
            user.u_pass = pass;
            user.u_nc=txt_nichen.Text;
            user.u_mail=txt_email.Text;
            if (sys.sys_user_update(user))
            {
                Fm.EntityClass.Urcenter ur = new Fm.EntityClass.Urcenter();
                ur.c_id =int.Parse(dv[0]["c_id"].ToString());
                ur.u_id = u_id;
                ur.r_id = int.Parse(drop_role.SelectedValue);
                if (sys.sys_ur_update(ur))
                {
                    Response.Redirect("../Erro.aspx?eid=该会员记录修改成功!&url=user/sys_user_list.aspx", false);
                }
            }
            else
            {
                Response.Write("<script>alert('...............!');</script>");
            }
        }
    }
}
