diff --git a/CasicBioRecWin.cpp b/CasicBioRecWin.cpp index 562f7ca..81d4615 100644 --- a/CasicBioRecWin.cpp +++ b/CasicBioRecWin.cpp @@ -9,8 +9,10 @@ { ui->setupUi(this); + // 程序启动时初始化缓存的数据 this->initCacheData(); + // 设置窗口透明和大小、位置 this->setWindowFlags(Qt::FramelessWindowHint); this->move(0, 0); this->resize(SettingConfig::getInstance().WINDOW_WIDTH, @@ -19,8 +21,10 @@ // 通过调色板的颜色来设置窗口的统一背景色 qApp->setPalette(QPalette(QColor(SettingConfig::getInstance().WINDOW_BACKGROUND_COLOR))); + // 初始化各个form界面并绑定切换响应函数 this->initFormsPtr(); + // 打印日志 LOG(INFO) << QString("应用程序启动成功[Application Startup Success]").toStdString(); } diff --git a/CasicBioRecWin.cpp b/CasicBioRecWin.cpp index 562f7ca..81d4615 100644 --- a/CasicBioRecWin.cpp +++ b/CasicBioRecWin.cpp @@ -9,8 +9,10 @@ { ui->setupUi(this); + // 程序启动时初始化缓存的数据 this->initCacheData(); + // 设置窗口透明和大小、位置 this->setWindowFlags(Qt::FramelessWindowHint); this->move(0, 0); this->resize(SettingConfig::getInstance().WINDOW_WIDTH, @@ -19,8 +21,10 @@ // 通过调色板的颜色来设置窗口的统一背景色 qApp->setPalette(QPalette(QColor(SettingConfig::getInstance().WINDOW_BACKGROUND_COLOR))); + // 初始化各个form界面并绑定切换响应函数 this->initFormsPtr(); + // 打印日志 LOG(INFO) << QString("应用程序启动成功[Application Startup Success]").toStdString(); } diff --git a/PersonListForm.cpp b/PersonListForm.cpp index 77fc565..e479626 100644 --- a/PersonListForm.cpp +++ b/PersonListForm.cpp @@ -21,26 +21,128 @@ ui->vsTableTop->changeSize(0, 20); ui->vsContentBottom->changeSize(0, 40); - itemModel = new QStandardItemModel(this); + // 初始化空的人员列表表格 + initPersonTableHeader(); + // 初始化部门下拉列表框 + SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); +} + +PersonListForm::~PersonListForm() +{ + delete ui; +} + +void PersonListForm::keyPressEvent(QKeyEvent * event) +{ + switch (event->key()) { + case Qt::Key_Return: // 小键盘的Enter键 + case Qt::Key_Enter: // Enter键 + currentPage = 0; + this->findPersonList(); + break; + + default: + QWidget::keyPressEvent(event); + } +} + +void PersonListForm::calcTotalPage(int totalCount) +{ + double temp = (totalCount * 1.0) / (tableRowCount * 1.0); + totalPage = ceil(temp); +} + +void PersonListForm::findPersonList() +{ + SysPersonDao personDao; + + // 获取查询条件 + QString name = ui->inputName->text(); + QString dept = ui->selectDept->currentData().toString(); + + // 计算分页查询的偏移量 + qint16 offset = currentPage * tableRowCount; + + // 查询总条数并计算总页数 + int totalCount = personDao.findRecordCountByNameAndDept(name, dept); + calcTotalPage(totalCount); + + // 赋值表格内容 + QVector perList = personDao.findRecordsByNameAndDept(name, dept, tableRowCount, offset); + + // 有数据且查询结果为空 则重新查询上一页 + if (totalCount > 0 && perList.isEmpty()) + { + // 触发查询上一页的操作 后续操作不再执行 + emit ui->btnPre->clicked(); + return ; + } + + this->personList->clear(); + for (int i = 0; i < perList.size(); i++) { + QVariantMap person = perList.at(i); + this->personList->append(person); + } + + // 更新显示表格 + this->updatePersonListTable(); + + // 更新页码 + if (totalCount == 0) + { + ui->labCurrPage->setText("0"); + } else + { + ui->labCurrPage->setText(QString("%1 / %2 , %3").arg(currentPage + 1).arg(totalPage).arg(totalCount)); + } +} + +void PersonListForm::initPersonTableHeader() +{ + itemModel = new QStandardItemModel(this); personList = new QList(); - SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); - + // 添加表头 QStringList header; header << "员工编号" << "姓名" << "部门 "<< "采集特征" << "操作"; itemModel->setHorizontalHeaderLabels(header); - for (int i = 0; i < tableRowCount; i++) { - QList row; - for ( int j = 0; j < tableColCount; j++) { - itemModel->setItem(i, j, new QStandardItem(QString(""))); - itemModel->item(i, j)->setTextAlignment(Qt::AlignCenter); - } - } + // 设置表头的宽度为固定值 不可调整 + ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); +} + +void PersonListForm::updatePersonListTable() +{ + // 清除表格原有数据 + itemModel->removeRows(0, itemModel->rowCount()); + ui->personListTable->setModel(itemModel); - ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); + // 判断是否有分页 + int max = tableRowCount > personList->size() ? personList->size() : tableRowCount; + for (int i = 0; i < max; i++) { + QList row; + itemModel->setItem(i, 0, new QStandardItem(personList->at(i).find("person_code")->toString())); + itemModel->item(i, 0)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 1, new QStandardItem(personList->at(i).find("name")->toString())); + itemModel->item(i, 1)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 2, new QStandardItem(personList->at(i).find("deptname")->toString())); + itemModel->item(i, 2)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 3, new QStandardItem(QString("iris face"))); + itemModel->item(i, 3)->setTextAlignment(Qt::AlignCenter); + + QPushButton * btnDele = new QPushButton("删除"); + btnDele->setProperty("personId", personList->at(i).find("id")->toString()); + btnDele->setProperty("class", "btnDelete"); + connect(btnDele, &QPushButton::clicked, + this, &PersonListForm::btnDeleClicked); + ui->personListTable->setIndexWidget(itemModel->index(i, 4), btnDele); + } + // 设置每行的高度 for ( int i = 0; i < tableRowCount; i++) { @@ -55,27 +157,6 @@ ui->personListTable->setColumnWidth(4, 150); } -PersonListForm::~PersonListForm() -{ - delete ui; -} - -void PersonListForm::findPersonList() -{ - SysPersonDao personDao; - QVector perList = personDao.findAllRecord(); - this->personList->clear(); - for (int i = 0; i < perList.size(); i++) { - QVariantMap person = perList.at(i); - this->personList->append(person); - } -} - -void PersonListForm::updatePersonListTable() -{ - -} - void PersonListForm::on_btnRegist_clicked() { emit switchToRegistForm("0"); @@ -90,3 +171,56 @@ { emit backToHomePage(); } + +void PersonListForm::on_selectDept_currentIndexChanged(int index) +{ + currentPage = 0; + this->findPersonList(); +} + +void PersonListForm::on_btnFirst_clicked() +{ + // 第一页 + currentPage = 0; + findPersonList(); +} + +void PersonListForm::on_btnLast_clicked() +{ + // 最后一页 + currentPage = totalPage - 1; + findPersonList(); +} + +void PersonListForm::on_btnPre_clicked() +{ + // 上一页 + if (currentPage > 0) + { + currentPage = currentPage - 1; + } + findPersonList(); +} + +void PersonListForm::on_btnNext_clicked() +{ + // 下一页 + if (currentPage < totalPage - 1) + { + currentPage++; + } + findPersonList(); +} + +void PersonListForm::btnDeleClicked() +{ + // 获取发送者的信息 + QPushButton * senderObj = (QPushButton *) sender(); + QString personId = senderObj->property("personId").toString(); + SysPersonDao personDao; + bool succ = personDao.dele(personId); + if (succ == 1) + { + findPersonList(); + } +} diff --git a/CasicBioRecWin.cpp b/CasicBioRecWin.cpp index 562f7ca..81d4615 100644 --- a/CasicBioRecWin.cpp +++ b/CasicBioRecWin.cpp @@ -9,8 +9,10 @@ { ui->setupUi(this); + // 程序启动时初始化缓存的数据 this->initCacheData(); + // 设置窗口透明和大小、位置 this->setWindowFlags(Qt::FramelessWindowHint); this->move(0, 0); this->resize(SettingConfig::getInstance().WINDOW_WIDTH, @@ -19,8 +21,10 @@ // 通过调色板的颜色来设置窗口的统一背景色 qApp->setPalette(QPalette(QColor(SettingConfig::getInstance().WINDOW_BACKGROUND_COLOR))); + // 初始化各个form界面并绑定切换响应函数 this->initFormsPtr(); + // 打印日志 LOG(INFO) << QString("应用程序启动成功[Application Startup Success]").toStdString(); } diff --git a/PersonListForm.cpp b/PersonListForm.cpp index 77fc565..e479626 100644 --- a/PersonListForm.cpp +++ b/PersonListForm.cpp @@ -21,26 +21,128 @@ ui->vsTableTop->changeSize(0, 20); ui->vsContentBottom->changeSize(0, 40); - itemModel = new QStandardItemModel(this); + // 初始化空的人员列表表格 + initPersonTableHeader(); + // 初始化部门下拉列表框 + SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); +} + +PersonListForm::~PersonListForm() +{ + delete ui; +} + +void PersonListForm::keyPressEvent(QKeyEvent * event) +{ + switch (event->key()) { + case Qt::Key_Return: // 小键盘的Enter键 + case Qt::Key_Enter: // Enter键 + currentPage = 0; + this->findPersonList(); + break; + + default: + QWidget::keyPressEvent(event); + } +} + +void PersonListForm::calcTotalPage(int totalCount) +{ + double temp = (totalCount * 1.0) / (tableRowCount * 1.0); + totalPage = ceil(temp); +} + +void PersonListForm::findPersonList() +{ + SysPersonDao personDao; + + // 获取查询条件 + QString name = ui->inputName->text(); + QString dept = ui->selectDept->currentData().toString(); + + // 计算分页查询的偏移量 + qint16 offset = currentPage * tableRowCount; + + // 查询总条数并计算总页数 + int totalCount = personDao.findRecordCountByNameAndDept(name, dept); + calcTotalPage(totalCount); + + // 赋值表格内容 + QVector perList = personDao.findRecordsByNameAndDept(name, dept, tableRowCount, offset); + + // 有数据且查询结果为空 则重新查询上一页 + if (totalCount > 0 && perList.isEmpty()) + { + // 触发查询上一页的操作 后续操作不再执行 + emit ui->btnPre->clicked(); + return ; + } + + this->personList->clear(); + for (int i = 0; i < perList.size(); i++) { + QVariantMap person = perList.at(i); + this->personList->append(person); + } + + // 更新显示表格 + this->updatePersonListTable(); + + // 更新页码 + if (totalCount == 0) + { + ui->labCurrPage->setText("0"); + } else + { + ui->labCurrPage->setText(QString("%1 / %2 , %3").arg(currentPage + 1).arg(totalPage).arg(totalCount)); + } +} + +void PersonListForm::initPersonTableHeader() +{ + itemModel = new QStandardItemModel(this); personList = new QList(); - SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); - + // 添加表头 QStringList header; header << "员工编号" << "姓名" << "部门 "<< "采集特征" << "操作"; itemModel->setHorizontalHeaderLabels(header); - for (int i = 0; i < tableRowCount; i++) { - QList row; - for ( int j = 0; j < tableColCount; j++) { - itemModel->setItem(i, j, new QStandardItem(QString(""))); - itemModel->item(i, j)->setTextAlignment(Qt::AlignCenter); - } - } + // 设置表头的宽度为固定值 不可调整 + ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); +} + +void PersonListForm::updatePersonListTable() +{ + // 清除表格原有数据 + itemModel->removeRows(0, itemModel->rowCount()); + ui->personListTable->setModel(itemModel); - ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); + // 判断是否有分页 + int max = tableRowCount > personList->size() ? personList->size() : tableRowCount; + for (int i = 0; i < max; i++) { + QList row; + itemModel->setItem(i, 0, new QStandardItem(personList->at(i).find("person_code")->toString())); + itemModel->item(i, 0)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 1, new QStandardItem(personList->at(i).find("name")->toString())); + itemModel->item(i, 1)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 2, new QStandardItem(personList->at(i).find("deptname")->toString())); + itemModel->item(i, 2)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 3, new QStandardItem(QString("iris face"))); + itemModel->item(i, 3)->setTextAlignment(Qt::AlignCenter); + + QPushButton * btnDele = new QPushButton("删除"); + btnDele->setProperty("personId", personList->at(i).find("id")->toString()); + btnDele->setProperty("class", "btnDelete"); + connect(btnDele, &QPushButton::clicked, + this, &PersonListForm::btnDeleClicked); + ui->personListTable->setIndexWidget(itemModel->index(i, 4), btnDele); + } + // 设置每行的高度 for ( int i = 0; i < tableRowCount; i++) { @@ -55,27 +157,6 @@ ui->personListTable->setColumnWidth(4, 150); } -PersonListForm::~PersonListForm() -{ - delete ui; -} - -void PersonListForm::findPersonList() -{ - SysPersonDao personDao; - QVector perList = personDao.findAllRecord(); - this->personList->clear(); - for (int i = 0; i < perList.size(); i++) { - QVariantMap person = perList.at(i); - this->personList->append(person); - } -} - -void PersonListForm::updatePersonListTable() -{ - -} - void PersonListForm::on_btnRegist_clicked() { emit switchToRegistForm("0"); @@ -90,3 +171,56 @@ { emit backToHomePage(); } + +void PersonListForm::on_selectDept_currentIndexChanged(int index) +{ + currentPage = 0; + this->findPersonList(); +} + +void PersonListForm::on_btnFirst_clicked() +{ + // 第一页 + currentPage = 0; + findPersonList(); +} + +void PersonListForm::on_btnLast_clicked() +{ + // 最后一页 + currentPage = totalPage - 1; + findPersonList(); +} + +void PersonListForm::on_btnPre_clicked() +{ + // 上一页 + if (currentPage > 0) + { + currentPage = currentPage - 1; + } + findPersonList(); +} + +void PersonListForm::on_btnNext_clicked() +{ + // 下一页 + if (currentPage < totalPage - 1) + { + currentPage++; + } + findPersonList(); +} + +void PersonListForm::btnDeleClicked() +{ + // 获取发送者的信息 + QPushButton * senderObj = (QPushButton *) sender(); + QString personId = senderObj->property("personId").toString(); + SysPersonDao personDao; + bool succ = personDao.dele(personId); + if (succ == 1) + { + findPersonList(); + } +} diff --git a/PersonListForm.h b/PersonListForm.h index 236bc53..cce03a3 100644 --- a/PersonListForm.h +++ b/PersonListForm.h @@ -19,6 +19,8 @@ explicit PersonListForm(QWidget *parent = nullptr); ~PersonListForm(); + void keyPressEvent(QKeyEvent * event); + private slots: void on_btnRegist_clicked(); @@ -26,6 +28,18 @@ void on_btnBack_clicked(); + void on_selectDept_currentIndexChanged(int index); + + void on_btnFirst_clicked(); + + void on_btnLast_clicked(); + + void on_btnPre_clicked(); + + void on_btnNext_clicked(); + + void btnDeleClicked(); + private: Ui::PersonListForm *ui; QStandardItemModel * itemModel; @@ -33,8 +47,12 @@ int tableRowCount = 8; int tableColCount = 5; + int currentPage = 0; + int totalPage = 0; + void calcTotalPage(int totalCount); void findPersonList(); + void initPersonTableHeader(); void updatePersonListTable(); signals: diff --git a/CasicBioRecWin.cpp b/CasicBioRecWin.cpp index 562f7ca..81d4615 100644 --- a/CasicBioRecWin.cpp +++ b/CasicBioRecWin.cpp @@ -9,8 +9,10 @@ { ui->setupUi(this); + // 程序启动时初始化缓存的数据 this->initCacheData(); + // 设置窗口透明和大小、位置 this->setWindowFlags(Qt::FramelessWindowHint); this->move(0, 0); this->resize(SettingConfig::getInstance().WINDOW_WIDTH, @@ -19,8 +21,10 @@ // 通过调色板的颜色来设置窗口的统一背景色 qApp->setPalette(QPalette(QColor(SettingConfig::getInstance().WINDOW_BACKGROUND_COLOR))); + // 初始化各个form界面并绑定切换响应函数 this->initFormsPtr(); + // 打印日志 LOG(INFO) << QString("应用程序启动成功[Application Startup Success]").toStdString(); } diff --git a/PersonListForm.cpp b/PersonListForm.cpp index 77fc565..e479626 100644 --- a/PersonListForm.cpp +++ b/PersonListForm.cpp @@ -21,26 +21,128 @@ ui->vsTableTop->changeSize(0, 20); ui->vsContentBottom->changeSize(0, 40); - itemModel = new QStandardItemModel(this); + // 初始化空的人员列表表格 + initPersonTableHeader(); + // 初始化部门下拉列表框 + SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); +} + +PersonListForm::~PersonListForm() +{ + delete ui; +} + +void PersonListForm::keyPressEvent(QKeyEvent * event) +{ + switch (event->key()) { + case Qt::Key_Return: // 小键盘的Enter键 + case Qt::Key_Enter: // Enter键 + currentPage = 0; + this->findPersonList(); + break; + + default: + QWidget::keyPressEvent(event); + } +} + +void PersonListForm::calcTotalPage(int totalCount) +{ + double temp = (totalCount * 1.0) / (tableRowCount * 1.0); + totalPage = ceil(temp); +} + +void PersonListForm::findPersonList() +{ + SysPersonDao personDao; + + // 获取查询条件 + QString name = ui->inputName->text(); + QString dept = ui->selectDept->currentData().toString(); + + // 计算分页查询的偏移量 + qint16 offset = currentPage * tableRowCount; + + // 查询总条数并计算总页数 + int totalCount = personDao.findRecordCountByNameAndDept(name, dept); + calcTotalPage(totalCount); + + // 赋值表格内容 + QVector perList = personDao.findRecordsByNameAndDept(name, dept, tableRowCount, offset); + + // 有数据且查询结果为空 则重新查询上一页 + if (totalCount > 0 && perList.isEmpty()) + { + // 触发查询上一页的操作 后续操作不再执行 + emit ui->btnPre->clicked(); + return ; + } + + this->personList->clear(); + for (int i = 0; i < perList.size(); i++) { + QVariantMap person = perList.at(i); + this->personList->append(person); + } + + // 更新显示表格 + this->updatePersonListTable(); + + // 更新页码 + if (totalCount == 0) + { + ui->labCurrPage->setText("0"); + } else + { + ui->labCurrPage->setText(QString("%1 / %2 , %3").arg(currentPage + 1).arg(totalPage).arg(totalCount)); + } +} + +void PersonListForm::initPersonTableHeader() +{ + itemModel = new QStandardItemModel(this); personList = new QList(); - SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); - + // 添加表头 QStringList header; header << "员工编号" << "姓名" << "部门 "<< "采集特征" << "操作"; itemModel->setHorizontalHeaderLabels(header); - for (int i = 0; i < tableRowCount; i++) { - QList row; - for ( int j = 0; j < tableColCount; j++) { - itemModel->setItem(i, j, new QStandardItem(QString(""))); - itemModel->item(i, j)->setTextAlignment(Qt::AlignCenter); - } - } + // 设置表头的宽度为固定值 不可调整 + ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); +} + +void PersonListForm::updatePersonListTable() +{ + // 清除表格原有数据 + itemModel->removeRows(0, itemModel->rowCount()); + ui->personListTable->setModel(itemModel); - ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); + // 判断是否有分页 + int max = tableRowCount > personList->size() ? personList->size() : tableRowCount; + for (int i = 0; i < max; i++) { + QList row; + itemModel->setItem(i, 0, new QStandardItem(personList->at(i).find("person_code")->toString())); + itemModel->item(i, 0)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 1, new QStandardItem(personList->at(i).find("name")->toString())); + itemModel->item(i, 1)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 2, new QStandardItem(personList->at(i).find("deptname")->toString())); + itemModel->item(i, 2)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 3, new QStandardItem(QString("iris face"))); + itemModel->item(i, 3)->setTextAlignment(Qt::AlignCenter); + + QPushButton * btnDele = new QPushButton("删除"); + btnDele->setProperty("personId", personList->at(i).find("id")->toString()); + btnDele->setProperty("class", "btnDelete"); + connect(btnDele, &QPushButton::clicked, + this, &PersonListForm::btnDeleClicked); + ui->personListTable->setIndexWidget(itemModel->index(i, 4), btnDele); + } + // 设置每行的高度 for ( int i = 0; i < tableRowCount; i++) { @@ -55,27 +157,6 @@ ui->personListTable->setColumnWidth(4, 150); } -PersonListForm::~PersonListForm() -{ - delete ui; -} - -void PersonListForm::findPersonList() -{ - SysPersonDao personDao; - QVector perList = personDao.findAllRecord(); - this->personList->clear(); - for (int i = 0; i < perList.size(); i++) { - QVariantMap person = perList.at(i); - this->personList->append(person); - } -} - -void PersonListForm::updatePersonListTable() -{ - -} - void PersonListForm::on_btnRegist_clicked() { emit switchToRegistForm("0"); @@ -90,3 +171,56 @@ { emit backToHomePage(); } + +void PersonListForm::on_selectDept_currentIndexChanged(int index) +{ + currentPage = 0; + this->findPersonList(); +} + +void PersonListForm::on_btnFirst_clicked() +{ + // 第一页 + currentPage = 0; + findPersonList(); +} + +void PersonListForm::on_btnLast_clicked() +{ + // 最后一页 + currentPage = totalPage - 1; + findPersonList(); +} + +void PersonListForm::on_btnPre_clicked() +{ + // 上一页 + if (currentPage > 0) + { + currentPage = currentPage - 1; + } + findPersonList(); +} + +void PersonListForm::on_btnNext_clicked() +{ + // 下一页 + if (currentPage < totalPage - 1) + { + currentPage++; + } + findPersonList(); +} + +void PersonListForm::btnDeleClicked() +{ + // 获取发送者的信息 + QPushButton * senderObj = (QPushButton *) sender(); + QString personId = senderObj->property("personId").toString(); + SysPersonDao personDao; + bool succ = personDao.dele(personId); + if (succ == 1) + { + findPersonList(); + } +} diff --git a/PersonListForm.h b/PersonListForm.h index 236bc53..cce03a3 100644 --- a/PersonListForm.h +++ b/PersonListForm.h @@ -19,6 +19,8 @@ explicit PersonListForm(QWidget *parent = nullptr); ~PersonListForm(); + void keyPressEvent(QKeyEvent * event); + private slots: void on_btnRegist_clicked(); @@ -26,6 +28,18 @@ void on_btnBack_clicked(); + void on_selectDept_currentIndexChanged(int index); + + void on_btnFirst_clicked(); + + void on_btnLast_clicked(); + + void on_btnPre_clicked(); + + void on_btnNext_clicked(); + + void btnDeleClicked(); + private: Ui::PersonListForm *ui; QStandardItemModel * itemModel; @@ -33,8 +47,12 @@ int tableRowCount = 8; int tableColCount = 5; + int currentPage = 0; + int totalPage = 0; + void calcTotalPage(int totalCount); void findPersonList(); + void initPersonTableHeader(); void updatePersonListTable(); signals: diff --git a/PersonListForm.ui b/PersonListForm.ui index 909cbf2..5bc81f5 100644 --- a/PersonListForm.ui +++ b/PersonListForm.ui @@ -233,7 +233,14 @@ - 1 / 1 + 1 + + + + + + + 条记录 diff --git a/CasicBioRecWin.cpp b/CasicBioRecWin.cpp index 562f7ca..81d4615 100644 --- a/CasicBioRecWin.cpp +++ b/CasicBioRecWin.cpp @@ -9,8 +9,10 @@ { ui->setupUi(this); + // 程序启动时初始化缓存的数据 this->initCacheData(); + // 设置窗口透明和大小、位置 this->setWindowFlags(Qt::FramelessWindowHint); this->move(0, 0); this->resize(SettingConfig::getInstance().WINDOW_WIDTH, @@ -19,8 +21,10 @@ // 通过调色板的颜色来设置窗口的统一背景色 qApp->setPalette(QPalette(QColor(SettingConfig::getInstance().WINDOW_BACKGROUND_COLOR))); + // 初始化各个form界面并绑定切换响应函数 this->initFormsPtr(); + // 打印日志 LOG(INFO) << QString("应用程序启动成功[Application Startup Success]").toStdString(); } diff --git a/PersonListForm.cpp b/PersonListForm.cpp index 77fc565..e479626 100644 --- a/PersonListForm.cpp +++ b/PersonListForm.cpp @@ -21,26 +21,128 @@ ui->vsTableTop->changeSize(0, 20); ui->vsContentBottom->changeSize(0, 40); - itemModel = new QStandardItemModel(this); + // 初始化空的人员列表表格 + initPersonTableHeader(); + // 初始化部门下拉列表框 + SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); +} + +PersonListForm::~PersonListForm() +{ + delete ui; +} + +void PersonListForm::keyPressEvent(QKeyEvent * event) +{ + switch (event->key()) { + case Qt::Key_Return: // 小键盘的Enter键 + case Qt::Key_Enter: // Enter键 + currentPage = 0; + this->findPersonList(); + break; + + default: + QWidget::keyPressEvent(event); + } +} + +void PersonListForm::calcTotalPage(int totalCount) +{ + double temp = (totalCount * 1.0) / (tableRowCount * 1.0); + totalPage = ceil(temp); +} + +void PersonListForm::findPersonList() +{ + SysPersonDao personDao; + + // 获取查询条件 + QString name = ui->inputName->text(); + QString dept = ui->selectDept->currentData().toString(); + + // 计算分页查询的偏移量 + qint16 offset = currentPage * tableRowCount; + + // 查询总条数并计算总页数 + int totalCount = personDao.findRecordCountByNameAndDept(name, dept); + calcTotalPage(totalCount); + + // 赋值表格内容 + QVector perList = personDao.findRecordsByNameAndDept(name, dept, tableRowCount, offset); + + // 有数据且查询结果为空 则重新查询上一页 + if (totalCount > 0 && perList.isEmpty()) + { + // 触发查询上一页的操作 后续操作不再执行 + emit ui->btnPre->clicked(); + return ; + } + + this->personList->clear(); + for (int i = 0; i < perList.size(); i++) { + QVariantMap person = perList.at(i); + this->personList->append(person); + } + + // 更新显示表格 + this->updatePersonListTable(); + + // 更新页码 + if (totalCount == 0) + { + ui->labCurrPage->setText("0"); + } else + { + ui->labCurrPage->setText(QString("%1 / %2 , %3").arg(currentPage + 1).arg(totalPage).arg(totalCount)); + } +} + +void PersonListForm::initPersonTableHeader() +{ + itemModel = new QStandardItemModel(this); personList = new QList(); - SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); - + // 添加表头 QStringList header; header << "员工编号" << "姓名" << "部门 "<< "采集特征" << "操作"; itemModel->setHorizontalHeaderLabels(header); - for (int i = 0; i < tableRowCount; i++) { - QList row; - for ( int j = 0; j < tableColCount; j++) { - itemModel->setItem(i, j, new QStandardItem(QString(""))); - itemModel->item(i, j)->setTextAlignment(Qt::AlignCenter); - } - } + // 设置表头的宽度为固定值 不可调整 + ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); +} + +void PersonListForm::updatePersonListTable() +{ + // 清除表格原有数据 + itemModel->removeRows(0, itemModel->rowCount()); + ui->personListTable->setModel(itemModel); - ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); + // 判断是否有分页 + int max = tableRowCount > personList->size() ? personList->size() : tableRowCount; + for (int i = 0; i < max; i++) { + QList row; + itemModel->setItem(i, 0, new QStandardItem(personList->at(i).find("person_code")->toString())); + itemModel->item(i, 0)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 1, new QStandardItem(personList->at(i).find("name")->toString())); + itemModel->item(i, 1)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 2, new QStandardItem(personList->at(i).find("deptname")->toString())); + itemModel->item(i, 2)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 3, new QStandardItem(QString("iris face"))); + itemModel->item(i, 3)->setTextAlignment(Qt::AlignCenter); + + QPushButton * btnDele = new QPushButton("删除"); + btnDele->setProperty("personId", personList->at(i).find("id")->toString()); + btnDele->setProperty("class", "btnDelete"); + connect(btnDele, &QPushButton::clicked, + this, &PersonListForm::btnDeleClicked); + ui->personListTable->setIndexWidget(itemModel->index(i, 4), btnDele); + } + // 设置每行的高度 for ( int i = 0; i < tableRowCount; i++) { @@ -55,27 +157,6 @@ ui->personListTable->setColumnWidth(4, 150); } -PersonListForm::~PersonListForm() -{ - delete ui; -} - -void PersonListForm::findPersonList() -{ - SysPersonDao personDao; - QVector perList = personDao.findAllRecord(); - this->personList->clear(); - for (int i = 0; i < perList.size(); i++) { - QVariantMap person = perList.at(i); - this->personList->append(person); - } -} - -void PersonListForm::updatePersonListTable() -{ - -} - void PersonListForm::on_btnRegist_clicked() { emit switchToRegistForm("0"); @@ -90,3 +171,56 @@ { emit backToHomePage(); } + +void PersonListForm::on_selectDept_currentIndexChanged(int index) +{ + currentPage = 0; + this->findPersonList(); +} + +void PersonListForm::on_btnFirst_clicked() +{ + // 第一页 + currentPage = 0; + findPersonList(); +} + +void PersonListForm::on_btnLast_clicked() +{ + // 最后一页 + currentPage = totalPage - 1; + findPersonList(); +} + +void PersonListForm::on_btnPre_clicked() +{ + // 上一页 + if (currentPage > 0) + { + currentPage = currentPage - 1; + } + findPersonList(); +} + +void PersonListForm::on_btnNext_clicked() +{ + // 下一页 + if (currentPage < totalPage - 1) + { + currentPage++; + } + findPersonList(); +} + +void PersonListForm::btnDeleClicked() +{ + // 获取发送者的信息 + QPushButton * senderObj = (QPushButton *) sender(); + QString personId = senderObj->property("personId").toString(); + SysPersonDao personDao; + bool succ = personDao.dele(personId); + if (succ == 1) + { + findPersonList(); + } +} diff --git a/PersonListForm.h b/PersonListForm.h index 236bc53..cce03a3 100644 --- a/PersonListForm.h +++ b/PersonListForm.h @@ -19,6 +19,8 @@ explicit PersonListForm(QWidget *parent = nullptr); ~PersonListForm(); + void keyPressEvent(QKeyEvent * event); + private slots: void on_btnRegist_clicked(); @@ -26,6 +28,18 @@ void on_btnBack_clicked(); + void on_selectDept_currentIndexChanged(int index); + + void on_btnFirst_clicked(); + + void on_btnLast_clicked(); + + void on_btnPre_clicked(); + + void on_btnNext_clicked(); + + void btnDeleClicked(); + private: Ui::PersonListForm *ui; QStandardItemModel * itemModel; @@ -33,8 +47,12 @@ int tableRowCount = 8; int tableColCount = 5; + int currentPage = 0; + int totalPage = 0; + void calcTotalPage(int totalCount); void findPersonList(); + void initPersonTableHeader(); void updatePersonListTable(); signals: diff --git a/PersonListForm.ui b/PersonListForm.ui index 909cbf2..5bc81f5 100644 --- a/PersonListForm.ui +++ b/PersonListForm.ui @@ -233,7 +233,14 @@ - 1 / 1 + 1 + + + + + + + 条记录 diff --git a/dao/BaseDao.h b/dao/BaseDao.h index aa67f80..1ea0c93 100644 --- a/dao/BaseDao.h +++ b/dao/BaseDao.h @@ -1,4 +1,4 @@ -#ifndef BASEDAO_H +#ifndef BASEDAO_H #define BASEDAO_H #include @@ -21,8 +21,8 @@ virtual QVector findRecordsByProperty(QString properName, QVariant properValue) = 0; virtual QString save(QVariantMap object) = 0; - virtual bool edit(QVariantMap newObject, qulonglong id) = 0; - virtual bool dele(qulonglong id) = 0; + virtual bool edit(QVariantMap newObject, QString id) = 0; + virtual bool dele(QString id) = 0; private: diff --git a/CasicBioRecWin.cpp b/CasicBioRecWin.cpp index 562f7ca..81d4615 100644 --- a/CasicBioRecWin.cpp +++ b/CasicBioRecWin.cpp @@ -9,8 +9,10 @@ { ui->setupUi(this); + // 程序启动时初始化缓存的数据 this->initCacheData(); + // 设置窗口透明和大小、位置 this->setWindowFlags(Qt::FramelessWindowHint); this->move(0, 0); this->resize(SettingConfig::getInstance().WINDOW_WIDTH, @@ -19,8 +21,10 @@ // 通过调色板的颜色来设置窗口的统一背景色 qApp->setPalette(QPalette(QColor(SettingConfig::getInstance().WINDOW_BACKGROUND_COLOR))); + // 初始化各个form界面并绑定切换响应函数 this->initFormsPtr(); + // 打印日志 LOG(INFO) << QString("应用程序启动成功[Application Startup Success]").toStdString(); } diff --git a/PersonListForm.cpp b/PersonListForm.cpp index 77fc565..e479626 100644 --- a/PersonListForm.cpp +++ b/PersonListForm.cpp @@ -21,26 +21,128 @@ ui->vsTableTop->changeSize(0, 20); ui->vsContentBottom->changeSize(0, 40); - itemModel = new QStandardItemModel(this); + // 初始化空的人员列表表格 + initPersonTableHeader(); + // 初始化部门下拉列表框 + SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); +} + +PersonListForm::~PersonListForm() +{ + delete ui; +} + +void PersonListForm::keyPressEvent(QKeyEvent * event) +{ + switch (event->key()) { + case Qt::Key_Return: // 小键盘的Enter键 + case Qt::Key_Enter: // Enter键 + currentPage = 0; + this->findPersonList(); + break; + + default: + QWidget::keyPressEvent(event); + } +} + +void PersonListForm::calcTotalPage(int totalCount) +{ + double temp = (totalCount * 1.0) / (tableRowCount * 1.0); + totalPage = ceil(temp); +} + +void PersonListForm::findPersonList() +{ + SysPersonDao personDao; + + // 获取查询条件 + QString name = ui->inputName->text(); + QString dept = ui->selectDept->currentData().toString(); + + // 计算分页查询的偏移量 + qint16 offset = currentPage * tableRowCount; + + // 查询总条数并计算总页数 + int totalCount = personDao.findRecordCountByNameAndDept(name, dept); + calcTotalPage(totalCount); + + // 赋值表格内容 + QVector perList = personDao.findRecordsByNameAndDept(name, dept, tableRowCount, offset); + + // 有数据且查询结果为空 则重新查询上一页 + if (totalCount > 0 && perList.isEmpty()) + { + // 触发查询上一页的操作 后续操作不再执行 + emit ui->btnPre->clicked(); + return ; + } + + this->personList->clear(); + for (int i = 0; i < perList.size(); i++) { + QVariantMap person = perList.at(i); + this->personList->append(person); + } + + // 更新显示表格 + this->updatePersonListTable(); + + // 更新页码 + if (totalCount == 0) + { + ui->labCurrPage->setText("0"); + } else + { + ui->labCurrPage->setText(QString("%1 / %2 , %3").arg(currentPage + 1).arg(totalPage).arg(totalCount)); + } +} + +void PersonListForm::initPersonTableHeader() +{ + itemModel = new QStandardItemModel(this); personList = new QList(); - SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); - + // 添加表头 QStringList header; header << "员工编号" << "姓名" << "部门 "<< "采集特征" << "操作"; itemModel->setHorizontalHeaderLabels(header); - for (int i = 0; i < tableRowCount; i++) { - QList row; - for ( int j = 0; j < tableColCount; j++) { - itemModel->setItem(i, j, new QStandardItem(QString(""))); - itemModel->item(i, j)->setTextAlignment(Qt::AlignCenter); - } - } + // 设置表头的宽度为固定值 不可调整 + ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); +} + +void PersonListForm::updatePersonListTable() +{ + // 清除表格原有数据 + itemModel->removeRows(0, itemModel->rowCount()); + ui->personListTable->setModel(itemModel); - ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); + // 判断是否有分页 + int max = tableRowCount > personList->size() ? personList->size() : tableRowCount; + for (int i = 0; i < max; i++) { + QList row; + itemModel->setItem(i, 0, new QStandardItem(personList->at(i).find("person_code")->toString())); + itemModel->item(i, 0)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 1, new QStandardItem(personList->at(i).find("name")->toString())); + itemModel->item(i, 1)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 2, new QStandardItem(personList->at(i).find("deptname")->toString())); + itemModel->item(i, 2)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 3, new QStandardItem(QString("iris face"))); + itemModel->item(i, 3)->setTextAlignment(Qt::AlignCenter); + + QPushButton * btnDele = new QPushButton("删除"); + btnDele->setProperty("personId", personList->at(i).find("id")->toString()); + btnDele->setProperty("class", "btnDelete"); + connect(btnDele, &QPushButton::clicked, + this, &PersonListForm::btnDeleClicked); + ui->personListTable->setIndexWidget(itemModel->index(i, 4), btnDele); + } + // 设置每行的高度 for ( int i = 0; i < tableRowCount; i++) { @@ -55,27 +157,6 @@ ui->personListTable->setColumnWidth(4, 150); } -PersonListForm::~PersonListForm() -{ - delete ui; -} - -void PersonListForm::findPersonList() -{ - SysPersonDao personDao; - QVector perList = personDao.findAllRecord(); - this->personList->clear(); - for (int i = 0; i < perList.size(); i++) { - QVariantMap person = perList.at(i); - this->personList->append(person); - } -} - -void PersonListForm::updatePersonListTable() -{ - -} - void PersonListForm::on_btnRegist_clicked() { emit switchToRegistForm("0"); @@ -90,3 +171,56 @@ { emit backToHomePage(); } + +void PersonListForm::on_selectDept_currentIndexChanged(int index) +{ + currentPage = 0; + this->findPersonList(); +} + +void PersonListForm::on_btnFirst_clicked() +{ + // 第一页 + currentPage = 0; + findPersonList(); +} + +void PersonListForm::on_btnLast_clicked() +{ + // 最后一页 + currentPage = totalPage - 1; + findPersonList(); +} + +void PersonListForm::on_btnPre_clicked() +{ + // 上一页 + if (currentPage > 0) + { + currentPage = currentPage - 1; + } + findPersonList(); +} + +void PersonListForm::on_btnNext_clicked() +{ + // 下一页 + if (currentPage < totalPage - 1) + { + currentPage++; + } + findPersonList(); +} + +void PersonListForm::btnDeleClicked() +{ + // 获取发送者的信息 + QPushButton * senderObj = (QPushButton *) sender(); + QString personId = senderObj->property("personId").toString(); + SysPersonDao personDao; + bool succ = personDao.dele(personId); + if (succ == 1) + { + findPersonList(); + } +} diff --git a/PersonListForm.h b/PersonListForm.h index 236bc53..cce03a3 100644 --- a/PersonListForm.h +++ b/PersonListForm.h @@ -19,6 +19,8 @@ explicit PersonListForm(QWidget *parent = nullptr); ~PersonListForm(); + void keyPressEvent(QKeyEvent * event); + private slots: void on_btnRegist_clicked(); @@ -26,6 +28,18 @@ void on_btnBack_clicked(); + void on_selectDept_currentIndexChanged(int index); + + void on_btnFirst_clicked(); + + void on_btnLast_clicked(); + + void on_btnPre_clicked(); + + void on_btnNext_clicked(); + + void btnDeleClicked(); + private: Ui::PersonListForm *ui; QStandardItemModel * itemModel; @@ -33,8 +47,12 @@ int tableRowCount = 8; int tableColCount = 5; + int currentPage = 0; + int totalPage = 0; + void calcTotalPage(int totalCount); void findPersonList(); + void initPersonTableHeader(); void updatePersonListTable(); signals: diff --git a/PersonListForm.ui b/PersonListForm.ui index 909cbf2..5bc81f5 100644 --- a/PersonListForm.ui +++ b/PersonListForm.ui @@ -233,7 +233,14 @@ - 1 / 1 + 1 + + + + + + + 条记录 diff --git a/dao/BaseDao.h b/dao/BaseDao.h index aa67f80..1ea0c93 100644 --- a/dao/BaseDao.h +++ b/dao/BaseDao.h @@ -1,4 +1,4 @@ -#ifndef BASEDAO_H +#ifndef BASEDAO_H #define BASEDAO_H #include @@ -21,8 +21,8 @@ virtual QVector findRecordsByProperty(QString properName, QVariant properValue) = 0; virtual QString save(QVariantMap object) = 0; - virtual bool edit(QVariantMap newObject, qulonglong id) = 0; - virtual bool dele(qulonglong id) = 0; + virtual bool edit(QVariantMap newObject, QString id) = 0; + virtual bool dele(QString id) = 0; private: diff --git a/dao/FaceDataDao.cpp b/dao/FaceDataDao.cpp index d668b0a..642f3fb 100644 --- a/dao/FaceDataDao.cpp +++ b/dao/FaceDataDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataDao.h" +#include "FaceDataDao.h" FaceDataDao::FaceDataDao(QObject *parent) : BaseDao(parent) { @@ -87,12 +87,12 @@ } } -bool FaceDataDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool FaceDataDao::dele(qulonglong id) +bool FaceDataDao::dele(QString id) { return false; } diff --git a/CasicBioRecWin.cpp b/CasicBioRecWin.cpp index 562f7ca..81d4615 100644 --- a/CasicBioRecWin.cpp +++ b/CasicBioRecWin.cpp @@ -9,8 +9,10 @@ { ui->setupUi(this); + // 程序启动时初始化缓存的数据 this->initCacheData(); + // 设置窗口透明和大小、位置 this->setWindowFlags(Qt::FramelessWindowHint); this->move(0, 0); this->resize(SettingConfig::getInstance().WINDOW_WIDTH, @@ -19,8 +21,10 @@ // 通过调色板的颜色来设置窗口的统一背景色 qApp->setPalette(QPalette(QColor(SettingConfig::getInstance().WINDOW_BACKGROUND_COLOR))); + // 初始化各个form界面并绑定切换响应函数 this->initFormsPtr(); + // 打印日志 LOG(INFO) << QString("应用程序启动成功[Application Startup Success]").toStdString(); } diff --git a/PersonListForm.cpp b/PersonListForm.cpp index 77fc565..e479626 100644 --- a/PersonListForm.cpp +++ b/PersonListForm.cpp @@ -21,26 +21,128 @@ ui->vsTableTop->changeSize(0, 20); ui->vsContentBottom->changeSize(0, 40); - itemModel = new QStandardItemModel(this); + // 初始化空的人员列表表格 + initPersonTableHeader(); + // 初始化部门下拉列表框 + SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); +} + +PersonListForm::~PersonListForm() +{ + delete ui; +} + +void PersonListForm::keyPressEvent(QKeyEvent * event) +{ + switch (event->key()) { + case Qt::Key_Return: // 小键盘的Enter键 + case Qt::Key_Enter: // Enter键 + currentPage = 0; + this->findPersonList(); + break; + + default: + QWidget::keyPressEvent(event); + } +} + +void PersonListForm::calcTotalPage(int totalCount) +{ + double temp = (totalCount * 1.0) / (tableRowCount * 1.0); + totalPage = ceil(temp); +} + +void PersonListForm::findPersonList() +{ + SysPersonDao personDao; + + // 获取查询条件 + QString name = ui->inputName->text(); + QString dept = ui->selectDept->currentData().toString(); + + // 计算分页查询的偏移量 + qint16 offset = currentPage * tableRowCount; + + // 查询总条数并计算总页数 + int totalCount = personDao.findRecordCountByNameAndDept(name, dept); + calcTotalPage(totalCount); + + // 赋值表格内容 + QVector perList = personDao.findRecordsByNameAndDept(name, dept, tableRowCount, offset); + + // 有数据且查询结果为空 则重新查询上一页 + if (totalCount > 0 && perList.isEmpty()) + { + // 触发查询上一页的操作 后续操作不再执行 + emit ui->btnPre->clicked(); + return ; + } + + this->personList->clear(); + for (int i = 0; i < perList.size(); i++) { + QVariantMap person = perList.at(i); + this->personList->append(person); + } + + // 更新显示表格 + this->updatePersonListTable(); + + // 更新页码 + if (totalCount == 0) + { + ui->labCurrPage->setText("0"); + } else + { + ui->labCurrPage->setText(QString("%1 / %2 , %3").arg(currentPage + 1).arg(totalPage).arg(totalCount)); + } +} + +void PersonListForm::initPersonTableHeader() +{ + itemModel = new QStandardItemModel(this); personList = new QList(); - SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); - + // 添加表头 QStringList header; header << "员工编号" << "姓名" << "部门 "<< "采集特征" << "操作"; itemModel->setHorizontalHeaderLabels(header); - for (int i = 0; i < tableRowCount; i++) { - QList row; - for ( int j = 0; j < tableColCount; j++) { - itemModel->setItem(i, j, new QStandardItem(QString(""))); - itemModel->item(i, j)->setTextAlignment(Qt::AlignCenter); - } - } + // 设置表头的宽度为固定值 不可调整 + ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); +} + +void PersonListForm::updatePersonListTable() +{ + // 清除表格原有数据 + itemModel->removeRows(0, itemModel->rowCount()); + ui->personListTable->setModel(itemModel); - ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); + // 判断是否有分页 + int max = tableRowCount > personList->size() ? personList->size() : tableRowCount; + for (int i = 0; i < max; i++) { + QList row; + itemModel->setItem(i, 0, new QStandardItem(personList->at(i).find("person_code")->toString())); + itemModel->item(i, 0)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 1, new QStandardItem(personList->at(i).find("name")->toString())); + itemModel->item(i, 1)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 2, new QStandardItem(personList->at(i).find("deptname")->toString())); + itemModel->item(i, 2)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 3, new QStandardItem(QString("iris face"))); + itemModel->item(i, 3)->setTextAlignment(Qt::AlignCenter); + + QPushButton * btnDele = new QPushButton("删除"); + btnDele->setProperty("personId", personList->at(i).find("id")->toString()); + btnDele->setProperty("class", "btnDelete"); + connect(btnDele, &QPushButton::clicked, + this, &PersonListForm::btnDeleClicked); + ui->personListTable->setIndexWidget(itemModel->index(i, 4), btnDele); + } + // 设置每行的高度 for ( int i = 0; i < tableRowCount; i++) { @@ -55,27 +157,6 @@ ui->personListTable->setColumnWidth(4, 150); } -PersonListForm::~PersonListForm() -{ - delete ui; -} - -void PersonListForm::findPersonList() -{ - SysPersonDao personDao; - QVector perList = personDao.findAllRecord(); - this->personList->clear(); - for (int i = 0; i < perList.size(); i++) { - QVariantMap person = perList.at(i); - this->personList->append(person); - } -} - -void PersonListForm::updatePersonListTable() -{ - -} - void PersonListForm::on_btnRegist_clicked() { emit switchToRegistForm("0"); @@ -90,3 +171,56 @@ { emit backToHomePage(); } + +void PersonListForm::on_selectDept_currentIndexChanged(int index) +{ + currentPage = 0; + this->findPersonList(); +} + +void PersonListForm::on_btnFirst_clicked() +{ + // 第一页 + currentPage = 0; + findPersonList(); +} + +void PersonListForm::on_btnLast_clicked() +{ + // 最后一页 + currentPage = totalPage - 1; + findPersonList(); +} + +void PersonListForm::on_btnPre_clicked() +{ + // 上一页 + if (currentPage > 0) + { + currentPage = currentPage - 1; + } + findPersonList(); +} + +void PersonListForm::on_btnNext_clicked() +{ + // 下一页 + if (currentPage < totalPage - 1) + { + currentPage++; + } + findPersonList(); +} + +void PersonListForm::btnDeleClicked() +{ + // 获取发送者的信息 + QPushButton * senderObj = (QPushButton *) sender(); + QString personId = senderObj->property("personId").toString(); + SysPersonDao personDao; + bool succ = personDao.dele(personId); + if (succ == 1) + { + findPersonList(); + } +} diff --git a/PersonListForm.h b/PersonListForm.h index 236bc53..cce03a3 100644 --- a/PersonListForm.h +++ b/PersonListForm.h @@ -19,6 +19,8 @@ explicit PersonListForm(QWidget *parent = nullptr); ~PersonListForm(); + void keyPressEvent(QKeyEvent * event); + private slots: void on_btnRegist_clicked(); @@ -26,6 +28,18 @@ void on_btnBack_clicked(); + void on_selectDept_currentIndexChanged(int index); + + void on_btnFirst_clicked(); + + void on_btnLast_clicked(); + + void on_btnPre_clicked(); + + void on_btnNext_clicked(); + + void btnDeleClicked(); + private: Ui::PersonListForm *ui; QStandardItemModel * itemModel; @@ -33,8 +47,12 @@ int tableRowCount = 8; int tableColCount = 5; + int currentPage = 0; + int totalPage = 0; + void calcTotalPage(int totalCount); void findPersonList(); + void initPersonTableHeader(); void updatePersonListTable(); signals: diff --git a/PersonListForm.ui b/PersonListForm.ui index 909cbf2..5bc81f5 100644 --- a/PersonListForm.ui +++ b/PersonListForm.ui @@ -233,7 +233,14 @@ - 1 / 1 + 1 + + + + + + + 条记录 diff --git a/dao/BaseDao.h b/dao/BaseDao.h index aa67f80..1ea0c93 100644 --- a/dao/BaseDao.h +++ b/dao/BaseDao.h @@ -1,4 +1,4 @@ -#ifndef BASEDAO_H +#ifndef BASEDAO_H #define BASEDAO_H #include @@ -21,8 +21,8 @@ virtual QVector findRecordsByProperty(QString properName, QVariant properValue) = 0; virtual QString save(QVariantMap object) = 0; - virtual bool edit(QVariantMap newObject, qulonglong id) = 0; - virtual bool dele(qulonglong id) = 0; + virtual bool edit(QVariantMap newObject, QString id) = 0; + virtual bool dele(QString id) = 0; private: diff --git a/dao/FaceDataDao.cpp b/dao/FaceDataDao.cpp index d668b0a..642f3fb 100644 --- a/dao/FaceDataDao.cpp +++ b/dao/FaceDataDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataDao.h" +#include "FaceDataDao.h" FaceDataDao::FaceDataDao(QObject *parent) : BaseDao(parent) { @@ -87,12 +87,12 @@ } } -bool FaceDataDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool FaceDataDao::dele(qulonglong id) +bool FaceDataDao::dele(QString id) { return false; } diff --git a/dao/FaceDataDao.h b/dao/FaceDataDao.h index 2db4a3d..87fce40 100644 --- a/dao/FaceDataDao.h +++ b/dao/FaceDataDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATADAO_H +#ifndef FACEDATADAO_H #define FACEDATADAO_H #include @@ -16,8 +16,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/CasicBioRecWin.cpp b/CasicBioRecWin.cpp index 562f7ca..81d4615 100644 --- a/CasicBioRecWin.cpp +++ b/CasicBioRecWin.cpp @@ -9,8 +9,10 @@ { ui->setupUi(this); + // 程序启动时初始化缓存的数据 this->initCacheData(); + // 设置窗口透明和大小、位置 this->setWindowFlags(Qt::FramelessWindowHint); this->move(0, 0); this->resize(SettingConfig::getInstance().WINDOW_WIDTH, @@ -19,8 +21,10 @@ // 通过调色板的颜色来设置窗口的统一背景色 qApp->setPalette(QPalette(QColor(SettingConfig::getInstance().WINDOW_BACKGROUND_COLOR))); + // 初始化各个form界面并绑定切换响应函数 this->initFormsPtr(); + // 打印日志 LOG(INFO) << QString("应用程序启动成功[Application Startup Success]").toStdString(); } diff --git a/PersonListForm.cpp b/PersonListForm.cpp index 77fc565..e479626 100644 --- a/PersonListForm.cpp +++ b/PersonListForm.cpp @@ -21,26 +21,128 @@ ui->vsTableTop->changeSize(0, 20); ui->vsContentBottom->changeSize(0, 40); - itemModel = new QStandardItemModel(this); + // 初始化空的人员列表表格 + initPersonTableHeader(); + // 初始化部门下拉列表框 + SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); +} + +PersonListForm::~PersonListForm() +{ + delete ui; +} + +void PersonListForm::keyPressEvent(QKeyEvent * event) +{ + switch (event->key()) { + case Qt::Key_Return: // 小键盘的Enter键 + case Qt::Key_Enter: // Enter键 + currentPage = 0; + this->findPersonList(); + break; + + default: + QWidget::keyPressEvent(event); + } +} + +void PersonListForm::calcTotalPage(int totalCount) +{ + double temp = (totalCount * 1.0) / (tableRowCount * 1.0); + totalPage = ceil(temp); +} + +void PersonListForm::findPersonList() +{ + SysPersonDao personDao; + + // 获取查询条件 + QString name = ui->inputName->text(); + QString dept = ui->selectDept->currentData().toString(); + + // 计算分页查询的偏移量 + qint16 offset = currentPage * tableRowCount; + + // 查询总条数并计算总页数 + int totalCount = personDao.findRecordCountByNameAndDept(name, dept); + calcTotalPage(totalCount); + + // 赋值表格内容 + QVector perList = personDao.findRecordsByNameAndDept(name, dept, tableRowCount, offset); + + // 有数据且查询结果为空 则重新查询上一页 + if (totalCount > 0 && perList.isEmpty()) + { + // 触发查询上一页的操作 后续操作不再执行 + emit ui->btnPre->clicked(); + return ; + } + + this->personList->clear(); + for (int i = 0; i < perList.size(); i++) { + QVariantMap person = perList.at(i); + this->personList->append(person); + } + + // 更新显示表格 + this->updatePersonListTable(); + + // 更新页码 + if (totalCount == 0) + { + ui->labCurrPage->setText("0"); + } else + { + ui->labCurrPage->setText(QString("%1 / %2 , %3").arg(currentPage + 1).arg(totalPage).arg(totalCount)); + } +} + +void PersonListForm::initPersonTableHeader() +{ + itemModel = new QStandardItemModel(this); personList = new QList(); - SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); - + // 添加表头 QStringList header; header << "员工编号" << "姓名" << "部门 "<< "采集特征" << "操作"; itemModel->setHorizontalHeaderLabels(header); - for (int i = 0; i < tableRowCount; i++) { - QList row; - for ( int j = 0; j < tableColCount; j++) { - itemModel->setItem(i, j, new QStandardItem(QString(""))); - itemModel->item(i, j)->setTextAlignment(Qt::AlignCenter); - } - } + // 设置表头的宽度为固定值 不可调整 + ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); +} + +void PersonListForm::updatePersonListTable() +{ + // 清除表格原有数据 + itemModel->removeRows(0, itemModel->rowCount()); + ui->personListTable->setModel(itemModel); - ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); + // 判断是否有分页 + int max = tableRowCount > personList->size() ? personList->size() : tableRowCount; + for (int i = 0; i < max; i++) { + QList row; + itemModel->setItem(i, 0, new QStandardItem(personList->at(i).find("person_code")->toString())); + itemModel->item(i, 0)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 1, new QStandardItem(personList->at(i).find("name")->toString())); + itemModel->item(i, 1)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 2, new QStandardItem(personList->at(i).find("deptname")->toString())); + itemModel->item(i, 2)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 3, new QStandardItem(QString("iris face"))); + itemModel->item(i, 3)->setTextAlignment(Qt::AlignCenter); + + QPushButton * btnDele = new QPushButton("删除"); + btnDele->setProperty("personId", personList->at(i).find("id")->toString()); + btnDele->setProperty("class", "btnDelete"); + connect(btnDele, &QPushButton::clicked, + this, &PersonListForm::btnDeleClicked); + ui->personListTable->setIndexWidget(itemModel->index(i, 4), btnDele); + } + // 设置每行的高度 for ( int i = 0; i < tableRowCount; i++) { @@ -55,27 +157,6 @@ ui->personListTable->setColumnWidth(4, 150); } -PersonListForm::~PersonListForm() -{ - delete ui; -} - -void PersonListForm::findPersonList() -{ - SysPersonDao personDao; - QVector perList = personDao.findAllRecord(); - this->personList->clear(); - for (int i = 0; i < perList.size(); i++) { - QVariantMap person = perList.at(i); - this->personList->append(person); - } -} - -void PersonListForm::updatePersonListTable() -{ - -} - void PersonListForm::on_btnRegist_clicked() { emit switchToRegistForm("0"); @@ -90,3 +171,56 @@ { emit backToHomePage(); } + +void PersonListForm::on_selectDept_currentIndexChanged(int index) +{ + currentPage = 0; + this->findPersonList(); +} + +void PersonListForm::on_btnFirst_clicked() +{ + // 第一页 + currentPage = 0; + findPersonList(); +} + +void PersonListForm::on_btnLast_clicked() +{ + // 最后一页 + currentPage = totalPage - 1; + findPersonList(); +} + +void PersonListForm::on_btnPre_clicked() +{ + // 上一页 + if (currentPage > 0) + { + currentPage = currentPage - 1; + } + findPersonList(); +} + +void PersonListForm::on_btnNext_clicked() +{ + // 下一页 + if (currentPage < totalPage - 1) + { + currentPage++; + } + findPersonList(); +} + +void PersonListForm::btnDeleClicked() +{ + // 获取发送者的信息 + QPushButton * senderObj = (QPushButton *) sender(); + QString personId = senderObj->property("personId").toString(); + SysPersonDao personDao; + bool succ = personDao.dele(personId); + if (succ == 1) + { + findPersonList(); + } +} diff --git a/PersonListForm.h b/PersonListForm.h index 236bc53..cce03a3 100644 --- a/PersonListForm.h +++ b/PersonListForm.h @@ -19,6 +19,8 @@ explicit PersonListForm(QWidget *parent = nullptr); ~PersonListForm(); + void keyPressEvent(QKeyEvent * event); + private slots: void on_btnRegist_clicked(); @@ -26,6 +28,18 @@ void on_btnBack_clicked(); + void on_selectDept_currentIndexChanged(int index); + + void on_btnFirst_clicked(); + + void on_btnLast_clicked(); + + void on_btnPre_clicked(); + + void on_btnNext_clicked(); + + void btnDeleClicked(); + private: Ui::PersonListForm *ui; QStandardItemModel * itemModel; @@ -33,8 +47,12 @@ int tableRowCount = 8; int tableColCount = 5; + int currentPage = 0; + int totalPage = 0; + void calcTotalPage(int totalCount); void findPersonList(); + void initPersonTableHeader(); void updatePersonListTable(); signals: diff --git a/PersonListForm.ui b/PersonListForm.ui index 909cbf2..5bc81f5 100644 --- a/PersonListForm.ui +++ b/PersonListForm.ui @@ -233,7 +233,14 @@ - 1 / 1 + 1 + + + + + + + 条记录 diff --git a/dao/BaseDao.h b/dao/BaseDao.h index aa67f80..1ea0c93 100644 --- a/dao/BaseDao.h +++ b/dao/BaseDao.h @@ -1,4 +1,4 @@ -#ifndef BASEDAO_H +#ifndef BASEDAO_H #define BASEDAO_H #include @@ -21,8 +21,8 @@ virtual QVector findRecordsByProperty(QString properName, QVariant properValue) = 0; virtual QString save(QVariantMap object) = 0; - virtual bool edit(QVariantMap newObject, qulonglong id) = 0; - virtual bool dele(qulonglong id) = 0; + virtual bool edit(QVariantMap newObject, QString id) = 0; + virtual bool dele(QString id) = 0; private: diff --git a/dao/FaceDataDao.cpp b/dao/FaceDataDao.cpp index d668b0a..642f3fb 100644 --- a/dao/FaceDataDao.cpp +++ b/dao/FaceDataDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataDao.h" +#include "FaceDataDao.h" FaceDataDao::FaceDataDao(QObject *parent) : BaseDao(parent) { @@ -87,12 +87,12 @@ } } -bool FaceDataDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool FaceDataDao::dele(qulonglong id) +bool FaceDataDao::dele(QString id) { return false; } diff --git a/dao/FaceDataDao.h b/dao/FaceDataDao.h index 2db4a3d..87fce40 100644 --- a/dao/FaceDataDao.h +++ b/dao/FaceDataDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATADAO_H +#ifndef FACEDATADAO_H #define FACEDATADAO_H #include @@ -16,8 +16,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/FaceDataImgDao.cpp b/dao/FaceDataImgDao.cpp index c4e96f8..ce8a72a 100644 --- a/dao/FaceDataImgDao.cpp +++ b/dao/FaceDataImgDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataImgDao.h" +#include "FaceDataImgDao.h" FaceDataImgDao::FaceDataImgDao(QObject *parent) : BaseDao(parent) { @@ -171,7 +171,7 @@ } } -bool FaceDataImgDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataImgDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -196,7 +196,7 @@ return success; } -bool FaceDataImgDao::dele(qulonglong id) +bool FaceDataImgDao::dele(QString id) { return false; } diff --git a/CasicBioRecWin.cpp b/CasicBioRecWin.cpp index 562f7ca..81d4615 100644 --- a/CasicBioRecWin.cpp +++ b/CasicBioRecWin.cpp @@ -9,8 +9,10 @@ { ui->setupUi(this); + // 程序启动时初始化缓存的数据 this->initCacheData(); + // 设置窗口透明和大小、位置 this->setWindowFlags(Qt::FramelessWindowHint); this->move(0, 0); this->resize(SettingConfig::getInstance().WINDOW_WIDTH, @@ -19,8 +21,10 @@ // 通过调色板的颜色来设置窗口的统一背景色 qApp->setPalette(QPalette(QColor(SettingConfig::getInstance().WINDOW_BACKGROUND_COLOR))); + // 初始化各个form界面并绑定切换响应函数 this->initFormsPtr(); + // 打印日志 LOG(INFO) << QString("应用程序启动成功[Application Startup Success]").toStdString(); } diff --git a/PersonListForm.cpp b/PersonListForm.cpp index 77fc565..e479626 100644 --- a/PersonListForm.cpp +++ b/PersonListForm.cpp @@ -21,26 +21,128 @@ ui->vsTableTop->changeSize(0, 20); ui->vsContentBottom->changeSize(0, 40); - itemModel = new QStandardItemModel(this); + // 初始化空的人员列表表格 + initPersonTableHeader(); + // 初始化部门下拉列表框 + SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); +} + +PersonListForm::~PersonListForm() +{ + delete ui; +} + +void PersonListForm::keyPressEvent(QKeyEvent * event) +{ + switch (event->key()) { + case Qt::Key_Return: // 小键盘的Enter键 + case Qt::Key_Enter: // Enter键 + currentPage = 0; + this->findPersonList(); + break; + + default: + QWidget::keyPressEvent(event); + } +} + +void PersonListForm::calcTotalPage(int totalCount) +{ + double temp = (totalCount * 1.0) / (tableRowCount * 1.0); + totalPage = ceil(temp); +} + +void PersonListForm::findPersonList() +{ + SysPersonDao personDao; + + // 获取查询条件 + QString name = ui->inputName->text(); + QString dept = ui->selectDept->currentData().toString(); + + // 计算分页查询的偏移量 + qint16 offset = currentPage * tableRowCount; + + // 查询总条数并计算总页数 + int totalCount = personDao.findRecordCountByNameAndDept(name, dept); + calcTotalPage(totalCount); + + // 赋值表格内容 + QVector perList = personDao.findRecordsByNameAndDept(name, dept, tableRowCount, offset); + + // 有数据且查询结果为空 则重新查询上一页 + if (totalCount > 0 && perList.isEmpty()) + { + // 触发查询上一页的操作 后续操作不再执行 + emit ui->btnPre->clicked(); + return ; + } + + this->personList->clear(); + for (int i = 0; i < perList.size(); i++) { + QVariantMap person = perList.at(i); + this->personList->append(person); + } + + // 更新显示表格 + this->updatePersonListTable(); + + // 更新页码 + if (totalCount == 0) + { + ui->labCurrPage->setText("0"); + } else + { + ui->labCurrPage->setText(QString("%1 / %2 , %3").arg(currentPage + 1).arg(totalPage).arg(totalCount)); + } +} + +void PersonListForm::initPersonTableHeader() +{ + itemModel = new QStandardItemModel(this); personList = new QList(); - SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); - + // 添加表头 QStringList header; header << "员工编号" << "姓名" << "部门 "<< "采集特征" << "操作"; itemModel->setHorizontalHeaderLabels(header); - for (int i = 0; i < tableRowCount; i++) { - QList row; - for ( int j = 0; j < tableColCount; j++) { - itemModel->setItem(i, j, new QStandardItem(QString(""))); - itemModel->item(i, j)->setTextAlignment(Qt::AlignCenter); - } - } + // 设置表头的宽度为固定值 不可调整 + ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); +} + +void PersonListForm::updatePersonListTable() +{ + // 清除表格原有数据 + itemModel->removeRows(0, itemModel->rowCount()); + ui->personListTable->setModel(itemModel); - ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); + // 判断是否有分页 + int max = tableRowCount > personList->size() ? personList->size() : tableRowCount; + for (int i = 0; i < max; i++) { + QList row; + itemModel->setItem(i, 0, new QStandardItem(personList->at(i).find("person_code")->toString())); + itemModel->item(i, 0)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 1, new QStandardItem(personList->at(i).find("name")->toString())); + itemModel->item(i, 1)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 2, new QStandardItem(personList->at(i).find("deptname")->toString())); + itemModel->item(i, 2)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 3, new QStandardItem(QString("iris face"))); + itemModel->item(i, 3)->setTextAlignment(Qt::AlignCenter); + + QPushButton * btnDele = new QPushButton("删除"); + btnDele->setProperty("personId", personList->at(i).find("id")->toString()); + btnDele->setProperty("class", "btnDelete"); + connect(btnDele, &QPushButton::clicked, + this, &PersonListForm::btnDeleClicked); + ui->personListTable->setIndexWidget(itemModel->index(i, 4), btnDele); + } + // 设置每行的高度 for ( int i = 0; i < tableRowCount; i++) { @@ -55,27 +157,6 @@ ui->personListTable->setColumnWidth(4, 150); } -PersonListForm::~PersonListForm() -{ - delete ui; -} - -void PersonListForm::findPersonList() -{ - SysPersonDao personDao; - QVector perList = personDao.findAllRecord(); - this->personList->clear(); - for (int i = 0; i < perList.size(); i++) { - QVariantMap person = perList.at(i); - this->personList->append(person); - } -} - -void PersonListForm::updatePersonListTable() -{ - -} - void PersonListForm::on_btnRegist_clicked() { emit switchToRegistForm("0"); @@ -90,3 +171,56 @@ { emit backToHomePage(); } + +void PersonListForm::on_selectDept_currentIndexChanged(int index) +{ + currentPage = 0; + this->findPersonList(); +} + +void PersonListForm::on_btnFirst_clicked() +{ + // 第一页 + currentPage = 0; + findPersonList(); +} + +void PersonListForm::on_btnLast_clicked() +{ + // 最后一页 + currentPage = totalPage - 1; + findPersonList(); +} + +void PersonListForm::on_btnPre_clicked() +{ + // 上一页 + if (currentPage > 0) + { + currentPage = currentPage - 1; + } + findPersonList(); +} + +void PersonListForm::on_btnNext_clicked() +{ + // 下一页 + if (currentPage < totalPage - 1) + { + currentPage++; + } + findPersonList(); +} + +void PersonListForm::btnDeleClicked() +{ + // 获取发送者的信息 + QPushButton * senderObj = (QPushButton *) sender(); + QString personId = senderObj->property("personId").toString(); + SysPersonDao personDao; + bool succ = personDao.dele(personId); + if (succ == 1) + { + findPersonList(); + } +} diff --git a/PersonListForm.h b/PersonListForm.h index 236bc53..cce03a3 100644 --- a/PersonListForm.h +++ b/PersonListForm.h @@ -19,6 +19,8 @@ explicit PersonListForm(QWidget *parent = nullptr); ~PersonListForm(); + void keyPressEvent(QKeyEvent * event); + private slots: void on_btnRegist_clicked(); @@ -26,6 +28,18 @@ void on_btnBack_clicked(); + void on_selectDept_currentIndexChanged(int index); + + void on_btnFirst_clicked(); + + void on_btnLast_clicked(); + + void on_btnPre_clicked(); + + void on_btnNext_clicked(); + + void btnDeleClicked(); + private: Ui::PersonListForm *ui; QStandardItemModel * itemModel; @@ -33,8 +47,12 @@ int tableRowCount = 8; int tableColCount = 5; + int currentPage = 0; + int totalPage = 0; + void calcTotalPage(int totalCount); void findPersonList(); + void initPersonTableHeader(); void updatePersonListTable(); signals: diff --git a/PersonListForm.ui b/PersonListForm.ui index 909cbf2..5bc81f5 100644 --- a/PersonListForm.ui +++ b/PersonListForm.ui @@ -233,7 +233,14 @@ - 1 / 1 + 1 + + + + + + + 条记录 diff --git a/dao/BaseDao.h b/dao/BaseDao.h index aa67f80..1ea0c93 100644 --- a/dao/BaseDao.h +++ b/dao/BaseDao.h @@ -1,4 +1,4 @@ -#ifndef BASEDAO_H +#ifndef BASEDAO_H #define BASEDAO_H #include @@ -21,8 +21,8 @@ virtual QVector findRecordsByProperty(QString properName, QVariant properValue) = 0; virtual QString save(QVariantMap object) = 0; - virtual bool edit(QVariantMap newObject, qulonglong id) = 0; - virtual bool dele(qulonglong id) = 0; + virtual bool edit(QVariantMap newObject, QString id) = 0; + virtual bool dele(QString id) = 0; private: diff --git a/dao/FaceDataDao.cpp b/dao/FaceDataDao.cpp index d668b0a..642f3fb 100644 --- a/dao/FaceDataDao.cpp +++ b/dao/FaceDataDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataDao.h" +#include "FaceDataDao.h" FaceDataDao::FaceDataDao(QObject *parent) : BaseDao(parent) { @@ -87,12 +87,12 @@ } } -bool FaceDataDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool FaceDataDao::dele(qulonglong id) +bool FaceDataDao::dele(QString id) { return false; } diff --git a/dao/FaceDataDao.h b/dao/FaceDataDao.h index 2db4a3d..87fce40 100644 --- a/dao/FaceDataDao.h +++ b/dao/FaceDataDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATADAO_H +#ifndef FACEDATADAO_H #define FACEDATADAO_H #include @@ -16,8 +16,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/FaceDataImgDao.cpp b/dao/FaceDataImgDao.cpp index c4e96f8..ce8a72a 100644 --- a/dao/FaceDataImgDao.cpp +++ b/dao/FaceDataImgDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataImgDao.h" +#include "FaceDataImgDao.h" FaceDataImgDao::FaceDataImgDao(QObject *parent) : BaseDao(parent) { @@ -171,7 +171,7 @@ } } -bool FaceDataImgDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataImgDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -196,7 +196,7 @@ return success; } -bool FaceDataImgDao::dele(qulonglong id) +bool FaceDataImgDao::dele(QString id) { return false; } diff --git a/dao/FaceDataImgDao.h b/dao/FaceDataImgDao.h index d249550..868d73a 100644 --- a/dao/FaceDataImgDao.h +++ b/dao/FaceDataImgDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATAIMGDAO_H +#ifndef FACEDATAIMGDAO_H #define FACEDATAIMGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/CasicBioRecWin.cpp b/CasicBioRecWin.cpp index 562f7ca..81d4615 100644 --- a/CasicBioRecWin.cpp +++ b/CasicBioRecWin.cpp @@ -9,8 +9,10 @@ { ui->setupUi(this); + // 程序启动时初始化缓存的数据 this->initCacheData(); + // 设置窗口透明和大小、位置 this->setWindowFlags(Qt::FramelessWindowHint); this->move(0, 0); this->resize(SettingConfig::getInstance().WINDOW_WIDTH, @@ -19,8 +21,10 @@ // 通过调色板的颜色来设置窗口的统一背景色 qApp->setPalette(QPalette(QColor(SettingConfig::getInstance().WINDOW_BACKGROUND_COLOR))); + // 初始化各个form界面并绑定切换响应函数 this->initFormsPtr(); + // 打印日志 LOG(INFO) << QString("应用程序启动成功[Application Startup Success]").toStdString(); } diff --git a/PersonListForm.cpp b/PersonListForm.cpp index 77fc565..e479626 100644 --- a/PersonListForm.cpp +++ b/PersonListForm.cpp @@ -21,26 +21,128 @@ ui->vsTableTop->changeSize(0, 20); ui->vsContentBottom->changeSize(0, 40); - itemModel = new QStandardItemModel(this); + // 初始化空的人员列表表格 + initPersonTableHeader(); + // 初始化部门下拉列表框 + SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); +} + +PersonListForm::~PersonListForm() +{ + delete ui; +} + +void PersonListForm::keyPressEvent(QKeyEvent * event) +{ + switch (event->key()) { + case Qt::Key_Return: // 小键盘的Enter键 + case Qt::Key_Enter: // Enter键 + currentPage = 0; + this->findPersonList(); + break; + + default: + QWidget::keyPressEvent(event); + } +} + +void PersonListForm::calcTotalPage(int totalCount) +{ + double temp = (totalCount * 1.0) / (tableRowCount * 1.0); + totalPage = ceil(temp); +} + +void PersonListForm::findPersonList() +{ + SysPersonDao personDao; + + // 获取查询条件 + QString name = ui->inputName->text(); + QString dept = ui->selectDept->currentData().toString(); + + // 计算分页查询的偏移量 + qint16 offset = currentPage * tableRowCount; + + // 查询总条数并计算总页数 + int totalCount = personDao.findRecordCountByNameAndDept(name, dept); + calcTotalPage(totalCount); + + // 赋值表格内容 + QVector perList = personDao.findRecordsByNameAndDept(name, dept, tableRowCount, offset); + + // 有数据且查询结果为空 则重新查询上一页 + if (totalCount > 0 && perList.isEmpty()) + { + // 触发查询上一页的操作 后续操作不再执行 + emit ui->btnPre->clicked(); + return ; + } + + this->personList->clear(); + for (int i = 0; i < perList.size(); i++) { + QVariantMap person = perList.at(i); + this->personList->append(person); + } + + // 更新显示表格 + this->updatePersonListTable(); + + // 更新页码 + if (totalCount == 0) + { + ui->labCurrPage->setText("0"); + } else + { + ui->labCurrPage->setText(QString("%1 / %2 , %3").arg(currentPage + 1).arg(totalPage).arg(totalCount)); + } +} + +void PersonListForm::initPersonTableHeader() +{ + itemModel = new QStandardItemModel(this); personList = new QList(); - SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); - + // 添加表头 QStringList header; header << "员工编号" << "姓名" << "部门 "<< "采集特征" << "操作"; itemModel->setHorizontalHeaderLabels(header); - for (int i = 0; i < tableRowCount; i++) { - QList row; - for ( int j = 0; j < tableColCount; j++) { - itemModel->setItem(i, j, new QStandardItem(QString(""))); - itemModel->item(i, j)->setTextAlignment(Qt::AlignCenter); - } - } + // 设置表头的宽度为固定值 不可调整 + ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); +} + +void PersonListForm::updatePersonListTable() +{ + // 清除表格原有数据 + itemModel->removeRows(0, itemModel->rowCount()); + ui->personListTable->setModel(itemModel); - ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); + // 判断是否有分页 + int max = tableRowCount > personList->size() ? personList->size() : tableRowCount; + for (int i = 0; i < max; i++) { + QList row; + itemModel->setItem(i, 0, new QStandardItem(personList->at(i).find("person_code")->toString())); + itemModel->item(i, 0)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 1, new QStandardItem(personList->at(i).find("name")->toString())); + itemModel->item(i, 1)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 2, new QStandardItem(personList->at(i).find("deptname")->toString())); + itemModel->item(i, 2)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 3, new QStandardItem(QString("iris face"))); + itemModel->item(i, 3)->setTextAlignment(Qt::AlignCenter); + + QPushButton * btnDele = new QPushButton("删除"); + btnDele->setProperty("personId", personList->at(i).find("id")->toString()); + btnDele->setProperty("class", "btnDelete"); + connect(btnDele, &QPushButton::clicked, + this, &PersonListForm::btnDeleClicked); + ui->personListTable->setIndexWidget(itemModel->index(i, 4), btnDele); + } + // 设置每行的高度 for ( int i = 0; i < tableRowCount; i++) { @@ -55,27 +157,6 @@ ui->personListTable->setColumnWidth(4, 150); } -PersonListForm::~PersonListForm() -{ - delete ui; -} - -void PersonListForm::findPersonList() -{ - SysPersonDao personDao; - QVector perList = personDao.findAllRecord(); - this->personList->clear(); - for (int i = 0; i < perList.size(); i++) { - QVariantMap person = perList.at(i); - this->personList->append(person); - } -} - -void PersonListForm::updatePersonListTable() -{ - -} - void PersonListForm::on_btnRegist_clicked() { emit switchToRegistForm("0"); @@ -90,3 +171,56 @@ { emit backToHomePage(); } + +void PersonListForm::on_selectDept_currentIndexChanged(int index) +{ + currentPage = 0; + this->findPersonList(); +} + +void PersonListForm::on_btnFirst_clicked() +{ + // 第一页 + currentPage = 0; + findPersonList(); +} + +void PersonListForm::on_btnLast_clicked() +{ + // 最后一页 + currentPage = totalPage - 1; + findPersonList(); +} + +void PersonListForm::on_btnPre_clicked() +{ + // 上一页 + if (currentPage > 0) + { + currentPage = currentPage - 1; + } + findPersonList(); +} + +void PersonListForm::on_btnNext_clicked() +{ + // 下一页 + if (currentPage < totalPage - 1) + { + currentPage++; + } + findPersonList(); +} + +void PersonListForm::btnDeleClicked() +{ + // 获取发送者的信息 + QPushButton * senderObj = (QPushButton *) sender(); + QString personId = senderObj->property("personId").toString(); + SysPersonDao personDao; + bool succ = personDao.dele(personId); + if (succ == 1) + { + findPersonList(); + } +} diff --git a/PersonListForm.h b/PersonListForm.h index 236bc53..cce03a3 100644 --- a/PersonListForm.h +++ b/PersonListForm.h @@ -19,6 +19,8 @@ explicit PersonListForm(QWidget *parent = nullptr); ~PersonListForm(); + void keyPressEvent(QKeyEvent * event); + private slots: void on_btnRegist_clicked(); @@ -26,6 +28,18 @@ void on_btnBack_clicked(); + void on_selectDept_currentIndexChanged(int index); + + void on_btnFirst_clicked(); + + void on_btnLast_clicked(); + + void on_btnPre_clicked(); + + void on_btnNext_clicked(); + + void btnDeleClicked(); + private: Ui::PersonListForm *ui; QStandardItemModel * itemModel; @@ -33,8 +47,12 @@ int tableRowCount = 8; int tableColCount = 5; + int currentPage = 0; + int totalPage = 0; + void calcTotalPage(int totalCount); void findPersonList(); + void initPersonTableHeader(); void updatePersonListTable(); signals: diff --git a/PersonListForm.ui b/PersonListForm.ui index 909cbf2..5bc81f5 100644 --- a/PersonListForm.ui +++ b/PersonListForm.ui @@ -233,7 +233,14 @@ - 1 / 1 + 1 + + + + + + + 条记录 diff --git a/dao/BaseDao.h b/dao/BaseDao.h index aa67f80..1ea0c93 100644 --- a/dao/BaseDao.h +++ b/dao/BaseDao.h @@ -1,4 +1,4 @@ -#ifndef BASEDAO_H +#ifndef BASEDAO_H #define BASEDAO_H #include @@ -21,8 +21,8 @@ virtual QVector findRecordsByProperty(QString properName, QVariant properValue) = 0; virtual QString save(QVariantMap object) = 0; - virtual bool edit(QVariantMap newObject, qulonglong id) = 0; - virtual bool dele(qulonglong id) = 0; + virtual bool edit(QVariantMap newObject, QString id) = 0; + virtual bool dele(QString id) = 0; private: diff --git a/dao/FaceDataDao.cpp b/dao/FaceDataDao.cpp index d668b0a..642f3fb 100644 --- a/dao/FaceDataDao.cpp +++ b/dao/FaceDataDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataDao.h" +#include "FaceDataDao.h" FaceDataDao::FaceDataDao(QObject *parent) : BaseDao(parent) { @@ -87,12 +87,12 @@ } } -bool FaceDataDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool FaceDataDao::dele(qulonglong id) +bool FaceDataDao::dele(QString id) { return false; } diff --git a/dao/FaceDataDao.h b/dao/FaceDataDao.h index 2db4a3d..87fce40 100644 --- a/dao/FaceDataDao.h +++ b/dao/FaceDataDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATADAO_H +#ifndef FACEDATADAO_H #define FACEDATADAO_H #include @@ -16,8 +16,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/FaceDataImgDao.cpp b/dao/FaceDataImgDao.cpp index c4e96f8..ce8a72a 100644 --- a/dao/FaceDataImgDao.cpp +++ b/dao/FaceDataImgDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataImgDao.h" +#include "FaceDataImgDao.h" FaceDataImgDao::FaceDataImgDao(QObject *parent) : BaseDao(parent) { @@ -171,7 +171,7 @@ } } -bool FaceDataImgDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataImgDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -196,7 +196,7 @@ return success; } -bool FaceDataImgDao::dele(qulonglong id) +bool FaceDataImgDao::dele(QString id) { return false; } diff --git a/dao/FaceDataImgDao.h b/dao/FaceDataImgDao.h index d249550..868d73a 100644 --- a/dao/FaceDataImgDao.h +++ b/dao/FaceDataImgDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATAIMGDAO_H +#ifndef FACEDATAIMGDAO_H #define FACEDATAIMGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/IrisDataDao.cpp b/dao/IrisDataDao.cpp index 26a68e2..5f1b047 100644 --- a/dao/IrisDataDao.cpp +++ b/dao/IrisDataDao.cpp @@ -1,4 +1,4 @@ -#include "IrisDataDao.h" +#include "IrisDataDao.h" IrisDataDao::IrisDataDao(QObject *parent) : BaseDao(parent) { @@ -95,13 +95,13 @@ } } -bool IrisDataDao::edit(QVariantMap newObject, qulonglong id) +bool IrisDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool IrisDataDao::dele(qulonglong id) +bool IrisDataDao::dele(QString id) { return false; } diff --git a/CasicBioRecWin.cpp b/CasicBioRecWin.cpp index 562f7ca..81d4615 100644 --- a/CasicBioRecWin.cpp +++ b/CasicBioRecWin.cpp @@ -9,8 +9,10 @@ { ui->setupUi(this); + // 程序启动时初始化缓存的数据 this->initCacheData(); + // 设置窗口透明和大小、位置 this->setWindowFlags(Qt::FramelessWindowHint); this->move(0, 0); this->resize(SettingConfig::getInstance().WINDOW_WIDTH, @@ -19,8 +21,10 @@ // 通过调色板的颜色来设置窗口的统一背景色 qApp->setPalette(QPalette(QColor(SettingConfig::getInstance().WINDOW_BACKGROUND_COLOR))); + // 初始化各个form界面并绑定切换响应函数 this->initFormsPtr(); + // 打印日志 LOG(INFO) << QString("应用程序启动成功[Application Startup Success]").toStdString(); } diff --git a/PersonListForm.cpp b/PersonListForm.cpp index 77fc565..e479626 100644 --- a/PersonListForm.cpp +++ b/PersonListForm.cpp @@ -21,26 +21,128 @@ ui->vsTableTop->changeSize(0, 20); ui->vsContentBottom->changeSize(0, 40); - itemModel = new QStandardItemModel(this); + // 初始化空的人员列表表格 + initPersonTableHeader(); + // 初始化部门下拉列表框 + SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); +} + +PersonListForm::~PersonListForm() +{ + delete ui; +} + +void PersonListForm::keyPressEvent(QKeyEvent * event) +{ + switch (event->key()) { + case Qt::Key_Return: // 小键盘的Enter键 + case Qt::Key_Enter: // Enter键 + currentPage = 0; + this->findPersonList(); + break; + + default: + QWidget::keyPressEvent(event); + } +} + +void PersonListForm::calcTotalPage(int totalCount) +{ + double temp = (totalCount * 1.0) / (tableRowCount * 1.0); + totalPage = ceil(temp); +} + +void PersonListForm::findPersonList() +{ + SysPersonDao personDao; + + // 获取查询条件 + QString name = ui->inputName->text(); + QString dept = ui->selectDept->currentData().toString(); + + // 计算分页查询的偏移量 + qint16 offset = currentPage * tableRowCount; + + // 查询总条数并计算总页数 + int totalCount = personDao.findRecordCountByNameAndDept(name, dept); + calcTotalPage(totalCount); + + // 赋值表格内容 + QVector perList = personDao.findRecordsByNameAndDept(name, dept, tableRowCount, offset); + + // 有数据且查询结果为空 则重新查询上一页 + if (totalCount > 0 && perList.isEmpty()) + { + // 触发查询上一页的操作 后续操作不再执行 + emit ui->btnPre->clicked(); + return ; + } + + this->personList->clear(); + for (int i = 0; i < perList.size(); i++) { + QVariantMap person = perList.at(i); + this->personList->append(person); + } + + // 更新显示表格 + this->updatePersonListTable(); + + // 更新页码 + if (totalCount == 0) + { + ui->labCurrPage->setText("0"); + } else + { + ui->labCurrPage->setText(QString("%1 / %2 , %3").arg(currentPage + 1).arg(totalPage).arg(totalCount)); + } +} + +void PersonListForm::initPersonTableHeader() +{ + itemModel = new QStandardItemModel(this); personList = new QList(); - SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); - + // 添加表头 QStringList header; header << "员工编号" << "姓名" << "部门 "<< "采集特征" << "操作"; itemModel->setHorizontalHeaderLabels(header); - for (int i = 0; i < tableRowCount; i++) { - QList row; - for ( int j = 0; j < tableColCount; j++) { - itemModel->setItem(i, j, new QStandardItem(QString(""))); - itemModel->item(i, j)->setTextAlignment(Qt::AlignCenter); - } - } + // 设置表头的宽度为固定值 不可调整 + ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); +} + +void PersonListForm::updatePersonListTable() +{ + // 清除表格原有数据 + itemModel->removeRows(0, itemModel->rowCount()); + ui->personListTable->setModel(itemModel); - ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); + // 判断是否有分页 + int max = tableRowCount > personList->size() ? personList->size() : tableRowCount; + for (int i = 0; i < max; i++) { + QList row; + itemModel->setItem(i, 0, new QStandardItem(personList->at(i).find("person_code")->toString())); + itemModel->item(i, 0)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 1, new QStandardItem(personList->at(i).find("name")->toString())); + itemModel->item(i, 1)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 2, new QStandardItem(personList->at(i).find("deptname")->toString())); + itemModel->item(i, 2)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 3, new QStandardItem(QString("iris face"))); + itemModel->item(i, 3)->setTextAlignment(Qt::AlignCenter); + + QPushButton * btnDele = new QPushButton("删除"); + btnDele->setProperty("personId", personList->at(i).find("id")->toString()); + btnDele->setProperty("class", "btnDelete"); + connect(btnDele, &QPushButton::clicked, + this, &PersonListForm::btnDeleClicked); + ui->personListTable->setIndexWidget(itemModel->index(i, 4), btnDele); + } + // 设置每行的高度 for ( int i = 0; i < tableRowCount; i++) { @@ -55,27 +157,6 @@ ui->personListTable->setColumnWidth(4, 150); } -PersonListForm::~PersonListForm() -{ - delete ui; -} - -void PersonListForm::findPersonList() -{ - SysPersonDao personDao; - QVector perList = personDao.findAllRecord(); - this->personList->clear(); - for (int i = 0; i < perList.size(); i++) { - QVariantMap person = perList.at(i); - this->personList->append(person); - } -} - -void PersonListForm::updatePersonListTable() -{ - -} - void PersonListForm::on_btnRegist_clicked() { emit switchToRegistForm("0"); @@ -90,3 +171,56 @@ { emit backToHomePage(); } + +void PersonListForm::on_selectDept_currentIndexChanged(int index) +{ + currentPage = 0; + this->findPersonList(); +} + +void PersonListForm::on_btnFirst_clicked() +{ + // 第一页 + currentPage = 0; + findPersonList(); +} + +void PersonListForm::on_btnLast_clicked() +{ + // 最后一页 + currentPage = totalPage - 1; + findPersonList(); +} + +void PersonListForm::on_btnPre_clicked() +{ + // 上一页 + if (currentPage > 0) + { + currentPage = currentPage - 1; + } + findPersonList(); +} + +void PersonListForm::on_btnNext_clicked() +{ + // 下一页 + if (currentPage < totalPage - 1) + { + currentPage++; + } + findPersonList(); +} + +void PersonListForm::btnDeleClicked() +{ + // 获取发送者的信息 + QPushButton * senderObj = (QPushButton *) sender(); + QString personId = senderObj->property("personId").toString(); + SysPersonDao personDao; + bool succ = personDao.dele(personId); + if (succ == 1) + { + findPersonList(); + } +} diff --git a/PersonListForm.h b/PersonListForm.h index 236bc53..cce03a3 100644 --- a/PersonListForm.h +++ b/PersonListForm.h @@ -19,6 +19,8 @@ explicit PersonListForm(QWidget *parent = nullptr); ~PersonListForm(); + void keyPressEvent(QKeyEvent * event); + private slots: void on_btnRegist_clicked(); @@ -26,6 +28,18 @@ void on_btnBack_clicked(); + void on_selectDept_currentIndexChanged(int index); + + void on_btnFirst_clicked(); + + void on_btnLast_clicked(); + + void on_btnPre_clicked(); + + void on_btnNext_clicked(); + + void btnDeleClicked(); + private: Ui::PersonListForm *ui; QStandardItemModel * itemModel; @@ -33,8 +47,12 @@ int tableRowCount = 8; int tableColCount = 5; + int currentPage = 0; + int totalPage = 0; + void calcTotalPage(int totalCount); void findPersonList(); + void initPersonTableHeader(); void updatePersonListTable(); signals: diff --git a/PersonListForm.ui b/PersonListForm.ui index 909cbf2..5bc81f5 100644 --- a/PersonListForm.ui +++ b/PersonListForm.ui @@ -233,7 +233,14 @@ - 1 / 1 + 1 + + + + + + + 条记录 diff --git a/dao/BaseDao.h b/dao/BaseDao.h index aa67f80..1ea0c93 100644 --- a/dao/BaseDao.h +++ b/dao/BaseDao.h @@ -1,4 +1,4 @@ -#ifndef BASEDAO_H +#ifndef BASEDAO_H #define BASEDAO_H #include @@ -21,8 +21,8 @@ virtual QVector findRecordsByProperty(QString properName, QVariant properValue) = 0; virtual QString save(QVariantMap object) = 0; - virtual bool edit(QVariantMap newObject, qulonglong id) = 0; - virtual bool dele(qulonglong id) = 0; + virtual bool edit(QVariantMap newObject, QString id) = 0; + virtual bool dele(QString id) = 0; private: diff --git a/dao/FaceDataDao.cpp b/dao/FaceDataDao.cpp index d668b0a..642f3fb 100644 --- a/dao/FaceDataDao.cpp +++ b/dao/FaceDataDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataDao.h" +#include "FaceDataDao.h" FaceDataDao::FaceDataDao(QObject *parent) : BaseDao(parent) { @@ -87,12 +87,12 @@ } } -bool FaceDataDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool FaceDataDao::dele(qulonglong id) +bool FaceDataDao::dele(QString id) { return false; } diff --git a/dao/FaceDataDao.h b/dao/FaceDataDao.h index 2db4a3d..87fce40 100644 --- a/dao/FaceDataDao.h +++ b/dao/FaceDataDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATADAO_H +#ifndef FACEDATADAO_H #define FACEDATADAO_H #include @@ -16,8 +16,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/FaceDataImgDao.cpp b/dao/FaceDataImgDao.cpp index c4e96f8..ce8a72a 100644 --- a/dao/FaceDataImgDao.cpp +++ b/dao/FaceDataImgDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataImgDao.h" +#include "FaceDataImgDao.h" FaceDataImgDao::FaceDataImgDao(QObject *parent) : BaseDao(parent) { @@ -171,7 +171,7 @@ } } -bool FaceDataImgDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataImgDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -196,7 +196,7 @@ return success; } -bool FaceDataImgDao::dele(qulonglong id) +bool FaceDataImgDao::dele(QString id) { return false; } diff --git a/dao/FaceDataImgDao.h b/dao/FaceDataImgDao.h index d249550..868d73a 100644 --- a/dao/FaceDataImgDao.h +++ b/dao/FaceDataImgDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATAIMGDAO_H +#ifndef FACEDATAIMGDAO_H #define FACEDATAIMGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/IrisDataDao.cpp b/dao/IrisDataDao.cpp index 26a68e2..5f1b047 100644 --- a/dao/IrisDataDao.cpp +++ b/dao/IrisDataDao.cpp @@ -1,4 +1,4 @@ -#include "IrisDataDao.h" +#include "IrisDataDao.h" IrisDataDao::IrisDataDao(QObject *parent) : BaseDao(parent) { @@ -95,13 +95,13 @@ } } -bool IrisDataDao::edit(QVariantMap newObject, qulonglong id) +bool IrisDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool IrisDataDao::dele(qulonglong id) +bool IrisDataDao::dele(QString id) { return false; } diff --git a/dao/IrisDataDao.h b/dao/IrisDataDao.h index 76e6267..1289074 100644 --- a/dao/IrisDataDao.h +++ b/dao/IrisDataDao.h @@ -1,4 +1,4 @@ -#ifndef IRISDATADAO_H +#ifndef IRISDATADAO_H #define IRISDATADAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/CasicBioRecWin.cpp b/CasicBioRecWin.cpp index 562f7ca..81d4615 100644 --- a/CasicBioRecWin.cpp +++ b/CasicBioRecWin.cpp @@ -9,8 +9,10 @@ { ui->setupUi(this); + // 程序启动时初始化缓存的数据 this->initCacheData(); + // 设置窗口透明和大小、位置 this->setWindowFlags(Qt::FramelessWindowHint); this->move(0, 0); this->resize(SettingConfig::getInstance().WINDOW_WIDTH, @@ -19,8 +21,10 @@ // 通过调色板的颜色来设置窗口的统一背景色 qApp->setPalette(QPalette(QColor(SettingConfig::getInstance().WINDOW_BACKGROUND_COLOR))); + // 初始化各个form界面并绑定切换响应函数 this->initFormsPtr(); + // 打印日志 LOG(INFO) << QString("应用程序启动成功[Application Startup Success]").toStdString(); } diff --git a/PersonListForm.cpp b/PersonListForm.cpp index 77fc565..e479626 100644 --- a/PersonListForm.cpp +++ b/PersonListForm.cpp @@ -21,26 +21,128 @@ ui->vsTableTop->changeSize(0, 20); ui->vsContentBottom->changeSize(0, 40); - itemModel = new QStandardItemModel(this); + // 初始化空的人员列表表格 + initPersonTableHeader(); + // 初始化部门下拉列表框 + SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); +} + +PersonListForm::~PersonListForm() +{ + delete ui; +} + +void PersonListForm::keyPressEvent(QKeyEvent * event) +{ + switch (event->key()) { + case Qt::Key_Return: // 小键盘的Enter键 + case Qt::Key_Enter: // Enter键 + currentPage = 0; + this->findPersonList(); + break; + + default: + QWidget::keyPressEvent(event); + } +} + +void PersonListForm::calcTotalPage(int totalCount) +{ + double temp = (totalCount * 1.0) / (tableRowCount * 1.0); + totalPage = ceil(temp); +} + +void PersonListForm::findPersonList() +{ + SysPersonDao personDao; + + // 获取查询条件 + QString name = ui->inputName->text(); + QString dept = ui->selectDept->currentData().toString(); + + // 计算分页查询的偏移量 + qint16 offset = currentPage * tableRowCount; + + // 查询总条数并计算总页数 + int totalCount = personDao.findRecordCountByNameAndDept(name, dept); + calcTotalPage(totalCount); + + // 赋值表格内容 + QVector perList = personDao.findRecordsByNameAndDept(name, dept, tableRowCount, offset); + + // 有数据且查询结果为空 则重新查询上一页 + if (totalCount > 0 && perList.isEmpty()) + { + // 触发查询上一页的操作 后续操作不再执行 + emit ui->btnPre->clicked(); + return ; + } + + this->personList->clear(); + for (int i = 0; i < perList.size(); i++) { + QVariantMap person = perList.at(i); + this->personList->append(person); + } + + // 更新显示表格 + this->updatePersonListTable(); + + // 更新页码 + if (totalCount == 0) + { + ui->labCurrPage->setText("0"); + } else + { + ui->labCurrPage->setText(QString("%1 / %2 , %3").arg(currentPage + 1).arg(totalPage).arg(totalCount)); + } +} + +void PersonListForm::initPersonTableHeader() +{ + itemModel = new QStandardItemModel(this); personList = new QList(); - SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); - + // 添加表头 QStringList header; header << "员工编号" << "姓名" << "部门 "<< "采集特征" << "操作"; itemModel->setHorizontalHeaderLabels(header); - for (int i = 0; i < tableRowCount; i++) { - QList row; - for ( int j = 0; j < tableColCount; j++) { - itemModel->setItem(i, j, new QStandardItem(QString(""))); - itemModel->item(i, j)->setTextAlignment(Qt::AlignCenter); - } - } + // 设置表头的宽度为固定值 不可调整 + ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); +} + +void PersonListForm::updatePersonListTable() +{ + // 清除表格原有数据 + itemModel->removeRows(0, itemModel->rowCount()); + ui->personListTable->setModel(itemModel); - ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); + // 判断是否有分页 + int max = tableRowCount > personList->size() ? personList->size() : tableRowCount; + for (int i = 0; i < max; i++) { + QList row; + itemModel->setItem(i, 0, new QStandardItem(personList->at(i).find("person_code")->toString())); + itemModel->item(i, 0)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 1, new QStandardItem(personList->at(i).find("name")->toString())); + itemModel->item(i, 1)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 2, new QStandardItem(personList->at(i).find("deptname")->toString())); + itemModel->item(i, 2)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 3, new QStandardItem(QString("iris face"))); + itemModel->item(i, 3)->setTextAlignment(Qt::AlignCenter); + + QPushButton * btnDele = new QPushButton("删除"); + btnDele->setProperty("personId", personList->at(i).find("id")->toString()); + btnDele->setProperty("class", "btnDelete"); + connect(btnDele, &QPushButton::clicked, + this, &PersonListForm::btnDeleClicked); + ui->personListTable->setIndexWidget(itemModel->index(i, 4), btnDele); + } + // 设置每行的高度 for ( int i = 0; i < tableRowCount; i++) { @@ -55,27 +157,6 @@ ui->personListTable->setColumnWidth(4, 150); } -PersonListForm::~PersonListForm() -{ - delete ui; -} - -void PersonListForm::findPersonList() -{ - SysPersonDao personDao; - QVector perList = personDao.findAllRecord(); - this->personList->clear(); - for (int i = 0; i < perList.size(); i++) { - QVariantMap person = perList.at(i); - this->personList->append(person); - } -} - -void PersonListForm::updatePersonListTable() -{ - -} - void PersonListForm::on_btnRegist_clicked() { emit switchToRegistForm("0"); @@ -90,3 +171,56 @@ { emit backToHomePage(); } + +void PersonListForm::on_selectDept_currentIndexChanged(int index) +{ + currentPage = 0; + this->findPersonList(); +} + +void PersonListForm::on_btnFirst_clicked() +{ + // 第一页 + currentPage = 0; + findPersonList(); +} + +void PersonListForm::on_btnLast_clicked() +{ + // 最后一页 + currentPage = totalPage - 1; + findPersonList(); +} + +void PersonListForm::on_btnPre_clicked() +{ + // 上一页 + if (currentPage > 0) + { + currentPage = currentPage - 1; + } + findPersonList(); +} + +void PersonListForm::on_btnNext_clicked() +{ + // 下一页 + if (currentPage < totalPage - 1) + { + currentPage++; + } + findPersonList(); +} + +void PersonListForm::btnDeleClicked() +{ + // 获取发送者的信息 + QPushButton * senderObj = (QPushButton *) sender(); + QString personId = senderObj->property("personId").toString(); + SysPersonDao personDao; + bool succ = personDao.dele(personId); + if (succ == 1) + { + findPersonList(); + } +} diff --git a/PersonListForm.h b/PersonListForm.h index 236bc53..cce03a3 100644 --- a/PersonListForm.h +++ b/PersonListForm.h @@ -19,6 +19,8 @@ explicit PersonListForm(QWidget *parent = nullptr); ~PersonListForm(); + void keyPressEvent(QKeyEvent * event); + private slots: void on_btnRegist_clicked(); @@ -26,6 +28,18 @@ void on_btnBack_clicked(); + void on_selectDept_currentIndexChanged(int index); + + void on_btnFirst_clicked(); + + void on_btnLast_clicked(); + + void on_btnPre_clicked(); + + void on_btnNext_clicked(); + + void btnDeleClicked(); + private: Ui::PersonListForm *ui; QStandardItemModel * itemModel; @@ -33,8 +47,12 @@ int tableRowCount = 8; int tableColCount = 5; + int currentPage = 0; + int totalPage = 0; + void calcTotalPage(int totalCount); void findPersonList(); + void initPersonTableHeader(); void updatePersonListTable(); signals: diff --git a/PersonListForm.ui b/PersonListForm.ui index 909cbf2..5bc81f5 100644 --- a/PersonListForm.ui +++ b/PersonListForm.ui @@ -233,7 +233,14 @@ - 1 / 1 + 1 + + + + + + + 条记录 diff --git a/dao/BaseDao.h b/dao/BaseDao.h index aa67f80..1ea0c93 100644 --- a/dao/BaseDao.h +++ b/dao/BaseDao.h @@ -1,4 +1,4 @@ -#ifndef BASEDAO_H +#ifndef BASEDAO_H #define BASEDAO_H #include @@ -21,8 +21,8 @@ virtual QVector findRecordsByProperty(QString properName, QVariant properValue) = 0; virtual QString save(QVariantMap object) = 0; - virtual bool edit(QVariantMap newObject, qulonglong id) = 0; - virtual bool dele(qulonglong id) = 0; + virtual bool edit(QVariantMap newObject, QString id) = 0; + virtual bool dele(QString id) = 0; private: diff --git a/dao/FaceDataDao.cpp b/dao/FaceDataDao.cpp index d668b0a..642f3fb 100644 --- a/dao/FaceDataDao.cpp +++ b/dao/FaceDataDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataDao.h" +#include "FaceDataDao.h" FaceDataDao::FaceDataDao(QObject *parent) : BaseDao(parent) { @@ -87,12 +87,12 @@ } } -bool FaceDataDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool FaceDataDao::dele(qulonglong id) +bool FaceDataDao::dele(QString id) { return false; } diff --git a/dao/FaceDataDao.h b/dao/FaceDataDao.h index 2db4a3d..87fce40 100644 --- a/dao/FaceDataDao.h +++ b/dao/FaceDataDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATADAO_H +#ifndef FACEDATADAO_H #define FACEDATADAO_H #include @@ -16,8 +16,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/FaceDataImgDao.cpp b/dao/FaceDataImgDao.cpp index c4e96f8..ce8a72a 100644 --- a/dao/FaceDataImgDao.cpp +++ b/dao/FaceDataImgDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataImgDao.h" +#include "FaceDataImgDao.h" FaceDataImgDao::FaceDataImgDao(QObject *parent) : BaseDao(parent) { @@ -171,7 +171,7 @@ } } -bool FaceDataImgDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataImgDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -196,7 +196,7 @@ return success; } -bool FaceDataImgDao::dele(qulonglong id) +bool FaceDataImgDao::dele(QString id) { return false; } diff --git a/dao/FaceDataImgDao.h b/dao/FaceDataImgDao.h index d249550..868d73a 100644 --- a/dao/FaceDataImgDao.h +++ b/dao/FaceDataImgDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATAIMGDAO_H +#ifndef FACEDATAIMGDAO_H #define FACEDATAIMGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/IrisDataDao.cpp b/dao/IrisDataDao.cpp index 26a68e2..5f1b047 100644 --- a/dao/IrisDataDao.cpp +++ b/dao/IrisDataDao.cpp @@ -1,4 +1,4 @@ -#include "IrisDataDao.h" +#include "IrisDataDao.h" IrisDataDao::IrisDataDao(QObject *parent) : BaseDao(parent) { @@ -95,13 +95,13 @@ } } -bool IrisDataDao::edit(QVariantMap newObject, qulonglong id) +bool IrisDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool IrisDataDao::dele(qulonglong id) +bool IrisDataDao::dele(QString id) { return false; } diff --git a/dao/IrisDataDao.h b/dao/IrisDataDao.h index 76e6267..1289074 100644 --- a/dao/IrisDataDao.h +++ b/dao/IrisDataDao.h @@ -1,4 +1,4 @@ -#ifndef IRISDATADAO_H +#ifndef IRISDATADAO_H #define IRISDATADAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/IrisDataImgDao.cpp b/dao/IrisDataImgDao.cpp index 691762c..18d4ce6 100644 --- a/dao/IrisDataImgDao.cpp +++ b/dao/IrisDataImgDao.cpp @@ -1,4 +1,4 @@ -#include "IrisDataImgDao.h" +#include "IrisDataImgDao.h" IrisDataImgDao::IrisDataImgDao(QObject *parent) : BaseDao(parent) { @@ -182,7 +182,7 @@ } } -bool IrisDataImgDao::edit(QVariantMap newObject, qulonglong id) +bool IrisDataImgDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -219,7 +219,7 @@ return success; } -bool IrisDataImgDao::dele(qulonglong id) +bool IrisDataImgDao::dele(QString id) { return false; } diff --git a/CasicBioRecWin.cpp b/CasicBioRecWin.cpp index 562f7ca..81d4615 100644 --- a/CasicBioRecWin.cpp +++ b/CasicBioRecWin.cpp @@ -9,8 +9,10 @@ { ui->setupUi(this); + // 程序启动时初始化缓存的数据 this->initCacheData(); + // 设置窗口透明和大小、位置 this->setWindowFlags(Qt::FramelessWindowHint); this->move(0, 0); this->resize(SettingConfig::getInstance().WINDOW_WIDTH, @@ -19,8 +21,10 @@ // 通过调色板的颜色来设置窗口的统一背景色 qApp->setPalette(QPalette(QColor(SettingConfig::getInstance().WINDOW_BACKGROUND_COLOR))); + // 初始化各个form界面并绑定切换响应函数 this->initFormsPtr(); + // 打印日志 LOG(INFO) << QString("应用程序启动成功[Application Startup Success]").toStdString(); } diff --git a/PersonListForm.cpp b/PersonListForm.cpp index 77fc565..e479626 100644 --- a/PersonListForm.cpp +++ b/PersonListForm.cpp @@ -21,26 +21,128 @@ ui->vsTableTop->changeSize(0, 20); ui->vsContentBottom->changeSize(0, 40); - itemModel = new QStandardItemModel(this); + // 初始化空的人员列表表格 + initPersonTableHeader(); + // 初始化部门下拉列表框 + SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); +} + +PersonListForm::~PersonListForm() +{ + delete ui; +} + +void PersonListForm::keyPressEvent(QKeyEvent * event) +{ + switch (event->key()) { + case Qt::Key_Return: // 小键盘的Enter键 + case Qt::Key_Enter: // Enter键 + currentPage = 0; + this->findPersonList(); + break; + + default: + QWidget::keyPressEvent(event); + } +} + +void PersonListForm::calcTotalPage(int totalCount) +{ + double temp = (totalCount * 1.0) / (tableRowCount * 1.0); + totalPage = ceil(temp); +} + +void PersonListForm::findPersonList() +{ + SysPersonDao personDao; + + // 获取查询条件 + QString name = ui->inputName->text(); + QString dept = ui->selectDept->currentData().toString(); + + // 计算分页查询的偏移量 + qint16 offset = currentPage * tableRowCount; + + // 查询总条数并计算总页数 + int totalCount = personDao.findRecordCountByNameAndDept(name, dept); + calcTotalPage(totalCount); + + // 赋值表格内容 + QVector perList = personDao.findRecordsByNameAndDept(name, dept, tableRowCount, offset); + + // 有数据且查询结果为空 则重新查询上一页 + if (totalCount > 0 && perList.isEmpty()) + { + // 触发查询上一页的操作 后续操作不再执行 + emit ui->btnPre->clicked(); + return ; + } + + this->personList->clear(); + for (int i = 0; i < perList.size(); i++) { + QVariantMap person = perList.at(i); + this->personList->append(person); + } + + // 更新显示表格 + this->updatePersonListTable(); + + // 更新页码 + if (totalCount == 0) + { + ui->labCurrPage->setText("0"); + } else + { + ui->labCurrPage->setText(QString("%1 / %2 , %3").arg(currentPage + 1).arg(totalPage).arg(totalCount)); + } +} + +void PersonListForm::initPersonTableHeader() +{ + itemModel = new QStandardItemModel(this); personList = new QList(); - SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); - + // 添加表头 QStringList header; header << "员工编号" << "姓名" << "部门 "<< "采集特征" << "操作"; itemModel->setHorizontalHeaderLabels(header); - for (int i = 0; i < tableRowCount; i++) { - QList row; - for ( int j = 0; j < tableColCount; j++) { - itemModel->setItem(i, j, new QStandardItem(QString(""))); - itemModel->item(i, j)->setTextAlignment(Qt::AlignCenter); - } - } + // 设置表头的宽度为固定值 不可调整 + ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); +} + +void PersonListForm::updatePersonListTable() +{ + // 清除表格原有数据 + itemModel->removeRows(0, itemModel->rowCount()); + ui->personListTable->setModel(itemModel); - ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); + // 判断是否有分页 + int max = tableRowCount > personList->size() ? personList->size() : tableRowCount; + for (int i = 0; i < max; i++) { + QList row; + itemModel->setItem(i, 0, new QStandardItem(personList->at(i).find("person_code")->toString())); + itemModel->item(i, 0)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 1, new QStandardItem(personList->at(i).find("name")->toString())); + itemModel->item(i, 1)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 2, new QStandardItem(personList->at(i).find("deptname")->toString())); + itemModel->item(i, 2)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 3, new QStandardItem(QString("iris face"))); + itemModel->item(i, 3)->setTextAlignment(Qt::AlignCenter); + + QPushButton * btnDele = new QPushButton("删除"); + btnDele->setProperty("personId", personList->at(i).find("id")->toString()); + btnDele->setProperty("class", "btnDelete"); + connect(btnDele, &QPushButton::clicked, + this, &PersonListForm::btnDeleClicked); + ui->personListTable->setIndexWidget(itemModel->index(i, 4), btnDele); + } + // 设置每行的高度 for ( int i = 0; i < tableRowCount; i++) { @@ -55,27 +157,6 @@ ui->personListTable->setColumnWidth(4, 150); } -PersonListForm::~PersonListForm() -{ - delete ui; -} - -void PersonListForm::findPersonList() -{ - SysPersonDao personDao; - QVector perList = personDao.findAllRecord(); - this->personList->clear(); - for (int i = 0; i < perList.size(); i++) { - QVariantMap person = perList.at(i); - this->personList->append(person); - } -} - -void PersonListForm::updatePersonListTable() -{ - -} - void PersonListForm::on_btnRegist_clicked() { emit switchToRegistForm("0"); @@ -90,3 +171,56 @@ { emit backToHomePage(); } + +void PersonListForm::on_selectDept_currentIndexChanged(int index) +{ + currentPage = 0; + this->findPersonList(); +} + +void PersonListForm::on_btnFirst_clicked() +{ + // 第一页 + currentPage = 0; + findPersonList(); +} + +void PersonListForm::on_btnLast_clicked() +{ + // 最后一页 + currentPage = totalPage - 1; + findPersonList(); +} + +void PersonListForm::on_btnPre_clicked() +{ + // 上一页 + if (currentPage > 0) + { + currentPage = currentPage - 1; + } + findPersonList(); +} + +void PersonListForm::on_btnNext_clicked() +{ + // 下一页 + if (currentPage < totalPage - 1) + { + currentPage++; + } + findPersonList(); +} + +void PersonListForm::btnDeleClicked() +{ + // 获取发送者的信息 + QPushButton * senderObj = (QPushButton *) sender(); + QString personId = senderObj->property("personId").toString(); + SysPersonDao personDao; + bool succ = personDao.dele(personId); + if (succ == 1) + { + findPersonList(); + } +} diff --git a/PersonListForm.h b/PersonListForm.h index 236bc53..cce03a3 100644 --- a/PersonListForm.h +++ b/PersonListForm.h @@ -19,6 +19,8 @@ explicit PersonListForm(QWidget *parent = nullptr); ~PersonListForm(); + void keyPressEvent(QKeyEvent * event); + private slots: void on_btnRegist_clicked(); @@ -26,6 +28,18 @@ void on_btnBack_clicked(); + void on_selectDept_currentIndexChanged(int index); + + void on_btnFirst_clicked(); + + void on_btnLast_clicked(); + + void on_btnPre_clicked(); + + void on_btnNext_clicked(); + + void btnDeleClicked(); + private: Ui::PersonListForm *ui; QStandardItemModel * itemModel; @@ -33,8 +47,12 @@ int tableRowCount = 8; int tableColCount = 5; + int currentPage = 0; + int totalPage = 0; + void calcTotalPage(int totalCount); void findPersonList(); + void initPersonTableHeader(); void updatePersonListTable(); signals: diff --git a/PersonListForm.ui b/PersonListForm.ui index 909cbf2..5bc81f5 100644 --- a/PersonListForm.ui +++ b/PersonListForm.ui @@ -233,7 +233,14 @@ - 1 / 1 + 1 + + + + + + + 条记录 diff --git a/dao/BaseDao.h b/dao/BaseDao.h index aa67f80..1ea0c93 100644 --- a/dao/BaseDao.h +++ b/dao/BaseDao.h @@ -1,4 +1,4 @@ -#ifndef BASEDAO_H +#ifndef BASEDAO_H #define BASEDAO_H #include @@ -21,8 +21,8 @@ virtual QVector findRecordsByProperty(QString properName, QVariant properValue) = 0; virtual QString save(QVariantMap object) = 0; - virtual bool edit(QVariantMap newObject, qulonglong id) = 0; - virtual bool dele(qulonglong id) = 0; + virtual bool edit(QVariantMap newObject, QString id) = 0; + virtual bool dele(QString id) = 0; private: diff --git a/dao/FaceDataDao.cpp b/dao/FaceDataDao.cpp index d668b0a..642f3fb 100644 --- a/dao/FaceDataDao.cpp +++ b/dao/FaceDataDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataDao.h" +#include "FaceDataDao.h" FaceDataDao::FaceDataDao(QObject *parent) : BaseDao(parent) { @@ -87,12 +87,12 @@ } } -bool FaceDataDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool FaceDataDao::dele(qulonglong id) +bool FaceDataDao::dele(QString id) { return false; } diff --git a/dao/FaceDataDao.h b/dao/FaceDataDao.h index 2db4a3d..87fce40 100644 --- a/dao/FaceDataDao.h +++ b/dao/FaceDataDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATADAO_H +#ifndef FACEDATADAO_H #define FACEDATADAO_H #include @@ -16,8 +16,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/FaceDataImgDao.cpp b/dao/FaceDataImgDao.cpp index c4e96f8..ce8a72a 100644 --- a/dao/FaceDataImgDao.cpp +++ b/dao/FaceDataImgDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataImgDao.h" +#include "FaceDataImgDao.h" FaceDataImgDao::FaceDataImgDao(QObject *parent) : BaseDao(parent) { @@ -171,7 +171,7 @@ } } -bool FaceDataImgDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataImgDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -196,7 +196,7 @@ return success; } -bool FaceDataImgDao::dele(qulonglong id) +bool FaceDataImgDao::dele(QString id) { return false; } diff --git a/dao/FaceDataImgDao.h b/dao/FaceDataImgDao.h index d249550..868d73a 100644 --- a/dao/FaceDataImgDao.h +++ b/dao/FaceDataImgDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATAIMGDAO_H +#ifndef FACEDATAIMGDAO_H #define FACEDATAIMGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/IrisDataDao.cpp b/dao/IrisDataDao.cpp index 26a68e2..5f1b047 100644 --- a/dao/IrisDataDao.cpp +++ b/dao/IrisDataDao.cpp @@ -1,4 +1,4 @@ -#include "IrisDataDao.h" +#include "IrisDataDao.h" IrisDataDao::IrisDataDao(QObject *parent) : BaseDao(parent) { @@ -95,13 +95,13 @@ } } -bool IrisDataDao::edit(QVariantMap newObject, qulonglong id) +bool IrisDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool IrisDataDao::dele(qulonglong id) +bool IrisDataDao::dele(QString id) { return false; } diff --git a/dao/IrisDataDao.h b/dao/IrisDataDao.h index 76e6267..1289074 100644 --- a/dao/IrisDataDao.h +++ b/dao/IrisDataDao.h @@ -1,4 +1,4 @@ -#ifndef IRISDATADAO_H +#ifndef IRISDATADAO_H #define IRISDATADAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/IrisDataImgDao.cpp b/dao/IrisDataImgDao.cpp index 691762c..18d4ce6 100644 --- a/dao/IrisDataImgDao.cpp +++ b/dao/IrisDataImgDao.cpp @@ -1,4 +1,4 @@ -#include "IrisDataImgDao.h" +#include "IrisDataImgDao.h" IrisDataImgDao::IrisDataImgDao(QObject *parent) : BaseDao(parent) { @@ -182,7 +182,7 @@ } } -bool IrisDataImgDao::edit(QVariantMap newObject, qulonglong id) +bool IrisDataImgDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -219,7 +219,7 @@ return success; } -bool IrisDataImgDao::dele(qulonglong id) +bool IrisDataImgDao::dele(QString id) { return false; } diff --git a/dao/IrisDataImgDao.h b/dao/IrisDataImgDao.h index 5d35d65..f39158a 100644 --- a/dao/IrisDataImgDao.h +++ b/dao/IrisDataImgDao.h @@ -1,4 +1,4 @@ -#ifndef IRISDATAIMGDAO_H +#ifndef IRISDATAIMGDAO_H #define IRISDATAIMGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/CasicBioRecWin.cpp b/CasicBioRecWin.cpp index 562f7ca..81d4615 100644 --- a/CasicBioRecWin.cpp +++ b/CasicBioRecWin.cpp @@ -9,8 +9,10 @@ { ui->setupUi(this); + // 程序启动时初始化缓存的数据 this->initCacheData(); + // 设置窗口透明和大小、位置 this->setWindowFlags(Qt::FramelessWindowHint); this->move(0, 0); this->resize(SettingConfig::getInstance().WINDOW_WIDTH, @@ -19,8 +21,10 @@ // 通过调色板的颜色来设置窗口的统一背景色 qApp->setPalette(QPalette(QColor(SettingConfig::getInstance().WINDOW_BACKGROUND_COLOR))); + // 初始化各个form界面并绑定切换响应函数 this->initFormsPtr(); + // 打印日志 LOG(INFO) << QString("应用程序启动成功[Application Startup Success]").toStdString(); } diff --git a/PersonListForm.cpp b/PersonListForm.cpp index 77fc565..e479626 100644 --- a/PersonListForm.cpp +++ b/PersonListForm.cpp @@ -21,26 +21,128 @@ ui->vsTableTop->changeSize(0, 20); ui->vsContentBottom->changeSize(0, 40); - itemModel = new QStandardItemModel(this); + // 初始化空的人员列表表格 + initPersonTableHeader(); + // 初始化部门下拉列表框 + SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); +} + +PersonListForm::~PersonListForm() +{ + delete ui; +} + +void PersonListForm::keyPressEvent(QKeyEvent * event) +{ + switch (event->key()) { + case Qt::Key_Return: // 小键盘的Enter键 + case Qt::Key_Enter: // Enter键 + currentPage = 0; + this->findPersonList(); + break; + + default: + QWidget::keyPressEvent(event); + } +} + +void PersonListForm::calcTotalPage(int totalCount) +{ + double temp = (totalCount * 1.0) / (tableRowCount * 1.0); + totalPage = ceil(temp); +} + +void PersonListForm::findPersonList() +{ + SysPersonDao personDao; + + // 获取查询条件 + QString name = ui->inputName->text(); + QString dept = ui->selectDept->currentData().toString(); + + // 计算分页查询的偏移量 + qint16 offset = currentPage * tableRowCount; + + // 查询总条数并计算总页数 + int totalCount = personDao.findRecordCountByNameAndDept(name, dept); + calcTotalPage(totalCount); + + // 赋值表格内容 + QVector perList = personDao.findRecordsByNameAndDept(name, dept, tableRowCount, offset); + + // 有数据且查询结果为空 则重新查询上一页 + if (totalCount > 0 && perList.isEmpty()) + { + // 触发查询上一页的操作 后续操作不再执行 + emit ui->btnPre->clicked(); + return ; + } + + this->personList->clear(); + for (int i = 0; i < perList.size(); i++) { + QVariantMap person = perList.at(i); + this->personList->append(person); + } + + // 更新显示表格 + this->updatePersonListTable(); + + // 更新页码 + if (totalCount == 0) + { + ui->labCurrPage->setText("0"); + } else + { + ui->labCurrPage->setText(QString("%1 / %2 , %3").arg(currentPage + 1).arg(totalPage).arg(totalCount)); + } +} + +void PersonListForm::initPersonTableHeader() +{ + itemModel = new QStandardItemModel(this); personList = new QList(); - SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); - + // 添加表头 QStringList header; header << "员工编号" << "姓名" << "部门 "<< "采集特征" << "操作"; itemModel->setHorizontalHeaderLabels(header); - for (int i = 0; i < tableRowCount; i++) { - QList row; - for ( int j = 0; j < tableColCount; j++) { - itemModel->setItem(i, j, new QStandardItem(QString(""))); - itemModel->item(i, j)->setTextAlignment(Qt::AlignCenter); - } - } + // 设置表头的宽度为固定值 不可调整 + ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); +} + +void PersonListForm::updatePersonListTable() +{ + // 清除表格原有数据 + itemModel->removeRows(0, itemModel->rowCount()); + ui->personListTable->setModel(itemModel); - ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); + // 判断是否有分页 + int max = tableRowCount > personList->size() ? personList->size() : tableRowCount; + for (int i = 0; i < max; i++) { + QList row; + itemModel->setItem(i, 0, new QStandardItem(personList->at(i).find("person_code")->toString())); + itemModel->item(i, 0)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 1, new QStandardItem(personList->at(i).find("name")->toString())); + itemModel->item(i, 1)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 2, new QStandardItem(personList->at(i).find("deptname")->toString())); + itemModel->item(i, 2)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 3, new QStandardItem(QString("iris face"))); + itemModel->item(i, 3)->setTextAlignment(Qt::AlignCenter); + + QPushButton * btnDele = new QPushButton("删除"); + btnDele->setProperty("personId", personList->at(i).find("id")->toString()); + btnDele->setProperty("class", "btnDelete"); + connect(btnDele, &QPushButton::clicked, + this, &PersonListForm::btnDeleClicked); + ui->personListTable->setIndexWidget(itemModel->index(i, 4), btnDele); + } + // 设置每行的高度 for ( int i = 0; i < tableRowCount; i++) { @@ -55,27 +157,6 @@ ui->personListTable->setColumnWidth(4, 150); } -PersonListForm::~PersonListForm() -{ - delete ui; -} - -void PersonListForm::findPersonList() -{ - SysPersonDao personDao; - QVector perList = personDao.findAllRecord(); - this->personList->clear(); - for (int i = 0; i < perList.size(); i++) { - QVariantMap person = perList.at(i); - this->personList->append(person); - } -} - -void PersonListForm::updatePersonListTable() -{ - -} - void PersonListForm::on_btnRegist_clicked() { emit switchToRegistForm("0"); @@ -90,3 +171,56 @@ { emit backToHomePage(); } + +void PersonListForm::on_selectDept_currentIndexChanged(int index) +{ + currentPage = 0; + this->findPersonList(); +} + +void PersonListForm::on_btnFirst_clicked() +{ + // 第一页 + currentPage = 0; + findPersonList(); +} + +void PersonListForm::on_btnLast_clicked() +{ + // 最后一页 + currentPage = totalPage - 1; + findPersonList(); +} + +void PersonListForm::on_btnPre_clicked() +{ + // 上一页 + if (currentPage > 0) + { + currentPage = currentPage - 1; + } + findPersonList(); +} + +void PersonListForm::on_btnNext_clicked() +{ + // 下一页 + if (currentPage < totalPage - 1) + { + currentPage++; + } + findPersonList(); +} + +void PersonListForm::btnDeleClicked() +{ + // 获取发送者的信息 + QPushButton * senderObj = (QPushButton *) sender(); + QString personId = senderObj->property("personId").toString(); + SysPersonDao personDao; + bool succ = personDao.dele(personId); + if (succ == 1) + { + findPersonList(); + } +} diff --git a/PersonListForm.h b/PersonListForm.h index 236bc53..cce03a3 100644 --- a/PersonListForm.h +++ b/PersonListForm.h @@ -19,6 +19,8 @@ explicit PersonListForm(QWidget *parent = nullptr); ~PersonListForm(); + void keyPressEvent(QKeyEvent * event); + private slots: void on_btnRegist_clicked(); @@ -26,6 +28,18 @@ void on_btnBack_clicked(); + void on_selectDept_currentIndexChanged(int index); + + void on_btnFirst_clicked(); + + void on_btnLast_clicked(); + + void on_btnPre_clicked(); + + void on_btnNext_clicked(); + + void btnDeleClicked(); + private: Ui::PersonListForm *ui; QStandardItemModel * itemModel; @@ -33,8 +47,12 @@ int tableRowCount = 8; int tableColCount = 5; + int currentPage = 0; + int totalPage = 0; + void calcTotalPage(int totalCount); void findPersonList(); + void initPersonTableHeader(); void updatePersonListTable(); signals: diff --git a/PersonListForm.ui b/PersonListForm.ui index 909cbf2..5bc81f5 100644 --- a/PersonListForm.ui +++ b/PersonListForm.ui @@ -233,7 +233,14 @@ - 1 / 1 + 1 + + + + + + + 条记录 diff --git a/dao/BaseDao.h b/dao/BaseDao.h index aa67f80..1ea0c93 100644 --- a/dao/BaseDao.h +++ b/dao/BaseDao.h @@ -1,4 +1,4 @@ -#ifndef BASEDAO_H +#ifndef BASEDAO_H #define BASEDAO_H #include @@ -21,8 +21,8 @@ virtual QVector findRecordsByProperty(QString properName, QVariant properValue) = 0; virtual QString save(QVariantMap object) = 0; - virtual bool edit(QVariantMap newObject, qulonglong id) = 0; - virtual bool dele(qulonglong id) = 0; + virtual bool edit(QVariantMap newObject, QString id) = 0; + virtual bool dele(QString id) = 0; private: diff --git a/dao/FaceDataDao.cpp b/dao/FaceDataDao.cpp index d668b0a..642f3fb 100644 --- a/dao/FaceDataDao.cpp +++ b/dao/FaceDataDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataDao.h" +#include "FaceDataDao.h" FaceDataDao::FaceDataDao(QObject *parent) : BaseDao(parent) { @@ -87,12 +87,12 @@ } } -bool FaceDataDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool FaceDataDao::dele(qulonglong id) +bool FaceDataDao::dele(QString id) { return false; } diff --git a/dao/FaceDataDao.h b/dao/FaceDataDao.h index 2db4a3d..87fce40 100644 --- a/dao/FaceDataDao.h +++ b/dao/FaceDataDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATADAO_H +#ifndef FACEDATADAO_H #define FACEDATADAO_H #include @@ -16,8 +16,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/FaceDataImgDao.cpp b/dao/FaceDataImgDao.cpp index c4e96f8..ce8a72a 100644 --- a/dao/FaceDataImgDao.cpp +++ b/dao/FaceDataImgDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataImgDao.h" +#include "FaceDataImgDao.h" FaceDataImgDao::FaceDataImgDao(QObject *parent) : BaseDao(parent) { @@ -171,7 +171,7 @@ } } -bool FaceDataImgDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataImgDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -196,7 +196,7 @@ return success; } -bool FaceDataImgDao::dele(qulonglong id) +bool FaceDataImgDao::dele(QString id) { return false; } diff --git a/dao/FaceDataImgDao.h b/dao/FaceDataImgDao.h index d249550..868d73a 100644 --- a/dao/FaceDataImgDao.h +++ b/dao/FaceDataImgDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATAIMGDAO_H +#ifndef FACEDATAIMGDAO_H #define FACEDATAIMGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/IrisDataDao.cpp b/dao/IrisDataDao.cpp index 26a68e2..5f1b047 100644 --- a/dao/IrisDataDao.cpp +++ b/dao/IrisDataDao.cpp @@ -1,4 +1,4 @@ -#include "IrisDataDao.h" +#include "IrisDataDao.h" IrisDataDao::IrisDataDao(QObject *parent) : BaseDao(parent) { @@ -95,13 +95,13 @@ } } -bool IrisDataDao::edit(QVariantMap newObject, qulonglong id) +bool IrisDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool IrisDataDao::dele(qulonglong id) +bool IrisDataDao::dele(QString id) { return false; } diff --git a/dao/IrisDataDao.h b/dao/IrisDataDao.h index 76e6267..1289074 100644 --- a/dao/IrisDataDao.h +++ b/dao/IrisDataDao.h @@ -1,4 +1,4 @@ -#ifndef IRISDATADAO_H +#ifndef IRISDATADAO_H #define IRISDATADAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/IrisDataImgDao.cpp b/dao/IrisDataImgDao.cpp index 691762c..18d4ce6 100644 --- a/dao/IrisDataImgDao.cpp +++ b/dao/IrisDataImgDao.cpp @@ -1,4 +1,4 @@ -#include "IrisDataImgDao.h" +#include "IrisDataImgDao.h" IrisDataImgDao::IrisDataImgDao(QObject *parent) : BaseDao(parent) { @@ -182,7 +182,7 @@ } } -bool IrisDataImgDao::edit(QVariantMap newObject, qulonglong id) +bool IrisDataImgDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -219,7 +219,7 @@ return success; } -bool IrisDataImgDao::dele(qulonglong id) +bool IrisDataImgDao::dele(QString id) { return false; } diff --git a/dao/IrisDataImgDao.h b/dao/IrisDataImgDao.h index 5d35d65..f39158a 100644 --- a/dao/IrisDataImgDao.h +++ b/dao/IrisDataImgDao.h @@ -1,4 +1,4 @@ -#ifndef IRISDATAIMGDAO_H +#ifndef IRISDATAIMGDAO_H #define IRISDATAIMGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/RecognitionRecordDao.cpp b/dao/RecognitionRecordDao.cpp index c6a188a..403894a 100644 --- a/dao/RecognitionRecordDao.cpp +++ b/dao/RecognitionRecordDao.cpp @@ -1,4 +1,4 @@ -#include "RecognitionRecordDao.h" +#include "RecognitionRecordDao.h" RecognitionRecordDao::RecognitionRecordDao(QObject *parent) : BaseDao(parent) { @@ -123,12 +123,12 @@ } } -bool RecognitionRecordDao::edit(QVariantMap newObject, qulonglong id) +bool RecognitionRecordDao::edit(QVariantMap newObject, QString id) { return false; } -bool RecognitionRecordDao::dele(qulonglong id) +bool RecognitionRecordDao::dele(QString id) { return false; } diff --git a/CasicBioRecWin.cpp b/CasicBioRecWin.cpp index 562f7ca..81d4615 100644 --- a/CasicBioRecWin.cpp +++ b/CasicBioRecWin.cpp @@ -9,8 +9,10 @@ { ui->setupUi(this); + // 程序启动时初始化缓存的数据 this->initCacheData(); + // 设置窗口透明和大小、位置 this->setWindowFlags(Qt::FramelessWindowHint); this->move(0, 0); this->resize(SettingConfig::getInstance().WINDOW_WIDTH, @@ -19,8 +21,10 @@ // 通过调色板的颜色来设置窗口的统一背景色 qApp->setPalette(QPalette(QColor(SettingConfig::getInstance().WINDOW_BACKGROUND_COLOR))); + // 初始化各个form界面并绑定切换响应函数 this->initFormsPtr(); + // 打印日志 LOG(INFO) << QString("应用程序启动成功[Application Startup Success]").toStdString(); } diff --git a/PersonListForm.cpp b/PersonListForm.cpp index 77fc565..e479626 100644 --- a/PersonListForm.cpp +++ b/PersonListForm.cpp @@ -21,26 +21,128 @@ ui->vsTableTop->changeSize(0, 20); ui->vsContentBottom->changeSize(0, 40); - itemModel = new QStandardItemModel(this); + // 初始化空的人员列表表格 + initPersonTableHeader(); + // 初始化部门下拉列表框 + SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); +} + +PersonListForm::~PersonListForm() +{ + delete ui; +} + +void PersonListForm::keyPressEvent(QKeyEvent * event) +{ + switch (event->key()) { + case Qt::Key_Return: // 小键盘的Enter键 + case Qt::Key_Enter: // Enter键 + currentPage = 0; + this->findPersonList(); + break; + + default: + QWidget::keyPressEvent(event); + } +} + +void PersonListForm::calcTotalPage(int totalCount) +{ + double temp = (totalCount * 1.0) / (tableRowCount * 1.0); + totalPage = ceil(temp); +} + +void PersonListForm::findPersonList() +{ + SysPersonDao personDao; + + // 获取查询条件 + QString name = ui->inputName->text(); + QString dept = ui->selectDept->currentData().toString(); + + // 计算分页查询的偏移量 + qint16 offset = currentPage * tableRowCount; + + // 查询总条数并计算总页数 + int totalCount = personDao.findRecordCountByNameAndDept(name, dept); + calcTotalPage(totalCount); + + // 赋值表格内容 + QVector perList = personDao.findRecordsByNameAndDept(name, dept, tableRowCount, offset); + + // 有数据且查询结果为空 则重新查询上一页 + if (totalCount > 0 && perList.isEmpty()) + { + // 触发查询上一页的操作 后续操作不再执行 + emit ui->btnPre->clicked(); + return ; + } + + this->personList->clear(); + for (int i = 0; i < perList.size(); i++) { + QVariantMap person = perList.at(i); + this->personList->append(person); + } + + // 更新显示表格 + this->updatePersonListTable(); + + // 更新页码 + if (totalCount == 0) + { + ui->labCurrPage->setText("0"); + } else + { + ui->labCurrPage->setText(QString("%1 / %2 , %3").arg(currentPage + 1).arg(totalPage).arg(totalCount)); + } +} + +void PersonListForm::initPersonTableHeader() +{ + itemModel = new QStandardItemModel(this); personList = new QList(); - SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); - + // 添加表头 QStringList header; header << "员工编号" << "姓名" << "部门 "<< "采集特征" << "操作"; itemModel->setHorizontalHeaderLabels(header); - for (int i = 0; i < tableRowCount; i++) { - QList row; - for ( int j = 0; j < tableColCount; j++) { - itemModel->setItem(i, j, new QStandardItem(QString(""))); - itemModel->item(i, j)->setTextAlignment(Qt::AlignCenter); - } - } + // 设置表头的宽度为固定值 不可调整 + ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); +} + +void PersonListForm::updatePersonListTable() +{ + // 清除表格原有数据 + itemModel->removeRows(0, itemModel->rowCount()); + ui->personListTable->setModel(itemModel); - ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); + // 判断是否有分页 + int max = tableRowCount > personList->size() ? personList->size() : tableRowCount; + for (int i = 0; i < max; i++) { + QList row; + itemModel->setItem(i, 0, new QStandardItem(personList->at(i).find("person_code")->toString())); + itemModel->item(i, 0)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 1, new QStandardItem(personList->at(i).find("name")->toString())); + itemModel->item(i, 1)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 2, new QStandardItem(personList->at(i).find("deptname")->toString())); + itemModel->item(i, 2)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 3, new QStandardItem(QString("iris face"))); + itemModel->item(i, 3)->setTextAlignment(Qt::AlignCenter); + + QPushButton * btnDele = new QPushButton("删除"); + btnDele->setProperty("personId", personList->at(i).find("id")->toString()); + btnDele->setProperty("class", "btnDelete"); + connect(btnDele, &QPushButton::clicked, + this, &PersonListForm::btnDeleClicked); + ui->personListTable->setIndexWidget(itemModel->index(i, 4), btnDele); + } + // 设置每行的高度 for ( int i = 0; i < tableRowCount; i++) { @@ -55,27 +157,6 @@ ui->personListTable->setColumnWidth(4, 150); } -PersonListForm::~PersonListForm() -{ - delete ui; -} - -void PersonListForm::findPersonList() -{ - SysPersonDao personDao; - QVector perList = personDao.findAllRecord(); - this->personList->clear(); - for (int i = 0; i < perList.size(); i++) { - QVariantMap person = perList.at(i); - this->personList->append(person); - } -} - -void PersonListForm::updatePersonListTable() -{ - -} - void PersonListForm::on_btnRegist_clicked() { emit switchToRegistForm("0"); @@ -90,3 +171,56 @@ { emit backToHomePage(); } + +void PersonListForm::on_selectDept_currentIndexChanged(int index) +{ + currentPage = 0; + this->findPersonList(); +} + +void PersonListForm::on_btnFirst_clicked() +{ + // 第一页 + currentPage = 0; + findPersonList(); +} + +void PersonListForm::on_btnLast_clicked() +{ + // 最后一页 + currentPage = totalPage - 1; + findPersonList(); +} + +void PersonListForm::on_btnPre_clicked() +{ + // 上一页 + if (currentPage > 0) + { + currentPage = currentPage - 1; + } + findPersonList(); +} + +void PersonListForm::on_btnNext_clicked() +{ + // 下一页 + if (currentPage < totalPage - 1) + { + currentPage++; + } + findPersonList(); +} + +void PersonListForm::btnDeleClicked() +{ + // 获取发送者的信息 + QPushButton * senderObj = (QPushButton *) sender(); + QString personId = senderObj->property("personId").toString(); + SysPersonDao personDao; + bool succ = personDao.dele(personId); + if (succ == 1) + { + findPersonList(); + } +} diff --git a/PersonListForm.h b/PersonListForm.h index 236bc53..cce03a3 100644 --- a/PersonListForm.h +++ b/PersonListForm.h @@ -19,6 +19,8 @@ explicit PersonListForm(QWidget *parent = nullptr); ~PersonListForm(); + void keyPressEvent(QKeyEvent * event); + private slots: void on_btnRegist_clicked(); @@ -26,6 +28,18 @@ void on_btnBack_clicked(); + void on_selectDept_currentIndexChanged(int index); + + void on_btnFirst_clicked(); + + void on_btnLast_clicked(); + + void on_btnPre_clicked(); + + void on_btnNext_clicked(); + + void btnDeleClicked(); + private: Ui::PersonListForm *ui; QStandardItemModel * itemModel; @@ -33,8 +47,12 @@ int tableRowCount = 8; int tableColCount = 5; + int currentPage = 0; + int totalPage = 0; + void calcTotalPage(int totalCount); void findPersonList(); + void initPersonTableHeader(); void updatePersonListTable(); signals: diff --git a/PersonListForm.ui b/PersonListForm.ui index 909cbf2..5bc81f5 100644 --- a/PersonListForm.ui +++ b/PersonListForm.ui @@ -233,7 +233,14 @@ - 1 / 1 + 1 + + + + + + + 条记录 diff --git a/dao/BaseDao.h b/dao/BaseDao.h index aa67f80..1ea0c93 100644 --- a/dao/BaseDao.h +++ b/dao/BaseDao.h @@ -1,4 +1,4 @@ -#ifndef BASEDAO_H +#ifndef BASEDAO_H #define BASEDAO_H #include @@ -21,8 +21,8 @@ virtual QVector findRecordsByProperty(QString properName, QVariant properValue) = 0; virtual QString save(QVariantMap object) = 0; - virtual bool edit(QVariantMap newObject, qulonglong id) = 0; - virtual bool dele(qulonglong id) = 0; + virtual bool edit(QVariantMap newObject, QString id) = 0; + virtual bool dele(QString id) = 0; private: diff --git a/dao/FaceDataDao.cpp b/dao/FaceDataDao.cpp index d668b0a..642f3fb 100644 --- a/dao/FaceDataDao.cpp +++ b/dao/FaceDataDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataDao.h" +#include "FaceDataDao.h" FaceDataDao::FaceDataDao(QObject *parent) : BaseDao(parent) { @@ -87,12 +87,12 @@ } } -bool FaceDataDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool FaceDataDao::dele(qulonglong id) +bool FaceDataDao::dele(QString id) { return false; } diff --git a/dao/FaceDataDao.h b/dao/FaceDataDao.h index 2db4a3d..87fce40 100644 --- a/dao/FaceDataDao.h +++ b/dao/FaceDataDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATADAO_H +#ifndef FACEDATADAO_H #define FACEDATADAO_H #include @@ -16,8 +16,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/FaceDataImgDao.cpp b/dao/FaceDataImgDao.cpp index c4e96f8..ce8a72a 100644 --- a/dao/FaceDataImgDao.cpp +++ b/dao/FaceDataImgDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataImgDao.h" +#include "FaceDataImgDao.h" FaceDataImgDao::FaceDataImgDao(QObject *parent) : BaseDao(parent) { @@ -171,7 +171,7 @@ } } -bool FaceDataImgDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataImgDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -196,7 +196,7 @@ return success; } -bool FaceDataImgDao::dele(qulonglong id) +bool FaceDataImgDao::dele(QString id) { return false; } diff --git a/dao/FaceDataImgDao.h b/dao/FaceDataImgDao.h index d249550..868d73a 100644 --- a/dao/FaceDataImgDao.h +++ b/dao/FaceDataImgDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATAIMGDAO_H +#ifndef FACEDATAIMGDAO_H #define FACEDATAIMGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/IrisDataDao.cpp b/dao/IrisDataDao.cpp index 26a68e2..5f1b047 100644 --- a/dao/IrisDataDao.cpp +++ b/dao/IrisDataDao.cpp @@ -1,4 +1,4 @@ -#include "IrisDataDao.h" +#include "IrisDataDao.h" IrisDataDao::IrisDataDao(QObject *parent) : BaseDao(parent) { @@ -95,13 +95,13 @@ } } -bool IrisDataDao::edit(QVariantMap newObject, qulonglong id) +bool IrisDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool IrisDataDao::dele(qulonglong id) +bool IrisDataDao::dele(QString id) { return false; } diff --git a/dao/IrisDataDao.h b/dao/IrisDataDao.h index 76e6267..1289074 100644 --- a/dao/IrisDataDao.h +++ b/dao/IrisDataDao.h @@ -1,4 +1,4 @@ -#ifndef IRISDATADAO_H +#ifndef IRISDATADAO_H #define IRISDATADAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/IrisDataImgDao.cpp b/dao/IrisDataImgDao.cpp index 691762c..18d4ce6 100644 --- a/dao/IrisDataImgDao.cpp +++ b/dao/IrisDataImgDao.cpp @@ -1,4 +1,4 @@ -#include "IrisDataImgDao.h" +#include "IrisDataImgDao.h" IrisDataImgDao::IrisDataImgDao(QObject *parent) : BaseDao(parent) { @@ -182,7 +182,7 @@ } } -bool IrisDataImgDao::edit(QVariantMap newObject, qulonglong id) +bool IrisDataImgDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -219,7 +219,7 @@ return success; } -bool IrisDataImgDao::dele(qulonglong id) +bool IrisDataImgDao::dele(QString id) { return false; } diff --git a/dao/IrisDataImgDao.h b/dao/IrisDataImgDao.h index 5d35d65..f39158a 100644 --- a/dao/IrisDataImgDao.h +++ b/dao/IrisDataImgDao.h @@ -1,4 +1,4 @@ -#ifndef IRISDATAIMGDAO_H +#ifndef IRISDATAIMGDAO_H #define IRISDATAIMGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/RecognitionRecordDao.cpp b/dao/RecognitionRecordDao.cpp index c6a188a..403894a 100644 --- a/dao/RecognitionRecordDao.cpp +++ b/dao/RecognitionRecordDao.cpp @@ -1,4 +1,4 @@ -#include "RecognitionRecordDao.h" +#include "RecognitionRecordDao.h" RecognitionRecordDao::RecognitionRecordDao(QObject *parent) : BaseDao(parent) { @@ -123,12 +123,12 @@ } } -bool RecognitionRecordDao::edit(QVariantMap newObject, qulonglong id) +bool RecognitionRecordDao::edit(QVariantMap newObject, QString id) { return false; } -bool RecognitionRecordDao::dele(qulonglong id) +bool RecognitionRecordDao::dele(QString id) { return false; } diff --git a/dao/RecognitionRecordDao.h b/dao/RecognitionRecordDao.h index 6ef54bf..37572c8 100644 --- a/dao/RecognitionRecordDao.h +++ b/dao/RecognitionRecordDao.h @@ -1,4 +1,4 @@ -#ifndef RECOGNITIONRECORDDAO_H +#ifndef RECOGNITIONRECORDDAO_H #define RECOGNITIONRECORDDAO_H #include @@ -14,8 +14,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/CasicBioRecWin.cpp b/CasicBioRecWin.cpp index 562f7ca..81d4615 100644 --- a/CasicBioRecWin.cpp +++ b/CasicBioRecWin.cpp @@ -9,8 +9,10 @@ { ui->setupUi(this); + // 程序启动时初始化缓存的数据 this->initCacheData(); + // 设置窗口透明和大小、位置 this->setWindowFlags(Qt::FramelessWindowHint); this->move(0, 0); this->resize(SettingConfig::getInstance().WINDOW_WIDTH, @@ -19,8 +21,10 @@ // 通过调色板的颜色来设置窗口的统一背景色 qApp->setPalette(QPalette(QColor(SettingConfig::getInstance().WINDOW_BACKGROUND_COLOR))); + // 初始化各个form界面并绑定切换响应函数 this->initFormsPtr(); + // 打印日志 LOG(INFO) << QString("应用程序启动成功[Application Startup Success]").toStdString(); } diff --git a/PersonListForm.cpp b/PersonListForm.cpp index 77fc565..e479626 100644 --- a/PersonListForm.cpp +++ b/PersonListForm.cpp @@ -21,26 +21,128 @@ ui->vsTableTop->changeSize(0, 20); ui->vsContentBottom->changeSize(0, 40); - itemModel = new QStandardItemModel(this); + // 初始化空的人员列表表格 + initPersonTableHeader(); + // 初始化部门下拉列表框 + SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); +} + +PersonListForm::~PersonListForm() +{ + delete ui; +} + +void PersonListForm::keyPressEvent(QKeyEvent * event) +{ + switch (event->key()) { + case Qt::Key_Return: // 小键盘的Enter键 + case Qt::Key_Enter: // Enter键 + currentPage = 0; + this->findPersonList(); + break; + + default: + QWidget::keyPressEvent(event); + } +} + +void PersonListForm::calcTotalPage(int totalCount) +{ + double temp = (totalCount * 1.0) / (tableRowCount * 1.0); + totalPage = ceil(temp); +} + +void PersonListForm::findPersonList() +{ + SysPersonDao personDao; + + // 获取查询条件 + QString name = ui->inputName->text(); + QString dept = ui->selectDept->currentData().toString(); + + // 计算分页查询的偏移量 + qint16 offset = currentPage * tableRowCount; + + // 查询总条数并计算总页数 + int totalCount = personDao.findRecordCountByNameAndDept(name, dept); + calcTotalPage(totalCount); + + // 赋值表格内容 + QVector perList = personDao.findRecordsByNameAndDept(name, dept, tableRowCount, offset); + + // 有数据且查询结果为空 则重新查询上一页 + if (totalCount > 0 && perList.isEmpty()) + { + // 触发查询上一页的操作 后续操作不再执行 + emit ui->btnPre->clicked(); + return ; + } + + this->personList->clear(); + for (int i = 0; i < perList.size(); i++) { + QVariantMap person = perList.at(i); + this->personList->append(person); + } + + // 更新显示表格 + this->updatePersonListTable(); + + // 更新页码 + if (totalCount == 0) + { + ui->labCurrPage->setText("0"); + } else + { + ui->labCurrPage->setText(QString("%1 / %2 , %3").arg(currentPage + 1).arg(totalPage).arg(totalCount)); + } +} + +void PersonListForm::initPersonTableHeader() +{ + itemModel = new QStandardItemModel(this); personList = new QList(); - SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); - + // 添加表头 QStringList header; header << "员工编号" << "姓名" << "部门 "<< "采集特征" << "操作"; itemModel->setHorizontalHeaderLabels(header); - for (int i = 0; i < tableRowCount; i++) { - QList row; - for ( int j = 0; j < tableColCount; j++) { - itemModel->setItem(i, j, new QStandardItem(QString(""))); - itemModel->item(i, j)->setTextAlignment(Qt::AlignCenter); - } - } + // 设置表头的宽度为固定值 不可调整 + ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); +} + +void PersonListForm::updatePersonListTable() +{ + // 清除表格原有数据 + itemModel->removeRows(0, itemModel->rowCount()); + ui->personListTable->setModel(itemModel); - ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); + // 判断是否有分页 + int max = tableRowCount > personList->size() ? personList->size() : tableRowCount; + for (int i = 0; i < max; i++) { + QList row; + itemModel->setItem(i, 0, new QStandardItem(personList->at(i).find("person_code")->toString())); + itemModel->item(i, 0)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 1, new QStandardItem(personList->at(i).find("name")->toString())); + itemModel->item(i, 1)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 2, new QStandardItem(personList->at(i).find("deptname")->toString())); + itemModel->item(i, 2)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 3, new QStandardItem(QString("iris face"))); + itemModel->item(i, 3)->setTextAlignment(Qt::AlignCenter); + + QPushButton * btnDele = new QPushButton("删除"); + btnDele->setProperty("personId", personList->at(i).find("id")->toString()); + btnDele->setProperty("class", "btnDelete"); + connect(btnDele, &QPushButton::clicked, + this, &PersonListForm::btnDeleClicked); + ui->personListTable->setIndexWidget(itemModel->index(i, 4), btnDele); + } + // 设置每行的高度 for ( int i = 0; i < tableRowCount; i++) { @@ -55,27 +157,6 @@ ui->personListTable->setColumnWidth(4, 150); } -PersonListForm::~PersonListForm() -{ - delete ui; -} - -void PersonListForm::findPersonList() -{ - SysPersonDao personDao; - QVector perList = personDao.findAllRecord(); - this->personList->clear(); - for (int i = 0; i < perList.size(); i++) { - QVariantMap person = perList.at(i); - this->personList->append(person); - } -} - -void PersonListForm::updatePersonListTable() -{ - -} - void PersonListForm::on_btnRegist_clicked() { emit switchToRegistForm("0"); @@ -90,3 +171,56 @@ { emit backToHomePage(); } + +void PersonListForm::on_selectDept_currentIndexChanged(int index) +{ + currentPage = 0; + this->findPersonList(); +} + +void PersonListForm::on_btnFirst_clicked() +{ + // 第一页 + currentPage = 0; + findPersonList(); +} + +void PersonListForm::on_btnLast_clicked() +{ + // 最后一页 + currentPage = totalPage - 1; + findPersonList(); +} + +void PersonListForm::on_btnPre_clicked() +{ + // 上一页 + if (currentPage > 0) + { + currentPage = currentPage - 1; + } + findPersonList(); +} + +void PersonListForm::on_btnNext_clicked() +{ + // 下一页 + if (currentPage < totalPage - 1) + { + currentPage++; + } + findPersonList(); +} + +void PersonListForm::btnDeleClicked() +{ + // 获取发送者的信息 + QPushButton * senderObj = (QPushButton *) sender(); + QString personId = senderObj->property("personId").toString(); + SysPersonDao personDao; + bool succ = personDao.dele(personId); + if (succ == 1) + { + findPersonList(); + } +} diff --git a/PersonListForm.h b/PersonListForm.h index 236bc53..cce03a3 100644 --- a/PersonListForm.h +++ b/PersonListForm.h @@ -19,6 +19,8 @@ explicit PersonListForm(QWidget *parent = nullptr); ~PersonListForm(); + void keyPressEvent(QKeyEvent * event); + private slots: void on_btnRegist_clicked(); @@ -26,6 +28,18 @@ void on_btnBack_clicked(); + void on_selectDept_currentIndexChanged(int index); + + void on_btnFirst_clicked(); + + void on_btnLast_clicked(); + + void on_btnPre_clicked(); + + void on_btnNext_clicked(); + + void btnDeleClicked(); + private: Ui::PersonListForm *ui; QStandardItemModel * itemModel; @@ -33,8 +47,12 @@ int tableRowCount = 8; int tableColCount = 5; + int currentPage = 0; + int totalPage = 0; + void calcTotalPage(int totalCount); void findPersonList(); + void initPersonTableHeader(); void updatePersonListTable(); signals: diff --git a/PersonListForm.ui b/PersonListForm.ui index 909cbf2..5bc81f5 100644 --- a/PersonListForm.ui +++ b/PersonListForm.ui @@ -233,7 +233,14 @@ - 1 / 1 + 1 + + + + + + + 条记录 diff --git a/dao/BaseDao.h b/dao/BaseDao.h index aa67f80..1ea0c93 100644 --- a/dao/BaseDao.h +++ b/dao/BaseDao.h @@ -1,4 +1,4 @@ -#ifndef BASEDAO_H +#ifndef BASEDAO_H #define BASEDAO_H #include @@ -21,8 +21,8 @@ virtual QVector findRecordsByProperty(QString properName, QVariant properValue) = 0; virtual QString save(QVariantMap object) = 0; - virtual bool edit(QVariantMap newObject, qulonglong id) = 0; - virtual bool dele(qulonglong id) = 0; + virtual bool edit(QVariantMap newObject, QString id) = 0; + virtual bool dele(QString id) = 0; private: diff --git a/dao/FaceDataDao.cpp b/dao/FaceDataDao.cpp index d668b0a..642f3fb 100644 --- a/dao/FaceDataDao.cpp +++ b/dao/FaceDataDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataDao.h" +#include "FaceDataDao.h" FaceDataDao::FaceDataDao(QObject *parent) : BaseDao(parent) { @@ -87,12 +87,12 @@ } } -bool FaceDataDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool FaceDataDao::dele(qulonglong id) +bool FaceDataDao::dele(QString id) { return false; } diff --git a/dao/FaceDataDao.h b/dao/FaceDataDao.h index 2db4a3d..87fce40 100644 --- a/dao/FaceDataDao.h +++ b/dao/FaceDataDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATADAO_H +#ifndef FACEDATADAO_H #define FACEDATADAO_H #include @@ -16,8 +16,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/FaceDataImgDao.cpp b/dao/FaceDataImgDao.cpp index c4e96f8..ce8a72a 100644 --- a/dao/FaceDataImgDao.cpp +++ b/dao/FaceDataImgDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataImgDao.h" +#include "FaceDataImgDao.h" FaceDataImgDao::FaceDataImgDao(QObject *parent) : BaseDao(parent) { @@ -171,7 +171,7 @@ } } -bool FaceDataImgDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataImgDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -196,7 +196,7 @@ return success; } -bool FaceDataImgDao::dele(qulonglong id) +bool FaceDataImgDao::dele(QString id) { return false; } diff --git a/dao/FaceDataImgDao.h b/dao/FaceDataImgDao.h index d249550..868d73a 100644 --- a/dao/FaceDataImgDao.h +++ b/dao/FaceDataImgDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATAIMGDAO_H +#ifndef FACEDATAIMGDAO_H #define FACEDATAIMGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/IrisDataDao.cpp b/dao/IrisDataDao.cpp index 26a68e2..5f1b047 100644 --- a/dao/IrisDataDao.cpp +++ b/dao/IrisDataDao.cpp @@ -1,4 +1,4 @@ -#include "IrisDataDao.h" +#include "IrisDataDao.h" IrisDataDao::IrisDataDao(QObject *parent) : BaseDao(parent) { @@ -95,13 +95,13 @@ } } -bool IrisDataDao::edit(QVariantMap newObject, qulonglong id) +bool IrisDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool IrisDataDao::dele(qulonglong id) +bool IrisDataDao::dele(QString id) { return false; } diff --git a/dao/IrisDataDao.h b/dao/IrisDataDao.h index 76e6267..1289074 100644 --- a/dao/IrisDataDao.h +++ b/dao/IrisDataDao.h @@ -1,4 +1,4 @@ -#ifndef IRISDATADAO_H +#ifndef IRISDATADAO_H #define IRISDATADAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/IrisDataImgDao.cpp b/dao/IrisDataImgDao.cpp index 691762c..18d4ce6 100644 --- a/dao/IrisDataImgDao.cpp +++ b/dao/IrisDataImgDao.cpp @@ -1,4 +1,4 @@ -#include "IrisDataImgDao.h" +#include "IrisDataImgDao.h" IrisDataImgDao::IrisDataImgDao(QObject *parent) : BaseDao(parent) { @@ -182,7 +182,7 @@ } } -bool IrisDataImgDao::edit(QVariantMap newObject, qulonglong id) +bool IrisDataImgDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -219,7 +219,7 @@ return success; } -bool IrisDataImgDao::dele(qulonglong id) +bool IrisDataImgDao::dele(QString id) { return false; } diff --git a/dao/IrisDataImgDao.h b/dao/IrisDataImgDao.h index 5d35d65..f39158a 100644 --- a/dao/IrisDataImgDao.h +++ b/dao/IrisDataImgDao.h @@ -1,4 +1,4 @@ -#ifndef IRISDATAIMGDAO_H +#ifndef IRISDATAIMGDAO_H #define IRISDATAIMGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/RecognitionRecordDao.cpp b/dao/RecognitionRecordDao.cpp index c6a188a..403894a 100644 --- a/dao/RecognitionRecordDao.cpp +++ b/dao/RecognitionRecordDao.cpp @@ -1,4 +1,4 @@ -#include "RecognitionRecordDao.h" +#include "RecognitionRecordDao.h" RecognitionRecordDao::RecognitionRecordDao(QObject *parent) : BaseDao(parent) { @@ -123,12 +123,12 @@ } } -bool RecognitionRecordDao::edit(QVariantMap newObject, qulonglong id) +bool RecognitionRecordDao::edit(QVariantMap newObject, QString id) { return false; } -bool RecognitionRecordDao::dele(qulonglong id) +bool RecognitionRecordDao::dele(QString id) { return false; } diff --git a/dao/RecognitionRecordDao.h b/dao/RecognitionRecordDao.h index 6ef54bf..37572c8 100644 --- a/dao/RecognitionRecordDao.h +++ b/dao/RecognitionRecordDao.h @@ -1,4 +1,4 @@ -#ifndef RECOGNITIONRECORDDAO_H +#ifndef RECOGNITIONRECORDDAO_H #define RECOGNITIONRECORDDAO_H #include @@ -14,8 +14,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/SysConfigDao.cpp b/dao/SysConfigDao.cpp index 1d51eca..cc1cbeb 100644 --- a/dao/SysConfigDao.cpp +++ b/dao/SysConfigDao.cpp @@ -1,4 +1,4 @@ -#include "SysConfigDao.h" +#include "SysConfigDao.h" SysConfigDao::SysConfigDao(QObject *parent) : BaseDao(parent) { @@ -32,7 +32,6 @@ result.append(item); } - LOG(DEBUG) << QString("查询SYS_CONFIG表的所有记录").toLocal8Bit().data(); return result; } @@ -54,12 +53,12 @@ return "0"; } -bool SysConfigDao::edit(QVariantMap newObject, qulonglong id) +bool SysConfigDao::edit(QVariantMap newObject, QString id) { return false; } -bool SysConfigDao::dele(qulonglong id) +bool SysConfigDao::dele(QString id) { return false; } diff --git a/CasicBioRecWin.cpp b/CasicBioRecWin.cpp index 562f7ca..81d4615 100644 --- a/CasicBioRecWin.cpp +++ b/CasicBioRecWin.cpp @@ -9,8 +9,10 @@ { ui->setupUi(this); + // 程序启动时初始化缓存的数据 this->initCacheData(); + // 设置窗口透明和大小、位置 this->setWindowFlags(Qt::FramelessWindowHint); this->move(0, 0); this->resize(SettingConfig::getInstance().WINDOW_WIDTH, @@ -19,8 +21,10 @@ // 通过调色板的颜色来设置窗口的统一背景色 qApp->setPalette(QPalette(QColor(SettingConfig::getInstance().WINDOW_BACKGROUND_COLOR))); + // 初始化各个form界面并绑定切换响应函数 this->initFormsPtr(); + // 打印日志 LOG(INFO) << QString("应用程序启动成功[Application Startup Success]").toStdString(); } diff --git a/PersonListForm.cpp b/PersonListForm.cpp index 77fc565..e479626 100644 --- a/PersonListForm.cpp +++ b/PersonListForm.cpp @@ -21,26 +21,128 @@ ui->vsTableTop->changeSize(0, 20); ui->vsContentBottom->changeSize(0, 40); - itemModel = new QStandardItemModel(this); + // 初始化空的人员列表表格 + initPersonTableHeader(); + // 初始化部门下拉列表框 + SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); +} + +PersonListForm::~PersonListForm() +{ + delete ui; +} + +void PersonListForm::keyPressEvent(QKeyEvent * event) +{ + switch (event->key()) { + case Qt::Key_Return: // 小键盘的Enter键 + case Qt::Key_Enter: // Enter键 + currentPage = 0; + this->findPersonList(); + break; + + default: + QWidget::keyPressEvent(event); + } +} + +void PersonListForm::calcTotalPage(int totalCount) +{ + double temp = (totalCount * 1.0) / (tableRowCount * 1.0); + totalPage = ceil(temp); +} + +void PersonListForm::findPersonList() +{ + SysPersonDao personDao; + + // 获取查询条件 + QString name = ui->inputName->text(); + QString dept = ui->selectDept->currentData().toString(); + + // 计算分页查询的偏移量 + qint16 offset = currentPage * tableRowCount; + + // 查询总条数并计算总页数 + int totalCount = personDao.findRecordCountByNameAndDept(name, dept); + calcTotalPage(totalCount); + + // 赋值表格内容 + QVector perList = personDao.findRecordsByNameAndDept(name, dept, tableRowCount, offset); + + // 有数据且查询结果为空 则重新查询上一页 + if (totalCount > 0 && perList.isEmpty()) + { + // 触发查询上一页的操作 后续操作不再执行 + emit ui->btnPre->clicked(); + return ; + } + + this->personList->clear(); + for (int i = 0; i < perList.size(); i++) { + QVariantMap person = perList.at(i); + this->personList->append(person); + } + + // 更新显示表格 + this->updatePersonListTable(); + + // 更新页码 + if (totalCount == 0) + { + ui->labCurrPage->setText("0"); + } else + { + ui->labCurrPage->setText(QString("%1 / %2 , %3").arg(currentPage + 1).arg(totalPage).arg(totalCount)); + } +} + +void PersonListForm::initPersonTableHeader() +{ + itemModel = new QStandardItemModel(this); personList = new QList(); - SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); - + // 添加表头 QStringList header; header << "员工编号" << "姓名" << "部门 "<< "采集特征" << "操作"; itemModel->setHorizontalHeaderLabels(header); - for (int i = 0; i < tableRowCount; i++) { - QList row; - for ( int j = 0; j < tableColCount; j++) { - itemModel->setItem(i, j, new QStandardItem(QString(""))); - itemModel->item(i, j)->setTextAlignment(Qt::AlignCenter); - } - } + // 设置表头的宽度为固定值 不可调整 + ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); +} + +void PersonListForm::updatePersonListTable() +{ + // 清除表格原有数据 + itemModel->removeRows(0, itemModel->rowCount()); + ui->personListTable->setModel(itemModel); - ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); + // 判断是否有分页 + int max = tableRowCount > personList->size() ? personList->size() : tableRowCount; + for (int i = 0; i < max; i++) { + QList row; + itemModel->setItem(i, 0, new QStandardItem(personList->at(i).find("person_code")->toString())); + itemModel->item(i, 0)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 1, new QStandardItem(personList->at(i).find("name")->toString())); + itemModel->item(i, 1)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 2, new QStandardItem(personList->at(i).find("deptname")->toString())); + itemModel->item(i, 2)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 3, new QStandardItem(QString("iris face"))); + itemModel->item(i, 3)->setTextAlignment(Qt::AlignCenter); + + QPushButton * btnDele = new QPushButton("删除"); + btnDele->setProperty("personId", personList->at(i).find("id")->toString()); + btnDele->setProperty("class", "btnDelete"); + connect(btnDele, &QPushButton::clicked, + this, &PersonListForm::btnDeleClicked); + ui->personListTable->setIndexWidget(itemModel->index(i, 4), btnDele); + } + // 设置每行的高度 for ( int i = 0; i < tableRowCount; i++) { @@ -55,27 +157,6 @@ ui->personListTable->setColumnWidth(4, 150); } -PersonListForm::~PersonListForm() -{ - delete ui; -} - -void PersonListForm::findPersonList() -{ - SysPersonDao personDao; - QVector perList = personDao.findAllRecord(); - this->personList->clear(); - for (int i = 0; i < perList.size(); i++) { - QVariantMap person = perList.at(i); - this->personList->append(person); - } -} - -void PersonListForm::updatePersonListTable() -{ - -} - void PersonListForm::on_btnRegist_clicked() { emit switchToRegistForm("0"); @@ -90,3 +171,56 @@ { emit backToHomePage(); } + +void PersonListForm::on_selectDept_currentIndexChanged(int index) +{ + currentPage = 0; + this->findPersonList(); +} + +void PersonListForm::on_btnFirst_clicked() +{ + // 第一页 + currentPage = 0; + findPersonList(); +} + +void PersonListForm::on_btnLast_clicked() +{ + // 最后一页 + currentPage = totalPage - 1; + findPersonList(); +} + +void PersonListForm::on_btnPre_clicked() +{ + // 上一页 + if (currentPage > 0) + { + currentPage = currentPage - 1; + } + findPersonList(); +} + +void PersonListForm::on_btnNext_clicked() +{ + // 下一页 + if (currentPage < totalPage - 1) + { + currentPage++; + } + findPersonList(); +} + +void PersonListForm::btnDeleClicked() +{ + // 获取发送者的信息 + QPushButton * senderObj = (QPushButton *) sender(); + QString personId = senderObj->property("personId").toString(); + SysPersonDao personDao; + bool succ = personDao.dele(personId); + if (succ == 1) + { + findPersonList(); + } +} diff --git a/PersonListForm.h b/PersonListForm.h index 236bc53..cce03a3 100644 --- a/PersonListForm.h +++ b/PersonListForm.h @@ -19,6 +19,8 @@ explicit PersonListForm(QWidget *parent = nullptr); ~PersonListForm(); + void keyPressEvent(QKeyEvent * event); + private slots: void on_btnRegist_clicked(); @@ -26,6 +28,18 @@ void on_btnBack_clicked(); + void on_selectDept_currentIndexChanged(int index); + + void on_btnFirst_clicked(); + + void on_btnLast_clicked(); + + void on_btnPre_clicked(); + + void on_btnNext_clicked(); + + void btnDeleClicked(); + private: Ui::PersonListForm *ui; QStandardItemModel * itemModel; @@ -33,8 +47,12 @@ int tableRowCount = 8; int tableColCount = 5; + int currentPage = 0; + int totalPage = 0; + void calcTotalPage(int totalCount); void findPersonList(); + void initPersonTableHeader(); void updatePersonListTable(); signals: diff --git a/PersonListForm.ui b/PersonListForm.ui index 909cbf2..5bc81f5 100644 --- a/PersonListForm.ui +++ b/PersonListForm.ui @@ -233,7 +233,14 @@ - 1 / 1 + 1 + + + + + + + 条记录 diff --git a/dao/BaseDao.h b/dao/BaseDao.h index aa67f80..1ea0c93 100644 --- a/dao/BaseDao.h +++ b/dao/BaseDao.h @@ -1,4 +1,4 @@ -#ifndef BASEDAO_H +#ifndef BASEDAO_H #define BASEDAO_H #include @@ -21,8 +21,8 @@ virtual QVector findRecordsByProperty(QString properName, QVariant properValue) = 0; virtual QString save(QVariantMap object) = 0; - virtual bool edit(QVariantMap newObject, qulonglong id) = 0; - virtual bool dele(qulonglong id) = 0; + virtual bool edit(QVariantMap newObject, QString id) = 0; + virtual bool dele(QString id) = 0; private: diff --git a/dao/FaceDataDao.cpp b/dao/FaceDataDao.cpp index d668b0a..642f3fb 100644 --- a/dao/FaceDataDao.cpp +++ b/dao/FaceDataDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataDao.h" +#include "FaceDataDao.h" FaceDataDao::FaceDataDao(QObject *parent) : BaseDao(parent) { @@ -87,12 +87,12 @@ } } -bool FaceDataDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool FaceDataDao::dele(qulonglong id) +bool FaceDataDao::dele(QString id) { return false; } diff --git a/dao/FaceDataDao.h b/dao/FaceDataDao.h index 2db4a3d..87fce40 100644 --- a/dao/FaceDataDao.h +++ b/dao/FaceDataDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATADAO_H +#ifndef FACEDATADAO_H #define FACEDATADAO_H #include @@ -16,8 +16,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/FaceDataImgDao.cpp b/dao/FaceDataImgDao.cpp index c4e96f8..ce8a72a 100644 --- a/dao/FaceDataImgDao.cpp +++ b/dao/FaceDataImgDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataImgDao.h" +#include "FaceDataImgDao.h" FaceDataImgDao::FaceDataImgDao(QObject *parent) : BaseDao(parent) { @@ -171,7 +171,7 @@ } } -bool FaceDataImgDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataImgDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -196,7 +196,7 @@ return success; } -bool FaceDataImgDao::dele(qulonglong id) +bool FaceDataImgDao::dele(QString id) { return false; } diff --git a/dao/FaceDataImgDao.h b/dao/FaceDataImgDao.h index d249550..868d73a 100644 --- a/dao/FaceDataImgDao.h +++ b/dao/FaceDataImgDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATAIMGDAO_H +#ifndef FACEDATAIMGDAO_H #define FACEDATAIMGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/IrisDataDao.cpp b/dao/IrisDataDao.cpp index 26a68e2..5f1b047 100644 --- a/dao/IrisDataDao.cpp +++ b/dao/IrisDataDao.cpp @@ -1,4 +1,4 @@ -#include "IrisDataDao.h" +#include "IrisDataDao.h" IrisDataDao::IrisDataDao(QObject *parent) : BaseDao(parent) { @@ -95,13 +95,13 @@ } } -bool IrisDataDao::edit(QVariantMap newObject, qulonglong id) +bool IrisDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool IrisDataDao::dele(qulonglong id) +bool IrisDataDao::dele(QString id) { return false; } diff --git a/dao/IrisDataDao.h b/dao/IrisDataDao.h index 76e6267..1289074 100644 --- a/dao/IrisDataDao.h +++ b/dao/IrisDataDao.h @@ -1,4 +1,4 @@ -#ifndef IRISDATADAO_H +#ifndef IRISDATADAO_H #define IRISDATADAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/IrisDataImgDao.cpp b/dao/IrisDataImgDao.cpp index 691762c..18d4ce6 100644 --- a/dao/IrisDataImgDao.cpp +++ b/dao/IrisDataImgDao.cpp @@ -1,4 +1,4 @@ -#include "IrisDataImgDao.h" +#include "IrisDataImgDao.h" IrisDataImgDao::IrisDataImgDao(QObject *parent) : BaseDao(parent) { @@ -182,7 +182,7 @@ } } -bool IrisDataImgDao::edit(QVariantMap newObject, qulonglong id) +bool IrisDataImgDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -219,7 +219,7 @@ return success; } -bool IrisDataImgDao::dele(qulonglong id) +bool IrisDataImgDao::dele(QString id) { return false; } diff --git a/dao/IrisDataImgDao.h b/dao/IrisDataImgDao.h index 5d35d65..f39158a 100644 --- a/dao/IrisDataImgDao.h +++ b/dao/IrisDataImgDao.h @@ -1,4 +1,4 @@ -#ifndef IRISDATAIMGDAO_H +#ifndef IRISDATAIMGDAO_H #define IRISDATAIMGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/RecognitionRecordDao.cpp b/dao/RecognitionRecordDao.cpp index c6a188a..403894a 100644 --- a/dao/RecognitionRecordDao.cpp +++ b/dao/RecognitionRecordDao.cpp @@ -1,4 +1,4 @@ -#include "RecognitionRecordDao.h" +#include "RecognitionRecordDao.h" RecognitionRecordDao::RecognitionRecordDao(QObject *parent) : BaseDao(parent) { @@ -123,12 +123,12 @@ } } -bool RecognitionRecordDao::edit(QVariantMap newObject, qulonglong id) +bool RecognitionRecordDao::edit(QVariantMap newObject, QString id) { return false; } -bool RecognitionRecordDao::dele(qulonglong id) +bool RecognitionRecordDao::dele(QString id) { return false; } diff --git a/dao/RecognitionRecordDao.h b/dao/RecognitionRecordDao.h index 6ef54bf..37572c8 100644 --- a/dao/RecognitionRecordDao.h +++ b/dao/RecognitionRecordDao.h @@ -1,4 +1,4 @@ -#ifndef RECOGNITIONRECORDDAO_H +#ifndef RECOGNITIONRECORDDAO_H #define RECOGNITIONRECORDDAO_H #include @@ -14,8 +14,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/SysConfigDao.cpp b/dao/SysConfigDao.cpp index 1d51eca..cc1cbeb 100644 --- a/dao/SysConfigDao.cpp +++ b/dao/SysConfigDao.cpp @@ -1,4 +1,4 @@ -#include "SysConfigDao.h" +#include "SysConfigDao.h" SysConfigDao::SysConfigDao(QObject *parent) : BaseDao(parent) { @@ -32,7 +32,6 @@ result.append(item); } - LOG(DEBUG) << QString("查询SYS_CONFIG表的所有记录").toLocal8Bit().data(); return result; } @@ -54,12 +53,12 @@ return "0"; } -bool SysConfigDao::edit(QVariantMap newObject, qulonglong id) +bool SysConfigDao::edit(QVariantMap newObject, QString id) { return false; } -bool SysConfigDao::dele(qulonglong id) +bool SysConfigDao::dele(QString id) { return false; } diff --git a/dao/SysConfigDao.h b/dao/SysConfigDao.h index 8b525cd..e88b993 100644 --- a/dao/SysConfigDao.h +++ b/dao/SysConfigDao.h @@ -1,4 +1,4 @@ -#ifndef SYSCONFIGDAO_H +#ifndef SYSCONFIGDAO_H #define SYSCONFIGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/CasicBioRecWin.cpp b/CasicBioRecWin.cpp index 562f7ca..81d4615 100644 --- a/CasicBioRecWin.cpp +++ b/CasicBioRecWin.cpp @@ -9,8 +9,10 @@ { ui->setupUi(this); + // 程序启动时初始化缓存的数据 this->initCacheData(); + // 设置窗口透明和大小、位置 this->setWindowFlags(Qt::FramelessWindowHint); this->move(0, 0); this->resize(SettingConfig::getInstance().WINDOW_WIDTH, @@ -19,8 +21,10 @@ // 通过调色板的颜色来设置窗口的统一背景色 qApp->setPalette(QPalette(QColor(SettingConfig::getInstance().WINDOW_BACKGROUND_COLOR))); + // 初始化各个form界面并绑定切换响应函数 this->initFormsPtr(); + // 打印日志 LOG(INFO) << QString("应用程序启动成功[Application Startup Success]").toStdString(); } diff --git a/PersonListForm.cpp b/PersonListForm.cpp index 77fc565..e479626 100644 --- a/PersonListForm.cpp +++ b/PersonListForm.cpp @@ -21,26 +21,128 @@ ui->vsTableTop->changeSize(0, 20); ui->vsContentBottom->changeSize(0, 40); - itemModel = new QStandardItemModel(this); + // 初始化空的人员列表表格 + initPersonTableHeader(); + // 初始化部门下拉列表框 + SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); +} + +PersonListForm::~PersonListForm() +{ + delete ui; +} + +void PersonListForm::keyPressEvent(QKeyEvent * event) +{ + switch (event->key()) { + case Qt::Key_Return: // 小键盘的Enter键 + case Qt::Key_Enter: // Enter键 + currentPage = 0; + this->findPersonList(); + break; + + default: + QWidget::keyPressEvent(event); + } +} + +void PersonListForm::calcTotalPage(int totalCount) +{ + double temp = (totalCount * 1.0) / (tableRowCount * 1.0); + totalPage = ceil(temp); +} + +void PersonListForm::findPersonList() +{ + SysPersonDao personDao; + + // 获取查询条件 + QString name = ui->inputName->text(); + QString dept = ui->selectDept->currentData().toString(); + + // 计算分页查询的偏移量 + qint16 offset = currentPage * tableRowCount; + + // 查询总条数并计算总页数 + int totalCount = personDao.findRecordCountByNameAndDept(name, dept); + calcTotalPage(totalCount); + + // 赋值表格内容 + QVector perList = personDao.findRecordsByNameAndDept(name, dept, tableRowCount, offset); + + // 有数据且查询结果为空 则重新查询上一页 + if (totalCount > 0 && perList.isEmpty()) + { + // 触发查询上一页的操作 后续操作不再执行 + emit ui->btnPre->clicked(); + return ; + } + + this->personList->clear(); + for (int i = 0; i < perList.size(); i++) { + QVariantMap person = perList.at(i); + this->personList->append(person); + } + + // 更新显示表格 + this->updatePersonListTable(); + + // 更新页码 + if (totalCount == 0) + { + ui->labCurrPage->setText("0"); + } else + { + ui->labCurrPage->setText(QString("%1 / %2 , %3").arg(currentPage + 1).arg(totalPage).arg(totalCount)); + } +} + +void PersonListForm::initPersonTableHeader() +{ + itemModel = new QStandardItemModel(this); personList = new QList(); - SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); - + // 添加表头 QStringList header; header << "员工编号" << "姓名" << "部门 "<< "采集特征" << "操作"; itemModel->setHorizontalHeaderLabels(header); - for (int i = 0; i < tableRowCount; i++) { - QList row; - for ( int j = 0; j < tableColCount; j++) { - itemModel->setItem(i, j, new QStandardItem(QString(""))); - itemModel->item(i, j)->setTextAlignment(Qt::AlignCenter); - } - } + // 设置表头的宽度为固定值 不可调整 + ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); +} + +void PersonListForm::updatePersonListTable() +{ + // 清除表格原有数据 + itemModel->removeRows(0, itemModel->rowCount()); + ui->personListTable->setModel(itemModel); - ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); + // 判断是否有分页 + int max = tableRowCount > personList->size() ? personList->size() : tableRowCount; + for (int i = 0; i < max; i++) { + QList row; + itemModel->setItem(i, 0, new QStandardItem(personList->at(i).find("person_code")->toString())); + itemModel->item(i, 0)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 1, new QStandardItem(personList->at(i).find("name")->toString())); + itemModel->item(i, 1)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 2, new QStandardItem(personList->at(i).find("deptname")->toString())); + itemModel->item(i, 2)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 3, new QStandardItem(QString("iris face"))); + itemModel->item(i, 3)->setTextAlignment(Qt::AlignCenter); + + QPushButton * btnDele = new QPushButton("删除"); + btnDele->setProperty("personId", personList->at(i).find("id")->toString()); + btnDele->setProperty("class", "btnDelete"); + connect(btnDele, &QPushButton::clicked, + this, &PersonListForm::btnDeleClicked); + ui->personListTable->setIndexWidget(itemModel->index(i, 4), btnDele); + } + // 设置每行的高度 for ( int i = 0; i < tableRowCount; i++) { @@ -55,27 +157,6 @@ ui->personListTable->setColumnWidth(4, 150); } -PersonListForm::~PersonListForm() -{ - delete ui; -} - -void PersonListForm::findPersonList() -{ - SysPersonDao personDao; - QVector perList = personDao.findAllRecord(); - this->personList->clear(); - for (int i = 0; i < perList.size(); i++) { - QVariantMap person = perList.at(i); - this->personList->append(person); - } -} - -void PersonListForm::updatePersonListTable() -{ - -} - void PersonListForm::on_btnRegist_clicked() { emit switchToRegistForm("0"); @@ -90,3 +171,56 @@ { emit backToHomePage(); } + +void PersonListForm::on_selectDept_currentIndexChanged(int index) +{ + currentPage = 0; + this->findPersonList(); +} + +void PersonListForm::on_btnFirst_clicked() +{ + // 第一页 + currentPage = 0; + findPersonList(); +} + +void PersonListForm::on_btnLast_clicked() +{ + // 最后一页 + currentPage = totalPage - 1; + findPersonList(); +} + +void PersonListForm::on_btnPre_clicked() +{ + // 上一页 + if (currentPage > 0) + { + currentPage = currentPage - 1; + } + findPersonList(); +} + +void PersonListForm::on_btnNext_clicked() +{ + // 下一页 + if (currentPage < totalPage - 1) + { + currentPage++; + } + findPersonList(); +} + +void PersonListForm::btnDeleClicked() +{ + // 获取发送者的信息 + QPushButton * senderObj = (QPushButton *) sender(); + QString personId = senderObj->property("personId").toString(); + SysPersonDao personDao; + bool succ = personDao.dele(personId); + if (succ == 1) + { + findPersonList(); + } +} diff --git a/PersonListForm.h b/PersonListForm.h index 236bc53..cce03a3 100644 --- a/PersonListForm.h +++ b/PersonListForm.h @@ -19,6 +19,8 @@ explicit PersonListForm(QWidget *parent = nullptr); ~PersonListForm(); + void keyPressEvent(QKeyEvent * event); + private slots: void on_btnRegist_clicked(); @@ -26,6 +28,18 @@ void on_btnBack_clicked(); + void on_selectDept_currentIndexChanged(int index); + + void on_btnFirst_clicked(); + + void on_btnLast_clicked(); + + void on_btnPre_clicked(); + + void on_btnNext_clicked(); + + void btnDeleClicked(); + private: Ui::PersonListForm *ui; QStandardItemModel * itemModel; @@ -33,8 +47,12 @@ int tableRowCount = 8; int tableColCount = 5; + int currentPage = 0; + int totalPage = 0; + void calcTotalPage(int totalCount); void findPersonList(); + void initPersonTableHeader(); void updatePersonListTable(); signals: diff --git a/PersonListForm.ui b/PersonListForm.ui index 909cbf2..5bc81f5 100644 --- a/PersonListForm.ui +++ b/PersonListForm.ui @@ -233,7 +233,14 @@ - 1 / 1 + 1 + + + + + + + 条记录 diff --git a/dao/BaseDao.h b/dao/BaseDao.h index aa67f80..1ea0c93 100644 --- a/dao/BaseDao.h +++ b/dao/BaseDao.h @@ -1,4 +1,4 @@ -#ifndef BASEDAO_H +#ifndef BASEDAO_H #define BASEDAO_H #include @@ -21,8 +21,8 @@ virtual QVector findRecordsByProperty(QString properName, QVariant properValue) = 0; virtual QString save(QVariantMap object) = 0; - virtual bool edit(QVariantMap newObject, qulonglong id) = 0; - virtual bool dele(qulonglong id) = 0; + virtual bool edit(QVariantMap newObject, QString id) = 0; + virtual bool dele(QString id) = 0; private: diff --git a/dao/FaceDataDao.cpp b/dao/FaceDataDao.cpp index d668b0a..642f3fb 100644 --- a/dao/FaceDataDao.cpp +++ b/dao/FaceDataDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataDao.h" +#include "FaceDataDao.h" FaceDataDao::FaceDataDao(QObject *parent) : BaseDao(parent) { @@ -87,12 +87,12 @@ } } -bool FaceDataDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool FaceDataDao::dele(qulonglong id) +bool FaceDataDao::dele(QString id) { return false; } diff --git a/dao/FaceDataDao.h b/dao/FaceDataDao.h index 2db4a3d..87fce40 100644 --- a/dao/FaceDataDao.h +++ b/dao/FaceDataDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATADAO_H +#ifndef FACEDATADAO_H #define FACEDATADAO_H #include @@ -16,8 +16,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/FaceDataImgDao.cpp b/dao/FaceDataImgDao.cpp index c4e96f8..ce8a72a 100644 --- a/dao/FaceDataImgDao.cpp +++ b/dao/FaceDataImgDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataImgDao.h" +#include "FaceDataImgDao.h" FaceDataImgDao::FaceDataImgDao(QObject *parent) : BaseDao(parent) { @@ -171,7 +171,7 @@ } } -bool FaceDataImgDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataImgDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -196,7 +196,7 @@ return success; } -bool FaceDataImgDao::dele(qulonglong id) +bool FaceDataImgDao::dele(QString id) { return false; } diff --git a/dao/FaceDataImgDao.h b/dao/FaceDataImgDao.h index d249550..868d73a 100644 --- a/dao/FaceDataImgDao.h +++ b/dao/FaceDataImgDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATAIMGDAO_H +#ifndef FACEDATAIMGDAO_H #define FACEDATAIMGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/IrisDataDao.cpp b/dao/IrisDataDao.cpp index 26a68e2..5f1b047 100644 --- a/dao/IrisDataDao.cpp +++ b/dao/IrisDataDao.cpp @@ -1,4 +1,4 @@ -#include "IrisDataDao.h" +#include "IrisDataDao.h" IrisDataDao::IrisDataDao(QObject *parent) : BaseDao(parent) { @@ -95,13 +95,13 @@ } } -bool IrisDataDao::edit(QVariantMap newObject, qulonglong id) +bool IrisDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool IrisDataDao::dele(qulonglong id) +bool IrisDataDao::dele(QString id) { return false; } diff --git a/dao/IrisDataDao.h b/dao/IrisDataDao.h index 76e6267..1289074 100644 --- a/dao/IrisDataDao.h +++ b/dao/IrisDataDao.h @@ -1,4 +1,4 @@ -#ifndef IRISDATADAO_H +#ifndef IRISDATADAO_H #define IRISDATADAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/IrisDataImgDao.cpp b/dao/IrisDataImgDao.cpp index 691762c..18d4ce6 100644 --- a/dao/IrisDataImgDao.cpp +++ b/dao/IrisDataImgDao.cpp @@ -1,4 +1,4 @@ -#include "IrisDataImgDao.h" +#include "IrisDataImgDao.h" IrisDataImgDao::IrisDataImgDao(QObject *parent) : BaseDao(parent) { @@ -182,7 +182,7 @@ } } -bool IrisDataImgDao::edit(QVariantMap newObject, qulonglong id) +bool IrisDataImgDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -219,7 +219,7 @@ return success; } -bool IrisDataImgDao::dele(qulonglong id) +bool IrisDataImgDao::dele(QString id) { return false; } diff --git a/dao/IrisDataImgDao.h b/dao/IrisDataImgDao.h index 5d35d65..f39158a 100644 --- a/dao/IrisDataImgDao.h +++ b/dao/IrisDataImgDao.h @@ -1,4 +1,4 @@ -#ifndef IRISDATAIMGDAO_H +#ifndef IRISDATAIMGDAO_H #define IRISDATAIMGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/RecognitionRecordDao.cpp b/dao/RecognitionRecordDao.cpp index c6a188a..403894a 100644 --- a/dao/RecognitionRecordDao.cpp +++ b/dao/RecognitionRecordDao.cpp @@ -1,4 +1,4 @@ -#include "RecognitionRecordDao.h" +#include "RecognitionRecordDao.h" RecognitionRecordDao::RecognitionRecordDao(QObject *parent) : BaseDao(parent) { @@ -123,12 +123,12 @@ } } -bool RecognitionRecordDao::edit(QVariantMap newObject, qulonglong id) +bool RecognitionRecordDao::edit(QVariantMap newObject, QString id) { return false; } -bool RecognitionRecordDao::dele(qulonglong id) +bool RecognitionRecordDao::dele(QString id) { return false; } diff --git a/dao/RecognitionRecordDao.h b/dao/RecognitionRecordDao.h index 6ef54bf..37572c8 100644 --- a/dao/RecognitionRecordDao.h +++ b/dao/RecognitionRecordDao.h @@ -1,4 +1,4 @@ -#ifndef RECOGNITIONRECORDDAO_H +#ifndef RECOGNITIONRECORDDAO_H #define RECOGNITIONRECORDDAO_H #include @@ -14,8 +14,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/SysConfigDao.cpp b/dao/SysConfigDao.cpp index 1d51eca..cc1cbeb 100644 --- a/dao/SysConfigDao.cpp +++ b/dao/SysConfigDao.cpp @@ -1,4 +1,4 @@ -#include "SysConfigDao.h" +#include "SysConfigDao.h" SysConfigDao::SysConfigDao(QObject *parent) : BaseDao(parent) { @@ -32,7 +32,6 @@ result.append(item); } - LOG(DEBUG) << QString("查询SYS_CONFIG表的所有记录").toLocal8Bit().data(); return result; } @@ -54,12 +53,12 @@ return "0"; } -bool SysConfigDao::edit(QVariantMap newObject, qulonglong id) +bool SysConfigDao::edit(QVariantMap newObject, QString id) { return false; } -bool SysConfigDao::dele(qulonglong id) +bool SysConfigDao::dele(QString id) { return false; } diff --git a/dao/SysConfigDao.h b/dao/SysConfigDao.h index 8b525cd..e88b993 100644 --- a/dao/SysConfigDao.h +++ b/dao/SysConfigDao.h @@ -1,4 +1,4 @@ -#ifndef SYSCONFIGDAO_H +#ifndef SYSCONFIGDAO_H #define SYSCONFIGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/SysDeptDao.cpp b/dao/SysDeptDao.cpp index d5c5d77..9562e78 100644 --- a/dao/SysDeptDao.cpp +++ b/dao/SysDeptDao.cpp @@ -104,35 +104,7 @@ result.append(item); } - LOG(DEBUG) << QString("根据属性值查询SYS_DEPT表的记录[%1][%2]").arg(count).arg(sql).toStdString(); - return result; -} - -QList SysDeptDao::findDeptTree(QString pid) -{ - // 新建查询 - QSqlQuery query(ConnectionManager::getInstance()->getConnection()); - - // 查询语句 - QString sql = "SELECT * FROM SYS_DEPT WHERE PID = '" + pid + "' ORDER BY NUM"; - - // 执行查询 - query.exec(sql); - - // 返回结果 - QList result; - - // 遍历查询部门树形结构 - while (query.next()) { - QVariantMap item; - QString id = query.value("id").toString(); - item.insert("id", id); - item.insert("pid", query.value("pid").toString()); - item.insert("pids", query.value("pids").toString()); - item.insert("fullname", query.value("fullname").toString()); - result.append(item); - } - + LOG(TRACE) << QString("根据属性值查询SYS_DEPT表的记录[%1][%2]").arg(count).arg(sql).toStdString(); return result; } @@ -140,11 +112,11 @@ { return "0"; } -bool SysDeptDao::edit(QVariantMap newObject, qulonglong id) +bool SysDeptDao::edit(QVariantMap newObject, QString id) { return true; } -bool SysDeptDao::dele(qulonglong id) +bool SysDeptDao::dele(QString id) { return true; } diff --git a/CasicBioRecWin.cpp b/CasicBioRecWin.cpp index 562f7ca..81d4615 100644 --- a/CasicBioRecWin.cpp +++ b/CasicBioRecWin.cpp @@ -9,8 +9,10 @@ { ui->setupUi(this); + // 程序启动时初始化缓存的数据 this->initCacheData(); + // 设置窗口透明和大小、位置 this->setWindowFlags(Qt::FramelessWindowHint); this->move(0, 0); this->resize(SettingConfig::getInstance().WINDOW_WIDTH, @@ -19,8 +21,10 @@ // 通过调色板的颜色来设置窗口的统一背景色 qApp->setPalette(QPalette(QColor(SettingConfig::getInstance().WINDOW_BACKGROUND_COLOR))); + // 初始化各个form界面并绑定切换响应函数 this->initFormsPtr(); + // 打印日志 LOG(INFO) << QString("应用程序启动成功[Application Startup Success]").toStdString(); } diff --git a/PersonListForm.cpp b/PersonListForm.cpp index 77fc565..e479626 100644 --- a/PersonListForm.cpp +++ b/PersonListForm.cpp @@ -21,26 +21,128 @@ ui->vsTableTop->changeSize(0, 20); ui->vsContentBottom->changeSize(0, 40); - itemModel = new QStandardItemModel(this); + // 初始化空的人员列表表格 + initPersonTableHeader(); + // 初始化部门下拉列表框 + SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); +} + +PersonListForm::~PersonListForm() +{ + delete ui; +} + +void PersonListForm::keyPressEvent(QKeyEvent * event) +{ + switch (event->key()) { + case Qt::Key_Return: // 小键盘的Enter键 + case Qt::Key_Enter: // Enter键 + currentPage = 0; + this->findPersonList(); + break; + + default: + QWidget::keyPressEvent(event); + } +} + +void PersonListForm::calcTotalPage(int totalCount) +{ + double temp = (totalCount * 1.0) / (tableRowCount * 1.0); + totalPage = ceil(temp); +} + +void PersonListForm::findPersonList() +{ + SysPersonDao personDao; + + // 获取查询条件 + QString name = ui->inputName->text(); + QString dept = ui->selectDept->currentData().toString(); + + // 计算分页查询的偏移量 + qint16 offset = currentPage * tableRowCount; + + // 查询总条数并计算总页数 + int totalCount = personDao.findRecordCountByNameAndDept(name, dept); + calcTotalPage(totalCount); + + // 赋值表格内容 + QVector perList = personDao.findRecordsByNameAndDept(name, dept, tableRowCount, offset); + + // 有数据且查询结果为空 则重新查询上一页 + if (totalCount > 0 && perList.isEmpty()) + { + // 触发查询上一页的操作 后续操作不再执行 + emit ui->btnPre->clicked(); + return ; + } + + this->personList->clear(); + for (int i = 0; i < perList.size(); i++) { + QVariantMap person = perList.at(i); + this->personList->append(person); + } + + // 更新显示表格 + this->updatePersonListTable(); + + // 更新页码 + if (totalCount == 0) + { + ui->labCurrPage->setText("0"); + } else + { + ui->labCurrPage->setText(QString("%1 / %2 , %3").arg(currentPage + 1).arg(totalPage).arg(totalCount)); + } +} + +void PersonListForm::initPersonTableHeader() +{ + itemModel = new QStandardItemModel(this); personList = new QList(); - SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); - + // 添加表头 QStringList header; header << "员工编号" << "姓名" << "部门 "<< "采集特征" << "操作"; itemModel->setHorizontalHeaderLabels(header); - for (int i = 0; i < tableRowCount; i++) { - QList row; - for ( int j = 0; j < tableColCount; j++) { - itemModel->setItem(i, j, new QStandardItem(QString(""))); - itemModel->item(i, j)->setTextAlignment(Qt::AlignCenter); - } - } + // 设置表头的宽度为固定值 不可调整 + ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); +} + +void PersonListForm::updatePersonListTable() +{ + // 清除表格原有数据 + itemModel->removeRows(0, itemModel->rowCount()); + ui->personListTable->setModel(itemModel); - ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); + // 判断是否有分页 + int max = tableRowCount > personList->size() ? personList->size() : tableRowCount; + for (int i = 0; i < max; i++) { + QList row; + itemModel->setItem(i, 0, new QStandardItem(personList->at(i).find("person_code")->toString())); + itemModel->item(i, 0)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 1, new QStandardItem(personList->at(i).find("name")->toString())); + itemModel->item(i, 1)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 2, new QStandardItem(personList->at(i).find("deptname")->toString())); + itemModel->item(i, 2)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 3, new QStandardItem(QString("iris face"))); + itemModel->item(i, 3)->setTextAlignment(Qt::AlignCenter); + + QPushButton * btnDele = new QPushButton("删除"); + btnDele->setProperty("personId", personList->at(i).find("id")->toString()); + btnDele->setProperty("class", "btnDelete"); + connect(btnDele, &QPushButton::clicked, + this, &PersonListForm::btnDeleClicked); + ui->personListTable->setIndexWidget(itemModel->index(i, 4), btnDele); + } + // 设置每行的高度 for ( int i = 0; i < tableRowCount; i++) { @@ -55,27 +157,6 @@ ui->personListTable->setColumnWidth(4, 150); } -PersonListForm::~PersonListForm() -{ - delete ui; -} - -void PersonListForm::findPersonList() -{ - SysPersonDao personDao; - QVector perList = personDao.findAllRecord(); - this->personList->clear(); - for (int i = 0; i < perList.size(); i++) { - QVariantMap person = perList.at(i); - this->personList->append(person); - } -} - -void PersonListForm::updatePersonListTable() -{ - -} - void PersonListForm::on_btnRegist_clicked() { emit switchToRegistForm("0"); @@ -90,3 +171,56 @@ { emit backToHomePage(); } + +void PersonListForm::on_selectDept_currentIndexChanged(int index) +{ + currentPage = 0; + this->findPersonList(); +} + +void PersonListForm::on_btnFirst_clicked() +{ + // 第一页 + currentPage = 0; + findPersonList(); +} + +void PersonListForm::on_btnLast_clicked() +{ + // 最后一页 + currentPage = totalPage - 1; + findPersonList(); +} + +void PersonListForm::on_btnPre_clicked() +{ + // 上一页 + if (currentPage > 0) + { + currentPage = currentPage - 1; + } + findPersonList(); +} + +void PersonListForm::on_btnNext_clicked() +{ + // 下一页 + if (currentPage < totalPage - 1) + { + currentPage++; + } + findPersonList(); +} + +void PersonListForm::btnDeleClicked() +{ + // 获取发送者的信息 + QPushButton * senderObj = (QPushButton *) sender(); + QString personId = senderObj->property("personId").toString(); + SysPersonDao personDao; + bool succ = personDao.dele(personId); + if (succ == 1) + { + findPersonList(); + } +} diff --git a/PersonListForm.h b/PersonListForm.h index 236bc53..cce03a3 100644 --- a/PersonListForm.h +++ b/PersonListForm.h @@ -19,6 +19,8 @@ explicit PersonListForm(QWidget *parent = nullptr); ~PersonListForm(); + void keyPressEvent(QKeyEvent * event); + private slots: void on_btnRegist_clicked(); @@ -26,6 +28,18 @@ void on_btnBack_clicked(); + void on_selectDept_currentIndexChanged(int index); + + void on_btnFirst_clicked(); + + void on_btnLast_clicked(); + + void on_btnPre_clicked(); + + void on_btnNext_clicked(); + + void btnDeleClicked(); + private: Ui::PersonListForm *ui; QStandardItemModel * itemModel; @@ -33,8 +47,12 @@ int tableRowCount = 8; int tableColCount = 5; + int currentPage = 0; + int totalPage = 0; + void calcTotalPage(int totalCount); void findPersonList(); + void initPersonTableHeader(); void updatePersonListTable(); signals: diff --git a/PersonListForm.ui b/PersonListForm.ui index 909cbf2..5bc81f5 100644 --- a/PersonListForm.ui +++ b/PersonListForm.ui @@ -233,7 +233,14 @@ - 1 / 1 + 1 + + + + + + + 条记录 diff --git a/dao/BaseDao.h b/dao/BaseDao.h index aa67f80..1ea0c93 100644 --- a/dao/BaseDao.h +++ b/dao/BaseDao.h @@ -1,4 +1,4 @@ -#ifndef BASEDAO_H +#ifndef BASEDAO_H #define BASEDAO_H #include @@ -21,8 +21,8 @@ virtual QVector findRecordsByProperty(QString properName, QVariant properValue) = 0; virtual QString save(QVariantMap object) = 0; - virtual bool edit(QVariantMap newObject, qulonglong id) = 0; - virtual bool dele(qulonglong id) = 0; + virtual bool edit(QVariantMap newObject, QString id) = 0; + virtual bool dele(QString id) = 0; private: diff --git a/dao/FaceDataDao.cpp b/dao/FaceDataDao.cpp index d668b0a..642f3fb 100644 --- a/dao/FaceDataDao.cpp +++ b/dao/FaceDataDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataDao.h" +#include "FaceDataDao.h" FaceDataDao::FaceDataDao(QObject *parent) : BaseDao(parent) { @@ -87,12 +87,12 @@ } } -bool FaceDataDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool FaceDataDao::dele(qulonglong id) +bool FaceDataDao::dele(QString id) { return false; } diff --git a/dao/FaceDataDao.h b/dao/FaceDataDao.h index 2db4a3d..87fce40 100644 --- a/dao/FaceDataDao.h +++ b/dao/FaceDataDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATADAO_H +#ifndef FACEDATADAO_H #define FACEDATADAO_H #include @@ -16,8 +16,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/FaceDataImgDao.cpp b/dao/FaceDataImgDao.cpp index c4e96f8..ce8a72a 100644 --- a/dao/FaceDataImgDao.cpp +++ b/dao/FaceDataImgDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataImgDao.h" +#include "FaceDataImgDao.h" FaceDataImgDao::FaceDataImgDao(QObject *parent) : BaseDao(parent) { @@ -171,7 +171,7 @@ } } -bool FaceDataImgDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataImgDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -196,7 +196,7 @@ return success; } -bool FaceDataImgDao::dele(qulonglong id) +bool FaceDataImgDao::dele(QString id) { return false; } diff --git a/dao/FaceDataImgDao.h b/dao/FaceDataImgDao.h index d249550..868d73a 100644 --- a/dao/FaceDataImgDao.h +++ b/dao/FaceDataImgDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATAIMGDAO_H +#ifndef FACEDATAIMGDAO_H #define FACEDATAIMGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/IrisDataDao.cpp b/dao/IrisDataDao.cpp index 26a68e2..5f1b047 100644 --- a/dao/IrisDataDao.cpp +++ b/dao/IrisDataDao.cpp @@ -1,4 +1,4 @@ -#include "IrisDataDao.h" +#include "IrisDataDao.h" IrisDataDao::IrisDataDao(QObject *parent) : BaseDao(parent) { @@ -95,13 +95,13 @@ } } -bool IrisDataDao::edit(QVariantMap newObject, qulonglong id) +bool IrisDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool IrisDataDao::dele(qulonglong id) +bool IrisDataDao::dele(QString id) { return false; } diff --git a/dao/IrisDataDao.h b/dao/IrisDataDao.h index 76e6267..1289074 100644 --- a/dao/IrisDataDao.h +++ b/dao/IrisDataDao.h @@ -1,4 +1,4 @@ -#ifndef IRISDATADAO_H +#ifndef IRISDATADAO_H #define IRISDATADAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/IrisDataImgDao.cpp b/dao/IrisDataImgDao.cpp index 691762c..18d4ce6 100644 --- a/dao/IrisDataImgDao.cpp +++ b/dao/IrisDataImgDao.cpp @@ -1,4 +1,4 @@ -#include "IrisDataImgDao.h" +#include "IrisDataImgDao.h" IrisDataImgDao::IrisDataImgDao(QObject *parent) : BaseDao(parent) { @@ -182,7 +182,7 @@ } } -bool IrisDataImgDao::edit(QVariantMap newObject, qulonglong id) +bool IrisDataImgDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -219,7 +219,7 @@ return success; } -bool IrisDataImgDao::dele(qulonglong id) +bool IrisDataImgDao::dele(QString id) { return false; } diff --git a/dao/IrisDataImgDao.h b/dao/IrisDataImgDao.h index 5d35d65..f39158a 100644 --- a/dao/IrisDataImgDao.h +++ b/dao/IrisDataImgDao.h @@ -1,4 +1,4 @@ -#ifndef IRISDATAIMGDAO_H +#ifndef IRISDATAIMGDAO_H #define IRISDATAIMGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/RecognitionRecordDao.cpp b/dao/RecognitionRecordDao.cpp index c6a188a..403894a 100644 --- a/dao/RecognitionRecordDao.cpp +++ b/dao/RecognitionRecordDao.cpp @@ -1,4 +1,4 @@ -#include "RecognitionRecordDao.h" +#include "RecognitionRecordDao.h" RecognitionRecordDao::RecognitionRecordDao(QObject *parent) : BaseDao(parent) { @@ -123,12 +123,12 @@ } } -bool RecognitionRecordDao::edit(QVariantMap newObject, qulonglong id) +bool RecognitionRecordDao::edit(QVariantMap newObject, QString id) { return false; } -bool RecognitionRecordDao::dele(qulonglong id) +bool RecognitionRecordDao::dele(QString id) { return false; } diff --git a/dao/RecognitionRecordDao.h b/dao/RecognitionRecordDao.h index 6ef54bf..37572c8 100644 --- a/dao/RecognitionRecordDao.h +++ b/dao/RecognitionRecordDao.h @@ -1,4 +1,4 @@ -#ifndef RECOGNITIONRECORDDAO_H +#ifndef RECOGNITIONRECORDDAO_H #define RECOGNITIONRECORDDAO_H #include @@ -14,8 +14,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/SysConfigDao.cpp b/dao/SysConfigDao.cpp index 1d51eca..cc1cbeb 100644 --- a/dao/SysConfigDao.cpp +++ b/dao/SysConfigDao.cpp @@ -1,4 +1,4 @@ -#include "SysConfigDao.h" +#include "SysConfigDao.h" SysConfigDao::SysConfigDao(QObject *parent) : BaseDao(parent) { @@ -32,7 +32,6 @@ result.append(item); } - LOG(DEBUG) << QString("查询SYS_CONFIG表的所有记录").toLocal8Bit().data(); return result; } @@ -54,12 +53,12 @@ return "0"; } -bool SysConfigDao::edit(QVariantMap newObject, qulonglong id) +bool SysConfigDao::edit(QVariantMap newObject, QString id) { return false; } -bool SysConfigDao::dele(qulonglong id) +bool SysConfigDao::dele(QString id) { return false; } diff --git a/dao/SysConfigDao.h b/dao/SysConfigDao.h index 8b525cd..e88b993 100644 --- a/dao/SysConfigDao.h +++ b/dao/SysConfigDao.h @@ -1,4 +1,4 @@ -#ifndef SYSCONFIGDAO_H +#ifndef SYSCONFIGDAO_H #define SYSCONFIGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/SysDeptDao.cpp b/dao/SysDeptDao.cpp index d5c5d77..9562e78 100644 --- a/dao/SysDeptDao.cpp +++ b/dao/SysDeptDao.cpp @@ -104,35 +104,7 @@ result.append(item); } - LOG(DEBUG) << QString("根据属性值查询SYS_DEPT表的记录[%1][%2]").arg(count).arg(sql).toStdString(); - return result; -} - -QList SysDeptDao::findDeptTree(QString pid) -{ - // 新建查询 - QSqlQuery query(ConnectionManager::getInstance()->getConnection()); - - // 查询语句 - QString sql = "SELECT * FROM SYS_DEPT WHERE PID = '" + pid + "' ORDER BY NUM"; - - // 执行查询 - query.exec(sql); - - // 返回结果 - QList result; - - // 遍历查询部门树形结构 - while (query.next()) { - QVariantMap item; - QString id = query.value("id").toString(); - item.insert("id", id); - item.insert("pid", query.value("pid").toString()); - item.insert("pids", query.value("pids").toString()); - item.insert("fullname", query.value("fullname").toString()); - result.append(item); - } - + LOG(TRACE) << QString("根据属性值查询SYS_DEPT表的记录[%1][%2]").arg(count).arg(sql).toStdString(); return result; } @@ -140,11 +112,11 @@ { return "0"; } -bool SysDeptDao::edit(QVariantMap newObject, qulonglong id) +bool SysDeptDao::edit(QVariantMap newObject, QString id) { return true; } -bool SysDeptDao::dele(qulonglong id) +bool SysDeptDao::dele(QString id) { return true; } diff --git a/dao/SysDeptDao.h b/dao/SysDeptDao.h index 51582cc..c22da9c 100644 --- a/dao/SysDeptDao.h +++ b/dao/SysDeptDao.h @@ -14,12 +14,11 @@ QVariantMap findRecordById(QString id); QVector findRecordsByProperty(QString properName, QVariant properValue); - QList findDeptTree(QString pid); void appendChild(QList * deptTree, QVariantMap node); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); private: diff --git a/CasicBioRecWin.cpp b/CasicBioRecWin.cpp index 562f7ca..81d4615 100644 --- a/CasicBioRecWin.cpp +++ b/CasicBioRecWin.cpp @@ -9,8 +9,10 @@ { ui->setupUi(this); + // 程序启动时初始化缓存的数据 this->initCacheData(); + // 设置窗口透明和大小、位置 this->setWindowFlags(Qt::FramelessWindowHint); this->move(0, 0); this->resize(SettingConfig::getInstance().WINDOW_WIDTH, @@ -19,8 +21,10 @@ // 通过调色板的颜色来设置窗口的统一背景色 qApp->setPalette(QPalette(QColor(SettingConfig::getInstance().WINDOW_BACKGROUND_COLOR))); + // 初始化各个form界面并绑定切换响应函数 this->initFormsPtr(); + // 打印日志 LOG(INFO) << QString("应用程序启动成功[Application Startup Success]").toStdString(); } diff --git a/PersonListForm.cpp b/PersonListForm.cpp index 77fc565..e479626 100644 --- a/PersonListForm.cpp +++ b/PersonListForm.cpp @@ -21,26 +21,128 @@ ui->vsTableTop->changeSize(0, 20); ui->vsContentBottom->changeSize(0, 40); - itemModel = new QStandardItemModel(this); + // 初始化空的人员列表表格 + initPersonTableHeader(); + // 初始化部门下拉列表框 + SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); +} + +PersonListForm::~PersonListForm() +{ + delete ui; +} + +void PersonListForm::keyPressEvent(QKeyEvent * event) +{ + switch (event->key()) { + case Qt::Key_Return: // 小键盘的Enter键 + case Qt::Key_Enter: // Enter键 + currentPage = 0; + this->findPersonList(); + break; + + default: + QWidget::keyPressEvent(event); + } +} + +void PersonListForm::calcTotalPage(int totalCount) +{ + double temp = (totalCount * 1.0) / (tableRowCount * 1.0); + totalPage = ceil(temp); +} + +void PersonListForm::findPersonList() +{ + SysPersonDao personDao; + + // 获取查询条件 + QString name = ui->inputName->text(); + QString dept = ui->selectDept->currentData().toString(); + + // 计算分页查询的偏移量 + qint16 offset = currentPage * tableRowCount; + + // 查询总条数并计算总页数 + int totalCount = personDao.findRecordCountByNameAndDept(name, dept); + calcTotalPage(totalCount); + + // 赋值表格内容 + QVector perList = personDao.findRecordsByNameAndDept(name, dept, tableRowCount, offset); + + // 有数据且查询结果为空 则重新查询上一页 + if (totalCount > 0 && perList.isEmpty()) + { + // 触发查询上一页的操作 后续操作不再执行 + emit ui->btnPre->clicked(); + return ; + } + + this->personList->clear(); + for (int i = 0; i < perList.size(); i++) { + QVariantMap person = perList.at(i); + this->personList->append(person); + } + + // 更新显示表格 + this->updatePersonListTable(); + + // 更新页码 + if (totalCount == 0) + { + ui->labCurrPage->setText("0"); + } else + { + ui->labCurrPage->setText(QString("%1 / %2 , %3").arg(currentPage + 1).arg(totalPage).arg(totalCount)); + } +} + +void PersonListForm::initPersonTableHeader() +{ + itemModel = new QStandardItemModel(this); personList = new QList(); - SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); - + // 添加表头 QStringList header; header << "员工编号" << "姓名" << "部门 "<< "采集特征" << "操作"; itemModel->setHorizontalHeaderLabels(header); - for (int i = 0; i < tableRowCount; i++) { - QList row; - for ( int j = 0; j < tableColCount; j++) { - itemModel->setItem(i, j, new QStandardItem(QString(""))); - itemModel->item(i, j)->setTextAlignment(Qt::AlignCenter); - } - } + // 设置表头的宽度为固定值 不可调整 + ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); +} + +void PersonListForm::updatePersonListTable() +{ + // 清除表格原有数据 + itemModel->removeRows(0, itemModel->rowCount()); + ui->personListTable->setModel(itemModel); - ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); + // 判断是否有分页 + int max = tableRowCount > personList->size() ? personList->size() : tableRowCount; + for (int i = 0; i < max; i++) { + QList row; + itemModel->setItem(i, 0, new QStandardItem(personList->at(i).find("person_code")->toString())); + itemModel->item(i, 0)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 1, new QStandardItem(personList->at(i).find("name")->toString())); + itemModel->item(i, 1)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 2, new QStandardItem(personList->at(i).find("deptname")->toString())); + itemModel->item(i, 2)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 3, new QStandardItem(QString("iris face"))); + itemModel->item(i, 3)->setTextAlignment(Qt::AlignCenter); + + QPushButton * btnDele = new QPushButton("删除"); + btnDele->setProperty("personId", personList->at(i).find("id")->toString()); + btnDele->setProperty("class", "btnDelete"); + connect(btnDele, &QPushButton::clicked, + this, &PersonListForm::btnDeleClicked); + ui->personListTable->setIndexWidget(itemModel->index(i, 4), btnDele); + } + // 设置每行的高度 for ( int i = 0; i < tableRowCount; i++) { @@ -55,27 +157,6 @@ ui->personListTable->setColumnWidth(4, 150); } -PersonListForm::~PersonListForm() -{ - delete ui; -} - -void PersonListForm::findPersonList() -{ - SysPersonDao personDao; - QVector perList = personDao.findAllRecord(); - this->personList->clear(); - for (int i = 0; i < perList.size(); i++) { - QVariantMap person = perList.at(i); - this->personList->append(person); - } -} - -void PersonListForm::updatePersonListTable() -{ - -} - void PersonListForm::on_btnRegist_clicked() { emit switchToRegistForm("0"); @@ -90,3 +171,56 @@ { emit backToHomePage(); } + +void PersonListForm::on_selectDept_currentIndexChanged(int index) +{ + currentPage = 0; + this->findPersonList(); +} + +void PersonListForm::on_btnFirst_clicked() +{ + // 第一页 + currentPage = 0; + findPersonList(); +} + +void PersonListForm::on_btnLast_clicked() +{ + // 最后一页 + currentPage = totalPage - 1; + findPersonList(); +} + +void PersonListForm::on_btnPre_clicked() +{ + // 上一页 + if (currentPage > 0) + { + currentPage = currentPage - 1; + } + findPersonList(); +} + +void PersonListForm::on_btnNext_clicked() +{ + // 下一页 + if (currentPage < totalPage - 1) + { + currentPage++; + } + findPersonList(); +} + +void PersonListForm::btnDeleClicked() +{ + // 获取发送者的信息 + QPushButton * senderObj = (QPushButton *) sender(); + QString personId = senderObj->property("personId").toString(); + SysPersonDao personDao; + bool succ = personDao.dele(personId); + if (succ == 1) + { + findPersonList(); + } +} diff --git a/PersonListForm.h b/PersonListForm.h index 236bc53..cce03a3 100644 --- a/PersonListForm.h +++ b/PersonListForm.h @@ -19,6 +19,8 @@ explicit PersonListForm(QWidget *parent = nullptr); ~PersonListForm(); + void keyPressEvent(QKeyEvent * event); + private slots: void on_btnRegist_clicked(); @@ -26,6 +28,18 @@ void on_btnBack_clicked(); + void on_selectDept_currentIndexChanged(int index); + + void on_btnFirst_clicked(); + + void on_btnLast_clicked(); + + void on_btnPre_clicked(); + + void on_btnNext_clicked(); + + void btnDeleClicked(); + private: Ui::PersonListForm *ui; QStandardItemModel * itemModel; @@ -33,8 +47,12 @@ int tableRowCount = 8; int tableColCount = 5; + int currentPage = 0; + int totalPage = 0; + void calcTotalPage(int totalCount); void findPersonList(); + void initPersonTableHeader(); void updatePersonListTable(); signals: diff --git a/PersonListForm.ui b/PersonListForm.ui index 909cbf2..5bc81f5 100644 --- a/PersonListForm.ui +++ b/PersonListForm.ui @@ -233,7 +233,14 @@ - 1 / 1 + 1 + + + + + + + 条记录 diff --git a/dao/BaseDao.h b/dao/BaseDao.h index aa67f80..1ea0c93 100644 --- a/dao/BaseDao.h +++ b/dao/BaseDao.h @@ -1,4 +1,4 @@ -#ifndef BASEDAO_H +#ifndef BASEDAO_H #define BASEDAO_H #include @@ -21,8 +21,8 @@ virtual QVector findRecordsByProperty(QString properName, QVariant properValue) = 0; virtual QString save(QVariantMap object) = 0; - virtual bool edit(QVariantMap newObject, qulonglong id) = 0; - virtual bool dele(qulonglong id) = 0; + virtual bool edit(QVariantMap newObject, QString id) = 0; + virtual bool dele(QString id) = 0; private: diff --git a/dao/FaceDataDao.cpp b/dao/FaceDataDao.cpp index d668b0a..642f3fb 100644 --- a/dao/FaceDataDao.cpp +++ b/dao/FaceDataDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataDao.h" +#include "FaceDataDao.h" FaceDataDao::FaceDataDao(QObject *parent) : BaseDao(parent) { @@ -87,12 +87,12 @@ } } -bool FaceDataDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool FaceDataDao::dele(qulonglong id) +bool FaceDataDao::dele(QString id) { return false; } diff --git a/dao/FaceDataDao.h b/dao/FaceDataDao.h index 2db4a3d..87fce40 100644 --- a/dao/FaceDataDao.h +++ b/dao/FaceDataDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATADAO_H +#ifndef FACEDATADAO_H #define FACEDATADAO_H #include @@ -16,8 +16,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/FaceDataImgDao.cpp b/dao/FaceDataImgDao.cpp index c4e96f8..ce8a72a 100644 --- a/dao/FaceDataImgDao.cpp +++ b/dao/FaceDataImgDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataImgDao.h" +#include "FaceDataImgDao.h" FaceDataImgDao::FaceDataImgDao(QObject *parent) : BaseDao(parent) { @@ -171,7 +171,7 @@ } } -bool FaceDataImgDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataImgDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -196,7 +196,7 @@ return success; } -bool FaceDataImgDao::dele(qulonglong id) +bool FaceDataImgDao::dele(QString id) { return false; } diff --git a/dao/FaceDataImgDao.h b/dao/FaceDataImgDao.h index d249550..868d73a 100644 --- a/dao/FaceDataImgDao.h +++ b/dao/FaceDataImgDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATAIMGDAO_H +#ifndef FACEDATAIMGDAO_H #define FACEDATAIMGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/IrisDataDao.cpp b/dao/IrisDataDao.cpp index 26a68e2..5f1b047 100644 --- a/dao/IrisDataDao.cpp +++ b/dao/IrisDataDao.cpp @@ -1,4 +1,4 @@ -#include "IrisDataDao.h" +#include "IrisDataDao.h" IrisDataDao::IrisDataDao(QObject *parent) : BaseDao(parent) { @@ -95,13 +95,13 @@ } } -bool IrisDataDao::edit(QVariantMap newObject, qulonglong id) +bool IrisDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool IrisDataDao::dele(qulonglong id) +bool IrisDataDao::dele(QString id) { return false; } diff --git a/dao/IrisDataDao.h b/dao/IrisDataDao.h index 76e6267..1289074 100644 --- a/dao/IrisDataDao.h +++ b/dao/IrisDataDao.h @@ -1,4 +1,4 @@ -#ifndef IRISDATADAO_H +#ifndef IRISDATADAO_H #define IRISDATADAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/IrisDataImgDao.cpp b/dao/IrisDataImgDao.cpp index 691762c..18d4ce6 100644 --- a/dao/IrisDataImgDao.cpp +++ b/dao/IrisDataImgDao.cpp @@ -1,4 +1,4 @@ -#include "IrisDataImgDao.h" +#include "IrisDataImgDao.h" IrisDataImgDao::IrisDataImgDao(QObject *parent) : BaseDao(parent) { @@ -182,7 +182,7 @@ } } -bool IrisDataImgDao::edit(QVariantMap newObject, qulonglong id) +bool IrisDataImgDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -219,7 +219,7 @@ return success; } -bool IrisDataImgDao::dele(qulonglong id) +bool IrisDataImgDao::dele(QString id) { return false; } diff --git a/dao/IrisDataImgDao.h b/dao/IrisDataImgDao.h index 5d35d65..f39158a 100644 --- a/dao/IrisDataImgDao.h +++ b/dao/IrisDataImgDao.h @@ -1,4 +1,4 @@ -#ifndef IRISDATAIMGDAO_H +#ifndef IRISDATAIMGDAO_H #define IRISDATAIMGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/RecognitionRecordDao.cpp b/dao/RecognitionRecordDao.cpp index c6a188a..403894a 100644 --- a/dao/RecognitionRecordDao.cpp +++ b/dao/RecognitionRecordDao.cpp @@ -1,4 +1,4 @@ -#include "RecognitionRecordDao.h" +#include "RecognitionRecordDao.h" RecognitionRecordDao::RecognitionRecordDao(QObject *parent) : BaseDao(parent) { @@ -123,12 +123,12 @@ } } -bool RecognitionRecordDao::edit(QVariantMap newObject, qulonglong id) +bool RecognitionRecordDao::edit(QVariantMap newObject, QString id) { return false; } -bool RecognitionRecordDao::dele(qulonglong id) +bool RecognitionRecordDao::dele(QString id) { return false; } diff --git a/dao/RecognitionRecordDao.h b/dao/RecognitionRecordDao.h index 6ef54bf..37572c8 100644 --- a/dao/RecognitionRecordDao.h +++ b/dao/RecognitionRecordDao.h @@ -1,4 +1,4 @@ -#ifndef RECOGNITIONRECORDDAO_H +#ifndef RECOGNITIONRECORDDAO_H #define RECOGNITIONRECORDDAO_H #include @@ -14,8 +14,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/SysConfigDao.cpp b/dao/SysConfigDao.cpp index 1d51eca..cc1cbeb 100644 --- a/dao/SysConfigDao.cpp +++ b/dao/SysConfigDao.cpp @@ -1,4 +1,4 @@ -#include "SysConfigDao.h" +#include "SysConfigDao.h" SysConfigDao::SysConfigDao(QObject *parent) : BaseDao(parent) { @@ -32,7 +32,6 @@ result.append(item); } - LOG(DEBUG) << QString("查询SYS_CONFIG表的所有记录").toLocal8Bit().data(); return result; } @@ -54,12 +53,12 @@ return "0"; } -bool SysConfigDao::edit(QVariantMap newObject, qulonglong id) +bool SysConfigDao::edit(QVariantMap newObject, QString id) { return false; } -bool SysConfigDao::dele(qulonglong id) +bool SysConfigDao::dele(QString id) { return false; } diff --git a/dao/SysConfigDao.h b/dao/SysConfigDao.h index 8b525cd..e88b993 100644 --- a/dao/SysConfigDao.h +++ b/dao/SysConfigDao.h @@ -1,4 +1,4 @@ -#ifndef SYSCONFIGDAO_H +#ifndef SYSCONFIGDAO_H #define SYSCONFIGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/SysDeptDao.cpp b/dao/SysDeptDao.cpp index d5c5d77..9562e78 100644 --- a/dao/SysDeptDao.cpp +++ b/dao/SysDeptDao.cpp @@ -104,35 +104,7 @@ result.append(item); } - LOG(DEBUG) << QString("根据属性值查询SYS_DEPT表的记录[%1][%2]").arg(count).arg(sql).toStdString(); - return result; -} - -QList SysDeptDao::findDeptTree(QString pid) -{ - // 新建查询 - QSqlQuery query(ConnectionManager::getInstance()->getConnection()); - - // 查询语句 - QString sql = "SELECT * FROM SYS_DEPT WHERE PID = '" + pid + "' ORDER BY NUM"; - - // 执行查询 - query.exec(sql); - - // 返回结果 - QList result; - - // 遍历查询部门树形结构 - while (query.next()) { - QVariantMap item; - QString id = query.value("id").toString(); - item.insert("id", id); - item.insert("pid", query.value("pid").toString()); - item.insert("pids", query.value("pids").toString()); - item.insert("fullname", query.value("fullname").toString()); - result.append(item); - } - + LOG(TRACE) << QString("根据属性值查询SYS_DEPT表的记录[%1][%2]").arg(count).arg(sql).toStdString(); return result; } @@ -140,11 +112,11 @@ { return "0"; } -bool SysDeptDao::edit(QVariantMap newObject, qulonglong id) +bool SysDeptDao::edit(QVariantMap newObject, QString id) { return true; } -bool SysDeptDao::dele(qulonglong id) +bool SysDeptDao::dele(QString id) { return true; } diff --git a/dao/SysDeptDao.h b/dao/SysDeptDao.h index 51582cc..c22da9c 100644 --- a/dao/SysDeptDao.h +++ b/dao/SysDeptDao.h @@ -14,12 +14,11 @@ QVariantMap findRecordById(QString id); QVector findRecordsByProperty(QString properName, QVariant properValue); - QList findDeptTree(QString pid); void appendChild(QList * deptTree, QVariantMap node); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); private: diff --git a/dao/SysPersonDao.cpp b/dao/SysPersonDao.cpp index cd232ca..6a0525d 100644 --- a/dao/SysPersonDao.cpp +++ b/dao/SysPersonDao.cpp @@ -6,49 +6,6 @@ } -QVector SysPersonDao::findAllDept() -{ - // 新建查询 - QSqlQuery query(ConnectionManager::getInstance()->getConnection()); - - // 查询语句 - QString sql = "SELECT * FROM SYS_DEPT WHERE PID != '-1'"; - - // 执行查询 - query.exec(sql); - - // 获取结果集的大小 - int count = 0; - - // 返回结果 - QVector result; - - // 遍历查询结果 - while (query.next()) { - QVariantMap item; - count++; - item.insert("id", query.value("id").toString()); - item.insert("pid", query.value("pid").toString()); - item.insert("pids", query.value("pids").toString()); - item.insert("fullname", query.value("fullname").toString()); - QStringList vector = query.value("pids").toString().split(","); - if (vector.count() == 2) { //集团 - result.append(item); - } else { - for (int i = 0; i < result.size(); i++) { - if (result[i].value("id") == query.value("pid").toString()) { - result.insert(i + 1, item); - break; - } - } - } - } - - LOG(DEBUG) << QString("查询表[SYS_DEPT]的所有记录[%1][%2]").arg(count).arg(sql).toStdString(); - - return result; -} - QVector SysPersonDao::findAllRecord() { // 新建查询 @@ -132,14 +89,55 @@ return result; } -QVector SysPersonDao::findRecordsByNameAndDept(QString name, QString dept) +int SysPersonDao::findRecordCountByNameAndDept(QString name, QString dept) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); // 查询语句 - QString sql = "SELECT * FROM SYS_PERSON LEFT JOIN SYS_DEPT ON SYS_PERSON.DEPTID = SYS_DEPT.ID WHERE SYS_PERSON.DELFLAG = '0' AND SYS_PERSON.NAME = '%1' AND SYS_PERSON.DEPTID = '%2'"; - sql = sql.arg(name).arg(dept); + QString sql = "SELECT COUNT(P.ID) AS RECCT FROM SYS_PERSON P LEFT JOIN SYS_DEPT D ON P.DEPTID = D.ID WHERE P.DELFLAG = '0'"; + if (name.isEmpty() == false) + { + sql += " AND P.NAME LIKE '%" + name + "%'"; + } + if (dept.isEmpty() == false && dept.indexOf("-1") < 0) + { + sql += QString(" AND (P.DEPTID = '%1') OR (D.PIDS LIKE '%,%1,%')").arg(dept); + } + + // 执行查询 + query.exec(sql); + + // 返回结果 + int result; + + // 遍历查询结果 + if (query.next()) { + result = query.value("RECCT").toInt(); + } + + LOG(TRACE) << QString("根据姓名和部门查询SYS_PERSON记录总数[%1][%2]").arg(result).arg(sql).toStdString(); + + return result; +} + +QVector SysPersonDao::findRecordsByNameAndDept(QString name, QString dept, qint8 limit, qint16 offset) +{ + // 新建查询 + QSqlQuery query(ConnectionManager::getInstance()->getConnection()); + + // 查询语句 + QString sql = "SELECT * FROM SYS_PERSON P LEFT JOIN SYS_DEPT D ON P.DEPTID = D.ID WHERE P.DELFLAG = '0'"; + if (name.isEmpty() == false) + { + sql += " AND P.NAME LIKE '%" + name + "%'"; + } + if (dept.isEmpty() == false && dept.indexOf("-1") < 0) + { + sql += QString(" AND (P.DEPTID = '%1') OR (D.PIDS LIKE '%,%1,%')").arg(dept); + } + + sql += QString(" LIMIT %1 OFFSET %2").arg(limit).arg(offset); // 执行查询 query.exec(sql); @@ -156,7 +154,7 @@ count++; - item.insert("id", query.value("id").toLongLong()); + item.insert("id", query.value("id").toString()); item.insert("delflag", query.value("delflag").toString()); item.insert("createtime", query.value("createtime").toString()); item.insert("updatetime", query.value("updatetime").toString()); @@ -172,7 +170,7 @@ result.append(item); } - LOG(DEBUG) << QString("根据姓名和部门查询SYS_PERSON表的记录[%1][%2]").arg(count).arg(sql).toStdString(); + LOG(TRACE) << QString("根据姓名和部门分页查询SYS_PERSON表的记录[%1][%2]").arg(count).arg(sql).toStdString(); return result; } @@ -317,7 +315,7 @@ } } -bool SysPersonDao::edit(QVariantMap newObject, qulonglong id) +bool SysPersonDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -360,7 +358,7 @@ return success; } -bool SysPersonDao::dele(qulonglong id) +bool SysPersonDao::dele(QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -369,7 +367,7 @@ qint64 tmms = QDateTime::currentDateTime().toMSecsSinceEpoch(); // UPDATE语句 - QString sql = QString("UPDATE SYS_PERSON SET UPDATETIME = '%1', DELFLAG = '%2' WHERE ID = %3") + QString sql = QString("UPDATE SYS_PERSON SET UPDATETIME = '%1', DELFLAG = '%2' WHERE ID = '%3'") .arg(tm).arg(tmms).arg(id); LOG(DEBUG) << sql.toStdString(); diff --git a/CasicBioRecWin.cpp b/CasicBioRecWin.cpp index 562f7ca..81d4615 100644 --- a/CasicBioRecWin.cpp +++ b/CasicBioRecWin.cpp @@ -9,8 +9,10 @@ { ui->setupUi(this); + // 程序启动时初始化缓存的数据 this->initCacheData(); + // 设置窗口透明和大小、位置 this->setWindowFlags(Qt::FramelessWindowHint); this->move(0, 0); this->resize(SettingConfig::getInstance().WINDOW_WIDTH, @@ -19,8 +21,10 @@ // 通过调色板的颜色来设置窗口的统一背景色 qApp->setPalette(QPalette(QColor(SettingConfig::getInstance().WINDOW_BACKGROUND_COLOR))); + // 初始化各个form界面并绑定切换响应函数 this->initFormsPtr(); + // 打印日志 LOG(INFO) << QString("应用程序启动成功[Application Startup Success]").toStdString(); } diff --git a/PersonListForm.cpp b/PersonListForm.cpp index 77fc565..e479626 100644 --- a/PersonListForm.cpp +++ b/PersonListForm.cpp @@ -21,26 +21,128 @@ ui->vsTableTop->changeSize(0, 20); ui->vsContentBottom->changeSize(0, 40); - itemModel = new QStandardItemModel(this); + // 初始化空的人员列表表格 + initPersonTableHeader(); + // 初始化部门下拉列表框 + SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); +} + +PersonListForm::~PersonListForm() +{ + delete ui; +} + +void PersonListForm::keyPressEvent(QKeyEvent * event) +{ + switch (event->key()) { + case Qt::Key_Return: // 小键盘的Enter键 + case Qt::Key_Enter: // Enter键 + currentPage = 0; + this->findPersonList(); + break; + + default: + QWidget::keyPressEvent(event); + } +} + +void PersonListForm::calcTotalPage(int totalCount) +{ + double temp = (totalCount * 1.0) / (tableRowCount * 1.0); + totalPage = ceil(temp); +} + +void PersonListForm::findPersonList() +{ + SysPersonDao personDao; + + // 获取查询条件 + QString name = ui->inputName->text(); + QString dept = ui->selectDept->currentData().toString(); + + // 计算分页查询的偏移量 + qint16 offset = currentPage * tableRowCount; + + // 查询总条数并计算总页数 + int totalCount = personDao.findRecordCountByNameAndDept(name, dept); + calcTotalPage(totalCount); + + // 赋值表格内容 + QVector perList = personDao.findRecordsByNameAndDept(name, dept, tableRowCount, offset); + + // 有数据且查询结果为空 则重新查询上一页 + if (totalCount > 0 && perList.isEmpty()) + { + // 触发查询上一页的操作 后续操作不再执行 + emit ui->btnPre->clicked(); + return ; + } + + this->personList->clear(); + for (int i = 0; i < perList.size(); i++) { + QVariantMap person = perList.at(i); + this->personList->append(person); + } + + // 更新显示表格 + this->updatePersonListTable(); + + // 更新页码 + if (totalCount == 0) + { + ui->labCurrPage->setText("0"); + } else + { + ui->labCurrPage->setText(QString("%1 / %2 , %3").arg(currentPage + 1).arg(totalPage).arg(totalCount)); + } +} + +void PersonListForm::initPersonTableHeader() +{ + itemModel = new QStandardItemModel(this); personList = new QList(); - SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); - + // 添加表头 QStringList header; header << "员工编号" << "姓名" << "部门 "<< "采集特征" << "操作"; itemModel->setHorizontalHeaderLabels(header); - for (int i = 0; i < tableRowCount; i++) { - QList row; - for ( int j = 0; j < tableColCount; j++) { - itemModel->setItem(i, j, new QStandardItem(QString(""))); - itemModel->item(i, j)->setTextAlignment(Qt::AlignCenter); - } - } + // 设置表头的宽度为固定值 不可调整 + ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); +} + +void PersonListForm::updatePersonListTable() +{ + // 清除表格原有数据 + itemModel->removeRows(0, itemModel->rowCount()); + ui->personListTable->setModel(itemModel); - ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); + // 判断是否有分页 + int max = tableRowCount > personList->size() ? personList->size() : tableRowCount; + for (int i = 0; i < max; i++) { + QList row; + itemModel->setItem(i, 0, new QStandardItem(personList->at(i).find("person_code")->toString())); + itemModel->item(i, 0)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 1, new QStandardItem(personList->at(i).find("name")->toString())); + itemModel->item(i, 1)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 2, new QStandardItem(personList->at(i).find("deptname")->toString())); + itemModel->item(i, 2)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 3, new QStandardItem(QString("iris face"))); + itemModel->item(i, 3)->setTextAlignment(Qt::AlignCenter); + + QPushButton * btnDele = new QPushButton("删除"); + btnDele->setProperty("personId", personList->at(i).find("id")->toString()); + btnDele->setProperty("class", "btnDelete"); + connect(btnDele, &QPushButton::clicked, + this, &PersonListForm::btnDeleClicked); + ui->personListTable->setIndexWidget(itemModel->index(i, 4), btnDele); + } + // 设置每行的高度 for ( int i = 0; i < tableRowCount; i++) { @@ -55,27 +157,6 @@ ui->personListTable->setColumnWidth(4, 150); } -PersonListForm::~PersonListForm() -{ - delete ui; -} - -void PersonListForm::findPersonList() -{ - SysPersonDao personDao; - QVector perList = personDao.findAllRecord(); - this->personList->clear(); - for (int i = 0; i < perList.size(); i++) { - QVariantMap person = perList.at(i); - this->personList->append(person); - } -} - -void PersonListForm::updatePersonListTable() -{ - -} - void PersonListForm::on_btnRegist_clicked() { emit switchToRegistForm("0"); @@ -90,3 +171,56 @@ { emit backToHomePage(); } + +void PersonListForm::on_selectDept_currentIndexChanged(int index) +{ + currentPage = 0; + this->findPersonList(); +} + +void PersonListForm::on_btnFirst_clicked() +{ + // 第一页 + currentPage = 0; + findPersonList(); +} + +void PersonListForm::on_btnLast_clicked() +{ + // 最后一页 + currentPage = totalPage - 1; + findPersonList(); +} + +void PersonListForm::on_btnPre_clicked() +{ + // 上一页 + if (currentPage > 0) + { + currentPage = currentPage - 1; + } + findPersonList(); +} + +void PersonListForm::on_btnNext_clicked() +{ + // 下一页 + if (currentPage < totalPage - 1) + { + currentPage++; + } + findPersonList(); +} + +void PersonListForm::btnDeleClicked() +{ + // 获取发送者的信息 + QPushButton * senderObj = (QPushButton *) sender(); + QString personId = senderObj->property("personId").toString(); + SysPersonDao personDao; + bool succ = personDao.dele(personId); + if (succ == 1) + { + findPersonList(); + } +} diff --git a/PersonListForm.h b/PersonListForm.h index 236bc53..cce03a3 100644 --- a/PersonListForm.h +++ b/PersonListForm.h @@ -19,6 +19,8 @@ explicit PersonListForm(QWidget *parent = nullptr); ~PersonListForm(); + void keyPressEvent(QKeyEvent * event); + private slots: void on_btnRegist_clicked(); @@ -26,6 +28,18 @@ void on_btnBack_clicked(); + void on_selectDept_currentIndexChanged(int index); + + void on_btnFirst_clicked(); + + void on_btnLast_clicked(); + + void on_btnPre_clicked(); + + void on_btnNext_clicked(); + + void btnDeleClicked(); + private: Ui::PersonListForm *ui; QStandardItemModel * itemModel; @@ -33,8 +47,12 @@ int tableRowCount = 8; int tableColCount = 5; + int currentPage = 0; + int totalPage = 0; + void calcTotalPage(int totalCount); void findPersonList(); + void initPersonTableHeader(); void updatePersonListTable(); signals: diff --git a/PersonListForm.ui b/PersonListForm.ui index 909cbf2..5bc81f5 100644 --- a/PersonListForm.ui +++ b/PersonListForm.ui @@ -233,7 +233,14 @@ - 1 / 1 + 1 + + + + + + + 条记录 diff --git a/dao/BaseDao.h b/dao/BaseDao.h index aa67f80..1ea0c93 100644 --- a/dao/BaseDao.h +++ b/dao/BaseDao.h @@ -1,4 +1,4 @@ -#ifndef BASEDAO_H +#ifndef BASEDAO_H #define BASEDAO_H #include @@ -21,8 +21,8 @@ virtual QVector findRecordsByProperty(QString properName, QVariant properValue) = 0; virtual QString save(QVariantMap object) = 0; - virtual bool edit(QVariantMap newObject, qulonglong id) = 0; - virtual bool dele(qulonglong id) = 0; + virtual bool edit(QVariantMap newObject, QString id) = 0; + virtual bool dele(QString id) = 0; private: diff --git a/dao/FaceDataDao.cpp b/dao/FaceDataDao.cpp index d668b0a..642f3fb 100644 --- a/dao/FaceDataDao.cpp +++ b/dao/FaceDataDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataDao.h" +#include "FaceDataDao.h" FaceDataDao::FaceDataDao(QObject *parent) : BaseDao(parent) { @@ -87,12 +87,12 @@ } } -bool FaceDataDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool FaceDataDao::dele(qulonglong id) +bool FaceDataDao::dele(QString id) { return false; } diff --git a/dao/FaceDataDao.h b/dao/FaceDataDao.h index 2db4a3d..87fce40 100644 --- a/dao/FaceDataDao.h +++ b/dao/FaceDataDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATADAO_H +#ifndef FACEDATADAO_H #define FACEDATADAO_H #include @@ -16,8 +16,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/FaceDataImgDao.cpp b/dao/FaceDataImgDao.cpp index c4e96f8..ce8a72a 100644 --- a/dao/FaceDataImgDao.cpp +++ b/dao/FaceDataImgDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataImgDao.h" +#include "FaceDataImgDao.h" FaceDataImgDao::FaceDataImgDao(QObject *parent) : BaseDao(parent) { @@ -171,7 +171,7 @@ } } -bool FaceDataImgDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataImgDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -196,7 +196,7 @@ return success; } -bool FaceDataImgDao::dele(qulonglong id) +bool FaceDataImgDao::dele(QString id) { return false; } diff --git a/dao/FaceDataImgDao.h b/dao/FaceDataImgDao.h index d249550..868d73a 100644 --- a/dao/FaceDataImgDao.h +++ b/dao/FaceDataImgDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATAIMGDAO_H +#ifndef FACEDATAIMGDAO_H #define FACEDATAIMGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/IrisDataDao.cpp b/dao/IrisDataDao.cpp index 26a68e2..5f1b047 100644 --- a/dao/IrisDataDao.cpp +++ b/dao/IrisDataDao.cpp @@ -1,4 +1,4 @@ -#include "IrisDataDao.h" +#include "IrisDataDao.h" IrisDataDao::IrisDataDao(QObject *parent) : BaseDao(parent) { @@ -95,13 +95,13 @@ } } -bool IrisDataDao::edit(QVariantMap newObject, qulonglong id) +bool IrisDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool IrisDataDao::dele(qulonglong id) +bool IrisDataDao::dele(QString id) { return false; } diff --git a/dao/IrisDataDao.h b/dao/IrisDataDao.h index 76e6267..1289074 100644 --- a/dao/IrisDataDao.h +++ b/dao/IrisDataDao.h @@ -1,4 +1,4 @@ -#ifndef IRISDATADAO_H +#ifndef IRISDATADAO_H #define IRISDATADAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/IrisDataImgDao.cpp b/dao/IrisDataImgDao.cpp index 691762c..18d4ce6 100644 --- a/dao/IrisDataImgDao.cpp +++ b/dao/IrisDataImgDao.cpp @@ -1,4 +1,4 @@ -#include "IrisDataImgDao.h" +#include "IrisDataImgDao.h" IrisDataImgDao::IrisDataImgDao(QObject *parent) : BaseDao(parent) { @@ -182,7 +182,7 @@ } } -bool IrisDataImgDao::edit(QVariantMap newObject, qulonglong id) +bool IrisDataImgDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -219,7 +219,7 @@ return success; } -bool IrisDataImgDao::dele(qulonglong id) +bool IrisDataImgDao::dele(QString id) { return false; } diff --git a/dao/IrisDataImgDao.h b/dao/IrisDataImgDao.h index 5d35d65..f39158a 100644 --- a/dao/IrisDataImgDao.h +++ b/dao/IrisDataImgDao.h @@ -1,4 +1,4 @@ -#ifndef IRISDATAIMGDAO_H +#ifndef IRISDATAIMGDAO_H #define IRISDATAIMGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/RecognitionRecordDao.cpp b/dao/RecognitionRecordDao.cpp index c6a188a..403894a 100644 --- a/dao/RecognitionRecordDao.cpp +++ b/dao/RecognitionRecordDao.cpp @@ -1,4 +1,4 @@ -#include "RecognitionRecordDao.h" +#include "RecognitionRecordDao.h" RecognitionRecordDao::RecognitionRecordDao(QObject *parent) : BaseDao(parent) { @@ -123,12 +123,12 @@ } } -bool RecognitionRecordDao::edit(QVariantMap newObject, qulonglong id) +bool RecognitionRecordDao::edit(QVariantMap newObject, QString id) { return false; } -bool RecognitionRecordDao::dele(qulonglong id) +bool RecognitionRecordDao::dele(QString id) { return false; } diff --git a/dao/RecognitionRecordDao.h b/dao/RecognitionRecordDao.h index 6ef54bf..37572c8 100644 --- a/dao/RecognitionRecordDao.h +++ b/dao/RecognitionRecordDao.h @@ -1,4 +1,4 @@ -#ifndef RECOGNITIONRECORDDAO_H +#ifndef RECOGNITIONRECORDDAO_H #define RECOGNITIONRECORDDAO_H #include @@ -14,8 +14,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/SysConfigDao.cpp b/dao/SysConfigDao.cpp index 1d51eca..cc1cbeb 100644 --- a/dao/SysConfigDao.cpp +++ b/dao/SysConfigDao.cpp @@ -1,4 +1,4 @@ -#include "SysConfigDao.h" +#include "SysConfigDao.h" SysConfigDao::SysConfigDao(QObject *parent) : BaseDao(parent) { @@ -32,7 +32,6 @@ result.append(item); } - LOG(DEBUG) << QString("查询SYS_CONFIG表的所有记录").toLocal8Bit().data(); return result; } @@ -54,12 +53,12 @@ return "0"; } -bool SysConfigDao::edit(QVariantMap newObject, qulonglong id) +bool SysConfigDao::edit(QVariantMap newObject, QString id) { return false; } -bool SysConfigDao::dele(qulonglong id) +bool SysConfigDao::dele(QString id) { return false; } diff --git a/dao/SysConfigDao.h b/dao/SysConfigDao.h index 8b525cd..e88b993 100644 --- a/dao/SysConfigDao.h +++ b/dao/SysConfigDao.h @@ -1,4 +1,4 @@ -#ifndef SYSCONFIGDAO_H +#ifndef SYSCONFIGDAO_H #define SYSCONFIGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/SysDeptDao.cpp b/dao/SysDeptDao.cpp index d5c5d77..9562e78 100644 --- a/dao/SysDeptDao.cpp +++ b/dao/SysDeptDao.cpp @@ -104,35 +104,7 @@ result.append(item); } - LOG(DEBUG) << QString("根据属性值查询SYS_DEPT表的记录[%1][%2]").arg(count).arg(sql).toStdString(); - return result; -} - -QList SysDeptDao::findDeptTree(QString pid) -{ - // 新建查询 - QSqlQuery query(ConnectionManager::getInstance()->getConnection()); - - // 查询语句 - QString sql = "SELECT * FROM SYS_DEPT WHERE PID = '" + pid + "' ORDER BY NUM"; - - // 执行查询 - query.exec(sql); - - // 返回结果 - QList result; - - // 遍历查询部门树形结构 - while (query.next()) { - QVariantMap item; - QString id = query.value("id").toString(); - item.insert("id", id); - item.insert("pid", query.value("pid").toString()); - item.insert("pids", query.value("pids").toString()); - item.insert("fullname", query.value("fullname").toString()); - result.append(item); - } - + LOG(TRACE) << QString("根据属性值查询SYS_DEPT表的记录[%1][%2]").arg(count).arg(sql).toStdString(); return result; } @@ -140,11 +112,11 @@ { return "0"; } -bool SysDeptDao::edit(QVariantMap newObject, qulonglong id) +bool SysDeptDao::edit(QVariantMap newObject, QString id) { return true; } -bool SysDeptDao::dele(qulonglong id) +bool SysDeptDao::dele(QString id) { return true; } diff --git a/dao/SysDeptDao.h b/dao/SysDeptDao.h index 51582cc..c22da9c 100644 --- a/dao/SysDeptDao.h +++ b/dao/SysDeptDao.h @@ -14,12 +14,11 @@ QVariantMap findRecordById(QString id); QVector findRecordsByProperty(QString properName, QVariant properValue); - QList findDeptTree(QString pid); void appendChild(QList * deptTree, QVariantMap node); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); private: diff --git a/dao/SysPersonDao.cpp b/dao/SysPersonDao.cpp index cd232ca..6a0525d 100644 --- a/dao/SysPersonDao.cpp +++ b/dao/SysPersonDao.cpp @@ -6,49 +6,6 @@ } -QVector SysPersonDao::findAllDept() -{ - // 新建查询 - QSqlQuery query(ConnectionManager::getInstance()->getConnection()); - - // 查询语句 - QString sql = "SELECT * FROM SYS_DEPT WHERE PID != '-1'"; - - // 执行查询 - query.exec(sql); - - // 获取结果集的大小 - int count = 0; - - // 返回结果 - QVector result; - - // 遍历查询结果 - while (query.next()) { - QVariantMap item; - count++; - item.insert("id", query.value("id").toString()); - item.insert("pid", query.value("pid").toString()); - item.insert("pids", query.value("pids").toString()); - item.insert("fullname", query.value("fullname").toString()); - QStringList vector = query.value("pids").toString().split(","); - if (vector.count() == 2) { //集团 - result.append(item); - } else { - for (int i = 0; i < result.size(); i++) { - if (result[i].value("id") == query.value("pid").toString()) { - result.insert(i + 1, item); - break; - } - } - } - } - - LOG(DEBUG) << QString("查询表[SYS_DEPT]的所有记录[%1][%2]").arg(count).arg(sql).toStdString(); - - return result; -} - QVector SysPersonDao::findAllRecord() { // 新建查询 @@ -132,14 +89,55 @@ return result; } -QVector SysPersonDao::findRecordsByNameAndDept(QString name, QString dept) +int SysPersonDao::findRecordCountByNameAndDept(QString name, QString dept) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); // 查询语句 - QString sql = "SELECT * FROM SYS_PERSON LEFT JOIN SYS_DEPT ON SYS_PERSON.DEPTID = SYS_DEPT.ID WHERE SYS_PERSON.DELFLAG = '0' AND SYS_PERSON.NAME = '%1' AND SYS_PERSON.DEPTID = '%2'"; - sql = sql.arg(name).arg(dept); + QString sql = "SELECT COUNT(P.ID) AS RECCT FROM SYS_PERSON P LEFT JOIN SYS_DEPT D ON P.DEPTID = D.ID WHERE P.DELFLAG = '0'"; + if (name.isEmpty() == false) + { + sql += " AND P.NAME LIKE '%" + name + "%'"; + } + if (dept.isEmpty() == false && dept.indexOf("-1") < 0) + { + sql += QString(" AND (P.DEPTID = '%1') OR (D.PIDS LIKE '%,%1,%')").arg(dept); + } + + // 执行查询 + query.exec(sql); + + // 返回结果 + int result; + + // 遍历查询结果 + if (query.next()) { + result = query.value("RECCT").toInt(); + } + + LOG(TRACE) << QString("根据姓名和部门查询SYS_PERSON记录总数[%1][%2]").arg(result).arg(sql).toStdString(); + + return result; +} + +QVector SysPersonDao::findRecordsByNameAndDept(QString name, QString dept, qint8 limit, qint16 offset) +{ + // 新建查询 + QSqlQuery query(ConnectionManager::getInstance()->getConnection()); + + // 查询语句 + QString sql = "SELECT * FROM SYS_PERSON P LEFT JOIN SYS_DEPT D ON P.DEPTID = D.ID WHERE P.DELFLAG = '0'"; + if (name.isEmpty() == false) + { + sql += " AND P.NAME LIKE '%" + name + "%'"; + } + if (dept.isEmpty() == false && dept.indexOf("-1") < 0) + { + sql += QString(" AND (P.DEPTID = '%1') OR (D.PIDS LIKE '%,%1,%')").arg(dept); + } + + sql += QString(" LIMIT %1 OFFSET %2").arg(limit).arg(offset); // 执行查询 query.exec(sql); @@ -156,7 +154,7 @@ count++; - item.insert("id", query.value("id").toLongLong()); + item.insert("id", query.value("id").toString()); item.insert("delflag", query.value("delflag").toString()); item.insert("createtime", query.value("createtime").toString()); item.insert("updatetime", query.value("updatetime").toString()); @@ -172,7 +170,7 @@ result.append(item); } - LOG(DEBUG) << QString("根据姓名和部门查询SYS_PERSON表的记录[%1][%2]").arg(count).arg(sql).toStdString(); + LOG(TRACE) << QString("根据姓名和部门分页查询SYS_PERSON表的记录[%1][%2]").arg(count).arg(sql).toStdString(); return result; } @@ -317,7 +315,7 @@ } } -bool SysPersonDao::edit(QVariantMap newObject, qulonglong id) +bool SysPersonDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -360,7 +358,7 @@ return success; } -bool SysPersonDao::dele(qulonglong id) +bool SysPersonDao::dele(QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -369,7 +367,7 @@ qint64 tmms = QDateTime::currentDateTime().toMSecsSinceEpoch(); // UPDATE语句 - QString sql = QString("UPDATE SYS_PERSON SET UPDATETIME = '%1', DELFLAG = '%2' WHERE ID = %3") + QString sql = QString("UPDATE SYS_PERSON SET UPDATETIME = '%1', DELFLAG = '%2' WHERE ID = '%3'") .arg(tm).arg(tmms).arg(id); LOG(DEBUG) << sql.toStdString(); diff --git a/dao/SysPersonDao.h b/dao/SysPersonDao.h index 3ca2ca3..c73d2ab 100644 --- a/dao/SysPersonDao.h +++ b/dao/SysPersonDao.h @@ -13,14 +13,13 @@ QVector findAllRecord(); QVariantMap findRecordById(QString id); QVector findRecordsByProperty(QString properName, QVariant properValue); - QVector findRecordsByNameAndDept(QString name, QString dept); + int findRecordCountByNameAndDept(QString name, QString dept); + QVector findRecordsByNameAndDept(QString name, QString dept, qint8 limit, qint16 offset); QVector findRecordsByProperties(QVariantMap conditions); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); - - QVector findAllDept(); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: }; diff --git a/CasicBioRecWin.cpp b/CasicBioRecWin.cpp index 562f7ca..81d4615 100644 --- a/CasicBioRecWin.cpp +++ b/CasicBioRecWin.cpp @@ -9,8 +9,10 @@ { ui->setupUi(this); + // 程序启动时初始化缓存的数据 this->initCacheData(); + // 设置窗口透明和大小、位置 this->setWindowFlags(Qt::FramelessWindowHint); this->move(0, 0); this->resize(SettingConfig::getInstance().WINDOW_WIDTH, @@ -19,8 +21,10 @@ // 通过调色板的颜色来设置窗口的统一背景色 qApp->setPalette(QPalette(QColor(SettingConfig::getInstance().WINDOW_BACKGROUND_COLOR))); + // 初始化各个form界面并绑定切换响应函数 this->initFormsPtr(); + // 打印日志 LOG(INFO) << QString("应用程序启动成功[Application Startup Success]").toStdString(); } diff --git a/PersonListForm.cpp b/PersonListForm.cpp index 77fc565..e479626 100644 --- a/PersonListForm.cpp +++ b/PersonListForm.cpp @@ -21,26 +21,128 @@ ui->vsTableTop->changeSize(0, 20); ui->vsContentBottom->changeSize(0, 40); - itemModel = new QStandardItemModel(this); + // 初始化空的人员列表表格 + initPersonTableHeader(); + // 初始化部门下拉列表框 + SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); +} + +PersonListForm::~PersonListForm() +{ + delete ui; +} + +void PersonListForm::keyPressEvent(QKeyEvent * event) +{ + switch (event->key()) { + case Qt::Key_Return: // 小键盘的Enter键 + case Qt::Key_Enter: // Enter键 + currentPage = 0; + this->findPersonList(); + break; + + default: + QWidget::keyPressEvent(event); + } +} + +void PersonListForm::calcTotalPage(int totalCount) +{ + double temp = (totalCount * 1.0) / (tableRowCount * 1.0); + totalPage = ceil(temp); +} + +void PersonListForm::findPersonList() +{ + SysPersonDao personDao; + + // 获取查询条件 + QString name = ui->inputName->text(); + QString dept = ui->selectDept->currentData().toString(); + + // 计算分页查询的偏移量 + qint16 offset = currentPage * tableRowCount; + + // 查询总条数并计算总页数 + int totalCount = personDao.findRecordCountByNameAndDept(name, dept); + calcTotalPage(totalCount); + + // 赋值表格内容 + QVector perList = personDao.findRecordsByNameAndDept(name, dept, tableRowCount, offset); + + // 有数据且查询结果为空 则重新查询上一页 + if (totalCount > 0 && perList.isEmpty()) + { + // 触发查询上一页的操作 后续操作不再执行 + emit ui->btnPre->clicked(); + return ; + } + + this->personList->clear(); + for (int i = 0; i < perList.size(); i++) { + QVariantMap person = perList.at(i); + this->personList->append(person); + } + + // 更新显示表格 + this->updatePersonListTable(); + + // 更新页码 + if (totalCount == 0) + { + ui->labCurrPage->setText("0"); + } else + { + ui->labCurrPage->setText(QString("%1 / %2 , %3").arg(currentPage + 1).arg(totalPage).arg(totalCount)); + } +} + +void PersonListForm::initPersonTableHeader() +{ + itemModel = new QStandardItemModel(this); personList = new QList(); - SelectDeptUtil::getInstance().initSelectDept(ui->selectDept, CacheManager::getInstance().getDeptCachePtr()); - + // 添加表头 QStringList header; header << "员工编号" << "姓名" << "部门 "<< "采集特征" << "操作"; itemModel->setHorizontalHeaderLabels(header); - for (int i = 0; i < tableRowCount; i++) { - QList row; - for ( int j = 0; j < tableColCount; j++) { - itemModel->setItem(i, j, new QStandardItem(QString(""))); - itemModel->item(i, j)->setTextAlignment(Qt::AlignCenter); - } - } + // 设置表头的宽度为固定值 不可调整 + ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); +} + +void PersonListForm::updatePersonListTable() +{ + // 清除表格原有数据 + itemModel->removeRows(0, itemModel->rowCount()); + ui->personListTable->setModel(itemModel); - ui->personListTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); + // 判断是否有分页 + int max = tableRowCount > personList->size() ? personList->size() : tableRowCount; + for (int i = 0; i < max; i++) { + QList row; + itemModel->setItem(i, 0, new QStandardItem(personList->at(i).find("person_code")->toString())); + itemModel->item(i, 0)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 1, new QStandardItem(personList->at(i).find("name")->toString())); + itemModel->item(i, 1)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 2, new QStandardItem(personList->at(i).find("deptname")->toString())); + itemModel->item(i, 2)->setTextAlignment(Qt::AlignCenter); + + itemModel->setItem(i, 3, new QStandardItem(QString("iris face"))); + itemModel->item(i, 3)->setTextAlignment(Qt::AlignCenter); + + QPushButton * btnDele = new QPushButton("删除"); + btnDele->setProperty("personId", personList->at(i).find("id")->toString()); + btnDele->setProperty("class", "btnDelete"); + connect(btnDele, &QPushButton::clicked, + this, &PersonListForm::btnDeleClicked); + ui->personListTable->setIndexWidget(itemModel->index(i, 4), btnDele); + } + // 设置每行的高度 for ( int i = 0; i < tableRowCount; i++) { @@ -55,27 +157,6 @@ ui->personListTable->setColumnWidth(4, 150); } -PersonListForm::~PersonListForm() -{ - delete ui; -} - -void PersonListForm::findPersonList() -{ - SysPersonDao personDao; - QVector perList = personDao.findAllRecord(); - this->personList->clear(); - for (int i = 0; i < perList.size(); i++) { - QVariantMap person = perList.at(i); - this->personList->append(person); - } -} - -void PersonListForm::updatePersonListTable() -{ - -} - void PersonListForm::on_btnRegist_clicked() { emit switchToRegistForm("0"); @@ -90,3 +171,56 @@ { emit backToHomePage(); } + +void PersonListForm::on_selectDept_currentIndexChanged(int index) +{ + currentPage = 0; + this->findPersonList(); +} + +void PersonListForm::on_btnFirst_clicked() +{ + // 第一页 + currentPage = 0; + findPersonList(); +} + +void PersonListForm::on_btnLast_clicked() +{ + // 最后一页 + currentPage = totalPage - 1; + findPersonList(); +} + +void PersonListForm::on_btnPre_clicked() +{ + // 上一页 + if (currentPage > 0) + { + currentPage = currentPage - 1; + } + findPersonList(); +} + +void PersonListForm::on_btnNext_clicked() +{ + // 下一页 + if (currentPage < totalPage - 1) + { + currentPage++; + } + findPersonList(); +} + +void PersonListForm::btnDeleClicked() +{ + // 获取发送者的信息 + QPushButton * senderObj = (QPushButton *) sender(); + QString personId = senderObj->property("personId").toString(); + SysPersonDao personDao; + bool succ = personDao.dele(personId); + if (succ == 1) + { + findPersonList(); + } +} diff --git a/PersonListForm.h b/PersonListForm.h index 236bc53..cce03a3 100644 --- a/PersonListForm.h +++ b/PersonListForm.h @@ -19,6 +19,8 @@ explicit PersonListForm(QWidget *parent = nullptr); ~PersonListForm(); + void keyPressEvent(QKeyEvent * event); + private slots: void on_btnRegist_clicked(); @@ -26,6 +28,18 @@ void on_btnBack_clicked(); + void on_selectDept_currentIndexChanged(int index); + + void on_btnFirst_clicked(); + + void on_btnLast_clicked(); + + void on_btnPre_clicked(); + + void on_btnNext_clicked(); + + void btnDeleClicked(); + private: Ui::PersonListForm *ui; QStandardItemModel * itemModel; @@ -33,8 +47,12 @@ int tableRowCount = 8; int tableColCount = 5; + int currentPage = 0; + int totalPage = 0; + void calcTotalPage(int totalCount); void findPersonList(); + void initPersonTableHeader(); void updatePersonListTable(); signals: diff --git a/PersonListForm.ui b/PersonListForm.ui index 909cbf2..5bc81f5 100644 --- a/PersonListForm.ui +++ b/PersonListForm.ui @@ -233,7 +233,14 @@ - 1 / 1 + 1 + + + + + + + 条记录 diff --git a/dao/BaseDao.h b/dao/BaseDao.h index aa67f80..1ea0c93 100644 --- a/dao/BaseDao.h +++ b/dao/BaseDao.h @@ -1,4 +1,4 @@ -#ifndef BASEDAO_H +#ifndef BASEDAO_H #define BASEDAO_H #include @@ -21,8 +21,8 @@ virtual QVector findRecordsByProperty(QString properName, QVariant properValue) = 0; virtual QString save(QVariantMap object) = 0; - virtual bool edit(QVariantMap newObject, qulonglong id) = 0; - virtual bool dele(qulonglong id) = 0; + virtual bool edit(QVariantMap newObject, QString id) = 0; + virtual bool dele(QString id) = 0; private: diff --git a/dao/FaceDataDao.cpp b/dao/FaceDataDao.cpp index d668b0a..642f3fb 100644 --- a/dao/FaceDataDao.cpp +++ b/dao/FaceDataDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataDao.h" +#include "FaceDataDao.h" FaceDataDao::FaceDataDao(QObject *parent) : BaseDao(parent) { @@ -87,12 +87,12 @@ } } -bool FaceDataDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool FaceDataDao::dele(qulonglong id) +bool FaceDataDao::dele(QString id) { return false; } diff --git a/dao/FaceDataDao.h b/dao/FaceDataDao.h index 2db4a3d..87fce40 100644 --- a/dao/FaceDataDao.h +++ b/dao/FaceDataDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATADAO_H +#ifndef FACEDATADAO_H #define FACEDATADAO_H #include @@ -16,8 +16,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/FaceDataImgDao.cpp b/dao/FaceDataImgDao.cpp index c4e96f8..ce8a72a 100644 --- a/dao/FaceDataImgDao.cpp +++ b/dao/FaceDataImgDao.cpp @@ -1,4 +1,4 @@ -#include "FaceDataImgDao.h" +#include "FaceDataImgDao.h" FaceDataImgDao::FaceDataImgDao(QObject *parent) : BaseDao(parent) { @@ -171,7 +171,7 @@ } } -bool FaceDataImgDao::edit(QVariantMap newObject, qulonglong id) +bool FaceDataImgDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -196,7 +196,7 @@ return success; } -bool FaceDataImgDao::dele(qulonglong id) +bool FaceDataImgDao::dele(QString id) { return false; } diff --git a/dao/FaceDataImgDao.h b/dao/FaceDataImgDao.h index d249550..868d73a 100644 --- a/dao/FaceDataImgDao.h +++ b/dao/FaceDataImgDao.h @@ -1,4 +1,4 @@ -#ifndef FACEDATAIMGDAO_H +#ifndef FACEDATAIMGDAO_H #define FACEDATAIMGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/IrisDataDao.cpp b/dao/IrisDataDao.cpp index 26a68e2..5f1b047 100644 --- a/dao/IrisDataDao.cpp +++ b/dao/IrisDataDao.cpp @@ -1,4 +1,4 @@ -#include "IrisDataDao.h" +#include "IrisDataDao.h" IrisDataDao::IrisDataDao(QObject *parent) : BaseDao(parent) { @@ -95,13 +95,13 @@ } } -bool IrisDataDao::edit(QVariantMap newObject, qulonglong id) +bool IrisDataDao::edit(QVariantMap newObject, QString id) { return false; } -bool IrisDataDao::dele(qulonglong id) +bool IrisDataDao::dele(QString id) { return false; } diff --git a/dao/IrisDataDao.h b/dao/IrisDataDao.h index 76e6267..1289074 100644 --- a/dao/IrisDataDao.h +++ b/dao/IrisDataDao.h @@ -1,4 +1,4 @@ -#ifndef IRISDATADAO_H +#ifndef IRISDATADAO_H #define IRISDATADAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/IrisDataImgDao.cpp b/dao/IrisDataImgDao.cpp index 691762c..18d4ce6 100644 --- a/dao/IrisDataImgDao.cpp +++ b/dao/IrisDataImgDao.cpp @@ -1,4 +1,4 @@ -#include "IrisDataImgDao.h" +#include "IrisDataImgDao.h" IrisDataImgDao::IrisDataImgDao(QObject *parent) : BaseDao(parent) { @@ -182,7 +182,7 @@ } } -bool IrisDataImgDao::edit(QVariantMap newObject, qulonglong id) +bool IrisDataImgDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -219,7 +219,7 @@ return success; } -bool IrisDataImgDao::dele(qulonglong id) +bool IrisDataImgDao::dele(QString id) { return false; } diff --git a/dao/IrisDataImgDao.h b/dao/IrisDataImgDao.h index 5d35d65..f39158a 100644 --- a/dao/IrisDataImgDao.h +++ b/dao/IrisDataImgDao.h @@ -1,4 +1,4 @@ -#ifndef IRISDATAIMGDAO_H +#ifndef IRISDATAIMGDAO_H #define IRISDATAIMGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/RecognitionRecordDao.cpp b/dao/RecognitionRecordDao.cpp index c6a188a..403894a 100644 --- a/dao/RecognitionRecordDao.cpp +++ b/dao/RecognitionRecordDao.cpp @@ -1,4 +1,4 @@ -#include "RecognitionRecordDao.h" +#include "RecognitionRecordDao.h" RecognitionRecordDao::RecognitionRecordDao(QObject *parent) : BaseDao(parent) { @@ -123,12 +123,12 @@ } } -bool RecognitionRecordDao::edit(QVariantMap newObject, qulonglong id) +bool RecognitionRecordDao::edit(QVariantMap newObject, QString id) { return false; } -bool RecognitionRecordDao::dele(qulonglong id) +bool RecognitionRecordDao::dele(QString id) { return false; } diff --git a/dao/RecognitionRecordDao.h b/dao/RecognitionRecordDao.h index 6ef54bf..37572c8 100644 --- a/dao/RecognitionRecordDao.h +++ b/dao/RecognitionRecordDao.h @@ -1,4 +1,4 @@ -#ifndef RECOGNITIONRECORDDAO_H +#ifndef RECOGNITIONRECORDDAO_H #define RECOGNITIONRECORDDAO_H #include @@ -14,8 +14,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/SysConfigDao.cpp b/dao/SysConfigDao.cpp index 1d51eca..cc1cbeb 100644 --- a/dao/SysConfigDao.cpp +++ b/dao/SysConfigDao.cpp @@ -1,4 +1,4 @@ -#include "SysConfigDao.h" +#include "SysConfigDao.h" SysConfigDao::SysConfigDao(QObject *parent) : BaseDao(parent) { @@ -32,7 +32,6 @@ result.append(item); } - LOG(DEBUG) << QString("查询SYS_CONFIG表的所有记录").toLocal8Bit().data(); return result; } @@ -54,12 +53,12 @@ return "0"; } -bool SysConfigDao::edit(QVariantMap newObject, qulonglong id) +bool SysConfigDao::edit(QVariantMap newObject, QString id) { return false; } -bool SysConfigDao::dele(qulonglong id) +bool SysConfigDao::dele(QString id) { return false; } diff --git a/dao/SysConfigDao.h b/dao/SysConfigDao.h index 8b525cd..e88b993 100644 --- a/dao/SysConfigDao.h +++ b/dao/SysConfigDao.h @@ -1,4 +1,4 @@ -#ifndef SYSCONFIGDAO_H +#ifndef SYSCONFIGDAO_H #define SYSCONFIGDAO_H #include @@ -15,8 +15,8 @@ QVector findRecordsByProperty(QString properName, QVariant properValue); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: diff --git a/dao/SysDeptDao.cpp b/dao/SysDeptDao.cpp index d5c5d77..9562e78 100644 --- a/dao/SysDeptDao.cpp +++ b/dao/SysDeptDao.cpp @@ -104,35 +104,7 @@ result.append(item); } - LOG(DEBUG) << QString("根据属性值查询SYS_DEPT表的记录[%1][%2]").arg(count).arg(sql).toStdString(); - return result; -} - -QList SysDeptDao::findDeptTree(QString pid) -{ - // 新建查询 - QSqlQuery query(ConnectionManager::getInstance()->getConnection()); - - // 查询语句 - QString sql = "SELECT * FROM SYS_DEPT WHERE PID = '" + pid + "' ORDER BY NUM"; - - // 执行查询 - query.exec(sql); - - // 返回结果 - QList result; - - // 遍历查询部门树形结构 - while (query.next()) { - QVariantMap item; - QString id = query.value("id").toString(); - item.insert("id", id); - item.insert("pid", query.value("pid").toString()); - item.insert("pids", query.value("pids").toString()); - item.insert("fullname", query.value("fullname").toString()); - result.append(item); - } - + LOG(TRACE) << QString("根据属性值查询SYS_DEPT表的记录[%1][%2]").arg(count).arg(sql).toStdString(); return result; } @@ -140,11 +112,11 @@ { return "0"; } -bool SysDeptDao::edit(QVariantMap newObject, qulonglong id) +bool SysDeptDao::edit(QVariantMap newObject, QString id) { return true; } -bool SysDeptDao::dele(qulonglong id) +bool SysDeptDao::dele(QString id) { return true; } diff --git a/dao/SysDeptDao.h b/dao/SysDeptDao.h index 51582cc..c22da9c 100644 --- a/dao/SysDeptDao.h +++ b/dao/SysDeptDao.h @@ -14,12 +14,11 @@ QVariantMap findRecordById(QString id); QVector findRecordsByProperty(QString properName, QVariant properValue); - QList findDeptTree(QString pid); void appendChild(QList * deptTree, QVariantMap node); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); private: diff --git a/dao/SysPersonDao.cpp b/dao/SysPersonDao.cpp index cd232ca..6a0525d 100644 --- a/dao/SysPersonDao.cpp +++ b/dao/SysPersonDao.cpp @@ -6,49 +6,6 @@ } -QVector SysPersonDao::findAllDept() -{ - // 新建查询 - QSqlQuery query(ConnectionManager::getInstance()->getConnection()); - - // 查询语句 - QString sql = "SELECT * FROM SYS_DEPT WHERE PID != '-1'"; - - // 执行查询 - query.exec(sql); - - // 获取结果集的大小 - int count = 0; - - // 返回结果 - QVector result; - - // 遍历查询结果 - while (query.next()) { - QVariantMap item; - count++; - item.insert("id", query.value("id").toString()); - item.insert("pid", query.value("pid").toString()); - item.insert("pids", query.value("pids").toString()); - item.insert("fullname", query.value("fullname").toString()); - QStringList vector = query.value("pids").toString().split(","); - if (vector.count() == 2) { //集团 - result.append(item); - } else { - for (int i = 0; i < result.size(); i++) { - if (result[i].value("id") == query.value("pid").toString()) { - result.insert(i + 1, item); - break; - } - } - } - } - - LOG(DEBUG) << QString("查询表[SYS_DEPT]的所有记录[%1][%2]").arg(count).arg(sql).toStdString(); - - return result; -} - QVector SysPersonDao::findAllRecord() { // 新建查询 @@ -132,14 +89,55 @@ return result; } -QVector SysPersonDao::findRecordsByNameAndDept(QString name, QString dept) +int SysPersonDao::findRecordCountByNameAndDept(QString name, QString dept) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); // 查询语句 - QString sql = "SELECT * FROM SYS_PERSON LEFT JOIN SYS_DEPT ON SYS_PERSON.DEPTID = SYS_DEPT.ID WHERE SYS_PERSON.DELFLAG = '0' AND SYS_PERSON.NAME = '%1' AND SYS_PERSON.DEPTID = '%2'"; - sql = sql.arg(name).arg(dept); + QString sql = "SELECT COUNT(P.ID) AS RECCT FROM SYS_PERSON P LEFT JOIN SYS_DEPT D ON P.DEPTID = D.ID WHERE P.DELFLAG = '0'"; + if (name.isEmpty() == false) + { + sql += " AND P.NAME LIKE '%" + name + "%'"; + } + if (dept.isEmpty() == false && dept.indexOf("-1") < 0) + { + sql += QString(" AND (P.DEPTID = '%1') OR (D.PIDS LIKE '%,%1,%')").arg(dept); + } + + // 执行查询 + query.exec(sql); + + // 返回结果 + int result; + + // 遍历查询结果 + if (query.next()) { + result = query.value("RECCT").toInt(); + } + + LOG(TRACE) << QString("根据姓名和部门查询SYS_PERSON记录总数[%1][%2]").arg(result).arg(sql).toStdString(); + + return result; +} + +QVector SysPersonDao::findRecordsByNameAndDept(QString name, QString dept, qint8 limit, qint16 offset) +{ + // 新建查询 + QSqlQuery query(ConnectionManager::getInstance()->getConnection()); + + // 查询语句 + QString sql = "SELECT * FROM SYS_PERSON P LEFT JOIN SYS_DEPT D ON P.DEPTID = D.ID WHERE P.DELFLAG = '0'"; + if (name.isEmpty() == false) + { + sql += " AND P.NAME LIKE '%" + name + "%'"; + } + if (dept.isEmpty() == false && dept.indexOf("-1") < 0) + { + sql += QString(" AND (P.DEPTID = '%1') OR (D.PIDS LIKE '%,%1,%')").arg(dept); + } + + sql += QString(" LIMIT %1 OFFSET %2").arg(limit).arg(offset); // 执行查询 query.exec(sql); @@ -156,7 +154,7 @@ count++; - item.insert("id", query.value("id").toLongLong()); + item.insert("id", query.value("id").toString()); item.insert("delflag", query.value("delflag").toString()); item.insert("createtime", query.value("createtime").toString()); item.insert("updatetime", query.value("updatetime").toString()); @@ -172,7 +170,7 @@ result.append(item); } - LOG(DEBUG) << QString("根据姓名和部门查询SYS_PERSON表的记录[%1][%2]").arg(count).arg(sql).toStdString(); + LOG(TRACE) << QString("根据姓名和部门分页查询SYS_PERSON表的记录[%1][%2]").arg(count).arg(sql).toStdString(); return result; } @@ -317,7 +315,7 @@ } } -bool SysPersonDao::edit(QVariantMap newObject, qulonglong id) +bool SysPersonDao::edit(QVariantMap newObject, QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -360,7 +358,7 @@ return success; } -bool SysPersonDao::dele(qulonglong id) +bool SysPersonDao::dele(QString id) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); @@ -369,7 +367,7 @@ qint64 tmms = QDateTime::currentDateTime().toMSecsSinceEpoch(); // UPDATE语句 - QString sql = QString("UPDATE SYS_PERSON SET UPDATETIME = '%1', DELFLAG = '%2' WHERE ID = %3") + QString sql = QString("UPDATE SYS_PERSON SET UPDATETIME = '%1', DELFLAG = '%2' WHERE ID = '%3'") .arg(tm).arg(tmms).arg(id); LOG(DEBUG) << sql.toStdString(); diff --git a/dao/SysPersonDao.h b/dao/SysPersonDao.h index 3ca2ca3..c73d2ab 100644 --- a/dao/SysPersonDao.h +++ b/dao/SysPersonDao.h @@ -13,14 +13,13 @@ QVector findAllRecord(); QVariantMap findRecordById(QString id); QVector findRecordsByProperty(QString properName, QVariant properValue); - QVector findRecordsByNameAndDept(QString name, QString dept); + int findRecordCountByNameAndDept(QString name, QString dept); + QVector findRecordsByNameAndDept(QString name, QString dept, qint8 limit, qint16 offset); QVector findRecordsByProperties(QVariantMap conditions); QString save(QVariantMap object); - bool edit(QVariantMap newObject, qulonglong id); - bool dele(qulonglong id); - - QVector findAllDept(); + bool edit(QVariantMap newObject, QString id); + bool dele(QString id); signals: }; diff --git a/qss/personList.css b/qss/personList.css index 2aec397..fcf1a23 100644 --- a/qss/personList.css +++ b/qss/personList.css @@ -87,9 +87,8 @@ border-radius: 6px; } -QLabel#labCurrPage { +QLabel#labCurrPage, QLabel#label { font-size: 24px; - margin-right: 15px; } QPushButton#btnRegist { @@ -115,7 +114,6 @@ border-bottom: 1px solid #6868A6; } - QTableView { margin: 0px; border: 2px solid #5F1BC6; @@ -133,3 +131,12 @@ QTableView::item::selected { background: #FFFFFF; } + +QPushButton[class="btnDelete"] { + color: #FF0000; + font-size: 24px; + font-family: "Microsoft YaHei"; + border: 2px solid #FF0000; + border-radius: 8px; + margin: 5px; +}