-
Notifications
You must be signed in to change notification settings - Fork 1
/
dialog.cpp
115 lines (108 loc) · 2.96 KB
/
dialog.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "dialog.h"
#include "ui_dialog.h"
#include"sql.h"
#include"domain.h"
#include<QMessageBox>
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
connect(this->ui->submit,SIGNAL(clicked(bool)),this,SLOT(submit()));
connect(this->ui->cancel,SIGNAL(clicked(bool)),this,SLOT(cancel()));
}
Dialog::~Dialog()
{
delete ui;
}
void setErrorMessageBox(QString text){
QMessageBox *message;
message=new QMessageBox(
"提示",
text,
QMessageBox::Critical,
QMessageBox::Ok|QMessageBox::Default,
0,
0
);
message->exec();
return ;
}
void setPassMessageBox(QString text){
QMessageBox *message;
message=new QMessageBox(
"提示",
text,
QMessageBox::Information,
QMessageBox::Ok|QMessageBox::Default,
0,
0
);
message->exec();
return;
}
//单击提交按钮
void Dialog::submit(){
QString name=this->ui->name->text();
QString id=this->ui->id->text();
QString password1=this->ui->password1->text();
QString password2=this->ui->password2->text();
QString sex=this->ui->select->currentText();
QString checkCode=this->ui->checkCode->text();
qDebug()<<sex;
if(id==""){
setErrorMessageBox("id不允许为空");
return ;
}
if(password1==""||password2==""){
setErrorMessageBox("密码不允许为空");
return ;
}
UserSql userSql;
Person user=userSql.findUserById(id);
if(user.getPersonId()==id){
setErrorMessageBox("该用户已存在");
return ;
}else{
if(password1!=password2){
setErrorMessageBox("两次输入的密码不一致");
return ;
}else{
if(checkCode==""){
//注册普通用户
Guests guests(
name,
id,
sex,
password1
);
user=guests;
userSql.insert(user);
setPassMessageBox("用户注册成功");
this->close();
return ;
}
if(checkCode=="1234"){
Charger charger(
name,
id,
sex,
password1
);
user=charger;
userSql.insert(user);
setPassMessageBox("管理员注册成功");
this->close();
return ;
}else{
setErrorMessageBox("校验码错误!");
return;
}
}
}
// setErrorMessageBox("注册失败");
//this->close();
}
void Dialog::cancel(){
this->close();
}