Ejemplo n.º 1
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        Hi.Model.SYS_Users    User            = null;
        Hi.Model.SYS_CompUser CompUser        = null;
        Hi.Model.SYS_RoleUser RoleUser        = null;
        Hi.BLL.SYS_RoleUser   RoleUserService = new Hi.BLL.SYS_RoleUser();
        SqlTransaction        Tran            = null;

        if (KeyID != 0)
        {
            #region 优化权限前的代码
            //int userid = ViewState["Userid"].ToString().ToInt(0);
            //if (Common.GetUserExists("UserName", txtUserName.Value.Trim(), userid.ToString()))
            //{
            //    JScript.AlertMsgOne(this, "该登录帐号已存在!", JScript.IconOption.错误);
            //    return;
            //}
            //if (Common.GetUserExists("Phone", txtPhone.Value.Trim(), userid.ToString()))
            //{
            //    JScript.AlertMsgOne(this, "该手机号码已存在!", JScript.IconOption.错误);
            //    return;
            //}
            //if (txtPwd.Text.Trim() != txtUserPwd.Text.Trim())
            //{
            //    JScript.AlertMsgOne(this, "确认密码填写不一致!", JScript.IconOption.错误);
            //    return;
            //}
            //List<Hi.Model.SYS_CompUser> ListCompUser = new Hi.BLL.SYS_CompUser().GetList("", "id=" + KeyID + " and isnull(dr,0)=0", "");
            //if (ListCompUser.Count == 0)
            //{
            //    JScript.AlertMethod(this, "用户明细数据有误!", JScript.IconOption.错误, "function (){ history.go(-1) ; }");
            //    return;
            //}
            //if (rdEnabledNo.Checked)
            //{
            //    if (ListCompUser[0].UType == 5)
            //    {
            //        JScript.AlertMsgOne(this, "用户为系统管理员,不可禁用!", JScript.IconOption.错误);
            //        return;
            //    }
            //}
            //else
            //{
            //    if (ListCompUser[0].UType != 5)
            //    {
            //        List<Hi.Model.SYS_Role> ListRole = new Hi.BLL.SYS_Role().GetList("RoleName,IsEnabled", " dr=0 and id=" + ListCompUser[0].RoleID + "", "");
            //        if (ListRole.Count > 0)
            //        {
            //            if (ListRole[0].IsEnabled == 0)
            //            {
            //                JScript.AlertMsgOne(this, "请先启用该人员所在岗位(" + ListRole[0].RoleName + ")!", JScript.IconOption.错误, 2500);
            //                return;
            //            }
            //        }
            //    }
            //}
            //Tran = DBUtility.SqlHelper.CreateStoreTranSaction();
            //User = new Hi.BLL.SYS_Users().GetModel(userid);
            //User.TrueName = txtTrueName.Value.Trim();
            //User.Identitys = txtIdentitys.Value.Trim();
            //User.Address = txtAddress.Value.Trim();
            //User.Email = txtEmail.Value.Trim();
            //ListCompUser[0].IsEnabled = rdEnabledYes.Checked ? 1 : 0;
            //ListCompUser[0].ts = DateTime.Now;
            //ListCompUser[0].modifyuser = UserID;
            //if (txtUserPwd.Text.Trim() != Util.md5("123456"))
            //{
            //    User.UserPwd = Util.md5(txtUserPwd.Text.Trim());
            //}
            //if (ListCompUser[0].UType != 4)
            //{
            //    User.UserName = txtUserName.Value.Trim();
            //    User.Phone = txtPhone.Value.Trim();
            //}
            //User.ts = DateTime.Now;
            //User.modifyuser = UserID;
            //new Hi.BLL.SYS_Users().Update(User, Tran);
            //new Hi.BLL.SYS_CompUser().Update(ListCompUser[0], Tran);
            //Tran.Commit();
            //JScript.AlertMethod(this, "操作成功!", JScript.IconOption.正确, "function(){ cancel(); }");
            #endregion
            Tran = DBUtility.SqlHelper.CreateStoreTranSaction();
            //修改
            User     = new Hi.BLL.SYS_Users().GetModel(KeyID);
            CompUser = new Hi.Model.SYS_CompUser();
            if (User.UserName != txtUserName.Value.Trim())
            {
                if (Common.GetUserExists("UserName", txtUserName.Value.Trim()))
                {
                    JScript.AlertMsgOne(this, "该登录帐号已存在!", JScript.IconOption.错误);
                    return;
                }
            }
            if (User.Phone != txtPhone.Value.Trim())
            {
                if (txtPhone.Value.Trim() == "")
                {
                    JScript.AlertMsgOne(this, "手机号码不能为空!", JScript.IconOption.错误);
                    return;
                }
                if (Common.GetUserExists("Phone", txtPhone.Value.Trim()))
                {
                    JScript.AlertMsgOne(this, "该手机号码已存在!", JScript.IconOption.错误);
                    return;
                }
            }
            if (txtPwd.Text.Trim() != txtUserPwd.Text.Trim())
            {
                JScript.AlertMsgOne(this, "确认密码填写不一致!", JScript.IconOption.错误);
                return;
            }
            //禁用时判断
            if (rdEnabledNo.Checked)
            {
                List <Hi.Model.SYS_CompUser> ListCompUser = new Hi.BLL.SYS_CompUser().GetList("", " CompID=" + CompID + " AND UserID=" + KeyID + " AND dr=0 AND IsEnabled=1 ", "");
                if (ListCompUser[0].UType == 5)
                {
                    JScript.AlertMsgOne(this, "用户为管理员,不可禁用!", JScript.IconOption.错误);
                    return;
                }
                else
                {
                    User.IsEnabled     = 0;
                    CompUser.IsEnabled = 0;
                    List <Hi.Model.SYS_RoleUser> roleusers = new Hi.BLL.SYS_RoleUser().GetList("", " UserID=" + KeyID + " AND dr=0 ", "");
                    if (roleusers.Count > 0)
                    {
                        for (int i = 0; i < roleusers.Count; i++)
                        {
                            roleusers[i].IsEnabled = false;
                        }
                    }
                }
            }
            if (rdEnabledYes.Checked)
            {
                User.IsEnabled     = 1;
                CompUser.IsEnabled = 1;
            }
            User.UserName  = Common.NoHTML(txtUserName.Value.Trim());
            User.TrueName  = Common.NoHTML(txtTrueName.Value.Trim());
            User.Identitys = Common.NoHTML(txtIdentitys.Value.Trim());
            User.Phone     = Common.NoHTML(txtPhone.Value.Trim());
            if (txtPwd.Text.Trim() != User.UserPwd)
            {
                User.UserPwd = Util.md5(txtUserPwd.Text.Trim());
            }
            User.Address    = Common.NoHTML(txtAddress.Value.Trim());
            User.Email      = Common.NoHTML(txtEmail.Value.Trim());
            User.Type       = 1;
            User.ts         = DateTime.Now;
            User.modifyuser = UserID;
            CompUser.UType  = 1;
            //岗位权限表
            List <Hi.Model.SYS_RoleUser> roleuser = new Hi.BLL.SYS_RoleUser().GetList("", "  UserID=" + KeyID + "  AND dr=0 ", "");
            for (int i = 0; i < roleuser.Count; i++)
            {
                roleuser[i].IsEnabled = false;
                roleuser[i].ts        = DateTime.Now;
                RoleUserService.Update(roleuser[i]);
            }
            if (hidMyRole.Value != "")
            {
                string[] rolestr = hidMyRole.Value.Substring(0, hidMyRole.Value.Length - 1).Split(',');
                for (int i = 0; i < rolestr.Length; i++)
                {
                    List <Hi.Model.SYS_RoleUser> rolenew = new Hi.BLL.SYS_RoleUser().GetList("", "  UserID=" + KeyID + " AND dr=0 AND RoleID=" + rolestr[i].ToInt(0) + " ", "");
                    if (rolenew.Count > 0)
                    {
                        rolenew[0].IsEnabled = true;
                        rolenew[0].ts        = DateTime.Now;
                        RoleUserService.Update(rolenew[0]);
                    }
                    else
                    {
                        RoleUser            = new Hi.Model.SYS_RoleUser();
                        RoleUser.FunType    = 1;
                        RoleUser.UserID     = KeyID;
                        RoleUser.RoleID     = rolestr[i].ToInt(0);
                        RoleUser.IsEnabled  = true;
                        RoleUser.CreateUser = this.UserID.ToString();
                        RoleUser.CreateDate = DateTime.Now;
                        RoleUser.ts         = DateTime.Now;
                        RoleUser.dr         = 0;
                        RoleUserService.Add(RoleUser, Tran);
                    }
                }
            }
            new Hi.BLL.SYS_Users().Update(User, Tran);
            new Hi.BLL.SYS_CompUser().Update(CompUser, Tran);
            Tran.Commit();
            Response.Redirect("UserInfo.aspx?KeyId=" + Common.DesEncrypt(KeyID.ToString(), Common.EncryptKey));
        }
        else
        {
            if (Common.GetUserExists("UserName", txtUserName.Value.Trim()))
            {
                JScript.AlertMsgOne(this, "该登录帐号已存在!", JScript.IconOption.错误);
                return;
            }
            if (txtPhone.Value.Trim() == "")
            {
                JScript.AlertMsgOne(this, "手机号码不能为空!", JScript.IconOption.错误);
                return;
            }
            if (Common.GetUserExists("Phone", txtPhone.Value.Trim()))
            {
                JScript.AlertMsgOne(this, "该手机号码已存在!", JScript.IconOption.错误);
                return;
            }
            if (txtPwd.Text.Trim() != txtUserPwd.Text.Trim())
            {
                JScript.AlertMsgOne(this, "确认密码填写不一致!", JScript.IconOption.错误);
                return;
            }
            Tran          = DBUtility.SqlHelper.CreateStoreTranSaction();
            User          = new Hi.Model.SYS_Users();
            User.UserName = Common.NoHTML(txtUserName.Value.Trim());
            User.UserPwd  = Util.md5(txtUserPwd.Text.Trim());
            //User.UserLoginName = txtUserLoginName.Value.Trim();
            User.TrueName = Common.NoHTML(txtTrueName.Value.Trim());
            //User.Sex = rdSexYes.Checked ? "男" : "女";
            User.Phone = Common.NoHTML(txtPhone.Value.Trim());
            //User.Tel = txtTel.Value.Trim();
            User.Identitys    = Common.NoHTML(txtIdentitys.Value.Trim());
            User.Address      = Common.NoHTML(txtAddress.Value.Trim());
            User.Email        = Common.NoHTML(txtEmail.Value.Trim());
            User.IsEnabled    = rdEnabledYes.Checked ? 1 : 0;
            User.IsFirst      = 0;
            User.CreateDate   = DateTime.Now;
            User.CreateUserID = UserID;
            User.AuditUser    = UserID.ToString();
            User.ts           = DateTime.Now;
            User.modifyuser   = UserID;
            int userid = new Hi.BLL.SYS_Users().Add(User, Tran);
            CompUser              = new Hi.Model.SYS_CompUser();
            CompUser.CompID       = CompID;
            CompUser.DisID        = DisID;
            CompUser.CreateDate   = DateTime.Now;
            CompUser.CreateUserID = UserID;
            CompUser.modifyuser   = UserID;
            CompUser.CType        = 2;
            CompUser.UType        = 1;//用户类型
            CompUser.RoleID       = 0;
            CompUser.IsEnabled    = rdEnabledYes.Checked ? 1 : 0;
            CompUser.IsAudit      = 2;
            CompUser.ts           = DateTime.Now;
            CompUser.dr           = 0;
            CompUser.UserID       = userid;
            new Hi.BLL.SYS_CompUser().Add(CompUser, Tran);
            //岗位权限表
            if (hidMyRole.Value != "")
            {
                string[] rolestr = hidMyRole.Value.Split(',');
                foreach (string str in rolestr)
                {
                    if (str != "" && Convert.ToInt32(str) > 0)
                    {
                        RoleUser            = new Hi.Model.SYS_RoleUser();
                        RoleUser.FunType    = 1;
                        RoleUser.UserID     = userid;
                        RoleUser.RoleID     = Convert.ToInt32(str);
                        RoleUser.IsEnabled  = true;
                        RoleUser.CreateUser = this.UserID.ToString();
                        RoleUser.CreateDate = DateTime.Now;
                        RoleUser.ts         = DateTime.Now;
                        RoleUser.dr         = 0;
                        RoleUserService.Add(RoleUser, Tran);
                    }
                }
            }
            Tran.Commit();
            Response.Redirect("UserInfo.aspx?KeyId=" + Common.DesEncrypt(userid.ToString(), Common.EncryptKey));
            //this.Page.ClientScript.RegisterStartupScript(Page.GetType(), "msg", "<script>cancel()</script>");
        }
    }
Ejemplo n.º 2
0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        #region 没有优化岗位权限前的代码
        //SqlTransaction Tran = DBUtility.SqlHelper.CreateStoreTranSaction();
        //Hi.Model.SYS_Users User = null;
        //if (KeyID != 0)
        //{
        //    //修改
        //    int userid = KeyID;
        //    User = new Hi.BLL.SYS_Users().GetModel(userid);
        //    if (Common.GetUserExists("UserName", txtUserName.Value.Trim(), userid.ToString()))
        //    {
        //        JScript.AlertMsgOne(this, "该登录帐号已存在!", JScript.IconOption.错误);
        //        return;
        //    }
        //    if (Common.GetUserExists("Phone", txtPhone.Value.Trim(), userid.ToString()))
        //    {
        //        JScript.AlertMsgOne(this, "该手机号码已存在!", JScript.IconOption.错误);
        //        return;
        //    }
        //    if (txtPwd.Text.Trim() != txtUserPwd.Text.Trim())
        //    {
        //        JScript.AlertMsgOne(this, "确认密码填写不一致!", JScript.IconOption.错误);
        //        return;
        //    }

        //    List<Hi.Model.SYS_CompUser> ListCompUser = new Hi.BLL.SYS_CompUser().GetList("", " CompID="+CompID+" AND UserID="+KeyID+" AND dr=0 AND IsEnabled=1 ", "");
        //    if (ListCompUser.Count == 0)
        //    {
        //        JScript.AlertMethod(this, "员工帐号信息有误!", JScript.IconOption.错误, "function (){ history.go(-1) ; }");
        //        return;
        //    }
        //    if (ListCompUser[0].UType != 4)
        //    {
        //        User.UserName = txtUserName.Value.Trim();
        //        User.Phone = txtPhone.Value.Trim();
        //    }
        //    if (rdEnabledNo.Checked)
        //    {
        //        if (ListCompUser[0].UType == 4)
        //        {
        //            JScript.AlertMsgOne(this, "用户为系统管理员,不可禁用!", JScript.IconOption.错误);
        //            return;
        //        }
        //    }
        //    User.TrueName = txtTrueName.Value.Trim();
        //    User.Identitys = txtIdentitys.Value.Trim();
        //    User.Address = txtAddress.Value.Trim();
        //    User.Email = txtEmail.Value.Trim();
        //    ListCompUser[0].IsEnabled = rdEnabledYes.Checked ? 1 : 0;
        //    ListCompUser[0].ts = DateTime.Now;
        //    ListCompUser[0].modifyuser = UserID;
        //    if (txtUserPwd.Text.Trim() != Util.md5("123456"))
        //    {
        //        User.UserPwd = Util.md5(txtUserPwd.Text.Trim());
        //    }
        //    User.ts = DateTime.Now;
        //    User.modifyuser = UserID;
        //    List<Hi.Model.SYS_RoleUser> list = new Hi.BLL.SYS_RoleUser().GetList("", " dr=0 and IsEnabled=1 and UserID=" + KeyID + "", "");
        //    if (list.Count > 0)
        //    {
        //        for (int i = 0; i < list.Count; i++)
        //        {
        //            Hi.Model.SYS_RoleUser roleu = new Hi.Model.SYS_RoleUser();
        //            roleu.ID = list[0].ID;
        //            roleu.FunType = list[0].FunType;
        //            roleu.UserID = list[0].UserID;
        //            roleu.RoleID = list[0].RoleID;
        //            roleu.IsEnabled = true;//禁用
        //            roleu.CreateUser = list[0].CreateUser;
        //            roleu.CreateDate = list[0].CreateDate;
        //            roleu.ts = DateTime.Now;
        //            roleu.dr = list[0].dr;
        //            bool sss = new Hi.BLL.SYS_RoleUser().Update(roleu);
        //        }
        //    }
        //    else
        //    {
        //        //岗位权限表
        //        if (hidMyRole.Value != "")
        //        {
        //            string[] rolestr = hidMyRole.Value.Split(',');
        //            Hi.BLL.SYS_RoleUser RoleUserService = new Hi.BLL.SYS_RoleUser();
        //            Hi.Model.SYS_RoleUser RoleUser = null;
        //            foreach (string str in rolestr)
        //            {
        //                if (str != "" && Convert.ToInt32(str) > 0)
        //                {
        //                    RoleUser = new Hi.Model.SYS_RoleUser();
        //                    RoleUser.FunType = 1;
        //                    RoleUser.UserID = userid;
        //                    RoleUser.RoleID = Convert.ToInt32(str);
        //                    RoleUser.IsEnabled = true;
        //                    RoleUser.CreateUser = this.UserID.ToString();
        //                    RoleUser.CreateDate = DateTime.Now;
        //                    RoleUser.ts = DateTime.Now;
        //                    RoleUser.dr = 0;
        //                    RoleUserService.Add(RoleUser, Tran);
        //                }
        //            }
        //        }
        //    }
        //    new Hi.BLL.SYS_Users().Update(User, Tran);
        //    new Hi.BLL.SYS_CompUser().Update(ListCompUser[0], Tran);
        //    Tran.Commit();
        //    JScript.AlertMethod(this, "操作成功!", JScript.IconOption.正确, "UserInfo.aspx?KeyId="+KeyID);
        //}
        //else
        //{
        //    //新增
        //    if (Common.GetUserExists("UserName", txtUserName.Value.Trim()))
        //    {
        //        JScript.AlertMsgOne(this, "该登录帐号已存在!", JScript.IconOption.错误);
        //        return;
        //    }
        //    if (Common.GetUserExists("Phone", txtPhone.Value.Trim()))
        //    {
        //        JScript.AlertMsgOne(this, "该手机号码已存在!", JScript.IconOption.错误);
        //        return;
        //    }
        //    if (txtPwd.Text.Trim() != txtUserPwd.Text.Trim())
        //    {
        //        JScript.AlertMsgOne(this, "确认密码填写不一致!", JScript.IconOption.错误);
        //        return;
        //    }
        //    User = new Hi.Model.SYS_Users();
        //    User.CompID = CompID;//厂商ID
        //    User.DisID = 0;
        //    User.Type = 3;
        //    User.AuditState = 2;
        //    User.UserName = txtUserName.Value.Trim();
        //    User.UserPwd = Util.md5(txtUserPwd.Text.Trim());
        //    User.TrueName = txtTrueName.Value.Trim();
        //    User.Phone = txtPhone.Value.Trim();
        //    User.Identitys = txtIdentitys.Value.Trim();
        //    User.Address = txtAddress.Value.Trim();
        //    User.Email = txtEmail.Value.Trim();
        //    User.IsEnabled = rdEnabledYes.Checked ? 1 : 0;
        //    User.IsFirst = 0;
        //    User.CreateDate = DateTime.Now;
        //    User.CreateUserID = UserID;
        //    User.AuditUser = UserID.ToString();
        //    User.ts = DateTime.Now;
        //    User.modifyuser = UserID;
        //    int userid = new Hi.BLL.SYS_Users().Add(User, Tran);
        //    //多角色表
        //    Hi.Model.SYS_CompUser CompUser = new Hi.Model.SYS_CompUser();
        //    CompUser.CompID = CompID;
        //    CompUser.DisID = 0;
        //    CompUser.CreateDate = DateTime.Now;
        //    CompUser.CreateUserID = UserID;
        //    CompUser.modifyuser = UserID;
        //    CompUser.CType = 1;
        //    CompUser.UType = 3;
        //    CompUser.RoleID = 0;//权限屏蔽掉
        //    CompUser.IsEnabled = rdEnabledYes.Checked ? 1 : 0;
        //    CompUser.IsAudit = 2;
        //    CompUser.ts = DateTime.Now;
        //    CompUser.dr = 0;
        //    CompUser.UserID = userid;
        //    new Hi.BLL.SYS_CompUser().Add(CompUser, Tran);
        //    //岗位权限表
        //    if (hidMyRole.Value != "")
        //    {
        //        string[] rolestr = hidMyRole.Value.Split(',');
        //        Hi.BLL.SYS_RoleUser RoleUserService = new Hi.BLL.SYS_RoleUser();
        //        Hi.Model.SYS_RoleUser RoleUser = null;
        //        foreach (string str in rolestr)
        //        {
        //            if (str != "" && Convert.ToInt32(str) > 0)
        //            {
        //                RoleUser = new Hi.Model.SYS_RoleUser();
        //                RoleUser.FunType = 1;
        //                RoleUser.UserID = userid;
        //                RoleUser.RoleID = Convert.ToInt32(str);
        //                RoleUser.IsEnabled = true;
        //                RoleUser.CreateUser = this.UserID.ToString();
        //                RoleUser.CreateDate = DateTime.Now;
        //                RoleUser.ts = DateTime.Now;
        //                RoleUser.dr = 0;
        //                RoleUserService.Add(RoleUser, Tran);
        //            }
        //        }
        //    }
        //    Tran.Commit();
        //    //this.Page.ClientScript.RegisterStartupScript(Page.GetType(), "msg", "<script>cancel()</script>");
        //    Response.Redirect("UserInfo.aspx?KeyId=" + userid);
        //}
        #endregion
        Hi.Model.SYS_Users    User            = null;
        Hi.Model.SYS_CompUser CompUser        = null;
        Hi.Model.SYS_RoleUser RoleUser        = null;
        Hi.BLL.SYS_RoleUser   RoleUserService = new Hi.BLL.SYS_RoleUser();
        if (KeyID != 0)
        {
            SqlTransaction Tran = DBUtility.SqlHelper.CreateStoreTranSaction();
            //修改
            User     = new Hi.BLL.SYS_Users().GetModel(KeyID);
            CompUser = new Hi.Model.SYS_CompUser();
            if (User.UserName != txtUserName.Value.Trim())
            {
                if (Common.GetUserExists("UserName", txtUserName.Value.Trim()))
                {
                    JScript.AlertMsgOne(this, "该登录帐号已存在!", JScript.IconOption.错误);
                    return;
                }
            }
            if (User.Phone != txtPhone.Value.Trim())
            {
                if (txtPhone.Value.Trim() == "")
                {
                    JScript.AlertMsgOne(this, "手机号码不能为空!", JScript.IconOption.错误);
                    return;
                }
                if (Common.GetUserExists("Phone", txtPhone.Value.Trim()))
                {
                    JScript.AlertMsgOne(this, "该手机号码已存在!", JScript.IconOption.错误);
                    return;
                }
            }
            if (txtPwd.Text.Trim() != txtUserPwd.Text.Trim())
            {
                JScript.AlertMsgOne(this, "确认密码填写不一致!", JScript.IconOption.错误);
                return;
            }
            List <Hi.Model.SYS_CompUser> ListCompUser = new Hi.BLL.SYS_CompUser().GetList("*", " CompID=" + CompID + " AND UserID=" + KeyID + " AND dr=0 AND IsEnabled=1 ", "");
            CompUser = ListCompUser[0];
            //禁用时判断
            if (rdEnabledNo.Checked)
            {
                if (ListCompUser[0].UType == 4)
                {
                    JScript.AlertMsgOne(this, "用户为管理员,不可禁用!", JScript.IconOption.错误);
                    return;
                }
                else
                {
                    User.IsEnabled     = 0;
                    CompUser.IsEnabled = 0;
                    List <Hi.Model.SYS_RoleUser> roleusers = new Hi.BLL.SYS_RoleUser().GetList("", " UserID=" + KeyID + " AND dr=0 ", "");
                    if (roleusers.Count > 0)
                    {
                        for (int i = 0; i < roleusers.Count; i++)
                        {
                            roleusers[i].IsEnabled = false;
                        }
                    }
                }
            }
            if (rdEnabledYes.Checked)
            {
                User.IsEnabled     = 1;
                CompUser.IsEnabled = 1;
            }
            User.UserName  = Common.NoHTML(txtUserName.Value.Trim());
            User.TrueName  = Common.NoHTML(txtTrueName.Value.Trim());
            User.Identitys = Common.NoHTML(txtIdentitys.Value.Trim());
            if (txtPwd.Text.Trim() != User.UserPwd)
            {
                User.UserPwd = Util.md5(txtUserPwd.Text.Trim());
            }
            User.Address    = Common.NoHTML(txtAddress.Value.Trim());
            User.Email      = Common.NoHTML(txtEmail.Value.Trim());
            User.Type       = 3;
            User.ts         = DateTime.Now;
            User.modifyuser = UserID;
            if (DisSalesManID.Value != "0")
            {
                if (CompUser.UType == 4)
                {
                    JScript.AlertMsgOne(this, "用户为管理员,不可修改类型!", JScript.IconOption.错误);
                    return;
                }
                CompUser.UType         = 6;
                CompUser.DisSalesManID = Convert.ToInt32(DisSalesManID.Value);
            }
            else
            {
                if (CompUser.UType == 4)
                {
                    CompUser.UType = 4;
                }
                else
                {
                    CompUser.UType = 3;
                }

                CompUser.DisSalesManID = 0;
            }


            //岗位权限表
            List <Hi.Model.SYS_RoleUser> roleuser = new Hi.BLL.SYS_RoleUser().GetList("", "  UserID=" + KeyID + "  AND dr=0 ", "");
            for (int i = 0; i < roleuser.Count; i++)
            {
                roleuser[i].IsEnabled = false;
                roleuser[i].ts        = DateTime.Now;
                RoleUserService.Update(roleuser[i]);
            }
            if (hidMyRole.Value != "")
            {
                string[] rolestr = hidMyRole.Value.Substring(0, hidMyRole.Value.Length - 1).Split(',');
                for (int i = 0; i < rolestr.Length; i++)
                {
                    List <Hi.Model.SYS_RoleUser> rolenew = new Hi.BLL.SYS_RoleUser().GetList("", "  UserID=" + KeyID + " AND dr=0 AND RoleID=" + rolestr[i].ToInt(0) + " ", "");
                    if (rolenew.Count > 0)
                    {
                        rolenew[0].IsEnabled = true;
                        rolenew[0].ts        = DateTime.Now;
                        RoleUserService.Update(rolenew[0]);
                    }
                    else
                    {
                        RoleUser            = new Hi.Model.SYS_RoleUser();
                        RoleUser.FunType    = 1;
                        RoleUser.UserID     = KeyID;
                        RoleUser.RoleID     = rolestr[i].ToInt(0);
                        RoleUser.IsEnabled  = true;
                        RoleUser.CreateUser = this.UserID.ToString();
                        RoleUser.CreateDate = DateTime.Now;
                        RoleUser.ts         = DateTime.Now;
                        RoleUser.dr         = 0;
                        RoleUserService.Add(RoleUser, Tran);
                    }
                }
            }
            new Hi.BLL.SYS_Users().Update(User, Tran);
            new Hi.BLL.SYS_CompUser().Update(CompUser, Tran);
            Tran.Commit();
            Response.Redirect("UserInfo.aspx?KeyId=" + Common.DesEncrypt(KeyID.ToString(), Common.EncryptKey));
        }
        else
        {
            SqlTransaction Tran = DBUtility.SqlHelper.CreateStoreTranSaction();
            //新增
            if (Common.GetUserExists("UserName", txtUserName.Value.Trim()))
            {
                JScript.AlertMsgOne(this, "该登录帐号已存在!", JScript.IconOption.错误);
                return;
            }
            if (txtPhone.Value.Trim() == "")
            {
                JScript.AlertMsgOne(this, "手机号码不能为空!", JScript.IconOption.错误);
                return;
            }
            if (Common.GetUserExists("Phone", txtPhone.Value.Trim()))
            {
                JScript.AlertMsgOne(this, "该手机号码已存在!", JScript.IconOption.错误);
                return;
            }
            if (txtPwd.Text.Trim() != txtUserPwd.Text.Trim())
            {
                JScript.AlertMsgOne(this, "确认密码填写不一致!", JScript.IconOption.错误);
                return;
            }
            User              = new Hi.Model.SYS_Users();
            User.CompID       = CompID;//厂商ID
            User.DisID        = 0;
            User.AuditState   = 2;
            User.UserName     = Common.NoHTML(txtUserName.Value.Trim());
            User.UserPwd      = Util.md5(txtUserPwd.Text.Trim());
            User.TrueName     = Common.NoHTML(txtTrueName.Value.Trim());
            User.Phone        = Common.NoHTML(txtPhone.Value.Trim());
            User.Identitys    = Common.NoHTML(txtIdentitys.Value.Trim());
            User.Address      = Common.NoHTML(txtAddress.Value.Trim());
            User.Email        = Common.NoHTML(txtEmail.Value.Trim());
            User.IsEnabled    = rdEnabledYes.Checked ? 1 : 0;
            User.IsFirst      = 0;
            User.CreateDate   = DateTime.Now;
            User.CreateUserID = UserID;
            User.AuditUser    = UserID.ToString();
            User.ts           = DateTime.Now;
            User.modifyuser   = UserID;
            int userid = new Hi.BLL.SYS_Users().Add(User, Tran);
            //多角色表
            CompUser              = new Hi.Model.SYS_CompUser();
            CompUser.CompID       = CompID;
            CompUser.DisID        = 0;
            CompUser.CreateDate   = DateTime.Now;
            CompUser.CreateUserID = UserID;
            CompUser.modifyuser   = UserID;
            CompUser.CType        = 1;
            if (DisSalesManID.Value != "0")
            {
                CompUser.UType         = 6;
                CompUser.DisSalesManID = Convert.ToInt32(DisSalesManID.Value);
            }
            else
            {
                CompUser.UType = 3;
            }
            CompUser.RoleID    = 0;//权限屏蔽掉
            CompUser.IsEnabled = rdEnabledYes.Checked ? 1 : 0;
            CompUser.IsAudit   = 2;
            CompUser.ts        = DateTime.Now;
            CompUser.dr        = 0;
            CompUser.UserID    = userid;
            new Hi.BLL.SYS_CompUser().Add(CompUser, Tran);
            //岗位权限表
            if (hidMyRole.Value != "")
            {
                string[] rolestr = hidMyRole.Value.Split(',');
                foreach (string str in rolestr)
                {
                    if (str != "" && Convert.ToInt32(str) > 0)
                    {
                        RoleUser            = new Hi.Model.SYS_RoleUser();
                        RoleUser.FunType    = 1;
                        RoleUser.UserID     = userid;
                        RoleUser.RoleID     = Convert.ToInt32(str);
                        RoleUser.IsEnabled  = true;
                        RoleUser.CreateUser = this.UserID.ToString();
                        RoleUser.CreateDate = DateTime.Now;
                        RoleUser.ts         = DateTime.Now;
                        RoleUser.dr         = 0;
                        RoleUserService.Add(RoleUser, Tran);
                    }
                }
            }
            Tran.Commit();
            Response.Redirect("UserInfo.aspx?KeyId=" + Common.DesEncrypt(userid.ToString(), Common.EncryptKey));
        }
    }