-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathchangeinfo.cpp
More file actions
162 lines (142 loc) · 4.57 KB
/
changeinfo.cpp
File metadata and controls
162 lines (142 loc) · 4.57 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include "changeinfo.h"
#include "ui_changeinfo.h"
#include<QLabel>
#include<QLineEdit>
#include<QSqlQuery>
#include<QMessageBox>
ChangeInfo::ChangeInfo(MainWindow*mainWin,QWidget *parent) :
QWidget(parent),
ui(new Ui::ChangeInfo)
{
ui->setupUi(this);
this->mainWin = mainWin;
info = mainWin->getUsrInfo();
ui->IdLabel->setText(QString::number(info->getId()));
ui->nickLineEdit->setText(info->getNick());
ui->mottoLineEdit->setText(info->getMotto());
}
ChangeInfo::~ChangeInfo()
{
delete ui;
}
void ChangeInfo::on_characterInfoCancelButton_clicked()
{
this->hide();
}
void ChangeInfo::on_passwordApplyButton_clicked()
{
qDebug()<<"on_passwordApplyButton_clicked"<<endl;
const QString&oldPassword = ui->oldPasswordLineEdit->text();
const QString&newPassword = ui->newPasswordLineEdit->text();
const QString&repeatPassword = ui->repeatPasswordLineEdit->text();
if(oldPassword.isEmpty()||newPassword.isEmpty()||repeatPassword.isEmpty()){
QMessageBox::warning(this,"警告","密码不能为空!",QMessageBox::Ok);
return;
}
if(newPassword!=repeatPassword){
QMessageBox::warning(this,"警告","两次输入的密码不相同!",QMessageBox::Ok);
return;
}
QSqlQuery query;
query.prepare("select * from Account where id=? and password=?;");
query.addBindValue(info->getId());
query.addBindValue(oldPassword);
query.exec();
if(query.next()){//密码正确
query.prepare("update Account set password=? where id=?;");
query.addBindValue(newPassword);
query.addBindValue(info->getId());
if(!query.exec()){
QMessageBox::warning(this,"警告","数据更新失败",QMessageBox::Ok);
return;
}
qDebug()<<"info update success"<<endl;
this->ui->passwordApplyButton->setEnabled(false);
}
else{
QMessageBox::warning(this,"警告","密码错误!",QMessageBox::Ok);
return;
}
}
void ChangeInfo::on_characterApplyButton_clicked()
{
qDebug()<<"clicked characterApplyButton"<<endl;
const QString&nick = ui->nickLineEdit->text();
QString motto = ui->mottoLineEdit->text();
if(nick.isEmpty()){
QMessageBox::warning(this,tr("警告"),tr("昵称不能为空!"),QMessageBox::Ok);
return;
}
if(motto.isEmpty()){
ui->mottoLineEdit->setText(tr("该用户很懒,什么都没有留下~"));
motto = tr("该用户很懒,什么都没有留下~");
}
if(info->getNick()!=nick||info->getMotto()!=motto){
QSqlQuery query;
query.prepare("update Account set nick=?,motto=? where id=?;");
query.addBindValue(nick);
query.addBindValue(motto);
query.addBindValue(info->getId());
bool check = query.exec();
//bool check = query.exec("update Account set nick='lrc',motto='mychat是宇宙上最好的聊天工具' where id=10000;");
if(!check){
QMessageBox::warning(this,tr("警告"),tr("数据更新失败!"),QMessageBox::Ok);
return;
}
qDebug()<<"info update success"<<endl;
info->updateInfo();
ui->characterApplyButton->setEnabled(false);
}
}
void ChangeInfo::on_characterInfoOkButton_clicked()
{
if(ui->characterApplyButton->isEnabled()){
on_characterApplyButton_clicked();
}
this->hide();
}
void ChangeInfo::on_passwordInfoOkButton_clicked()
{
if(ui->passwordApplyButton->isEnabled()){
on_passwordApplyButton_clicked();
}
this->hide();
}
void ChangeInfo::on_passwordInfoCancelButton_clicked()
{
this->hide();
}
void ChangeInfo::setPasswordApplyButtonEnabled(){
if(ui->oldPasswordLineEdit->text().isEmpty()||
ui->newPasswordLineEdit->text().isEmpty()||
ui->repeatPasswordLineEdit->text().isEmpty()){
return;
}
ui->passwordApplyButton->setEnabled(true);
}
void ChangeInfo::setcharacterApplyButtonEnabled(){
if(ui->nickLineEdit->text().isEmpty()){
return;
}
ui->characterApplyButton->setEnabled(true);
}
void ChangeInfo::on_oldPasswordLineEdit_textChanged(const QString &arg1)
{
setPasswordApplyButtonEnabled();
}
void ChangeInfo::on_newPasswordLineEdit_textChanged(const QString &arg1)
{
setPasswordApplyButtonEnabled();
}
void ChangeInfo::on_repeatPasswordLineEdit_textChanged(const QString &arg1)
{
setPasswordApplyButtonEnabled();
}
void ChangeInfo::on_nickLineEdit_textChanged(const QString &arg1)
{
setcharacterApplyButtonEnabled();
}
void ChangeInfo::on_mottoLineEdit_textChanged(const QString &arg1)
{
setcharacterApplyButtonEnabled();
}