diff --git a/CardManageSystem.pro b/CardManageSystem.pro
index 36f2e7b..ae4ea9c 100644
--- a/CardManageSystem.pro
+++ b/CardManageSystem.pro
@@ -18,6 +18,7 @@ SOURCES += \
newCardPage.cpp \
quitAppPage.cpp \
readerAPI.cpp \
+ reportLossPage.cpp \
settingPage.cpp
HEADERS += \
diff --git a/mainwindow.cpp b/mainwindow.cpp
index c4aac12..2f8461f 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -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;
}
+
diff --git a/mainwindow.h b/mainwindow.h
index 48fa7b2..05094c8 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -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
diff --git a/mainwindow.ui b/mainwindow.ui
index 2954fe4..7ef65f4 100644
--- a/mainwindow.ui
+++ b/mainwindow.ui
@@ -27,7 +27,7 @@
true
- 2
+ 3
@@ -354,6 +354,53 @@
+
+
+
+
+ 230
+ 150
+ 281
+ 80
+
+
+
+ -
+
+
+ 请输入学/工号:
+
+
+
+ -
+
+
+ 1000
+
+
+ 99999999
+
+
+ 21281280
+
+
+
+
+
+
+
+
+ 330
+ 250
+ 80
+ 23
+
+
+
+ 挂失
+
+
+
diff --git a/newCardPage.cpp b/newCardPage.cpp
index 25ff740..c839036 100644
--- a/newCardPage.cpp
+++ b/newCardPage.cpp
@@ -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;
diff --git a/reportLossPage.cpp b/reportLossPage.cpp
new file mode 100644
index 0000000..ddee988
--- /dev/null
+++ b/reportLossPage.cpp
@@ -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;
+}
diff --git a/settingPage.cpp b/settingPage.cpp
index 97adce8..7a83dad 100644
--- a/settingPage.cpp
+++ b/settingPage.cpp
@@ -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;
+}