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

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

View File

@ -18,6 +18,7 @@ SOURCES += \
newCardPage.cpp \
quitAppPage.cpp \
readerAPI.cpp \
reportLossPage.cpp \
settingPage.cpp
HEADERS += \

View File

@ -4,6 +4,7 @@
#include "settingPage.cpp"
#include "quitAppPage.cpp"
#include "newCardPage.cpp"
#include "reportLossPage.cpp"
MainWindow::MainWindow(QWidget *parent)
@ -41,8 +42,11 @@ MainWindow::MainWindow(QWidget *parent)
// 清空部分输入框
ui->userIdBox->clear();
userIdFilled = false;
connect(ui->userIdBox, &QSpinBox::valueChanged, [this]{ userIdFilled = true; });
newCardUserIdFilled = false;
connect(ui->userIdBox, &QSpinBox::valueChanged, [this]{ newCardUserIdFilled = true; });
ui->reportLossUserIdBox->clear();
reportLossUserIdFilled = false;
connect(ui->reportLossUserIdBox, &QSpinBox::valueChanged, [this]{ reportLossUserIdFilled = true; });
// 设置启动页面
@ -54,3 +58,4 @@ MainWindow::~MainWindow()
{
delete ui;
}

View File

@ -28,7 +28,8 @@ public:
~MainWindow();
void updateStatusBarComNumber();
bool ready();
bool allReady();
bool softwareReady();
bool bindUserWithCard(int userId, QString cardId, QString &info);
bool getNewUserInfo(QString &username, QString &password, QString &info);
bool createUser(int userId, QString &info);
@ -40,12 +41,14 @@ private slots:
void on_settingAction_triggered();
void on_quitAppAction_triggered();
void on_NewCardAction_triggered();
void on_reportLossAction_triggered();
void on_connectReaderButton_clicked();
void on_confirmQuitButton_clicked();
void on_connectDatabaseButton_clicked();
void on_inventoryButton_clicked();
void on_newCardButton_clicked();
void on_reportLossButton_clicked();
private:
Ui::MainWindow *ui;
@ -62,6 +65,7 @@ private:
QLabel *databaseLabel;
QLabel *deviceLabel;
bool userIdFilled; ///< 初始时学/工号填写框被清空该变量为false当用户填写后该变量为true
bool newCardUserIdFilled; ///< 开卡时:初始时学/工号填写框被清空该变量为false当用户填写后该变量为true
bool reportLossUserIdFilled; ///< 挂失时:初始时学/工号填写框被清空该变量为false当用户填写后该变量为true
};
#endif // MAINWINDOW_H

View File

@ -27,7 +27,7 @@
<bool>true</bool>
</property>
<property name="currentIndex">
<number>2</number>
<number>3</number>
</property>
<widget class="QWidget" name="quitAppPage">
<widget class="QPushButton" name="confirmQuitButton">
@ -354,6 +354,53 @@
</property>
</widget>
</widget>
<widget class="QWidget" name="reportLossPage">
<widget class="QWidget" name="horizontalLayoutWidget">
<property name="geometry">
<rect>
<x>230</x>
<y>150</y>
<width>281</width>
<height>80</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>请输入学/工号:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="reportLossUserIdBox">
<property name="minimum">
<number>1000</number>
</property>
<property name="maximum">
<number>99999999</number>
</property>
<property name="value">
<number>21281280</number>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QPushButton" name="reportLossButton">
<property name="geometry">
<rect>
<x>330</x>
<y>250</y>
<width>80</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>挂失</string>
</property>
</widget>
</widget>
</widget>
</widget>
<widget class="QStatusBar" name="statusBar">

View File

@ -4,9 +4,7 @@
/**
* @brief
*
* -
* -
*
* @param void
* @return void
* @author
@ -14,23 +12,15 @@
*/
void MainWindow::on_NewCardAction_triggered()
{
if (!ready())
{
QMessageBox::warning(this, QString("提示"), QString("读卡器或数据库未连接,请设置。"));
if (ui->stackedWidget->currentWidget() != ui->settingPage)
{
ui->stackedWidget->setCurrentWidget(ui->settingPage);
}
return;
}
ui->stackedWidget->setCurrentWidget(ui->newCardPage);
}
/**
* @brief
* Inventory的查询结果10
*
*
* Inventory的查询结果10
* @param void
* @return void
* @author
@ -38,6 +28,16 @@ void MainWindow::on_NewCardAction_triggered()
*/
void MainWindow::on_inventoryButton_clicked()
{
if (!reader.is_connected())
{
QMessageBox::warning(this, QString("提示"), QString("读卡器未连接,请设置。"));
if (ui->stackedWidget->currentWidget() != ui->settingPage)
{
ui->stackedWidget->setCurrentWidget(ui->settingPage);
}
return;
}
QStringList cardIdList = reader.inventory(10); // 最多显示10张卡
ui->cardIdBox->clear();
if (cardIdList.empty())
@ -54,10 +54,12 @@ void MainWindow::on_inventoryButton_clicked()
/**
* @brief
*
*
* ID
*
* @details
*
* ID和填写的用户ID
* ID退
*
@ -73,13 +75,23 @@ void MainWindow::on_inventoryButton_clicked()
*/
void MainWindow::on_newCardButton_clicked()
{
if (!softwareReady())
{
QMessageBox::warning(this, QString("提示"), QString("数据库未连接,请设置。"));
if (ui->stackedWidget->currentWidget() != ui->settingPage)
{
ui->stackedWidget->setCurrentWidget(ui->settingPage);
}
return;
}
if (ui->cardIdBox->currentIndex() == -1)
{
QMessageBox::warning(this, "提示", "请放置卡片并点击查询按钮。");
return;
}
if (!userIdFilled)
if (!newCardUserIdFilled)
{
QMessageBox::warning(this, "提示", "请填写学/工号。");
return;

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;
}

View File

@ -113,10 +113,27 @@ void MainWindow::on_connectDatabaseButton_clicked()
* @author
* @date 2024-07-27
*/
bool MainWindow::ready()
bool MainWindow::allReady()
{
if (!reader.is_connected()) return false;
if (db == nullptr || !db->is_connected()) return false;
if (!device.is_verified()) return false;
return true;
}
/**
* @brief
* @param void
* @return
* - true
* - false
* @author
* @date 2024-07-30
*/
bool MainWindow::softwareReady()
{
if (db == nullptr || !db->is_connected()) return false;
if (!device.is_verified()) return false;
return true;
}