Exemplo n.º 1
0
        private void LogForm_Load(object sender, EventArgs e)
        {
            List <DeptEntity> deptLsit = AppContext.Session.deptList;

            menuTest1.KeyFieldName    = "id";
            menuTest1.ParentFieldName = "parentId";
            menuTest1.DisplayMember   = "name";
            menuTest1.ValueMember     = "id";
            menuTest1.DataSource      = deptLsit;
            menuTest1.EditValue       = "23";
            DeptEntity dept = menuTest1.selectItem as DeptEntity;
        }
Exemplo n.º 2
0
 /// <summary>
 /// 设置菜单CheckBox选中
 /// </summary>
 /// <param name="key"></param>
 /// <param name="node"></param>
 private void SetMenuNodeChecked(DevExpress.XtraTreeList.TreeList treeList, String key, TreeListNodes node)
 {
     foreach (TreeListNode childeNode in node)
     {
         DeptEntity data = treeList.GetDataRecordByNode(childeNode) as DeptEntity;
         if (data.id == key)
         {
             childeNode.Checked = true;
         }
         if (childeNode.HasChildren)
         {
             SetMenuNodeChecked(treeList, key, childeNode.Nodes);
         }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// 获取选择状态的数据主键ID集合
        /// </summary>
        /// <param name="parentNode">父级节点</param>
        private void GetCheckedID(DevExpress.XtraTreeList.TreeList treeList, TreeListNode parentNode, List <String> strList)
        {
            if (parentNode.Nodes.Count == 0)
            {
                return;//递归终止
            }

            foreach (TreeListNode node in parentNode.Nodes)
            {
                if (node.CheckState == CheckState.Checked || node.CheckState == CheckState.Indeterminate)
                {
                    DeptEntity menu = treeList.GetDataRecordByNode(node) as DeptEntity;
                    if (menu != null)
                    {
                        strList.Add(menu.id);
                    }
                }
                GetCheckedID(treeList, node, strList);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// 获取选择状态的数据主键ID集合
 /// </summary>
 /// <param name="parentNode">父级节点</param>
 private void GetCheckedKeyID(TreeListNode parentNode)
 {
     if (parentNode.CheckState != CheckState.Unchecked)
     {
         DeptEntity dept = treeDept.Properties.TreeList.GetDataRecordByNode(parentNode) as DeptEntity;
         if (dept != null)
         {
             int    KeyFieldName  = int.Parse(dept.id);
             string DisplayMember = dept.name;
             if (!lstCheckedKeyID.Contains(KeyFieldName))
             {
                 lstCheckedKeyID.Add(KeyFieldName);
             }
             if (!lstCheckedKeyName.Contains(DisplayMember))
             {
                 lstCheckedKeyName.Add(DisplayMember);
             }
         }
     }
     if (parentNode.Nodes.Count == 0)
     {
         return;//递归终止
     }
     foreach (TreeListNode node in parentNode.Nodes)
     {
         if (node.CheckState != CheckState.Unchecked)
         {
             DeptEntity dept = treeDept.Properties.TreeList.GetDataRecordByNode(node) as DeptEntity;
             if (dept != null)
             {
                 int    KeyFieldName  = int.Parse(dept.id);
                 string DisplayMember = dept.name;
                 lstCheckedKeyID.Add(KeyFieldName);
                 lstCheckedKeyName.Add(DisplayMember);
             }
         }
         GetCheckedKeyID(node);
     }
 }
Exemplo n.º 5
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);
                }
            });
        }