Beispiel #1
0
        private void confirmB_Click(object sender, EventArgs e)
        {
            if (nameT.TextLength == 0 || passwordT.TextLength == 0)
            {
                MessageBox.Show("请填完所有表单");
                return;
            }

            string name     = nameT.Text;
            string password = passwordT.Text;

            User.Privilege role;
            switch ((string)roleC.SelectedItem)
            {
            case "admin": role = User.Privilege.admin; break;

            case "user": role = User.Privilege.user; break;

            default: role = User.Privilege.user; break;
            }

            if (daoManager.getUserDao().UserExisted(name))
            {
                MessageBox.Show("用戶已存在!!!");
                return;
            }

            User user = new User(name, password, role);

            daoManager.getUserDao().add(user);
            this.DialogResult = DialogResult.OK;
        }
        public void fill()
        {
            List <User>  users = daoManager.getUserDao().getAll();
            ListViewItem it;

            foreach (User u in users)
            {
                it      = new ListViewItem();
                it.Text = u.Id.ToString();
                it.SubItems.Add(u.Name);
                it.SubItems.Add(u.Role.ToString());
                this.userList.Items.Add(it);
            }

            this.userList.EndUpdate();
        }
        private void confirmB_Click(object sender, EventArgs e)
        {
            if (nameT.TextLength == 0 || passwordT.TextLength == 0)
            {
                MessageBox.Show("请填完所有表单");
                return;
            }

            string name     = nameT.Text;
            string password = passwordT.Text;

            try
            {
                User check = daoManager.getUserDao().getByName(name);
                if (!check.Password.Equals(password))
                {
                    MessageBox.Show("密码错误");
                    return;
                }
                else
                {
                    User = check;
                    this.DialogResult = DialogResult.OK;
                }
            }catch (UserNotFoundException)
            {
                MessageBox.Show("用户不存在啊!!!!");
            }
        }