예제 #1
0
        private void Button_Ok_Click(object sender, EventArgs e)
        {
            //保存用户的信息
            List <User> users = new List <User>();

            foreach (TreeNode Node in UsersView.Nodes)
            {
                User user = Node.Tag as User;
                if (user != null)
                {
                    users.Add(user);
                }
            }

            if (users.Count > 0)
            {
                DepositoryUser.Update(users.ToArray());
            }
            Close();
        }
예제 #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);
                }
            }
        }