Beispiel #1
0
        private void InitUsers()
        {
            UsersView.Nodes.Clear();

            List <User> Users = DepositoryUser.Init();

            foreach (User user in Users)
            {
                TreeNode Node = new TreeNode();
                Node.Name = user.Index;
                Node.Text = user.Name;
                Node.Tag  = user;

                UsersView.Nodes.Add(Node);
            }

            if (UsersView.Nodes.Count > 0)
            {
                //为了解决最后一个根节点不显示的问题,加几行代码
                UsersView.Nodes[UsersView.Nodes.Count - 1].Nodes.Add("");
                UsersView.Nodes[UsersView.Nodes.Count - 1].Expand();
                UsersView.Nodes[UsersView.Nodes.Count - 1].Nodes.Clear();

                UsersView.SelectedNode = UsersView.Nodes[0];
            }
        }
Beispiel #2
0
        private void ShowUserInformation(Role role)
        {
            if (role == null)
            {
                return;
            }

            List <User> Users = DepositoryUser.Init(new string[] { role.Index });

            foreach (TreeNode Node in UsersView.Nodes)
            {
                User user = Node.Tag as User;
                Node.Checked = (Users.IndexOf(user) != -1);
            }
        }
Beispiel #3
0
        private void EditUser()
        {
            TreeNode  Node      = OrganizationView.SelectedNode;
            Selection selection = Node.Tag as Selection;
            Boolean   IsUser    = !System.Convert.ToBoolean(selection.Value);

            if (IsUser)
            {
                UserDialog userForm = new UserDialog();
                User       user     = DepositoryUser.Init(selection.ID);
                userForm.EditUser = user;
                userForm.Text     = "编辑用户";

                if (DialogResult.OK == userForm.ShowDialog(this))
                {
                    user.Name     = userForm.TextBox_Name.Text;
                    user.Password = EncryptSerivce.Encrypt(userForm.TextBox_Password1.Text);
                    user.IsSys    = false;

                    user.Roles.Clear();
                    foreach (DataGridViewRow row in userForm.RolesView.Rows)
                    {
                        Role role = row.Tag as Role;
                        if (role != null)
                        {
                            user.Roles.Add(role);
                        }
                    }

                    bool r = DepositoryUser.Update(user);
                    if (r)
                    {
                        Node.Text = userForm.TextBox_Name.Text;
                    }

                    string Msg = r ? "更新用户成功。" : "更新用户失败。";
                    MessageBox.Show(Msg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }