添加挂失页面;修改了判断数据库、设备、设备名是否设置好的函数名

This commit is contained in:
2024-07-30 14:25:45 +08:00
parent ad40ab7ecd
commit 9b227f3a14
7 changed files with 189 additions and 21 deletions

82
reportLossPage.cpp Normal file
View File

@@ -0,0 +1,82 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
/**
* @brief 切换到挂失页面
* 点击工具栏的“挂失”触发
* @param void
* @return void
* @author 柯劲帆
* @date 2024-07-28
*/
void MainWindow::on_reportLossAction_triggered()
{
ui->stackedWidget->setCurrentWidget(ui->reportLossPage);
}
/**
* @brief 挂失卡
* 该函数用于将指定用户的卡片设置为挂失状态。当用户点击“挂失”按钮时触发。
* @details
* 函数首先检查数据库连接状态,如果数据库未连接,显示警告信息并跳转到设置页面。
* 然后检查是否填写了用户的学/工号。如果未填写,显示警告信息并返回。
* 然后,函数在数据库中查询该学/工号是否存在。如果不存在,显示警告信息并返回。
* 如果学/工号存在,函数将该用户的卡片状态设置为挂失(`status` = -1并在操作成功后显示挂失成功的信息。
* @param void
* @return void
* @author 柯劲帆
* @date 2024-07-30
*/
void MainWindow::on_reportLossButton_clicked()
{
if (!softwareReady())
{
QMessageBox::warning(this, QString("提示"), QString("数据库未连接,请设置。"));
if (ui->stackedWidget->currentWidget() != ui->settingPage)
{
ui->stackedWidget->setCurrentWidget(ui->settingPage);
}
return;
}
if (!reportLossUserIdFilled)
{
QMessageBox::warning(this, "提示", "请填写学/工号。");
return;
}
int userId = ui->reportLossUserIdBox->value();
// 查询学/工号是否存在
QSqlQuery query(db->getDatabase());
query.prepare(QString("select id from card "
"where userId = :userId;"));
query.bindValue(":userId", userId);
bool success = query.exec();
if (!success)
{
QMessageBox::warning(this, "提示", "数据库异常,挂失失败。");
return;
}
if (!query.next())
{
QMessageBox::warning(this, "提示", "学/工号不存在,挂失失败。");
return;
}
// 将该学/工号的卡设置为挂失状态
query.prepare(QString("update card "
"set `status` = -1 "
"where userId = :userId;"));
query.bindValue(":userId", userId);
success = query.exec();
if (!success)
{
QMessageBox::warning(this, "提示", "数据库异常,挂失失败。");
return;
}
QMessageBox::information(this, "提示", "挂失成功。");
return;
}