示例#1
0
        private void RoleEdit_Load(object sender, EventArgs e)
        {
            cmd = new Xr.Common.Controls.OpaqueCommand(this);
            cmd.ShowOpaqueLayer(0f);

            dcRole.DataType = typeof(RoleEntity);

            //获取下拉框数据
            String url = AppContext.AppConfig.serverUrl + "sys/sysRole/getDropDownData";

            this.DoWorkAsync(500, (o) =>  //耗时逻辑处理(此处不能操作UI控件,因为是在异步中)
            {
                String data = HttpClass.httpPost(url);
                return(data);
            }, null, (data) => //显示结果(此处用于对上面结果的处理,比如显示到界面上)
            {
                JObject objT = JObject.Parse(data.ToString());
                if (string.Compare(objT["state"].ToString(), "true", true) == 0)
                {
                    treeParent.Properties.DataSource               = objT["result"]["officeList"].ToObject <List <OfficeEntity> >();
                    treeParent.Properties.TreeList.KeyFieldName    = "id";       //设置ID  
                    treeParent.Properties.TreeList.ParentFieldName = "parentId"; //设置PreID  
                    treeParent.Properties.DisplayMember            = "name";     //要在树里展示的
                    treeParent.Properties.ValueMember              = "id";       //对应的value
                    treeParent.EditValue = "2";

                    lueDataScope.Properties.DataSource    = objT["result"]["dataScopeDictList"].ToObject <List <OfficeEntity> >();
                    lueDataScope.Properties.DisplayMember = "name";
                    lueDataScope.Properties.ValueMember   = "code";
                    if (objT["result"]["dataScopeDictList"].Count() > 0)
                    {
                        lueDataScope.EditValue = objT["result"]["dataScopeDictList"][0]["code"].ToString();
                    }

                    treeList1.DataSource                 = objT["result"]["menuList"].ToObject <List <MenuEntity> >();
                    treeList1.KeyFieldName               = "id";                 //设置ID  
                    treeList1.ParentFieldName            = "parentId";           //设置PreID  
                    treeList1.OptionsView.ShowCheckBoxes = true;                 //显示多选框
                    treeList1.OptionsBehavior.AllowRecursiveNodeChecking = true; //选中父节点,子节点也会全部选中
                    treeList1.OptionsBehavior.Editable = false;                  //数据不可编辑
                    treeList1.ExpandAll();                                       //展开所有节点

                    treeList2.DataSource                 = objT["result"]["functionList"].ToObject <List <FunctionEntity> >();
                    treeList2.KeyFieldName               = "id";                 //设置ID  
                    treeList2.ParentFieldName            = "parentId";           //设置PreID  
                    treeList2.OptionsView.ShowCheckBoxes = true;                 //显示多选框
                    treeList2.OptionsBehavior.AllowRecursiveNodeChecking = true; //选中父节点,子节点也会全部选中
                    treeList2.OptionsBehavior.Editable = false;                  //数据不可编辑
                    treeList2.ExpandAll();                                       //展开所有节点

                    if (role != null)
                    {
                        url = AppContext.AppConfig.serverUrl + "sys/sysRole/getRole?roleId=" + role.id;
                        this.DoWorkAsync(500, (o) => //耗时逻辑处理(此处不能操作UI控件,因为是在异步中)
                        {
                            data = HttpClass.httpPost(url);
                            return(data);
                        }, null, (data2) => //显示结果(此处用于对上面结果的处理,比如显示到界面上)
                        {
                            objT = JObject.Parse(data2.ToString());
                            if (string.Compare(objT["state"].ToString(), "true", true) == 0)
                            {
                                role = objT["result"].ToObject <RoleEntity>();
                                dcRole.SetValue(role);
                                String[] menuArray = role.menuIds.Split(',');
                                for (int i = 0; i < menuArray.Count(); i++)
                                {
                                    SetMenuNodeChecked(treeList1, menuArray[i], treeList1.Nodes);
                                }
                                String[] functionArray = role.functionIds.Split(',');
                                for (int i = 0; i < functionArray.Count(); i++)
                                {
                                    SetFunctionNodeChecked(treeList2, functionArray[i], treeList2.Nodes);
                                }
                                oldName = role.name;
                                cmd.HideOpaqueLayer();
                            }
                            else
                            {
                                cmd.HideOpaqueLayer();
                                MessageBoxUtils.Show(objT["message"].ToString(), MessageBoxButtons.OK,
                                                     MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, this);
                            }
                        });
                    }
                    else
                    {
                        role = new RoleEntity();
                        cmd.HideOpaqueLayer();
                    }
                }
                else
                {
                    cmd.HideOpaqueLayer();
                    MessageBoxUtils.Show(objT["message"].ToString(), MessageBoxButtons.OK,
                                         MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, this);
                }
            });
        }
示例#2
0
        private List <String> listCheckedRoleID = new List <String>(); //角色ID集合

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!dcUser.Validate())
            {
                return;
            }
            if (user.id == null)
            {
                if (tePassword.Text.Length == 0)
                {
                    dcUser.ShowError(tePassword, "密码不能为空");
                    return;
                }
            }
            if (user.id == null || (user.id != null && !user.password.Equals(tePassword.Text) && tePassword.Text.Length != 0))
            {
                if (radioGroup1.EditValue.Equals("1"))
                {
                    //密码复杂度验证
                    var regex = new Regex(@"
                        (?=.*[0-9])                     #必须包含数字
                        (?=.*[a-zA-Z])                  #必须包含小写或大写字母
                        (?=([\x21-\x7e]+)[^a-zA-Z0-9])  #必须包含特殊符号
                        .{8,16}                         #至少8个字符,最多16个字符
                        ", RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
                    if (!regex.IsMatch(tePassword.Text))
                    {
                        dcUser.ShowError(tePassword, "密码数字+字母+符号三种组合以上,至少8位数,最多16位数");
                        return;
                    }
                }
                else
                {
                    //密码复杂度验证
                    var regex = new Regex(@"
                        (?=.*[0-9])                     #必须包含数字
                        (?=.*[a-zA-Z])                  #必须包含小写或大写字母
                        (?=([\x21-\x7e]+)[^a-zA-Z0-9])  #必须包含特殊符号
                        .{6,16}                         #至少6个字符,最多16个字符
                        ", RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
                    if (!regex.IsMatch(tePassword.Text))
                    {
                        dcUser.ShowError(tePassword, "密码数字+字母+符号三种组合以上,至少6位数,最多16位数");
                        return;
                    }
                }
            }
            if (user.id == null)
            {
                if (!tePassword.Text.Equals(tePassword2.Text))
                {
                    dcUser.ShowError(tePassword2, "密码不一致");
                    return;
                }
            }
            else
            {
                if (tePassword2.Text.Length > 0)
                {
                    if (!tePassword.Text.Equals(tePassword2.Text))
                    {
                        dcUser.ShowError(tePassword2, "密码不一致");
                        return;
                    }
                }
            }

            dcUser.GetValue(user);
            if (user.id != null && tePassword.Text.Length == 0)
            {
                user.password = password;
            }
            //编辑框的内容要进行转码,不然后台获取的数据会异常缺失数据
            user.remarks = HttpUtility.UrlEncode(richEditor1.InnerHtml, Encoding.UTF8);
            user.imgPath = serviceFilePath;

            //获取选中的角色
            this.listCheckedRoleID.Clear();
            if (treeListRole.Nodes.Count > 0)
            {
                foreach (TreeListNode root in treeListRole.Nodes)
                {
                    if (root.CheckState == CheckState.Checked || root.CheckState == CheckState.Indeterminate)
                    {
                        RoleEntity role = treeListRole.GetDataRecordByNode(root) as RoleEntity;
                        if (role != null)
                        {
                            listCheckedRoleID.Add(role.id);
                        }
                    }
                    GetCheckedID(treeListRole, root, listCheckedRoleID);
                }
            }

            string RoleIdStr = string.Empty;

            foreach (String id in listCheckedRoleID)
            {
                RoleIdStr += id + ",";
            }
            if (RoleIdStr.Length != 0)
            {
                RoleIdStr = RoleIdStr.Substring(0, RoleIdStr.Length - 1);
            }
            else
            {
                dcUser.ShowError(treeListRole, "用户角色至少选一个"); return;
            }
            user.roleIds = RoleIdStr;



            //获取选中的菜单权限
            this.lstCheckedDeptID.Clear();
            if (treeList1.Nodes.Count > 0)
            {
                foreach (TreeListNode root in treeList1.Nodes)
                {
                    if (root.CheckState == CheckState.Checked)// || root.CheckState == CheckState.Indeterminate)
                    {
                        DeptEntity dept = treeList1.GetDataRecordByNode(root) as DeptEntity;
                        if (dept != null)
                        {
                            lstCheckedDeptID.Add(dept.id);
                        }
                    }
                    GetCheckedID(treeList1, root, lstCheckedDeptID);
                }
            }

            string idStr = string.Empty;

            foreach (String id in lstCheckedDeptID)
            {
                idStr += id + ",";
            }
            if (idStr.Length != 0)
            {
                idStr = idStr.Substring(0, idStr.Length - 1);
            }
            user.deptIds = idStr;

            String param = PackReflectionEntity <UserEntity> .GetEntityToRequestParameters(user, true);

            if (oldLoginName != null)
            {
                param = param + "&&oldLoginName=" + oldLoginName;
            }
            String url = AppContext.AppConfig.serverUrl + "sys/sysUser/save?";

            cmd.ShowOpaqueLayer(255, true);
            this.DoWorkAsync(0, (o) => //耗时逻辑处理(此处不能操作UI控件,因为是在异步中)
            {
                String data = HttpClass.httpPost(url, param);
                return(data);
            }, null, (data) => //显示结果(此处用于对上面结果的处理,比如显示到界面上)
            {
                cmd.HideOpaqueLayer();
                JObject objT = JObject.Parse(data.ToString());
                if (string.Compare(objT["state"].ToString(), "true", true) == 0)
                {
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    MessageBoxUtils.Show(objT["message"].ToString(), MessageBoxButtons.OK,
                                         MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, this);
                }
            });
        }