コード例 #1
0
        private void btnDelUser_Click(object sender, EventArgs e)
        {
            if (this.treeUser.SelectedNode == null)
            {
                MessageBox.Show(this, "请选中要删除的用户!!!", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            //获取要删除的用户
            UserClass user = (UserClass)this.treeUser.SelectedNode.Tag;

            //询问用户确认删除操作
            if (MessageBox.Show(this, "真的要删除用户:" + user.Name + "?", "提示",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }
            //删除用户
            if (UserSql.DeleteUser(user.Name))
            {
                MessageBox.Show(this, "删除成功!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //删除成功,刷新用户列表
                this.LoadUserList();
            }
            else
            {
                MessageBox.Show(this, "删除失败!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
コード例 #2
0
        private void ModifyPasswardForm_Load(object sender, EventArgs e)
        {
            List <UserClass> userLst = UserSql.LoadUserList();

            foreach (UserClass user in userLst)
            {
                this.cmbUser.Items.Add(user);
            }
        }
コード例 #3
0
 private void LoadUserList( )
 {
     //从数据库加载所有可用的用户
     this.UserList = UserSql.LoadUserList();
     this.cmbUser.Items.Clear();
     if (this.UserList != null)
     {
         foreach (UserClass user in this.UserList)
         {
             this.cmbUser.Items.Add(user);
         }
         //默认选中第一个用户
         if (this.cmbUser.Items.Count > 0)
         {
             this.cmbUser.SelectedIndex = 0;
         }
     }
 }
コード例 #4
0
        private void LoadUserList()
        {
            //清空原有数据显示
            this.treeUser.Nodes.Clear();
            //加载用户列表
            List <UserClass> userList = UserSql.LoadUserList();

            if (userList != null)
            {
                //依次显示所有的用户信息
                foreach (UserClass user in userList)
                {
                    TreeNode node = new TreeNode();
                    node.Text = user.Name;
                    node.Tag  = user;
                    this.treeUser.Nodes.Add(node);
                }
            }
        }
コード例 #5
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //进行姓名合法性检查
            string name = this.tbName.Text.Trim( );

            if (string.IsNullOrEmpty(name))
            {
                MessageBox.Show("请输入姓名!", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            //进行密码合法性检查
            if (this.tbPwd.Text.Trim() != this.tbPwd2.Text.Trim())
            {
                MessageBox.Show("两次密码不一致,请再次确认新密码!", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                //清空现有密码,并将光标移动到密码输入框
                this.tbPwd.Clear();
                this.tbPwd2.Clear();
                this.tbPwd.Focus();
                return;
            }
            string     pwd   = tbPwd.Text.Trim();
            UserRights right = (UserRights)this.cmbRight.SelectedIndex;
            //创建用户对象
            UserClass user = new UserClass(name, pwd, right);

            //添加用户到数据库
            if (UserSql.Adduser(user))
            {
                MessageBox.Show("添加用户:" + name + ",成功", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                //添加成功,关闭对话框
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show("添加用户:" + name + ",失败", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #6
0
        private void btnCPwd_Click(object sender, EventArgs e)
        {
            //获取当前选中用户
            UserClass user = (UserClass)this.cmbUser.SelectedItem;

            //检查旧密码的输入合法性
            if (this.tbPwd.Text.Trim() != user.Password)
            {
                MessageBox.Show("请输入正确的原密码!", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                //清空原密码输入框,并获取焦点
                this.tbPwd.Clear();
                this.tbPwd.Focus();
                return;
            }
            //检查新密码的合法性
            if (this.tbNewPwd1.Text.Trim() != this.tbNewPwd2.Text.Trim())
            {
                MessageBox.Show("两次新密码不一致,请再次确认新密码!", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                //清空现有密码,并将光标移动到密码输入框
                this.tbNewPwd1.Clear();
                this.tbNewPwd2.Clear();
                this.tbNewPwd1.Focus();
                return;
            }
            user.Password = tbNewPwd1.Text;
            if (UserSql.ModifyUser(user))
            {
                MessageBox.Show("修改用户信息:" + user.ToString() + ",成功", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("修改用户信息:" + user.ToString() + ",失败", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                user.Password = tbPwd.Text.Trim();
            }
        }