Beispiel #1
0
        private void NewUser()
        {
            TreeNode  Node      = OrganizationView.SelectedNode;
            Selection selection = Node.Tag as Selection;
            Boolean   IsNode    = System.Convert.ToBoolean(selection.Value);

            if (IsNode)
            {
                UserDialog userForm = new UserDialog();
                userForm.Text = "新建用户";
                if (DialogResult.OK == userForm.ShowDialog(this))
                {
                    User user = new User();
                    user.Index    = Guid.NewGuid().ToString();
                    user.Code     = DepositoryUser.GetNextCode(Node.Name);
                    user.Name     = userForm.TextBox_Name.Text;
                    user.Password = EncryptSerivce.Encrypt(userForm.TextBox_Password1.Text);
                    user.IsSys    = false;

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

                    bool r = DepositoryUser.New(user);
                    if (r)
                    {
                        TreeNode uNode = new TreeNode();
                        uNode.Text               = user.Name;
                        uNode.Name               = user.Code;
                        uNode.ImageIndex         = 2;
                        uNode.SelectedImageIndex = 2;
                        selection       = new Selection();
                        selection.ID    = user.Index;
                        selection.Value = false.ToString();
                        uNode.Tag       = selection;
                        Node.Nodes.Add(uNode);

                        Node.Expand();
                        OrganizationView.SelectedNode = uNode;
                    }

                    string Msg = r ? "新建用户成功。" : "新建用户失败。";
                    MessageBox.Show(Msg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
Beispiel #2
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);
                }
            }
        }