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

namespace KstCMS.KstCMS_Manager.SystemSet.Users.urs
{
    public partial class AddUser : 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)
        {
            string RoleId_List = Request.Form.Get("RoleId_List");
            string Pwd = Request.Form.Get("Password1");
            if (Pwd != Request.Form.Get("Password"))
            {
                throw new Exception("二次输入的密码不一至，请重新输入密码！");
            }
            Pwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Pwd, "MD5");
            string[] FieldValues = new string[]{
                UserName.Text.Trim(),
                Pwd,
                YourName.Text.Trim(),
                Email.Text.Trim(),
                RoleId_List
           };
            
            KstCmsBase.DAL.Users.Users_Insert(FieldValues, "UserName", "UserPwd", "YourName", "Email", "UserRole");
            ShowMsgModle("增加成功！", "location.href=\"index.aspx\";");
            if (ActMail.Checked)
            {
                StringBuilder BodySb=new StringBuilder();
                BodySb.Append("网站后台网址："+SysRootUrl+"/KstCMS_Manager/Admin_login.aspx");
                BodySb.Append("<br />您的用户名："+UserName.Text.Trim());
                BodySb.Append("<br />密码："+ Request.Form.Get("Password"));
                KstCmsBase.DAL.EmlServer.Mailto("管理员为你开通了网站后台用户名及密码", BodySb.ToString(), System.Text.Encoding.UTF8, Email.Text.Trim());
            }
            
        }


        void Set_Control()
        {
            string[] sTitles = new string[]{
                 "用户名~noChinese!",
                 "真实姓名~!",
                 "邮件地址~email!"
            };
            base.Set_Control(sTitles, UserName, YourName, Email);
        }
    }
}