Commit 44eff581 authored by Qiu Chuntao's avatar Qiu Chuntao

Optimize the code

parent 47efbeaf
This diff is collapsed.
...@@ -34,6 +34,8 @@ void Regist::on_pushButton_clicked() ...@@ -34,6 +34,8 @@ void Regist::on_pushButton_clicked()
return; return;
} }
QMessageBox::about(this,"提示","注册成功"); QMessageBox::about(this,"提示","注册成功");
this->parentWidget()->show();
this->hide();
} }
void Regist::on_goback_clicked() void Regist::on_goback_clicked()
......
...@@ -46,8 +46,12 @@ void UserWindow::on_find_usr_clicked() ...@@ -46,8 +46,12 @@ void UserWindow::on_find_usr_clicked()
bool ok; bool ok;
QString text = QInputDialog::getText(this, tr("查询"), QString text = QInputDialog::getText(this, tr("查询"),
tr("查找用户"), QLineEdit::Normal, tr("查找用户"), QLineEdit::Normal,
tr("请输入用户名"), &ok); tr(""), &ok);
if (ok) { if (ok) {
if (text.isEmpty()) {
QMessageBox::warning(this, "提示", "请输入需要查找的用户!", QMessageBox::Ok);
return;
}
QString str = QString("SELECT * FROM user WHERE username = '%1'").arg(text); QString str = QString("SELECT * FROM user WHERE username = '%1'").arg(text);
QSqlQuery query(QSqlDatabase::database("HB")); QSqlQuery query(QSqlDatabase::database("HB"));
if (!query.exec(str)) { if (!query.exec(str)) {
...@@ -81,8 +85,12 @@ void UserWindow::on_delet_usr_clicked() ...@@ -81,8 +85,12 @@ void UserWindow::on_delet_usr_clicked()
bool ok; bool ok;
QString text = QInputDialog::getText(this, tr("删除用户"), QString text = QInputDialog::getText(this, tr("删除用户"),
tr("查找用户"), QLineEdit::Normal, tr("查找用户"), QLineEdit::Normal,
tr("请输入用户名"), &ok); tr(""), &ok);
if (ok) { if (ok) {
if (text.isEmpty()) {
QMessageBox::warning(this,"提示","输入为空",QMessageBox::Ok);
return;
}
QString str = QString("DELETE FROM user WHERE username = '%1'").arg(text); QString str = QString("DELETE FROM user WHERE username = '%1'").arg(text);
QSqlQuery sql_query(db); QSqlQuery sql_query(db);
if (!sql_query.exec(str)) { if (!sql_query.exec(str)) {
...@@ -107,16 +115,23 @@ void UserWindow::on_updata_usr_clicked() ...@@ -107,16 +115,23 @@ void UserWindow::on_updata_usr_clicked()
bool ok; bool ok;
QString text = QInputDialog::getText(this, tr("修改用户信息"), QString text = QInputDialog::getText(this, tr("修改用户信息"),
tr("查找用户"), QLineEdit::Normal, tr("查找用户"), QLineEdit::Normal,
tr("请输入需要修改的用户"), &ok); tr(""), &ok);
if (ok) { if (ok) {
if (text.isEmpty()) {
QMessageBox::warning(this,"提示","输入为空",QMessageBox::Ok);
return;
}
int ret = QMessageBox::question(this, tr("修改选项"), int ret = QMessageBox::question(this, tr("修改选项"),
"修改用户名/密码?(Yes-用户名|No-密码)", "修改用户名/密码?(Yes-用户名|No-密码)",
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel); QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
if (ret == QMessageBox::Yes ) { if (ret == QMessageBox::Yes ) {
QString newname = QInputDialog::getText(this, tr("提示"), QString newname = QInputDialog::getText(this, tr("提示"),
tr("修改用户名!"), QLineEdit::Normal, tr("修改用户名!"), QLineEdit::Normal,
tr("请输入要修改的用户名"), &ok); tr(""), &ok);
if (newname.isEmpty()) {
QMessageBox::warning(this,"提示","输入为空",QMessageBox::Ok);
return;
}
QString str = QString("UPDATE user SET username = '%1' WHERE username = '%2'").arg(newname).arg(text); QString str = QString("UPDATE user SET username = '%1' WHERE username = '%2'").arg(newname).arg(text);
QSqlQuery sql_query(db); QSqlQuery sql_query(db);
if (!sql_query.exec(str)) { if (!sql_query.exec(str)) {
...@@ -130,7 +145,10 @@ void UserWindow::on_updata_usr_clicked() ...@@ -130,7 +145,10 @@ void UserWindow::on_updata_usr_clicked()
QString newpassword = QInputDialog::getText(this, tr("提示"), QString newpassword = QInputDialog::getText(this, tr("提示"),
tr("修改密码"), QLineEdit::Normal, tr("修改密码"), QLineEdit::Normal,
tr("请输入需要修改的密码"), &ok); tr("请输入需要修改的密码"), &ok);
if (newpassword.isEmpty()) {
QMessageBox::warning(this,"提示","输入为空",QMessageBox::Ok);
return;
}
QString str = QString("UPDATE user SET password = '%1' WHERE username = '%2'").arg(newpassword).arg(text); QString str = QString("UPDATE user SET password = '%1' WHERE username = '%2'").arg(newpassword).arg(text);
QSqlQuery sql_query(db); QSqlQuery sql_query(db);
if (!sql_query.exec(str)) { if (!sql_query.exec(str)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment