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

namespace KstCMS.KstCMS_Manager.SystemSet.Users.person_info
{
    public partial class index : KstCmsBase.WebPage.FrmControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            OkBtn.Click += new EventHandler(OkBtn_Click);
            if (!IsPostBack)
            {
                Set_Control();
            }
        }

        void OkBtn_Click(object sender, EventArgs e)
        {
            KstCmsBase.Entities.UsersEntity TTUser = KstCmsBase.DAL.Users.Get_UserInfo(User.Identity.Name);
            string Oldpwd = Request.Form.Get("OLDPwd");
            string Pwd1 = Request.Form.Get("Pwd1");
            string Pwd2 = Request.Form.Get("Pwd2");
            Oldpwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Oldpwd, "MD5");
            if (Oldpwd != TTUser.UserPwd)
            {
                throw new Exception("旧密码不正确！");
            }
            if (Pwd1 != Pwd2)
            {
                throw new Exception("二次密码输入不一至，请重新输入！");
            }
            string[] updatevalues = new string[]{
                System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Pwd2,"MD5"),
                txt_Email.Text.Trim()
            };
            KstCmsBase.DAL.Users.Users_Update(Convert.ToInt32(TTUser.UserId), updatevalues, "UserPwd", "Email");
            ShowMsgModle("修改成功！");
        }

        void Set_Control()
        {
            KstCmsBase.Entities.UsersEntity TTUser = KstCmsBase.DAL.Users.Get_UserInfo(User.Identity.Name);
            string str=TTUser.RoleNameList;
            if(TTUser.isAdmin==1){
                 str="系统管理员";
            }
            lit_Info.Text = "您好！" + TTUser.YourName + ",您的用户名为：<span style=\"color:red\">" + TTUser.UserName + "</span>,所属角色为：" + str;
            txt_Email.Text = TTUser.Email;
            string[] Cons = new string[] { "邮件地址~email!" };
            base.Set_Control(Cons, txt_Email);
        }
    }
}