-
Notifications
You must be signed in to change notification settings - Fork 3
/
creatnewuserdialog.cpp
59 lines (49 loc) · 1.4 KB
/
creatnewuserdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "creatnewuserdialog.h"
#include "ui_creatnewuserdialog.h"
#include "myglobal.h"
#include "QMessageBox"
CreatNewUserDialog::CreatNewUserDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::CreatNewUserDialog)
{
ui->setupUi(this);
ui->userNamelineEdit->setFocus();
}
CreatNewUserDialog::~CreatNewUserDialog()
{
delete ui;
}
void CreatNewUserDialog::on_YesButton_clicked()
{
QString userName = ui->userNamelineEdit->text();
QString password = ui->passwordlineEdit->text();
QString verifyPsw = ui->surePasswordlineEdit->text();
if (userName.isEmpty())
{
QMessageBox::warning(this, tr("错误"), tr("用户名不能为空."), QMessageBox::Ok);
ui->userNamelineEdit->setFocus();
return;
}
if (password != verifyPsw)
{
QMessageBox::warning(this, tr("错误"), tr("两次输入密码不一致."), QMessageBox::Ok);
ui->passwordlineEdit->setFocus();
return;
}
if (Global::UserMag->exists(userName))
{
QMessageBox::warning(this, tr("错误"), tr("该用户已存在."), QMessageBox::Ok);
ui->userNamelineEdit->setFocus();
ui->userNamelineEdit->selectAll();
return;
}
QMap<QString, QVariant> userinfo;
userinfo["userName"] = userName;
userinfo["password"] = verifyPsw;
Global::UserMag->addUser(userinfo);
accept();
}
void CreatNewUserDialog::on_NoButton_clicked()
{
reject();
}