diff --git a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro index bf70fab..d9a99ea 100644 --- a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro +++ b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro @@ -35,6 +35,7 @@ create_task.cpp \ createtask_scandevice.cpp \ databaseconnection.cpp \ + databaseconnectionmainsys.cpp \ datasyncview.cpp \ depar_task.cpp \ depar_task_server.cpp \ @@ -55,6 +56,7 @@ newverifymethod.cpp \ rulefileitem.cpp \ standard_deviceitem.cpp \ + syncdialog.cpp \ synctask.cpp \ testdataitem.cpp \ testview.cpp \ @@ -69,6 +71,7 @@ DataProcessingBLL.h \ PageControl.h \ createtask_scandevice.h \ + databaseconnectionmainsys.h \ formaddrsetting.h \ formcommsetting.h \ id/IdWorker.h \ @@ -104,6 +107,7 @@ newverifymethod.h \ rulefileitem.h \ standard_deviceitem.h \ + syncdialog.h \ synctask.h \ testdataitem.h \ testview.h \ @@ -138,6 +142,7 @@ newverifymethod.ui \ rulefileitem.ui \ standard_deviceitem.ui \ + syncdialog.ui \ testdataitem.ui \ testview.ui \ verifydevice.ui \ diff --git a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro index bf70fab..d9a99ea 100644 --- a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro +++ b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro @@ -35,6 +35,7 @@ create_task.cpp \ createtask_scandevice.cpp \ databaseconnection.cpp \ + databaseconnectionmainsys.cpp \ datasyncview.cpp \ depar_task.cpp \ depar_task_server.cpp \ @@ -55,6 +56,7 @@ newverifymethod.cpp \ rulefileitem.cpp \ standard_deviceitem.cpp \ + syncdialog.cpp \ synctask.cpp \ testdataitem.cpp \ testview.cpp \ @@ -69,6 +71,7 @@ DataProcessingBLL.h \ PageControl.h \ createtask_scandevice.h \ + databaseconnectionmainsys.h \ formaddrsetting.h \ formcommsetting.h \ id/IdWorker.h \ @@ -104,6 +107,7 @@ newverifymethod.h \ rulefileitem.h \ standard_deviceitem.h \ + syncdialog.h \ synctask.h \ testdataitem.h \ testview.h \ @@ -138,6 +142,7 @@ newverifymethod.ui \ rulefileitem.ui \ standard_deviceitem.ui \ + syncdialog.ui \ testdataitem.ui \ testview.ui \ verifydevice.ui \ diff --git a/softwareDirectory/AutoVerScheme/PageControl.cpp b/softwareDirectory/AutoVerScheme/PageControl.cpp index d0fd72b..d1bdddc 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.cpp +++ b/softwareDirectory/AutoVerScheme/PageControl.cpp @@ -22,14 +22,14 @@ } } -void PagedTableWidget::setData(const QList> &data, int rowsPerPage,QTableWidget *table) { - tableWidget=table; - +void PagedTableWidget::setData(int datacount, int rowsPerPage) { + //tableWidget=table; + totaldatacount=datacount; this->rowsPerPage = rowsPerPage; - allData = data; + //allData = data; currentPage = 0; createPageButtons(); - updateTable(); + //updateTable(); } void PagedTableWidget::setCurrentPage(int page) { @@ -39,7 +39,7 @@ button->setChecked(false); }*/ currentPage = page; - updateTable(); + //updateTable(); emit pageChanged(page); } } @@ -89,6 +89,7 @@ setCurrentPage(pageIndex); } } +/* void PagedTableWidget::updateTable() { //tableWidget->clear(); tableWidget->setRowCount(0); @@ -105,7 +106,7 @@ } } } - +*/ void PagedTableWidget::createPageButtons() { int totalPages = calculateTotalPages(); for (auto button : pageButtons) { @@ -150,5 +151,5 @@ } int PagedTableWidget::calculateTotalPages() { - return ((allData.count() + rowsPerPage -1) / rowsPerPage); + return ((totaldatacount + rowsPerPage -1) / rowsPerPage); } diff --git a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro index bf70fab..d9a99ea 100644 --- a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro +++ b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro @@ -35,6 +35,7 @@ create_task.cpp \ createtask_scandevice.cpp \ databaseconnection.cpp \ + databaseconnectionmainsys.cpp \ datasyncview.cpp \ depar_task.cpp \ depar_task_server.cpp \ @@ -55,6 +56,7 @@ newverifymethod.cpp \ rulefileitem.cpp \ standard_deviceitem.cpp \ + syncdialog.cpp \ synctask.cpp \ testdataitem.cpp \ testview.cpp \ @@ -69,6 +71,7 @@ DataProcessingBLL.h \ PageControl.h \ createtask_scandevice.h \ + databaseconnectionmainsys.h \ formaddrsetting.h \ formcommsetting.h \ id/IdWorker.h \ @@ -104,6 +107,7 @@ newverifymethod.h \ rulefileitem.h \ standard_deviceitem.h \ + syncdialog.h \ synctask.h \ testdataitem.h \ testview.h \ @@ -138,6 +142,7 @@ newverifymethod.ui \ rulefileitem.ui \ standard_deviceitem.ui \ + syncdialog.ui \ testdataitem.ui \ testview.ui \ verifydevice.ui \ diff --git a/softwareDirectory/AutoVerScheme/PageControl.cpp b/softwareDirectory/AutoVerScheme/PageControl.cpp index d0fd72b..d1bdddc 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.cpp +++ b/softwareDirectory/AutoVerScheme/PageControl.cpp @@ -22,14 +22,14 @@ } } -void PagedTableWidget::setData(const QList> &data, int rowsPerPage,QTableWidget *table) { - tableWidget=table; - +void PagedTableWidget::setData(int datacount, int rowsPerPage) { + //tableWidget=table; + totaldatacount=datacount; this->rowsPerPage = rowsPerPage; - allData = data; + //allData = data; currentPage = 0; createPageButtons(); - updateTable(); + //updateTable(); } void PagedTableWidget::setCurrentPage(int page) { @@ -39,7 +39,7 @@ button->setChecked(false); }*/ currentPage = page; - updateTable(); + //updateTable(); emit pageChanged(page); } } @@ -89,6 +89,7 @@ setCurrentPage(pageIndex); } } +/* void PagedTableWidget::updateTable() { //tableWidget->clear(); tableWidget->setRowCount(0); @@ -105,7 +106,7 @@ } } } - +*/ void PagedTableWidget::createPageButtons() { int totalPages = calculateTotalPages(); for (auto button : pageButtons) { @@ -150,5 +151,5 @@ } int PagedTableWidget::calculateTotalPages() { - return ((allData.count() + rowsPerPage -1) / rowsPerPage); + return ((totaldatacount + rowsPerPage -1) / rowsPerPage); } diff --git a/softwareDirectory/AutoVerScheme/PageControl.h b/softwareDirectory/AutoVerScheme/PageControl.h index 74ed1ce..2224760 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.h +++ b/softwareDirectory/AutoVerScheme/PageControl.h @@ -15,7 +15,7 @@ explicit PagedTableWidget(QWidget *parent = nullptr,QHBoxLayout *PageLayout=NULL); ~PagedTableWidget(); - void setData(const QList> &data, int rowsPerPage = 10,QTableWidget *table=NULL); + void setData(int datacount, int rowsPerPage = 10); void setCurrentPage(int page); signals: @@ -30,6 +30,7 @@ QHBoxLayout *pageLayout; QList pageButtons; QList> allData; + int totaldatacount; int rowsPerPage; int currentPage; diff --git a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro index bf70fab..d9a99ea 100644 --- a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro +++ b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro @@ -35,6 +35,7 @@ create_task.cpp \ createtask_scandevice.cpp \ databaseconnection.cpp \ + databaseconnectionmainsys.cpp \ datasyncview.cpp \ depar_task.cpp \ depar_task_server.cpp \ @@ -55,6 +56,7 @@ newverifymethod.cpp \ rulefileitem.cpp \ standard_deviceitem.cpp \ + syncdialog.cpp \ synctask.cpp \ testdataitem.cpp \ testview.cpp \ @@ -69,6 +71,7 @@ DataProcessingBLL.h \ PageControl.h \ createtask_scandevice.h \ + databaseconnectionmainsys.h \ formaddrsetting.h \ formcommsetting.h \ id/IdWorker.h \ @@ -104,6 +107,7 @@ newverifymethod.h \ rulefileitem.h \ standard_deviceitem.h \ + syncdialog.h \ synctask.h \ testdataitem.h \ testview.h \ @@ -138,6 +142,7 @@ newverifymethod.ui \ rulefileitem.ui \ standard_deviceitem.ui \ + syncdialog.ui \ testdataitem.ui \ testview.ui \ verifydevice.ui \ diff --git a/softwareDirectory/AutoVerScheme/PageControl.cpp b/softwareDirectory/AutoVerScheme/PageControl.cpp index d0fd72b..d1bdddc 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.cpp +++ b/softwareDirectory/AutoVerScheme/PageControl.cpp @@ -22,14 +22,14 @@ } } -void PagedTableWidget::setData(const QList> &data, int rowsPerPage,QTableWidget *table) { - tableWidget=table; - +void PagedTableWidget::setData(int datacount, int rowsPerPage) { + //tableWidget=table; + totaldatacount=datacount; this->rowsPerPage = rowsPerPage; - allData = data; + //allData = data; currentPage = 0; createPageButtons(); - updateTable(); + //updateTable(); } void PagedTableWidget::setCurrentPage(int page) { @@ -39,7 +39,7 @@ button->setChecked(false); }*/ currentPage = page; - updateTable(); + //updateTable(); emit pageChanged(page); } } @@ -89,6 +89,7 @@ setCurrentPage(pageIndex); } } +/* void PagedTableWidget::updateTable() { //tableWidget->clear(); tableWidget->setRowCount(0); @@ -105,7 +106,7 @@ } } } - +*/ void PagedTableWidget::createPageButtons() { int totalPages = calculateTotalPages(); for (auto button : pageButtons) { @@ -150,5 +151,5 @@ } int PagedTableWidget::calculateTotalPages() { - return ((allData.count() + rowsPerPage -1) / rowsPerPage); + return ((totaldatacount + rowsPerPage -1) / rowsPerPage); } diff --git a/softwareDirectory/AutoVerScheme/PageControl.h b/softwareDirectory/AutoVerScheme/PageControl.h index 74ed1ce..2224760 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.h +++ b/softwareDirectory/AutoVerScheme/PageControl.h @@ -15,7 +15,7 @@ explicit PagedTableWidget(QWidget *parent = nullptr,QHBoxLayout *PageLayout=NULL); ~PagedTableWidget(); - void setData(const QList> &data, int rowsPerPage = 10,QTableWidget *table=NULL); + void setData(int datacount, int rowsPerPage = 10); void setCurrentPage(int page); signals: @@ -30,6 +30,7 @@ QHBoxLayout *pageLayout; QList pageButtons; QList> allData; + int totaldatacount; int rowsPerPage; int currentPage; diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.cpp b/softwareDirectory/AutoVerScheme/basecommonapi.cpp index 49cbd7e..6f6fe94 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.cpp +++ b/softwareDirectory/AutoVerScheme/basecommonapi.cpp @@ -13,7 +13,7 @@ } const QString BaseCommonApi::temporary_user_id="1634107227953819649"; const QString BaseCommonApi::measure_person_id="1695282436182188034"; - +static SyncRunStatus syncstate=SyncRunStatus::Stopped; //sys_user表的id转换为measure_person_id 检定人id(meter_staff表id) @@ -167,7 +167,8 @@ "JOIN eqpt_equipment_info eei ON eei.id = blei.sample_id " "JOIN biz_business_order_info bo ON bo.id = blei.order_id " "LEFT JOIN sys_dept sd ON blei.measure_dept_id = sd.ID " - " WHERE blei.measure_person_id = :person_id " + " WHERE blei.measure_person_id = :person_id " + " AND blei.measure_status =3 or blei.measure_status = 4 " " ORDER BY blei.update_time DESC"); // 将参数绑定到占位符 @@ -175,7 +176,8 @@ //query.bindValue(":status", status); if (query.exec()) { while (query.next()) { - MyTask task; + + MyTask task; task.id = query.value("id").toString(); task.sample_name = query.value("sampleName").toString(); task.sample_model = query.value("sampleModel").toString(); @@ -2872,9 +2874,40 @@ return result; } +//保存log信息 +//log文件 + bool BaseCommonApi::SaveLogInfo(QString path,QString Info) +{ + QByteArray utf8Dat; + QString Message=Info; + QFile file(path); + // 如果目录不存在,则创建目录 + // 获取文件所在的目录 + QDir logDir = QDir(QFileInfo(path).absolutePath()); + if (!logDir.exists()) { + if (!logDir.mkpath(".")) { + qDebug() << "Failed to create log directory:" << logDir.absolutePath(); + return false; + } + } + + if (!file.open(QIODevice::Append | QIODevice::Text)) { + qDebug() << "无法打开文件:" << file.errorString(); + return false; + } + QTextStream out(&file); + utf8Dat = Message.toUtf8(); + out << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss") + << "\t" << utf8Dat << "\n"; + file.close(); + return true; + } + + //新增日志表数据 bool BaseCommonApi::InsertzdLog(zdLog log) { + log.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_log(id,is_sync,sync_time,remark,userid,type,create_time,update_time) " " VALUES(:id,:is_sync,:sync_time,:remark,:userid,:type,:create_time,:update_time) "); @@ -2898,6 +2931,7 @@ //根据userid查询日志表数据 QList BaseCommonApi::getzdLogByuserId(QString userid) { + userid=temporary_user_id; QList result; QSqlQuery query; query.prepare("SELECT * FROM zd_log WHERE userid = :userid "); @@ -2922,6 +2956,7 @@ //新增数据同步表 bool BaseCommonApi::InsertzdDataSync(zdDataSync data) { + data.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_data_sync(id,type,ssql,userid,remark,create_time,update_time,log_sync_id,sync_type) " " VALUES " @@ -2945,12 +2980,12 @@ return isSuccess; } //根据userid查询数据同步表 -QList getzdDataSyncByuserId(QString userid) +QList BaseCommonApi::getzdDataSyncByuserId(QString log_sync_id) { QList result; QSqlQuery query; - query.prepare("SELECT * FROM zd_data_sync WHERE userid= :userid "); - query.bindValue(":userid",userid); + query.prepare("SELECT * FROM zd_data_sync WHERE log_sync_id= :log_sync_id "); + query.bindValue(":log_sync_id",log_sync_id); if (query.exec()) { while (query.next()) { zdDataSync data; @@ -2972,3 +3007,4 @@ } + diff --git a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro index bf70fab..d9a99ea 100644 --- a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro +++ b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro @@ -35,6 +35,7 @@ create_task.cpp \ createtask_scandevice.cpp \ databaseconnection.cpp \ + databaseconnectionmainsys.cpp \ datasyncview.cpp \ depar_task.cpp \ depar_task_server.cpp \ @@ -55,6 +56,7 @@ newverifymethod.cpp \ rulefileitem.cpp \ standard_deviceitem.cpp \ + syncdialog.cpp \ synctask.cpp \ testdataitem.cpp \ testview.cpp \ @@ -69,6 +71,7 @@ DataProcessingBLL.h \ PageControl.h \ createtask_scandevice.h \ + databaseconnectionmainsys.h \ formaddrsetting.h \ formcommsetting.h \ id/IdWorker.h \ @@ -104,6 +107,7 @@ newverifymethod.h \ rulefileitem.h \ standard_deviceitem.h \ + syncdialog.h \ synctask.h \ testdataitem.h \ testview.h \ @@ -138,6 +142,7 @@ newverifymethod.ui \ rulefileitem.ui \ standard_deviceitem.ui \ + syncdialog.ui \ testdataitem.ui \ testview.ui \ verifydevice.ui \ diff --git a/softwareDirectory/AutoVerScheme/PageControl.cpp b/softwareDirectory/AutoVerScheme/PageControl.cpp index d0fd72b..d1bdddc 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.cpp +++ b/softwareDirectory/AutoVerScheme/PageControl.cpp @@ -22,14 +22,14 @@ } } -void PagedTableWidget::setData(const QList> &data, int rowsPerPage,QTableWidget *table) { - tableWidget=table; - +void PagedTableWidget::setData(int datacount, int rowsPerPage) { + //tableWidget=table; + totaldatacount=datacount; this->rowsPerPage = rowsPerPage; - allData = data; + //allData = data; currentPage = 0; createPageButtons(); - updateTable(); + //updateTable(); } void PagedTableWidget::setCurrentPage(int page) { @@ -39,7 +39,7 @@ button->setChecked(false); }*/ currentPage = page; - updateTable(); + //updateTable(); emit pageChanged(page); } } @@ -89,6 +89,7 @@ setCurrentPage(pageIndex); } } +/* void PagedTableWidget::updateTable() { //tableWidget->clear(); tableWidget->setRowCount(0); @@ -105,7 +106,7 @@ } } } - +*/ void PagedTableWidget::createPageButtons() { int totalPages = calculateTotalPages(); for (auto button : pageButtons) { @@ -150,5 +151,5 @@ } int PagedTableWidget::calculateTotalPages() { - return ((allData.count() + rowsPerPage -1) / rowsPerPage); + return ((totaldatacount + rowsPerPage -1) / rowsPerPage); } diff --git a/softwareDirectory/AutoVerScheme/PageControl.h b/softwareDirectory/AutoVerScheme/PageControl.h index 74ed1ce..2224760 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.h +++ b/softwareDirectory/AutoVerScheme/PageControl.h @@ -15,7 +15,7 @@ explicit PagedTableWidget(QWidget *parent = nullptr,QHBoxLayout *PageLayout=NULL); ~PagedTableWidget(); - void setData(const QList> &data, int rowsPerPage = 10,QTableWidget *table=NULL); + void setData(int datacount, int rowsPerPage = 10); void setCurrentPage(int page); signals: @@ -30,6 +30,7 @@ QHBoxLayout *pageLayout; QList pageButtons; QList> allData; + int totaldatacount; int rowsPerPage; int currentPage; diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.cpp b/softwareDirectory/AutoVerScheme/basecommonapi.cpp index 49cbd7e..6f6fe94 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.cpp +++ b/softwareDirectory/AutoVerScheme/basecommonapi.cpp @@ -13,7 +13,7 @@ } const QString BaseCommonApi::temporary_user_id="1634107227953819649"; const QString BaseCommonApi::measure_person_id="1695282436182188034"; - +static SyncRunStatus syncstate=SyncRunStatus::Stopped; //sys_user表的id转换为measure_person_id 检定人id(meter_staff表id) @@ -167,7 +167,8 @@ "JOIN eqpt_equipment_info eei ON eei.id = blei.sample_id " "JOIN biz_business_order_info bo ON bo.id = blei.order_id " "LEFT JOIN sys_dept sd ON blei.measure_dept_id = sd.ID " - " WHERE blei.measure_person_id = :person_id " + " WHERE blei.measure_person_id = :person_id " + " AND blei.measure_status =3 or blei.measure_status = 4 " " ORDER BY blei.update_time DESC"); // 将参数绑定到占位符 @@ -175,7 +176,8 @@ //query.bindValue(":status", status); if (query.exec()) { while (query.next()) { - MyTask task; + + MyTask task; task.id = query.value("id").toString(); task.sample_name = query.value("sampleName").toString(); task.sample_model = query.value("sampleModel").toString(); @@ -2872,9 +2874,40 @@ return result; } +//保存log信息 +//log文件 + bool BaseCommonApi::SaveLogInfo(QString path,QString Info) +{ + QByteArray utf8Dat; + QString Message=Info; + QFile file(path); + // 如果目录不存在,则创建目录 + // 获取文件所在的目录 + QDir logDir = QDir(QFileInfo(path).absolutePath()); + if (!logDir.exists()) { + if (!logDir.mkpath(".")) { + qDebug() << "Failed to create log directory:" << logDir.absolutePath(); + return false; + } + } + + if (!file.open(QIODevice::Append | QIODevice::Text)) { + qDebug() << "无法打开文件:" << file.errorString(); + return false; + } + QTextStream out(&file); + utf8Dat = Message.toUtf8(); + out << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss") + << "\t" << utf8Dat << "\n"; + file.close(); + return true; + } + + //新增日志表数据 bool BaseCommonApi::InsertzdLog(zdLog log) { + log.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_log(id,is_sync,sync_time,remark,userid,type,create_time,update_time) " " VALUES(:id,:is_sync,:sync_time,:remark,:userid,:type,:create_time,:update_time) "); @@ -2898,6 +2931,7 @@ //根据userid查询日志表数据 QList BaseCommonApi::getzdLogByuserId(QString userid) { + userid=temporary_user_id; QList result; QSqlQuery query; query.prepare("SELECT * FROM zd_log WHERE userid = :userid "); @@ -2922,6 +2956,7 @@ //新增数据同步表 bool BaseCommonApi::InsertzdDataSync(zdDataSync data) { + data.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_data_sync(id,type,ssql,userid,remark,create_time,update_time,log_sync_id,sync_type) " " VALUES " @@ -2945,12 +2980,12 @@ return isSuccess; } //根据userid查询数据同步表 -QList getzdDataSyncByuserId(QString userid) +QList BaseCommonApi::getzdDataSyncByuserId(QString log_sync_id) { QList result; QSqlQuery query; - query.prepare("SELECT * FROM zd_data_sync WHERE userid= :userid "); - query.bindValue(":userid",userid); + query.prepare("SELECT * FROM zd_data_sync WHERE log_sync_id= :log_sync_id "); + query.bindValue(":log_sync_id",log_sync_id); if (query.exec()) { while (query.next()) { zdDataSync data; @@ -2972,3 +3007,4 @@ } + diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.h b/softwareDirectory/AutoVerScheme/basecommonapi.h index 12196fb..4949683 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.h +++ b/softwareDirectory/AutoVerScheme/basecommonapi.h @@ -919,6 +919,7 @@ QDateTime create_time; QDateTime update_time; }; + //数据同步-数据表 class zdDataSync { @@ -935,6 +936,12 @@ }; +enum class SyncRunStatus { + + Running, + Stopped, + Paused +}; using namespace Jiawa::Core; class BaseCommonApi @@ -945,7 +952,6 @@ const static QString temporary_costomer_id; const static QString measure_person_id; - QString encrypt(const QString &str, const QString &publicKey); //判断检定装置表并查询 参数设备id @@ -1137,14 +1143,19 @@ //单独查询任务单表 //更新 任务单 static InsertTask SelectTaskSingle(QString order_id); + + //log文件 + static bool SaveLogInfo(QString path,QString Info); + //新增日志表数据 static bool InsertzdLog(zdLog log); //查询日志表数据 static QList getzdLogByuserId(QString userid); //新增数据同步表 static bool InsertzdDataSync(zdDataSync data); - //根据userid查询数据同步表 - static QList getzdDataSyncByuserId(QString userid); + //根据log_sync_id查询数据同步表 + static QList getzdDataSyncByuserId(QString log_sync_id); + }; diff --git a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro index bf70fab..d9a99ea 100644 --- a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro +++ b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro @@ -35,6 +35,7 @@ create_task.cpp \ createtask_scandevice.cpp \ databaseconnection.cpp \ + databaseconnectionmainsys.cpp \ datasyncview.cpp \ depar_task.cpp \ depar_task_server.cpp \ @@ -55,6 +56,7 @@ newverifymethod.cpp \ rulefileitem.cpp \ standard_deviceitem.cpp \ + syncdialog.cpp \ synctask.cpp \ testdataitem.cpp \ testview.cpp \ @@ -69,6 +71,7 @@ DataProcessingBLL.h \ PageControl.h \ createtask_scandevice.h \ + databaseconnectionmainsys.h \ formaddrsetting.h \ formcommsetting.h \ id/IdWorker.h \ @@ -104,6 +107,7 @@ newverifymethod.h \ rulefileitem.h \ standard_deviceitem.h \ + syncdialog.h \ synctask.h \ testdataitem.h \ testview.h \ @@ -138,6 +142,7 @@ newverifymethod.ui \ rulefileitem.ui \ standard_deviceitem.ui \ + syncdialog.ui \ testdataitem.ui \ testview.ui \ verifydevice.ui \ diff --git a/softwareDirectory/AutoVerScheme/PageControl.cpp b/softwareDirectory/AutoVerScheme/PageControl.cpp index d0fd72b..d1bdddc 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.cpp +++ b/softwareDirectory/AutoVerScheme/PageControl.cpp @@ -22,14 +22,14 @@ } } -void PagedTableWidget::setData(const QList> &data, int rowsPerPage,QTableWidget *table) { - tableWidget=table; - +void PagedTableWidget::setData(int datacount, int rowsPerPage) { + //tableWidget=table; + totaldatacount=datacount; this->rowsPerPage = rowsPerPage; - allData = data; + //allData = data; currentPage = 0; createPageButtons(); - updateTable(); + //updateTable(); } void PagedTableWidget::setCurrentPage(int page) { @@ -39,7 +39,7 @@ button->setChecked(false); }*/ currentPage = page; - updateTable(); + //updateTable(); emit pageChanged(page); } } @@ -89,6 +89,7 @@ setCurrentPage(pageIndex); } } +/* void PagedTableWidget::updateTable() { //tableWidget->clear(); tableWidget->setRowCount(0); @@ -105,7 +106,7 @@ } } } - +*/ void PagedTableWidget::createPageButtons() { int totalPages = calculateTotalPages(); for (auto button : pageButtons) { @@ -150,5 +151,5 @@ } int PagedTableWidget::calculateTotalPages() { - return ((allData.count() + rowsPerPage -1) / rowsPerPage); + return ((totaldatacount + rowsPerPage -1) / rowsPerPage); } diff --git a/softwareDirectory/AutoVerScheme/PageControl.h b/softwareDirectory/AutoVerScheme/PageControl.h index 74ed1ce..2224760 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.h +++ b/softwareDirectory/AutoVerScheme/PageControl.h @@ -15,7 +15,7 @@ explicit PagedTableWidget(QWidget *parent = nullptr,QHBoxLayout *PageLayout=NULL); ~PagedTableWidget(); - void setData(const QList> &data, int rowsPerPage = 10,QTableWidget *table=NULL); + void setData(int datacount, int rowsPerPage = 10); void setCurrentPage(int page); signals: @@ -30,6 +30,7 @@ QHBoxLayout *pageLayout; QList pageButtons; QList> allData; + int totaldatacount; int rowsPerPage; int currentPage; diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.cpp b/softwareDirectory/AutoVerScheme/basecommonapi.cpp index 49cbd7e..6f6fe94 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.cpp +++ b/softwareDirectory/AutoVerScheme/basecommonapi.cpp @@ -13,7 +13,7 @@ } const QString BaseCommonApi::temporary_user_id="1634107227953819649"; const QString BaseCommonApi::measure_person_id="1695282436182188034"; - +static SyncRunStatus syncstate=SyncRunStatus::Stopped; //sys_user表的id转换为measure_person_id 检定人id(meter_staff表id) @@ -167,7 +167,8 @@ "JOIN eqpt_equipment_info eei ON eei.id = blei.sample_id " "JOIN biz_business_order_info bo ON bo.id = blei.order_id " "LEFT JOIN sys_dept sd ON blei.measure_dept_id = sd.ID " - " WHERE blei.measure_person_id = :person_id " + " WHERE blei.measure_person_id = :person_id " + " AND blei.measure_status =3 or blei.measure_status = 4 " " ORDER BY blei.update_time DESC"); // 将参数绑定到占位符 @@ -175,7 +176,8 @@ //query.bindValue(":status", status); if (query.exec()) { while (query.next()) { - MyTask task; + + MyTask task; task.id = query.value("id").toString(); task.sample_name = query.value("sampleName").toString(); task.sample_model = query.value("sampleModel").toString(); @@ -2872,9 +2874,40 @@ return result; } +//保存log信息 +//log文件 + bool BaseCommonApi::SaveLogInfo(QString path,QString Info) +{ + QByteArray utf8Dat; + QString Message=Info; + QFile file(path); + // 如果目录不存在,则创建目录 + // 获取文件所在的目录 + QDir logDir = QDir(QFileInfo(path).absolutePath()); + if (!logDir.exists()) { + if (!logDir.mkpath(".")) { + qDebug() << "Failed to create log directory:" << logDir.absolutePath(); + return false; + } + } + + if (!file.open(QIODevice::Append | QIODevice::Text)) { + qDebug() << "无法打开文件:" << file.errorString(); + return false; + } + QTextStream out(&file); + utf8Dat = Message.toUtf8(); + out << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss") + << "\t" << utf8Dat << "\n"; + file.close(); + return true; + } + + //新增日志表数据 bool BaseCommonApi::InsertzdLog(zdLog log) { + log.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_log(id,is_sync,sync_time,remark,userid,type,create_time,update_time) " " VALUES(:id,:is_sync,:sync_time,:remark,:userid,:type,:create_time,:update_time) "); @@ -2898,6 +2931,7 @@ //根据userid查询日志表数据 QList BaseCommonApi::getzdLogByuserId(QString userid) { + userid=temporary_user_id; QList result; QSqlQuery query; query.prepare("SELECT * FROM zd_log WHERE userid = :userid "); @@ -2922,6 +2956,7 @@ //新增数据同步表 bool BaseCommonApi::InsertzdDataSync(zdDataSync data) { + data.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_data_sync(id,type,ssql,userid,remark,create_time,update_time,log_sync_id,sync_type) " " VALUES " @@ -2945,12 +2980,12 @@ return isSuccess; } //根据userid查询数据同步表 -QList getzdDataSyncByuserId(QString userid) +QList BaseCommonApi::getzdDataSyncByuserId(QString log_sync_id) { QList result; QSqlQuery query; - query.prepare("SELECT * FROM zd_data_sync WHERE userid= :userid "); - query.bindValue(":userid",userid); + query.prepare("SELECT * FROM zd_data_sync WHERE log_sync_id= :log_sync_id "); + query.bindValue(":log_sync_id",log_sync_id); if (query.exec()) { while (query.next()) { zdDataSync data; @@ -2972,3 +3007,4 @@ } + diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.h b/softwareDirectory/AutoVerScheme/basecommonapi.h index 12196fb..4949683 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.h +++ b/softwareDirectory/AutoVerScheme/basecommonapi.h @@ -919,6 +919,7 @@ QDateTime create_time; QDateTime update_time; }; + //数据同步-数据表 class zdDataSync { @@ -935,6 +936,12 @@ }; +enum class SyncRunStatus { + + Running, + Stopped, + Paused +}; using namespace Jiawa::Core; class BaseCommonApi @@ -945,7 +952,6 @@ const static QString temporary_costomer_id; const static QString measure_person_id; - QString encrypt(const QString &str, const QString &publicKey); //判断检定装置表并查询 参数设备id @@ -1137,14 +1143,19 @@ //单独查询任务单表 //更新 任务单 static InsertTask SelectTaskSingle(QString order_id); + + //log文件 + static bool SaveLogInfo(QString path,QString Info); + //新增日志表数据 static bool InsertzdLog(zdLog log); //查询日志表数据 static QList getzdLogByuserId(QString userid); //新增数据同步表 static bool InsertzdDataSync(zdDataSync data); - //根据userid查询数据同步表 - static QList getzdDataSyncByuserId(QString userid); + //根据log_sync_id查询数据同步表 + static QList getzdDataSyncByuserId(QString log_sync_id); + }; diff --git a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp index 00d746b..ae60962 100644 --- a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp @@ -352,6 +352,7 @@ } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -395,6 +396,7 @@ row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro index bf70fab..d9a99ea 100644 --- a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro +++ b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro @@ -35,6 +35,7 @@ create_task.cpp \ createtask_scandevice.cpp \ databaseconnection.cpp \ + databaseconnectionmainsys.cpp \ datasyncview.cpp \ depar_task.cpp \ depar_task_server.cpp \ @@ -55,6 +56,7 @@ newverifymethod.cpp \ rulefileitem.cpp \ standard_deviceitem.cpp \ + syncdialog.cpp \ synctask.cpp \ testdataitem.cpp \ testview.cpp \ @@ -69,6 +71,7 @@ DataProcessingBLL.h \ PageControl.h \ createtask_scandevice.h \ + databaseconnectionmainsys.h \ formaddrsetting.h \ formcommsetting.h \ id/IdWorker.h \ @@ -104,6 +107,7 @@ newverifymethod.h \ rulefileitem.h \ standard_deviceitem.h \ + syncdialog.h \ synctask.h \ testdataitem.h \ testview.h \ @@ -138,6 +142,7 @@ newverifymethod.ui \ rulefileitem.ui \ standard_deviceitem.ui \ + syncdialog.ui \ testdataitem.ui \ testview.ui \ verifydevice.ui \ diff --git a/softwareDirectory/AutoVerScheme/PageControl.cpp b/softwareDirectory/AutoVerScheme/PageControl.cpp index d0fd72b..d1bdddc 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.cpp +++ b/softwareDirectory/AutoVerScheme/PageControl.cpp @@ -22,14 +22,14 @@ } } -void PagedTableWidget::setData(const QList> &data, int rowsPerPage,QTableWidget *table) { - tableWidget=table; - +void PagedTableWidget::setData(int datacount, int rowsPerPage) { + //tableWidget=table; + totaldatacount=datacount; this->rowsPerPage = rowsPerPage; - allData = data; + //allData = data; currentPage = 0; createPageButtons(); - updateTable(); + //updateTable(); } void PagedTableWidget::setCurrentPage(int page) { @@ -39,7 +39,7 @@ button->setChecked(false); }*/ currentPage = page; - updateTable(); + //updateTable(); emit pageChanged(page); } } @@ -89,6 +89,7 @@ setCurrentPage(pageIndex); } } +/* void PagedTableWidget::updateTable() { //tableWidget->clear(); tableWidget->setRowCount(0); @@ -105,7 +106,7 @@ } } } - +*/ void PagedTableWidget::createPageButtons() { int totalPages = calculateTotalPages(); for (auto button : pageButtons) { @@ -150,5 +151,5 @@ } int PagedTableWidget::calculateTotalPages() { - return ((allData.count() + rowsPerPage -1) / rowsPerPage); + return ((totaldatacount + rowsPerPage -1) / rowsPerPage); } diff --git a/softwareDirectory/AutoVerScheme/PageControl.h b/softwareDirectory/AutoVerScheme/PageControl.h index 74ed1ce..2224760 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.h +++ b/softwareDirectory/AutoVerScheme/PageControl.h @@ -15,7 +15,7 @@ explicit PagedTableWidget(QWidget *parent = nullptr,QHBoxLayout *PageLayout=NULL); ~PagedTableWidget(); - void setData(const QList> &data, int rowsPerPage = 10,QTableWidget *table=NULL); + void setData(int datacount, int rowsPerPage = 10); void setCurrentPage(int page); signals: @@ -30,6 +30,7 @@ QHBoxLayout *pageLayout; QList pageButtons; QList> allData; + int totaldatacount; int rowsPerPage; int currentPage; diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.cpp b/softwareDirectory/AutoVerScheme/basecommonapi.cpp index 49cbd7e..6f6fe94 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.cpp +++ b/softwareDirectory/AutoVerScheme/basecommonapi.cpp @@ -13,7 +13,7 @@ } const QString BaseCommonApi::temporary_user_id="1634107227953819649"; const QString BaseCommonApi::measure_person_id="1695282436182188034"; - +static SyncRunStatus syncstate=SyncRunStatus::Stopped; //sys_user表的id转换为measure_person_id 检定人id(meter_staff表id) @@ -167,7 +167,8 @@ "JOIN eqpt_equipment_info eei ON eei.id = blei.sample_id " "JOIN biz_business_order_info bo ON bo.id = blei.order_id " "LEFT JOIN sys_dept sd ON blei.measure_dept_id = sd.ID " - " WHERE blei.measure_person_id = :person_id " + " WHERE blei.measure_person_id = :person_id " + " AND blei.measure_status =3 or blei.measure_status = 4 " " ORDER BY blei.update_time DESC"); // 将参数绑定到占位符 @@ -175,7 +176,8 @@ //query.bindValue(":status", status); if (query.exec()) { while (query.next()) { - MyTask task; + + MyTask task; task.id = query.value("id").toString(); task.sample_name = query.value("sampleName").toString(); task.sample_model = query.value("sampleModel").toString(); @@ -2872,9 +2874,40 @@ return result; } +//保存log信息 +//log文件 + bool BaseCommonApi::SaveLogInfo(QString path,QString Info) +{ + QByteArray utf8Dat; + QString Message=Info; + QFile file(path); + // 如果目录不存在,则创建目录 + // 获取文件所在的目录 + QDir logDir = QDir(QFileInfo(path).absolutePath()); + if (!logDir.exists()) { + if (!logDir.mkpath(".")) { + qDebug() << "Failed to create log directory:" << logDir.absolutePath(); + return false; + } + } + + if (!file.open(QIODevice::Append | QIODevice::Text)) { + qDebug() << "无法打开文件:" << file.errorString(); + return false; + } + QTextStream out(&file); + utf8Dat = Message.toUtf8(); + out << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss") + << "\t" << utf8Dat << "\n"; + file.close(); + return true; + } + + //新增日志表数据 bool BaseCommonApi::InsertzdLog(zdLog log) { + log.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_log(id,is_sync,sync_time,remark,userid,type,create_time,update_time) " " VALUES(:id,:is_sync,:sync_time,:remark,:userid,:type,:create_time,:update_time) "); @@ -2898,6 +2931,7 @@ //根据userid查询日志表数据 QList BaseCommonApi::getzdLogByuserId(QString userid) { + userid=temporary_user_id; QList result; QSqlQuery query; query.prepare("SELECT * FROM zd_log WHERE userid = :userid "); @@ -2922,6 +2956,7 @@ //新增数据同步表 bool BaseCommonApi::InsertzdDataSync(zdDataSync data) { + data.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_data_sync(id,type,ssql,userid,remark,create_time,update_time,log_sync_id,sync_type) " " VALUES " @@ -2945,12 +2980,12 @@ return isSuccess; } //根据userid查询数据同步表 -QList getzdDataSyncByuserId(QString userid) +QList BaseCommonApi::getzdDataSyncByuserId(QString log_sync_id) { QList result; QSqlQuery query; - query.prepare("SELECT * FROM zd_data_sync WHERE userid= :userid "); - query.bindValue(":userid",userid); + query.prepare("SELECT * FROM zd_data_sync WHERE log_sync_id= :log_sync_id "); + query.bindValue(":log_sync_id",log_sync_id); if (query.exec()) { while (query.next()) { zdDataSync data; @@ -2972,3 +3007,4 @@ } + diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.h b/softwareDirectory/AutoVerScheme/basecommonapi.h index 12196fb..4949683 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.h +++ b/softwareDirectory/AutoVerScheme/basecommonapi.h @@ -919,6 +919,7 @@ QDateTime create_time; QDateTime update_time; }; + //数据同步-数据表 class zdDataSync { @@ -935,6 +936,12 @@ }; +enum class SyncRunStatus { + + Running, + Stopped, + Paused +}; using namespace Jiawa::Core; class BaseCommonApi @@ -945,7 +952,6 @@ const static QString temporary_costomer_id; const static QString measure_person_id; - QString encrypt(const QString &str, const QString &publicKey); //判断检定装置表并查询 参数设备id @@ -1137,14 +1143,19 @@ //单独查询任务单表 //更新 任务单 static InsertTask SelectTaskSingle(QString order_id); + + //log文件 + static bool SaveLogInfo(QString path,QString Info); + //新增日志表数据 static bool InsertzdLog(zdLog log); //查询日志表数据 static QList getzdLogByuserId(QString userid); //新增数据同步表 static bool InsertzdDataSync(zdDataSync data); - //根据userid查询数据同步表 - static QList getzdDataSyncByuserId(QString userid); + //根据log_sync_id查询数据同步表 + static QList getzdDataSyncByuserId(QString log_sync_id); + }; diff --git a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp index 00d746b..ae60962 100644 --- a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp @@ -352,6 +352,7 @@ } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -395,6 +396,7 @@ row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.cpp b/softwareDirectory/AutoVerScheme/databaseconnection.cpp index 1d957d9..5284fe6 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.cpp +++ b/softwareDirectory/AutoVerScheme/databaseconnection.cpp @@ -10,17 +10,21 @@ { // 连接数据库 - db = QSqlDatabase::addDatabase("QODBC"); - /*db.setHostName("111.198.10.15"); - db.setDatabaseName("casic_metering_xichang"); - db.setPort(21906); - db.setUserName("zdjdcs"); - db.setPassword("11111111");*/ - db.setHostName("localhost"); - db.setDatabaseName("zdjd"); - db.setPort(3306); - db.setUserName("root"); - db.setPassword("123456"); + localdb = QSqlDatabase::addDatabase("QODBC"); + + localdb.setHostName("localhost"); + localdb.setDatabaseName("zdjd"); + localdb.setPort(3306); + localdb.setUserName("root"); + localdb.setPassword("123456"); + + Maindb = QSqlDatabase::addDatabase("QODBC","Main"); + Maindb.setHostName("111.198.10.15"); + Maindb.setDatabaseName("casic_metering_xichang"); + Maindb.setPort(21906); + Maindb.setUserName("zdjdcs"); + Maindb.setPassword("11111111"); + } @@ -29,18 +33,28 @@ close(); } bool DatabaseConnection::open() { - return db.open(); + return localdb.open(); +} +bool DatabaseConnection::openmain() { + return Maindb.open(); } bool DatabaseConnection::isopen() { - return db.isOpen(); + return localdb.isOpen(); } - +bool DatabaseConnection::isopenmain() { + return Maindb.isOpen(); +} void DatabaseConnection::close() { - db.close(); + localdb.close(); } - +void DatabaseConnection::closemain() { + Maindb.close(); +} QSqlDatabase& DatabaseConnection::getDatabase() { - return db; + return localdb; +} +QSqlDatabase& DatabaseConnection::getDatabaseMain() { + return Maindb; } DatabaseConnection* DatabaseConnection::getInstance() { diff --git a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro index bf70fab..d9a99ea 100644 --- a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro +++ b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro @@ -35,6 +35,7 @@ create_task.cpp \ createtask_scandevice.cpp \ databaseconnection.cpp \ + databaseconnectionmainsys.cpp \ datasyncview.cpp \ depar_task.cpp \ depar_task_server.cpp \ @@ -55,6 +56,7 @@ newverifymethod.cpp \ rulefileitem.cpp \ standard_deviceitem.cpp \ + syncdialog.cpp \ synctask.cpp \ testdataitem.cpp \ testview.cpp \ @@ -69,6 +71,7 @@ DataProcessingBLL.h \ PageControl.h \ createtask_scandevice.h \ + databaseconnectionmainsys.h \ formaddrsetting.h \ formcommsetting.h \ id/IdWorker.h \ @@ -104,6 +107,7 @@ newverifymethod.h \ rulefileitem.h \ standard_deviceitem.h \ + syncdialog.h \ synctask.h \ testdataitem.h \ testview.h \ @@ -138,6 +142,7 @@ newverifymethod.ui \ rulefileitem.ui \ standard_deviceitem.ui \ + syncdialog.ui \ testdataitem.ui \ testview.ui \ verifydevice.ui \ diff --git a/softwareDirectory/AutoVerScheme/PageControl.cpp b/softwareDirectory/AutoVerScheme/PageControl.cpp index d0fd72b..d1bdddc 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.cpp +++ b/softwareDirectory/AutoVerScheme/PageControl.cpp @@ -22,14 +22,14 @@ } } -void PagedTableWidget::setData(const QList> &data, int rowsPerPage,QTableWidget *table) { - tableWidget=table; - +void PagedTableWidget::setData(int datacount, int rowsPerPage) { + //tableWidget=table; + totaldatacount=datacount; this->rowsPerPage = rowsPerPage; - allData = data; + //allData = data; currentPage = 0; createPageButtons(); - updateTable(); + //updateTable(); } void PagedTableWidget::setCurrentPage(int page) { @@ -39,7 +39,7 @@ button->setChecked(false); }*/ currentPage = page; - updateTable(); + //updateTable(); emit pageChanged(page); } } @@ -89,6 +89,7 @@ setCurrentPage(pageIndex); } } +/* void PagedTableWidget::updateTable() { //tableWidget->clear(); tableWidget->setRowCount(0); @@ -105,7 +106,7 @@ } } } - +*/ void PagedTableWidget::createPageButtons() { int totalPages = calculateTotalPages(); for (auto button : pageButtons) { @@ -150,5 +151,5 @@ } int PagedTableWidget::calculateTotalPages() { - return ((allData.count() + rowsPerPage -1) / rowsPerPage); + return ((totaldatacount + rowsPerPage -1) / rowsPerPage); } diff --git a/softwareDirectory/AutoVerScheme/PageControl.h b/softwareDirectory/AutoVerScheme/PageControl.h index 74ed1ce..2224760 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.h +++ b/softwareDirectory/AutoVerScheme/PageControl.h @@ -15,7 +15,7 @@ explicit PagedTableWidget(QWidget *parent = nullptr,QHBoxLayout *PageLayout=NULL); ~PagedTableWidget(); - void setData(const QList> &data, int rowsPerPage = 10,QTableWidget *table=NULL); + void setData(int datacount, int rowsPerPage = 10); void setCurrentPage(int page); signals: @@ -30,6 +30,7 @@ QHBoxLayout *pageLayout; QList pageButtons; QList> allData; + int totaldatacount; int rowsPerPage; int currentPage; diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.cpp b/softwareDirectory/AutoVerScheme/basecommonapi.cpp index 49cbd7e..6f6fe94 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.cpp +++ b/softwareDirectory/AutoVerScheme/basecommonapi.cpp @@ -13,7 +13,7 @@ } const QString BaseCommonApi::temporary_user_id="1634107227953819649"; const QString BaseCommonApi::measure_person_id="1695282436182188034"; - +static SyncRunStatus syncstate=SyncRunStatus::Stopped; //sys_user表的id转换为measure_person_id 检定人id(meter_staff表id) @@ -167,7 +167,8 @@ "JOIN eqpt_equipment_info eei ON eei.id = blei.sample_id " "JOIN biz_business_order_info bo ON bo.id = blei.order_id " "LEFT JOIN sys_dept sd ON blei.measure_dept_id = sd.ID " - " WHERE blei.measure_person_id = :person_id " + " WHERE blei.measure_person_id = :person_id " + " AND blei.measure_status =3 or blei.measure_status = 4 " " ORDER BY blei.update_time DESC"); // 将参数绑定到占位符 @@ -175,7 +176,8 @@ //query.bindValue(":status", status); if (query.exec()) { while (query.next()) { - MyTask task; + + MyTask task; task.id = query.value("id").toString(); task.sample_name = query.value("sampleName").toString(); task.sample_model = query.value("sampleModel").toString(); @@ -2872,9 +2874,40 @@ return result; } +//保存log信息 +//log文件 + bool BaseCommonApi::SaveLogInfo(QString path,QString Info) +{ + QByteArray utf8Dat; + QString Message=Info; + QFile file(path); + // 如果目录不存在,则创建目录 + // 获取文件所在的目录 + QDir logDir = QDir(QFileInfo(path).absolutePath()); + if (!logDir.exists()) { + if (!logDir.mkpath(".")) { + qDebug() << "Failed to create log directory:" << logDir.absolutePath(); + return false; + } + } + + if (!file.open(QIODevice::Append | QIODevice::Text)) { + qDebug() << "无法打开文件:" << file.errorString(); + return false; + } + QTextStream out(&file); + utf8Dat = Message.toUtf8(); + out << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss") + << "\t" << utf8Dat << "\n"; + file.close(); + return true; + } + + //新增日志表数据 bool BaseCommonApi::InsertzdLog(zdLog log) { + log.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_log(id,is_sync,sync_time,remark,userid,type,create_time,update_time) " " VALUES(:id,:is_sync,:sync_time,:remark,:userid,:type,:create_time,:update_time) "); @@ -2898,6 +2931,7 @@ //根据userid查询日志表数据 QList BaseCommonApi::getzdLogByuserId(QString userid) { + userid=temporary_user_id; QList result; QSqlQuery query; query.prepare("SELECT * FROM zd_log WHERE userid = :userid "); @@ -2922,6 +2956,7 @@ //新增数据同步表 bool BaseCommonApi::InsertzdDataSync(zdDataSync data) { + data.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_data_sync(id,type,ssql,userid,remark,create_time,update_time,log_sync_id,sync_type) " " VALUES " @@ -2945,12 +2980,12 @@ return isSuccess; } //根据userid查询数据同步表 -QList getzdDataSyncByuserId(QString userid) +QList BaseCommonApi::getzdDataSyncByuserId(QString log_sync_id) { QList result; QSqlQuery query; - query.prepare("SELECT * FROM zd_data_sync WHERE userid= :userid "); - query.bindValue(":userid",userid); + query.prepare("SELECT * FROM zd_data_sync WHERE log_sync_id= :log_sync_id "); + query.bindValue(":log_sync_id",log_sync_id); if (query.exec()) { while (query.next()) { zdDataSync data; @@ -2972,3 +3007,4 @@ } + diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.h b/softwareDirectory/AutoVerScheme/basecommonapi.h index 12196fb..4949683 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.h +++ b/softwareDirectory/AutoVerScheme/basecommonapi.h @@ -919,6 +919,7 @@ QDateTime create_time; QDateTime update_time; }; + //数据同步-数据表 class zdDataSync { @@ -935,6 +936,12 @@ }; +enum class SyncRunStatus { + + Running, + Stopped, + Paused +}; using namespace Jiawa::Core; class BaseCommonApi @@ -945,7 +952,6 @@ const static QString temporary_costomer_id; const static QString measure_person_id; - QString encrypt(const QString &str, const QString &publicKey); //判断检定装置表并查询 参数设备id @@ -1137,14 +1143,19 @@ //单独查询任务单表 //更新 任务单 static InsertTask SelectTaskSingle(QString order_id); + + //log文件 + static bool SaveLogInfo(QString path,QString Info); + //新增日志表数据 static bool InsertzdLog(zdLog log); //查询日志表数据 static QList getzdLogByuserId(QString userid); //新增数据同步表 static bool InsertzdDataSync(zdDataSync data); - //根据userid查询数据同步表 - static QList getzdDataSyncByuserId(QString userid); + //根据log_sync_id查询数据同步表 + static QList getzdDataSyncByuserId(QString log_sync_id); + }; diff --git a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp index 00d746b..ae60962 100644 --- a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp @@ -352,6 +352,7 @@ } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -395,6 +396,7 @@ row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.cpp b/softwareDirectory/AutoVerScheme/databaseconnection.cpp index 1d957d9..5284fe6 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.cpp +++ b/softwareDirectory/AutoVerScheme/databaseconnection.cpp @@ -10,17 +10,21 @@ { // 连接数据库 - db = QSqlDatabase::addDatabase("QODBC"); - /*db.setHostName("111.198.10.15"); - db.setDatabaseName("casic_metering_xichang"); - db.setPort(21906); - db.setUserName("zdjdcs"); - db.setPassword("11111111");*/ - db.setHostName("localhost"); - db.setDatabaseName("zdjd"); - db.setPort(3306); - db.setUserName("root"); - db.setPassword("123456"); + localdb = QSqlDatabase::addDatabase("QODBC"); + + localdb.setHostName("localhost"); + localdb.setDatabaseName("zdjd"); + localdb.setPort(3306); + localdb.setUserName("root"); + localdb.setPassword("123456"); + + Maindb = QSqlDatabase::addDatabase("QODBC","Main"); + Maindb.setHostName("111.198.10.15"); + Maindb.setDatabaseName("casic_metering_xichang"); + Maindb.setPort(21906); + Maindb.setUserName("zdjdcs"); + Maindb.setPassword("11111111"); + } @@ -29,18 +33,28 @@ close(); } bool DatabaseConnection::open() { - return db.open(); + return localdb.open(); +} +bool DatabaseConnection::openmain() { + return Maindb.open(); } bool DatabaseConnection::isopen() { - return db.isOpen(); + return localdb.isOpen(); } - +bool DatabaseConnection::isopenmain() { + return Maindb.isOpen(); +} void DatabaseConnection::close() { - db.close(); + localdb.close(); } - +void DatabaseConnection::closemain() { + Maindb.close(); +} QSqlDatabase& DatabaseConnection::getDatabase() { - return db; + return localdb; +} +QSqlDatabase& DatabaseConnection::getDatabaseMain() { + return Maindb; } DatabaseConnection* DatabaseConnection::getInstance() { diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.h b/softwareDirectory/AutoVerScheme/databaseconnection.h index 586b794..5f9810b 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.h +++ b/softwareDirectory/AutoVerScheme/databaseconnection.h @@ -16,8 +16,12 @@ ~DatabaseConnection(); bool open(); bool isopen(); + bool openmain(); void close(); + void closemain(); + bool isopenmain(); QSqlDatabase& getDatabase(); + QSqlDatabase& getDatabaseMain(); private: //单列模式 保证DatabaseConnection的唯一性 static DatabaseConnection* Connect; @@ -33,7 +37,8 @@ //如果尝试这样做,编译器同样会报错。 DatabaseConnection& operator=(const DatabaseConnection&) = delete; //数据库db类 - QSqlDatabase db; + QSqlDatabase Maindb; + QSqlDatabase localdb; }; #endif // DATABASECONNECTION_H diff --git a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro index bf70fab..d9a99ea 100644 --- a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro +++ b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro @@ -35,6 +35,7 @@ create_task.cpp \ createtask_scandevice.cpp \ databaseconnection.cpp \ + databaseconnectionmainsys.cpp \ datasyncview.cpp \ depar_task.cpp \ depar_task_server.cpp \ @@ -55,6 +56,7 @@ newverifymethod.cpp \ rulefileitem.cpp \ standard_deviceitem.cpp \ + syncdialog.cpp \ synctask.cpp \ testdataitem.cpp \ testview.cpp \ @@ -69,6 +71,7 @@ DataProcessingBLL.h \ PageControl.h \ createtask_scandevice.h \ + databaseconnectionmainsys.h \ formaddrsetting.h \ formcommsetting.h \ id/IdWorker.h \ @@ -104,6 +107,7 @@ newverifymethod.h \ rulefileitem.h \ standard_deviceitem.h \ + syncdialog.h \ synctask.h \ testdataitem.h \ testview.h \ @@ -138,6 +142,7 @@ newverifymethod.ui \ rulefileitem.ui \ standard_deviceitem.ui \ + syncdialog.ui \ testdataitem.ui \ testview.ui \ verifydevice.ui \ diff --git a/softwareDirectory/AutoVerScheme/PageControl.cpp b/softwareDirectory/AutoVerScheme/PageControl.cpp index d0fd72b..d1bdddc 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.cpp +++ b/softwareDirectory/AutoVerScheme/PageControl.cpp @@ -22,14 +22,14 @@ } } -void PagedTableWidget::setData(const QList> &data, int rowsPerPage,QTableWidget *table) { - tableWidget=table; - +void PagedTableWidget::setData(int datacount, int rowsPerPage) { + //tableWidget=table; + totaldatacount=datacount; this->rowsPerPage = rowsPerPage; - allData = data; + //allData = data; currentPage = 0; createPageButtons(); - updateTable(); + //updateTable(); } void PagedTableWidget::setCurrentPage(int page) { @@ -39,7 +39,7 @@ button->setChecked(false); }*/ currentPage = page; - updateTable(); + //updateTable(); emit pageChanged(page); } } @@ -89,6 +89,7 @@ setCurrentPage(pageIndex); } } +/* void PagedTableWidget::updateTable() { //tableWidget->clear(); tableWidget->setRowCount(0); @@ -105,7 +106,7 @@ } } } - +*/ void PagedTableWidget::createPageButtons() { int totalPages = calculateTotalPages(); for (auto button : pageButtons) { @@ -150,5 +151,5 @@ } int PagedTableWidget::calculateTotalPages() { - return ((allData.count() + rowsPerPage -1) / rowsPerPage); + return ((totaldatacount + rowsPerPage -1) / rowsPerPage); } diff --git a/softwareDirectory/AutoVerScheme/PageControl.h b/softwareDirectory/AutoVerScheme/PageControl.h index 74ed1ce..2224760 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.h +++ b/softwareDirectory/AutoVerScheme/PageControl.h @@ -15,7 +15,7 @@ explicit PagedTableWidget(QWidget *parent = nullptr,QHBoxLayout *PageLayout=NULL); ~PagedTableWidget(); - void setData(const QList> &data, int rowsPerPage = 10,QTableWidget *table=NULL); + void setData(int datacount, int rowsPerPage = 10); void setCurrentPage(int page); signals: @@ -30,6 +30,7 @@ QHBoxLayout *pageLayout; QList pageButtons; QList> allData; + int totaldatacount; int rowsPerPage; int currentPage; diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.cpp b/softwareDirectory/AutoVerScheme/basecommonapi.cpp index 49cbd7e..6f6fe94 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.cpp +++ b/softwareDirectory/AutoVerScheme/basecommonapi.cpp @@ -13,7 +13,7 @@ } const QString BaseCommonApi::temporary_user_id="1634107227953819649"; const QString BaseCommonApi::measure_person_id="1695282436182188034"; - +static SyncRunStatus syncstate=SyncRunStatus::Stopped; //sys_user表的id转换为measure_person_id 检定人id(meter_staff表id) @@ -167,7 +167,8 @@ "JOIN eqpt_equipment_info eei ON eei.id = blei.sample_id " "JOIN biz_business_order_info bo ON bo.id = blei.order_id " "LEFT JOIN sys_dept sd ON blei.measure_dept_id = sd.ID " - " WHERE blei.measure_person_id = :person_id " + " WHERE blei.measure_person_id = :person_id " + " AND blei.measure_status =3 or blei.measure_status = 4 " " ORDER BY blei.update_time DESC"); // 将参数绑定到占位符 @@ -175,7 +176,8 @@ //query.bindValue(":status", status); if (query.exec()) { while (query.next()) { - MyTask task; + + MyTask task; task.id = query.value("id").toString(); task.sample_name = query.value("sampleName").toString(); task.sample_model = query.value("sampleModel").toString(); @@ -2872,9 +2874,40 @@ return result; } +//保存log信息 +//log文件 + bool BaseCommonApi::SaveLogInfo(QString path,QString Info) +{ + QByteArray utf8Dat; + QString Message=Info; + QFile file(path); + // 如果目录不存在,则创建目录 + // 获取文件所在的目录 + QDir logDir = QDir(QFileInfo(path).absolutePath()); + if (!logDir.exists()) { + if (!logDir.mkpath(".")) { + qDebug() << "Failed to create log directory:" << logDir.absolutePath(); + return false; + } + } + + if (!file.open(QIODevice::Append | QIODevice::Text)) { + qDebug() << "无法打开文件:" << file.errorString(); + return false; + } + QTextStream out(&file); + utf8Dat = Message.toUtf8(); + out << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss") + << "\t" << utf8Dat << "\n"; + file.close(); + return true; + } + + //新增日志表数据 bool BaseCommonApi::InsertzdLog(zdLog log) { + log.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_log(id,is_sync,sync_time,remark,userid,type,create_time,update_time) " " VALUES(:id,:is_sync,:sync_time,:remark,:userid,:type,:create_time,:update_time) "); @@ -2898,6 +2931,7 @@ //根据userid查询日志表数据 QList BaseCommonApi::getzdLogByuserId(QString userid) { + userid=temporary_user_id; QList result; QSqlQuery query; query.prepare("SELECT * FROM zd_log WHERE userid = :userid "); @@ -2922,6 +2956,7 @@ //新增数据同步表 bool BaseCommonApi::InsertzdDataSync(zdDataSync data) { + data.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_data_sync(id,type,ssql,userid,remark,create_time,update_time,log_sync_id,sync_type) " " VALUES " @@ -2945,12 +2980,12 @@ return isSuccess; } //根据userid查询数据同步表 -QList getzdDataSyncByuserId(QString userid) +QList BaseCommonApi::getzdDataSyncByuserId(QString log_sync_id) { QList result; QSqlQuery query; - query.prepare("SELECT * FROM zd_data_sync WHERE userid= :userid "); - query.bindValue(":userid",userid); + query.prepare("SELECT * FROM zd_data_sync WHERE log_sync_id= :log_sync_id "); + query.bindValue(":log_sync_id",log_sync_id); if (query.exec()) { while (query.next()) { zdDataSync data; @@ -2972,3 +3007,4 @@ } + diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.h b/softwareDirectory/AutoVerScheme/basecommonapi.h index 12196fb..4949683 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.h +++ b/softwareDirectory/AutoVerScheme/basecommonapi.h @@ -919,6 +919,7 @@ QDateTime create_time; QDateTime update_time; }; + //数据同步-数据表 class zdDataSync { @@ -935,6 +936,12 @@ }; +enum class SyncRunStatus { + + Running, + Stopped, + Paused +}; using namespace Jiawa::Core; class BaseCommonApi @@ -945,7 +952,6 @@ const static QString temporary_costomer_id; const static QString measure_person_id; - QString encrypt(const QString &str, const QString &publicKey); //判断检定装置表并查询 参数设备id @@ -1137,14 +1143,19 @@ //单独查询任务单表 //更新 任务单 static InsertTask SelectTaskSingle(QString order_id); + + //log文件 + static bool SaveLogInfo(QString path,QString Info); + //新增日志表数据 static bool InsertzdLog(zdLog log); //查询日志表数据 static QList getzdLogByuserId(QString userid); //新增数据同步表 static bool InsertzdDataSync(zdDataSync data); - //根据userid查询数据同步表 - static QList getzdDataSyncByuserId(QString userid); + //根据log_sync_id查询数据同步表 + static QList getzdDataSyncByuserId(QString log_sync_id); + }; diff --git a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp index 00d746b..ae60962 100644 --- a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp @@ -352,6 +352,7 @@ } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -395,6 +396,7 @@ row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.cpp b/softwareDirectory/AutoVerScheme/databaseconnection.cpp index 1d957d9..5284fe6 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.cpp +++ b/softwareDirectory/AutoVerScheme/databaseconnection.cpp @@ -10,17 +10,21 @@ { // 连接数据库 - db = QSqlDatabase::addDatabase("QODBC"); - /*db.setHostName("111.198.10.15"); - db.setDatabaseName("casic_metering_xichang"); - db.setPort(21906); - db.setUserName("zdjdcs"); - db.setPassword("11111111");*/ - db.setHostName("localhost"); - db.setDatabaseName("zdjd"); - db.setPort(3306); - db.setUserName("root"); - db.setPassword("123456"); + localdb = QSqlDatabase::addDatabase("QODBC"); + + localdb.setHostName("localhost"); + localdb.setDatabaseName("zdjd"); + localdb.setPort(3306); + localdb.setUserName("root"); + localdb.setPassword("123456"); + + Maindb = QSqlDatabase::addDatabase("QODBC","Main"); + Maindb.setHostName("111.198.10.15"); + Maindb.setDatabaseName("casic_metering_xichang"); + Maindb.setPort(21906); + Maindb.setUserName("zdjdcs"); + Maindb.setPassword("11111111"); + } @@ -29,18 +33,28 @@ close(); } bool DatabaseConnection::open() { - return db.open(); + return localdb.open(); +} +bool DatabaseConnection::openmain() { + return Maindb.open(); } bool DatabaseConnection::isopen() { - return db.isOpen(); + return localdb.isOpen(); } - +bool DatabaseConnection::isopenmain() { + return Maindb.isOpen(); +} void DatabaseConnection::close() { - db.close(); + localdb.close(); } - +void DatabaseConnection::closemain() { + Maindb.close(); +} QSqlDatabase& DatabaseConnection::getDatabase() { - return db; + return localdb; +} +QSqlDatabase& DatabaseConnection::getDatabaseMain() { + return Maindb; } DatabaseConnection* DatabaseConnection::getInstance() { diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.h b/softwareDirectory/AutoVerScheme/databaseconnection.h index 586b794..5f9810b 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.h +++ b/softwareDirectory/AutoVerScheme/databaseconnection.h @@ -16,8 +16,12 @@ ~DatabaseConnection(); bool open(); bool isopen(); + bool openmain(); void close(); + void closemain(); + bool isopenmain(); QSqlDatabase& getDatabase(); + QSqlDatabase& getDatabaseMain(); private: //单列模式 保证DatabaseConnection的唯一性 static DatabaseConnection* Connect; @@ -33,7 +37,8 @@ //如果尝试这样做,编译器同样会报错。 DatabaseConnection& operator=(const DatabaseConnection&) = delete; //数据库db类 - QSqlDatabase db; + QSqlDatabase Maindb; + QSqlDatabase localdb; }; #endif // DATABASECONNECTION_H diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp new file mode 100644 index 0000000..080288b --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp @@ -0,0 +1,54 @@ +#include "databaseconnectionmainsys.h" + + + + +DatabaseConnectionMainSys* DatabaseConnectionMainSys::Connect = nullptr; +QMutex DatabaseConnectionMainSys::mutex; + +DatabaseConnectionMainSys::DatabaseConnectionMainSys() +{ + + // 连接数据库 + dbmain = QSqlDatabase::addDatabase("QODBC"); + dbmain.setHostName("111.198.10.15"); + dbmain.setDatabaseName("casic_metering_xichang"); + dbmain.setPort(21906); + dbmain.setUserName("zdjdcs"); + dbmain.setPassword("11111111"); + /* db.setHostName("localhost"); + db.setDatabaseName("zdjd"); + db.setPort(3306); + db.setUserName("root"); + db.setPassword("123456");*/ + + +} +DatabaseConnectionMainSys::~DatabaseConnectionMainSys() { + // 在析构函数中关闭数据库连接 + close(); +} +bool DatabaseConnectionMainSys::open() { + return dbmain.open(); +} +bool DatabaseConnectionMainSys::isopen() { + return dbmain.isOpen(); +} + +void DatabaseConnectionMainSys::close() { + dbmain.close(); +} + +QSqlDatabase& DatabaseConnectionMainSys::getDatabase() { + return dbmain; +} +DatabaseConnectionMainSys* DatabaseConnectionMainSys::getInstance() +{ + if (!Connect) { + QMutexLocker locker(&mutex); + if (!Connect) { + Connect = new DatabaseConnectionMainSys(); + } + } + return Connect; +} diff --git a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro index bf70fab..d9a99ea 100644 --- a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro +++ b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro @@ -35,6 +35,7 @@ create_task.cpp \ createtask_scandevice.cpp \ databaseconnection.cpp \ + databaseconnectionmainsys.cpp \ datasyncview.cpp \ depar_task.cpp \ depar_task_server.cpp \ @@ -55,6 +56,7 @@ newverifymethod.cpp \ rulefileitem.cpp \ standard_deviceitem.cpp \ + syncdialog.cpp \ synctask.cpp \ testdataitem.cpp \ testview.cpp \ @@ -69,6 +71,7 @@ DataProcessingBLL.h \ PageControl.h \ createtask_scandevice.h \ + databaseconnectionmainsys.h \ formaddrsetting.h \ formcommsetting.h \ id/IdWorker.h \ @@ -104,6 +107,7 @@ newverifymethod.h \ rulefileitem.h \ standard_deviceitem.h \ + syncdialog.h \ synctask.h \ testdataitem.h \ testview.h \ @@ -138,6 +142,7 @@ newverifymethod.ui \ rulefileitem.ui \ standard_deviceitem.ui \ + syncdialog.ui \ testdataitem.ui \ testview.ui \ verifydevice.ui \ diff --git a/softwareDirectory/AutoVerScheme/PageControl.cpp b/softwareDirectory/AutoVerScheme/PageControl.cpp index d0fd72b..d1bdddc 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.cpp +++ b/softwareDirectory/AutoVerScheme/PageControl.cpp @@ -22,14 +22,14 @@ } } -void PagedTableWidget::setData(const QList> &data, int rowsPerPage,QTableWidget *table) { - tableWidget=table; - +void PagedTableWidget::setData(int datacount, int rowsPerPage) { + //tableWidget=table; + totaldatacount=datacount; this->rowsPerPage = rowsPerPage; - allData = data; + //allData = data; currentPage = 0; createPageButtons(); - updateTable(); + //updateTable(); } void PagedTableWidget::setCurrentPage(int page) { @@ -39,7 +39,7 @@ button->setChecked(false); }*/ currentPage = page; - updateTable(); + //updateTable(); emit pageChanged(page); } } @@ -89,6 +89,7 @@ setCurrentPage(pageIndex); } } +/* void PagedTableWidget::updateTable() { //tableWidget->clear(); tableWidget->setRowCount(0); @@ -105,7 +106,7 @@ } } } - +*/ void PagedTableWidget::createPageButtons() { int totalPages = calculateTotalPages(); for (auto button : pageButtons) { @@ -150,5 +151,5 @@ } int PagedTableWidget::calculateTotalPages() { - return ((allData.count() + rowsPerPage -1) / rowsPerPage); + return ((totaldatacount + rowsPerPage -1) / rowsPerPage); } diff --git a/softwareDirectory/AutoVerScheme/PageControl.h b/softwareDirectory/AutoVerScheme/PageControl.h index 74ed1ce..2224760 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.h +++ b/softwareDirectory/AutoVerScheme/PageControl.h @@ -15,7 +15,7 @@ explicit PagedTableWidget(QWidget *parent = nullptr,QHBoxLayout *PageLayout=NULL); ~PagedTableWidget(); - void setData(const QList> &data, int rowsPerPage = 10,QTableWidget *table=NULL); + void setData(int datacount, int rowsPerPage = 10); void setCurrentPage(int page); signals: @@ -30,6 +30,7 @@ QHBoxLayout *pageLayout; QList pageButtons; QList> allData; + int totaldatacount; int rowsPerPage; int currentPage; diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.cpp b/softwareDirectory/AutoVerScheme/basecommonapi.cpp index 49cbd7e..6f6fe94 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.cpp +++ b/softwareDirectory/AutoVerScheme/basecommonapi.cpp @@ -13,7 +13,7 @@ } const QString BaseCommonApi::temporary_user_id="1634107227953819649"; const QString BaseCommonApi::measure_person_id="1695282436182188034"; - +static SyncRunStatus syncstate=SyncRunStatus::Stopped; //sys_user表的id转换为measure_person_id 检定人id(meter_staff表id) @@ -167,7 +167,8 @@ "JOIN eqpt_equipment_info eei ON eei.id = blei.sample_id " "JOIN biz_business_order_info bo ON bo.id = blei.order_id " "LEFT JOIN sys_dept sd ON blei.measure_dept_id = sd.ID " - " WHERE blei.measure_person_id = :person_id " + " WHERE blei.measure_person_id = :person_id " + " AND blei.measure_status =3 or blei.measure_status = 4 " " ORDER BY blei.update_time DESC"); // 将参数绑定到占位符 @@ -175,7 +176,8 @@ //query.bindValue(":status", status); if (query.exec()) { while (query.next()) { - MyTask task; + + MyTask task; task.id = query.value("id").toString(); task.sample_name = query.value("sampleName").toString(); task.sample_model = query.value("sampleModel").toString(); @@ -2872,9 +2874,40 @@ return result; } +//保存log信息 +//log文件 + bool BaseCommonApi::SaveLogInfo(QString path,QString Info) +{ + QByteArray utf8Dat; + QString Message=Info; + QFile file(path); + // 如果目录不存在,则创建目录 + // 获取文件所在的目录 + QDir logDir = QDir(QFileInfo(path).absolutePath()); + if (!logDir.exists()) { + if (!logDir.mkpath(".")) { + qDebug() << "Failed to create log directory:" << logDir.absolutePath(); + return false; + } + } + + if (!file.open(QIODevice::Append | QIODevice::Text)) { + qDebug() << "无法打开文件:" << file.errorString(); + return false; + } + QTextStream out(&file); + utf8Dat = Message.toUtf8(); + out << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss") + << "\t" << utf8Dat << "\n"; + file.close(); + return true; + } + + //新增日志表数据 bool BaseCommonApi::InsertzdLog(zdLog log) { + log.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_log(id,is_sync,sync_time,remark,userid,type,create_time,update_time) " " VALUES(:id,:is_sync,:sync_time,:remark,:userid,:type,:create_time,:update_time) "); @@ -2898,6 +2931,7 @@ //根据userid查询日志表数据 QList BaseCommonApi::getzdLogByuserId(QString userid) { + userid=temporary_user_id; QList result; QSqlQuery query; query.prepare("SELECT * FROM zd_log WHERE userid = :userid "); @@ -2922,6 +2956,7 @@ //新增数据同步表 bool BaseCommonApi::InsertzdDataSync(zdDataSync data) { + data.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_data_sync(id,type,ssql,userid,remark,create_time,update_time,log_sync_id,sync_type) " " VALUES " @@ -2945,12 +2980,12 @@ return isSuccess; } //根据userid查询数据同步表 -QList getzdDataSyncByuserId(QString userid) +QList BaseCommonApi::getzdDataSyncByuserId(QString log_sync_id) { QList result; QSqlQuery query; - query.prepare("SELECT * FROM zd_data_sync WHERE userid= :userid "); - query.bindValue(":userid",userid); + query.prepare("SELECT * FROM zd_data_sync WHERE log_sync_id= :log_sync_id "); + query.bindValue(":log_sync_id",log_sync_id); if (query.exec()) { while (query.next()) { zdDataSync data; @@ -2972,3 +3007,4 @@ } + diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.h b/softwareDirectory/AutoVerScheme/basecommonapi.h index 12196fb..4949683 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.h +++ b/softwareDirectory/AutoVerScheme/basecommonapi.h @@ -919,6 +919,7 @@ QDateTime create_time; QDateTime update_time; }; + //数据同步-数据表 class zdDataSync { @@ -935,6 +936,12 @@ }; +enum class SyncRunStatus { + + Running, + Stopped, + Paused +}; using namespace Jiawa::Core; class BaseCommonApi @@ -945,7 +952,6 @@ const static QString temporary_costomer_id; const static QString measure_person_id; - QString encrypt(const QString &str, const QString &publicKey); //判断检定装置表并查询 参数设备id @@ -1137,14 +1143,19 @@ //单独查询任务单表 //更新 任务单 static InsertTask SelectTaskSingle(QString order_id); + + //log文件 + static bool SaveLogInfo(QString path,QString Info); + //新增日志表数据 static bool InsertzdLog(zdLog log); //查询日志表数据 static QList getzdLogByuserId(QString userid); //新增数据同步表 static bool InsertzdDataSync(zdDataSync data); - //根据userid查询数据同步表 - static QList getzdDataSyncByuserId(QString userid); + //根据log_sync_id查询数据同步表 + static QList getzdDataSyncByuserId(QString log_sync_id); + }; diff --git a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp index 00d746b..ae60962 100644 --- a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp @@ -352,6 +352,7 @@ } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -395,6 +396,7 @@ row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.cpp b/softwareDirectory/AutoVerScheme/databaseconnection.cpp index 1d957d9..5284fe6 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.cpp +++ b/softwareDirectory/AutoVerScheme/databaseconnection.cpp @@ -10,17 +10,21 @@ { // 连接数据库 - db = QSqlDatabase::addDatabase("QODBC"); - /*db.setHostName("111.198.10.15"); - db.setDatabaseName("casic_metering_xichang"); - db.setPort(21906); - db.setUserName("zdjdcs"); - db.setPassword("11111111");*/ - db.setHostName("localhost"); - db.setDatabaseName("zdjd"); - db.setPort(3306); - db.setUserName("root"); - db.setPassword("123456"); + localdb = QSqlDatabase::addDatabase("QODBC"); + + localdb.setHostName("localhost"); + localdb.setDatabaseName("zdjd"); + localdb.setPort(3306); + localdb.setUserName("root"); + localdb.setPassword("123456"); + + Maindb = QSqlDatabase::addDatabase("QODBC","Main"); + Maindb.setHostName("111.198.10.15"); + Maindb.setDatabaseName("casic_metering_xichang"); + Maindb.setPort(21906); + Maindb.setUserName("zdjdcs"); + Maindb.setPassword("11111111"); + } @@ -29,18 +33,28 @@ close(); } bool DatabaseConnection::open() { - return db.open(); + return localdb.open(); +} +bool DatabaseConnection::openmain() { + return Maindb.open(); } bool DatabaseConnection::isopen() { - return db.isOpen(); + return localdb.isOpen(); } - +bool DatabaseConnection::isopenmain() { + return Maindb.isOpen(); +} void DatabaseConnection::close() { - db.close(); + localdb.close(); } - +void DatabaseConnection::closemain() { + Maindb.close(); +} QSqlDatabase& DatabaseConnection::getDatabase() { - return db; + return localdb; +} +QSqlDatabase& DatabaseConnection::getDatabaseMain() { + return Maindb; } DatabaseConnection* DatabaseConnection::getInstance() { diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.h b/softwareDirectory/AutoVerScheme/databaseconnection.h index 586b794..5f9810b 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.h +++ b/softwareDirectory/AutoVerScheme/databaseconnection.h @@ -16,8 +16,12 @@ ~DatabaseConnection(); bool open(); bool isopen(); + bool openmain(); void close(); + void closemain(); + bool isopenmain(); QSqlDatabase& getDatabase(); + QSqlDatabase& getDatabaseMain(); private: //单列模式 保证DatabaseConnection的唯一性 static DatabaseConnection* Connect; @@ -33,7 +37,8 @@ //如果尝试这样做,编译器同样会报错。 DatabaseConnection& operator=(const DatabaseConnection&) = delete; //数据库db类 - QSqlDatabase db; + QSqlDatabase Maindb; + QSqlDatabase localdb; }; #endif // DATABASECONNECTION_H diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp new file mode 100644 index 0000000..080288b --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp @@ -0,0 +1,54 @@ +#include "databaseconnectionmainsys.h" + + + + +DatabaseConnectionMainSys* DatabaseConnectionMainSys::Connect = nullptr; +QMutex DatabaseConnectionMainSys::mutex; + +DatabaseConnectionMainSys::DatabaseConnectionMainSys() +{ + + // 连接数据库 + dbmain = QSqlDatabase::addDatabase("QODBC"); + dbmain.setHostName("111.198.10.15"); + dbmain.setDatabaseName("casic_metering_xichang"); + dbmain.setPort(21906); + dbmain.setUserName("zdjdcs"); + dbmain.setPassword("11111111"); + /* db.setHostName("localhost"); + db.setDatabaseName("zdjd"); + db.setPort(3306); + db.setUserName("root"); + db.setPassword("123456");*/ + + +} +DatabaseConnectionMainSys::~DatabaseConnectionMainSys() { + // 在析构函数中关闭数据库连接 + close(); +} +bool DatabaseConnectionMainSys::open() { + return dbmain.open(); +} +bool DatabaseConnectionMainSys::isopen() { + return dbmain.isOpen(); +} + +void DatabaseConnectionMainSys::close() { + dbmain.close(); +} + +QSqlDatabase& DatabaseConnectionMainSys::getDatabase() { + return dbmain; +} +DatabaseConnectionMainSys* DatabaseConnectionMainSys::getInstance() +{ + if (!Connect) { + QMutexLocker locker(&mutex); + if (!Connect) { + Connect = new DatabaseConnectionMainSys(); + } + } + return Connect; +} diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h new file mode 100644 index 0000000..57702ad --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h @@ -0,0 +1,41 @@ +#ifndef DATABASECONNECTIONMAINSYS_H +#define DATABASECONNECTIONMAINSYS_H +#include +#include +#include +#include + + +class DatabaseConnectionMainSys +{ + + +public: + //获取数据库实例 + static DatabaseConnectionMainSys* getInstance(); + + DatabaseConnectionMainSys(); + ~DatabaseConnectionMainSys(); + bool open(); + bool isopen(); + void close(); + QSqlDatabase& getDatabase(); +private: + //单列模式 保证MainSysDatabaseConnection的唯一性 + static DatabaseConnectionMainSys* Connect; + //QMutex 来确保在多线程环境下单例的正确创建。 + static QMutex mutex; + + //这是拷贝构造函数的声明,后面跟着 = delete; 表示这个构造函数被删除了。 + //这意味着你不能通过拷贝另一个 DatabaseConnection 对象来创建新的 DatabaseConnection 对象。 + //如果尝试这样做,编译器会报错。 + DatabaseConnectionMainSys(const DatabaseConnectionMainSys&) = delete; + //这是拷贝赋值运算符的声明,同样后面跟着 = delete; 表示这个运算符被删除了。 + //这意味着你不能将一个 DatabaseConnection 对象赋值给另一个 DatabaseConnection 对象。 + //如果尝试这样做,编译器同样会报错。 + DatabaseConnectionMainSys& operator=(const DatabaseConnectionMainSys&) = delete; + //数据库db类 + QSqlDatabase dbmain; +}; + +#endif // DATABASECONNECTIONMAINSYS_H diff --git a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro index bf70fab..d9a99ea 100644 --- a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro +++ b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro @@ -35,6 +35,7 @@ create_task.cpp \ createtask_scandevice.cpp \ databaseconnection.cpp \ + databaseconnectionmainsys.cpp \ datasyncview.cpp \ depar_task.cpp \ depar_task_server.cpp \ @@ -55,6 +56,7 @@ newverifymethod.cpp \ rulefileitem.cpp \ standard_deviceitem.cpp \ + syncdialog.cpp \ synctask.cpp \ testdataitem.cpp \ testview.cpp \ @@ -69,6 +71,7 @@ DataProcessingBLL.h \ PageControl.h \ createtask_scandevice.h \ + databaseconnectionmainsys.h \ formaddrsetting.h \ formcommsetting.h \ id/IdWorker.h \ @@ -104,6 +107,7 @@ newverifymethod.h \ rulefileitem.h \ standard_deviceitem.h \ + syncdialog.h \ synctask.h \ testdataitem.h \ testview.h \ @@ -138,6 +142,7 @@ newverifymethod.ui \ rulefileitem.ui \ standard_deviceitem.ui \ + syncdialog.ui \ testdataitem.ui \ testview.ui \ verifydevice.ui \ diff --git a/softwareDirectory/AutoVerScheme/PageControl.cpp b/softwareDirectory/AutoVerScheme/PageControl.cpp index d0fd72b..d1bdddc 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.cpp +++ b/softwareDirectory/AutoVerScheme/PageControl.cpp @@ -22,14 +22,14 @@ } } -void PagedTableWidget::setData(const QList> &data, int rowsPerPage,QTableWidget *table) { - tableWidget=table; - +void PagedTableWidget::setData(int datacount, int rowsPerPage) { + //tableWidget=table; + totaldatacount=datacount; this->rowsPerPage = rowsPerPage; - allData = data; + //allData = data; currentPage = 0; createPageButtons(); - updateTable(); + //updateTable(); } void PagedTableWidget::setCurrentPage(int page) { @@ -39,7 +39,7 @@ button->setChecked(false); }*/ currentPage = page; - updateTable(); + //updateTable(); emit pageChanged(page); } } @@ -89,6 +89,7 @@ setCurrentPage(pageIndex); } } +/* void PagedTableWidget::updateTable() { //tableWidget->clear(); tableWidget->setRowCount(0); @@ -105,7 +106,7 @@ } } } - +*/ void PagedTableWidget::createPageButtons() { int totalPages = calculateTotalPages(); for (auto button : pageButtons) { @@ -150,5 +151,5 @@ } int PagedTableWidget::calculateTotalPages() { - return ((allData.count() + rowsPerPage -1) / rowsPerPage); + return ((totaldatacount + rowsPerPage -1) / rowsPerPage); } diff --git a/softwareDirectory/AutoVerScheme/PageControl.h b/softwareDirectory/AutoVerScheme/PageControl.h index 74ed1ce..2224760 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.h +++ b/softwareDirectory/AutoVerScheme/PageControl.h @@ -15,7 +15,7 @@ explicit PagedTableWidget(QWidget *parent = nullptr,QHBoxLayout *PageLayout=NULL); ~PagedTableWidget(); - void setData(const QList> &data, int rowsPerPage = 10,QTableWidget *table=NULL); + void setData(int datacount, int rowsPerPage = 10); void setCurrentPage(int page); signals: @@ -30,6 +30,7 @@ QHBoxLayout *pageLayout; QList pageButtons; QList> allData; + int totaldatacount; int rowsPerPage; int currentPage; diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.cpp b/softwareDirectory/AutoVerScheme/basecommonapi.cpp index 49cbd7e..6f6fe94 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.cpp +++ b/softwareDirectory/AutoVerScheme/basecommonapi.cpp @@ -13,7 +13,7 @@ } const QString BaseCommonApi::temporary_user_id="1634107227953819649"; const QString BaseCommonApi::measure_person_id="1695282436182188034"; - +static SyncRunStatus syncstate=SyncRunStatus::Stopped; //sys_user表的id转换为measure_person_id 检定人id(meter_staff表id) @@ -167,7 +167,8 @@ "JOIN eqpt_equipment_info eei ON eei.id = blei.sample_id " "JOIN biz_business_order_info bo ON bo.id = blei.order_id " "LEFT JOIN sys_dept sd ON blei.measure_dept_id = sd.ID " - " WHERE blei.measure_person_id = :person_id " + " WHERE blei.measure_person_id = :person_id " + " AND blei.measure_status =3 or blei.measure_status = 4 " " ORDER BY blei.update_time DESC"); // 将参数绑定到占位符 @@ -175,7 +176,8 @@ //query.bindValue(":status", status); if (query.exec()) { while (query.next()) { - MyTask task; + + MyTask task; task.id = query.value("id").toString(); task.sample_name = query.value("sampleName").toString(); task.sample_model = query.value("sampleModel").toString(); @@ -2872,9 +2874,40 @@ return result; } +//保存log信息 +//log文件 + bool BaseCommonApi::SaveLogInfo(QString path,QString Info) +{ + QByteArray utf8Dat; + QString Message=Info; + QFile file(path); + // 如果目录不存在,则创建目录 + // 获取文件所在的目录 + QDir logDir = QDir(QFileInfo(path).absolutePath()); + if (!logDir.exists()) { + if (!logDir.mkpath(".")) { + qDebug() << "Failed to create log directory:" << logDir.absolutePath(); + return false; + } + } + + if (!file.open(QIODevice::Append | QIODevice::Text)) { + qDebug() << "无法打开文件:" << file.errorString(); + return false; + } + QTextStream out(&file); + utf8Dat = Message.toUtf8(); + out << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss") + << "\t" << utf8Dat << "\n"; + file.close(); + return true; + } + + //新增日志表数据 bool BaseCommonApi::InsertzdLog(zdLog log) { + log.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_log(id,is_sync,sync_time,remark,userid,type,create_time,update_time) " " VALUES(:id,:is_sync,:sync_time,:remark,:userid,:type,:create_time,:update_time) "); @@ -2898,6 +2931,7 @@ //根据userid查询日志表数据 QList BaseCommonApi::getzdLogByuserId(QString userid) { + userid=temporary_user_id; QList result; QSqlQuery query; query.prepare("SELECT * FROM zd_log WHERE userid = :userid "); @@ -2922,6 +2956,7 @@ //新增数据同步表 bool BaseCommonApi::InsertzdDataSync(zdDataSync data) { + data.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_data_sync(id,type,ssql,userid,remark,create_time,update_time,log_sync_id,sync_type) " " VALUES " @@ -2945,12 +2980,12 @@ return isSuccess; } //根据userid查询数据同步表 -QList getzdDataSyncByuserId(QString userid) +QList BaseCommonApi::getzdDataSyncByuserId(QString log_sync_id) { QList result; QSqlQuery query; - query.prepare("SELECT * FROM zd_data_sync WHERE userid= :userid "); - query.bindValue(":userid",userid); + query.prepare("SELECT * FROM zd_data_sync WHERE log_sync_id= :log_sync_id "); + query.bindValue(":log_sync_id",log_sync_id); if (query.exec()) { while (query.next()) { zdDataSync data; @@ -2972,3 +3007,4 @@ } + diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.h b/softwareDirectory/AutoVerScheme/basecommonapi.h index 12196fb..4949683 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.h +++ b/softwareDirectory/AutoVerScheme/basecommonapi.h @@ -919,6 +919,7 @@ QDateTime create_time; QDateTime update_time; }; + //数据同步-数据表 class zdDataSync { @@ -935,6 +936,12 @@ }; +enum class SyncRunStatus { + + Running, + Stopped, + Paused +}; using namespace Jiawa::Core; class BaseCommonApi @@ -945,7 +952,6 @@ const static QString temporary_costomer_id; const static QString measure_person_id; - QString encrypt(const QString &str, const QString &publicKey); //判断检定装置表并查询 参数设备id @@ -1137,14 +1143,19 @@ //单独查询任务单表 //更新 任务单 static InsertTask SelectTaskSingle(QString order_id); + + //log文件 + static bool SaveLogInfo(QString path,QString Info); + //新增日志表数据 static bool InsertzdLog(zdLog log); //查询日志表数据 static QList getzdLogByuserId(QString userid); //新增数据同步表 static bool InsertzdDataSync(zdDataSync data); - //根据userid查询数据同步表 - static QList getzdDataSyncByuserId(QString userid); + //根据log_sync_id查询数据同步表 + static QList getzdDataSyncByuserId(QString log_sync_id); + }; diff --git a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp index 00d746b..ae60962 100644 --- a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp @@ -352,6 +352,7 @@ } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -395,6 +396,7 @@ row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.cpp b/softwareDirectory/AutoVerScheme/databaseconnection.cpp index 1d957d9..5284fe6 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.cpp +++ b/softwareDirectory/AutoVerScheme/databaseconnection.cpp @@ -10,17 +10,21 @@ { // 连接数据库 - db = QSqlDatabase::addDatabase("QODBC"); - /*db.setHostName("111.198.10.15"); - db.setDatabaseName("casic_metering_xichang"); - db.setPort(21906); - db.setUserName("zdjdcs"); - db.setPassword("11111111");*/ - db.setHostName("localhost"); - db.setDatabaseName("zdjd"); - db.setPort(3306); - db.setUserName("root"); - db.setPassword("123456"); + localdb = QSqlDatabase::addDatabase("QODBC"); + + localdb.setHostName("localhost"); + localdb.setDatabaseName("zdjd"); + localdb.setPort(3306); + localdb.setUserName("root"); + localdb.setPassword("123456"); + + Maindb = QSqlDatabase::addDatabase("QODBC","Main"); + Maindb.setHostName("111.198.10.15"); + Maindb.setDatabaseName("casic_metering_xichang"); + Maindb.setPort(21906); + Maindb.setUserName("zdjdcs"); + Maindb.setPassword("11111111"); + } @@ -29,18 +33,28 @@ close(); } bool DatabaseConnection::open() { - return db.open(); + return localdb.open(); +} +bool DatabaseConnection::openmain() { + return Maindb.open(); } bool DatabaseConnection::isopen() { - return db.isOpen(); + return localdb.isOpen(); } - +bool DatabaseConnection::isopenmain() { + return Maindb.isOpen(); +} void DatabaseConnection::close() { - db.close(); + localdb.close(); } - +void DatabaseConnection::closemain() { + Maindb.close(); +} QSqlDatabase& DatabaseConnection::getDatabase() { - return db; + return localdb; +} +QSqlDatabase& DatabaseConnection::getDatabaseMain() { + return Maindb; } DatabaseConnection* DatabaseConnection::getInstance() { diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.h b/softwareDirectory/AutoVerScheme/databaseconnection.h index 586b794..5f9810b 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.h +++ b/softwareDirectory/AutoVerScheme/databaseconnection.h @@ -16,8 +16,12 @@ ~DatabaseConnection(); bool open(); bool isopen(); + bool openmain(); void close(); + void closemain(); + bool isopenmain(); QSqlDatabase& getDatabase(); + QSqlDatabase& getDatabaseMain(); private: //单列模式 保证DatabaseConnection的唯一性 static DatabaseConnection* Connect; @@ -33,7 +37,8 @@ //如果尝试这样做,编译器同样会报错。 DatabaseConnection& operator=(const DatabaseConnection&) = delete; //数据库db类 - QSqlDatabase db; + QSqlDatabase Maindb; + QSqlDatabase localdb; }; #endif // DATABASECONNECTION_H diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp new file mode 100644 index 0000000..080288b --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp @@ -0,0 +1,54 @@ +#include "databaseconnectionmainsys.h" + + + + +DatabaseConnectionMainSys* DatabaseConnectionMainSys::Connect = nullptr; +QMutex DatabaseConnectionMainSys::mutex; + +DatabaseConnectionMainSys::DatabaseConnectionMainSys() +{ + + // 连接数据库 + dbmain = QSqlDatabase::addDatabase("QODBC"); + dbmain.setHostName("111.198.10.15"); + dbmain.setDatabaseName("casic_metering_xichang"); + dbmain.setPort(21906); + dbmain.setUserName("zdjdcs"); + dbmain.setPassword("11111111"); + /* db.setHostName("localhost"); + db.setDatabaseName("zdjd"); + db.setPort(3306); + db.setUserName("root"); + db.setPassword("123456");*/ + + +} +DatabaseConnectionMainSys::~DatabaseConnectionMainSys() { + // 在析构函数中关闭数据库连接 + close(); +} +bool DatabaseConnectionMainSys::open() { + return dbmain.open(); +} +bool DatabaseConnectionMainSys::isopen() { + return dbmain.isOpen(); +} + +void DatabaseConnectionMainSys::close() { + dbmain.close(); +} + +QSqlDatabase& DatabaseConnectionMainSys::getDatabase() { + return dbmain; +} +DatabaseConnectionMainSys* DatabaseConnectionMainSys::getInstance() +{ + if (!Connect) { + QMutexLocker locker(&mutex); + if (!Connect) { + Connect = new DatabaseConnectionMainSys(); + } + } + return Connect; +} diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h new file mode 100644 index 0000000..57702ad --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h @@ -0,0 +1,41 @@ +#ifndef DATABASECONNECTIONMAINSYS_H +#define DATABASECONNECTIONMAINSYS_H +#include +#include +#include +#include + + +class DatabaseConnectionMainSys +{ + + +public: + //获取数据库实例 + static DatabaseConnectionMainSys* getInstance(); + + DatabaseConnectionMainSys(); + ~DatabaseConnectionMainSys(); + bool open(); + bool isopen(); + void close(); + QSqlDatabase& getDatabase(); +private: + //单列模式 保证MainSysDatabaseConnection的唯一性 + static DatabaseConnectionMainSys* Connect; + //QMutex 来确保在多线程环境下单例的正确创建。 + static QMutex mutex; + + //这是拷贝构造函数的声明,后面跟着 = delete; 表示这个构造函数被删除了。 + //这意味着你不能通过拷贝另一个 DatabaseConnection 对象来创建新的 DatabaseConnection 对象。 + //如果尝试这样做,编译器会报错。 + DatabaseConnectionMainSys(const DatabaseConnectionMainSys&) = delete; + //这是拷贝赋值运算符的声明,同样后面跟着 = delete; 表示这个运算符被删除了。 + //这意味着你不能将一个 DatabaseConnection 对象赋值给另一个 DatabaseConnection 对象。 + //如果尝试这样做,编译器同样会报错。 + DatabaseConnectionMainSys& operator=(const DatabaseConnectionMainSys&) = delete; + //数据库db类 + QSqlDatabase dbmain; +}; + +#endif // DATABASECONNECTIONMAINSYS_H diff --git a/softwareDirectory/AutoVerScheme/datasyncview.cpp b/softwareDirectory/AutoVerScheme/datasyncview.cpp index fbf4508..06c7f9a 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.cpp +++ b/softwareDirectory/AutoVerScheme/datasyncview.cpp @@ -1,11 +1,10 @@ #include "datasyncview.h" #include "ui_datasyncview.h" -#include "synctask.h" -#include "databaseconnection.h" -#include "mainsysdatabaseconnection.h" +#include "syncdialog.h" - +QString filePath = "C:\\AutoVerScheme\\sync_info.txt"; +// 获取当前时间戳 DataSyncView::DataSyncView(QWidget *parent) : QWidget(parent), ui(new Ui::DataSyncView) @@ -20,7 +19,7 @@ } void DataSyncView::initForm() { - //tableWidget设置 + ui->stackedWidget->setCurrentIndex(0); //设置控件的边框显示 ui->tableWidget->setStyleSheet("QHeaderView::section {" "border: 1px solid grey;" @@ -32,29 +31,129 @@ "}"); ui->tableWidget->setRowCount(10); // 设置10行 - ui->tableWidget->setColumnCount(4); // 设置11列 - ui->tableWidget->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnCount(7); // 设置11列 + ui->tableWidget->setColumnWidth(0, 0); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnWidth(2, 200); // 设置第一列的宽度为100像素 ui->tableWidget->verticalHeader()->setParent(nullptr); //隐藏行头 - QTableWidgetItem *item = new QTableWidgetItem("测试数据"); - item->setTextAlignment(Qt::AlignCenter); - ui->tableWidget->setItem(0, 0, item); //设置数据 + + //初始化TableWidget 设置列 QStringList headers; - headers << "序号" << "同步时间" << "是否同步成功" << "备注" ; + headers <<"id" << "序号" << "同步时间" << "是否同步成功" << "备注" + <<"类型" <<"操作"; ui->tableWidget->setHorizontalHeaderLabels(headers); + //详情内 + + //设置控件的边框显示 + ui->tableWidget_2->setStyleSheet("QHeaderView::section {" + "border: 1px solid grey;" + "border-left:none;" + "border-top:none;" + "background-color:white;" + " color:black;" + "font: bold 18px Arial, sans-serif;" + "}"); + + ui->tableWidget_2->setRowCount(10); // 设置10行 + ui->tableWidget_2->setColumnCount(3); // 设置11列 + ui->tableWidget_2->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget_2->verticalHeader()->setParent(nullptr); //隐藏行头 + ui->tableWidget_2->setColumnWidth(1, 1000); // 设置第一列的宽度为100像素 + + //初始化TableWidget 设置列 + + headers << "序号" << "信息" << "状态" ; + ui->tableWidget_2->setHorizontalHeaderLabels(headers); + + //数据显示 + + //先设置为行为0 + ui->tableWidget->setRowCount(0); + int rowCount=0; + int row=0; + QList zdlog= BaseCommonApi::getzdLogByuserId(""); + for(const zdLog & zd:zdlog) + { + rowCount = ui->tableWidget->rowCount(); + ui->tableWidget->insertRow(rowCount); + ui->tableWidget->setItem(row, 0, new QTableWidgetItem(zd.id)); + ui->tableWidget->setItem(row, 1, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget->setItem(row, 2, new QTableWidgetItem(zd.sync_time.toString())); + ui->tableWidget->setItem(row, 3, new QTableWidgetItem(zd.is_sync)); + ui->tableWidget->setItem(row, 4, new QTableWidgetItem(zd.remark)); + if(zd.type=="1") + { + ui->tableWidget->setItem(row, 5, new QTableWidgetItem("下载")); + }else{ ui->tableWidget->setItem(row, 5, new QTableWidgetItem("上传")); } + + //添加操作按钮 + QPushButton *button = new QPushButton("查询信息"); + button->setIconSize(QSize(16,16)); + button->setIcon(QIcon(":/image/Index/u2327.svg")); + ui->tableWidget->setCellWidget(row, 6, button); + //设置按钮简单样式 + button->setStyleSheet("QPushButton {" + " border: none; /* 无边框 */" + " color: green; /* 文本颜色 */" + " text-decoration: underline; /* 文本下划线 */" + "}"); + + // 设置鼠标悬停时的光标样式为小手图标 + button->setCursor(Qt::PointingHandCursor); + // 连接按钮的 clicked 信号到自定义槽函数 + connect(button, &QPushButton::clicked, this, [this, button, zd]() { + // 获取当前行第一列的 ID + + OnButtonSelectClicked(zd); + + }); + row++; + } } void DataSyncView::on_DownloadDataButton_clicked() { - //从主系统下载 + + SyncDialog *syncDialog = new SyncDialog(this); + syncDialog->exec(); // 显示进度条窗体并阻塞主窗口 + + this->initForm(); + } -void DataSyncView::syncTable() +void DataSyncView::OnButtonSelectClicked(zdLog log) { - //连接两个数据库 - bool IsOpen=false; - DatabaseConnection *Conn=DatabaseConnection::getInstance(); - IsOpen=Conn->open(); - //MainSysDatabaseConnection *MainConn=MainSysDatabaseConnection::getInstance(); - //IsOpen=MainConn->open(); + ui->stackedWidget->setCurrentIndex(1); + ui->tableWidget_2->setRowCount(0); + int rowCount=0; + int row=0; + QList data= BaseCommonApi::getzdDataSyncByuserId(log.id); + for(const zdDataSync & item:data) + { + rowCount = ui->tableWidget_2->rowCount(); + ui->tableWidget_2->insertRow(rowCount); + ui->tableWidget_2->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget_2->setItem(row, 1, new QTableWidgetItem(item.remark)); + QTableWidgetItem *itemRow; + if(item.sync_type=="0"){ + itemRow = new QTableWidgetItem("未同步"); + itemRow->setBackground(QBrush(QColor(255, 255, 192))); + }else if (item.sync_type=="1") + { + itemRow = new QTableWidgetItem("同步成功"); + itemRow->setBackground(QBrush(QColor(173, 255, 47))); // 浅绿色 + }else{ + itemRow = new QTableWidgetItem("同步失败"); + itemRow->setBackground(QBrush(QColor(255, 105, 180))); // 浅红色 + } + itemRow->setTextAlignment(Qt::AlignCenter); + ui->tableWidget_2->setItem(row, 2, itemRow); + + row++; + } +} + +void DataSyncView::on_button_return_clicked() +{ + ui->stackedWidget->setCurrentIndex(0); } diff --git a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro index bf70fab..d9a99ea 100644 --- a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro +++ b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro @@ -35,6 +35,7 @@ create_task.cpp \ createtask_scandevice.cpp \ databaseconnection.cpp \ + databaseconnectionmainsys.cpp \ datasyncview.cpp \ depar_task.cpp \ depar_task_server.cpp \ @@ -55,6 +56,7 @@ newverifymethod.cpp \ rulefileitem.cpp \ standard_deviceitem.cpp \ + syncdialog.cpp \ synctask.cpp \ testdataitem.cpp \ testview.cpp \ @@ -69,6 +71,7 @@ DataProcessingBLL.h \ PageControl.h \ createtask_scandevice.h \ + databaseconnectionmainsys.h \ formaddrsetting.h \ formcommsetting.h \ id/IdWorker.h \ @@ -104,6 +107,7 @@ newverifymethod.h \ rulefileitem.h \ standard_deviceitem.h \ + syncdialog.h \ synctask.h \ testdataitem.h \ testview.h \ @@ -138,6 +142,7 @@ newverifymethod.ui \ rulefileitem.ui \ standard_deviceitem.ui \ + syncdialog.ui \ testdataitem.ui \ testview.ui \ verifydevice.ui \ diff --git a/softwareDirectory/AutoVerScheme/PageControl.cpp b/softwareDirectory/AutoVerScheme/PageControl.cpp index d0fd72b..d1bdddc 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.cpp +++ b/softwareDirectory/AutoVerScheme/PageControl.cpp @@ -22,14 +22,14 @@ } } -void PagedTableWidget::setData(const QList> &data, int rowsPerPage,QTableWidget *table) { - tableWidget=table; - +void PagedTableWidget::setData(int datacount, int rowsPerPage) { + //tableWidget=table; + totaldatacount=datacount; this->rowsPerPage = rowsPerPage; - allData = data; + //allData = data; currentPage = 0; createPageButtons(); - updateTable(); + //updateTable(); } void PagedTableWidget::setCurrentPage(int page) { @@ -39,7 +39,7 @@ button->setChecked(false); }*/ currentPage = page; - updateTable(); + //updateTable(); emit pageChanged(page); } } @@ -89,6 +89,7 @@ setCurrentPage(pageIndex); } } +/* void PagedTableWidget::updateTable() { //tableWidget->clear(); tableWidget->setRowCount(0); @@ -105,7 +106,7 @@ } } } - +*/ void PagedTableWidget::createPageButtons() { int totalPages = calculateTotalPages(); for (auto button : pageButtons) { @@ -150,5 +151,5 @@ } int PagedTableWidget::calculateTotalPages() { - return ((allData.count() + rowsPerPage -1) / rowsPerPage); + return ((totaldatacount + rowsPerPage -1) / rowsPerPage); } diff --git a/softwareDirectory/AutoVerScheme/PageControl.h b/softwareDirectory/AutoVerScheme/PageControl.h index 74ed1ce..2224760 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.h +++ b/softwareDirectory/AutoVerScheme/PageControl.h @@ -15,7 +15,7 @@ explicit PagedTableWidget(QWidget *parent = nullptr,QHBoxLayout *PageLayout=NULL); ~PagedTableWidget(); - void setData(const QList> &data, int rowsPerPage = 10,QTableWidget *table=NULL); + void setData(int datacount, int rowsPerPage = 10); void setCurrentPage(int page); signals: @@ -30,6 +30,7 @@ QHBoxLayout *pageLayout; QList pageButtons; QList> allData; + int totaldatacount; int rowsPerPage; int currentPage; diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.cpp b/softwareDirectory/AutoVerScheme/basecommonapi.cpp index 49cbd7e..6f6fe94 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.cpp +++ b/softwareDirectory/AutoVerScheme/basecommonapi.cpp @@ -13,7 +13,7 @@ } const QString BaseCommonApi::temporary_user_id="1634107227953819649"; const QString BaseCommonApi::measure_person_id="1695282436182188034"; - +static SyncRunStatus syncstate=SyncRunStatus::Stopped; //sys_user表的id转换为measure_person_id 检定人id(meter_staff表id) @@ -167,7 +167,8 @@ "JOIN eqpt_equipment_info eei ON eei.id = blei.sample_id " "JOIN biz_business_order_info bo ON bo.id = blei.order_id " "LEFT JOIN sys_dept sd ON blei.measure_dept_id = sd.ID " - " WHERE blei.measure_person_id = :person_id " + " WHERE blei.measure_person_id = :person_id " + " AND blei.measure_status =3 or blei.measure_status = 4 " " ORDER BY blei.update_time DESC"); // 将参数绑定到占位符 @@ -175,7 +176,8 @@ //query.bindValue(":status", status); if (query.exec()) { while (query.next()) { - MyTask task; + + MyTask task; task.id = query.value("id").toString(); task.sample_name = query.value("sampleName").toString(); task.sample_model = query.value("sampleModel").toString(); @@ -2872,9 +2874,40 @@ return result; } +//保存log信息 +//log文件 + bool BaseCommonApi::SaveLogInfo(QString path,QString Info) +{ + QByteArray utf8Dat; + QString Message=Info; + QFile file(path); + // 如果目录不存在,则创建目录 + // 获取文件所在的目录 + QDir logDir = QDir(QFileInfo(path).absolutePath()); + if (!logDir.exists()) { + if (!logDir.mkpath(".")) { + qDebug() << "Failed to create log directory:" << logDir.absolutePath(); + return false; + } + } + + if (!file.open(QIODevice::Append | QIODevice::Text)) { + qDebug() << "无法打开文件:" << file.errorString(); + return false; + } + QTextStream out(&file); + utf8Dat = Message.toUtf8(); + out << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss") + << "\t" << utf8Dat << "\n"; + file.close(); + return true; + } + + //新增日志表数据 bool BaseCommonApi::InsertzdLog(zdLog log) { + log.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_log(id,is_sync,sync_time,remark,userid,type,create_time,update_time) " " VALUES(:id,:is_sync,:sync_time,:remark,:userid,:type,:create_time,:update_time) "); @@ -2898,6 +2931,7 @@ //根据userid查询日志表数据 QList BaseCommonApi::getzdLogByuserId(QString userid) { + userid=temporary_user_id; QList result; QSqlQuery query; query.prepare("SELECT * FROM zd_log WHERE userid = :userid "); @@ -2922,6 +2956,7 @@ //新增数据同步表 bool BaseCommonApi::InsertzdDataSync(zdDataSync data) { + data.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_data_sync(id,type,ssql,userid,remark,create_time,update_time,log_sync_id,sync_type) " " VALUES " @@ -2945,12 +2980,12 @@ return isSuccess; } //根据userid查询数据同步表 -QList getzdDataSyncByuserId(QString userid) +QList BaseCommonApi::getzdDataSyncByuserId(QString log_sync_id) { QList result; QSqlQuery query; - query.prepare("SELECT * FROM zd_data_sync WHERE userid= :userid "); - query.bindValue(":userid",userid); + query.prepare("SELECT * FROM zd_data_sync WHERE log_sync_id= :log_sync_id "); + query.bindValue(":log_sync_id",log_sync_id); if (query.exec()) { while (query.next()) { zdDataSync data; @@ -2972,3 +3007,4 @@ } + diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.h b/softwareDirectory/AutoVerScheme/basecommonapi.h index 12196fb..4949683 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.h +++ b/softwareDirectory/AutoVerScheme/basecommonapi.h @@ -919,6 +919,7 @@ QDateTime create_time; QDateTime update_time; }; + //数据同步-数据表 class zdDataSync { @@ -935,6 +936,12 @@ }; +enum class SyncRunStatus { + + Running, + Stopped, + Paused +}; using namespace Jiawa::Core; class BaseCommonApi @@ -945,7 +952,6 @@ const static QString temporary_costomer_id; const static QString measure_person_id; - QString encrypt(const QString &str, const QString &publicKey); //判断检定装置表并查询 参数设备id @@ -1137,14 +1143,19 @@ //单独查询任务单表 //更新 任务单 static InsertTask SelectTaskSingle(QString order_id); + + //log文件 + static bool SaveLogInfo(QString path,QString Info); + //新增日志表数据 static bool InsertzdLog(zdLog log); //查询日志表数据 static QList getzdLogByuserId(QString userid); //新增数据同步表 static bool InsertzdDataSync(zdDataSync data); - //根据userid查询数据同步表 - static QList getzdDataSyncByuserId(QString userid); + //根据log_sync_id查询数据同步表 + static QList getzdDataSyncByuserId(QString log_sync_id); + }; diff --git a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp index 00d746b..ae60962 100644 --- a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp @@ -352,6 +352,7 @@ } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -395,6 +396,7 @@ row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.cpp b/softwareDirectory/AutoVerScheme/databaseconnection.cpp index 1d957d9..5284fe6 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.cpp +++ b/softwareDirectory/AutoVerScheme/databaseconnection.cpp @@ -10,17 +10,21 @@ { // 连接数据库 - db = QSqlDatabase::addDatabase("QODBC"); - /*db.setHostName("111.198.10.15"); - db.setDatabaseName("casic_metering_xichang"); - db.setPort(21906); - db.setUserName("zdjdcs"); - db.setPassword("11111111");*/ - db.setHostName("localhost"); - db.setDatabaseName("zdjd"); - db.setPort(3306); - db.setUserName("root"); - db.setPassword("123456"); + localdb = QSqlDatabase::addDatabase("QODBC"); + + localdb.setHostName("localhost"); + localdb.setDatabaseName("zdjd"); + localdb.setPort(3306); + localdb.setUserName("root"); + localdb.setPassword("123456"); + + Maindb = QSqlDatabase::addDatabase("QODBC","Main"); + Maindb.setHostName("111.198.10.15"); + Maindb.setDatabaseName("casic_metering_xichang"); + Maindb.setPort(21906); + Maindb.setUserName("zdjdcs"); + Maindb.setPassword("11111111"); + } @@ -29,18 +33,28 @@ close(); } bool DatabaseConnection::open() { - return db.open(); + return localdb.open(); +} +bool DatabaseConnection::openmain() { + return Maindb.open(); } bool DatabaseConnection::isopen() { - return db.isOpen(); + return localdb.isOpen(); } - +bool DatabaseConnection::isopenmain() { + return Maindb.isOpen(); +} void DatabaseConnection::close() { - db.close(); + localdb.close(); } - +void DatabaseConnection::closemain() { + Maindb.close(); +} QSqlDatabase& DatabaseConnection::getDatabase() { - return db; + return localdb; +} +QSqlDatabase& DatabaseConnection::getDatabaseMain() { + return Maindb; } DatabaseConnection* DatabaseConnection::getInstance() { diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.h b/softwareDirectory/AutoVerScheme/databaseconnection.h index 586b794..5f9810b 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.h +++ b/softwareDirectory/AutoVerScheme/databaseconnection.h @@ -16,8 +16,12 @@ ~DatabaseConnection(); bool open(); bool isopen(); + bool openmain(); void close(); + void closemain(); + bool isopenmain(); QSqlDatabase& getDatabase(); + QSqlDatabase& getDatabaseMain(); private: //单列模式 保证DatabaseConnection的唯一性 static DatabaseConnection* Connect; @@ -33,7 +37,8 @@ //如果尝试这样做,编译器同样会报错。 DatabaseConnection& operator=(const DatabaseConnection&) = delete; //数据库db类 - QSqlDatabase db; + QSqlDatabase Maindb; + QSqlDatabase localdb; }; #endif // DATABASECONNECTION_H diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp new file mode 100644 index 0000000..080288b --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp @@ -0,0 +1,54 @@ +#include "databaseconnectionmainsys.h" + + + + +DatabaseConnectionMainSys* DatabaseConnectionMainSys::Connect = nullptr; +QMutex DatabaseConnectionMainSys::mutex; + +DatabaseConnectionMainSys::DatabaseConnectionMainSys() +{ + + // 连接数据库 + dbmain = QSqlDatabase::addDatabase("QODBC"); + dbmain.setHostName("111.198.10.15"); + dbmain.setDatabaseName("casic_metering_xichang"); + dbmain.setPort(21906); + dbmain.setUserName("zdjdcs"); + dbmain.setPassword("11111111"); + /* db.setHostName("localhost"); + db.setDatabaseName("zdjd"); + db.setPort(3306); + db.setUserName("root"); + db.setPassword("123456");*/ + + +} +DatabaseConnectionMainSys::~DatabaseConnectionMainSys() { + // 在析构函数中关闭数据库连接 + close(); +} +bool DatabaseConnectionMainSys::open() { + return dbmain.open(); +} +bool DatabaseConnectionMainSys::isopen() { + return dbmain.isOpen(); +} + +void DatabaseConnectionMainSys::close() { + dbmain.close(); +} + +QSqlDatabase& DatabaseConnectionMainSys::getDatabase() { + return dbmain; +} +DatabaseConnectionMainSys* DatabaseConnectionMainSys::getInstance() +{ + if (!Connect) { + QMutexLocker locker(&mutex); + if (!Connect) { + Connect = new DatabaseConnectionMainSys(); + } + } + return Connect; +} diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h new file mode 100644 index 0000000..57702ad --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h @@ -0,0 +1,41 @@ +#ifndef DATABASECONNECTIONMAINSYS_H +#define DATABASECONNECTIONMAINSYS_H +#include +#include +#include +#include + + +class DatabaseConnectionMainSys +{ + + +public: + //获取数据库实例 + static DatabaseConnectionMainSys* getInstance(); + + DatabaseConnectionMainSys(); + ~DatabaseConnectionMainSys(); + bool open(); + bool isopen(); + void close(); + QSqlDatabase& getDatabase(); +private: + //单列模式 保证MainSysDatabaseConnection的唯一性 + static DatabaseConnectionMainSys* Connect; + //QMutex 来确保在多线程环境下单例的正确创建。 + static QMutex mutex; + + //这是拷贝构造函数的声明,后面跟着 = delete; 表示这个构造函数被删除了。 + //这意味着你不能通过拷贝另一个 DatabaseConnection 对象来创建新的 DatabaseConnection 对象。 + //如果尝试这样做,编译器会报错。 + DatabaseConnectionMainSys(const DatabaseConnectionMainSys&) = delete; + //这是拷贝赋值运算符的声明,同样后面跟着 = delete; 表示这个运算符被删除了。 + //这意味着你不能将一个 DatabaseConnection 对象赋值给另一个 DatabaseConnection 对象。 + //如果尝试这样做,编译器同样会报错。 + DatabaseConnectionMainSys& operator=(const DatabaseConnectionMainSys&) = delete; + //数据库db类 + QSqlDatabase dbmain; +}; + +#endif // DATABASECONNECTIONMAINSYS_H diff --git a/softwareDirectory/AutoVerScheme/datasyncview.cpp b/softwareDirectory/AutoVerScheme/datasyncview.cpp index fbf4508..06c7f9a 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.cpp +++ b/softwareDirectory/AutoVerScheme/datasyncview.cpp @@ -1,11 +1,10 @@ #include "datasyncview.h" #include "ui_datasyncview.h" -#include "synctask.h" -#include "databaseconnection.h" -#include "mainsysdatabaseconnection.h" +#include "syncdialog.h" - +QString filePath = "C:\\AutoVerScheme\\sync_info.txt"; +// 获取当前时间戳 DataSyncView::DataSyncView(QWidget *parent) : QWidget(parent), ui(new Ui::DataSyncView) @@ -20,7 +19,7 @@ } void DataSyncView::initForm() { - //tableWidget设置 + ui->stackedWidget->setCurrentIndex(0); //设置控件的边框显示 ui->tableWidget->setStyleSheet("QHeaderView::section {" "border: 1px solid grey;" @@ -32,29 +31,129 @@ "}"); ui->tableWidget->setRowCount(10); // 设置10行 - ui->tableWidget->setColumnCount(4); // 设置11列 - ui->tableWidget->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnCount(7); // 设置11列 + ui->tableWidget->setColumnWidth(0, 0); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnWidth(2, 200); // 设置第一列的宽度为100像素 ui->tableWidget->verticalHeader()->setParent(nullptr); //隐藏行头 - QTableWidgetItem *item = new QTableWidgetItem("测试数据"); - item->setTextAlignment(Qt::AlignCenter); - ui->tableWidget->setItem(0, 0, item); //设置数据 + + //初始化TableWidget 设置列 QStringList headers; - headers << "序号" << "同步时间" << "是否同步成功" << "备注" ; + headers <<"id" << "序号" << "同步时间" << "是否同步成功" << "备注" + <<"类型" <<"操作"; ui->tableWidget->setHorizontalHeaderLabels(headers); + //详情内 + + //设置控件的边框显示 + ui->tableWidget_2->setStyleSheet("QHeaderView::section {" + "border: 1px solid grey;" + "border-left:none;" + "border-top:none;" + "background-color:white;" + " color:black;" + "font: bold 18px Arial, sans-serif;" + "}"); + + ui->tableWidget_2->setRowCount(10); // 设置10行 + ui->tableWidget_2->setColumnCount(3); // 设置11列 + ui->tableWidget_2->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget_2->verticalHeader()->setParent(nullptr); //隐藏行头 + ui->tableWidget_2->setColumnWidth(1, 1000); // 设置第一列的宽度为100像素 + + //初始化TableWidget 设置列 + + headers << "序号" << "信息" << "状态" ; + ui->tableWidget_2->setHorizontalHeaderLabels(headers); + + //数据显示 + + //先设置为行为0 + ui->tableWidget->setRowCount(0); + int rowCount=0; + int row=0; + QList zdlog= BaseCommonApi::getzdLogByuserId(""); + for(const zdLog & zd:zdlog) + { + rowCount = ui->tableWidget->rowCount(); + ui->tableWidget->insertRow(rowCount); + ui->tableWidget->setItem(row, 0, new QTableWidgetItem(zd.id)); + ui->tableWidget->setItem(row, 1, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget->setItem(row, 2, new QTableWidgetItem(zd.sync_time.toString())); + ui->tableWidget->setItem(row, 3, new QTableWidgetItem(zd.is_sync)); + ui->tableWidget->setItem(row, 4, new QTableWidgetItem(zd.remark)); + if(zd.type=="1") + { + ui->tableWidget->setItem(row, 5, new QTableWidgetItem("下载")); + }else{ ui->tableWidget->setItem(row, 5, new QTableWidgetItem("上传")); } + + //添加操作按钮 + QPushButton *button = new QPushButton("查询信息"); + button->setIconSize(QSize(16,16)); + button->setIcon(QIcon(":/image/Index/u2327.svg")); + ui->tableWidget->setCellWidget(row, 6, button); + //设置按钮简单样式 + button->setStyleSheet("QPushButton {" + " border: none; /* 无边框 */" + " color: green; /* 文本颜色 */" + " text-decoration: underline; /* 文本下划线 */" + "}"); + + // 设置鼠标悬停时的光标样式为小手图标 + button->setCursor(Qt::PointingHandCursor); + // 连接按钮的 clicked 信号到自定义槽函数 + connect(button, &QPushButton::clicked, this, [this, button, zd]() { + // 获取当前行第一列的 ID + + OnButtonSelectClicked(zd); + + }); + row++; + } } void DataSyncView::on_DownloadDataButton_clicked() { - //从主系统下载 + + SyncDialog *syncDialog = new SyncDialog(this); + syncDialog->exec(); // 显示进度条窗体并阻塞主窗口 + + this->initForm(); + } -void DataSyncView::syncTable() +void DataSyncView::OnButtonSelectClicked(zdLog log) { - //连接两个数据库 - bool IsOpen=false; - DatabaseConnection *Conn=DatabaseConnection::getInstance(); - IsOpen=Conn->open(); - //MainSysDatabaseConnection *MainConn=MainSysDatabaseConnection::getInstance(); - //IsOpen=MainConn->open(); + ui->stackedWidget->setCurrentIndex(1); + ui->tableWidget_2->setRowCount(0); + int rowCount=0; + int row=0; + QList data= BaseCommonApi::getzdDataSyncByuserId(log.id); + for(const zdDataSync & item:data) + { + rowCount = ui->tableWidget_2->rowCount(); + ui->tableWidget_2->insertRow(rowCount); + ui->tableWidget_2->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget_2->setItem(row, 1, new QTableWidgetItem(item.remark)); + QTableWidgetItem *itemRow; + if(item.sync_type=="0"){ + itemRow = new QTableWidgetItem("未同步"); + itemRow->setBackground(QBrush(QColor(255, 255, 192))); + }else if (item.sync_type=="1") + { + itemRow = new QTableWidgetItem("同步成功"); + itemRow->setBackground(QBrush(QColor(173, 255, 47))); // 浅绿色 + }else{ + itemRow = new QTableWidgetItem("同步失败"); + itemRow->setBackground(QBrush(QColor(255, 105, 180))); // 浅红色 + } + itemRow->setTextAlignment(Qt::AlignCenter); + ui->tableWidget_2->setItem(row, 2, itemRow); + + row++; + } +} + +void DataSyncView::on_button_return_clicked() +{ + ui->stackedWidget->setCurrentIndex(0); } diff --git a/softwareDirectory/AutoVerScheme/datasyncview.h b/softwareDirectory/AutoVerScheme/datasyncview.h index 174480e..b2b9847 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.h +++ b/softwareDirectory/AutoVerScheme/datasyncview.h @@ -2,6 +2,16 @@ #define DATASYNCVIEW_H #include +#include +#include "synctask.h" +#include "databaseconnection.h" +#include "basecommonapi.h" +#include "databaseconnectionmainsys.h" +#include +#include +#include +#include +#include namespace Ui { class DataSyncView; @@ -18,8 +28,12 @@ void initForm(); //初始化界面数据 void on_DownloadDataButton_clicked(); - //异步更新 - void syncTable(); + void OnButtonSelectClicked(zdLog log); + void on_button_return_clicked(); + +public: + + private: Ui::DataSyncView *ui; }; diff --git a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro index bf70fab..d9a99ea 100644 --- a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro +++ b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro @@ -35,6 +35,7 @@ create_task.cpp \ createtask_scandevice.cpp \ databaseconnection.cpp \ + databaseconnectionmainsys.cpp \ datasyncview.cpp \ depar_task.cpp \ depar_task_server.cpp \ @@ -55,6 +56,7 @@ newverifymethod.cpp \ rulefileitem.cpp \ standard_deviceitem.cpp \ + syncdialog.cpp \ synctask.cpp \ testdataitem.cpp \ testview.cpp \ @@ -69,6 +71,7 @@ DataProcessingBLL.h \ PageControl.h \ createtask_scandevice.h \ + databaseconnectionmainsys.h \ formaddrsetting.h \ formcommsetting.h \ id/IdWorker.h \ @@ -104,6 +107,7 @@ newverifymethod.h \ rulefileitem.h \ standard_deviceitem.h \ + syncdialog.h \ synctask.h \ testdataitem.h \ testview.h \ @@ -138,6 +142,7 @@ newverifymethod.ui \ rulefileitem.ui \ standard_deviceitem.ui \ + syncdialog.ui \ testdataitem.ui \ testview.ui \ verifydevice.ui \ diff --git a/softwareDirectory/AutoVerScheme/PageControl.cpp b/softwareDirectory/AutoVerScheme/PageControl.cpp index d0fd72b..d1bdddc 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.cpp +++ b/softwareDirectory/AutoVerScheme/PageControl.cpp @@ -22,14 +22,14 @@ } } -void PagedTableWidget::setData(const QList> &data, int rowsPerPage,QTableWidget *table) { - tableWidget=table; - +void PagedTableWidget::setData(int datacount, int rowsPerPage) { + //tableWidget=table; + totaldatacount=datacount; this->rowsPerPage = rowsPerPage; - allData = data; + //allData = data; currentPage = 0; createPageButtons(); - updateTable(); + //updateTable(); } void PagedTableWidget::setCurrentPage(int page) { @@ -39,7 +39,7 @@ button->setChecked(false); }*/ currentPage = page; - updateTable(); + //updateTable(); emit pageChanged(page); } } @@ -89,6 +89,7 @@ setCurrentPage(pageIndex); } } +/* void PagedTableWidget::updateTable() { //tableWidget->clear(); tableWidget->setRowCount(0); @@ -105,7 +106,7 @@ } } } - +*/ void PagedTableWidget::createPageButtons() { int totalPages = calculateTotalPages(); for (auto button : pageButtons) { @@ -150,5 +151,5 @@ } int PagedTableWidget::calculateTotalPages() { - return ((allData.count() + rowsPerPage -1) / rowsPerPage); + return ((totaldatacount + rowsPerPage -1) / rowsPerPage); } diff --git a/softwareDirectory/AutoVerScheme/PageControl.h b/softwareDirectory/AutoVerScheme/PageControl.h index 74ed1ce..2224760 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.h +++ b/softwareDirectory/AutoVerScheme/PageControl.h @@ -15,7 +15,7 @@ explicit PagedTableWidget(QWidget *parent = nullptr,QHBoxLayout *PageLayout=NULL); ~PagedTableWidget(); - void setData(const QList> &data, int rowsPerPage = 10,QTableWidget *table=NULL); + void setData(int datacount, int rowsPerPage = 10); void setCurrentPage(int page); signals: @@ -30,6 +30,7 @@ QHBoxLayout *pageLayout; QList pageButtons; QList> allData; + int totaldatacount; int rowsPerPage; int currentPage; diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.cpp b/softwareDirectory/AutoVerScheme/basecommonapi.cpp index 49cbd7e..6f6fe94 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.cpp +++ b/softwareDirectory/AutoVerScheme/basecommonapi.cpp @@ -13,7 +13,7 @@ } const QString BaseCommonApi::temporary_user_id="1634107227953819649"; const QString BaseCommonApi::measure_person_id="1695282436182188034"; - +static SyncRunStatus syncstate=SyncRunStatus::Stopped; //sys_user表的id转换为measure_person_id 检定人id(meter_staff表id) @@ -167,7 +167,8 @@ "JOIN eqpt_equipment_info eei ON eei.id = blei.sample_id " "JOIN biz_business_order_info bo ON bo.id = blei.order_id " "LEFT JOIN sys_dept sd ON blei.measure_dept_id = sd.ID " - " WHERE blei.measure_person_id = :person_id " + " WHERE blei.measure_person_id = :person_id " + " AND blei.measure_status =3 or blei.measure_status = 4 " " ORDER BY blei.update_time DESC"); // 将参数绑定到占位符 @@ -175,7 +176,8 @@ //query.bindValue(":status", status); if (query.exec()) { while (query.next()) { - MyTask task; + + MyTask task; task.id = query.value("id").toString(); task.sample_name = query.value("sampleName").toString(); task.sample_model = query.value("sampleModel").toString(); @@ -2872,9 +2874,40 @@ return result; } +//保存log信息 +//log文件 + bool BaseCommonApi::SaveLogInfo(QString path,QString Info) +{ + QByteArray utf8Dat; + QString Message=Info; + QFile file(path); + // 如果目录不存在,则创建目录 + // 获取文件所在的目录 + QDir logDir = QDir(QFileInfo(path).absolutePath()); + if (!logDir.exists()) { + if (!logDir.mkpath(".")) { + qDebug() << "Failed to create log directory:" << logDir.absolutePath(); + return false; + } + } + + if (!file.open(QIODevice::Append | QIODevice::Text)) { + qDebug() << "无法打开文件:" << file.errorString(); + return false; + } + QTextStream out(&file); + utf8Dat = Message.toUtf8(); + out << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss") + << "\t" << utf8Dat << "\n"; + file.close(); + return true; + } + + //新增日志表数据 bool BaseCommonApi::InsertzdLog(zdLog log) { + log.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_log(id,is_sync,sync_time,remark,userid,type,create_time,update_time) " " VALUES(:id,:is_sync,:sync_time,:remark,:userid,:type,:create_time,:update_time) "); @@ -2898,6 +2931,7 @@ //根据userid查询日志表数据 QList BaseCommonApi::getzdLogByuserId(QString userid) { + userid=temporary_user_id; QList result; QSqlQuery query; query.prepare("SELECT * FROM zd_log WHERE userid = :userid "); @@ -2922,6 +2956,7 @@ //新增数据同步表 bool BaseCommonApi::InsertzdDataSync(zdDataSync data) { + data.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_data_sync(id,type,ssql,userid,remark,create_time,update_time,log_sync_id,sync_type) " " VALUES " @@ -2945,12 +2980,12 @@ return isSuccess; } //根据userid查询数据同步表 -QList getzdDataSyncByuserId(QString userid) +QList BaseCommonApi::getzdDataSyncByuserId(QString log_sync_id) { QList result; QSqlQuery query; - query.prepare("SELECT * FROM zd_data_sync WHERE userid= :userid "); - query.bindValue(":userid",userid); + query.prepare("SELECT * FROM zd_data_sync WHERE log_sync_id= :log_sync_id "); + query.bindValue(":log_sync_id",log_sync_id); if (query.exec()) { while (query.next()) { zdDataSync data; @@ -2972,3 +3007,4 @@ } + diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.h b/softwareDirectory/AutoVerScheme/basecommonapi.h index 12196fb..4949683 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.h +++ b/softwareDirectory/AutoVerScheme/basecommonapi.h @@ -919,6 +919,7 @@ QDateTime create_time; QDateTime update_time; }; + //数据同步-数据表 class zdDataSync { @@ -935,6 +936,12 @@ }; +enum class SyncRunStatus { + + Running, + Stopped, + Paused +}; using namespace Jiawa::Core; class BaseCommonApi @@ -945,7 +952,6 @@ const static QString temporary_costomer_id; const static QString measure_person_id; - QString encrypt(const QString &str, const QString &publicKey); //判断检定装置表并查询 参数设备id @@ -1137,14 +1143,19 @@ //单独查询任务单表 //更新 任务单 static InsertTask SelectTaskSingle(QString order_id); + + //log文件 + static bool SaveLogInfo(QString path,QString Info); + //新增日志表数据 static bool InsertzdLog(zdLog log); //查询日志表数据 static QList getzdLogByuserId(QString userid); //新增数据同步表 static bool InsertzdDataSync(zdDataSync data); - //根据userid查询数据同步表 - static QList getzdDataSyncByuserId(QString userid); + //根据log_sync_id查询数据同步表 + static QList getzdDataSyncByuserId(QString log_sync_id); + }; diff --git a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp index 00d746b..ae60962 100644 --- a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp @@ -352,6 +352,7 @@ } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -395,6 +396,7 @@ row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.cpp b/softwareDirectory/AutoVerScheme/databaseconnection.cpp index 1d957d9..5284fe6 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.cpp +++ b/softwareDirectory/AutoVerScheme/databaseconnection.cpp @@ -10,17 +10,21 @@ { // 连接数据库 - db = QSqlDatabase::addDatabase("QODBC"); - /*db.setHostName("111.198.10.15"); - db.setDatabaseName("casic_metering_xichang"); - db.setPort(21906); - db.setUserName("zdjdcs"); - db.setPassword("11111111");*/ - db.setHostName("localhost"); - db.setDatabaseName("zdjd"); - db.setPort(3306); - db.setUserName("root"); - db.setPassword("123456"); + localdb = QSqlDatabase::addDatabase("QODBC"); + + localdb.setHostName("localhost"); + localdb.setDatabaseName("zdjd"); + localdb.setPort(3306); + localdb.setUserName("root"); + localdb.setPassword("123456"); + + Maindb = QSqlDatabase::addDatabase("QODBC","Main"); + Maindb.setHostName("111.198.10.15"); + Maindb.setDatabaseName("casic_metering_xichang"); + Maindb.setPort(21906); + Maindb.setUserName("zdjdcs"); + Maindb.setPassword("11111111"); + } @@ -29,18 +33,28 @@ close(); } bool DatabaseConnection::open() { - return db.open(); + return localdb.open(); +} +bool DatabaseConnection::openmain() { + return Maindb.open(); } bool DatabaseConnection::isopen() { - return db.isOpen(); + return localdb.isOpen(); } - +bool DatabaseConnection::isopenmain() { + return Maindb.isOpen(); +} void DatabaseConnection::close() { - db.close(); + localdb.close(); } - +void DatabaseConnection::closemain() { + Maindb.close(); +} QSqlDatabase& DatabaseConnection::getDatabase() { - return db; + return localdb; +} +QSqlDatabase& DatabaseConnection::getDatabaseMain() { + return Maindb; } DatabaseConnection* DatabaseConnection::getInstance() { diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.h b/softwareDirectory/AutoVerScheme/databaseconnection.h index 586b794..5f9810b 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.h +++ b/softwareDirectory/AutoVerScheme/databaseconnection.h @@ -16,8 +16,12 @@ ~DatabaseConnection(); bool open(); bool isopen(); + bool openmain(); void close(); + void closemain(); + bool isopenmain(); QSqlDatabase& getDatabase(); + QSqlDatabase& getDatabaseMain(); private: //单列模式 保证DatabaseConnection的唯一性 static DatabaseConnection* Connect; @@ -33,7 +37,8 @@ //如果尝试这样做,编译器同样会报错。 DatabaseConnection& operator=(const DatabaseConnection&) = delete; //数据库db类 - QSqlDatabase db; + QSqlDatabase Maindb; + QSqlDatabase localdb; }; #endif // DATABASECONNECTION_H diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp new file mode 100644 index 0000000..080288b --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp @@ -0,0 +1,54 @@ +#include "databaseconnectionmainsys.h" + + + + +DatabaseConnectionMainSys* DatabaseConnectionMainSys::Connect = nullptr; +QMutex DatabaseConnectionMainSys::mutex; + +DatabaseConnectionMainSys::DatabaseConnectionMainSys() +{ + + // 连接数据库 + dbmain = QSqlDatabase::addDatabase("QODBC"); + dbmain.setHostName("111.198.10.15"); + dbmain.setDatabaseName("casic_metering_xichang"); + dbmain.setPort(21906); + dbmain.setUserName("zdjdcs"); + dbmain.setPassword("11111111"); + /* db.setHostName("localhost"); + db.setDatabaseName("zdjd"); + db.setPort(3306); + db.setUserName("root"); + db.setPassword("123456");*/ + + +} +DatabaseConnectionMainSys::~DatabaseConnectionMainSys() { + // 在析构函数中关闭数据库连接 + close(); +} +bool DatabaseConnectionMainSys::open() { + return dbmain.open(); +} +bool DatabaseConnectionMainSys::isopen() { + return dbmain.isOpen(); +} + +void DatabaseConnectionMainSys::close() { + dbmain.close(); +} + +QSqlDatabase& DatabaseConnectionMainSys::getDatabase() { + return dbmain; +} +DatabaseConnectionMainSys* DatabaseConnectionMainSys::getInstance() +{ + if (!Connect) { + QMutexLocker locker(&mutex); + if (!Connect) { + Connect = new DatabaseConnectionMainSys(); + } + } + return Connect; +} diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h new file mode 100644 index 0000000..57702ad --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h @@ -0,0 +1,41 @@ +#ifndef DATABASECONNECTIONMAINSYS_H +#define DATABASECONNECTIONMAINSYS_H +#include +#include +#include +#include + + +class DatabaseConnectionMainSys +{ + + +public: + //获取数据库实例 + static DatabaseConnectionMainSys* getInstance(); + + DatabaseConnectionMainSys(); + ~DatabaseConnectionMainSys(); + bool open(); + bool isopen(); + void close(); + QSqlDatabase& getDatabase(); +private: + //单列模式 保证MainSysDatabaseConnection的唯一性 + static DatabaseConnectionMainSys* Connect; + //QMutex 来确保在多线程环境下单例的正确创建。 + static QMutex mutex; + + //这是拷贝构造函数的声明,后面跟着 = delete; 表示这个构造函数被删除了。 + //这意味着你不能通过拷贝另一个 DatabaseConnection 对象来创建新的 DatabaseConnection 对象。 + //如果尝试这样做,编译器会报错。 + DatabaseConnectionMainSys(const DatabaseConnectionMainSys&) = delete; + //这是拷贝赋值运算符的声明,同样后面跟着 = delete; 表示这个运算符被删除了。 + //这意味着你不能将一个 DatabaseConnection 对象赋值给另一个 DatabaseConnection 对象。 + //如果尝试这样做,编译器同样会报错。 + DatabaseConnectionMainSys& operator=(const DatabaseConnectionMainSys&) = delete; + //数据库db类 + QSqlDatabase dbmain; +}; + +#endif // DATABASECONNECTIONMAINSYS_H diff --git a/softwareDirectory/AutoVerScheme/datasyncview.cpp b/softwareDirectory/AutoVerScheme/datasyncview.cpp index fbf4508..06c7f9a 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.cpp +++ b/softwareDirectory/AutoVerScheme/datasyncview.cpp @@ -1,11 +1,10 @@ #include "datasyncview.h" #include "ui_datasyncview.h" -#include "synctask.h" -#include "databaseconnection.h" -#include "mainsysdatabaseconnection.h" +#include "syncdialog.h" - +QString filePath = "C:\\AutoVerScheme\\sync_info.txt"; +// 获取当前时间戳 DataSyncView::DataSyncView(QWidget *parent) : QWidget(parent), ui(new Ui::DataSyncView) @@ -20,7 +19,7 @@ } void DataSyncView::initForm() { - //tableWidget设置 + ui->stackedWidget->setCurrentIndex(0); //设置控件的边框显示 ui->tableWidget->setStyleSheet("QHeaderView::section {" "border: 1px solid grey;" @@ -32,29 +31,129 @@ "}"); ui->tableWidget->setRowCount(10); // 设置10行 - ui->tableWidget->setColumnCount(4); // 设置11列 - ui->tableWidget->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnCount(7); // 设置11列 + ui->tableWidget->setColumnWidth(0, 0); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnWidth(2, 200); // 设置第一列的宽度为100像素 ui->tableWidget->verticalHeader()->setParent(nullptr); //隐藏行头 - QTableWidgetItem *item = new QTableWidgetItem("测试数据"); - item->setTextAlignment(Qt::AlignCenter); - ui->tableWidget->setItem(0, 0, item); //设置数据 + + //初始化TableWidget 设置列 QStringList headers; - headers << "序号" << "同步时间" << "是否同步成功" << "备注" ; + headers <<"id" << "序号" << "同步时间" << "是否同步成功" << "备注" + <<"类型" <<"操作"; ui->tableWidget->setHorizontalHeaderLabels(headers); + //详情内 + + //设置控件的边框显示 + ui->tableWidget_2->setStyleSheet("QHeaderView::section {" + "border: 1px solid grey;" + "border-left:none;" + "border-top:none;" + "background-color:white;" + " color:black;" + "font: bold 18px Arial, sans-serif;" + "}"); + + ui->tableWidget_2->setRowCount(10); // 设置10行 + ui->tableWidget_2->setColumnCount(3); // 设置11列 + ui->tableWidget_2->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget_2->verticalHeader()->setParent(nullptr); //隐藏行头 + ui->tableWidget_2->setColumnWidth(1, 1000); // 设置第一列的宽度为100像素 + + //初始化TableWidget 设置列 + + headers << "序号" << "信息" << "状态" ; + ui->tableWidget_2->setHorizontalHeaderLabels(headers); + + //数据显示 + + //先设置为行为0 + ui->tableWidget->setRowCount(0); + int rowCount=0; + int row=0; + QList zdlog= BaseCommonApi::getzdLogByuserId(""); + for(const zdLog & zd:zdlog) + { + rowCount = ui->tableWidget->rowCount(); + ui->tableWidget->insertRow(rowCount); + ui->tableWidget->setItem(row, 0, new QTableWidgetItem(zd.id)); + ui->tableWidget->setItem(row, 1, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget->setItem(row, 2, new QTableWidgetItem(zd.sync_time.toString())); + ui->tableWidget->setItem(row, 3, new QTableWidgetItem(zd.is_sync)); + ui->tableWidget->setItem(row, 4, new QTableWidgetItem(zd.remark)); + if(zd.type=="1") + { + ui->tableWidget->setItem(row, 5, new QTableWidgetItem("下载")); + }else{ ui->tableWidget->setItem(row, 5, new QTableWidgetItem("上传")); } + + //添加操作按钮 + QPushButton *button = new QPushButton("查询信息"); + button->setIconSize(QSize(16,16)); + button->setIcon(QIcon(":/image/Index/u2327.svg")); + ui->tableWidget->setCellWidget(row, 6, button); + //设置按钮简单样式 + button->setStyleSheet("QPushButton {" + " border: none; /* 无边框 */" + " color: green; /* 文本颜色 */" + " text-decoration: underline; /* 文本下划线 */" + "}"); + + // 设置鼠标悬停时的光标样式为小手图标 + button->setCursor(Qt::PointingHandCursor); + // 连接按钮的 clicked 信号到自定义槽函数 + connect(button, &QPushButton::clicked, this, [this, button, zd]() { + // 获取当前行第一列的 ID + + OnButtonSelectClicked(zd); + + }); + row++; + } } void DataSyncView::on_DownloadDataButton_clicked() { - //从主系统下载 + + SyncDialog *syncDialog = new SyncDialog(this); + syncDialog->exec(); // 显示进度条窗体并阻塞主窗口 + + this->initForm(); + } -void DataSyncView::syncTable() +void DataSyncView::OnButtonSelectClicked(zdLog log) { - //连接两个数据库 - bool IsOpen=false; - DatabaseConnection *Conn=DatabaseConnection::getInstance(); - IsOpen=Conn->open(); - //MainSysDatabaseConnection *MainConn=MainSysDatabaseConnection::getInstance(); - //IsOpen=MainConn->open(); + ui->stackedWidget->setCurrentIndex(1); + ui->tableWidget_2->setRowCount(0); + int rowCount=0; + int row=0; + QList data= BaseCommonApi::getzdDataSyncByuserId(log.id); + for(const zdDataSync & item:data) + { + rowCount = ui->tableWidget_2->rowCount(); + ui->tableWidget_2->insertRow(rowCount); + ui->tableWidget_2->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget_2->setItem(row, 1, new QTableWidgetItem(item.remark)); + QTableWidgetItem *itemRow; + if(item.sync_type=="0"){ + itemRow = new QTableWidgetItem("未同步"); + itemRow->setBackground(QBrush(QColor(255, 255, 192))); + }else if (item.sync_type=="1") + { + itemRow = new QTableWidgetItem("同步成功"); + itemRow->setBackground(QBrush(QColor(173, 255, 47))); // 浅绿色 + }else{ + itemRow = new QTableWidgetItem("同步失败"); + itemRow->setBackground(QBrush(QColor(255, 105, 180))); // 浅红色 + } + itemRow->setTextAlignment(Qt::AlignCenter); + ui->tableWidget_2->setItem(row, 2, itemRow); + + row++; + } +} + +void DataSyncView::on_button_return_clicked() +{ + ui->stackedWidget->setCurrentIndex(0); } diff --git a/softwareDirectory/AutoVerScheme/datasyncview.h b/softwareDirectory/AutoVerScheme/datasyncview.h index 174480e..b2b9847 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.h +++ b/softwareDirectory/AutoVerScheme/datasyncview.h @@ -2,6 +2,16 @@ #define DATASYNCVIEW_H #include +#include +#include "synctask.h" +#include "databaseconnection.h" +#include "basecommonapi.h" +#include "databaseconnectionmainsys.h" +#include +#include +#include +#include +#include namespace Ui { class DataSyncView; @@ -18,8 +28,12 @@ void initForm(); //初始化界面数据 void on_DownloadDataButton_clicked(); - //异步更新 - void syncTable(); + void OnButtonSelectClicked(zdLog log); + void on_button_return_clicked(); + +public: + + private: Ui::DataSyncView *ui; }; diff --git a/softwareDirectory/AutoVerScheme/datasyncview.ui b/softwareDirectory/AutoVerScheme/datasyncview.ui index 53c379c..7c9df8e 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.ui +++ b/softwareDirectory/AutoVerScheme/datasyncview.ui @@ -14,21 +14,9 @@ 数据同步 - background-color:rgba(240, 240, 240, 1); + background-color:white; - - - 0 - - - 0 - - - 0 - - - 0 - + @@ -73,119 +61,173 @@ - - - background-color:white; - - - - - - - 3 - - - - - - 0 - 0 - - - - background-color:white; + + + + + + + background-color:white; + + + + + + + 3 + + + + + + 0 + 0 + + + + background-color:white; border:0; - - - - - - - - - - 0 - 0 - - - - font:bold 20px Arial, sans-serif; + + + + + + + + + + 0 + 0 + + + + font:bold 20px Arial, sans-serif; color:#334582; - - - 同步记录 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - background-color:#334582; + + + 同步记录 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + background-color:#334582; font: bold 18px Arial, sans-serif; color:white; padding:10px; - - - 下载数据 - - - - - - - - 200 - 0 - - - - - 100 - 40 - - - - Qt::RightToLeft - - - background-color:#334582; + + + 下载数据 + + + + + + + + 200 + 0 + + + + + 100 + 40 + + + + Qt::RightToLeft + + + background-color:#334582; font: bold 18px Arial, sans-serif; color:white; padding:10px; - - - 发送同步请求 - - - - :/image/Index/u8458.svg:/image/Index/u8458.svg - - - - - - - - - - - - - - + + + 发送同步请求 + + + + :/image/Index/u8458.svg:/image/Index/u8458.svg + + + + + + + + + + + + + + + + + + + + + + + + background-color:white; + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + color:black; + + + 返回 + + + + + + + + + + + + + diff --git a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro index bf70fab..d9a99ea 100644 --- a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro +++ b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro @@ -35,6 +35,7 @@ create_task.cpp \ createtask_scandevice.cpp \ databaseconnection.cpp \ + databaseconnectionmainsys.cpp \ datasyncview.cpp \ depar_task.cpp \ depar_task_server.cpp \ @@ -55,6 +56,7 @@ newverifymethod.cpp \ rulefileitem.cpp \ standard_deviceitem.cpp \ + syncdialog.cpp \ synctask.cpp \ testdataitem.cpp \ testview.cpp \ @@ -69,6 +71,7 @@ DataProcessingBLL.h \ PageControl.h \ createtask_scandevice.h \ + databaseconnectionmainsys.h \ formaddrsetting.h \ formcommsetting.h \ id/IdWorker.h \ @@ -104,6 +107,7 @@ newverifymethod.h \ rulefileitem.h \ standard_deviceitem.h \ + syncdialog.h \ synctask.h \ testdataitem.h \ testview.h \ @@ -138,6 +142,7 @@ newverifymethod.ui \ rulefileitem.ui \ standard_deviceitem.ui \ + syncdialog.ui \ testdataitem.ui \ testview.ui \ verifydevice.ui \ diff --git a/softwareDirectory/AutoVerScheme/PageControl.cpp b/softwareDirectory/AutoVerScheme/PageControl.cpp index d0fd72b..d1bdddc 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.cpp +++ b/softwareDirectory/AutoVerScheme/PageControl.cpp @@ -22,14 +22,14 @@ } } -void PagedTableWidget::setData(const QList> &data, int rowsPerPage,QTableWidget *table) { - tableWidget=table; - +void PagedTableWidget::setData(int datacount, int rowsPerPage) { + //tableWidget=table; + totaldatacount=datacount; this->rowsPerPage = rowsPerPage; - allData = data; + //allData = data; currentPage = 0; createPageButtons(); - updateTable(); + //updateTable(); } void PagedTableWidget::setCurrentPage(int page) { @@ -39,7 +39,7 @@ button->setChecked(false); }*/ currentPage = page; - updateTable(); + //updateTable(); emit pageChanged(page); } } @@ -89,6 +89,7 @@ setCurrentPage(pageIndex); } } +/* void PagedTableWidget::updateTable() { //tableWidget->clear(); tableWidget->setRowCount(0); @@ -105,7 +106,7 @@ } } } - +*/ void PagedTableWidget::createPageButtons() { int totalPages = calculateTotalPages(); for (auto button : pageButtons) { @@ -150,5 +151,5 @@ } int PagedTableWidget::calculateTotalPages() { - return ((allData.count() + rowsPerPage -1) / rowsPerPage); + return ((totaldatacount + rowsPerPage -1) / rowsPerPage); } diff --git a/softwareDirectory/AutoVerScheme/PageControl.h b/softwareDirectory/AutoVerScheme/PageControl.h index 74ed1ce..2224760 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.h +++ b/softwareDirectory/AutoVerScheme/PageControl.h @@ -15,7 +15,7 @@ explicit PagedTableWidget(QWidget *parent = nullptr,QHBoxLayout *PageLayout=NULL); ~PagedTableWidget(); - void setData(const QList> &data, int rowsPerPage = 10,QTableWidget *table=NULL); + void setData(int datacount, int rowsPerPage = 10); void setCurrentPage(int page); signals: @@ -30,6 +30,7 @@ QHBoxLayout *pageLayout; QList pageButtons; QList> allData; + int totaldatacount; int rowsPerPage; int currentPage; diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.cpp b/softwareDirectory/AutoVerScheme/basecommonapi.cpp index 49cbd7e..6f6fe94 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.cpp +++ b/softwareDirectory/AutoVerScheme/basecommonapi.cpp @@ -13,7 +13,7 @@ } const QString BaseCommonApi::temporary_user_id="1634107227953819649"; const QString BaseCommonApi::measure_person_id="1695282436182188034"; - +static SyncRunStatus syncstate=SyncRunStatus::Stopped; //sys_user表的id转换为measure_person_id 检定人id(meter_staff表id) @@ -167,7 +167,8 @@ "JOIN eqpt_equipment_info eei ON eei.id = blei.sample_id " "JOIN biz_business_order_info bo ON bo.id = blei.order_id " "LEFT JOIN sys_dept sd ON blei.measure_dept_id = sd.ID " - " WHERE blei.measure_person_id = :person_id " + " WHERE blei.measure_person_id = :person_id " + " AND blei.measure_status =3 or blei.measure_status = 4 " " ORDER BY blei.update_time DESC"); // 将参数绑定到占位符 @@ -175,7 +176,8 @@ //query.bindValue(":status", status); if (query.exec()) { while (query.next()) { - MyTask task; + + MyTask task; task.id = query.value("id").toString(); task.sample_name = query.value("sampleName").toString(); task.sample_model = query.value("sampleModel").toString(); @@ -2872,9 +2874,40 @@ return result; } +//保存log信息 +//log文件 + bool BaseCommonApi::SaveLogInfo(QString path,QString Info) +{ + QByteArray utf8Dat; + QString Message=Info; + QFile file(path); + // 如果目录不存在,则创建目录 + // 获取文件所在的目录 + QDir logDir = QDir(QFileInfo(path).absolutePath()); + if (!logDir.exists()) { + if (!logDir.mkpath(".")) { + qDebug() << "Failed to create log directory:" << logDir.absolutePath(); + return false; + } + } + + if (!file.open(QIODevice::Append | QIODevice::Text)) { + qDebug() << "无法打开文件:" << file.errorString(); + return false; + } + QTextStream out(&file); + utf8Dat = Message.toUtf8(); + out << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss") + << "\t" << utf8Dat << "\n"; + file.close(); + return true; + } + + //新增日志表数据 bool BaseCommonApi::InsertzdLog(zdLog log) { + log.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_log(id,is_sync,sync_time,remark,userid,type,create_time,update_time) " " VALUES(:id,:is_sync,:sync_time,:remark,:userid,:type,:create_time,:update_time) "); @@ -2898,6 +2931,7 @@ //根据userid查询日志表数据 QList BaseCommonApi::getzdLogByuserId(QString userid) { + userid=temporary_user_id; QList result; QSqlQuery query; query.prepare("SELECT * FROM zd_log WHERE userid = :userid "); @@ -2922,6 +2956,7 @@ //新增数据同步表 bool BaseCommonApi::InsertzdDataSync(zdDataSync data) { + data.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_data_sync(id,type,ssql,userid,remark,create_time,update_time,log_sync_id,sync_type) " " VALUES " @@ -2945,12 +2980,12 @@ return isSuccess; } //根据userid查询数据同步表 -QList getzdDataSyncByuserId(QString userid) +QList BaseCommonApi::getzdDataSyncByuserId(QString log_sync_id) { QList result; QSqlQuery query; - query.prepare("SELECT * FROM zd_data_sync WHERE userid= :userid "); - query.bindValue(":userid",userid); + query.prepare("SELECT * FROM zd_data_sync WHERE log_sync_id= :log_sync_id "); + query.bindValue(":log_sync_id",log_sync_id); if (query.exec()) { while (query.next()) { zdDataSync data; @@ -2972,3 +3007,4 @@ } + diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.h b/softwareDirectory/AutoVerScheme/basecommonapi.h index 12196fb..4949683 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.h +++ b/softwareDirectory/AutoVerScheme/basecommonapi.h @@ -919,6 +919,7 @@ QDateTime create_time; QDateTime update_time; }; + //数据同步-数据表 class zdDataSync { @@ -935,6 +936,12 @@ }; +enum class SyncRunStatus { + + Running, + Stopped, + Paused +}; using namespace Jiawa::Core; class BaseCommonApi @@ -945,7 +952,6 @@ const static QString temporary_costomer_id; const static QString measure_person_id; - QString encrypt(const QString &str, const QString &publicKey); //判断检定装置表并查询 参数设备id @@ -1137,14 +1143,19 @@ //单独查询任务单表 //更新 任务单 static InsertTask SelectTaskSingle(QString order_id); + + //log文件 + static bool SaveLogInfo(QString path,QString Info); + //新增日志表数据 static bool InsertzdLog(zdLog log); //查询日志表数据 static QList getzdLogByuserId(QString userid); //新增数据同步表 static bool InsertzdDataSync(zdDataSync data); - //根据userid查询数据同步表 - static QList getzdDataSyncByuserId(QString userid); + //根据log_sync_id查询数据同步表 + static QList getzdDataSyncByuserId(QString log_sync_id); + }; diff --git a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp index 00d746b..ae60962 100644 --- a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp @@ -352,6 +352,7 @@ } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -395,6 +396,7 @@ row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.cpp b/softwareDirectory/AutoVerScheme/databaseconnection.cpp index 1d957d9..5284fe6 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.cpp +++ b/softwareDirectory/AutoVerScheme/databaseconnection.cpp @@ -10,17 +10,21 @@ { // 连接数据库 - db = QSqlDatabase::addDatabase("QODBC"); - /*db.setHostName("111.198.10.15"); - db.setDatabaseName("casic_metering_xichang"); - db.setPort(21906); - db.setUserName("zdjdcs"); - db.setPassword("11111111");*/ - db.setHostName("localhost"); - db.setDatabaseName("zdjd"); - db.setPort(3306); - db.setUserName("root"); - db.setPassword("123456"); + localdb = QSqlDatabase::addDatabase("QODBC"); + + localdb.setHostName("localhost"); + localdb.setDatabaseName("zdjd"); + localdb.setPort(3306); + localdb.setUserName("root"); + localdb.setPassword("123456"); + + Maindb = QSqlDatabase::addDatabase("QODBC","Main"); + Maindb.setHostName("111.198.10.15"); + Maindb.setDatabaseName("casic_metering_xichang"); + Maindb.setPort(21906); + Maindb.setUserName("zdjdcs"); + Maindb.setPassword("11111111"); + } @@ -29,18 +33,28 @@ close(); } bool DatabaseConnection::open() { - return db.open(); + return localdb.open(); +} +bool DatabaseConnection::openmain() { + return Maindb.open(); } bool DatabaseConnection::isopen() { - return db.isOpen(); + return localdb.isOpen(); } - +bool DatabaseConnection::isopenmain() { + return Maindb.isOpen(); +} void DatabaseConnection::close() { - db.close(); + localdb.close(); } - +void DatabaseConnection::closemain() { + Maindb.close(); +} QSqlDatabase& DatabaseConnection::getDatabase() { - return db; + return localdb; +} +QSqlDatabase& DatabaseConnection::getDatabaseMain() { + return Maindb; } DatabaseConnection* DatabaseConnection::getInstance() { diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.h b/softwareDirectory/AutoVerScheme/databaseconnection.h index 586b794..5f9810b 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.h +++ b/softwareDirectory/AutoVerScheme/databaseconnection.h @@ -16,8 +16,12 @@ ~DatabaseConnection(); bool open(); bool isopen(); + bool openmain(); void close(); + void closemain(); + bool isopenmain(); QSqlDatabase& getDatabase(); + QSqlDatabase& getDatabaseMain(); private: //单列模式 保证DatabaseConnection的唯一性 static DatabaseConnection* Connect; @@ -33,7 +37,8 @@ //如果尝试这样做,编译器同样会报错。 DatabaseConnection& operator=(const DatabaseConnection&) = delete; //数据库db类 - QSqlDatabase db; + QSqlDatabase Maindb; + QSqlDatabase localdb; }; #endif // DATABASECONNECTION_H diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp new file mode 100644 index 0000000..080288b --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp @@ -0,0 +1,54 @@ +#include "databaseconnectionmainsys.h" + + + + +DatabaseConnectionMainSys* DatabaseConnectionMainSys::Connect = nullptr; +QMutex DatabaseConnectionMainSys::mutex; + +DatabaseConnectionMainSys::DatabaseConnectionMainSys() +{ + + // 连接数据库 + dbmain = QSqlDatabase::addDatabase("QODBC"); + dbmain.setHostName("111.198.10.15"); + dbmain.setDatabaseName("casic_metering_xichang"); + dbmain.setPort(21906); + dbmain.setUserName("zdjdcs"); + dbmain.setPassword("11111111"); + /* db.setHostName("localhost"); + db.setDatabaseName("zdjd"); + db.setPort(3306); + db.setUserName("root"); + db.setPassword("123456");*/ + + +} +DatabaseConnectionMainSys::~DatabaseConnectionMainSys() { + // 在析构函数中关闭数据库连接 + close(); +} +bool DatabaseConnectionMainSys::open() { + return dbmain.open(); +} +bool DatabaseConnectionMainSys::isopen() { + return dbmain.isOpen(); +} + +void DatabaseConnectionMainSys::close() { + dbmain.close(); +} + +QSqlDatabase& DatabaseConnectionMainSys::getDatabase() { + return dbmain; +} +DatabaseConnectionMainSys* DatabaseConnectionMainSys::getInstance() +{ + if (!Connect) { + QMutexLocker locker(&mutex); + if (!Connect) { + Connect = new DatabaseConnectionMainSys(); + } + } + return Connect; +} diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h new file mode 100644 index 0000000..57702ad --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h @@ -0,0 +1,41 @@ +#ifndef DATABASECONNECTIONMAINSYS_H +#define DATABASECONNECTIONMAINSYS_H +#include +#include +#include +#include + + +class DatabaseConnectionMainSys +{ + + +public: + //获取数据库实例 + static DatabaseConnectionMainSys* getInstance(); + + DatabaseConnectionMainSys(); + ~DatabaseConnectionMainSys(); + bool open(); + bool isopen(); + void close(); + QSqlDatabase& getDatabase(); +private: + //单列模式 保证MainSysDatabaseConnection的唯一性 + static DatabaseConnectionMainSys* Connect; + //QMutex 来确保在多线程环境下单例的正确创建。 + static QMutex mutex; + + //这是拷贝构造函数的声明,后面跟着 = delete; 表示这个构造函数被删除了。 + //这意味着你不能通过拷贝另一个 DatabaseConnection 对象来创建新的 DatabaseConnection 对象。 + //如果尝试这样做,编译器会报错。 + DatabaseConnectionMainSys(const DatabaseConnectionMainSys&) = delete; + //这是拷贝赋值运算符的声明,同样后面跟着 = delete; 表示这个运算符被删除了。 + //这意味着你不能将一个 DatabaseConnection 对象赋值给另一个 DatabaseConnection 对象。 + //如果尝试这样做,编译器同样会报错。 + DatabaseConnectionMainSys& operator=(const DatabaseConnectionMainSys&) = delete; + //数据库db类 + QSqlDatabase dbmain; +}; + +#endif // DATABASECONNECTIONMAINSYS_H diff --git a/softwareDirectory/AutoVerScheme/datasyncview.cpp b/softwareDirectory/AutoVerScheme/datasyncview.cpp index fbf4508..06c7f9a 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.cpp +++ b/softwareDirectory/AutoVerScheme/datasyncview.cpp @@ -1,11 +1,10 @@ #include "datasyncview.h" #include "ui_datasyncview.h" -#include "synctask.h" -#include "databaseconnection.h" -#include "mainsysdatabaseconnection.h" +#include "syncdialog.h" - +QString filePath = "C:\\AutoVerScheme\\sync_info.txt"; +// 获取当前时间戳 DataSyncView::DataSyncView(QWidget *parent) : QWidget(parent), ui(new Ui::DataSyncView) @@ -20,7 +19,7 @@ } void DataSyncView::initForm() { - //tableWidget设置 + ui->stackedWidget->setCurrentIndex(0); //设置控件的边框显示 ui->tableWidget->setStyleSheet("QHeaderView::section {" "border: 1px solid grey;" @@ -32,29 +31,129 @@ "}"); ui->tableWidget->setRowCount(10); // 设置10行 - ui->tableWidget->setColumnCount(4); // 设置11列 - ui->tableWidget->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnCount(7); // 设置11列 + ui->tableWidget->setColumnWidth(0, 0); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnWidth(2, 200); // 设置第一列的宽度为100像素 ui->tableWidget->verticalHeader()->setParent(nullptr); //隐藏行头 - QTableWidgetItem *item = new QTableWidgetItem("测试数据"); - item->setTextAlignment(Qt::AlignCenter); - ui->tableWidget->setItem(0, 0, item); //设置数据 + + //初始化TableWidget 设置列 QStringList headers; - headers << "序号" << "同步时间" << "是否同步成功" << "备注" ; + headers <<"id" << "序号" << "同步时间" << "是否同步成功" << "备注" + <<"类型" <<"操作"; ui->tableWidget->setHorizontalHeaderLabels(headers); + //详情内 + + //设置控件的边框显示 + ui->tableWidget_2->setStyleSheet("QHeaderView::section {" + "border: 1px solid grey;" + "border-left:none;" + "border-top:none;" + "background-color:white;" + " color:black;" + "font: bold 18px Arial, sans-serif;" + "}"); + + ui->tableWidget_2->setRowCount(10); // 设置10行 + ui->tableWidget_2->setColumnCount(3); // 设置11列 + ui->tableWidget_2->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget_2->verticalHeader()->setParent(nullptr); //隐藏行头 + ui->tableWidget_2->setColumnWidth(1, 1000); // 设置第一列的宽度为100像素 + + //初始化TableWidget 设置列 + + headers << "序号" << "信息" << "状态" ; + ui->tableWidget_2->setHorizontalHeaderLabels(headers); + + //数据显示 + + //先设置为行为0 + ui->tableWidget->setRowCount(0); + int rowCount=0; + int row=0; + QList zdlog= BaseCommonApi::getzdLogByuserId(""); + for(const zdLog & zd:zdlog) + { + rowCount = ui->tableWidget->rowCount(); + ui->tableWidget->insertRow(rowCount); + ui->tableWidget->setItem(row, 0, new QTableWidgetItem(zd.id)); + ui->tableWidget->setItem(row, 1, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget->setItem(row, 2, new QTableWidgetItem(zd.sync_time.toString())); + ui->tableWidget->setItem(row, 3, new QTableWidgetItem(zd.is_sync)); + ui->tableWidget->setItem(row, 4, new QTableWidgetItem(zd.remark)); + if(zd.type=="1") + { + ui->tableWidget->setItem(row, 5, new QTableWidgetItem("下载")); + }else{ ui->tableWidget->setItem(row, 5, new QTableWidgetItem("上传")); } + + //添加操作按钮 + QPushButton *button = new QPushButton("查询信息"); + button->setIconSize(QSize(16,16)); + button->setIcon(QIcon(":/image/Index/u2327.svg")); + ui->tableWidget->setCellWidget(row, 6, button); + //设置按钮简单样式 + button->setStyleSheet("QPushButton {" + " border: none; /* 无边框 */" + " color: green; /* 文本颜色 */" + " text-decoration: underline; /* 文本下划线 */" + "}"); + + // 设置鼠标悬停时的光标样式为小手图标 + button->setCursor(Qt::PointingHandCursor); + // 连接按钮的 clicked 信号到自定义槽函数 + connect(button, &QPushButton::clicked, this, [this, button, zd]() { + // 获取当前行第一列的 ID + + OnButtonSelectClicked(zd); + + }); + row++; + } } void DataSyncView::on_DownloadDataButton_clicked() { - //从主系统下载 + + SyncDialog *syncDialog = new SyncDialog(this); + syncDialog->exec(); // 显示进度条窗体并阻塞主窗口 + + this->initForm(); + } -void DataSyncView::syncTable() +void DataSyncView::OnButtonSelectClicked(zdLog log) { - //连接两个数据库 - bool IsOpen=false; - DatabaseConnection *Conn=DatabaseConnection::getInstance(); - IsOpen=Conn->open(); - //MainSysDatabaseConnection *MainConn=MainSysDatabaseConnection::getInstance(); - //IsOpen=MainConn->open(); + ui->stackedWidget->setCurrentIndex(1); + ui->tableWidget_2->setRowCount(0); + int rowCount=0; + int row=0; + QList data= BaseCommonApi::getzdDataSyncByuserId(log.id); + for(const zdDataSync & item:data) + { + rowCount = ui->tableWidget_2->rowCount(); + ui->tableWidget_2->insertRow(rowCount); + ui->tableWidget_2->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget_2->setItem(row, 1, new QTableWidgetItem(item.remark)); + QTableWidgetItem *itemRow; + if(item.sync_type=="0"){ + itemRow = new QTableWidgetItem("未同步"); + itemRow->setBackground(QBrush(QColor(255, 255, 192))); + }else if (item.sync_type=="1") + { + itemRow = new QTableWidgetItem("同步成功"); + itemRow->setBackground(QBrush(QColor(173, 255, 47))); // 浅绿色 + }else{ + itemRow = new QTableWidgetItem("同步失败"); + itemRow->setBackground(QBrush(QColor(255, 105, 180))); // 浅红色 + } + itemRow->setTextAlignment(Qt::AlignCenter); + ui->tableWidget_2->setItem(row, 2, itemRow); + + row++; + } +} + +void DataSyncView::on_button_return_clicked() +{ + ui->stackedWidget->setCurrentIndex(0); } diff --git a/softwareDirectory/AutoVerScheme/datasyncview.h b/softwareDirectory/AutoVerScheme/datasyncview.h index 174480e..b2b9847 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.h +++ b/softwareDirectory/AutoVerScheme/datasyncview.h @@ -2,6 +2,16 @@ #define DATASYNCVIEW_H #include +#include +#include "synctask.h" +#include "databaseconnection.h" +#include "basecommonapi.h" +#include "databaseconnectionmainsys.h" +#include +#include +#include +#include +#include namespace Ui { class DataSyncView; @@ -18,8 +28,12 @@ void initForm(); //初始化界面数据 void on_DownloadDataButton_clicked(); - //异步更新 - void syncTable(); + void OnButtonSelectClicked(zdLog log); + void on_button_return_clicked(); + +public: + + private: Ui::DataSyncView *ui; }; diff --git a/softwareDirectory/AutoVerScheme/datasyncview.ui b/softwareDirectory/AutoVerScheme/datasyncview.ui index 53c379c..7c9df8e 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.ui +++ b/softwareDirectory/AutoVerScheme/datasyncview.ui @@ -14,21 +14,9 @@ 数据同步 - background-color:rgba(240, 240, 240, 1); + background-color:white; - - - 0 - - - 0 - - - 0 - - - 0 - + @@ -73,119 +61,173 @@ - - - background-color:white; - - - - - - - 3 - - - - - - 0 - 0 - - - - background-color:white; + + + + + + + background-color:white; + + + + + + + 3 + + + + + + 0 + 0 + + + + background-color:white; border:0; - - - - - - - - - - 0 - 0 - - - - font:bold 20px Arial, sans-serif; + + + + + + + + + + 0 + 0 + + + + font:bold 20px Arial, sans-serif; color:#334582; - - - 同步记录 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - background-color:#334582; + + + 同步记录 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + background-color:#334582; font: bold 18px Arial, sans-serif; color:white; padding:10px; - - - 下载数据 - - - - - - - - 200 - 0 - - - - - 100 - 40 - - - - Qt::RightToLeft - - - background-color:#334582; + + + 下载数据 + + + + + + + + 200 + 0 + + + + + 100 + 40 + + + + Qt::RightToLeft + + + background-color:#334582; font: bold 18px Arial, sans-serif; color:white; padding:10px; - - - 发送同步请求 - - - - :/image/Index/u8458.svg:/image/Index/u8458.svg - - - - - - - - - - - - - - + + + 发送同步请求 + + + + :/image/Index/u8458.svg:/image/Index/u8458.svg + + + + + + + + + + + + + + + + + + + + + + + + background-color:white; + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + color:black; + + + 返回 + + + + + + + + + + + + + diff --git a/softwareDirectory/AutoVerScheme/depar_task.cpp b/softwareDirectory/AutoVerScheme/depar_task.cpp index d551972..d58cf35 100644 --- a/softwareDirectory/AutoVerScheme/depar_task.cpp +++ b/softwareDirectory/AutoVerScheme/depar_task.cpp @@ -113,6 +113,7 @@ else State="否"; ui->tableWidget->setItem(row, 9, new QTableWidgetItem(State)); //设置数据 + SetHomePaheCombox(dept); //添加 PageData数据 TempData.append(QString::number(row+1)); TempData.append(dept.sample_name); @@ -133,9 +134,9 @@ //设置分页控件 // 创建分页表格控件 - PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); +// PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); //data转换位QList> - pagedTable->setData(PageData, 20,ui->tableWidget); // 每页20行 + // pagedTable->setData(PageData, 20,ui->tableWidget); // 每页20行 } void Depar_Task::on_SelectButton_clicked() @@ -155,26 +156,31 @@ if(dept.measure_status=="3" || dept.measure_status=="4"){ bool shouldAddRow = true; // 初始假设应该添加这一行 // 根据设备名称筛选 + QString names; if (ui->name->currentText() != "ALL") { + names=ui->name->currentText(); if (ui->name->currentText() != dept.sample_name) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } if (ui->mode->currentText() != "ALL") { + names=ui->mode->currentText(); if (ui->mode->currentText() != dept.sample_model) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } if (ui->customer->currentText() != "ALL") { + if (ui->customer->currentText() != dept.customer_name) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } - if (ui->dept->currentText() != "") { + if (ui->dept->currentText() != "ALL") { if (ui->dept->currentText() != dept.FULL_NAME) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); ui->tableWidget->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); @@ -193,9 +199,10 @@ State="否"; ui->tableWidget->setItem(row, 9, new QTableWidgetItem(State)); //设置数据 // - SetHomePaheCombox(dept); + //QDebug row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro index bf70fab..d9a99ea 100644 --- a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro +++ b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro @@ -35,6 +35,7 @@ create_task.cpp \ createtask_scandevice.cpp \ databaseconnection.cpp \ + databaseconnectionmainsys.cpp \ datasyncview.cpp \ depar_task.cpp \ depar_task_server.cpp \ @@ -55,6 +56,7 @@ newverifymethod.cpp \ rulefileitem.cpp \ standard_deviceitem.cpp \ + syncdialog.cpp \ synctask.cpp \ testdataitem.cpp \ testview.cpp \ @@ -69,6 +71,7 @@ DataProcessingBLL.h \ PageControl.h \ createtask_scandevice.h \ + databaseconnectionmainsys.h \ formaddrsetting.h \ formcommsetting.h \ id/IdWorker.h \ @@ -104,6 +107,7 @@ newverifymethod.h \ rulefileitem.h \ standard_deviceitem.h \ + syncdialog.h \ synctask.h \ testdataitem.h \ testview.h \ @@ -138,6 +142,7 @@ newverifymethod.ui \ rulefileitem.ui \ standard_deviceitem.ui \ + syncdialog.ui \ testdataitem.ui \ testview.ui \ verifydevice.ui \ diff --git a/softwareDirectory/AutoVerScheme/PageControl.cpp b/softwareDirectory/AutoVerScheme/PageControl.cpp index d0fd72b..d1bdddc 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.cpp +++ b/softwareDirectory/AutoVerScheme/PageControl.cpp @@ -22,14 +22,14 @@ } } -void PagedTableWidget::setData(const QList> &data, int rowsPerPage,QTableWidget *table) { - tableWidget=table; - +void PagedTableWidget::setData(int datacount, int rowsPerPage) { + //tableWidget=table; + totaldatacount=datacount; this->rowsPerPage = rowsPerPage; - allData = data; + //allData = data; currentPage = 0; createPageButtons(); - updateTable(); + //updateTable(); } void PagedTableWidget::setCurrentPage(int page) { @@ -39,7 +39,7 @@ button->setChecked(false); }*/ currentPage = page; - updateTable(); + //updateTable(); emit pageChanged(page); } } @@ -89,6 +89,7 @@ setCurrentPage(pageIndex); } } +/* void PagedTableWidget::updateTable() { //tableWidget->clear(); tableWidget->setRowCount(0); @@ -105,7 +106,7 @@ } } } - +*/ void PagedTableWidget::createPageButtons() { int totalPages = calculateTotalPages(); for (auto button : pageButtons) { @@ -150,5 +151,5 @@ } int PagedTableWidget::calculateTotalPages() { - return ((allData.count() + rowsPerPage -1) / rowsPerPage); + return ((totaldatacount + rowsPerPage -1) / rowsPerPage); } diff --git a/softwareDirectory/AutoVerScheme/PageControl.h b/softwareDirectory/AutoVerScheme/PageControl.h index 74ed1ce..2224760 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.h +++ b/softwareDirectory/AutoVerScheme/PageControl.h @@ -15,7 +15,7 @@ explicit PagedTableWidget(QWidget *parent = nullptr,QHBoxLayout *PageLayout=NULL); ~PagedTableWidget(); - void setData(const QList> &data, int rowsPerPage = 10,QTableWidget *table=NULL); + void setData(int datacount, int rowsPerPage = 10); void setCurrentPage(int page); signals: @@ -30,6 +30,7 @@ QHBoxLayout *pageLayout; QList pageButtons; QList> allData; + int totaldatacount; int rowsPerPage; int currentPage; diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.cpp b/softwareDirectory/AutoVerScheme/basecommonapi.cpp index 49cbd7e..6f6fe94 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.cpp +++ b/softwareDirectory/AutoVerScheme/basecommonapi.cpp @@ -13,7 +13,7 @@ } const QString BaseCommonApi::temporary_user_id="1634107227953819649"; const QString BaseCommonApi::measure_person_id="1695282436182188034"; - +static SyncRunStatus syncstate=SyncRunStatus::Stopped; //sys_user表的id转换为measure_person_id 检定人id(meter_staff表id) @@ -167,7 +167,8 @@ "JOIN eqpt_equipment_info eei ON eei.id = blei.sample_id " "JOIN biz_business_order_info bo ON bo.id = blei.order_id " "LEFT JOIN sys_dept sd ON blei.measure_dept_id = sd.ID " - " WHERE blei.measure_person_id = :person_id " + " WHERE blei.measure_person_id = :person_id " + " AND blei.measure_status =3 or blei.measure_status = 4 " " ORDER BY blei.update_time DESC"); // 将参数绑定到占位符 @@ -175,7 +176,8 @@ //query.bindValue(":status", status); if (query.exec()) { while (query.next()) { - MyTask task; + + MyTask task; task.id = query.value("id").toString(); task.sample_name = query.value("sampleName").toString(); task.sample_model = query.value("sampleModel").toString(); @@ -2872,9 +2874,40 @@ return result; } +//保存log信息 +//log文件 + bool BaseCommonApi::SaveLogInfo(QString path,QString Info) +{ + QByteArray utf8Dat; + QString Message=Info; + QFile file(path); + // 如果目录不存在,则创建目录 + // 获取文件所在的目录 + QDir logDir = QDir(QFileInfo(path).absolutePath()); + if (!logDir.exists()) { + if (!logDir.mkpath(".")) { + qDebug() << "Failed to create log directory:" << logDir.absolutePath(); + return false; + } + } + + if (!file.open(QIODevice::Append | QIODevice::Text)) { + qDebug() << "无法打开文件:" << file.errorString(); + return false; + } + QTextStream out(&file); + utf8Dat = Message.toUtf8(); + out << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss") + << "\t" << utf8Dat << "\n"; + file.close(); + return true; + } + + //新增日志表数据 bool BaseCommonApi::InsertzdLog(zdLog log) { + log.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_log(id,is_sync,sync_time,remark,userid,type,create_time,update_time) " " VALUES(:id,:is_sync,:sync_time,:remark,:userid,:type,:create_time,:update_time) "); @@ -2898,6 +2931,7 @@ //根据userid查询日志表数据 QList BaseCommonApi::getzdLogByuserId(QString userid) { + userid=temporary_user_id; QList result; QSqlQuery query; query.prepare("SELECT * FROM zd_log WHERE userid = :userid "); @@ -2922,6 +2956,7 @@ //新增数据同步表 bool BaseCommonApi::InsertzdDataSync(zdDataSync data) { + data.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_data_sync(id,type,ssql,userid,remark,create_time,update_time,log_sync_id,sync_type) " " VALUES " @@ -2945,12 +2980,12 @@ return isSuccess; } //根据userid查询数据同步表 -QList getzdDataSyncByuserId(QString userid) +QList BaseCommonApi::getzdDataSyncByuserId(QString log_sync_id) { QList result; QSqlQuery query; - query.prepare("SELECT * FROM zd_data_sync WHERE userid= :userid "); - query.bindValue(":userid",userid); + query.prepare("SELECT * FROM zd_data_sync WHERE log_sync_id= :log_sync_id "); + query.bindValue(":log_sync_id",log_sync_id); if (query.exec()) { while (query.next()) { zdDataSync data; @@ -2972,3 +3007,4 @@ } + diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.h b/softwareDirectory/AutoVerScheme/basecommonapi.h index 12196fb..4949683 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.h +++ b/softwareDirectory/AutoVerScheme/basecommonapi.h @@ -919,6 +919,7 @@ QDateTime create_time; QDateTime update_time; }; + //数据同步-数据表 class zdDataSync { @@ -935,6 +936,12 @@ }; +enum class SyncRunStatus { + + Running, + Stopped, + Paused +}; using namespace Jiawa::Core; class BaseCommonApi @@ -945,7 +952,6 @@ const static QString temporary_costomer_id; const static QString measure_person_id; - QString encrypt(const QString &str, const QString &publicKey); //判断检定装置表并查询 参数设备id @@ -1137,14 +1143,19 @@ //单独查询任务单表 //更新 任务单 static InsertTask SelectTaskSingle(QString order_id); + + //log文件 + static bool SaveLogInfo(QString path,QString Info); + //新增日志表数据 static bool InsertzdLog(zdLog log); //查询日志表数据 static QList getzdLogByuserId(QString userid); //新增数据同步表 static bool InsertzdDataSync(zdDataSync data); - //根据userid查询数据同步表 - static QList getzdDataSyncByuserId(QString userid); + //根据log_sync_id查询数据同步表 + static QList getzdDataSyncByuserId(QString log_sync_id); + }; diff --git a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp index 00d746b..ae60962 100644 --- a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp @@ -352,6 +352,7 @@ } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -395,6 +396,7 @@ row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.cpp b/softwareDirectory/AutoVerScheme/databaseconnection.cpp index 1d957d9..5284fe6 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.cpp +++ b/softwareDirectory/AutoVerScheme/databaseconnection.cpp @@ -10,17 +10,21 @@ { // 连接数据库 - db = QSqlDatabase::addDatabase("QODBC"); - /*db.setHostName("111.198.10.15"); - db.setDatabaseName("casic_metering_xichang"); - db.setPort(21906); - db.setUserName("zdjdcs"); - db.setPassword("11111111");*/ - db.setHostName("localhost"); - db.setDatabaseName("zdjd"); - db.setPort(3306); - db.setUserName("root"); - db.setPassword("123456"); + localdb = QSqlDatabase::addDatabase("QODBC"); + + localdb.setHostName("localhost"); + localdb.setDatabaseName("zdjd"); + localdb.setPort(3306); + localdb.setUserName("root"); + localdb.setPassword("123456"); + + Maindb = QSqlDatabase::addDatabase("QODBC","Main"); + Maindb.setHostName("111.198.10.15"); + Maindb.setDatabaseName("casic_metering_xichang"); + Maindb.setPort(21906); + Maindb.setUserName("zdjdcs"); + Maindb.setPassword("11111111"); + } @@ -29,18 +33,28 @@ close(); } bool DatabaseConnection::open() { - return db.open(); + return localdb.open(); +} +bool DatabaseConnection::openmain() { + return Maindb.open(); } bool DatabaseConnection::isopen() { - return db.isOpen(); + return localdb.isOpen(); } - +bool DatabaseConnection::isopenmain() { + return Maindb.isOpen(); +} void DatabaseConnection::close() { - db.close(); + localdb.close(); } - +void DatabaseConnection::closemain() { + Maindb.close(); +} QSqlDatabase& DatabaseConnection::getDatabase() { - return db; + return localdb; +} +QSqlDatabase& DatabaseConnection::getDatabaseMain() { + return Maindb; } DatabaseConnection* DatabaseConnection::getInstance() { diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.h b/softwareDirectory/AutoVerScheme/databaseconnection.h index 586b794..5f9810b 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.h +++ b/softwareDirectory/AutoVerScheme/databaseconnection.h @@ -16,8 +16,12 @@ ~DatabaseConnection(); bool open(); bool isopen(); + bool openmain(); void close(); + void closemain(); + bool isopenmain(); QSqlDatabase& getDatabase(); + QSqlDatabase& getDatabaseMain(); private: //单列模式 保证DatabaseConnection的唯一性 static DatabaseConnection* Connect; @@ -33,7 +37,8 @@ //如果尝试这样做,编译器同样会报错。 DatabaseConnection& operator=(const DatabaseConnection&) = delete; //数据库db类 - QSqlDatabase db; + QSqlDatabase Maindb; + QSqlDatabase localdb; }; #endif // DATABASECONNECTION_H diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp new file mode 100644 index 0000000..080288b --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp @@ -0,0 +1,54 @@ +#include "databaseconnectionmainsys.h" + + + + +DatabaseConnectionMainSys* DatabaseConnectionMainSys::Connect = nullptr; +QMutex DatabaseConnectionMainSys::mutex; + +DatabaseConnectionMainSys::DatabaseConnectionMainSys() +{ + + // 连接数据库 + dbmain = QSqlDatabase::addDatabase("QODBC"); + dbmain.setHostName("111.198.10.15"); + dbmain.setDatabaseName("casic_metering_xichang"); + dbmain.setPort(21906); + dbmain.setUserName("zdjdcs"); + dbmain.setPassword("11111111"); + /* db.setHostName("localhost"); + db.setDatabaseName("zdjd"); + db.setPort(3306); + db.setUserName("root"); + db.setPassword("123456");*/ + + +} +DatabaseConnectionMainSys::~DatabaseConnectionMainSys() { + // 在析构函数中关闭数据库连接 + close(); +} +bool DatabaseConnectionMainSys::open() { + return dbmain.open(); +} +bool DatabaseConnectionMainSys::isopen() { + return dbmain.isOpen(); +} + +void DatabaseConnectionMainSys::close() { + dbmain.close(); +} + +QSqlDatabase& DatabaseConnectionMainSys::getDatabase() { + return dbmain; +} +DatabaseConnectionMainSys* DatabaseConnectionMainSys::getInstance() +{ + if (!Connect) { + QMutexLocker locker(&mutex); + if (!Connect) { + Connect = new DatabaseConnectionMainSys(); + } + } + return Connect; +} diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h new file mode 100644 index 0000000..57702ad --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h @@ -0,0 +1,41 @@ +#ifndef DATABASECONNECTIONMAINSYS_H +#define DATABASECONNECTIONMAINSYS_H +#include +#include +#include +#include + + +class DatabaseConnectionMainSys +{ + + +public: + //获取数据库实例 + static DatabaseConnectionMainSys* getInstance(); + + DatabaseConnectionMainSys(); + ~DatabaseConnectionMainSys(); + bool open(); + bool isopen(); + void close(); + QSqlDatabase& getDatabase(); +private: + //单列模式 保证MainSysDatabaseConnection的唯一性 + static DatabaseConnectionMainSys* Connect; + //QMutex 来确保在多线程环境下单例的正确创建。 + static QMutex mutex; + + //这是拷贝构造函数的声明,后面跟着 = delete; 表示这个构造函数被删除了。 + //这意味着你不能通过拷贝另一个 DatabaseConnection 对象来创建新的 DatabaseConnection 对象。 + //如果尝试这样做,编译器会报错。 + DatabaseConnectionMainSys(const DatabaseConnectionMainSys&) = delete; + //这是拷贝赋值运算符的声明,同样后面跟着 = delete; 表示这个运算符被删除了。 + //这意味着你不能将一个 DatabaseConnection 对象赋值给另一个 DatabaseConnection 对象。 + //如果尝试这样做,编译器同样会报错。 + DatabaseConnectionMainSys& operator=(const DatabaseConnectionMainSys&) = delete; + //数据库db类 + QSqlDatabase dbmain; +}; + +#endif // DATABASECONNECTIONMAINSYS_H diff --git a/softwareDirectory/AutoVerScheme/datasyncview.cpp b/softwareDirectory/AutoVerScheme/datasyncview.cpp index fbf4508..06c7f9a 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.cpp +++ b/softwareDirectory/AutoVerScheme/datasyncview.cpp @@ -1,11 +1,10 @@ #include "datasyncview.h" #include "ui_datasyncview.h" -#include "synctask.h" -#include "databaseconnection.h" -#include "mainsysdatabaseconnection.h" +#include "syncdialog.h" - +QString filePath = "C:\\AutoVerScheme\\sync_info.txt"; +// 获取当前时间戳 DataSyncView::DataSyncView(QWidget *parent) : QWidget(parent), ui(new Ui::DataSyncView) @@ -20,7 +19,7 @@ } void DataSyncView::initForm() { - //tableWidget设置 + ui->stackedWidget->setCurrentIndex(0); //设置控件的边框显示 ui->tableWidget->setStyleSheet("QHeaderView::section {" "border: 1px solid grey;" @@ -32,29 +31,129 @@ "}"); ui->tableWidget->setRowCount(10); // 设置10行 - ui->tableWidget->setColumnCount(4); // 设置11列 - ui->tableWidget->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnCount(7); // 设置11列 + ui->tableWidget->setColumnWidth(0, 0); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnWidth(2, 200); // 设置第一列的宽度为100像素 ui->tableWidget->verticalHeader()->setParent(nullptr); //隐藏行头 - QTableWidgetItem *item = new QTableWidgetItem("测试数据"); - item->setTextAlignment(Qt::AlignCenter); - ui->tableWidget->setItem(0, 0, item); //设置数据 + + //初始化TableWidget 设置列 QStringList headers; - headers << "序号" << "同步时间" << "是否同步成功" << "备注" ; + headers <<"id" << "序号" << "同步时间" << "是否同步成功" << "备注" + <<"类型" <<"操作"; ui->tableWidget->setHorizontalHeaderLabels(headers); + //详情内 + + //设置控件的边框显示 + ui->tableWidget_2->setStyleSheet("QHeaderView::section {" + "border: 1px solid grey;" + "border-left:none;" + "border-top:none;" + "background-color:white;" + " color:black;" + "font: bold 18px Arial, sans-serif;" + "}"); + + ui->tableWidget_2->setRowCount(10); // 设置10行 + ui->tableWidget_2->setColumnCount(3); // 设置11列 + ui->tableWidget_2->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget_2->verticalHeader()->setParent(nullptr); //隐藏行头 + ui->tableWidget_2->setColumnWidth(1, 1000); // 设置第一列的宽度为100像素 + + //初始化TableWidget 设置列 + + headers << "序号" << "信息" << "状态" ; + ui->tableWidget_2->setHorizontalHeaderLabels(headers); + + //数据显示 + + //先设置为行为0 + ui->tableWidget->setRowCount(0); + int rowCount=0; + int row=0; + QList zdlog= BaseCommonApi::getzdLogByuserId(""); + for(const zdLog & zd:zdlog) + { + rowCount = ui->tableWidget->rowCount(); + ui->tableWidget->insertRow(rowCount); + ui->tableWidget->setItem(row, 0, new QTableWidgetItem(zd.id)); + ui->tableWidget->setItem(row, 1, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget->setItem(row, 2, new QTableWidgetItem(zd.sync_time.toString())); + ui->tableWidget->setItem(row, 3, new QTableWidgetItem(zd.is_sync)); + ui->tableWidget->setItem(row, 4, new QTableWidgetItem(zd.remark)); + if(zd.type=="1") + { + ui->tableWidget->setItem(row, 5, new QTableWidgetItem("下载")); + }else{ ui->tableWidget->setItem(row, 5, new QTableWidgetItem("上传")); } + + //添加操作按钮 + QPushButton *button = new QPushButton("查询信息"); + button->setIconSize(QSize(16,16)); + button->setIcon(QIcon(":/image/Index/u2327.svg")); + ui->tableWidget->setCellWidget(row, 6, button); + //设置按钮简单样式 + button->setStyleSheet("QPushButton {" + " border: none; /* 无边框 */" + " color: green; /* 文本颜色 */" + " text-decoration: underline; /* 文本下划线 */" + "}"); + + // 设置鼠标悬停时的光标样式为小手图标 + button->setCursor(Qt::PointingHandCursor); + // 连接按钮的 clicked 信号到自定义槽函数 + connect(button, &QPushButton::clicked, this, [this, button, zd]() { + // 获取当前行第一列的 ID + + OnButtonSelectClicked(zd); + + }); + row++; + } } void DataSyncView::on_DownloadDataButton_clicked() { - //从主系统下载 + + SyncDialog *syncDialog = new SyncDialog(this); + syncDialog->exec(); // 显示进度条窗体并阻塞主窗口 + + this->initForm(); + } -void DataSyncView::syncTable() +void DataSyncView::OnButtonSelectClicked(zdLog log) { - //连接两个数据库 - bool IsOpen=false; - DatabaseConnection *Conn=DatabaseConnection::getInstance(); - IsOpen=Conn->open(); - //MainSysDatabaseConnection *MainConn=MainSysDatabaseConnection::getInstance(); - //IsOpen=MainConn->open(); + ui->stackedWidget->setCurrentIndex(1); + ui->tableWidget_2->setRowCount(0); + int rowCount=0; + int row=0; + QList data= BaseCommonApi::getzdDataSyncByuserId(log.id); + for(const zdDataSync & item:data) + { + rowCount = ui->tableWidget_2->rowCount(); + ui->tableWidget_2->insertRow(rowCount); + ui->tableWidget_2->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget_2->setItem(row, 1, new QTableWidgetItem(item.remark)); + QTableWidgetItem *itemRow; + if(item.sync_type=="0"){ + itemRow = new QTableWidgetItem("未同步"); + itemRow->setBackground(QBrush(QColor(255, 255, 192))); + }else if (item.sync_type=="1") + { + itemRow = new QTableWidgetItem("同步成功"); + itemRow->setBackground(QBrush(QColor(173, 255, 47))); // 浅绿色 + }else{ + itemRow = new QTableWidgetItem("同步失败"); + itemRow->setBackground(QBrush(QColor(255, 105, 180))); // 浅红色 + } + itemRow->setTextAlignment(Qt::AlignCenter); + ui->tableWidget_2->setItem(row, 2, itemRow); + + row++; + } +} + +void DataSyncView::on_button_return_clicked() +{ + ui->stackedWidget->setCurrentIndex(0); } diff --git a/softwareDirectory/AutoVerScheme/datasyncview.h b/softwareDirectory/AutoVerScheme/datasyncview.h index 174480e..b2b9847 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.h +++ b/softwareDirectory/AutoVerScheme/datasyncview.h @@ -2,6 +2,16 @@ #define DATASYNCVIEW_H #include +#include +#include "synctask.h" +#include "databaseconnection.h" +#include "basecommonapi.h" +#include "databaseconnectionmainsys.h" +#include +#include +#include +#include +#include namespace Ui { class DataSyncView; @@ -18,8 +28,12 @@ void initForm(); //初始化界面数据 void on_DownloadDataButton_clicked(); - //异步更新 - void syncTable(); + void OnButtonSelectClicked(zdLog log); + void on_button_return_clicked(); + +public: + + private: Ui::DataSyncView *ui; }; diff --git a/softwareDirectory/AutoVerScheme/datasyncview.ui b/softwareDirectory/AutoVerScheme/datasyncview.ui index 53c379c..7c9df8e 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.ui +++ b/softwareDirectory/AutoVerScheme/datasyncview.ui @@ -14,21 +14,9 @@ 数据同步 - background-color:rgba(240, 240, 240, 1); + background-color:white; - - - 0 - - - 0 - - - 0 - - - 0 - + @@ -73,119 +61,173 @@ - - - background-color:white; - - - - - - - 3 - - - - - - 0 - 0 - - - - background-color:white; + + + + + + + background-color:white; + + + + + + + 3 + + + + + + 0 + 0 + + + + background-color:white; border:0; - - - - - - - - - - 0 - 0 - - - - font:bold 20px Arial, sans-serif; + + + + + + + + + + 0 + 0 + + + + font:bold 20px Arial, sans-serif; color:#334582; - - - 同步记录 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - background-color:#334582; + + + 同步记录 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + background-color:#334582; font: bold 18px Arial, sans-serif; color:white; padding:10px; - - - 下载数据 - - - - - - - - 200 - 0 - - - - - 100 - 40 - - - - Qt::RightToLeft - - - background-color:#334582; + + + 下载数据 + + + + + + + + 200 + 0 + + + + + 100 + 40 + + + + Qt::RightToLeft + + + background-color:#334582; font: bold 18px Arial, sans-serif; color:white; padding:10px; - - - 发送同步请求 - - - - :/image/Index/u8458.svg:/image/Index/u8458.svg - - - - - - - - - - - - - - + + + 发送同步请求 + + + + :/image/Index/u8458.svg:/image/Index/u8458.svg + + + + + + + + + + + + + + + + + + + + + + + + background-color:white; + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + color:black; + + + 返回 + + + + + + + + + + + + + diff --git a/softwareDirectory/AutoVerScheme/depar_task.cpp b/softwareDirectory/AutoVerScheme/depar_task.cpp index d551972..d58cf35 100644 --- a/softwareDirectory/AutoVerScheme/depar_task.cpp +++ b/softwareDirectory/AutoVerScheme/depar_task.cpp @@ -113,6 +113,7 @@ else State="否"; ui->tableWidget->setItem(row, 9, new QTableWidgetItem(State)); //设置数据 + SetHomePaheCombox(dept); //添加 PageData数据 TempData.append(QString::number(row+1)); TempData.append(dept.sample_name); @@ -133,9 +134,9 @@ //设置分页控件 // 创建分页表格控件 - PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); +// PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); //data转换位QList> - pagedTable->setData(PageData, 20,ui->tableWidget); // 每页20行 + // pagedTable->setData(PageData, 20,ui->tableWidget); // 每页20行 } void Depar_Task::on_SelectButton_clicked() @@ -155,26 +156,31 @@ if(dept.measure_status=="3" || dept.measure_status=="4"){ bool shouldAddRow = true; // 初始假设应该添加这一行 // 根据设备名称筛选 + QString names; if (ui->name->currentText() != "ALL") { + names=ui->name->currentText(); if (ui->name->currentText() != dept.sample_name) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } if (ui->mode->currentText() != "ALL") { + names=ui->mode->currentText(); if (ui->mode->currentText() != dept.sample_model) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } if (ui->customer->currentText() != "ALL") { + if (ui->customer->currentText() != dept.customer_name) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } - if (ui->dept->currentText() != "") { + if (ui->dept->currentText() != "ALL") { if (ui->dept->currentText() != dept.FULL_NAME) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); ui->tableWidget->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); @@ -193,9 +199,10 @@ State="否"; ui->tableWidget->setItem(row, 9, new QTableWidgetItem(State)); //设置数据 // - SetHomePaheCombox(dept); + //QDebug row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/indexwindow.cpp b/softwareDirectory/AutoVerScheme/indexwindow.cpp index eed192a..060b86e 100644 --- a/softwareDirectory/AutoVerScheme/indexwindow.cpp +++ b/softwareDirectory/AutoVerScheme/indexwindow.cpp @@ -58,7 +58,7 @@ DatabaseConnection *Conn=DatabaseConnection::getInstance(); //数据库连接 目前先放这里 后续需要放到登录界面 - bool IsOpen=Conn->open(); + bool IsOpen=Conn->open(); if(IsOpen) ShowMessageBox("数据库连接","连接成功"); else diff --git a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro index bf70fab..d9a99ea 100644 --- a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro +++ b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro @@ -35,6 +35,7 @@ create_task.cpp \ createtask_scandevice.cpp \ databaseconnection.cpp \ + databaseconnectionmainsys.cpp \ datasyncview.cpp \ depar_task.cpp \ depar_task_server.cpp \ @@ -55,6 +56,7 @@ newverifymethod.cpp \ rulefileitem.cpp \ standard_deviceitem.cpp \ + syncdialog.cpp \ synctask.cpp \ testdataitem.cpp \ testview.cpp \ @@ -69,6 +71,7 @@ DataProcessingBLL.h \ PageControl.h \ createtask_scandevice.h \ + databaseconnectionmainsys.h \ formaddrsetting.h \ formcommsetting.h \ id/IdWorker.h \ @@ -104,6 +107,7 @@ newverifymethod.h \ rulefileitem.h \ standard_deviceitem.h \ + syncdialog.h \ synctask.h \ testdataitem.h \ testview.h \ @@ -138,6 +142,7 @@ newverifymethod.ui \ rulefileitem.ui \ standard_deviceitem.ui \ + syncdialog.ui \ testdataitem.ui \ testview.ui \ verifydevice.ui \ diff --git a/softwareDirectory/AutoVerScheme/PageControl.cpp b/softwareDirectory/AutoVerScheme/PageControl.cpp index d0fd72b..d1bdddc 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.cpp +++ b/softwareDirectory/AutoVerScheme/PageControl.cpp @@ -22,14 +22,14 @@ } } -void PagedTableWidget::setData(const QList> &data, int rowsPerPage,QTableWidget *table) { - tableWidget=table; - +void PagedTableWidget::setData(int datacount, int rowsPerPage) { + //tableWidget=table; + totaldatacount=datacount; this->rowsPerPage = rowsPerPage; - allData = data; + //allData = data; currentPage = 0; createPageButtons(); - updateTable(); + //updateTable(); } void PagedTableWidget::setCurrentPage(int page) { @@ -39,7 +39,7 @@ button->setChecked(false); }*/ currentPage = page; - updateTable(); + //updateTable(); emit pageChanged(page); } } @@ -89,6 +89,7 @@ setCurrentPage(pageIndex); } } +/* void PagedTableWidget::updateTable() { //tableWidget->clear(); tableWidget->setRowCount(0); @@ -105,7 +106,7 @@ } } } - +*/ void PagedTableWidget::createPageButtons() { int totalPages = calculateTotalPages(); for (auto button : pageButtons) { @@ -150,5 +151,5 @@ } int PagedTableWidget::calculateTotalPages() { - return ((allData.count() + rowsPerPage -1) / rowsPerPage); + return ((totaldatacount + rowsPerPage -1) / rowsPerPage); } diff --git a/softwareDirectory/AutoVerScheme/PageControl.h b/softwareDirectory/AutoVerScheme/PageControl.h index 74ed1ce..2224760 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.h +++ b/softwareDirectory/AutoVerScheme/PageControl.h @@ -15,7 +15,7 @@ explicit PagedTableWidget(QWidget *parent = nullptr,QHBoxLayout *PageLayout=NULL); ~PagedTableWidget(); - void setData(const QList> &data, int rowsPerPage = 10,QTableWidget *table=NULL); + void setData(int datacount, int rowsPerPage = 10); void setCurrentPage(int page); signals: @@ -30,6 +30,7 @@ QHBoxLayout *pageLayout; QList pageButtons; QList> allData; + int totaldatacount; int rowsPerPage; int currentPage; diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.cpp b/softwareDirectory/AutoVerScheme/basecommonapi.cpp index 49cbd7e..6f6fe94 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.cpp +++ b/softwareDirectory/AutoVerScheme/basecommonapi.cpp @@ -13,7 +13,7 @@ } const QString BaseCommonApi::temporary_user_id="1634107227953819649"; const QString BaseCommonApi::measure_person_id="1695282436182188034"; - +static SyncRunStatus syncstate=SyncRunStatus::Stopped; //sys_user表的id转换为measure_person_id 检定人id(meter_staff表id) @@ -167,7 +167,8 @@ "JOIN eqpt_equipment_info eei ON eei.id = blei.sample_id " "JOIN biz_business_order_info bo ON bo.id = blei.order_id " "LEFT JOIN sys_dept sd ON blei.measure_dept_id = sd.ID " - " WHERE blei.measure_person_id = :person_id " + " WHERE blei.measure_person_id = :person_id " + " AND blei.measure_status =3 or blei.measure_status = 4 " " ORDER BY blei.update_time DESC"); // 将参数绑定到占位符 @@ -175,7 +176,8 @@ //query.bindValue(":status", status); if (query.exec()) { while (query.next()) { - MyTask task; + + MyTask task; task.id = query.value("id").toString(); task.sample_name = query.value("sampleName").toString(); task.sample_model = query.value("sampleModel").toString(); @@ -2872,9 +2874,40 @@ return result; } +//保存log信息 +//log文件 + bool BaseCommonApi::SaveLogInfo(QString path,QString Info) +{ + QByteArray utf8Dat; + QString Message=Info; + QFile file(path); + // 如果目录不存在,则创建目录 + // 获取文件所在的目录 + QDir logDir = QDir(QFileInfo(path).absolutePath()); + if (!logDir.exists()) { + if (!logDir.mkpath(".")) { + qDebug() << "Failed to create log directory:" << logDir.absolutePath(); + return false; + } + } + + if (!file.open(QIODevice::Append | QIODevice::Text)) { + qDebug() << "无法打开文件:" << file.errorString(); + return false; + } + QTextStream out(&file); + utf8Dat = Message.toUtf8(); + out << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss") + << "\t" << utf8Dat << "\n"; + file.close(); + return true; + } + + //新增日志表数据 bool BaseCommonApi::InsertzdLog(zdLog log) { + log.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_log(id,is_sync,sync_time,remark,userid,type,create_time,update_time) " " VALUES(:id,:is_sync,:sync_time,:remark,:userid,:type,:create_time,:update_time) "); @@ -2898,6 +2931,7 @@ //根据userid查询日志表数据 QList BaseCommonApi::getzdLogByuserId(QString userid) { + userid=temporary_user_id; QList result; QSqlQuery query; query.prepare("SELECT * FROM zd_log WHERE userid = :userid "); @@ -2922,6 +2956,7 @@ //新增数据同步表 bool BaseCommonApi::InsertzdDataSync(zdDataSync data) { + data.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_data_sync(id,type,ssql,userid,remark,create_time,update_time,log_sync_id,sync_type) " " VALUES " @@ -2945,12 +2980,12 @@ return isSuccess; } //根据userid查询数据同步表 -QList getzdDataSyncByuserId(QString userid) +QList BaseCommonApi::getzdDataSyncByuserId(QString log_sync_id) { QList result; QSqlQuery query; - query.prepare("SELECT * FROM zd_data_sync WHERE userid= :userid "); - query.bindValue(":userid",userid); + query.prepare("SELECT * FROM zd_data_sync WHERE log_sync_id= :log_sync_id "); + query.bindValue(":log_sync_id",log_sync_id); if (query.exec()) { while (query.next()) { zdDataSync data; @@ -2972,3 +3007,4 @@ } + diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.h b/softwareDirectory/AutoVerScheme/basecommonapi.h index 12196fb..4949683 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.h +++ b/softwareDirectory/AutoVerScheme/basecommonapi.h @@ -919,6 +919,7 @@ QDateTime create_time; QDateTime update_time; }; + //数据同步-数据表 class zdDataSync { @@ -935,6 +936,12 @@ }; +enum class SyncRunStatus { + + Running, + Stopped, + Paused +}; using namespace Jiawa::Core; class BaseCommonApi @@ -945,7 +952,6 @@ const static QString temporary_costomer_id; const static QString measure_person_id; - QString encrypt(const QString &str, const QString &publicKey); //判断检定装置表并查询 参数设备id @@ -1137,14 +1143,19 @@ //单独查询任务单表 //更新 任务单 static InsertTask SelectTaskSingle(QString order_id); + + //log文件 + static bool SaveLogInfo(QString path,QString Info); + //新增日志表数据 static bool InsertzdLog(zdLog log); //查询日志表数据 static QList getzdLogByuserId(QString userid); //新增数据同步表 static bool InsertzdDataSync(zdDataSync data); - //根据userid查询数据同步表 - static QList getzdDataSyncByuserId(QString userid); + //根据log_sync_id查询数据同步表 + static QList getzdDataSyncByuserId(QString log_sync_id); + }; diff --git a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp index 00d746b..ae60962 100644 --- a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp @@ -352,6 +352,7 @@ } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -395,6 +396,7 @@ row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.cpp b/softwareDirectory/AutoVerScheme/databaseconnection.cpp index 1d957d9..5284fe6 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.cpp +++ b/softwareDirectory/AutoVerScheme/databaseconnection.cpp @@ -10,17 +10,21 @@ { // 连接数据库 - db = QSqlDatabase::addDatabase("QODBC"); - /*db.setHostName("111.198.10.15"); - db.setDatabaseName("casic_metering_xichang"); - db.setPort(21906); - db.setUserName("zdjdcs"); - db.setPassword("11111111");*/ - db.setHostName("localhost"); - db.setDatabaseName("zdjd"); - db.setPort(3306); - db.setUserName("root"); - db.setPassword("123456"); + localdb = QSqlDatabase::addDatabase("QODBC"); + + localdb.setHostName("localhost"); + localdb.setDatabaseName("zdjd"); + localdb.setPort(3306); + localdb.setUserName("root"); + localdb.setPassword("123456"); + + Maindb = QSqlDatabase::addDatabase("QODBC","Main"); + Maindb.setHostName("111.198.10.15"); + Maindb.setDatabaseName("casic_metering_xichang"); + Maindb.setPort(21906); + Maindb.setUserName("zdjdcs"); + Maindb.setPassword("11111111"); + } @@ -29,18 +33,28 @@ close(); } bool DatabaseConnection::open() { - return db.open(); + return localdb.open(); +} +bool DatabaseConnection::openmain() { + return Maindb.open(); } bool DatabaseConnection::isopen() { - return db.isOpen(); + return localdb.isOpen(); } - +bool DatabaseConnection::isopenmain() { + return Maindb.isOpen(); +} void DatabaseConnection::close() { - db.close(); + localdb.close(); } - +void DatabaseConnection::closemain() { + Maindb.close(); +} QSqlDatabase& DatabaseConnection::getDatabase() { - return db; + return localdb; +} +QSqlDatabase& DatabaseConnection::getDatabaseMain() { + return Maindb; } DatabaseConnection* DatabaseConnection::getInstance() { diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.h b/softwareDirectory/AutoVerScheme/databaseconnection.h index 586b794..5f9810b 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.h +++ b/softwareDirectory/AutoVerScheme/databaseconnection.h @@ -16,8 +16,12 @@ ~DatabaseConnection(); bool open(); bool isopen(); + bool openmain(); void close(); + void closemain(); + bool isopenmain(); QSqlDatabase& getDatabase(); + QSqlDatabase& getDatabaseMain(); private: //单列模式 保证DatabaseConnection的唯一性 static DatabaseConnection* Connect; @@ -33,7 +37,8 @@ //如果尝试这样做,编译器同样会报错。 DatabaseConnection& operator=(const DatabaseConnection&) = delete; //数据库db类 - QSqlDatabase db; + QSqlDatabase Maindb; + QSqlDatabase localdb; }; #endif // DATABASECONNECTION_H diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp new file mode 100644 index 0000000..080288b --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp @@ -0,0 +1,54 @@ +#include "databaseconnectionmainsys.h" + + + + +DatabaseConnectionMainSys* DatabaseConnectionMainSys::Connect = nullptr; +QMutex DatabaseConnectionMainSys::mutex; + +DatabaseConnectionMainSys::DatabaseConnectionMainSys() +{ + + // 连接数据库 + dbmain = QSqlDatabase::addDatabase("QODBC"); + dbmain.setHostName("111.198.10.15"); + dbmain.setDatabaseName("casic_metering_xichang"); + dbmain.setPort(21906); + dbmain.setUserName("zdjdcs"); + dbmain.setPassword("11111111"); + /* db.setHostName("localhost"); + db.setDatabaseName("zdjd"); + db.setPort(3306); + db.setUserName("root"); + db.setPassword("123456");*/ + + +} +DatabaseConnectionMainSys::~DatabaseConnectionMainSys() { + // 在析构函数中关闭数据库连接 + close(); +} +bool DatabaseConnectionMainSys::open() { + return dbmain.open(); +} +bool DatabaseConnectionMainSys::isopen() { + return dbmain.isOpen(); +} + +void DatabaseConnectionMainSys::close() { + dbmain.close(); +} + +QSqlDatabase& DatabaseConnectionMainSys::getDatabase() { + return dbmain; +} +DatabaseConnectionMainSys* DatabaseConnectionMainSys::getInstance() +{ + if (!Connect) { + QMutexLocker locker(&mutex); + if (!Connect) { + Connect = new DatabaseConnectionMainSys(); + } + } + return Connect; +} diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h new file mode 100644 index 0000000..57702ad --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h @@ -0,0 +1,41 @@ +#ifndef DATABASECONNECTIONMAINSYS_H +#define DATABASECONNECTIONMAINSYS_H +#include +#include +#include +#include + + +class DatabaseConnectionMainSys +{ + + +public: + //获取数据库实例 + static DatabaseConnectionMainSys* getInstance(); + + DatabaseConnectionMainSys(); + ~DatabaseConnectionMainSys(); + bool open(); + bool isopen(); + void close(); + QSqlDatabase& getDatabase(); +private: + //单列模式 保证MainSysDatabaseConnection的唯一性 + static DatabaseConnectionMainSys* Connect; + //QMutex 来确保在多线程环境下单例的正确创建。 + static QMutex mutex; + + //这是拷贝构造函数的声明,后面跟着 = delete; 表示这个构造函数被删除了。 + //这意味着你不能通过拷贝另一个 DatabaseConnection 对象来创建新的 DatabaseConnection 对象。 + //如果尝试这样做,编译器会报错。 + DatabaseConnectionMainSys(const DatabaseConnectionMainSys&) = delete; + //这是拷贝赋值运算符的声明,同样后面跟着 = delete; 表示这个运算符被删除了。 + //这意味着你不能将一个 DatabaseConnection 对象赋值给另一个 DatabaseConnection 对象。 + //如果尝试这样做,编译器同样会报错。 + DatabaseConnectionMainSys& operator=(const DatabaseConnectionMainSys&) = delete; + //数据库db类 + QSqlDatabase dbmain; +}; + +#endif // DATABASECONNECTIONMAINSYS_H diff --git a/softwareDirectory/AutoVerScheme/datasyncview.cpp b/softwareDirectory/AutoVerScheme/datasyncview.cpp index fbf4508..06c7f9a 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.cpp +++ b/softwareDirectory/AutoVerScheme/datasyncview.cpp @@ -1,11 +1,10 @@ #include "datasyncview.h" #include "ui_datasyncview.h" -#include "synctask.h" -#include "databaseconnection.h" -#include "mainsysdatabaseconnection.h" +#include "syncdialog.h" - +QString filePath = "C:\\AutoVerScheme\\sync_info.txt"; +// 获取当前时间戳 DataSyncView::DataSyncView(QWidget *parent) : QWidget(parent), ui(new Ui::DataSyncView) @@ -20,7 +19,7 @@ } void DataSyncView::initForm() { - //tableWidget设置 + ui->stackedWidget->setCurrentIndex(0); //设置控件的边框显示 ui->tableWidget->setStyleSheet("QHeaderView::section {" "border: 1px solid grey;" @@ -32,29 +31,129 @@ "}"); ui->tableWidget->setRowCount(10); // 设置10行 - ui->tableWidget->setColumnCount(4); // 设置11列 - ui->tableWidget->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnCount(7); // 设置11列 + ui->tableWidget->setColumnWidth(0, 0); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnWidth(2, 200); // 设置第一列的宽度为100像素 ui->tableWidget->verticalHeader()->setParent(nullptr); //隐藏行头 - QTableWidgetItem *item = new QTableWidgetItem("测试数据"); - item->setTextAlignment(Qt::AlignCenter); - ui->tableWidget->setItem(0, 0, item); //设置数据 + + //初始化TableWidget 设置列 QStringList headers; - headers << "序号" << "同步时间" << "是否同步成功" << "备注" ; + headers <<"id" << "序号" << "同步时间" << "是否同步成功" << "备注" + <<"类型" <<"操作"; ui->tableWidget->setHorizontalHeaderLabels(headers); + //详情内 + + //设置控件的边框显示 + ui->tableWidget_2->setStyleSheet("QHeaderView::section {" + "border: 1px solid grey;" + "border-left:none;" + "border-top:none;" + "background-color:white;" + " color:black;" + "font: bold 18px Arial, sans-serif;" + "}"); + + ui->tableWidget_2->setRowCount(10); // 设置10行 + ui->tableWidget_2->setColumnCount(3); // 设置11列 + ui->tableWidget_2->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget_2->verticalHeader()->setParent(nullptr); //隐藏行头 + ui->tableWidget_2->setColumnWidth(1, 1000); // 设置第一列的宽度为100像素 + + //初始化TableWidget 设置列 + + headers << "序号" << "信息" << "状态" ; + ui->tableWidget_2->setHorizontalHeaderLabels(headers); + + //数据显示 + + //先设置为行为0 + ui->tableWidget->setRowCount(0); + int rowCount=0; + int row=0; + QList zdlog= BaseCommonApi::getzdLogByuserId(""); + for(const zdLog & zd:zdlog) + { + rowCount = ui->tableWidget->rowCount(); + ui->tableWidget->insertRow(rowCount); + ui->tableWidget->setItem(row, 0, new QTableWidgetItem(zd.id)); + ui->tableWidget->setItem(row, 1, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget->setItem(row, 2, new QTableWidgetItem(zd.sync_time.toString())); + ui->tableWidget->setItem(row, 3, new QTableWidgetItem(zd.is_sync)); + ui->tableWidget->setItem(row, 4, new QTableWidgetItem(zd.remark)); + if(zd.type=="1") + { + ui->tableWidget->setItem(row, 5, new QTableWidgetItem("下载")); + }else{ ui->tableWidget->setItem(row, 5, new QTableWidgetItem("上传")); } + + //添加操作按钮 + QPushButton *button = new QPushButton("查询信息"); + button->setIconSize(QSize(16,16)); + button->setIcon(QIcon(":/image/Index/u2327.svg")); + ui->tableWidget->setCellWidget(row, 6, button); + //设置按钮简单样式 + button->setStyleSheet("QPushButton {" + " border: none; /* 无边框 */" + " color: green; /* 文本颜色 */" + " text-decoration: underline; /* 文本下划线 */" + "}"); + + // 设置鼠标悬停时的光标样式为小手图标 + button->setCursor(Qt::PointingHandCursor); + // 连接按钮的 clicked 信号到自定义槽函数 + connect(button, &QPushButton::clicked, this, [this, button, zd]() { + // 获取当前行第一列的 ID + + OnButtonSelectClicked(zd); + + }); + row++; + } } void DataSyncView::on_DownloadDataButton_clicked() { - //从主系统下载 + + SyncDialog *syncDialog = new SyncDialog(this); + syncDialog->exec(); // 显示进度条窗体并阻塞主窗口 + + this->initForm(); + } -void DataSyncView::syncTable() +void DataSyncView::OnButtonSelectClicked(zdLog log) { - //连接两个数据库 - bool IsOpen=false; - DatabaseConnection *Conn=DatabaseConnection::getInstance(); - IsOpen=Conn->open(); - //MainSysDatabaseConnection *MainConn=MainSysDatabaseConnection::getInstance(); - //IsOpen=MainConn->open(); + ui->stackedWidget->setCurrentIndex(1); + ui->tableWidget_2->setRowCount(0); + int rowCount=0; + int row=0; + QList data= BaseCommonApi::getzdDataSyncByuserId(log.id); + for(const zdDataSync & item:data) + { + rowCount = ui->tableWidget_2->rowCount(); + ui->tableWidget_2->insertRow(rowCount); + ui->tableWidget_2->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget_2->setItem(row, 1, new QTableWidgetItem(item.remark)); + QTableWidgetItem *itemRow; + if(item.sync_type=="0"){ + itemRow = new QTableWidgetItem("未同步"); + itemRow->setBackground(QBrush(QColor(255, 255, 192))); + }else if (item.sync_type=="1") + { + itemRow = new QTableWidgetItem("同步成功"); + itemRow->setBackground(QBrush(QColor(173, 255, 47))); // 浅绿色 + }else{ + itemRow = new QTableWidgetItem("同步失败"); + itemRow->setBackground(QBrush(QColor(255, 105, 180))); // 浅红色 + } + itemRow->setTextAlignment(Qt::AlignCenter); + ui->tableWidget_2->setItem(row, 2, itemRow); + + row++; + } +} + +void DataSyncView::on_button_return_clicked() +{ + ui->stackedWidget->setCurrentIndex(0); } diff --git a/softwareDirectory/AutoVerScheme/datasyncview.h b/softwareDirectory/AutoVerScheme/datasyncview.h index 174480e..b2b9847 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.h +++ b/softwareDirectory/AutoVerScheme/datasyncview.h @@ -2,6 +2,16 @@ #define DATASYNCVIEW_H #include +#include +#include "synctask.h" +#include "databaseconnection.h" +#include "basecommonapi.h" +#include "databaseconnectionmainsys.h" +#include +#include +#include +#include +#include namespace Ui { class DataSyncView; @@ -18,8 +28,12 @@ void initForm(); //初始化界面数据 void on_DownloadDataButton_clicked(); - //异步更新 - void syncTable(); + void OnButtonSelectClicked(zdLog log); + void on_button_return_clicked(); + +public: + + private: Ui::DataSyncView *ui; }; diff --git a/softwareDirectory/AutoVerScheme/datasyncview.ui b/softwareDirectory/AutoVerScheme/datasyncview.ui index 53c379c..7c9df8e 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.ui +++ b/softwareDirectory/AutoVerScheme/datasyncview.ui @@ -14,21 +14,9 @@ 数据同步 - background-color:rgba(240, 240, 240, 1); + background-color:white; - - - 0 - - - 0 - - - 0 - - - 0 - + @@ -73,119 +61,173 @@ - - - background-color:white; - - - - - - - 3 - - - - - - 0 - 0 - - - - background-color:white; + + + + + + + background-color:white; + + + + + + + 3 + + + + + + 0 + 0 + + + + background-color:white; border:0; - - - - - - - - - - 0 - 0 - - - - font:bold 20px Arial, sans-serif; + + + + + + + + + + 0 + 0 + + + + font:bold 20px Arial, sans-serif; color:#334582; - - - 同步记录 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - background-color:#334582; + + + 同步记录 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + background-color:#334582; font: bold 18px Arial, sans-serif; color:white; padding:10px; - - - 下载数据 - - - - - - - - 200 - 0 - - - - - 100 - 40 - - - - Qt::RightToLeft - - - background-color:#334582; + + + 下载数据 + + + + + + + + 200 + 0 + + + + + 100 + 40 + + + + Qt::RightToLeft + + + background-color:#334582; font: bold 18px Arial, sans-serif; color:white; padding:10px; - - - 发送同步请求 - - - - :/image/Index/u8458.svg:/image/Index/u8458.svg - - - - - - - - - - - - - - + + + 发送同步请求 + + + + :/image/Index/u8458.svg:/image/Index/u8458.svg + + + + + + + + + + + + + + + + + + + + + + + + background-color:white; + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + color:black; + + + 返回 + + + + + + + + + + + + + diff --git a/softwareDirectory/AutoVerScheme/depar_task.cpp b/softwareDirectory/AutoVerScheme/depar_task.cpp index d551972..d58cf35 100644 --- a/softwareDirectory/AutoVerScheme/depar_task.cpp +++ b/softwareDirectory/AutoVerScheme/depar_task.cpp @@ -113,6 +113,7 @@ else State="否"; ui->tableWidget->setItem(row, 9, new QTableWidgetItem(State)); //设置数据 + SetHomePaheCombox(dept); //添加 PageData数据 TempData.append(QString::number(row+1)); TempData.append(dept.sample_name); @@ -133,9 +134,9 @@ //设置分页控件 // 创建分页表格控件 - PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); +// PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); //data转换位QList> - pagedTable->setData(PageData, 20,ui->tableWidget); // 每页20行 + // pagedTable->setData(PageData, 20,ui->tableWidget); // 每页20行 } void Depar_Task::on_SelectButton_clicked() @@ -155,26 +156,31 @@ if(dept.measure_status=="3" || dept.measure_status=="4"){ bool shouldAddRow = true; // 初始假设应该添加这一行 // 根据设备名称筛选 + QString names; if (ui->name->currentText() != "ALL") { + names=ui->name->currentText(); if (ui->name->currentText() != dept.sample_name) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } if (ui->mode->currentText() != "ALL") { + names=ui->mode->currentText(); if (ui->mode->currentText() != dept.sample_model) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } if (ui->customer->currentText() != "ALL") { + if (ui->customer->currentText() != dept.customer_name) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } - if (ui->dept->currentText() != "") { + if (ui->dept->currentText() != "ALL") { if (ui->dept->currentText() != dept.FULL_NAME) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); ui->tableWidget->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); @@ -193,9 +199,10 @@ State="否"; ui->tableWidget->setItem(row, 9, new QTableWidgetItem(State)); //设置数据 // - SetHomePaheCombox(dept); + //QDebug row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/indexwindow.cpp b/softwareDirectory/AutoVerScheme/indexwindow.cpp index eed192a..060b86e 100644 --- a/softwareDirectory/AutoVerScheme/indexwindow.cpp +++ b/softwareDirectory/AutoVerScheme/indexwindow.cpp @@ -58,7 +58,7 @@ DatabaseConnection *Conn=DatabaseConnection::getInstance(); //数据库连接 目前先放这里 后续需要放到登录界面 - bool IsOpen=Conn->open(); + bool IsOpen=Conn->open(); if(IsOpen) ShowMessageBox("数据库连接","连接成功"); else diff --git a/softwareDirectory/AutoVerScheme/my_task.cpp b/softwareDirectory/AutoVerScheme/my_task.cpp index 1735575..cd735f8 100644 --- a/softwareDirectory/AutoVerScheme/my_task.cpp +++ b/softwareDirectory/AutoVerScheme/my_task.cpp @@ -62,7 +62,8 @@ } void My_Task::Load() { - QList> PageData; + + //QList> PageData; //先设置为行为0 ui->tableWidget->setRowCount(0); //添加comboBox @@ -86,11 +87,29 @@ QString userId=""; data = BaseCommonApi::getMyTasks(userId,"3"); + QString State; + //设置单页显示数量 + page=20; + // 创建分页表格控件 + PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); + pagedTable->setData(data.count(), page); // 每页10行 + connect(pagedTable, &PagedTableWidget::pageChanged, this,&My_Task::onpageChanged); + this->onpageChanged(0); + +} +void My_Task::onpageChanged(int currPage){ + currPage+=1; + // 计算当前页的开始和结束索引 + int start = (currPage - 1) * page; + int end = std::min(start + page, data.size()); + // 从 QList 中筛选出当前页的数据 + QList tempdate = data.mid(start, end - start); int rowCount = 0; int row=0; QString State; - for (const MyTask& myTask : data) { - if(myTask.measure_status=="3" || myTask.measure_status=="4"){ + ui->tableWidget->setRowCount(0); + for (const MyTask& myTask : tempdate) { + QList TempData; rowCount = ui->tableWidget->rowCount(); @@ -118,42 +137,15 @@ ui->tableWidget->setItem(row, 10,new QTableWidgetItem("检测完成")); } - //渲染下拉框 - SetHomePaheCombox(myTask); - //QDebug - - //添加 PageData数据 - TempData.append(QString::number(row+1)); - TempData.append(myTask.sample_name); - TempData.append(myTask.sample_model); - TempData.append(myTask.help_instruction); - TempData.append(myTask.manufacture_no); - TempData.append(myTask.manufacturer); - TempData.append(myTask.customer_name); - TempData.append(myTask.FULL_NAME); - TempData.append(myTask.require_over_time.toString()); - TempData.append(State); - TempData.append(myTask.measure_status); - PageData.append(TempData); + //渲染下拉框 + SetHomePaheCombox(myTask); row++; - } - - } - //设置分页控件 - // 创建分页表格控件 - - PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); - //data转换位QList> - pagedTable->setData(PageData, 20,ui->tableWidget); // 每页10行 - //ui->HBoxPageLayout->addWidget(pagedTable); - //setLayout(ui->HBoxPageLayout); - // 连接信号以处理页码变化 - /* connect(pagedTable, &PagedTableWidget::pageChanged, this, [=](int page) { - // 在这里处理页码变化事件,比如更新UI中的其他部分 - qDebug() << "Page changed to:" << page; - });*/ + }; + //按钮点击事件 + // QMessageBox::information(this, "点击按钮",QString::number(page)); + // qDebug() << "Page changed to:" << page; } void My_Task::SetHomePaheCombox(MyTask entity) { diff --git a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro index bf70fab..d9a99ea 100644 --- a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro +++ b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro @@ -35,6 +35,7 @@ create_task.cpp \ createtask_scandevice.cpp \ databaseconnection.cpp \ + databaseconnectionmainsys.cpp \ datasyncview.cpp \ depar_task.cpp \ depar_task_server.cpp \ @@ -55,6 +56,7 @@ newverifymethod.cpp \ rulefileitem.cpp \ standard_deviceitem.cpp \ + syncdialog.cpp \ synctask.cpp \ testdataitem.cpp \ testview.cpp \ @@ -69,6 +71,7 @@ DataProcessingBLL.h \ PageControl.h \ createtask_scandevice.h \ + databaseconnectionmainsys.h \ formaddrsetting.h \ formcommsetting.h \ id/IdWorker.h \ @@ -104,6 +107,7 @@ newverifymethod.h \ rulefileitem.h \ standard_deviceitem.h \ + syncdialog.h \ synctask.h \ testdataitem.h \ testview.h \ @@ -138,6 +142,7 @@ newverifymethod.ui \ rulefileitem.ui \ standard_deviceitem.ui \ + syncdialog.ui \ testdataitem.ui \ testview.ui \ verifydevice.ui \ diff --git a/softwareDirectory/AutoVerScheme/PageControl.cpp b/softwareDirectory/AutoVerScheme/PageControl.cpp index d0fd72b..d1bdddc 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.cpp +++ b/softwareDirectory/AutoVerScheme/PageControl.cpp @@ -22,14 +22,14 @@ } } -void PagedTableWidget::setData(const QList> &data, int rowsPerPage,QTableWidget *table) { - tableWidget=table; - +void PagedTableWidget::setData(int datacount, int rowsPerPage) { + //tableWidget=table; + totaldatacount=datacount; this->rowsPerPage = rowsPerPage; - allData = data; + //allData = data; currentPage = 0; createPageButtons(); - updateTable(); + //updateTable(); } void PagedTableWidget::setCurrentPage(int page) { @@ -39,7 +39,7 @@ button->setChecked(false); }*/ currentPage = page; - updateTable(); + //updateTable(); emit pageChanged(page); } } @@ -89,6 +89,7 @@ setCurrentPage(pageIndex); } } +/* void PagedTableWidget::updateTable() { //tableWidget->clear(); tableWidget->setRowCount(0); @@ -105,7 +106,7 @@ } } } - +*/ void PagedTableWidget::createPageButtons() { int totalPages = calculateTotalPages(); for (auto button : pageButtons) { @@ -150,5 +151,5 @@ } int PagedTableWidget::calculateTotalPages() { - return ((allData.count() + rowsPerPage -1) / rowsPerPage); + return ((totaldatacount + rowsPerPage -1) / rowsPerPage); } diff --git a/softwareDirectory/AutoVerScheme/PageControl.h b/softwareDirectory/AutoVerScheme/PageControl.h index 74ed1ce..2224760 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.h +++ b/softwareDirectory/AutoVerScheme/PageControl.h @@ -15,7 +15,7 @@ explicit PagedTableWidget(QWidget *parent = nullptr,QHBoxLayout *PageLayout=NULL); ~PagedTableWidget(); - void setData(const QList> &data, int rowsPerPage = 10,QTableWidget *table=NULL); + void setData(int datacount, int rowsPerPage = 10); void setCurrentPage(int page); signals: @@ -30,6 +30,7 @@ QHBoxLayout *pageLayout; QList pageButtons; QList> allData; + int totaldatacount; int rowsPerPage; int currentPage; diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.cpp b/softwareDirectory/AutoVerScheme/basecommonapi.cpp index 49cbd7e..6f6fe94 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.cpp +++ b/softwareDirectory/AutoVerScheme/basecommonapi.cpp @@ -13,7 +13,7 @@ } const QString BaseCommonApi::temporary_user_id="1634107227953819649"; const QString BaseCommonApi::measure_person_id="1695282436182188034"; - +static SyncRunStatus syncstate=SyncRunStatus::Stopped; //sys_user表的id转换为measure_person_id 检定人id(meter_staff表id) @@ -167,7 +167,8 @@ "JOIN eqpt_equipment_info eei ON eei.id = blei.sample_id " "JOIN biz_business_order_info bo ON bo.id = blei.order_id " "LEFT JOIN sys_dept sd ON blei.measure_dept_id = sd.ID " - " WHERE blei.measure_person_id = :person_id " + " WHERE blei.measure_person_id = :person_id " + " AND blei.measure_status =3 or blei.measure_status = 4 " " ORDER BY blei.update_time DESC"); // 将参数绑定到占位符 @@ -175,7 +176,8 @@ //query.bindValue(":status", status); if (query.exec()) { while (query.next()) { - MyTask task; + + MyTask task; task.id = query.value("id").toString(); task.sample_name = query.value("sampleName").toString(); task.sample_model = query.value("sampleModel").toString(); @@ -2872,9 +2874,40 @@ return result; } +//保存log信息 +//log文件 + bool BaseCommonApi::SaveLogInfo(QString path,QString Info) +{ + QByteArray utf8Dat; + QString Message=Info; + QFile file(path); + // 如果目录不存在,则创建目录 + // 获取文件所在的目录 + QDir logDir = QDir(QFileInfo(path).absolutePath()); + if (!logDir.exists()) { + if (!logDir.mkpath(".")) { + qDebug() << "Failed to create log directory:" << logDir.absolutePath(); + return false; + } + } + + if (!file.open(QIODevice::Append | QIODevice::Text)) { + qDebug() << "无法打开文件:" << file.errorString(); + return false; + } + QTextStream out(&file); + utf8Dat = Message.toUtf8(); + out << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss") + << "\t" << utf8Dat << "\n"; + file.close(); + return true; + } + + //新增日志表数据 bool BaseCommonApi::InsertzdLog(zdLog log) { + log.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_log(id,is_sync,sync_time,remark,userid,type,create_time,update_time) " " VALUES(:id,:is_sync,:sync_time,:remark,:userid,:type,:create_time,:update_time) "); @@ -2898,6 +2931,7 @@ //根据userid查询日志表数据 QList BaseCommonApi::getzdLogByuserId(QString userid) { + userid=temporary_user_id; QList result; QSqlQuery query; query.prepare("SELECT * FROM zd_log WHERE userid = :userid "); @@ -2922,6 +2956,7 @@ //新增数据同步表 bool BaseCommonApi::InsertzdDataSync(zdDataSync data) { + data.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_data_sync(id,type,ssql,userid,remark,create_time,update_time,log_sync_id,sync_type) " " VALUES " @@ -2945,12 +2980,12 @@ return isSuccess; } //根据userid查询数据同步表 -QList getzdDataSyncByuserId(QString userid) +QList BaseCommonApi::getzdDataSyncByuserId(QString log_sync_id) { QList result; QSqlQuery query; - query.prepare("SELECT * FROM zd_data_sync WHERE userid= :userid "); - query.bindValue(":userid",userid); + query.prepare("SELECT * FROM zd_data_sync WHERE log_sync_id= :log_sync_id "); + query.bindValue(":log_sync_id",log_sync_id); if (query.exec()) { while (query.next()) { zdDataSync data; @@ -2972,3 +3007,4 @@ } + diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.h b/softwareDirectory/AutoVerScheme/basecommonapi.h index 12196fb..4949683 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.h +++ b/softwareDirectory/AutoVerScheme/basecommonapi.h @@ -919,6 +919,7 @@ QDateTime create_time; QDateTime update_time; }; + //数据同步-数据表 class zdDataSync { @@ -935,6 +936,12 @@ }; +enum class SyncRunStatus { + + Running, + Stopped, + Paused +}; using namespace Jiawa::Core; class BaseCommonApi @@ -945,7 +952,6 @@ const static QString temporary_costomer_id; const static QString measure_person_id; - QString encrypt(const QString &str, const QString &publicKey); //判断检定装置表并查询 参数设备id @@ -1137,14 +1143,19 @@ //单独查询任务单表 //更新 任务单 static InsertTask SelectTaskSingle(QString order_id); + + //log文件 + static bool SaveLogInfo(QString path,QString Info); + //新增日志表数据 static bool InsertzdLog(zdLog log); //查询日志表数据 static QList getzdLogByuserId(QString userid); //新增数据同步表 static bool InsertzdDataSync(zdDataSync data); - //根据userid查询数据同步表 - static QList getzdDataSyncByuserId(QString userid); + //根据log_sync_id查询数据同步表 + static QList getzdDataSyncByuserId(QString log_sync_id); + }; diff --git a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp index 00d746b..ae60962 100644 --- a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp @@ -352,6 +352,7 @@ } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -395,6 +396,7 @@ row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.cpp b/softwareDirectory/AutoVerScheme/databaseconnection.cpp index 1d957d9..5284fe6 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.cpp +++ b/softwareDirectory/AutoVerScheme/databaseconnection.cpp @@ -10,17 +10,21 @@ { // 连接数据库 - db = QSqlDatabase::addDatabase("QODBC"); - /*db.setHostName("111.198.10.15"); - db.setDatabaseName("casic_metering_xichang"); - db.setPort(21906); - db.setUserName("zdjdcs"); - db.setPassword("11111111");*/ - db.setHostName("localhost"); - db.setDatabaseName("zdjd"); - db.setPort(3306); - db.setUserName("root"); - db.setPassword("123456"); + localdb = QSqlDatabase::addDatabase("QODBC"); + + localdb.setHostName("localhost"); + localdb.setDatabaseName("zdjd"); + localdb.setPort(3306); + localdb.setUserName("root"); + localdb.setPassword("123456"); + + Maindb = QSqlDatabase::addDatabase("QODBC","Main"); + Maindb.setHostName("111.198.10.15"); + Maindb.setDatabaseName("casic_metering_xichang"); + Maindb.setPort(21906); + Maindb.setUserName("zdjdcs"); + Maindb.setPassword("11111111"); + } @@ -29,18 +33,28 @@ close(); } bool DatabaseConnection::open() { - return db.open(); + return localdb.open(); +} +bool DatabaseConnection::openmain() { + return Maindb.open(); } bool DatabaseConnection::isopen() { - return db.isOpen(); + return localdb.isOpen(); } - +bool DatabaseConnection::isopenmain() { + return Maindb.isOpen(); +} void DatabaseConnection::close() { - db.close(); + localdb.close(); } - +void DatabaseConnection::closemain() { + Maindb.close(); +} QSqlDatabase& DatabaseConnection::getDatabase() { - return db; + return localdb; +} +QSqlDatabase& DatabaseConnection::getDatabaseMain() { + return Maindb; } DatabaseConnection* DatabaseConnection::getInstance() { diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.h b/softwareDirectory/AutoVerScheme/databaseconnection.h index 586b794..5f9810b 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.h +++ b/softwareDirectory/AutoVerScheme/databaseconnection.h @@ -16,8 +16,12 @@ ~DatabaseConnection(); bool open(); bool isopen(); + bool openmain(); void close(); + void closemain(); + bool isopenmain(); QSqlDatabase& getDatabase(); + QSqlDatabase& getDatabaseMain(); private: //单列模式 保证DatabaseConnection的唯一性 static DatabaseConnection* Connect; @@ -33,7 +37,8 @@ //如果尝试这样做,编译器同样会报错。 DatabaseConnection& operator=(const DatabaseConnection&) = delete; //数据库db类 - QSqlDatabase db; + QSqlDatabase Maindb; + QSqlDatabase localdb; }; #endif // DATABASECONNECTION_H diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp new file mode 100644 index 0000000..080288b --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp @@ -0,0 +1,54 @@ +#include "databaseconnectionmainsys.h" + + + + +DatabaseConnectionMainSys* DatabaseConnectionMainSys::Connect = nullptr; +QMutex DatabaseConnectionMainSys::mutex; + +DatabaseConnectionMainSys::DatabaseConnectionMainSys() +{ + + // 连接数据库 + dbmain = QSqlDatabase::addDatabase("QODBC"); + dbmain.setHostName("111.198.10.15"); + dbmain.setDatabaseName("casic_metering_xichang"); + dbmain.setPort(21906); + dbmain.setUserName("zdjdcs"); + dbmain.setPassword("11111111"); + /* db.setHostName("localhost"); + db.setDatabaseName("zdjd"); + db.setPort(3306); + db.setUserName("root"); + db.setPassword("123456");*/ + + +} +DatabaseConnectionMainSys::~DatabaseConnectionMainSys() { + // 在析构函数中关闭数据库连接 + close(); +} +bool DatabaseConnectionMainSys::open() { + return dbmain.open(); +} +bool DatabaseConnectionMainSys::isopen() { + return dbmain.isOpen(); +} + +void DatabaseConnectionMainSys::close() { + dbmain.close(); +} + +QSqlDatabase& DatabaseConnectionMainSys::getDatabase() { + return dbmain; +} +DatabaseConnectionMainSys* DatabaseConnectionMainSys::getInstance() +{ + if (!Connect) { + QMutexLocker locker(&mutex); + if (!Connect) { + Connect = new DatabaseConnectionMainSys(); + } + } + return Connect; +} diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h new file mode 100644 index 0000000..57702ad --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h @@ -0,0 +1,41 @@ +#ifndef DATABASECONNECTIONMAINSYS_H +#define DATABASECONNECTIONMAINSYS_H +#include +#include +#include +#include + + +class DatabaseConnectionMainSys +{ + + +public: + //获取数据库实例 + static DatabaseConnectionMainSys* getInstance(); + + DatabaseConnectionMainSys(); + ~DatabaseConnectionMainSys(); + bool open(); + bool isopen(); + void close(); + QSqlDatabase& getDatabase(); +private: + //单列模式 保证MainSysDatabaseConnection的唯一性 + static DatabaseConnectionMainSys* Connect; + //QMutex 来确保在多线程环境下单例的正确创建。 + static QMutex mutex; + + //这是拷贝构造函数的声明,后面跟着 = delete; 表示这个构造函数被删除了。 + //这意味着你不能通过拷贝另一个 DatabaseConnection 对象来创建新的 DatabaseConnection 对象。 + //如果尝试这样做,编译器会报错。 + DatabaseConnectionMainSys(const DatabaseConnectionMainSys&) = delete; + //这是拷贝赋值运算符的声明,同样后面跟着 = delete; 表示这个运算符被删除了。 + //这意味着你不能将一个 DatabaseConnection 对象赋值给另一个 DatabaseConnection 对象。 + //如果尝试这样做,编译器同样会报错。 + DatabaseConnectionMainSys& operator=(const DatabaseConnectionMainSys&) = delete; + //数据库db类 + QSqlDatabase dbmain; +}; + +#endif // DATABASECONNECTIONMAINSYS_H diff --git a/softwareDirectory/AutoVerScheme/datasyncview.cpp b/softwareDirectory/AutoVerScheme/datasyncview.cpp index fbf4508..06c7f9a 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.cpp +++ b/softwareDirectory/AutoVerScheme/datasyncview.cpp @@ -1,11 +1,10 @@ #include "datasyncview.h" #include "ui_datasyncview.h" -#include "synctask.h" -#include "databaseconnection.h" -#include "mainsysdatabaseconnection.h" +#include "syncdialog.h" - +QString filePath = "C:\\AutoVerScheme\\sync_info.txt"; +// 获取当前时间戳 DataSyncView::DataSyncView(QWidget *parent) : QWidget(parent), ui(new Ui::DataSyncView) @@ -20,7 +19,7 @@ } void DataSyncView::initForm() { - //tableWidget设置 + ui->stackedWidget->setCurrentIndex(0); //设置控件的边框显示 ui->tableWidget->setStyleSheet("QHeaderView::section {" "border: 1px solid grey;" @@ -32,29 +31,129 @@ "}"); ui->tableWidget->setRowCount(10); // 设置10行 - ui->tableWidget->setColumnCount(4); // 设置11列 - ui->tableWidget->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnCount(7); // 设置11列 + ui->tableWidget->setColumnWidth(0, 0); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnWidth(2, 200); // 设置第一列的宽度为100像素 ui->tableWidget->verticalHeader()->setParent(nullptr); //隐藏行头 - QTableWidgetItem *item = new QTableWidgetItem("测试数据"); - item->setTextAlignment(Qt::AlignCenter); - ui->tableWidget->setItem(0, 0, item); //设置数据 + + //初始化TableWidget 设置列 QStringList headers; - headers << "序号" << "同步时间" << "是否同步成功" << "备注" ; + headers <<"id" << "序号" << "同步时间" << "是否同步成功" << "备注" + <<"类型" <<"操作"; ui->tableWidget->setHorizontalHeaderLabels(headers); + //详情内 + + //设置控件的边框显示 + ui->tableWidget_2->setStyleSheet("QHeaderView::section {" + "border: 1px solid grey;" + "border-left:none;" + "border-top:none;" + "background-color:white;" + " color:black;" + "font: bold 18px Arial, sans-serif;" + "}"); + + ui->tableWidget_2->setRowCount(10); // 设置10行 + ui->tableWidget_2->setColumnCount(3); // 设置11列 + ui->tableWidget_2->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget_2->verticalHeader()->setParent(nullptr); //隐藏行头 + ui->tableWidget_2->setColumnWidth(1, 1000); // 设置第一列的宽度为100像素 + + //初始化TableWidget 设置列 + + headers << "序号" << "信息" << "状态" ; + ui->tableWidget_2->setHorizontalHeaderLabels(headers); + + //数据显示 + + //先设置为行为0 + ui->tableWidget->setRowCount(0); + int rowCount=0; + int row=0; + QList zdlog= BaseCommonApi::getzdLogByuserId(""); + for(const zdLog & zd:zdlog) + { + rowCount = ui->tableWidget->rowCount(); + ui->tableWidget->insertRow(rowCount); + ui->tableWidget->setItem(row, 0, new QTableWidgetItem(zd.id)); + ui->tableWidget->setItem(row, 1, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget->setItem(row, 2, new QTableWidgetItem(zd.sync_time.toString())); + ui->tableWidget->setItem(row, 3, new QTableWidgetItem(zd.is_sync)); + ui->tableWidget->setItem(row, 4, new QTableWidgetItem(zd.remark)); + if(zd.type=="1") + { + ui->tableWidget->setItem(row, 5, new QTableWidgetItem("下载")); + }else{ ui->tableWidget->setItem(row, 5, new QTableWidgetItem("上传")); } + + //添加操作按钮 + QPushButton *button = new QPushButton("查询信息"); + button->setIconSize(QSize(16,16)); + button->setIcon(QIcon(":/image/Index/u2327.svg")); + ui->tableWidget->setCellWidget(row, 6, button); + //设置按钮简单样式 + button->setStyleSheet("QPushButton {" + " border: none; /* 无边框 */" + " color: green; /* 文本颜色 */" + " text-decoration: underline; /* 文本下划线 */" + "}"); + + // 设置鼠标悬停时的光标样式为小手图标 + button->setCursor(Qt::PointingHandCursor); + // 连接按钮的 clicked 信号到自定义槽函数 + connect(button, &QPushButton::clicked, this, [this, button, zd]() { + // 获取当前行第一列的 ID + + OnButtonSelectClicked(zd); + + }); + row++; + } } void DataSyncView::on_DownloadDataButton_clicked() { - //从主系统下载 + + SyncDialog *syncDialog = new SyncDialog(this); + syncDialog->exec(); // 显示进度条窗体并阻塞主窗口 + + this->initForm(); + } -void DataSyncView::syncTable() +void DataSyncView::OnButtonSelectClicked(zdLog log) { - //连接两个数据库 - bool IsOpen=false; - DatabaseConnection *Conn=DatabaseConnection::getInstance(); - IsOpen=Conn->open(); - //MainSysDatabaseConnection *MainConn=MainSysDatabaseConnection::getInstance(); - //IsOpen=MainConn->open(); + ui->stackedWidget->setCurrentIndex(1); + ui->tableWidget_2->setRowCount(0); + int rowCount=0; + int row=0; + QList data= BaseCommonApi::getzdDataSyncByuserId(log.id); + for(const zdDataSync & item:data) + { + rowCount = ui->tableWidget_2->rowCount(); + ui->tableWidget_2->insertRow(rowCount); + ui->tableWidget_2->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget_2->setItem(row, 1, new QTableWidgetItem(item.remark)); + QTableWidgetItem *itemRow; + if(item.sync_type=="0"){ + itemRow = new QTableWidgetItem("未同步"); + itemRow->setBackground(QBrush(QColor(255, 255, 192))); + }else if (item.sync_type=="1") + { + itemRow = new QTableWidgetItem("同步成功"); + itemRow->setBackground(QBrush(QColor(173, 255, 47))); // 浅绿色 + }else{ + itemRow = new QTableWidgetItem("同步失败"); + itemRow->setBackground(QBrush(QColor(255, 105, 180))); // 浅红色 + } + itemRow->setTextAlignment(Qt::AlignCenter); + ui->tableWidget_2->setItem(row, 2, itemRow); + + row++; + } +} + +void DataSyncView::on_button_return_clicked() +{ + ui->stackedWidget->setCurrentIndex(0); } diff --git a/softwareDirectory/AutoVerScheme/datasyncview.h b/softwareDirectory/AutoVerScheme/datasyncview.h index 174480e..b2b9847 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.h +++ b/softwareDirectory/AutoVerScheme/datasyncview.h @@ -2,6 +2,16 @@ #define DATASYNCVIEW_H #include +#include +#include "synctask.h" +#include "databaseconnection.h" +#include "basecommonapi.h" +#include "databaseconnectionmainsys.h" +#include +#include +#include +#include +#include namespace Ui { class DataSyncView; @@ -18,8 +28,12 @@ void initForm(); //初始化界面数据 void on_DownloadDataButton_clicked(); - //异步更新 - void syncTable(); + void OnButtonSelectClicked(zdLog log); + void on_button_return_clicked(); + +public: + + private: Ui::DataSyncView *ui; }; diff --git a/softwareDirectory/AutoVerScheme/datasyncview.ui b/softwareDirectory/AutoVerScheme/datasyncview.ui index 53c379c..7c9df8e 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.ui +++ b/softwareDirectory/AutoVerScheme/datasyncview.ui @@ -14,21 +14,9 @@ 数据同步 - background-color:rgba(240, 240, 240, 1); + background-color:white; - - - 0 - - - 0 - - - 0 - - - 0 - + @@ -73,119 +61,173 @@ - - - background-color:white; - - - - - - - 3 - - - - - - 0 - 0 - - - - background-color:white; + + + + + + + background-color:white; + + + + + + + 3 + + + + + + 0 + 0 + + + + background-color:white; border:0; - - - - - - - - - - 0 - 0 - - - - font:bold 20px Arial, sans-serif; + + + + + + + + + + 0 + 0 + + + + font:bold 20px Arial, sans-serif; color:#334582; - - - 同步记录 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - background-color:#334582; + + + 同步记录 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + background-color:#334582; font: bold 18px Arial, sans-serif; color:white; padding:10px; - - - 下载数据 - - - - - - - - 200 - 0 - - - - - 100 - 40 - - - - Qt::RightToLeft - - - background-color:#334582; + + + 下载数据 + + + + + + + + 200 + 0 + + + + + 100 + 40 + + + + Qt::RightToLeft + + + background-color:#334582; font: bold 18px Arial, sans-serif; color:white; padding:10px; - - - 发送同步请求 - - - - :/image/Index/u8458.svg:/image/Index/u8458.svg - - - - - - - - - - - - - - + + + 发送同步请求 + + + + :/image/Index/u8458.svg:/image/Index/u8458.svg + + + + + + + + + + + + + + + + + + + + + + + + background-color:white; + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + color:black; + + + 返回 + + + + + + + + + + + + + diff --git a/softwareDirectory/AutoVerScheme/depar_task.cpp b/softwareDirectory/AutoVerScheme/depar_task.cpp index d551972..d58cf35 100644 --- a/softwareDirectory/AutoVerScheme/depar_task.cpp +++ b/softwareDirectory/AutoVerScheme/depar_task.cpp @@ -113,6 +113,7 @@ else State="否"; ui->tableWidget->setItem(row, 9, new QTableWidgetItem(State)); //设置数据 + SetHomePaheCombox(dept); //添加 PageData数据 TempData.append(QString::number(row+1)); TempData.append(dept.sample_name); @@ -133,9 +134,9 @@ //设置分页控件 // 创建分页表格控件 - PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); +// PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); //data转换位QList> - pagedTable->setData(PageData, 20,ui->tableWidget); // 每页20行 + // pagedTable->setData(PageData, 20,ui->tableWidget); // 每页20行 } void Depar_Task::on_SelectButton_clicked() @@ -155,26 +156,31 @@ if(dept.measure_status=="3" || dept.measure_status=="4"){ bool shouldAddRow = true; // 初始假设应该添加这一行 // 根据设备名称筛选 + QString names; if (ui->name->currentText() != "ALL") { + names=ui->name->currentText(); if (ui->name->currentText() != dept.sample_name) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } if (ui->mode->currentText() != "ALL") { + names=ui->mode->currentText(); if (ui->mode->currentText() != dept.sample_model) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } if (ui->customer->currentText() != "ALL") { + if (ui->customer->currentText() != dept.customer_name) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } - if (ui->dept->currentText() != "") { + if (ui->dept->currentText() != "ALL") { if (ui->dept->currentText() != dept.FULL_NAME) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); ui->tableWidget->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); @@ -193,9 +199,10 @@ State="否"; ui->tableWidget->setItem(row, 9, new QTableWidgetItem(State)); //设置数据 // - SetHomePaheCombox(dept); + //QDebug row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/indexwindow.cpp b/softwareDirectory/AutoVerScheme/indexwindow.cpp index eed192a..060b86e 100644 --- a/softwareDirectory/AutoVerScheme/indexwindow.cpp +++ b/softwareDirectory/AutoVerScheme/indexwindow.cpp @@ -58,7 +58,7 @@ DatabaseConnection *Conn=DatabaseConnection::getInstance(); //数据库连接 目前先放这里 后续需要放到登录界面 - bool IsOpen=Conn->open(); + bool IsOpen=Conn->open(); if(IsOpen) ShowMessageBox("数据库连接","连接成功"); else diff --git a/softwareDirectory/AutoVerScheme/my_task.cpp b/softwareDirectory/AutoVerScheme/my_task.cpp index 1735575..cd735f8 100644 --- a/softwareDirectory/AutoVerScheme/my_task.cpp +++ b/softwareDirectory/AutoVerScheme/my_task.cpp @@ -62,7 +62,8 @@ } void My_Task::Load() { - QList> PageData; + + //QList> PageData; //先设置为行为0 ui->tableWidget->setRowCount(0); //添加comboBox @@ -86,11 +87,29 @@ QString userId=""; data = BaseCommonApi::getMyTasks(userId,"3"); + QString State; + //设置单页显示数量 + page=20; + // 创建分页表格控件 + PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); + pagedTable->setData(data.count(), page); // 每页10行 + connect(pagedTable, &PagedTableWidget::pageChanged, this,&My_Task::onpageChanged); + this->onpageChanged(0); + +} +void My_Task::onpageChanged(int currPage){ + currPage+=1; + // 计算当前页的开始和结束索引 + int start = (currPage - 1) * page; + int end = std::min(start + page, data.size()); + // 从 QList 中筛选出当前页的数据 + QList tempdate = data.mid(start, end - start); int rowCount = 0; int row=0; QString State; - for (const MyTask& myTask : data) { - if(myTask.measure_status=="3" || myTask.measure_status=="4"){ + ui->tableWidget->setRowCount(0); + for (const MyTask& myTask : tempdate) { + QList TempData; rowCount = ui->tableWidget->rowCount(); @@ -118,42 +137,15 @@ ui->tableWidget->setItem(row, 10,new QTableWidgetItem("检测完成")); } - //渲染下拉框 - SetHomePaheCombox(myTask); - //QDebug - - //添加 PageData数据 - TempData.append(QString::number(row+1)); - TempData.append(myTask.sample_name); - TempData.append(myTask.sample_model); - TempData.append(myTask.help_instruction); - TempData.append(myTask.manufacture_no); - TempData.append(myTask.manufacturer); - TempData.append(myTask.customer_name); - TempData.append(myTask.FULL_NAME); - TempData.append(myTask.require_over_time.toString()); - TempData.append(State); - TempData.append(myTask.measure_status); - PageData.append(TempData); + //渲染下拉框 + SetHomePaheCombox(myTask); row++; - } - - } - //设置分页控件 - // 创建分页表格控件 - - PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); - //data转换位QList> - pagedTable->setData(PageData, 20,ui->tableWidget); // 每页10行 - //ui->HBoxPageLayout->addWidget(pagedTable); - //setLayout(ui->HBoxPageLayout); - // 连接信号以处理页码变化 - /* connect(pagedTable, &PagedTableWidget::pageChanged, this, [=](int page) { - // 在这里处理页码变化事件,比如更新UI中的其他部分 - qDebug() << "Page changed to:" << page; - });*/ + }; + //按钮点击事件 + // QMessageBox::information(this, "点击按钮",QString::number(page)); + // qDebug() << "Page changed to:" << page; } void My_Task::SetHomePaheCombox(MyTask entity) { diff --git a/softwareDirectory/AutoVerScheme/my_task.h b/softwareDirectory/AutoVerScheme/my_task.h index 289e7f4..8a4ad07 100644 --- a/softwareDirectory/AutoVerScheme/my_task.h +++ b/softwareDirectory/AutoVerScheme/my_task.h @@ -26,9 +26,11 @@ void on_pushButtonUpdate_clicked(); void on_SeachButton_clicked(); + void onpageChanged(int page); public: QList data; - + int page; + int totalcount; private: Ui::My_Task *ui; }; diff --git a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro index bf70fab..d9a99ea 100644 --- a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro +++ b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro @@ -35,6 +35,7 @@ create_task.cpp \ createtask_scandevice.cpp \ databaseconnection.cpp \ + databaseconnectionmainsys.cpp \ datasyncview.cpp \ depar_task.cpp \ depar_task_server.cpp \ @@ -55,6 +56,7 @@ newverifymethod.cpp \ rulefileitem.cpp \ standard_deviceitem.cpp \ + syncdialog.cpp \ synctask.cpp \ testdataitem.cpp \ testview.cpp \ @@ -69,6 +71,7 @@ DataProcessingBLL.h \ PageControl.h \ createtask_scandevice.h \ + databaseconnectionmainsys.h \ formaddrsetting.h \ formcommsetting.h \ id/IdWorker.h \ @@ -104,6 +107,7 @@ newverifymethod.h \ rulefileitem.h \ standard_deviceitem.h \ + syncdialog.h \ synctask.h \ testdataitem.h \ testview.h \ @@ -138,6 +142,7 @@ newverifymethod.ui \ rulefileitem.ui \ standard_deviceitem.ui \ + syncdialog.ui \ testdataitem.ui \ testview.ui \ verifydevice.ui \ diff --git a/softwareDirectory/AutoVerScheme/PageControl.cpp b/softwareDirectory/AutoVerScheme/PageControl.cpp index d0fd72b..d1bdddc 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.cpp +++ b/softwareDirectory/AutoVerScheme/PageControl.cpp @@ -22,14 +22,14 @@ } } -void PagedTableWidget::setData(const QList> &data, int rowsPerPage,QTableWidget *table) { - tableWidget=table; - +void PagedTableWidget::setData(int datacount, int rowsPerPage) { + //tableWidget=table; + totaldatacount=datacount; this->rowsPerPage = rowsPerPage; - allData = data; + //allData = data; currentPage = 0; createPageButtons(); - updateTable(); + //updateTable(); } void PagedTableWidget::setCurrentPage(int page) { @@ -39,7 +39,7 @@ button->setChecked(false); }*/ currentPage = page; - updateTable(); + //updateTable(); emit pageChanged(page); } } @@ -89,6 +89,7 @@ setCurrentPage(pageIndex); } } +/* void PagedTableWidget::updateTable() { //tableWidget->clear(); tableWidget->setRowCount(0); @@ -105,7 +106,7 @@ } } } - +*/ void PagedTableWidget::createPageButtons() { int totalPages = calculateTotalPages(); for (auto button : pageButtons) { @@ -150,5 +151,5 @@ } int PagedTableWidget::calculateTotalPages() { - return ((allData.count() + rowsPerPage -1) / rowsPerPage); + return ((totaldatacount + rowsPerPage -1) / rowsPerPage); } diff --git a/softwareDirectory/AutoVerScheme/PageControl.h b/softwareDirectory/AutoVerScheme/PageControl.h index 74ed1ce..2224760 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.h +++ b/softwareDirectory/AutoVerScheme/PageControl.h @@ -15,7 +15,7 @@ explicit PagedTableWidget(QWidget *parent = nullptr,QHBoxLayout *PageLayout=NULL); ~PagedTableWidget(); - void setData(const QList> &data, int rowsPerPage = 10,QTableWidget *table=NULL); + void setData(int datacount, int rowsPerPage = 10); void setCurrentPage(int page); signals: @@ -30,6 +30,7 @@ QHBoxLayout *pageLayout; QList pageButtons; QList> allData; + int totaldatacount; int rowsPerPage; int currentPage; diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.cpp b/softwareDirectory/AutoVerScheme/basecommonapi.cpp index 49cbd7e..6f6fe94 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.cpp +++ b/softwareDirectory/AutoVerScheme/basecommonapi.cpp @@ -13,7 +13,7 @@ } const QString BaseCommonApi::temporary_user_id="1634107227953819649"; const QString BaseCommonApi::measure_person_id="1695282436182188034"; - +static SyncRunStatus syncstate=SyncRunStatus::Stopped; //sys_user表的id转换为measure_person_id 检定人id(meter_staff表id) @@ -167,7 +167,8 @@ "JOIN eqpt_equipment_info eei ON eei.id = blei.sample_id " "JOIN biz_business_order_info bo ON bo.id = blei.order_id " "LEFT JOIN sys_dept sd ON blei.measure_dept_id = sd.ID " - " WHERE blei.measure_person_id = :person_id " + " WHERE blei.measure_person_id = :person_id " + " AND blei.measure_status =3 or blei.measure_status = 4 " " ORDER BY blei.update_time DESC"); // 将参数绑定到占位符 @@ -175,7 +176,8 @@ //query.bindValue(":status", status); if (query.exec()) { while (query.next()) { - MyTask task; + + MyTask task; task.id = query.value("id").toString(); task.sample_name = query.value("sampleName").toString(); task.sample_model = query.value("sampleModel").toString(); @@ -2872,9 +2874,40 @@ return result; } +//保存log信息 +//log文件 + bool BaseCommonApi::SaveLogInfo(QString path,QString Info) +{ + QByteArray utf8Dat; + QString Message=Info; + QFile file(path); + // 如果目录不存在,则创建目录 + // 获取文件所在的目录 + QDir logDir = QDir(QFileInfo(path).absolutePath()); + if (!logDir.exists()) { + if (!logDir.mkpath(".")) { + qDebug() << "Failed to create log directory:" << logDir.absolutePath(); + return false; + } + } + + if (!file.open(QIODevice::Append | QIODevice::Text)) { + qDebug() << "无法打开文件:" << file.errorString(); + return false; + } + QTextStream out(&file); + utf8Dat = Message.toUtf8(); + out << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss") + << "\t" << utf8Dat << "\n"; + file.close(); + return true; + } + + //新增日志表数据 bool BaseCommonApi::InsertzdLog(zdLog log) { + log.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_log(id,is_sync,sync_time,remark,userid,type,create_time,update_time) " " VALUES(:id,:is_sync,:sync_time,:remark,:userid,:type,:create_time,:update_time) "); @@ -2898,6 +2931,7 @@ //根据userid查询日志表数据 QList BaseCommonApi::getzdLogByuserId(QString userid) { + userid=temporary_user_id; QList result; QSqlQuery query; query.prepare("SELECT * FROM zd_log WHERE userid = :userid "); @@ -2922,6 +2956,7 @@ //新增数据同步表 bool BaseCommonApi::InsertzdDataSync(zdDataSync data) { + data.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_data_sync(id,type,ssql,userid,remark,create_time,update_time,log_sync_id,sync_type) " " VALUES " @@ -2945,12 +2980,12 @@ return isSuccess; } //根据userid查询数据同步表 -QList getzdDataSyncByuserId(QString userid) +QList BaseCommonApi::getzdDataSyncByuserId(QString log_sync_id) { QList result; QSqlQuery query; - query.prepare("SELECT * FROM zd_data_sync WHERE userid= :userid "); - query.bindValue(":userid",userid); + query.prepare("SELECT * FROM zd_data_sync WHERE log_sync_id= :log_sync_id "); + query.bindValue(":log_sync_id",log_sync_id); if (query.exec()) { while (query.next()) { zdDataSync data; @@ -2972,3 +3007,4 @@ } + diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.h b/softwareDirectory/AutoVerScheme/basecommonapi.h index 12196fb..4949683 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.h +++ b/softwareDirectory/AutoVerScheme/basecommonapi.h @@ -919,6 +919,7 @@ QDateTime create_time; QDateTime update_time; }; + //数据同步-数据表 class zdDataSync { @@ -935,6 +936,12 @@ }; +enum class SyncRunStatus { + + Running, + Stopped, + Paused +}; using namespace Jiawa::Core; class BaseCommonApi @@ -945,7 +952,6 @@ const static QString temporary_costomer_id; const static QString measure_person_id; - QString encrypt(const QString &str, const QString &publicKey); //判断检定装置表并查询 参数设备id @@ -1137,14 +1143,19 @@ //单独查询任务单表 //更新 任务单 static InsertTask SelectTaskSingle(QString order_id); + + //log文件 + static bool SaveLogInfo(QString path,QString Info); + //新增日志表数据 static bool InsertzdLog(zdLog log); //查询日志表数据 static QList getzdLogByuserId(QString userid); //新增数据同步表 static bool InsertzdDataSync(zdDataSync data); - //根据userid查询数据同步表 - static QList getzdDataSyncByuserId(QString userid); + //根据log_sync_id查询数据同步表 + static QList getzdDataSyncByuserId(QString log_sync_id); + }; diff --git a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp index 00d746b..ae60962 100644 --- a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp @@ -352,6 +352,7 @@ } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -395,6 +396,7 @@ row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.cpp b/softwareDirectory/AutoVerScheme/databaseconnection.cpp index 1d957d9..5284fe6 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.cpp +++ b/softwareDirectory/AutoVerScheme/databaseconnection.cpp @@ -10,17 +10,21 @@ { // 连接数据库 - db = QSqlDatabase::addDatabase("QODBC"); - /*db.setHostName("111.198.10.15"); - db.setDatabaseName("casic_metering_xichang"); - db.setPort(21906); - db.setUserName("zdjdcs"); - db.setPassword("11111111");*/ - db.setHostName("localhost"); - db.setDatabaseName("zdjd"); - db.setPort(3306); - db.setUserName("root"); - db.setPassword("123456"); + localdb = QSqlDatabase::addDatabase("QODBC"); + + localdb.setHostName("localhost"); + localdb.setDatabaseName("zdjd"); + localdb.setPort(3306); + localdb.setUserName("root"); + localdb.setPassword("123456"); + + Maindb = QSqlDatabase::addDatabase("QODBC","Main"); + Maindb.setHostName("111.198.10.15"); + Maindb.setDatabaseName("casic_metering_xichang"); + Maindb.setPort(21906); + Maindb.setUserName("zdjdcs"); + Maindb.setPassword("11111111"); + } @@ -29,18 +33,28 @@ close(); } bool DatabaseConnection::open() { - return db.open(); + return localdb.open(); +} +bool DatabaseConnection::openmain() { + return Maindb.open(); } bool DatabaseConnection::isopen() { - return db.isOpen(); + return localdb.isOpen(); } - +bool DatabaseConnection::isopenmain() { + return Maindb.isOpen(); +} void DatabaseConnection::close() { - db.close(); + localdb.close(); } - +void DatabaseConnection::closemain() { + Maindb.close(); +} QSqlDatabase& DatabaseConnection::getDatabase() { - return db; + return localdb; +} +QSqlDatabase& DatabaseConnection::getDatabaseMain() { + return Maindb; } DatabaseConnection* DatabaseConnection::getInstance() { diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.h b/softwareDirectory/AutoVerScheme/databaseconnection.h index 586b794..5f9810b 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.h +++ b/softwareDirectory/AutoVerScheme/databaseconnection.h @@ -16,8 +16,12 @@ ~DatabaseConnection(); bool open(); bool isopen(); + bool openmain(); void close(); + void closemain(); + bool isopenmain(); QSqlDatabase& getDatabase(); + QSqlDatabase& getDatabaseMain(); private: //单列模式 保证DatabaseConnection的唯一性 static DatabaseConnection* Connect; @@ -33,7 +37,8 @@ //如果尝试这样做,编译器同样会报错。 DatabaseConnection& operator=(const DatabaseConnection&) = delete; //数据库db类 - QSqlDatabase db; + QSqlDatabase Maindb; + QSqlDatabase localdb; }; #endif // DATABASECONNECTION_H diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp new file mode 100644 index 0000000..080288b --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp @@ -0,0 +1,54 @@ +#include "databaseconnectionmainsys.h" + + + + +DatabaseConnectionMainSys* DatabaseConnectionMainSys::Connect = nullptr; +QMutex DatabaseConnectionMainSys::mutex; + +DatabaseConnectionMainSys::DatabaseConnectionMainSys() +{ + + // 连接数据库 + dbmain = QSqlDatabase::addDatabase("QODBC"); + dbmain.setHostName("111.198.10.15"); + dbmain.setDatabaseName("casic_metering_xichang"); + dbmain.setPort(21906); + dbmain.setUserName("zdjdcs"); + dbmain.setPassword("11111111"); + /* db.setHostName("localhost"); + db.setDatabaseName("zdjd"); + db.setPort(3306); + db.setUserName("root"); + db.setPassword("123456");*/ + + +} +DatabaseConnectionMainSys::~DatabaseConnectionMainSys() { + // 在析构函数中关闭数据库连接 + close(); +} +bool DatabaseConnectionMainSys::open() { + return dbmain.open(); +} +bool DatabaseConnectionMainSys::isopen() { + return dbmain.isOpen(); +} + +void DatabaseConnectionMainSys::close() { + dbmain.close(); +} + +QSqlDatabase& DatabaseConnectionMainSys::getDatabase() { + return dbmain; +} +DatabaseConnectionMainSys* DatabaseConnectionMainSys::getInstance() +{ + if (!Connect) { + QMutexLocker locker(&mutex); + if (!Connect) { + Connect = new DatabaseConnectionMainSys(); + } + } + return Connect; +} diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h new file mode 100644 index 0000000..57702ad --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h @@ -0,0 +1,41 @@ +#ifndef DATABASECONNECTIONMAINSYS_H +#define DATABASECONNECTIONMAINSYS_H +#include +#include +#include +#include + + +class DatabaseConnectionMainSys +{ + + +public: + //获取数据库实例 + static DatabaseConnectionMainSys* getInstance(); + + DatabaseConnectionMainSys(); + ~DatabaseConnectionMainSys(); + bool open(); + bool isopen(); + void close(); + QSqlDatabase& getDatabase(); +private: + //单列模式 保证MainSysDatabaseConnection的唯一性 + static DatabaseConnectionMainSys* Connect; + //QMutex 来确保在多线程环境下单例的正确创建。 + static QMutex mutex; + + //这是拷贝构造函数的声明,后面跟着 = delete; 表示这个构造函数被删除了。 + //这意味着你不能通过拷贝另一个 DatabaseConnection 对象来创建新的 DatabaseConnection 对象。 + //如果尝试这样做,编译器会报错。 + DatabaseConnectionMainSys(const DatabaseConnectionMainSys&) = delete; + //这是拷贝赋值运算符的声明,同样后面跟着 = delete; 表示这个运算符被删除了。 + //这意味着你不能将一个 DatabaseConnection 对象赋值给另一个 DatabaseConnection 对象。 + //如果尝试这样做,编译器同样会报错。 + DatabaseConnectionMainSys& operator=(const DatabaseConnectionMainSys&) = delete; + //数据库db类 + QSqlDatabase dbmain; +}; + +#endif // DATABASECONNECTIONMAINSYS_H diff --git a/softwareDirectory/AutoVerScheme/datasyncview.cpp b/softwareDirectory/AutoVerScheme/datasyncview.cpp index fbf4508..06c7f9a 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.cpp +++ b/softwareDirectory/AutoVerScheme/datasyncview.cpp @@ -1,11 +1,10 @@ #include "datasyncview.h" #include "ui_datasyncview.h" -#include "synctask.h" -#include "databaseconnection.h" -#include "mainsysdatabaseconnection.h" +#include "syncdialog.h" - +QString filePath = "C:\\AutoVerScheme\\sync_info.txt"; +// 获取当前时间戳 DataSyncView::DataSyncView(QWidget *parent) : QWidget(parent), ui(new Ui::DataSyncView) @@ -20,7 +19,7 @@ } void DataSyncView::initForm() { - //tableWidget设置 + ui->stackedWidget->setCurrentIndex(0); //设置控件的边框显示 ui->tableWidget->setStyleSheet("QHeaderView::section {" "border: 1px solid grey;" @@ -32,29 +31,129 @@ "}"); ui->tableWidget->setRowCount(10); // 设置10行 - ui->tableWidget->setColumnCount(4); // 设置11列 - ui->tableWidget->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnCount(7); // 设置11列 + ui->tableWidget->setColumnWidth(0, 0); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnWidth(2, 200); // 设置第一列的宽度为100像素 ui->tableWidget->verticalHeader()->setParent(nullptr); //隐藏行头 - QTableWidgetItem *item = new QTableWidgetItem("测试数据"); - item->setTextAlignment(Qt::AlignCenter); - ui->tableWidget->setItem(0, 0, item); //设置数据 + + //初始化TableWidget 设置列 QStringList headers; - headers << "序号" << "同步时间" << "是否同步成功" << "备注" ; + headers <<"id" << "序号" << "同步时间" << "是否同步成功" << "备注" + <<"类型" <<"操作"; ui->tableWidget->setHorizontalHeaderLabels(headers); + //详情内 + + //设置控件的边框显示 + ui->tableWidget_2->setStyleSheet("QHeaderView::section {" + "border: 1px solid grey;" + "border-left:none;" + "border-top:none;" + "background-color:white;" + " color:black;" + "font: bold 18px Arial, sans-serif;" + "}"); + + ui->tableWidget_2->setRowCount(10); // 设置10行 + ui->tableWidget_2->setColumnCount(3); // 设置11列 + ui->tableWidget_2->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget_2->verticalHeader()->setParent(nullptr); //隐藏行头 + ui->tableWidget_2->setColumnWidth(1, 1000); // 设置第一列的宽度为100像素 + + //初始化TableWidget 设置列 + + headers << "序号" << "信息" << "状态" ; + ui->tableWidget_2->setHorizontalHeaderLabels(headers); + + //数据显示 + + //先设置为行为0 + ui->tableWidget->setRowCount(0); + int rowCount=0; + int row=0; + QList zdlog= BaseCommonApi::getzdLogByuserId(""); + for(const zdLog & zd:zdlog) + { + rowCount = ui->tableWidget->rowCount(); + ui->tableWidget->insertRow(rowCount); + ui->tableWidget->setItem(row, 0, new QTableWidgetItem(zd.id)); + ui->tableWidget->setItem(row, 1, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget->setItem(row, 2, new QTableWidgetItem(zd.sync_time.toString())); + ui->tableWidget->setItem(row, 3, new QTableWidgetItem(zd.is_sync)); + ui->tableWidget->setItem(row, 4, new QTableWidgetItem(zd.remark)); + if(zd.type=="1") + { + ui->tableWidget->setItem(row, 5, new QTableWidgetItem("下载")); + }else{ ui->tableWidget->setItem(row, 5, new QTableWidgetItem("上传")); } + + //添加操作按钮 + QPushButton *button = new QPushButton("查询信息"); + button->setIconSize(QSize(16,16)); + button->setIcon(QIcon(":/image/Index/u2327.svg")); + ui->tableWidget->setCellWidget(row, 6, button); + //设置按钮简单样式 + button->setStyleSheet("QPushButton {" + " border: none; /* 无边框 */" + " color: green; /* 文本颜色 */" + " text-decoration: underline; /* 文本下划线 */" + "}"); + + // 设置鼠标悬停时的光标样式为小手图标 + button->setCursor(Qt::PointingHandCursor); + // 连接按钮的 clicked 信号到自定义槽函数 + connect(button, &QPushButton::clicked, this, [this, button, zd]() { + // 获取当前行第一列的 ID + + OnButtonSelectClicked(zd); + + }); + row++; + } } void DataSyncView::on_DownloadDataButton_clicked() { - //从主系统下载 + + SyncDialog *syncDialog = new SyncDialog(this); + syncDialog->exec(); // 显示进度条窗体并阻塞主窗口 + + this->initForm(); + } -void DataSyncView::syncTable() +void DataSyncView::OnButtonSelectClicked(zdLog log) { - //连接两个数据库 - bool IsOpen=false; - DatabaseConnection *Conn=DatabaseConnection::getInstance(); - IsOpen=Conn->open(); - //MainSysDatabaseConnection *MainConn=MainSysDatabaseConnection::getInstance(); - //IsOpen=MainConn->open(); + ui->stackedWidget->setCurrentIndex(1); + ui->tableWidget_2->setRowCount(0); + int rowCount=0; + int row=0; + QList data= BaseCommonApi::getzdDataSyncByuserId(log.id); + for(const zdDataSync & item:data) + { + rowCount = ui->tableWidget_2->rowCount(); + ui->tableWidget_2->insertRow(rowCount); + ui->tableWidget_2->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget_2->setItem(row, 1, new QTableWidgetItem(item.remark)); + QTableWidgetItem *itemRow; + if(item.sync_type=="0"){ + itemRow = new QTableWidgetItem("未同步"); + itemRow->setBackground(QBrush(QColor(255, 255, 192))); + }else if (item.sync_type=="1") + { + itemRow = new QTableWidgetItem("同步成功"); + itemRow->setBackground(QBrush(QColor(173, 255, 47))); // 浅绿色 + }else{ + itemRow = new QTableWidgetItem("同步失败"); + itemRow->setBackground(QBrush(QColor(255, 105, 180))); // 浅红色 + } + itemRow->setTextAlignment(Qt::AlignCenter); + ui->tableWidget_2->setItem(row, 2, itemRow); + + row++; + } +} + +void DataSyncView::on_button_return_clicked() +{ + ui->stackedWidget->setCurrentIndex(0); } diff --git a/softwareDirectory/AutoVerScheme/datasyncview.h b/softwareDirectory/AutoVerScheme/datasyncview.h index 174480e..b2b9847 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.h +++ b/softwareDirectory/AutoVerScheme/datasyncview.h @@ -2,6 +2,16 @@ #define DATASYNCVIEW_H #include +#include +#include "synctask.h" +#include "databaseconnection.h" +#include "basecommonapi.h" +#include "databaseconnectionmainsys.h" +#include +#include +#include +#include +#include namespace Ui { class DataSyncView; @@ -18,8 +28,12 @@ void initForm(); //初始化界面数据 void on_DownloadDataButton_clicked(); - //异步更新 - void syncTable(); + void OnButtonSelectClicked(zdLog log); + void on_button_return_clicked(); + +public: + + private: Ui::DataSyncView *ui; }; diff --git a/softwareDirectory/AutoVerScheme/datasyncview.ui b/softwareDirectory/AutoVerScheme/datasyncview.ui index 53c379c..7c9df8e 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.ui +++ b/softwareDirectory/AutoVerScheme/datasyncview.ui @@ -14,21 +14,9 @@ 数据同步 - background-color:rgba(240, 240, 240, 1); + background-color:white; - - - 0 - - - 0 - - - 0 - - - 0 - + @@ -73,119 +61,173 @@ - - - background-color:white; - - - - - - - 3 - - - - - - 0 - 0 - - - - background-color:white; + + + + + + + background-color:white; + + + + + + + 3 + + + + + + 0 + 0 + + + + background-color:white; border:0; - - - - - - - - - - 0 - 0 - - - - font:bold 20px Arial, sans-serif; + + + + + + + + + + 0 + 0 + + + + font:bold 20px Arial, sans-serif; color:#334582; - - - 同步记录 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - background-color:#334582; + + + 同步记录 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + background-color:#334582; font: bold 18px Arial, sans-serif; color:white; padding:10px; - - - 下载数据 - - - - - - - - 200 - 0 - - - - - 100 - 40 - - - - Qt::RightToLeft - - - background-color:#334582; + + + 下载数据 + + + + + + + + 200 + 0 + + + + + 100 + 40 + + + + Qt::RightToLeft + + + background-color:#334582; font: bold 18px Arial, sans-serif; color:white; padding:10px; - - - 发送同步请求 - - - - :/image/Index/u8458.svg:/image/Index/u8458.svg - - - - - - - - - - - - - - + + + 发送同步请求 + + + + :/image/Index/u8458.svg:/image/Index/u8458.svg + + + + + + + + + + + + + + + + + + + + + + + + background-color:white; + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + color:black; + + + 返回 + + + + + + + + + + + + + diff --git a/softwareDirectory/AutoVerScheme/depar_task.cpp b/softwareDirectory/AutoVerScheme/depar_task.cpp index d551972..d58cf35 100644 --- a/softwareDirectory/AutoVerScheme/depar_task.cpp +++ b/softwareDirectory/AutoVerScheme/depar_task.cpp @@ -113,6 +113,7 @@ else State="否"; ui->tableWidget->setItem(row, 9, new QTableWidgetItem(State)); //设置数据 + SetHomePaheCombox(dept); //添加 PageData数据 TempData.append(QString::number(row+1)); TempData.append(dept.sample_name); @@ -133,9 +134,9 @@ //设置分页控件 // 创建分页表格控件 - PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); +// PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); //data转换位QList> - pagedTable->setData(PageData, 20,ui->tableWidget); // 每页20行 + // pagedTable->setData(PageData, 20,ui->tableWidget); // 每页20行 } void Depar_Task::on_SelectButton_clicked() @@ -155,26 +156,31 @@ if(dept.measure_status=="3" || dept.measure_status=="4"){ bool shouldAddRow = true; // 初始假设应该添加这一行 // 根据设备名称筛选 + QString names; if (ui->name->currentText() != "ALL") { + names=ui->name->currentText(); if (ui->name->currentText() != dept.sample_name) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } if (ui->mode->currentText() != "ALL") { + names=ui->mode->currentText(); if (ui->mode->currentText() != dept.sample_model) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } if (ui->customer->currentText() != "ALL") { + if (ui->customer->currentText() != dept.customer_name) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } - if (ui->dept->currentText() != "") { + if (ui->dept->currentText() != "ALL") { if (ui->dept->currentText() != dept.FULL_NAME) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); ui->tableWidget->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); @@ -193,9 +199,10 @@ State="否"; ui->tableWidget->setItem(row, 9, new QTableWidgetItem(State)); //设置数据 // - SetHomePaheCombox(dept); + //QDebug row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/indexwindow.cpp b/softwareDirectory/AutoVerScheme/indexwindow.cpp index eed192a..060b86e 100644 --- a/softwareDirectory/AutoVerScheme/indexwindow.cpp +++ b/softwareDirectory/AutoVerScheme/indexwindow.cpp @@ -58,7 +58,7 @@ DatabaseConnection *Conn=DatabaseConnection::getInstance(); //数据库连接 目前先放这里 后续需要放到登录界面 - bool IsOpen=Conn->open(); + bool IsOpen=Conn->open(); if(IsOpen) ShowMessageBox("数据库连接","连接成功"); else diff --git a/softwareDirectory/AutoVerScheme/my_task.cpp b/softwareDirectory/AutoVerScheme/my_task.cpp index 1735575..cd735f8 100644 --- a/softwareDirectory/AutoVerScheme/my_task.cpp +++ b/softwareDirectory/AutoVerScheme/my_task.cpp @@ -62,7 +62,8 @@ } void My_Task::Load() { - QList> PageData; + + //QList> PageData; //先设置为行为0 ui->tableWidget->setRowCount(0); //添加comboBox @@ -86,11 +87,29 @@ QString userId=""; data = BaseCommonApi::getMyTasks(userId,"3"); + QString State; + //设置单页显示数量 + page=20; + // 创建分页表格控件 + PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); + pagedTable->setData(data.count(), page); // 每页10行 + connect(pagedTable, &PagedTableWidget::pageChanged, this,&My_Task::onpageChanged); + this->onpageChanged(0); + +} +void My_Task::onpageChanged(int currPage){ + currPage+=1; + // 计算当前页的开始和结束索引 + int start = (currPage - 1) * page; + int end = std::min(start + page, data.size()); + // 从 QList 中筛选出当前页的数据 + QList tempdate = data.mid(start, end - start); int rowCount = 0; int row=0; QString State; - for (const MyTask& myTask : data) { - if(myTask.measure_status=="3" || myTask.measure_status=="4"){ + ui->tableWidget->setRowCount(0); + for (const MyTask& myTask : tempdate) { + QList TempData; rowCount = ui->tableWidget->rowCount(); @@ -118,42 +137,15 @@ ui->tableWidget->setItem(row, 10,new QTableWidgetItem("检测完成")); } - //渲染下拉框 - SetHomePaheCombox(myTask); - //QDebug - - //添加 PageData数据 - TempData.append(QString::number(row+1)); - TempData.append(myTask.sample_name); - TempData.append(myTask.sample_model); - TempData.append(myTask.help_instruction); - TempData.append(myTask.manufacture_no); - TempData.append(myTask.manufacturer); - TempData.append(myTask.customer_name); - TempData.append(myTask.FULL_NAME); - TempData.append(myTask.require_over_time.toString()); - TempData.append(State); - TempData.append(myTask.measure_status); - PageData.append(TempData); + //渲染下拉框 + SetHomePaheCombox(myTask); row++; - } - - } - //设置分页控件 - // 创建分页表格控件 - - PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); - //data转换位QList> - pagedTable->setData(PageData, 20,ui->tableWidget); // 每页10行 - //ui->HBoxPageLayout->addWidget(pagedTable); - //setLayout(ui->HBoxPageLayout); - // 连接信号以处理页码变化 - /* connect(pagedTable, &PagedTableWidget::pageChanged, this, [=](int page) { - // 在这里处理页码变化事件,比如更新UI中的其他部分 - qDebug() << "Page changed to:" << page; - });*/ + }; + //按钮点击事件 + // QMessageBox::information(this, "点击按钮",QString::number(page)); + // qDebug() << "Page changed to:" << page; } void My_Task::SetHomePaheCombox(MyTask entity) { diff --git a/softwareDirectory/AutoVerScheme/my_task.h b/softwareDirectory/AutoVerScheme/my_task.h index 289e7f4..8a4ad07 100644 --- a/softwareDirectory/AutoVerScheme/my_task.h +++ b/softwareDirectory/AutoVerScheme/my_task.h @@ -26,9 +26,11 @@ void on_pushButtonUpdate_clicked(); void on_SeachButton_clicked(); + void onpageChanged(int page); public: QList data; - + int page; + int totalcount; private: Ui::My_Task *ui; }; diff --git a/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp b/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp index e9cfb66..3ef9d60 100644 --- a/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp @@ -3,7 +3,7 @@ #include "InfoBase.h" #include "QMessageBox" #include "basecommonapi.h" - +#include "PageControl.h" //标准设备管理 .cpp Standard_DeviceItem::Standard_DeviceItem(QWidget *parent) : @@ -32,7 +32,7 @@ // ui->tableWidget->setRowCount(10); // 设置10行 ui->tableWidget->setColumnCount(7); // 设置11列 - ui->tableWidget->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnWidth(0, 0); // 设置第一列的宽度为100像素 ui->tableWidget->verticalHeader()->setParent(nullptr); //隐藏行头 //QTableWidgetItem *item = new QTableWidgetItem("测试数据"); //item->setTextAlignment(Qt::AlignCenter); @@ -102,12 +102,32 @@ // 调用数据库管理器的函数获取数据 - int rowCount=0; - int row=0; + data = BaseCommonApi::getBizDeviceManage(); + QString State; + //设置单页显示数量 + page=20; + // 创建分页表格控件 + PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); + pagedTable->setData(data.count(), page); // 每页10行 + connect(pagedTable, &PagedTableWidget::pageChanged, this,&Standard_DeviceItem::onpageChanged); + this->onpageChanged(0); - for (const BizDevice& bizDevice : data) { +} +void Standard_DeviceItem::onpageChanged(int currPage){ + + currPage+=1; + // 计算当前页的开始和结束索引 + int start = (currPage - 1) * page; + int end = std::min(start + page, data.size()); + // 从 QList 中筛选出当前页的数据 + QList tempdate = data.mid(start, end - start); + int rowCount = 0; + int row=0; + QString State; + ui->tableWidget->setRowCount(0); + for (const BizDevice& bizDevice : tempdate) { rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -147,8 +167,9 @@ SetHomePaheCombox(bizDevice); row++; } - } + + void Standard_DeviceItem::OnButtonSelectClicked(QString id) { //添加 diff --git a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro index bf70fab..d9a99ea 100644 --- a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro +++ b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro @@ -35,6 +35,7 @@ create_task.cpp \ createtask_scandevice.cpp \ databaseconnection.cpp \ + databaseconnectionmainsys.cpp \ datasyncview.cpp \ depar_task.cpp \ depar_task_server.cpp \ @@ -55,6 +56,7 @@ newverifymethod.cpp \ rulefileitem.cpp \ standard_deviceitem.cpp \ + syncdialog.cpp \ synctask.cpp \ testdataitem.cpp \ testview.cpp \ @@ -69,6 +71,7 @@ DataProcessingBLL.h \ PageControl.h \ createtask_scandevice.h \ + databaseconnectionmainsys.h \ formaddrsetting.h \ formcommsetting.h \ id/IdWorker.h \ @@ -104,6 +107,7 @@ newverifymethod.h \ rulefileitem.h \ standard_deviceitem.h \ + syncdialog.h \ synctask.h \ testdataitem.h \ testview.h \ @@ -138,6 +142,7 @@ newverifymethod.ui \ rulefileitem.ui \ standard_deviceitem.ui \ + syncdialog.ui \ testdataitem.ui \ testview.ui \ verifydevice.ui \ diff --git a/softwareDirectory/AutoVerScheme/PageControl.cpp b/softwareDirectory/AutoVerScheme/PageControl.cpp index d0fd72b..d1bdddc 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.cpp +++ b/softwareDirectory/AutoVerScheme/PageControl.cpp @@ -22,14 +22,14 @@ } } -void PagedTableWidget::setData(const QList> &data, int rowsPerPage,QTableWidget *table) { - tableWidget=table; - +void PagedTableWidget::setData(int datacount, int rowsPerPage) { + //tableWidget=table; + totaldatacount=datacount; this->rowsPerPage = rowsPerPage; - allData = data; + //allData = data; currentPage = 0; createPageButtons(); - updateTable(); + //updateTable(); } void PagedTableWidget::setCurrentPage(int page) { @@ -39,7 +39,7 @@ button->setChecked(false); }*/ currentPage = page; - updateTable(); + //updateTable(); emit pageChanged(page); } } @@ -89,6 +89,7 @@ setCurrentPage(pageIndex); } } +/* void PagedTableWidget::updateTable() { //tableWidget->clear(); tableWidget->setRowCount(0); @@ -105,7 +106,7 @@ } } } - +*/ void PagedTableWidget::createPageButtons() { int totalPages = calculateTotalPages(); for (auto button : pageButtons) { @@ -150,5 +151,5 @@ } int PagedTableWidget::calculateTotalPages() { - return ((allData.count() + rowsPerPage -1) / rowsPerPage); + return ((totaldatacount + rowsPerPage -1) / rowsPerPage); } diff --git a/softwareDirectory/AutoVerScheme/PageControl.h b/softwareDirectory/AutoVerScheme/PageControl.h index 74ed1ce..2224760 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.h +++ b/softwareDirectory/AutoVerScheme/PageControl.h @@ -15,7 +15,7 @@ explicit PagedTableWidget(QWidget *parent = nullptr,QHBoxLayout *PageLayout=NULL); ~PagedTableWidget(); - void setData(const QList> &data, int rowsPerPage = 10,QTableWidget *table=NULL); + void setData(int datacount, int rowsPerPage = 10); void setCurrentPage(int page); signals: @@ -30,6 +30,7 @@ QHBoxLayout *pageLayout; QList pageButtons; QList> allData; + int totaldatacount; int rowsPerPage; int currentPage; diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.cpp b/softwareDirectory/AutoVerScheme/basecommonapi.cpp index 49cbd7e..6f6fe94 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.cpp +++ b/softwareDirectory/AutoVerScheme/basecommonapi.cpp @@ -13,7 +13,7 @@ } const QString BaseCommonApi::temporary_user_id="1634107227953819649"; const QString BaseCommonApi::measure_person_id="1695282436182188034"; - +static SyncRunStatus syncstate=SyncRunStatus::Stopped; //sys_user表的id转换为measure_person_id 检定人id(meter_staff表id) @@ -167,7 +167,8 @@ "JOIN eqpt_equipment_info eei ON eei.id = blei.sample_id " "JOIN biz_business_order_info bo ON bo.id = blei.order_id " "LEFT JOIN sys_dept sd ON blei.measure_dept_id = sd.ID " - " WHERE blei.measure_person_id = :person_id " + " WHERE blei.measure_person_id = :person_id " + " AND blei.measure_status =3 or blei.measure_status = 4 " " ORDER BY blei.update_time DESC"); // 将参数绑定到占位符 @@ -175,7 +176,8 @@ //query.bindValue(":status", status); if (query.exec()) { while (query.next()) { - MyTask task; + + MyTask task; task.id = query.value("id").toString(); task.sample_name = query.value("sampleName").toString(); task.sample_model = query.value("sampleModel").toString(); @@ -2872,9 +2874,40 @@ return result; } +//保存log信息 +//log文件 + bool BaseCommonApi::SaveLogInfo(QString path,QString Info) +{ + QByteArray utf8Dat; + QString Message=Info; + QFile file(path); + // 如果目录不存在,则创建目录 + // 获取文件所在的目录 + QDir logDir = QDir(QFileInfo(path).absolutePath()); + if (!logDir.exists()) { + if (!logDir.mkpath(".")) { + qDebug() << "Failed to create log directory:" << logDir.absolutePath(); + return false; + } + } + + if (!file.open(QIODevice::Append | QIODevice::Text)) { + qDebug() << "无法打开文件:" << file.errorString(); + return false; + } + QTextStream out(&file); + utf8Dat = Message.toUtf8(); + out << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss") + << "\t" << utf8Dat << "\n"; + file.close(); + return true; + } + + //新增日志表数据 bool BaseCommonApi::InsertzdLog(zdLog log) { + log.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_log(id,is_sync,sync_time,remark,userid,type,create_time,update_time) " " VALUES(:id,:is_sync,:sync_time,:remark,:userid,:type,:create_time,:update_time) "); @@ -2898,6 +2931,7 @@ //根据userid查询日志表数据 QList BaseCommonApi::getzdLogByuserId(QString userid) { + userid=temporary_user_id; QList result; QSqlQuery query; query.prepare("SELECT * FROM zd_log WHERE userid = :userid "); @@ -2922,6 +2956,7 @@ //新增数据同步表 bool BaseCommonApi::InsertzdDataSync(zdDataSync data) { + data.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_data_sync(id,type,ssql,userid,remark,create_time,update_time,log_sync_id,sync_type) " " VALUES " @@ -2945,12 +2980,12 @@ return isSuccess; } //根据userid查询数据同步表 -QList getzdDataSyncByuserId(QString userid) +QList BaseCommonApi::getzdDataSyncByuserId(QString log_sync_id) { QList result; QSqlQuery query; - query.prepare("SELECT * FROM zd_data_sync WHERE userid= :userid "); - query.bindValue(":userid",userid); + query.prepare("SELECT * FROM zd_data_sync WHERE log_sync_id= :log_sync_id "); + query.bindValue(":log_sync_id",log_sync_id); if (query.exec()) { while (query.next()) { zdDataSync data; @@ -2972,3 +3007,4 @@ } + diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.h b/softwareDirectory/AutoVerScheme/basecommonapi.h index 12196fb..4949683 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.h +++ b/softwareDirectory/AutoVerScheme/basecommonapi.h @@ -919,6 +919,7 @@ QDateTime create_time; QDateTime update_time; }; + //数据同步-数据表 class zdDataSync { @@ -935,6 +936,12 @@ }; +enum class SyncRunStatus { + + Running, + Stopped, + Paused +}; using namespace Jiawa::Core; class BaseCommonApi @@ -945,7 +952,6 @@ const static QString temporary_costomer_id; const static QString measure_person_id; - QString encrypt(const QString &str, const QString &publicKey); //判断检定装置表并查询 参数设备id @@ -1137,14 +1143,19 @@ //单独查询任务单表 //更新 任务单 static InsertTask SelectTaskSingle(QString order_id); + + //log文件 + static bool SaveLogInfo(QString path,QString Info); + //新增日志表数据 static bool InsertzdLog(zdLog log); //查询日志表数据 static QList getzdLogByuserId(QString userid); //新增数据同步表 static bool InsertzdDataSync(zdDataSync data); - //根据userid查询数据同步表 - static QList getzdDataSyncByuserId(QString userid); + //根据log_sync_id查询数据同步表 + static QList getzdDataSyncByuserId(QString log_sync_id); + }; diff --git a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp index 00d746b..ae60962 100644 --- a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp @@ -352,6 +352,7 @@ } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -395,6 +396,7 @@ row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.cpp b/softwareDirectory/AutoVerScheme/databaseconnection.cpp index 1d957d9..5284fe6 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.cpp +++ b/softwareDirectory/AutoVerScheme/databaseconnection.cpp @@ -10,17 +10,21 @@ { // 连接数据库 - db = QSqlDatabase::addDatabase("QODBC"); - /*db.setHostName("111.198.10.15"); - db.setDatabaseName("casic_metering_xichang"); - db.setPort(21906); - db.setUserName("zdjdcs"); - db.setPassword("11111111");*/ - db.setHostName("localhost"); - db.setDatabaseName("zdjd"); - db.setPort(3306); - db.setUserName("root"); - db.setPassword("123456"); + localdb = QSqlDatabase::addDatabase("QODBC"); + + localdb.setHostName("localhost"); + localdb.setDatabaseName("zdjd"); + localdb.setPort(3306); + localdb.setUserName("root"); + localdb.setPassword("123456"); + + Maindb = QSqlDatabase::addDatabase("QODBC","Main"); + Maindb.setHostName("111.198.10.15"); + Maindb.setDatabaseName("casic_metering_xichang"); + Maindb.setPort(21906); + Maindb.setUserName("zdjdcs"); + Maindb.setPassword("11111111"); + } @@ -29,18 +33,28 @@ close(); } bool DatabaseConnection::open() { - return db.open(); + return localdb.open(); +} +bool DatabaseConnection::openmain() { + return Maindb.open(); } bool DatabaseConnection::isopen() { - return db.isOpen(); + return localdb.isOpen(); } - +bool DatabaseConnection::isopenmain() { + return Maindb.isOpen(); +} void DatabaseConnection::close() { - db.close(); + localdb.close(); } - +void DatabaseConnection::closemain() { + Maindb.close(); +} QSqlDatabase& DatabaseConnection::getDatabase() { - return db; + return localdb; +} +QSqlDatabase& DatabaseConnection::getDatabaseMain() { + return Maindb; } DatabaseConnection* DatabaseConnection::getInstance() { diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.h b/softwareDirectory/AutoVerScheme/databaseconnection.h index 586b794..5f9810b 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.h +++ b/softwareDirectory/AutoVerScheme/databaseconnection.h @@ -16,8 +16,12 @@ ~DatabaseConnection(); bool open(); bool isopen(); + bool openmain(); void close(); + void closemain(); + bool isopenmain(); QSqlDatabase& getDatabase(); + QSqlDatabase& getDatabaseMain(); private: //单列模式 保证DatabaseConnection的唯一性 static DatabaseConnection* Connect; @@ -33,7 +37,8 @@ //如果尝试这样做,编译器同样会报错。 DatabaseConnection& operator=(const DatabaseConnection&) = delete; //数据库db类 - QSqlDatabase db; + QSqlDatabase Maindb; + QSqlDatabase localdb; }; #endif // DATABASECONNECTION_H diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp new file mode 100644 index 0000000..080288b --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp @@ -0,0 +1,54 @@ +#include "databaseconnectionmainsys.h" + + + + +DatabaseConnectionMainSys* DatabaseConnectionMainSys::Connect = nullptr; +QMutex DatabaseConnectionMainSys::mutex; + +DatabaseConnectionMainSys::DatabaseConnectionMainSys() +{ + + // 连接数据库 + dbmain = QSqlDatabase::addDatabase("QODBC"); + dbmain.setHostName("111.198.10.15"); + dbmain.setDatabaseName("casic_metering_xichang"); + dbmain.setPort(21906); + dbmain.setUserName("zdjdcs"); + dbmain.setPassword("11111111"); + /* db.setHostName("localhost"); + db.setDatabaseName("zdjd"); + db.setPort(3306); + db.setUserName("root"); + db.setPassword("123456");*/ + + +} +DatabaseConnectionMainSys::~DatabaseConnectionMainSys() { + // 在析构函数中关闭数据库连接 + close(); +} +bool DatabaseConnectionMainSys::open() { + return dbmain.open(); +} +bool DatabaseConnectionMainSys::isopen() { + return dbmain.isOpen(); +} + +void DatabaseConnectionMainSys::close() { + dbmain.close(); +} + +QSqlDatabase& DatabaseConnectionMainSys::getDatabase() { + return dbmain; +} +DatabaseConnectionMainSys* DatabaseConnectionMainSys::getInstance() +{ + if (!Connect) { + QMutexLocker locker(&mutex); + if (!Connect) { + Connect = new DatabaseConnectionMainSys(); + } + } + return Connect; +} diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h new file mode 100644 index 0000000..57702ad --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h @@ -0,0 +1,41 @@ +#ifndef DATABASECONNECTIONMAINSYS_H +#define DATABASECONNECTIONMAINSYS_H +#include +#include +#include +#include + + +class DatabaseConnectionMainSys +{ + + +public: + //获取数据库实例 + static DatabaseConnectionMainSys* getInstance(); + + DatabaseConnectionMainSys(); + ~DatabaseConnectionMainSys(); + bool open(); + bool isopen(); + void close(); + QSqlDatabase& getDatabase(); +private: + //单列模式 保证MainSysDatabaseConnection的唯一性 + static DatabaseConnectionMainSys* Connect; + //QMutex 来确保在多线程环境下单例的正确创建。 + static QMutex mutex; + + //这是拷贝构造函数的声明,后面跟着 = delete; 表示这个构造函数被删除了。 + //这意味着你不能通过拷贝另一个 DatabaseConnection 对象来创建新的 DatabaseConnection 对象。 + //如果尝试这样做,编译器会报错。 + DatabaseConnectionMainSys(const DatabaseConnectionMainSys&) = delete; + //这是拷贝赋值运算符的声明,同样后面跟着 = delete; 表示这个运算符被删除了。 + //这意味着你不能将一个 DatabaseConnection 对象赋值给另一个 DatabaseConnection 对象。 + //如果尝试这样做,编译器同样会报错。 + DatabaseConnectionMainSys& operator=(const DatabaseConnectionMainSys&) = delete; + //数据库db类 + QSqlDatabase dbmain; +}; + +#endif // DATABASECONNECTIONMAINSYS_H diff --git a/softwareDirectory/AutoVerScheme/datasyncview.cpp b/softwareDirectory/AutoVerScheme/datasyncview.cpp index fbf4508..06c7f9a 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.cpp +++ b/softwareDirectory/AutoVerScheme/datasyncview.cpp @@ -1,11 +1,10 @@ #include "datasyncview.h" #include "ui_datasyncview.h" -#include "synctask.h" -#include "databaseconnection.h" -#include "mainsysdatabaseconnection.h" +#include "syncdialog.h" - +QString filePath = "C:\\AutoVerScheme\\sync_info.txt"; +// 获取当前时间戳 DataSyncView::DataSyncView(QWidget *parent) : QWidget(parent), ui(new Ui::DataSyncView) @@ -20,7 +19,7 @@ } void DataSyncView::initForm() { - //tableWidget设置 + ui->stackedWidget->setCurrentIndex(0); //设置控件的边框显示 ui->tableWidget->setStyleSheet("QHeaderView::section {" "border: 1px solid grey;" @@ -32,29 +31,129 @@ "}"); ui->tableWidget->setRowCount(10); // 设置10行 - ui->tableWidget->setColumnCount(4); // 设置11列 - ui->tableWidget->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnCount(7); // 设置11列 + ui->tableWidget->setColumnWidth(0, 0); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnWidth(2, 200); // 设置第一列的宽度为100像素 ui->tableWidget->verticalHeader()->setParent(nullptr); //隐藏行头 - QTableWidgetItem *item = new QTableWidgetItem("测试数据"); - item->setTextAlignment(Qt::AlignCenter); - ui->tableWidget->setItem(0, 0, item); //设置数据 + + //初始化TableWidget 设置列 QStringList headers; - headers << "序号" << "同步时间" << "是否同步成功" << "备注" ; + headers <<"id" << "序号" << "同步时间" << "是否同步成功" << "备注" + <<"类型" <<"操作"; ui->tableWidget->setHorizontalHeaderLabels(headers); + //详情内 + + //设置控件的边框显示 + ui->tableWidget_2->setStyleSheet("QHeaderView::section {" + "border: 1px solid grey;" + "border-left:none;" + "border-top:none;" + "background-color:white;" + " color:black;" + "font: bold 18px Arial, sans-serif;" + "}"); + + ui->tableWidget_2->setRowCount(10); // 设置10行 + ui->tableWidget_2->setColumnCount(3); // 设置11列 + ui->tableWidget_2->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget_2->verticalHeader()->setParent(nullptr); //隐藏行头 + ui->tableWidget_2->setColumnWidth(1, 1000); // 设置第一列的宽度为100像素 + + //初始化TableWidget 设置列 + + headers << "序号" << "信息" << "状态" ; + ui->tableWidget_2->setHorizontalHeaderLabels(headers); + + //数据显示 + + //先设置为行为0 + ui->tableWidget->setRowCount(0); + int rowCount=0; + int row=0; + QList zdlog= BaseCommonApi::getzdLogByuserId(""); + for(const zdLog & zd:zdlog) + { + rowCount = ui->tableWidget->rowCount(); + ui->tableWidget->insertRow(rowCount); + ui->tableWidget->setItem(row, 0, new QTableWidgetItem(zd.id)); + ui->tableWidget->setItem(row, 1, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget->setItem(row, 2, new QTableWidgetItem(zd.sync_time.toString())); + ui->tableWidget->setItem(row, 3, new QTableWidgetItem(zd.is_sync)); + ui->tableWidget->setItem(row, 4, new QTableWidgetItem(zd.remark)); + if(zd.type=="1") + { + ui->tableWidget->setItem(row, 5, new QTableWidgetItem("下载")); + }else{ ui->tableWidget->setItem(row, 5, new QTableWidgetItem("上传")); } + + //添加操作按钮 + QPushButton *button = new QPushButton("查询信息"); + button->setIconSize(QSize(16,16)); + button->setIcon(QIcon(":/image/Index/u2327.svg")); + ui->tableWidget->setCellWidget(row, 6, button); + //设置按钮简单样式 + button->setStyleSheet("QPushButton {" + " border: none; /* 无边框 */" + " color: green; /* 文本颜色 */" + " text-decoration: underline; /* 文本下划线 */" + "}"); + + // 设置鼠标悬停时的光标样式为小手图标 + button->setCursor(Qt::PointingHandCursor); + // 连接按钮的 clicked 信号到自定义槽函数 + connect(button, &QPushButton::clicked, this, [this, button, zd]() { + // 获取当前行第一列的 ID + + OnButtonSelectClicked(zd); + + }); + row++; + } } void DataSyncView::on_DownloadDataButton_clicked() { - //从主系统下载 + + SyncDialog *syncDialog = new SyncDialog(this); + syncDialog->exec(); // 显示进度条窗体并阻塞主窗口 + + this->initForm(); + } -void DataSyncView::syncTable() +void DataSyncView::OnButtonSelectClicked(zdLog log) { - //连接两个数据库 - bool IsOpen=false; - DatabaseConnection *Conn=DatabaseConnection::getInstance(); - IsOpen=Conn->open(); - //MainSysDatabaseConnection *MainConn=MainSysDatabaseConnection::getInstance(); - //IsOpen=MainConn->open(); + ui->stackedWidget->setCurrentIndex(1); + ui->tableWidget_2->setRowCount(0); + int rowCount=0; + int row=0; + QList data= BaseCommonApi::getzdDataSyncByuserId(log.id); + for(const zdDataSync & item:data) + { + rowCount = ui->tableWidget_2->rowCount(); + ui->tableWidget_2->insertRow(rowCount); + ui->tableWidget_2->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget_2->setItem(row, 1, new QTableWidgetItem(item.remark)); + QTableWidgetItem *itemRow; + if(item.sync_type=="0"){ + itemRow = new QTableWidgetItem("未同步"); + itemRow->setBackground(QBrush(QColor(255, 255, 192))); + }else if (item.sync_type=="1") + { + itemRow = new QTableWidgetItem("同步成功"); + itemRow->setBackground(QBrush(QColor(173, 255, 47))); // 浅绿色 + }else{ + itemRow = new QTableWidgetItem("同步失败"); + itemRow->setBackground(QBrush(QColor(255, 105, 180))); // 浅红色 + } + itemRow->setTextAlignment(Qt::AlignCenter); + ui->tableWidget_2->setItem(row, 2, itemRow); + + row++; + } +} + +void DataSyncView::on_button_return_clicked() +{ + ui->stackedWidget->setCurrentIndex(0); } diff --git a/softwareDirectory/AutoVerScheme/datasyncview.h b/softwareDirectory/AutoVerScheme/datasyncview.h index 174480e..b2b9847 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.h +++ b/softwareDirectory/AutoVerScheme/datasyncview.h @@ -2,6 +2,16 @@ #define DATASYNCVIEW_H #include +#include +#include "synctask.h" +#include "databaseconnection.h" +#include "basecommonapi.h" +#include "databaseconnectionmainsys.h" +#include +#include +#include +#include +#include namespace Ui { class DataSyncView; @@ -18,8 +28,12 @@ void initForm(); //初始化界面数据 void on_DownloadDataButton_clicked(); - //异步更新 - void syncTable(); + void OnButtonSelectClicked(zdLog log); + void on_button_return_clicked(); + +public: + + private: Ui::DataSyncView *ui; }; diff --git a/softwareDirectory/AutoVerScheme/datasyncview.ui b/softwareDirectory/AutoVerScheme/datasyncview.ui index 53c379c..7c9df8e 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.ui +++ b/softwareDirectory/AutoVerScheme/datasyncview.ui @@ -14,21 +14,9 @@ 数据同步 - background-color:rgba(240, 240, 240, 1); + background-color:white; - - - 0 - - - 0 - - - 0 - - - 0 - + @@ -73,119 +61,173 @@ - - - background-color:white; - - - - - - - 3 - - - - - - 0 - 0 - - - - background-color:white; + + + + + + + background-color:white; + + + + + + + 3 + + + + + + 0 + 0 + + + + background-color:white; border:0; - - - - - - - - - - 0 - 0 - - - - font:bold 20px Arial, sans-serif; + + + + + + + + + + 0 + 0 + + + + font:bold 20px Arial, sans-serif; color:#334582; - - - 同步记录 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - background-color:#334582; + + + 同步记录 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + background-color:#334582; font: bold 18px Arial, sans-serif; color:white; padding:10px; - - - 下载数据 - - - - - - - - 200 - 0 - - - - - 100 - 40 - - - - Qt::RightToLeft - - - background-color:#334582; + + + 下载数据 + + + + + + + + 200 + 0 + + + + + 100 + 40 + + + + Qt::RightToLeft + + + background-color:#334582; font: bold 18px Arial, sans-serif; color:white; padding:10px; - - - 发送同步请求 - - - - :/image/Index/u8458.svg:/image/Index/u8458.svg - - - - - - - - - - - - - - + + + 发送同步请求 + + + + :/image/Index/u8458.svg:/image/Index/u8458.svg + + + + + + + + + + + + + + + + + + + + + + + + background-color:white; + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + color:black; + + + 返回 + + + + + + + + + + + + + diff --git a/softwareDirectory/AutoVerScheme/depar_task.cpp b/softwareDirectory/AutoVerScheme/depar_task.cpp index d551972..d58cf35 100644 --- a/softwareDirectory/AutoVerScheme/depar_task.cpp +++ b/softwareDirectory/AutoVerScheme/depar_task.cpp @@ -113,6 +113,7 @@ else State="否"; ui->tableWidget->setItem(row, 9, new QTableWidgetItem(State)); //设置数据 + SetHomePaheCombox(dept); //添加 PageData数据 TempData.append(QString::number(row+1)); TempData.append(dept.sample_name); @@ -133,9 +134,9 @@ //设置分页控件 // 创建分页表格控件 - PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); +// PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); //data转换位QList> - pagedTable->setData(PageData, 20,ui->tableWidget); // 每页20行 + // pagedTable->setData(PageData, 20,ui->tableWidget); // 每页20行 } void Depar_Task::on_SelectButton_clicked() @@ -155,26 +156,31 @@ if(dept.measure_status=="3" || dept.measure_status=="4"){ bool shouldAddRow = true; // 初始假设应该添加这一行 // 根据设备名称筛选 + QString names; if (ui->name->currentText() != "ALL") { + names=ui->name->currentText(); if (ui->name->currentText() != dept.sample_name) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } if (ui->mode->currentText() != "ALL") { + names=ui->mode->currentText(); if (ui->mode->currentText() != dept.sample_model) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } if (ui->customer->currentText() != "ALL") { + if (ui->customer->currentText() != dept.customer_name) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } - if (ui->dept->currentText() != "") { + if (ui->dept->currentText() != "ALL") { if (ui->dept->currentText() != dept.FULL_NAME) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); ui->tableWidget->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); @@ -193,9 +199,10 @@ State="否"; ui->tableWidget->setItem(row, 9, new QTableWidgetItem(State)); //设置数据 // - SetHomePaheCombox(dept); + //QDebug row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/indexwindow.cpp b/softwareDirectory/AutoVerScheme/indexwindow.cpp index eed192a..060b86e 100644 --- a/softwareDirectory/AutoVerScheme/indexwindow.cpp +++ b/softwareDirectory/AutoVerScheme/indexwindow.cpp @@ -58,7 +58,7 @@ DatabaseConnection *Conn=DatabaseConnection::getInstance(); //数据库连接 目前先放这里 后续需要放到登录界面 - bool IsOpen=Conn->open(); + bool IsOpen=Conn->open(); if(IsOpen) ShowMessageBox("数据库连接","连接成功"); else diff --git a/softwareDirectory/AutoVerScheme/my_task.cpp b/softwareDirectory/AutoVerScheme/my_task.cpp index 1735575..cd735f8 100644 --- a/softwareDirectory/AutoVerScheme/my_task.cpp +++ b/softwareDirectory/AutoVerScheme/my_task.cpp @@ -62,7 +62,8 @@ } void My_Task::Load() { - QList> PageData; + + //QList> PageData; //先设置为行为0 ui->tableWidget->setRowCount(0); //添加comboBox @@ -86,11 +87,29 @@ QString userId=""; data = BaseCommonApi::getMyTasks(userId,"3"); + QString State; + //设置单页显示数量 + page=20; + // 创建分页表格控件 + PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); + pagedTable->setData(data.count(), page); // 每页10行 + connect(pagedTable, &PagedTableWidget::pageChanged, this,&My_Task::onpageChanged); + this->onpageChanged(0); + +} +void My_Task::onpageChanged(int currPage){ + currPage+=1; + // 计算当前页的开始和结束索引 + int start = (currPage - 1) * page; + int end = std::min(start + page, data.size()); + // 从 QList 中筛选出当前页的数据 + QList tempdate = data.mid(start, end - start); int rowCount = 0; int row=0; QString State; - for (const MyTask& myTask : data) { - if(myTask.measure_status=="3" || myTask.measure_status=="4"){ + ui->tableWidget->setRowCount(0); + for (const MyTask& myTask : tempdate) { + QList TempData; rowCount = ui->tableWidget->rowCount(); @@ -118,42 +137,15 @@ ui->tableWidget->setItem(row, 10,new QTableWidgetItem("检测完成")); } - //渲染下拉框 - SetHomePaheCombox(myTask); - //QDebug - - //添加 PageData数据 - TempData.append(QString::number(row+1)); - TempData.append(myTask.sample_name); - TempData.append(myTask.sample_model); - TempData.append(myTask.help_instruction); - TempData.append(myTask.manufacture_no); - TempData.append(myTask.manufacturer); - TempData.append(myTask.customer_name); - TempData.append(myTask.FULL_NAME); - TempData.append(myTask.require_over_time.toString()); - TempData.append(State); - TempData.append(myTask.measure_status); - PageData.append(TempData); + //渲染下拉框 + SetHomePaheCombox(myTask); row++; - } - - } - //设置分页控件 - // 创建分页表格控件 - - PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); - //data转换位QList> - pagedTable->setData(PageData, 20,ui->tableWidget); // 每页10行 - //ui->HBoxPageLayout->addWidget(pagedTable); - //setLayout(ui->HBoxPageLayout); - // 连接信号以处理页码变化 - /* connect(pagedTable, &PagedTableWidget::pageChanged, this, [=](int page) { - // 在这里处理页码变化事件,比如更新UI中的其他部分 - qDebug() << "Page changed to:" << page; - });*/ + }; + //按钮点击事件 + // QMessageBox::information(this, "点击按钮",QString::number(page)); + // qDebug() << "Page changed to:" << page; } void My_Task::SetHomePaheCombox(MyTask entity) { diff --git a/softwareDirectory/AutoVerScheme/my_task.h b/softwareDirectory/AutoVerScheme/my_task.h index 289e7f4..8a4ad07 100644 --- a/softwareDirectory/AutoVerScheme/my_task.h +++ b/softwareDirectory/AutoVerScheme/my_task.h @@ -26,9 +26,11 @@ void on_pushButtonUpdate_clicked(); void on_SeachButton_clicked(); + void onpageChanged(int page); public: QList data; - + int page; + int totalcount; private: Ui::My_Task *ui; }; diff --git a/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp b/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp index e9cfb66..3ef9d60 100644 --- a/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp @@ -3,7 +3,7 @@ #include "InfoBase.h" #include "QMessageBox" #include "basecommonapi.h" - +#include "PageControl.h" //标准设备管理 .cpp Standard_DeviceItem::Standard_DeviceItem(QWidget *parent) : @@ -32,7 +32,7 @@ // ui->tableWidget->setRowCount(10); // 设置10行 ui->tableWidget->setColumnCount(7); // 设置11列 - ui->tableWidget->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnWidth(0, 0); // 设置第一列的宽度为100像素 ui->tableWidget->verticalHeader()->setParent(nullptr); //隐藏行头 //QTableWidgetItem *item = new QTableWidgetItem("测试数据"); //item->setTextAlignment(Qt::AlignCenter); @@ -102,12 +102,32 @@ // 调用数据库管理器的函数获取数据 - int rowCount=0; - int row=0; + data = BaseCommonApi::getBizDeviceManage(); + QString State; + //设置单页显示数量 + page=20; + // 创建分页表格控件 + PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); + pagedTable->setData(data.count(), page); // 每页10行 + connect(pagedTable, &PagedTableWidget::pageChanged, this,&Standard_DeviceItem::onpageChanged); + this->onpageChanged(0); - for (const BizDevice& bizDevice : data) { +} +void Standard_DeviceItem::onpageChanged(int currPage){ + + currPage+=1; + // 计算当前页的开始和结束索引 + int start = (currPage - 1) * page; + int end = std::min(start + page, data.size()); + // 从 QList 中筛选出当前页的数据 + QList tempdate = data.mid(start, end - start); + int rowCount = 0; + int row=0; + QString State; + ui->tableWidget->setRowCount(0); + for (const BizDevice& bizDevice : tempdate) { rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -147,8 +167,9 @@ SetHomePaheCombox(bizDevice); row++; } - } + + void Standard_DeviceItem::OnButtonSelectClicked(QString id) { //添加 diff --git a/softwareDirectory/AutoVerScheme/standard_deviceitem.h b/softwareDirectory/AutoVerScheme/standard_deviceitem.h index f522658..c506728 100644 --- a/softwareDirectory/AutoVerScheme/standard_deviceitem.h +++ b/softwareDirectory/AutoVerScheme/standard_deviceitem.h @@ -30,6 +30,9 @@ void on_pushButton_8_clicked(); public: QList data; + void onpageChanged(int currPage); + int page; + int totalcount; private: Ui::Standard_DeviceItem *ui; }; diff --git a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro index bf70fab..d9a99ea 100644 --- a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro +++ b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro @@ -35,6 +35,7 @@ create_task.cpp \ createtask_scandevice.cpp \ databaseconnection.cpp \ + databaseconnectionmainsys.cpp \ datasyncview.cpp \ depar_task.cpp \ depar_task_server.cpp \ @@ -55,6 +56,7 @@ newverifymethod.cpp \ rulefileitem.cpp \ standard_deviceitem.cpp \ + syncdialog.cpp \ synctask.cpp \ testdataitem.cpp \ testview.cpp \ @@ -69,6 +71,7 @@ DataProcessingBLL.h \ PageControl.h \ createtask_scandevice.h \ + databaseconnectionmainsys.h \ formaddrsetting.h \ formcommsetting.h \ id/IdWorker.h \ @@ -104,6 +107,7 @@ newverifymethod.h \ rulefileitem.h \ standard_deviceitem.h \ + syncdialog.h \ synctask.h \ testdataitem.h \ testview.h \ @@ -138,6 +142,7 @@ newverifymethod.ui \ rulefileitem.ui \ standard_deviceitem.ui \ + syncdialog.ui \ testdataitem.ui \ testview.ui \ verifydevice.ui \ diff --git a/softwareDirectory/AutoVerScheme/PageControl.cpp b/softwareDirectory/AutoVerScheme/PageControl.cpp index d0fd72b..d1bdddc 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.cpp +++ b/softwareDirectory/AutoVerScheme/PageControl.cpp @@ -22,14 +22,14 @@ } } -void PagedTableWidget::setData(const QList> &data, int rowsPerPage,QTableWidget *table) { - tableWidget=table; - +void PagedTableWidget::setData(int datacount, int rowsPerPage) { + //tableWidget=table; + totaldatacount=datacount; this->rowsPerPage = rowsPerPage; - allData = data; + //allData = data; currentPage = 0; createPageButtons(); - updateTable(); + //updateTable(); } void PagedTableWidget::setCurrentPage(int page) { @@ -39,7 +39,7 @@ button->setChecked(false); }*/ currentPage = page; - updateTable(); + //updateTable(); emit pageChanged(page); } } @@ -89,6 +89,7 @@ setCurrentPage(pageIndex); } } +/* void PagedTableWidget::updateTable() { //tableWidget->clear(); tableWidget->setRowCount(0); @@ -105,7 +106,7 @@ } } } - +*/ void PagedTableWidget::createPageButtons() { int totalPages = calculateTotalPages(); for (auto button : pageButtons) { @@ -150,5 +151,5 @@ } int PagedTableWidget::calculateTotalPages() { - return ((allData.count() + rowsPerPage -1) / rowsPerPage); + return ((totaldatacount + rowsPerPage -1) / rowsPerPage); } diff --git a/softwareDirectory/AutoVerScheme/PageControl.h b/softwareDirectory/AutoVerScheme/PageControl.h index 74ed1ce..2224760 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.h +++ b/softwareDirectory/AutoVerScheme/PageControl.h @@ -15,7 +15,7 @@ explicit PagedTableWidget(QWidget *parent = nullptr,QHBoxLayout *PageLayout=NULL); ~PagedTableWidget(); - void setData(const QList> &data, int rowsPerPage = 10,QTableWidget *table=NULL); + void setData(int datacount, int rowsPerPage = 10); void setCurrentPage(int page); signals: @@ -30,6 +30,7 @@ QHBoxLayout *pageLayout; QList pageButtons; QList> allData; + int totaldatacount; int rowsPerPage; int currentPage; diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.cpp b/softwareDirectory/AutoVerScheme/basecommonapi.cpp index 49cbd7e..6f6fe94 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.cpp +++ b/softwareDirectory/AutoVerScheme/basecommonapi.cpp @@ -13,7 +13,7 @@ } const QString BaseCommonApi::temporary_user_id="1634107227953819649"; const QString BaseCommonApi::measure_person_id="1695282436182188034"; - +static SyncRunStatus syncstate=SyncRunStatus::Stopped; //sys_user表的id转换为measure_person_id 检定人id(meter_staff表id) @@ -167,7 +167,8 @@ "JOIN eqpt_equipment_info eei ON eei.id = blei.sample_id " "JOIN biz_business_order_info bo ON bo.id = blei.order_id " "LEFT JOIN sys_dept sd ON blei.measure_dept_id = sd.ID " - " WHERE blei.measure_person_id = :person_id " + " WHERE blei.measure_person_id = :person_id " + " AND blei.measure_status =3 or blei.measure_status = 4 " " ORDER BY blei.update_time DESC"); // 将参数绑定到占位符 @@ -175,7 +176,8 @@ //query.bindValue(":status", status); if (query.exec()) { while (query.next()) { - MyTask task; + + MyTask task; task.id = query.value("id").toString(); task.sample_name = query.value("sampleName").toString(); task.sample_model = query.value("sampleModel").toString(); @@ -2872,9 +2874,40 @@ return result; } +//保存log信息 +//log文件 + bool BaseCommonApi::SaveLogInfo(QString path,QString Info) +{ + QByteArray utf8Dat; + QString Message=Info; + QFile file(path); + // 如果目录不存在,则创建目录 + // 获取文件所在的目录 + QDir logDir = QDir(QFileInfo(path).absolutePath()); + if (!logDir.exists()) { + if (!logDir.mkpath(".")) { + qDebug() << "Failed to create log directory:" << logDir.absolutePath(); + return false; + } + } + + if (!file.open(QIODevice::Append | QIODevice::Text)) { + qDebug() << "无法打开文件:" << file.errorString(); + return false; + } + QTextStream out(&file); + utf8Dat = Message.toUtf8(); + out << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss") + << "\t" << utf8Dat << "\n"; + file.close(); + return true; + } + + //新增日志表数据 bool BaseCommonApi::InsertzdLog(zdLog log) { + log.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_log(id,is_sync,sync_time,remark,userid,type,create_time,update_time) " " VALUES(:id,:is_sync,:sync_time,:remark,:userid,:type,:create_time,:update_time) "); @@ -2898,6 +2931,7 @@ //根据userid查询日志表数据 QList BaseCommonApi::getzdLogByuserId(QString userid) { + userid=temporary_user_id; QList result; QSqlQuery query; query.prepare("SELECT * FROM zd_log WHERE userid = :userid "); @@ -2922,6 +2956,7 @@ //新增数据同步表 bool BaseCommonApi::InsertzdDataSync(zdDataSync data) { + data.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_data_sync(id,type,ssql,userid,remark,create_time,update_time,log_sync_id,sync_type) " " VALUES " @@ -2945,12 +2980,12 @@ return isSuccess; } //根据userid查询数据同步表 -QList getzdDataSyncByuserId(QString userid) +QList BaseCommonApi::getzdDataSyncByuserId(QString log_sync_id) { QList result; QSqlQuery query; - query.prepare("SELECT * FROM zd_data_sync WHERE userid= :userid "); - query.bindValue(":userid",userid); + query.prepare("SELECT * FROM zd_data_sync WHERE log_sync_id= :log_sync_id "); + query.bindValue(":log_sync_id",log_sync_id); if (query.exec()) { while (query.next()) { zdDataSync data; @@ -2972,3 +3007,4 @@ } + diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.h b/softwareDirectory/AutoVerScheme/basecommonapi.h index 12196fb..4949683 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.h +++ b/softwareDirectory/AutoVerScheme/basecommonapi.h @@ -919,6 +919,7 @@ QDateTime create_time; QDateTime update_time; }; + //数据同步-数据表 class zdDataSync { @@ -935,6 +936,12 @@ }; +enum class SyncRunStatus { + + Running, + Stopped, + Paused +}; using namespace Jiawa::Core; class BaseCommonApi @@ -945,7 +952,6 @@ const static QString temporary_costomer_id; const static QString measure_person_id; - QString encrypt(const QString &str, const QString &publicKey); //判断检定装置表并查询 参数设备id @@ -1137,14 +1143,19 @@ //单独查询任务单表 //更新 任务单 static InsertTask SelectTaskSingle(QString order_id); + + //log文件 + static bool SaveLogInfo(QString path,QString Info); + //新增日志表数据 static bool InsertzdLog(zdLog log); //查询日志表数据 static QList getzdLogByuserId(QString userid); //新增数据同步表 static bool InsertzdDataSync(zdDataSync data); - //根据userid查询数据同步表 - static QList getzdDataSyncByuserId(QString userid); + //根据log_sync_id查询数据同步表 + static QList getzdDataSyncByuserId(QString log_sync_id); + }; diff --git a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp index 00d746b..ae60962 100644 --- a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp @@ -352,6 +352,7 @@ } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -395,6 +396,7 @@ row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.cpp b/softwareDirectory/AutoVerScheme/databaseconnection.cpp index 1d957d9..5284fe6 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.cpp +++ b/softwareDirectory/AutoVerScheme/databaseconnection.cpp @@ -10,17 +10,21 @@ { // 连接数据库 - db = QSqlDatabase::addDatabase("QODBC"); - /*db.setHostName("111.198.10.15"); - db.setDatabaseName("casic_metering_xichang"); - db.setPort(21906); - db.setUserName("zdjdcs"); - db.setPassword("11111111");*/ - db.setHostName("localhost"); - db.setDatabaseName("zdjd"); - db.setPort(3306); - db.setUserName("root"); - db.setPassword("123456"); + localdb = QSqlDatabase::addDatabase("QODBC"); + + localdb.setHostName("localhost"); + localdb.setDatabaseName("zdjd"); + localdb.setPort(3306); + localdb.setUserName("root"); + localdb.setPassword("123456"); + + Maindb = QSqlDatabase::addDatabase("QODBC","Main"); + Maindb.setHostName("111.198.10.15"); + Maindb.setDatabaseName("casic_metering_xichang"); + Maindb.setPort(21906); + Maindb.setUserName("zdjdcs"); + Maindb.setPassword("11111111"); + } @@ -29,18 +33,28 @@ close(); } bool DatabaseConnection::open() { - return db.open(); + return localdb.open(); +} +bool DatabaseConnection::openmain() { + return Maindb.open(); } bool DatabaseConnection::isopen() { - return db.isOpen(); + return localdb.isOpen(); } - +bool DatabaseConnection::isopenmain() { + return Maindb.isOpen(); +} void DatabaseConnection::close() { - db.close(); + localdb.close(); } - +void DatabaseConnection::closemain() { + Maindb.close(); +} QSqlDatabase& DatabaseConnection::getDatabase() { - return db; + return localdb; +} +QSqlDatabase& DatabaseConnection::getDatabaseMain() { + return Maindb; } DatabaseConnection* DatabaseConnection::getInstance() { diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.h b/softwareDirectory/AutoVerScheme/databaseconnection.h index 586b794..5f9810b 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.h +++ b/softwareDirectory/AutoVerScheme/databaseconnection.h @@ -16,8 +16,12 @@ ~DatabaseConnection(); bool open(); bool isopen(); + bool openmain(); void close(); + void closemain(); + bool isopenmain(); QSqlDatabase& getDatabase(); + QSqlDatabase& getDatabaseMain(); private: //单列模式 保证DatabaseConnection的唯一性 static DatabaseConnection* Connect; @@ -33,7 +37,8 @@ //如果尝试这样做,编译器同样会报错。 DatabaseConnection& operator=(const DatabaseConnection&) = delete; //数据库db类 - QSqlDatabase db; + QSqlDatabase Maindb; + QSqlDatabase localdb; }; #endif // DATABASECONNECTION_H diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp new file mode 100644 index 0000000..080288b --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp @@ -0,0 +1,54 @@ +#include "databaseconnectionmainsys.h" + + + + +DatabaseConnectionMainSys* DatabaseConnectionMainSys::Connect = nullptr; +QMutex DatabaseConnectionMainSys::mutex; + +DatabaseConnectionMainSys::DatabaseConnectionMainSys() +{ + + // 连接数据库 + dbmain = QSqlDatabase::addDatabase("QODBC"); + dbmain.setHostName("111.198.10.15"); + dbmain.setDatabaseName("casic_metering_xichang"); + dbmain.setPort(21906); + dbmain.setUserName("zdjdcs"); + dbmain.setPassword("11111111"); + /* db.setHostName("localhost"); + db.setDatabaseName("zdjd"); + db.setPort(3306); + db.setUserName("root"); + db.setPassword("123456");*/ + + +} +DatabaseConnectionMainSys::~DatabaseConnectionMainSys() { + // 在析构函数中关闭数据库连接 + close(); +} +bool DatabaseConnectionMainSys::open() { + return dbmain.open(); +} +bool DatabaseConnectionMainSys::isopen() { + return dbmain.isOpen(); +} + +void DatabaseConnectionMainSys::close() { + dbmain.close(); +} + +QSqlDatabase& DatabaseConnectionMainSys::getDatabase() { + return dbmain; +} +DatabaseConnectionMainSys* DatabaseConnectionMainSys::getInstance() +{ + if (!Connect) { + QMutexLocker locker(&mutex); + if (!Connect) { + Connect = new DatabaseConnectionMainSys(); + } + } + return Connect; +} diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h new file mode 100644 index 0000000..57702ad --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h @@ -0,0 +1,41 @@ +#ifndef DATABASECONNECTIONMAINSYS_H +#define DATABASECONNECTIONMAINSYS_H +#include +#include +#include +#include + + +class DatabaseConnectionMainSys +{ + + +public: + //获取数据库实例 + static DatabaseConnectionMainSys* getInstance(); + + DatabaseConnectionMainSys(); + ~DatabaseConnectionMainSys(); + bool open(); + bool isopen(); + void close(); + QSqlDatabase& getDatabase(); +private: + //单列模式 保证MainSysDatabaseConnection的唯一性 + static DatabaseConnectionMainSys* Connect; + //QMutex 来确保在多线程环境下单例的正确创建。 + static QMutex mutex; + + //这是拷贝构造函数的声明,后面跟着 = delete; 表示这个构造函数被删除了。 + //这意味着你不能通过拷贝另一个 DatabaseConnection 对象来创建新的 DatabaseConnection 对象。 + //如果尝试这样做,编译器会报错。 + DatabaseConnectionMainSys(const DatabaseConnectionMainSys&) = delete; + //这是拷贝赋值运算符的声明,同样后面跟着 = delete; 表示这个运算符被删除了。 + //这意味着你不能将一个 DatabaseConnection 对象赋值给另一个 DatabaseConnection 对象。 + //如果尝试这样做,编译器同样会报错。 + DatabaseConnectionMainSys& operator=(const DatabaseConnectionMainSys&) = delete; + //数据库db类 + QSqlDatabase dbmain; +}; + +#endif // DATABASECONNECTIONMAINSYS_H diff --git a/softwareDirectory/AutoVerScheme/datasyncview.cpp b/softwareDirectory/AutoVerScheme/datasyncview.cpp index fbf4508..06c7f9a 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.cpp +++ b/softwareDirectory/AutoVerScheme/datasyncview.cpp @@ -1,11 +1,10 @@ #include "datasyncview.h" #include "ui_datasyncview.h" -#include "synctask.h" -#include "databaseconnection.h" -#include "mainsysdatabaseconnection.h" +#include "syncdialog.h" - +QString filePath = "C:\\AutoVerScheme\\sync_info.txt"; +// 获取当前时间戳 DataSyncView::DataSyncView(QWidget *parent) : QWidget(parent), ui(new Ui::DataSyncView) @@ -20,7 +19,7 @@ } void DataSyncView::initForm() { - //tableWidget设置 + ui->stackedWidget->setCurrentIndex(0); //设置控件的边框显示 ui->tableWidget->setStyleSheet("QHeaderView::section {" "border: 1px solid grey;" @@ -32,29 +31,129 @@ "}"); ui->tableWidget->setRowCount(10); // 设置10行 - ui->tableWidget->setColumnCount(4); // 设置11列 - ui->tableWidget->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnCount(7); // 设置11列 + ui->tableWidget->setColumnWidth(0, 0); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnWidth(2, 200); // 设置第一列的宽度为100像素 ui->tableWidget->verticalHeader()->setParent(nullptr); //隐藏行头 - QTableWidgetItem *item = new QTableWidgetItem("测试数据"); - item->setTextAlignment(Qt::AlignCenter); - ui->tableWidget->setItem(0, 0, item); //设置数据 + + //初始化TableWidget 设置列 QStringList headers; - headers << "序号" << "同步时间" << "是否同步成功" << "备注" ; + headers <<"id" << "序号" << "同步时间" << "是否同步成功" << "备注" + <<"类型" <<"操作"; ui->tableWidget->setHorizontalHeaderLabels(headers); + //详情内 + + //设置控件的边框显示 + ui->tableWidget_2->setStyleSheet("QHeaderView::section {" + "border: 1px solid grey;" + "border-left:none;" + "border-top:none;" + "background-color:white;" + " color:black;" + "font: bold 18px Arial, sans-serif;" + "}"); + + ui->tableWidget_2->setRowCount(10); // 设置10行 + ui->tableWidget_2->setColumnCount(3); // 设置11列 + ui->tableWidget_2->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget_2->verticalHeader()->setParent(nullptr); //隐藏行头 + ui->tableWidget_2->setColumnWidth(1, 1000); // 设置第一列的宽度为100像素 + + //初始化TableWidget 设置列 + + headers << "序号" << "信息" << "状态" ; + ui->tableWidget_2->setHorizontalHeaderLabels(headers); + + //数据显示 + + //先设置为行为0 + ui->tableWidget->setRowCount(0); + int rowCount=0; + int row=0; + QList zdlog= BaseCommonApi::getzdLogByuserId(""); + for(const zdLog & zd:zdlog) + { + rowCount = ui->tableWidget->rowCount(); + ui->tableWidget->insertRow(rowCount); + ui->tableWidget->setItem(row, 0, new QTableWidgetItem(zd.id)); + ui->tableWidget->setItem(row, 1, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget->setItem(row, 2, new QTableWidgetItem(zd.sync_time.toString())); + ui->tableWidget->setItem(row, 3, new QTableWidgetItem(zd.is_sync)); + ui->tableWidget->setItem(row, 4, new QTableWidgetItem(zd.remark)); + if(zd.type=="1") + { + ui->tableWidget->setItem(row, 5, new QTableWidgetItem("下载")); + }else{ ui->tableWidget->setItem(row, 5, new QTableWidgetItem("上传")); } + + //添加操作按钮 + QPushButton *button = new QPushButton("查询信息"); + button->setIconSize(QSize(16,16)); + button->setIcon(QIcon(":/image/Index/u2327.svg")); + ui->tableWidget->setCellWidget(row, 6, button); + //设置按钮简单样式 + button->setStyleSheet("QPushButton {" + " border: none; /* 无边框 */" + " color: green; /* 文本颜色 */" + " text-decoration: underline; /* 文本下划线 */" + "}"); + + // 设置鼠标悬停时的光标样式为小手图标 + button->setCursor(Qt::PointingHandCursor); + // 连接按钮的 clicked 信号到自定义槽函数 + connect(button, &QPushButton::clicked, this, [this, button, zd]() { + // 获取当前行第一列的 ID + + OnButtonSelectClicked(zd); + + }); + row++; + } } void DataSyncView::on_DownloadDataButton_clicked() { - //从主系统下载 + + SyncDialog *syncDialog = new SyncDialog(this); + syncDialog->exec(); // 显示进度条窗体并阻塞主窗口 + + this->initForm(); + } -void DataSyncView::syncTable() +void DataSyncView::OnButtonSelectClicked(zdLog log) { - //连接两个数据库 - bool IsOpen=false; - DatabaseConnection *Conn=DatabaseConnection::getInstance(); - IsOpen=Conn->open(); - //MainSysDatabaseConnection *MainConn=MainSysDatabaseConnection::getInstance(); - //IsOpen=MainConn->open(); + ui->stackedWidget->setCurrentIndex(1); + ui->tableWidget_2->setRowCount(0); + int rowCount=0; + int row=0; + QList data= BaseCommonApi::getzdDataSyncByuserId(log.id); + for(const zdDataSync & item:data) + { + rowCount = ui->tableWidget_2->rowCount(); + ui->tableWidget_2->insertRow(rowCount); + ui->tableWidget_2->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget_2->setItem(row, 1, new QTableWidgetItem(item.remark)); + QTableWidgetItem *itemRow; + if(item.sync_type=="0"){ + itemRow = new QTableWidgetItem("未同步"); + itemRow->setBackground(QBrush(QColor(255, 255, 192))); + }else if (item.sync_type=="1") + { + itemRow = new QTableWidgetItem("同步成功"); + itemRow->setBackground(QBrush(QColor(173, 255, 47))); // 浅绿色 + }else{ + itemRow = new QTableWidgetItem("同步失败"); + itemRow->setBackground(QBrush(QColor(255, 105, 180))); // 浅红色 + } + itemRow->setTextAlignment(Qt::AlignCenter); + ui->tableWidget_2->setItem(row, 2, itemRow); + + row++; + } +} + +void DataSyncView::on_button_return_clicked() +{ + ui->stackedWidget->setCurrentIndex(0); } diff --git a/softwareDirectory/AutoVerScheme/datasyncview.h b/softwareDirectory/AutoVerScheme/datasyncview.h index 174480e..b2b9847 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.h +++ b/softwareDirectory/AutoVerScheme/datasyncview.h @@ -2,6 +2,16 @@ #define DATASYNCVIEW_H #include +#include +#include "synctask.h" +#include "databaseconnection.h" +#include "basecommonapi.h" +#include "databaseconnectionmainsys.h" +#include +#include +#include +#include +#include namespace Ui { class DataSyncView; @@ -18,8 +28,12 @@ void initForm(); //初始化界面数据 void on_DownloadDataButton_clicked(); - //异步更新 - void syncTable(); + void OnButtonSelectClicked(zdLog log); + void on_button_return_clicked(); + +public: + + private: Ui::DataSyncView *ui; }; diff --git a/softwareDirectory/AutoVerScheme/datasyncview.ui b/softwareDirectory/AutoVerScheme/datasyncview.ui index 53c379c..7c9df8e 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.ui +++ b/softwareDirectory/AutoVerScheme/datasyncview.ui @@ -14,21 +14,9 @@ 数据同步 - background-color:rgba(240, 240, 240, 1); + background-color:white; - - - 0 - - - 0 - - - 0 - - - 0 - + @@ -73,119 +61,173 @@ - - - background-color:white; - - - - - - - 3 - - - - - - 0 - 0 - - - - background-color:white; + + + + + + + background-color:white; + + + + + + + 3 + + + + + + 0 + 0 + + + + background-color:white; border:0; - - - - - - - - - - 0 - 0 - - - - font:bold 20px Arial, sans-serif; + + + + + + + + + + 0 + 0 + + + + font:bold 20px Arial, sans-serif; color:#334582; - - - 同步记录 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - background-color:#334582; + + + 同步记录 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + background-color:#334582; font: bold 18px Arial, sans-serif; color:white; padding:10px; - - - 下载数据 - - - - - - - - 200 - 0 - - - - - 100 - 40 - - - - Qt::RightToLeft - - - background-color:#334582; + + + 下载数据 + + + + + + + + 200 + 0 + + + + + 100 + 40 + + + + Qt::RightToLeft + + + background-color:#334582; font: bold 18px Arial, sans-serif; color:white; padding:10px; - - - 发送同步请求 - - - - :/image/Index/u8458.svg:/image/Index/u8458.svg - - - - - - - - - - - - - - + + + 发送同步请求 + + + + :/image/Index/u8458.svg:/image/Index/u8458.svg + + + + + + + + + + + + + + + + + + + + + + + + background-color:white; + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + color:black; + + + 返回 + + + + + + + + + + + + + diff --git a/softwareDirectory/AutoVerScheme/depar_task.cpp b/softwareDirectory/AutoVerScheme/depar_task.cpp index d551972..d58cf35 100644 --- a/softwareDirectory/AutoVerScheme/depar_task.cpp +++ b/softwareDirectory/AutoVerScheme/depar_task.cpp @@ -113,6 +113,7 @@ else State="否"; ui->tableWidget->setItem(row, 9, new QTableWidgetItem(State)); //设置数据 + SetHomePaheCombox(dept); //添加 PageData数据 TempData.append(QString::number(row+1)); TempData.append(dept.sample_name); @@ -133,9 +134,9 @@ //设置分页控件 // 创建分页表格控件 - PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); +// PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); //data转换位QList> - pagedTable->setData(PageData, 20,ui->tableWidget); // 每页20行 + // pagedTable->setData(PageData, 20,ui->tableWidget); // 每页20行 } void Depar_Task::on_SelectButton_clicked() @@ -155,26 +156,31 @@ if(dept.measure_status=="3" || dept.measure_status=="4"){ bool shouldAddRow = true; // 初始假设应该添加这一行 // 根据设备名称筛选 + QString names; if (ui->name->currentText() != "ALL") { + names=ui->name->currentText(); if (ui->name->currentText() != dept.sample_name) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } if (ui->mode->currentText() != "ALL") { + names=ui->mode->currentText(); if (ui->mode->currentText() != dept.sample_model) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } if (ui->customer->currentText() != "ALL") { + if (ui->customer->currentText() != dept.customer_name) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } - if (ui->dept->currentText() != "") { + if (ui->dept->currentText() != "ALL") { if (ui->dept->currentText() != dept.FULL_NAME) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); ui->tableWidget->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); @@ -193,9 +199,10 @@ State="否"; ui->tableWidget->setItem(row, 9, new QTableWidgetItem(State)); //设置数据 // - SetHomePaheCombox(dept); + //QDebug row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/indexwindow.cpp b/softwareDirectory/AutoVerScheme/indexwindow.cpp index eed192a..060b86e 100644 --- a/softwareDirectory/AutoVerScheme/indexwindow.cpp +++ b/softwareDirectory/AutoVerScheme/indexwindow.cpp @@ -58,7 +58,7 @@ DatabaseConnection *Conn=DatabaseConnection::getInstance(); //数据库连接 目前先放这里 后续需要放到登录界面 - bool IsOpen=Conn->open(); + bool IsOpen=Conn->open(); if(IsOpen) ShowMessageBox("数据库连接","连接成功"); else diff --git a/softwareDirectory/AutoVerScheme/my_task.cpp b/softwareDirectory/AutoVerScheme/my_task.cpp index 1735575..cd735f8 100644 --- a/softwareDirectory/AutoVerScheme/my_task.cpp +++ b/softwareDirectory/AutoVerScheme/my_task.cpp @@ -62,7 +62,8 @@ } void My_Task::Load() { - QList> PageData; + + //QList> PageData; //先设置为行为0 ui->tableWidget->setRowCount(0); //添加comboBox @@ -86,11 +87,29 @@ QString userId=""; data = BaseCommonApi::getMyTasks(userId,"3"); + QString State; + //设置单页显示数量 + page=20; + // 创建分页表格控件 + PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); + pagedTable->setData(data.count(), page); // 每页10行 + connect(pagedTable, &PagedTableWidget::pageChanged, this,&My_Task::onpageChanged); + this->onpageChanged(0); + +} +void My_Task::onpageChanged(int currPage){ + currPage+=1; + // 计算当前页的开始和结束索引 + int start = (currPage - 1) * page; + int end = std::min(start + page, data.size()); + // 从 QList 中筛选出当前页的数据 + QList tempdate = data.mid(start, end - start); int rowCount = 0; int row=0; QString State; - for (const MyTask& myTask : data) { - if(myTask.measure_status=="3" || myTask.measure_status=="4"){ + ui->tableWidget->setRowCount(0); + for (const MyTask& myTask : tempdate) { + QList TempData; rowCount = ui->tableWidget->rowCount(); @@ -118,42 +137,15 @@ ui->tableWidget->setItem(row, 10,new QTableWidgetItem("检测完成")); } - //渲染下拉框 - SetHomePaheCombox(myTask); - //QDebug - - //添加 PageData数据 - TempData.append(QString::number(row+1)); - TempData.append(myTask.sample_name); - TempData.append(myTask.sample_model); - TempData.append(myTask.help_instruction); - TempData.append(myTask.manufacture_no); - TempData.append(myTask.manufacturer); - TempData.append(myTask.customer_name); - TempData.append(myTask.FULL_NAME); - TempData.append(myTask.require_over_time.toString()); - TempData.append(State); - TempData.append(myTask.measure_status); - PageData.append(TempData); + //渲染下拉框 + SetHomePaheCombox(myTask); row++; - } - - } - //设置分页控件 - // 创建分页表格控件 - - PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); - //data转换位QList> - pagedTable->setData(PageData, 20,ui->tableWidget); // 每页10行 - //ui->HBoxPageLayout->addWidget(pagedTable); - //setLayout(ui->HBoxPageLayout); - // 连接信号以处理页码变化 - /* connect(pagedTable, &PagedTableWidget::pageChanged, this, [=](int page) { - // 在这里处理页码变化事件,比如更新UI中的其他部分 - qDebug() << "Page changed to:" << page; - });*/ + }; + //按钮点击事件 + // QMessageBox::information(this, "点击按钮",QString::number(page)); + // qDebug() << "Page changed to:" << page; } void My_Task::SetHomePaheCombox(MyTask entity) { diff --git a/softwareDirectory/AutoVerScheme/my_task.h b/softwareDirectory/AutoVerScheme/my_task.h index 289e7f4..8a4ad07 100644 --- a/softwareDirectory/AutoVerScheme/my_task.h +++ b/softwareDirectory/AutoVerScheme/my_task.h @@ -26,9 +26,11 @@ void on_pushButtonUpdate_clicked(); void on_SeachButton_clicked(); + void onpageChanged(int page); public: QList data; - + int page; + int totalcount; private: Ui::My_Task *ui; }; diff --git a/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp b/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp index e9cfb66..3ef9d60 100644 --- a/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp @@ -3,7 +3,7 @@ #include "InfoBase.h" #include "QMessageBox" #include "basecommonapi.h" - +#include "PageControl.h" //标准设备管理 .cpp Standard_DeviceItem::Standard_DeviceItem(QWidget *parent) : @@ -32,7 +32,7 @@ // ui->tableWidget->setRowCount(10); // 设置10行 ui->tableWidget->setColumnCount(7); // 设置11列 - ui->tableWidget->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnWidth(0, 0); // 设置第一列的宽度为100像素 ui->tableWidget->verticalHeader()->setParent(nullptr); //隐藏行头 //QTableWidgetItem *item = new QTableWidgetItem("测试数据"); //item->setTextAlignment(Qt::AlignCenter); @@ -102,12 +102,32 @@ // 调用数据库管理器的函数获取数据 - int rowCount=0; - int row=0; + data = BaseCommonApi::getBizDeviceManage(); + QString State; + //设置单页显示数量 + page=20; + // 创建分页表格控件 + PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); + pagedTable->setData(data.count(), page); // 每页10行 + connect(pagedTable, &PagedTableWidget::pageChanged, this,&Standard_DeviceItem::onpageChanged); + this->onpageChanged(0); - for (const BizDevice& bizDevice : data) { +} +void Standard_DeviceItem::onpageChanged(int currPage){ + + currPage+=1; + // 计算当前页的开始和结束索引 + int start = (currPage - 1) * page; + int end = std::min(start + page, data.size()); + // 从 QList 中筛选出当前页的数据 + QList tempdate = data.mid(start, end - start); + int rowCount = 0; + int row=0; + QString State; + ui->tableWidget->setRowCount(0); + for (const BizDevice& bizDevice : tempdate) { rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -147,8 +167,9 @@ SetHomePaheCombox(bizDevice); row++; } - } + + void Standard_DeviceItem::OnButtonSelectClicked(QString id) { //添加 diff --git a/softwareDirectory/AutoVerScheme/standard_deviceitem.h b/softwareDirectory/AutoVerScheme/standard_deviceitem.h index f522658..c506728 100644 --- a/softwareDirectory/AutoVerScheme/standard_deviceitem.h +++ b/softwareDirectory/AutoVerScheme/standard_deviceitem.h @@ -30,6 +30,9 @@ void on_pushButton_8_clicked(); public: QList data; + void onpageChanged(int currPage); + int page; + int totalcount; private: Ui::Standard_DeviceItem *ui; }; diff --git a/softwareDirectory/AutoVerScheme/standard_deviceitem.ui b/softwareDirectory/AutoVerScheme/standard_deviceitem.ui index 9b1acd4..861993d 100644 --- a/softwareDirectory/AutoVerScheme/standard_deviceitem.ui +++ b/softwareDirectory/AutoVerScheme/standard_deviceitem.ui @@ -233,6 +233,24 @@ + + + + + + + + Qt::Horizontal + + + + 1108 + 36 + + + + + diff --git a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro index bf70fab..d9a99ea 100644 --- a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro +++ b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro @@ -35,6 +35,7 @@ create_task.cpp \ createtask_scandevice.cpp \ databaseconnection.cpp \ + databaseconnectionmainsys.cpp \ datasyncview.cpp \ depar_task.cpp \ depar_task_server.cpp \ @@ -55,6 +56,7 @@ newverifymethod.cpp \ rulefileitem.cpp \ standard_deviceitem.cpp \ + syncdialog.cpp \ synctask.cpp \ testdataitem.cpp \ testview.cpp \ @@ -69,6 +71,7 @@ DataProcessingBLL.h \ PageControl.h \ createtask_scandevice.h \ + databaseconnectionmainsys.h \ formaddrsetting.h \ formcommsetting.h \ id/IdWorker.h \ @@ -104,6 +107,7 @@ newverifymethod.h \ rulefileitem.h \ standard_deviceitem.h \ + syncdialog.h \ synctask.h \ testdataitem.h \ testview.h \ @@ -138,6 +142,7 @@ newverifymethod.ui \ rulefileitem.ui \ standard_deviceitem.ui \ + syncdialog.ui \ testdataitem.ui \ testview.ui \ verifydevice.ui \ diff --git a/softwareDirectory/AutoVerScheme/PageControl.cpp b/softwareDirectory/AutoVerScheme/PageControl.cpp index d0fd72b..d1bdddc 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.cpp +++ b/softwareDirectory/AutoVerScheme/PageControl.cpp @@ -22,14 +22,14 @@ } } -void PagedTableWidget::setData(const QList> &data, int rowsPerPage,QTableWidget *table) { - tableWidget=table; - +void PagedTableWidget::setData(int datacount, int rowsPerPage) { + //tableWidget=table; + totaldatacount=datacount; this->rowsPerPage = rowsPerPage; - allData = data; + //allData = data; currentPage = 0; createPageButtons(); - updateTable(); + //updateTable(); } void PagedTableWidget::setCurrentPage(int page) { @@ -39,7 +39,7 @@ button->setChecked(false); }*/ currentPage = page; - updateTable(); + //updateTable(); emit pageChanged(page); } } @@ -89,6 +89,7 @@ setCurrentPage(pageIndex); } } +/* void PagedTableWidget::updateTable() { //tableWidget->clear(); tableWidget->setRowCount(0); @@ -105,7 +106,7 @@ } } } - +*/ void PagedTableWidget::createPageButtons() { int totalPages = calculateTotalPages(); for (auto button : pageButtons) { @@ -150,5 +151,5 @@ } int PagedTableWidget::calculateTotalPages() { - return ((allData.count() + rowsPerPage -1) / rowsPerPage); + return ((totaldatacount + rowsPerPage -1) / rowsPerPage); } diff --git a/softwareDirectory/AutoVerScheme/PageControl.h b/softwareDirectory/AutoVerScheme/PageControl.h index 74ed1ce..2224760 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.h +++ b/softwareDirectory/AutoVerScheme/PageControl.h @@ -15,7 +15,7 @@ explicit PagedTableWidget(QWidget *parent = nullptr,QHBoxLayout *PageLayout=NULL); ~PagedTableWidget(); - void setData(const QList> &data, int rowsPerPage = 10,QTableWidget *table=NULL); + void setData(int datacount, int rowsPerPage = 10); void setCurrentPage(int page); signals: @@ -30,6 +30,7 @@ QHBoxLayout *pageLayout; QList pageButtons; QList> allData; + int totaldatacount; int rowsPerPage; int currentPage; diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.cpp b/softwareDirectory/AutoVerScheme/basecommonapi.cpp index 49cbd7e..6f6fe94 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.cpp +++ b/softwareDirectory/AutoVerScheme/basecommonapi.cpp @@ -13,7 +13,7 @@ } const QString BaseCommonApi::temporary_user_id="1634107227953819649"; const QString BaseCommonApi::measure_person_id="1695282436182188034"; - +static SyncRunStatus syncstate=SyncRunStatus::Stopped; //sys_user表的id转换为measure_person_id 检定人id(meter_staff表id) @@ -167,7 +167,8 @@ "JOIN eqpt_equipment_info eei ON eei.id = blei.sample_id " "JOIN biz_business_order_info bo ON bo.id = blei.order_id " "LEFT JOIN sys_dept sd ON blei.measure_dept_id = sd.ID " - " WHERE blei.measure_person_id = :person_id " + " WHERE blei.measure_person_id = :person_id " + " AND blei.measure_status =3 or blei.measure_status = 4 " " ORDER BY blei.update_time DESC"); // 将参数绑定到占位符 @@ -175,7 +176,8 @@ //query.bindValue(":status", status); if (query.exec()) { while (query.next()) { - MyTask task; + + MyTask task; task.id = query.value("id").toString(); task.sample_name = query.value("sampleName").toString(); task.sample_model = query.value("sampleModel").toString(); @@ -2872,9 +2874,40 @@ return result; } +//保存log信息 +//log文件 + bool BaseCommonApi::SaveLogInfo(QString path,QString Info) +{ + QByteArray utf8Dat; + QString Message=Info; + QFile file(path); + // 如果目录不存在,则创建目录 + // 获取文件所在的目录 + QDir logDir = QDir(QFileInfo(path).absolutePath()); + if (!logDir.exists()) { + if (!logDir.mkpath(".")) { + qDebug() << "Failed to create log directory:" << logDir.absolutePath(); + return false; + } + } + + if (!file.open(QIODevice::Append | QIODevice::Text)) { + qDebug() << "无法打开文件:" << file.errorString(); + return false; + } + QTextStream out(&file); + utf8Dat = Message.toUtf8(); + out << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss") + << "\t" << utf8Dat << "\n"; + file.close(); + return true; + } + + //新增日志表数据 bool BaseCommonApi::InsertzdLog(zdLog log) { + log.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_log(id,is_sync,sync_time,remark,userid,type,create_time,update_time) " " VALUES(:id,:is_sync,:sync_time,:remark,:userid,:type,:create_time,:update_time) "); @@ -2898,6 +2931,7 @@ //根据userid查询日志表数据 QList BaseCommonApi::getzdLogByuserId(QString userid) { + userid=temporary_user_id; QList result; QSqlQuery query; query.prepare("SELECT * FROM zd_log WHERE userid = :userid "); @@ -2922,6 +2956,7 @@ //新增数据同步表 bool BaseCommonApi::InsertzdDataSync(zdDataSync data) { + data.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_data_sync(id,type,ssql,userid,remark,create_time,update_time,log_sync_id,sync_type) " " VALUES " @@ -2945,12 +2980,12 @@ return isSuccess; } //根据userid查询数据同步表 -QList getzdDataSyncByuserId(QString userid) +QList BaseCommonApi::getzdDataSyncByuserId(QString log_sync_id) { QList result; QSqlQuery query; - query.prepare("SELECT * FROM zd_data_sync WHERE userid= :userid "); - query.bindValue(":userid",userid); + query.prepare("SELECT * FROM zd_data_sync WHERE log_sync_id= :log_sync_id "); + query.bindValue(":log_sync_id",log_sync_id); if (query.exec()) { while (query.next()) { zdDataSync data; @@ -2972,3 +3007,4 @@ } + diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.h b/softwareDirectory/AutoVerScheme/basecommonapi.h index 12196fb..4949683 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.h +++ b/softwareDirectory/AutoVerScheme/basecommonapi.h @@ -919,6 +919,7 @@ QDateTime create_time; QDateTime update_time; }; + //数据同步-数据表 class zdDataSync { @@ -935,6 +936,12 @@ }; +enum class SyncRunStatus { + + Running, + Stopped, + Paused +}; using namespace Jiawa::Core; class BaseCommonApi @@ -945,7 +952,6 @@ const static QString temporary_costomer_id; const static QString measure_person_id; - QString encrypt(const QString &str, const QString &publicKey); //判断检定装置表并查询 参数设备id @@ -1137,14 +1143,19 @@ //单独查询任务单表 //更新 任务单 static InsertTask SelectTaskSingle(QString order_id); + + //log文件 + static bool SaveLogInfo(QString path,QString Info); + //新增日志表数据 static bool InsertzdLog(zdLog log); //查询日志表数据 static QList getzdLogByuserId(QString userid); //新增数据同步表 static bool InsertzdDataSync(zdDataSync data); - //根据userid查询数据同步表 - static QList getzdDataSyncByuserId(QString userid); + //根据log_sync_id查询数据同步表 + static QList getzdDataSyncByuserId(QString log_sync_id); + }; diff --git a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp index 00d746b..ae60962 100644 --- a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp @@ -352,6 +352,7 @@ } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -395,6 +396,7 @@ row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.cpp b/softwareDirectory/AutoVerScheme/databaseconnection.cpp index 1d957d9..5284fe6 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.cpp +++ b/softwareDirectory/AutoVerScheme/databaseconnection.cpp @@ -10,17 +10,21 @@ { // 连接数据库 - db = QSqlDatabase::addDatabase("QODBC"); - /*db.setHostName("111.198.10.15"); - db.setDatabaseName("casic_metering_xichang"); - db.setPort(21906); - db.setUserName("zdjdcs"); - db.setPassword("11111111");*/ - db.setHostName("localhost"); - db.setDatabaseName("zdjd"); - db.setPort(3306); - db.setUserName("root"); - db.setPassword("123456"); + localdb = QSqlDatabase::addDatabase("QODBC"); + + localdb.setHostName("localhost"); + localdb.setDatabaseName("zdjd"); + localdb.setPort(3306); + localdb.setUserName("root"); + localdb.setPassword("123456"); + + Maindb = QSqlDatabase::addDatabase("QODBC","Main"); + Maindb.setHostName("111.198.10.15"); + Maindb.setDatabaseName("casic_metering_xichang"); + Maindb.setPort(21906); + Maindb.setUserName("zdjdcs"); + Maindb.setPassword("11111111"); + } @@ -29,18 +33,28 @@ close(); } bool DatabaseConnection::open() { - return db.open(); + return localdb.open(); +} +bool DatabaseConnection::openmain() { + return Maindb.open(); } bool DatabaseConnection::isopen() { - return db.isOpen(); + return localdb.isOpen(); } - +bool DatabaseConnection::isopenmain() { + return Maindb.isOpen(); +} void DatabaseConnection::close() { - db.close(); + localdb.close(); } - +void DatabaseConnection::closemain() { + Maindb.close(); +} QSqlDatabase& DatabaseConnection::getDatabase() { - return db; + return localdb; +} +QSqlDatabase& DatabaseConnection::getDatabaseMain() { + return Maindb; } DatabaseConnection* DatabaseConnection::getInstance() { diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.h b/softwareDirectory/AutoVerScheme/databaseconnection.h index 586b794..5f9810b 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.h +++ b/softwareDirectory/AutoVerScheme/databaseconnection.h @@ -16,8 +16,12 @@ ~DatabaseConnection(); bool open(); bool isopen(); + bool openmain(); void close(); + void closemain(); + bool isopenmain(); QSqlDatabase& getDatabase(); + QSqlDatabase& getDatabaseMain(); private: //单列模式 保证DatabaseConnection的唯一性 static DatabaseConnection* Connect; @@ -33,7 +37,8 @@ //如果尝试这样做,编译器同样会报错。 DatabaseConnection& operator=(const DatabaseConnection&) = delete; //数据库db类 - QSqlDatabase db; + QSqlDatabase Maindb; + QSqlDatabase localdb; }; #endif // DATABASECONNECTION_H diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp new file mode 100644 index 0000000..080288b --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp @@ -0,0 +1,54 @@ +#include "databaseconnectionmainsys.h" + + + + +DatabaseConnectionMainSys* DatabaseConnectionMainSys::Connect = nullptr; +QMutex DatabaseConnectionMainSys::mutex; + +DatabaseConnectionMainSys::DatabaseConnectionMainSys() +{ + + // 连接数据库 + dbmain = QSqlDatabase::addDatabase("QODBC"); + dbmain.setHostName("111.198.10.15"); + dbmain.setDatabaseName("casic_metering_xichang"); + dbmain.setPort(21906); + dbmain.setUserName("zdjdcs"); + dbmain.setPassword("11111111"); + /* db.setHostName("localhost"); + db.setDatabaseName("zdjd"); + db.setPort(3306); + db.setUserName("root"); + db.setPassword("123456");*/ + + +} +DatabaseConnectionMainSys::~DatabaseConnectionMainSys() { + // 在析构函数中关闭数据库连接 + close(); +} +bool DatabaseConnectionMainSys::open() { + return dbmain.open(); +} +bool DatabaseConnectionMainSys::isopen() { + return dbmain.isOpen(); +} + +void DatabaseConnectionMainSys::close() { + dbmain.close(); +} + +QSqlDatabase& DatabaseConnectionMainSys::getDatabase() { + return dbmain; +} +DatabaseConnectionMainSys* DatabaseConnectionMainSys::getInstance() +{ + if (!Connect) { + QMutexLocker locker(&mutex); + if (!Connect) { + Connect = new DatabaseConnectionMainSys(); + } + } + return Connect; +} diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h new file mode 100644 index 0000000..57702ad --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h @@ -0,0 +1,41 @@ +#ifndef DATABASECONNECTIONMAINSYS_H +#define DATABASECONNECTIONMAINSYS_H +#include +#include +#include +#include + + +class DatabaseConnectionMainSys +{ + + +public: + //获取数据库实例 + static DatabaseConnectionMainSys* getInstance(); + + DatabaseConnectionMainSys(); + ~DatabaseConnectionMainSys(); + bool open(); + bool isopen(); + void close(); + QSqlDatabase& getDatabase(); +private: + //单列模式 保证MainSysDatabaseConnection的唯一性 + static DatabaseConnectionMainSys* Connect; + //QMutex 来确保在多线程环境下单例的正确创建。 + static QMutex mutex; + + //这是拷贝构造函数的声明,后面跟着 = delete; 表示这个构造函数被删除了。 + //这意味着你不能通过拷贝另一个 DatabaseConnection 对象来创建新的 DatabaseConnection 对象。 + //如果尝试这样做,编译器会报错。 + DatabaseConnectionMainSys(const DatabaseConnectionMainSys&) = delete; + //这是拷贝赋值运算符的声明,同样后面跟着 = delete; 表示这个运算符被删除了。 + //这意味着你不能将一个 DatabaseConnection 对象赋值给另一个 DatabaseConnection 对象。 + //如果尝试这样做,编译器同样会报错。 + DatabaseConnectionMainSys& operator=(const DatabaseConnectionMainSys&) = delete; + //数据库db类 + QSqlDatabase dbmain; +}; + +#endif // DATABASECONNECTIONMAINSYS_H diff --git a/softwareDirectory/AutoVerScheme/datasyncview.cpp b/softwareDirectory/AutoVerScheme/datasyncview.cpp index fbf4508..06c7f9a 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.cpp +++ b/softwareDirectory/AutoVerScheme/datasyncview.cpp @@ -1,11 +1,10 @@ #include "datasyncview.h" #include "ui_datasyncview.h" -#include "synctask.h" -#include "databaseconnection.h" -#include "mainsysdatabaseconnection.h" +#include "syncdialog.h" - +QString filePath = "C:\\AutoVerScheme\\sync_info.txt"; +// 获取当前时间戳 DataSyncView::DataSyncView(QWidget *parent) : QWidget(parent), ui(new Ui::DataSyncView) @@ -20,7 +19,7 @@ } void DataSyncView::initForm() { - //tableWidget设置 + ui->stackedWidget->setCurrentIndex(0); //设置控件的边框显示 ui->tableWidget->setStyleSheet("QHeaderView::section {" "border: 1px solid grey;" @@ -32,29 +31,129 @@ "}"); ui->tableWidget->setRowCount(10); // 设置10行 - ui->tableWidget->setColumnCount(4); // 设置11列 - ui->tableWidget->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnCount(7); // 设置11列 + ui->tableWidget->setColumnWidth(0, 0); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnWidth(2, 200); // 设置第一列的宽度为100像素 ui->tableWidget->verticalHeader()->setParent(nullptr); //隐藏行头 - QTableWidgetItem *item = new QTableWidgetItem("测试数据"); - item->setTextAlignment(Qt::AlignCenter); - ui->tableWidget->setItem(0, 0, item); //设置数据 + + //初始化TableWidget 设置列 QStringList headers; - headers << "序号" << "同步时间" << "是否同步成功" << "备注" ; + headers <<"id" << "序号" << "同步时间" << "是否同步成功" << "备注" + <<"类型" <<"操作"; ui->tableWidget->setHorizontalHeaderLabels(headers); + //详情内 + + //设置控件的边框显示 + ui->tableWidget_2->setStyleSheet("QHeaderView::section {" + "border: 1px solid grey;" + "border-left:none;" + "border-top:none;" + "background-color:white;" + " color:black;" + "font: bold 18px Arial, sans-serif;" + "}"); + + ui->tableWidget_2->setRowCount(10); // 设置10行 + ui->tableWidget_2->setColumnCount(3); // 设置11列 + ui->tableWidget_2->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget_2->verticalHeader()->setParent(nullptr); //隐藏行头 + ui->tableWidget_2->setColumnWidth(1, 1000); // 设置第一列的宽度为100像素 + + //初始化TableWidget 设置列 + + headers << "序号" << "信息" << "状态" ; + ui->tableWidget_2->setHorizontalHeaderLabels(headers); + + //数据显示 + + //先设置为行为0 + ui->tableWidget->setRowCount(0); + int rowCount=0; + int row=0; + QList zdlog= BaseCommonApi::getzdLogByuserId(""); + for(const zdLog & zd:zdlog) + { + rowCount = ui->tableWidget->rowCount(); + ui->tableWidget->insertRow(rowCount); + ui->tableWidget->setItem(row, 0, new QTableWidgetItem(zd.id)); + ui->tableWidget->setItem(row, 1, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget->setItem(row, 2, new QTableWidgetItem(zd.sync_time.toString())); + ui->tableWidget->setItem(row, 3, new QTableWidgetItem(zd.is_sync)); + ui->tableWidget->setItem(row, 4, new QTableWidgetItem(zd.remark)); + if(zd.type=="1") + { + ui->tableWidget->setItem(row, 5, new QTableWidgetItem("下载")); + }else{ ui->tableWidget->setItem(row, 5, new QTableWidgetItem("上传")); } + + //添加操作按钮 + QPushButton *button = new QPushButton("查询信息"); + button->setIconSize(QSize(16,16)); + button->setIcon(QIcon(":/image/Index/u2327.svg")); + ui->tableWidget->setCellWidget(row, 6, button); + //设置按钮简单样式 + button->setStyleSheet("QPushButton {" + " border: none; /* 无边框 */" + " color: green; /* 文本颜色 */" + " text-decoration: underline; /* 文本下划线 */" + "}"); + + // 设置鼠标悬停时的光标样式为小手图标 + button->setCursor(Qt::PointingHandCursor); + // 连接按钮的 clicked 信号到自定义槽函数 + connect(button, &QPushButton::clicked, this, [this, button, zd]() { + // 获取当前行第一列的 ID + + OnButtonSelectClicked(zd); + + }); + row++; + } } void DataSyncView::on_DownloadDataButton_clicked() { - //从主系统下载 + + SyncDialog *syncDialog = new SyncDialog(this); + syncDialog->exec(); // 显示进度条窗体并阻塞主窗口 + + this->initForm(); + } -void DataSyncView::syncTable() +void DataSyncView::OnButtonSelectClicked(zdLog log) { - //连接两个数据库 - bool IsOpen=false; - DatabaseConnection *Conn=DatabaseConnection::getInstance(); - IsOpen=Conn->open(); - //MainSysDatabaseConnection *MainConn=MainSysDatabaseConnection::getInstance(); - //IsOpen=MainConn->open(); + ui->stackedWidget->setCurrentIndex(1); + ui->tableWidget_2->setRowCount(0); + int rowCount=0; + int row=0; + QList data= BaseCommonApi::getzdDataSyncByuserId(log.id); + for(const zdDataSync & item:data) + { + rowCount = ui->tableWidget_2->rowCount(); + ui->tableWidget_2->insertRow(rowCount); + ui->tableWidget_2->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget_2->setItem(row, 1, new QTableWidgetItem(item.remark)); + QTableWidgetItem *itemRow; + if(item.sync_type=="0"){ + itemRow = new QTableWidgetItem("未同步"); + itemRow->setBackground(QBrush(QColor(255, 255, 192))); + }else if (item.sync_type=="1") + { + itemRow = new QTableWidgetItem("同步成功"); + itemRow->setBackground(QBrush(QColor(173, 255, 47))); // 浅绿色 + }else{ + itemRow = new QTableWidgetItem("同步失败"); + itemRow->setBackground(QBrush(QColor(255, 105, 180))); // 浅红色 + } + itemRow->setTextAlignment(Qt::AlignCenter); + ui->tableWidget_2->setItem(row, 2, itemRow); + + row++; + } +} + +void DataSyncView::on_button_return_clicked() +{ + ui->stackedWidget->setCurrentIndex(0); } diff --git a/softwareDirectory/AutoVerScheme/datasyncview.h b/softwareDirectory/AutoVerScheme/datasyncview.h index 174480e..b2b9847 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.h +++ b/softwareDirectory/AutoVerScheme/datasyncview.h @@ -2,6 +2,16 @@ #define DATASYNCVIEW_H #include +#include +#include "synctask.h" +#include "databaseconnection.h" +#include "basecommonapi.h" +#include "databaseconnectionmainsys.h" +#include +#include +#include +#include +#include namespace Ui { class DataSyncView; @@ -18,8 +28,12 @@ void initForm(); //初始化界面数据 void on_DownloadDataButton_clicked(); - //异步更新 - void syncTable(); + void OnButtonSelectClicked(zdLog log); + void on_button_return_clicked(); + +public: + + private: Ui::DataSyncView *ui; }; diff --git a/softwareDirectory/AutoVerScheme/datasyncview.ui b/softwareDirectory/AutoVerScheme/datasyncview.ui index 53c379c..7c9df8e 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.ui +++ b/softwareDirectory/AutoVerScheme/datasyncview.ui @@ -14,21 +14,9 @@ 数据同步 - background-color:rgba(240, 240, 240, 1); + background-color:white; - - - 0 - - - 0 - - - 0 - - - 0 - + @@ -73,119 +61,173 @@ - - - background-color:white; - - - - - - - 3 - - - - - - 0 - 0 - - - - background-color:white; + + + + + + + background-color:white; + + + + + + + 3 + + + + + + 0 + 0 + + + + background-color:white; border:0; - - - - - - - - - - 0 - 0 - - - - font:bold 20px Arial, sans-serif; + + + + + + + + + + 0 + 0 + + + + font:bold 20px Arial, sans-serif; color:#334582; - - - 同步记录 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - background-color:#334582; + + + 同步记录 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + background-color:#334582; font: bold 18px Arial, sans-serif; color:white; padding:10px; - - - 下载数据 - - - - - - - - 200 - 0 - - - - - 100 - 40 - - - - Qt::RightToLeft - - - background-color:#334582; + + + 下载数据 + + + + + + + + 200 + 0 + + + + + 100 + 40 + + + + Qt::RightToLeft + + + background-color:#334582; font: bold 18px Arial, sans-serif; color:white; padding:10px; - - - 发送同步请求 - - - - :/image/Index/u8458.svg:/image/Index/u8458.svg - - - - - - - - - - - - - - + + + 发送同步请求 + + + + :/image/Index/u8458.svg:/image/Index/u8458.svg + + + + + + + + + + + + + + + + + + + + + + + + background-color:white; + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + color:black; + + + 返回 + + + + + + + + + + + + + diff --git a/softwareDirectory/AutoVerScheme/depar_task.cpp b/softwareDirectory/AutoVerScheme/depar_task.cpp index d551972..d58cf35 100644 --- a/softwareDirectory/AutoVerScheme/depar_task.cpp +++ b/softwareDirectory/AutoVerScheme/depar_task.cpp @@ -113,6 +113,7 @@ else State="否"; ui->tableWidget->setItem(row, 9, new QTableWidgetItem(State)); //设置数据 + SetHomePaheCombox(dept); //添加 PageData数据 TempData.append(QString::number(row+1)); TempData.append(dept.sample_name); @@ -133,9 +134,9 @@ //设置分页控件 // 创建分页表格控件 - PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); +// PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); //data转换位QList> - pagedTable->setData(PageData, 20,ui->tableWidget); // 每页20行 + // pagedTable->setData(PageData, 20,ui->tableWidget); // 每页20行 } void Depar_Task::on_SelectButton_clicked() @@ -155,26 +156,31 @@ if(dept.measure_status=="3" || dept.measure_status=="4"){ bool shouldAddRow = true; // 初始假设应该添加这一行 // 根据设备名称筛选 + QString names; if (ui->name->currentText() != "ALL") { + names=ui->name->currentText(); if (ui->name->currentText() != dept.sample_name) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } if (ui->mode->currentText() != "ALL") { + names=ui->mode->currentText(); if (ui->mode->currentText() != dept.sample_model) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } if (ui->customer->currentText() != "ALL") { + if (ui->customer->currentText() != dept.customer_name) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } - if (ui->dept->currentText() != "") { + if (ui->dept->currentText() != "ALL") { if (ui->dept->currentText() != dept.FULL_NAME) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); ui->tableWidget->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); @@ -193,9 +199,10 @@ State="否"; ui->tableWidget->setItem(row, 9, new QTableWidgetItem(State)); //设置数据 // - SetHomePaheCombox(dept); + //QDebug row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/indexwindow.cpp b/softwareDirectory/AutoVerScheme/indexwindow.cpp index eed192a..060b86e 100644 --- a/softwareDirectory/AutoVerScheme/indexwindow.cpp +++ b/softwareDirectory/AutoVerScheme/indexwindow.cpp @@ -58,7 +58,7 @@ DatabaseConnection *Conn=DatabaseConnection::getInstance(); //数据库连接 目前先放这里 后续需要放到登录界面 - bool IsOpen=Conn->open(); + bool IsOpen=Conn->open(); if(IsOpen) ShowMessageBox("数据库连接","连接成功"); else diff --git a/softwareDirectory/AutoVerScheme/my_task.cpp b/softwareDirectory/AutoVerScheme/my_task.cpp index 1735575..cd735f8 100644 --- a/softwareDirectory/AutoVerScheme/my_task.cpp +++ b/softwareDirectory/AutoVerScheme/my_task.cpp @@ -62,7 +62,8 @@ } void My_Task::Load() { - QList> PageData; + + //QList> PageData; //先设置为行为0 ui->tableWidget->setRowCount(0); //添加comboBox @@ -86,11 +87,29 @@ QString userId=""; data = BaseCommonApi::getMyTasks(userId,"3"); + QString State; + //设置单页显示数量 + page=20; + // 创建分页表格控件 + PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); + pagedTable->setData(data.count(), page); // 每页10行 + connect(pagedTable, &PagedTableWidget::pageChanged, this,&My_Task::onpageChanged); + this->onpageChanged(0); + +} +void My_Task::onpageChanged(int currPage){ + currPage+=1; + // 计算当前页的开始和结束索引 + int start = (currPage - 1) * page; + int end = std::min(start + page, data.size()); + // 从 QList 中筛选出当前页的数据 + QList tempdate = data.mid(start, end - start); int rowCount = 0; int row=0; QString State; - for (const MyTask& myTask : data) { - if(myTask.measure_status=="3" || myTask.measure_status=="4"){ + ui->tableWidget->setRowCount(0); + for (const MyTask& myTask : tempdate) { + QList TempData; rowCount = ui->tableWidget->rowCount(); @@ -118,42 +137,15 @@ ui->tableWidget->setItem(row, 10,new QTableWidgetItem("检测完成")); } - //渲染下拉框 - SetHomePaheCombox(myTask); - //QDebug - - //添加 PageData数据 - TempData.append(QString::number(row+1)); - TempData.append(myTask.sample_name); - TempData.append(myTask.sample_model); - TempData.append(myTask.help_instruction); - TempData.append(myTask.manufacture_no); - TempData.append(myTask.manufacturer); - TempData.append(myTask.customer_name); - TempData.append(myTask.FULL_NAME); - TempData.append(myTask.require_over_time.toString()); - TempData.append(State); - TempData.append(myTask.measure_status); - PageData.append(TempData); + //渲染下拉框 + SetHomePaheCombox(myTask); row++; - } - - } - //设置分页控件 - // 创建分页表格控件 - - PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); - //data转换位QList> - pagedTable->setData(PageData, 20,ui->tableWidget); // 每页10行 - //ui->HBoxPageLayout->addWidget(pagedTable); - //setLayout(ui->HBoxPageLayout); - // 连接信号以处理页码变化 - /* connect(pagedTable, &PagedTableWidget::pageChanged, this, [=](int page) { - // 在这里处理页码变化事件,比如更新UI中的其他部分 - qDebug() << "Page changed to:" << page; - });*/ + }; + //按钮点击事件 + // QMessageBox::information(this, "点击按钮",QString::number(page)); + // qDebug() << "Page changed to:" << page; } void My_Task::SetHomePaheCombox(MyTask entity) { diff --git a/softwareDirectory/AutoVerScheme/my_task.h b/softwareDirectory/AutoVerScheme/my_task.h index 289e7f4..8a4ad07 100644 --- a/softwareDirectory/AutoVerScheme/my_task.h +++ b/softwareDirectory/AutoVerScheme/my_task.h @@ -26,9 +26,11 @@ void on_pushButtonUpdate_clicked(); void on_SeachButton_clicked(); + void onpageChanged(int page); public: QList data; - + int page; + int totalcount; private: Ui::My_Task *ui; }; diff --git a/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp b/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp index e9cfb66..3ef9d60 100644 --- a/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp @@ -3,7 +3,7 @@ #include "InfoBase.h" #include "QMessageBox" #include "basecommonapi.h" - +#include "PageControl.h" //标准设备管理 .cpp Standard_DeviceItem::Standard_DeviceItem(QWidget *parent) : @@ -32,7 +32,7 @@ // ui->tableWidget->setRowCount(10); // 设置10行 ui->tableWidget->setColumnCount(7); // 设置11列 - ui->tableWidget->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnWidth(0, 0); // 设置第一列的宽度为100像素 ui->tableWidget->verticalHeader()->setParent(nullptr); //隐藏行头 //QTableWidgetItem *item = new QTableWidgetItem("测试数据"); //item->setTextAlignment(Qt::AlignCenter); @@ -102,12 +102,32 @@ // 调用数据库管理器的函数获取数据 - int rowCount=0; - int row=0; + data = BaseCommonApi::getBizDeviceManage(); + QString State; + //设置单页显示数量 + page=20; + // 创建分页表格控件 + PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); + pagedTable->setData(data.count(), page); // 每页10行 + connect(pagedTable, &PagedTableWidget::pageChanged, this,&Standard_DeviceItem::onpageChanged); + this->onpageChanged(0); - for (const BizDevice& bizDevice : data) { +} +void Standard_DeviceItem::onpageChanged(int currPage){ + + currPage+=1; + // 计算当前页的开始和结束索引 + int start = (currPage - 1) * page; + int end = std::min(start + page, data.size()); + // 从 QList 中筛选出当前页的数据 + QList tempdate = data.mid(start, end - start); + int rowCount = 0; + int row=0; + QString State; + ui->tableWidget->setRowCount(0); + for (const BizDevice& bizDevice : tempdate) { rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -147,8 +167,9 @@ SetHomePaheCombox(bizDevice); row++; } - } + + void Standard_DeviceItem::OnButtonSelectClicked(QString id) { //添加 diff --git a/softwareDirectory/AutoVerScheme/standard_deviceitem.h b/softwareDirectory/AutoVerScheme/standard_deviceitem.h index f522658..c506728 100644 --- a/softwareDirectory/AutoVerScheme/standard_deviceitem.h +++ b/softwareDirectory/AutoVerScheme/standard_deviceitem.h @@ -30,6 +30,9 @@ void on_pushButton_8_clicked(); public: QList data; + void onpageChanged(int currPage); + int page; + int totalcount; private: Ui::Standard_DeviceItem *ui; }; diff --git a/softwareDirectory/AutoVerScheme/standard_deviceitem.ui b/softwareDirectory/AutoVerScheme/standard_deviceitem.ui index 9b1acd4..861993d 100644 --- a/softwareDirectory/AutoVerScheme/standard_deviceitem.ui +++ b/softwareDirectory/AutoVerScheme/standard_deviceitem.ui @@ -233,6 +233,24 @@ + + + + + + + + Qt::Horizontal + + + + 1108 + 36 + + + + + diff --git a/softwareDirectory/AutoVerScheme/syncdialog.cpp b/softwareDirectory/AutoVerScheme/syncdialog.cpp new file mode 100644 index 0000000..f9195f1 --- /dev/null +++ b/softwareDirectory/AutoVerScheme/syncdialog.cpp @@ -0,0 +1,207 @@ +#include "syncdialog.h" +#include "ui_syncdialog.h" + + +int SyncDialog::m_totalTasks; +int SyncDialog::stepcount; +int SyncDialog::filecount; + + +SyncDialog::SyncDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::SyncDialog) +{ + ui->setupUi(this); + + + +} + +SyncDialog::~SyncDialog() +{ + delete ui; +} + +void SyncDialog::on_button_Start_clicked() +{ + + + //qint64 id = dbmang.generateId(); + //zdlogId=QString::number(id); + zdDataSyncList.clear(); + querydstList.clear(); + //从主系统下载 + //连接两个数据库 + bool IsOpen=false; + bool IsOpenMain=false; + + DatabaseConnection *Conn=DatabaseConnection::getInstance(); + //DatabaseConnectionMainSys *MainConn=DatabaseConnectionMainSys::getInstance(); + if(!Conn->isopen()){IsOpen=Conn->open();}else{IsOpen=true;}; + if(!Conn->isopenmain()){IsOpenMain=Conn->openmain();}else{IsOpenMain=true;}; + + // 记录任务数量 + + m_totalTasks=0; + stepcount=0; + filecount=0; + // 获取第一个数据库的所有表名 + dstDb=Conn->getDatabase(); + srcDb=Conn->getDatabaseMain(); + QSqlQuery querydst(dstDb); + querydst.exec("SHOW TABLES"); + QSqlQuery query(srcDb); + query.exec("SHOW TABLES"); + + while(querydst.next()){ + QString tableName = querydst.value(0).toString(); + if(tableName.contains("act_") ||tableName.contains("flw_ru_")){continue;}; + querydstList.append(tableName);}; + // 创建一个线程池 + threadPool= QThreadPool::globalInstance(); + threadPool->setMaxThreadCount(5); // 设置线程池中的最大线程数 + // 遍历表名,为每个表创建一个任务并提交到线程池 + BaseCommonApi::SaveLogInfo(filePath,"开始下载同步"); + + while (query.next()) { + QString tableName = query.value(0).toString(); + if(!querydstList.contains(tableName)){continue;}; + if(tableName.contains("ACT_") ||tableName.contains("FLW_RU_")){continue;}; + SyncTask *task = new SyncTask(srcDb, dstDb, tableName); + connectTaskSignals(task); + // 提交任务到线程池 + threadPool->start(task); + ++m_totalTasks; + // + + } + //总数量 + ui->lab_sum->setText(QString::number(m_totalTasks)); + progressDecrement=static_cast(100) / m_totalTasks; + +} +void SyncDialog::connectTaskSignals(SyncTask *task) { + connect(task, &SyncTask::taskCompleted, this, &SyncDialog::onTaskCompleted); + connect(task, &SyncTask::TextState, this, &SyncDialog::onTextState); + connect(this,&SyncDialog::StopRequested,task,&SyncTask::UpdateState); + //当前正在执行的 +} +void SyncDialog::onTaskCompleted(int success,QString tableName, const QString& errorMessage) +{ + if(success!=2){ + if(querydstList.contains(tableName)){querydstList.removeAll(tableName);}; + //添加同步表 + //任务完成 任务失败 都需要添加 + qint64 id = dbmang.generateId(); + zdDataSync zdDataSyncentity; + zdDataSyncentity.id=QString::number(id);; + zdDataSyncentity.remark=errorMessage; + zdDataSyncentity.log_sync_id=""; + zdDataSyncentity.sync_type=QString::number(success+1); + zdDataSyncList.append(zdDataSyncentity); + // dbmang.InsertzdDataSync(zdDataSyncentity); + }; + QString mess; + if (success==0) { + // 任务成功完成 + mess = "任务完成"; + mess+=errorMessage; + + } else if(success==1){ + // 任务执行失败 + mess = "任务失败"; + mess +=errorMessage; + filecount++; + //失败数量 + ui->lab_fail->setText(QString::number(filecount));; + }else{ + mess = "正在执行"; + mess +=errorMessage+"....."; + } + //log保存 + BaseCommonApi::SaveLogInfo(filePath,mess); + //界面listview显示 + ui->listWidget->addItem(mess); + // 当添加新项后,滚动到底部 + ui->listWidget->scrollToBottom(); + +} +void SyncDialog::onTextState() +{ + + stepcount++; + //成功数量 + ui->lab_succ->setText(QString::number(stepcount));; + //更新进度条 + int progress = static_cast(progressDecrement * stepcount); + ui->progressBar->setValue(progress); + if(stepcount>=m_totalTasks) + { + this->StopSync(); + } + +} + +void SyncDialog::on_button_Close_clicked() +{ + emit StopRequested(2); + threadPool->waitForDone(); + this->StopSync(); + srcDb.close(); + this->close(); +} +void SyncDialog::StopSync() +{ + ui->progressBar->setValue(100); + srcDb.close(); + //dstDb.close(); + + //添加日志表 + zdLog zlog; + zlog.id=QString::number( dbmang.generateId());; + zlog.type="1"; + if(filecount==0) + { + zlog.is_sync="成功"; + }else + { + zlog.is_sync="失败"; + } + zlog.sync_time=QDateTime::currentDateTime(); + zlog.remark="错误数量"+QString::number(filecount); + dbmang.InsertzdLog(zlog); + //添加记录表 + for (int i=0;ibutton_step->text()=="暂停") + { + ui->button_step->setText("继续"); + emit StopRequested(1); + + + }else{ + ui->button_step->setText("暂停"); + emit StopRequested(0); + }; +} diff --git a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro index bf70fab..d9a99ea 100644 --- a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro +++ b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro @@ -35,6 +35,7 @@ create_task.cpp \ createtask_scandevice.cpp \ databaseconnection.cpp \ + databaseconnectionmainsys.cpp \ datasyncview.cpp \ depar_task.cpp \ depar_task_server.cpp \ @@ -55,6 +56,7 @@ newverifymethod.cpp \ rulefileitem.cpp \ standard_deviceitem.cpp \ + syncdialog.cpp \ synctask.cpp \ testdataitem.cpp \ testview.cpp \ @@ -69,6 +71,7 @@ DataProcessingBLL.h \ PageControl.h \ createtask_scandevice.h \ + databaseconnectionmainsys.h \ formaddrsetting.h \ formcommsetting.h \ id/IdWorker.h \ @@ -104,6 +107,7 @@ newverifymethod.h \ rulefileitem.h \ standard_deviceitem.h \ + syncdialog.h \ synctask.h \ testdataitem.h \ testview.h \ @@ -138,6 +142,7 @@ newverifymethod.ui \ rulefileitem.ui \ standard_deviceitem.ui \ + syncdialog.ui \ testdataitem.ui \ testview.ui \ verifydevice.ui \ diff --git a/softwareDirectory/AutoVerScheme/PageControl.cpp b/softwareDirectory/AutoVerScheme/PageControl.cpp index d0fd72b..d1bdddc 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.cpp +++ b/softwareDirectory/AutoVerScheme/PageControl.cpp @@ -22,14 +22,14 @@ } } -void PagedTableWidget::setData(const QList> &data, int rowsPerPage,QTableWidget *table) { - tableWidget=table; - +void PagedTableWidget::setData(int datacount, int rowsPerPage) { + //tableWidget=table; + totaldatacount=datacount; this->rowsPerPage = rowsPerPage; - allData = data; + //allData = data; currentPage = 0; createPageButtons(); - updateTable(); + //updateTable(); } void PagedTableWidget::setCurrentPage(int page) { @@ -39,7 +39,7 @@ button->setChecked(false); }*/ currentPage = page; - updateTable(); + //updateTable(); emit pageChanged(page); } } @@ -89,6 +89,7 @@ setCurrentPage(pageIndex); } } +/* void PagedTableWidget::updateTable() { //tableWidget->clear(); tableWidget->setRowCount(0); @@ -105,7 +106,7 @@ } } } - +*/ void PagedTableWidget::createPageButtons() { int totalPages = calculateTotalPages(); for (auto button : pageButtons) { @@ -150,5 +151,5 @@ } int PagedTableWidget::calculateTotalPages() { - return ((allData.count() + rowsPerPage -1) / rowsPerPage); + return ((totaldatacount + rowsPerPage -1) / rowsPerPage); } diff --git a/softwareDirectory/AutoVerScheme/PageControl.h b/softwareDirectory/AutoVerScheme/PageControl.h index 74ed1ce..2224760 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.h +++ b/softwareDirectory/AutoVerScheme/PageControl.h @@ -15,7 +15,7 @@ explicit PagedTableWidget(QWidget *parent = nullptr,QHBoxLayout *PageLayout=NULL); ~PagedTableWidget(); - void setData(const QList> &data, int rowsPerPage = 10,QTableWidget *table=NULL); + void setData(int datacount, int rowsPerPage = 10); void setCurrentPage(int page); signals: @@ -30,6 +30,7 @@ QHBoxLayout *pageLayout; QList pageButtons; QList> allData; + int totaldatacount; int rowsPerPage; int currentPage; diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.cpp b/softwareDirectory/AutoVerScheme/basecommonapi.cpp index 49cbd7e..6f6fe94 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.cpp +++ b/softwareDirectory/AutoVerScheme/basecommonapi.cpp @@ -13,7 +13,7 @@ } const QString BaseCommonApi::temporary_user_id="1634107227953819649"; const QString BaseCommonApi::measure_person_id="1695282436182188034"; - +static SyncRunStatus syncstate=SyncRunStatus::Stopped; //sys_user表的id转换为measure_person_id 检定人id(meter_staff表id) @@ -167,7 +167,8 @@ "JOIN eqpt_equipment_info eei ON eei.id = blei.sample_id " "JOIN biz_business_order_info bo ON bo.id = blei.order_id " "LEFT JOIN sys_dept sd ON blei.measure_dept_id = sd.ID " - " WHERE blei.measure_person_id = :person_id " + " WHERE blei.measure_person_id = :person_id " + " AND blei.measure_status =3 or blei.measure_status = 4 " " ORDER BY blei.update_time DESC"); // 将参数绑定到占位符 @@ -175,7 +176,8 @@ //query.bindValue(":status", status); if (query.exec()) { while (query.next()) { - MyTask task; + + MyTask task; task.id = query.value("id").toString(); task.sample_name = query.value("sampleName").toString(); task.sample_model = query.value("sampleModel").toString(); @@ -2872,9 +2874,40 @@ return result; } +//保存log信息 +//log文件 + bool BaseCommonApi::SaveLogInfo(QString path,QString Info) +{ + QByteArray utf8Dat; + QString Message=Info; + QFile file(path); + // 如果目录不存在,则创建目录 + // 获取文件所在的目录 + QDir logDir = QDir(QFileInfo(path).absolutePath()); + if (!logDir.exists()) { + if (!logDir.mkpath(".")) { + qDebug() << "Failed to create log directory:" << logDir.absolutePath(); + return false; + } + } + + if (!file.open(QIODevice::Append | QIODevice::Text)) { + qDebug() << "无法打开文件:" << file.errorString(); + return false; + } + QTextStream out(&file); + utf8Dat = Message.toUtf8(); + out << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss") + << "\t" << utf8Dat << "\n"; + file.close(); + return true; + } + + //新增日志表数据 bool BaseCommonApi::InsertzdLog(zdLog log) { + log.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_log(id,is_sync,sync_time,remark,userid,type,create_time,update_time) " " VALUES(:id,:is_sync,:sync_time,:remark,:userid,:type,:create_time,:update_time) "); @@ -2898,6 +2931,7 @@ //根据userid查询日志表数据 QList BaseCommonApi::getzdLogByuserId(QString userid) { + userid=temporary_user_id; QList result; QSqlQuery query; query.prepare("SELECT * FROM zd_log WHERE userid = :userid "); @@ -2922,6 +2956,7 @@ //新增数据同步表 bool BaseCommonApi::InsertzdDataSync(zdDataSync data) { + data.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_data_sync(id,type,ssql,userid,remark,create_time,update_time,log_sync_id,sync_type) " " VALUES " @@ -2945,12 +2980,12 @@ return isSuccess; } //根据userid查询数据同步表 -QList getzdDataSyncByuserId(QString userid) +QList BaseCommonApi::getzdDataSyncByuserId(QString log_sync_id) { QList result; QSqlQuery query; - query.prepare("SELECT * FROM zd_data_sync WHERE userid= :userid "); - query.bindValue(":userid",userid); + query.prepare("SELECT * FROM zd_data_sync WHERE log_sync_id= :log_sync_id "); + query.bindValue(":log_sync_id",log_sync_id); if (query.exec()) { while (query.next()) { zdDataSync data; @@ -2972,3 +3007,4 @@ } + diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.h b/softwareDirectory/AutoVerScheme/basecommonapi.h index 12196fb..4949683 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.h +++ b/softwareDirectory/AutoVerScheme/basecommonapi.h @@ -919,6 +919,7 @@ QDateTime create_time; QDateTime update_time; }; + //数据同步-数据表 class zdDataSync { @@ -935,6 +936,12 @@ }; +enum class SyncRunStatus { + + Running, + Stopped, + Paused +}; using namespace Jiawa::Core; class BaseCommonApi @@ -945,7 +952,6 @@ const static QString temporary_costomer_id; const static QString measure_person_id; - QString encrypt(const QString &str, const QString &publicKey); //判断检定装置表并查询 参数设备id @@ -1137,14 +1143,19 @@ //单独查询任务单表 //更新 任务单 static InsertTask SelectTaskSingle(QString order_id); + + //log文件 + static bool SaveLogInfo(QString path,QString Info); + //新增日志表数据 static bool InsertzdLog(zdLog log); //查询日志表数据 static QList getzdLogByuserId(QString userid); //新增数据同步表 static bool InsertzdDataSync(zdDataSync data); - //根据userid查询数据同步表 - static QList getzdDataSyncByuserId(QString userid); + //根据log_sync_id查询数据同步表 + static QList getzdDataSyncByuserId(QString log_sync_id); + }; diff --git a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp index 00d746b..ae60962 100644 --- a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp @@ -352,6 +352,7 @@ } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -395,6 +396,7 @@ row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.cpp b/softwareDirectory/AutoVerScheme/databaseconnection.cpp index 1d957d9..5284fe6 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.cpp +++ b/softwareDirectory/AutoVerScheme/databaseconnection.cpp @@ -10,17 +10,21 @@ { // 连接数据库 - db = QSqlDatabase::addDatabase("QODBC"); - /*db.setHostName("111.198.10.15"); - db.setDatabaseName("casic_metering_xichang"); - db.setPort(21906); - db.setUserName("zdjdcs"); - db.setPassword("11111111");*/ - db.setHostName("localhost"); - db.setDatabaseName("zdjd"); - db.setPort(3306); - db.setUserName("root"); - db.setPassword("123456"); + localdb = QSqlDatabase::addDatabase("QODBC"); + + localdb.setHostName("localhost"); + localdb.setDatabaseName("zdjd"); + localdb.setPort(3306); + localdb.setUserName("root"); + localdb.setPassword("123456"); + + Maindb = QSqlDatabase::addDatabase("QODBC","Main"); + Maindb.setHostName("111.198.10.15"); + Maindb.setDatabaseName("casic_metering_xichang"); + Maindb.setPort(21906); + Maindb.setUserName("zdjdcs"); + Maindb.setPassword("11111111"); + } @@ -29,18 +33,28 @@ close(); } bool DatabaseConnection::open() { - return db.open(); + return localdb.open(); +} +bool DatabaseConnection::openmain() { + return Maindb.open(); } bool DatabaseConnection::isopen() { - return db.isOpen(); + return localdb.isOpen(); } - +bool DatabaseConnection::isopenmain() { + return Maindb.isOpen(); +} void DatabaseConnection::close() { - db.close(); + localdb.close(); } - +void DatabaseConnection::closemain() { + Maindb.close(); +} QSqlDatabase& DatabaseConnection::getDatabase() { - return db; + return localdb; +} +QSqlDatabase& DatabaseConnection::getDatabaseMain() { + return Maindb; } DatabaseConnection* DatabaseConnection::getInstance() { diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.h b/softwareDirectory/AutoVerScheme/databaseconnection.h index 586b794..5f9810b 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.h +++ b/softwareDirectory/AutoVerScheme/databaseconnection.h @@ -16,8 +16,12 @@ ~DatabaseConnection(); bool open(); bool isopen(); + bool openmain(); void close(); + void closemain(); + bool isopenmain(); QSqlDatabase& getDatabase(); + QSqlDatabase& getDatabaseMain(); private: //单列模式 保证DatabaseConnection的唯一性 static DatabaseConnection* Connect; @@ -33,7 +37,8 @@ //如果尝试这样做,编译器同样会报错。 DatabaseConnection& operator=(const DatabaseConnection&) = delete; //数据库db类 - QSqlDatabase db; + QSqlDatabase Maindb; + QSqlDatabase localdb; }; #endif // DATABASECONNECTION_H diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp new file mode 100644 index 0000000..080288b --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp @@ -0,0 +1,54 @@ +#include "databaseconnectionmainsys.h" + + + + +DatabaseConnectionMainSys* DatabaseConnectionMainSys::Connect = nullptr; +QMutex DatabaseConnectionMainSys::mutex; + +DatabaseConnectionMainSys::DatabaseConnectionMainSys() +{ + + // 连接数据库 + dbmain = QSqlDatabase::addDatabase("QODBC"); + dbmain.setHostName("111.198.10.15"); + dbmain.setDatabaseName("casic_metering_xichang"); + dbmain.setPort(21906); + dbmain.setUserName("zdjdcs"); + dbmain.setPassword("11111111"); + /* db.setHostName("localhost"); + db.setDatabaseName("zdjd"); + db.setPort(3306); + db.setUserName("root"); + db.setPassword("123456");*/ + + +} +DatabaseConnectionMainSys::~DatabaseConnectionMainSys() { + // 在析构函数中关闭数据库连接 + close(); +} +bool DatabaseConnectionMainSys::open() { + return dbmain.open(); +} +bool DatabaseConnectionMainSys::isopen() { + return dbmain.isOpen(); +} + +void DatabaseConnectionMainSys::close() { + dbmain.close(); +} + +QSqlDatabase& DatabaseConnectionMainSys::getDatabase() { + return dbmain; +} +DatabaseConnectionMainSys* DatabaseConnectionMainSys::getInstance() +{ + if (!Connect) { + QMutexLocker locker(&mutex); + if (!Connect) { + Connect = new DatabaseConnectionMainSys(); + } + } + return Connect; +} diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h new file mode 100644 index 0000000..57702ad --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h @@ -0,0 +1,41 @@ +#ifndef DATABASECONNECTIONMAINSYS_H +#define DATABASECONNECTIONMAINSYS_H +#include +#include +#include +#include + + +class DatabaseConnectionMainSys +{ + + +public: + //获取数据库实例 + static DatabaseConnectionMainSys* getInstance(); + + DatabaseConnectionMainSys(); + ~DatabaseConnectionMainSys(); + bool open(); + bool isopen(); + void close(); + QSqlDatabase& getDatabase(); +private: + //单列模式 保证MainSysDatabaseConnection的唯一性 + static DatabaseConnectionMainSys* Connect; + //QMutex 来确保在多线程环境下单例的正确创建。 + static QMutex mutex; + + //这是拷贝构造函数的声明,后面跟着 = delete; 表示这个构造函数被删除了。 + //这意味着你不能通过拷贝另一个 DatabaseConnection 对象来创建新的 DatabaseConnection 对象。 + //如果尝试这样做,编译器会报错。 + DatabaseConnectionMainSys(const DatabaseConnectionMainSys&) = delete; + //这是拷贝赋值运算符的声明,同样后面跟着 = delete; 表示这个运算符被删除了。 + //这意味着你不能将一个 DatabaseConnection 对象赋值给另一个 DatabaseConnection 对象。 + //如果尝试这样做,编译器同样会报错。 + DatabaseConnectionMainSys& operator=(const DatabaseConnectionMainSys&) = delete; + //数据库db类 + QSqlDatabase dbmain; +}; + +#endif // DATABASECONNECTIONMAINSYS_H diff --git a/softwareDirectory/AutoVerScheme/datasyncview.cpp b/softwareDirectory/AutoVerScheme/datasyncview.cpp index fbf4508..06c7f9a 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.cpp +++ b/softwareDirectory/AutoVerScheme/datasyncview.cpp @@ -1,11 +1,10 @@ #include "datasyncview.h" #include "ui_datasyncview.h" -#include "synctask.h" -#include "databaseconnection.h" -#include "mainsysdatabaseconnection.h" +#include "syncdialog.h" - +QString filePath = "C:\\AutoVerScheme\\sync_info.txt"; +// 获取当前时间戳 DataSyncView::DataSyncView(QWidget *parent) : QWidget(parent), ui(new Ui::DataSyncView) @@ -20,7 +19,7 @@ } void DataSyncView::initForm() { - //tableWidget设置 + ui->stackedWidget->setCurrentIndex(0); //设置控件的边框显示 ui->tableWidget->setStyleSheet("QHeaderView::section {" "border: 1px solid grey;" @@ -32,29 +31,129 @@ "}"); ui->tableWidget->setRowCount(10); // 设置10行 - ui->tableWidget->setColumnCount(4); // 设置11列 - ui->tableWidget->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnCount(7); // 设置11列 + ui->tableWidget->setColumnWidth(0, 0); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnWidth(2, 200); // 设置第一列的宽度为100像素 ui->tableWidget->verticalHeader()->setParent(nullptr); //隐藏行头 - QTableWidgetItem *item = new QTableWidgetItem("测试数据"); - item->setTextAlignment(Qt::AlignCenter); - ui->tableWidget->setItem(0, 0, item); //设置数据 + + //初始化TableWidget 设置列 QStringList headers; - headers << "序号" << "同步时间" << "是否同步成功" << "备注" ; + headers <<"id" << "序号" << "同步时间" << "是否同步成功" << "备注" + <<"类型" <<"操作"; ui->tableWidget->setHorizontalHeaderLabels(headers); + //详情内 + + //设置控件的边框显示 + ui->tableWidget_2->setStyleSheet("QHeaderView::section {" + "border: 1px solid grey;" + "border-left:none;" + "border-top:none;" + "background-color:white;" + " color:black;" + "font: bold 18px Arial, sans-serif;" + "}"); + + ui->tableWidget_2->setRowCount(10); // 设置10行 + ui->tableWidget_2->setColumnCount(3); // 设置11列 + ui->tableWidget_2->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget_2->verticalHeader()->setParent(nullptr); //隐藏行头 + ui->tableWidget_2->setColumnWidth(1, 1000); // 设置第一列的宽度为100像素 + + //初始化TableWidget 设置列 + + headers << "序号" << "信息" << "状态" ; + ui->tableWidget_2->setHorizontalHeaderLabels(headers); + + //数据显示 + + //先设置为行为0 + ui->tableWidget->setRowCount(0); + int rowCount=0; + int row=0; + QList zdlog= BaseCommonApi::getzdLogByuserId(""); + for(const zdLog & zd:zdlog) + { + rowCount = ui->tableWidget->rowCount(); + ui->tableWidget->insertRow(rowCount); + ui->tableWidget->setItem(row, 0, new QTableWidgetItem(zd.id)); + ui->tableWidget->setItem(row, 1, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget->setItem(row, 2, new QTableWidgetItem(zd.sync_time.toString())); + ui->tableWidget->setItem(row, 3, new QTableWidgetItem(zd.is_sync)); + ui->tableWidget->setItem(row, 4, new QTableWidgetItem(zd.remark)); + if(zd.type=="1") + { + ui->tableWidget->setItem(row, 5, new QTableWidgetItem("下载")); + }else{ ui->tableWidget->setItem(row, 5, new QTableWidgetItem("上传")); } + + //添加操作按钮 + QPushButton *button = new QPushButton("查询信息"); + button->setIconSize(QSize(16,16)); + button->setIcon(QIcon(":/image/Index/u2327.svg")); + ui->tableWidget->setCellWidget(row, 6, button); + //设置按钮简单样式 + button->setStyleSheet("QPushButton {" + " border: none; /* 无边框 */" + " color: green; /* 文本颜色 */" + " text-decoration: underline; /* 文本下划线 */" + "}"); + + // 设置鼠标悬停时的光标样式为小手图标 + button->setCursor(Qt::PointingHandCursor); + // 连接按钮的 clicked 信号到自定义槽函数 + connect(button, &QPushButton::clicked, this, [this, button, zd]() { + // 获取当前行第一列的 ID + + OnButtonSelectClicked(zd); + + }); + row++; + } } void DataSyncView::on_DownloadDataButton_clicked() { - //从主系统下载 + + SyncDialog *syncDialog = new SyncDialog(this); + syncDialog->exec(); // 显示进度条窗体并阻塞主窗口 + + this->initForm(); + } -void DataSyncView::syncTable() +void DataSyncView::OnButtonSelectClicked(zdLog log) { - //连接两个数据库 - bool IsOpen=false; - DatabaseConnection *Conn=DatabaseConnection::getInstance(); - IsOpen=Conn->open(); - //MainSysDatabaseConnection *MainConn=MainSysDatabaseConnection::getInstance(); - //IsOpen=MainConn->open(); + ui->stackedWidget->setCurrentIndex(1); + ui->tableWidget_2->setRowCount(0); + int rowCount=0; + int row=0; + QList data= BaseCommonApi::getzdDataSyncByuserId(log.id); + for(const zdDataSync & item:data) + { + rowCount = ui->tableWidget_2->rowCount(); + ui->tableWidget_2->insertRow(rowCount); + ui->tableWidget_2->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget_2->setItem(row, 1, new QTableWidgetItem(item.remark)); + QTableWidgetItem *itemRow; + if(item.sync_type=="0"){ + itemRow = new QTableWidgetItem("未同步"); + itemRow->setBackground(QBrush(QColor(255, 255, 192))); + }else if (item.sync_type=="1") + { + itemRow = new QTableWidgetItem("同步成功"); + itemRow->setBackground(QBrush(QColor(173, 255, 47))); // 浅绿色 + }else{ + itemRow = new QTableWidgetItem("同步失败"); + itemRow->setBackground(QBrush(QColor(255, 105, 180))); // 浅红色 + } + itemRow->setTextAlignment(Qt::AlignCenter); + ui->tableWidget_2->setItem(row, 2, itemRow); + + row++; + } +} + +void DataSyncView::on_button_return_clicked() +{ + ui->stackedWidget->setCurrentIndex(0); } diff --git a/softwareDirectory/AutoVerScheme/datasyncview.h b/softwareDirectory/AutoVerScheme/datasyncview.h index 174480e..b2b9847 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.h +++ b/softwareDirectory/AutoVerScheme/datasyncview.h @@ -2,6 +2,16 @@ #define DATASYNCVIEW_H #include +#include +#include "synctask.h" +#include "databaseconnection.h" +#include "basecommonapi.h" +#include "databaseconnectionmainsys.h" +#include +#include +#include +#include +#include namespace Ui { class DataSyncView; @@ -18,8 +28,12 @@ void initForm(); //初始化界面数据 void on_DownloadDataButton_clicked(); - //异步更新 - void syncTable(); + void OnButtonSelectClicked(zdLog log); + void on_button_return_clicked(); + +public: + + private: Ui::DataSyncView *ui; }; diff --git a/softwareDirectory/AutoVerScheme/datasyncview.ui b/softwareDirectory/AutoVerScheme/datasyncview.ui index 53c379c..7c9df8e 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.ui +++ b/softwareDirectory/AutoVerScheme/datasyncview.ui @@ -14,21 +14,9 @@ 数据同步 - background-color:rgba(240, 240, 240, 1); + background-color:white; - - - 0 - - - 0 - - - 0 - - - 0 - + @@ -73,119 +61,173 @@ - - - background-color:white; - - - - - - - 3 - - - - - - 0 - 0 - - - - background-color:white; + + + + + + + background-color:white; + + + + + + + 3 + + + + + + 0 + 0 + + + + background-color:white; border:0; - - - - - - - - - - 0 - 0 - - - - font:bold 20px Arial, sans-serif; + + + + + + + + + + 0 + 0 + + + + font:bold 20px Arial, sans-serif; color:#334582; - - - 同步记录 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - background-color:#334582; + + + 同步记录 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + background-color:#334582; font: bold 18px Arial, sans-serif; color:white; padding:10px; - - - 下载数据 - - - - - - - - 200 - 0 - - - - - 100 - 40 - - - - Qt::RightToLeft - - - background-color:#334582; + + + 下载数据 + + + + + + + + 200 + 0 + + + + + 100 + 40 + + + + Qt::RightToLeft + + + background-color:#334582; font: bold 18px Arial, sans-serif; color:white; padding:10px; - - - 发送同步请求 - - - - :/image/Index/u8458.svg:/image/Index/u8458.svg - - - - - - - - - - - - - - + + + 发送同步请求 + + + + :/image/Index/u8458.svg:/image/Index/u8458.svg + + + + + + + + + + + + + + + + + + + + + + + + background-color:white; + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + color:black; + + + 返回 + + + + + + + + + + + + + diff --git a/softwareDirectory/AutoVerScheme/depar_task.cpp b/softwareDirectory/AutoVerScheme/depar_task.cpp index d551972..d58cf35 100644 --- a/softwareDirectory/AutoVerScheme/depar_task.cpp +++ b/softwareDirectory/AutoVerScheme/depar_task.cpp @@ -113,6 +113,7 @@ else State="否"; ui->tableWidget->setItem(row, 9, new QTableWidgetItem(State)); //设置数据 + SetHomePaheCombox(dept); //添加 PageData数据 TempData.append(QString::number(row+1)); TempData.append(dept.sample_name); @@ -133,9 +134,9 @@ //设置分页控件 // 创建分页表格控件 - PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); +// PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); //data转换位QList> - pagedTable->setData(PageData, 20,ui->tableWidget); // 每页20行 + // pagedTable->setData(PageData, 20,ui->tableWidget); // 每页20行 } void Depar_Task::on_SelectButton_clicked() @@ -155,26 +156,31 @@ if(dept.measure_status=="3" || dept.measure_status=="4"){ bool shouldAddRow = true; // 初始假设应该添加这一行 // 根据设备名称筛选 + QString names; if (ui->name->currentText() != "ALL") { + names=ui->name->currentText(); if (ui->name->currentText() != dept.sample_name) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } if (ui->mode->currentText() != "ALL") { + names=ui->mode->currentText(); if (ui->mode->currentText() != dept.sample_model) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } if (ui->customer->currentText() != "ALL") { + if (ui->customer->currentText() != dept.customer_name) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } - if (ui->dept->currentText() != "") { + if (ui->dept->currentText() != "ALL") { if (ui->dept->currentText() != dept.FULL_NAME) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); ui->tableWidget->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); @@ -193,9 +199,10 @@ State="否"; ui->tableWidget->setItem(row, 9, new QTableWidgetItem(State)); //设置数据 // - SetHomePaheCombox(dept); + //QDebug row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/indexwindow.cpp b/softwareDirectory/AutoVerScheme/indexwindow.cpp index eed192a..060b86e 100644 --- a/softwareDirectory/AutoVerScheme/indexwindow.cpp +++ b/softwareDirectory/AutoVerScheme/indexwindow.cpp @@ -58,7 +58,7 @@ DatabaseConnection *Conn=DatabaseConnection::getInstance(); //数据库连接 目前先放这里 后续需要放到登录界面 - bool IsOpen=Conn->open(); + bool IsOpen=Conn->open(); if(IsOpen) ShowMessageBox("数据库连接","连接成功"); else diff --git a/softwareDirectory/AutoVerScheme/my_task.cpp b/softwareDirectory/AutoVerScheme/my_task.cpp index 1735575..cd735f8 100644 --- a/softwareDirectory/AutoVerScheme/my_task.cpp +++ b/softwareDirectory/AutoVerScheme/my_task.cpp @@ -62,7 +62,8 @@ } void My_Task::Load() { - QList> PageData; + + //QList> PageData; //先设置为行为0 ui->tableWidget->setRowCount(0); //添加comboBox @@ -86,11 +87,29 @@ QString userId=""; data = BaseCommonApi::getMyTasks(userId,"3"); + QString State; + //设置单页显示数量 + page=20; + // 创建分页表格控件 + PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); + pagedTable->setData(data.count(), page); // 每页10行 + connect(pagedTable, &PagedTableWidget::pageChanged, this,&My_Task::onpageChanged); + this->onpageChanged(0); + +} +void My_Task::onpageChanged(int currPage){ + currPage+=1; + // 计算当前页的开始和结束索引 + int start = (currPage - 1) * page; + int end = std::min(start + page, data.size()); + // 从 QList 中筛选出当前页的数据 + QList tempdate = data.mid(start, end - start); int rowCount = 0; int row=0; QString State; - for (const MyTask& myTask : data) { - if(myTask.measure_status=="3" || myTask.measure_status=="4"){ + ui->tableWidget->setRowCount(0); + for (const MyTask& myTask : tempdate) { + QList TempData; rowCount = ui->tableWidget->rowCount(); @@ -118,42 +137,15 @@ ui->tableWidget->setItem(row, 10,new QTableWidgetItem("检测完成")); } - //渲染下拉框 - SetHomePaheCombox(myTask); - //QDebug - - //添加 PageData数据 - TempData.append(QString::number(row+1)); - TempData.append(myTask.sample_name); - TempData.append(myTask.sample_model); - TempData.append(myTask.help_instruction); - TempData.append(myTask.manufacture_no); - TempData.append(myTask.manufacturer); - TempData.append(myTask.customer_name); - TempData.append(myTask.FULL_NAME); - TempData.append(myTask.require_over_time.toString()); - TempData.append(State); - TempData.append(myTask.measure_status); - PageData.append(TempData); + //渲染下拉框 + SetHomePaheCombox(myTask); row++; - } - - } - //设置分页控件 - // 创建分页表格控件 - - PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); - //data转换位QList> - pagedTable->setData(PageData, 20,ui->tableWidget); // 每页10行 - //ui->HBoxPageLayout->addWidget(pagedTable); - //setLayout(ui->HBoxPageLayout); - // 连接信号以处理页码变化 - /* connect(pagedTable, &PagedTableWidget::pageChanged, this, [=](int page) { - // 在这里处理页码变化事件,比如更新UI中的其他部分 - qDebug() << "Page changed to:" << page; - });*/ + }; + //按钮点击事件 + // QMessageBox::information(this, "点击按钮",QString::number(page)); + // qDebug() << "Page changed to:" << page; } void My_Task::SetHomePaheCombox(MyTask entity) { diff --git a/softwareDirectory/AutoVerScheme/my_task.h b/softwareDirectory/AutoVerScheme/my_task.h index 289e7f4..8a4ad07 100644 --- a/softwareDirectory/AutoVerScheme/my_task.h +++ b/softwareDirectory/AutoVerScheme/my_task.h @@ -26,9 +26,11 @@ void on_pushButtonUpdate_clicked(); void on_SeachButton_clicked(); + void onpageChanged(int page); public: QList data; - + int page; + int totalcount; private: Ui::My_Task *ui; }; diff --git a/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp b/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp index e9cfb66..3ef9d60 100644 --- a/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp @@ -3,7 +3,7 @@ #include "InfoBase.h" #include "QMessageBox" #include "basecommonapi.h" - +#include "PageControl.h" //标准设备管理 .cpp Standard_DeviceItem::Standard_DeviceItem(QWidget *parent) : @@ -32,7 +32,7 @@ // ui->tableWidget->setRowCount(10); // 设置10行 ui->tableWidget->setColumnCount(7); // 设置11列 - ui->tableWidget->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnWidth(0, 0); // 设置第一列的宽度为100像素 ui->tableWidget->verticalHeader()->setParent(nullptr); //隐藏行头 //QTableWidgetItem *item = new QTableWidgetItem("测试数据"); //item->setTextAlignment(Qt::AlignCenter); @@ -102,12 +102,32 @@ // 调用数据库管理器的函数获取数据 - int rowCount=0; - int row=0; + data = BaseCommonApi::getBizDeviceManage(); + QString State; + //设置单页显示数量 + page=20; + // 创建分页表格控件 + PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); + pagedTable->setData(data.count(), page); // 每页10行 + connect(pagedTable, &PagedTableWidget::pageChanged, this,&Standard_DeviceItem::onpageChanged); + this->onpageChanged(0); - for (const BizDevice& bizDevice : data) { +} +void Standard_DeviceItem::onpageChanged(int currPage){ + + currPage+=1; + // 计算当前页的开始和结束索引 + int start = (currPage - 1) * page; + int end = std::min(start + page, data.size()); + // 从 QList 中筛选出当前页的数据 + QList tempdate = data.mid(start, end - start); + int rowCount = 0; + int row=0; + QString State; + ui->tableWidget->setRowCount(0); + for (const BizDevice& bizDevice : tempdate) { rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -147,8 +167,9 @@ SetHomePaheCombox(bizDevice); row++; } - } + + void Standard_DeviceItem::OnButtonSelectClicked(QString id) { //添加 diff --git a/softwareDirectory/AutoVerScheme/standard_deviceitem.h b/softwareDirectory/AutoVerScheme/standard_deviceitem.h index f522658..c506728 100644 --- a/softwareDirectory/AutoVerScheme/standard_deviceitem.h +++ b/softwareDirectory/AutoVerScheme/standard_deviceitem.h @@ -30,6 +30,9 @@ void on_pushButton_8_clicked(); public: QList data; + void onpageChanged(int currPage); + int page; + int totalcount; private: Ui::Standard_DeviceItem *ui; }; diff --git a/softwareDirectory/AutoVerScheme/standard_deviceitem.ui b/softwareDirectory/AutoVerScheme/standard_deviceitem.ui index 9b1acd4..861993d 100644 --- a/softwareDirectory/AutoVerScheme/standard_deviceitem.ui +++ b/softwareDirectory/AutoVerScheme/standard_deviceitem.ui @@ -233,6 +233,24 @@ + + + + + + + + Qt::Horizontal + + + + 1108 + 36 + + + + + diff --git a/softwareDirectory/AutoVerScheme/syncdialog.cpp b/softwareDirectory/AutoVerScheme/syncdialog.cpp new file mode 100644 index 0000000..f9195f1 --- /dev/null +++ b/softwareDirectory/AutoVerScheme/syncdialog.cpp @@ -0,0 +1,207 @@ +#include "syncdialog.h" +#include "ui_syncdialog.h" + + +int SyncDialog::m_totalTasks; +int SyncDialog::stepcount; +int SyncDialog::filecount; + + +SyncDialog::SyncDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::SyncDialog) +{ + ui->setupUi(this); + + + +} + +SyncDialog::~SyncDialog() +{ + delete ui; +} + +void SyncDialog::on_button_Start_clicked() +{ + + + //qint64 id = dbmang.generateId(); + //zdlogId=QString::number(id); + zdDataSyncList.clear(); + querydstList.clear(); + //从主系统下载 + //连接两个数据库 + bool IsOpen=false; + bool IsOpenMain=false; + + DatabaseConnection *Conn=DatabaseConnection::getInstance(); + //DatabaseConnectionMainSys *MainConn=DatabaseConnectionMainSys::getInstance(); + if(!Conn->isopen()){IsOpen=Conn->open();}else{IsOpen=true;}; + if(!Conn->isopenmain()){IsOpenMain=Conn->openmain();}else{IsOpenMain=true;}; + + // 记录任务数量 + + m_totalTasks=0; + stepcount=0; + filecount=0; + // 获取第一个数据库的所有表名 + dstDb=Conn->getDatabase(); + srcDb=Conn->getDatabaseMain(); + QSqlQuery querydst(dstDb); + querydst.exec("SHOW TABLES"); + QSqlQuery query(srcDb); + query.exec("SHOW TABLES"); + + while(querydst.next()){ + QString tableName = querydst.value(0).toString(); + if(tableName.contains("act_") ||tableName.contains("flw_ru_")){continue;}; + querydstList.append(tableName);}; + // 创建一个线程池 + threadPool= QThreadPool::globalInstance(); + threadPool->setMaxThreadCount(5); // 设置线程池中的最大线程数 + // 遍历表名,为每个表创建一个任务并提交到线程池 + BaseCommonApi::SaveLogInfo(filePath,"开始下载同步"); + + while (query.next()) { + QString tableName = query.value(0).toString(); + if(!querydstList.contains(tableName)){continue;}; + if(tableName.contains("ACT_") ||tableName.contains("FLW_RU_")){continue;}; + SyncTask *task = new SyncTask(srcDb, dstDb, tableName); + connectTaskSignals(task); + // 提交任务到线程池 + threadPool->start(task); + ++m_totalTasks; + // + + } + //总数量 + ui->lab_sum->setText(QString::number(m_totalTasks)); + progressDecrement=static_cast(100) / m_totalTasks; + +} +void SyncDialog::connectTaskSignals(SyncTask *task) { + connect(task, &SyncTask::taskCompleted, this, &SyncDialog::onTaskCompleted); + connect(task, &SyncTask::TextState, this, &SyncDialog::onTextState); + connect(this,&SyncDialog::StopRequested,task,&SyncTask::UpdateState); + //当前正在执行的 +} +void SyncDialog::onTaskCompleted(int success,QString tableName, const QString& errorMessage) +{ + if(success!=2){ + if(querydstList.contains(tableName)){querydstList.removeAll(tableName);}; + //添加同步表 + //任务完成 任务失败 都需要添加 + qint64 id = dbmang.generateId(); + zdDataSync zdDataSyncentity; + zdDataSyncentity.id=QString::number(id);; + zdDataSyncentity.remark=errorMessage; + zdDataSyncentity.log_sync_id=""; + zdDataSyncentity.sync_type=QString::number(success+1); + zdDataSyncList.append(zdDataSyncentity); + // dbmang.InsertzdDataSync(zdDataSyncentity); + }; + QString mess; + if (success==0) { + // 任务成功完成 + mess = "任务完成"; + mess+=errorMessage; + + } else if(success==1){ + // 任务执行失败 + mess = "任务失败"; + mess +=errorMessage; + filecount++; + //失败数量 + ui->lab_fail->setText(QString::number(filecount));; + }else{ + mess = "正在执行"; + mess +=errorMessage+"....."; + } + //log保存 + BaseCommonApi::SaveLogInfo(filePath,mess); + //界面listview显示 + ui->listWidget->addItem(mess); + // 当添加新项后,滚动到底部 + ui->listWidget->scrollToBottom(); + +} +void SyncDialog::onTextState() +{ + + stepcount++; + //成功数量 + ui->lab_succ->setText(QString::number(stepcount));; + //更新进度条 + int progress = static_cast(progressDecrement * stepcount); + ui->progressBar->setValue(progress); + if(stepcount>=m_totalTasks) + { + this->StopSync(); + } + +} + +void SyncDialog::on_button_Close_clicked() +{ + emit StopRequested(2); + threadPool->waitForDone(); + this->StopSync(); + srcDb.close(); + this->close(); +} +void SyncDialog::StopSync() +{ + ui->progressBar->setValue(100); + srcDb.close(); + //dstDb.close(); + + //添加日志表 + zdLog zlog; + zlog.id=QString::number( dbmang.generateId());; + zlog.type="1"; + if(filecount==0) + { + zlog.is_sync="成功"; + }else + { + zlog.is_sync="失败"; + } + zlog.sync_time=QDateTime::currentDateTime(); + zlog.remark="错误数量"+QString::number(filecount); + dbmang.InsertzdLog(zlog); + //添加记录表 + for (int i=0;ibutton_step->text()=="暂停") + { + ui->button_step->setText("继续"); + emit StopRequested(1); + + + }else{ + ui->button_step->setText("暂停"); + emit StopRequested(0); + }; +} diff --git a/softwareDirectory/AutoVerScheme/syncdialog.h b/softwareDirectory/AutoVerScheme/syncdialog.h new file mode 100644 index 0000000..2d5c41c --- /dev/null +++ b/softwareDirectory/AutoVerScheme/syncdialog.h @@ -0,0 +1,60 @@ +#ifndef SYNCDIALOG_H +#define SYNCDIALOG_H + +#include +#include "databaseconnection.h" +#include "basecommonapi.h" +#include "databaseconnectionmainsys.h" +#include +#include +#include +#include +#include +#include "synctask.h" + +namespace Ui { +class SyncDialog; +} + +class SyncDialog : public QDialog +{ + Q_OBJECT + +public: + explicit SyncDialog(QWidget *parent = nullptr); + ~SyncDialog(); + +private slots: + void on_button_Start_clicked(); + + + void connectTaskSignals(SyncTask *task); + void onTaskCompleted(int success,QString tableName, const QString& errorMessage); + void onTextState(); + void on_button_Close_clicked(); + void StopSync(); + void on_button_step_clicked(); + +public: + static int m_totalTasks; + static int filecount; + static int stepcount; + + QThreadPool *threadPool; + QSqlDatabase dstDb; + QSqlDatabase srcDb; + double progressDecrement; + QString filePath = "C:\\AutoVerScheme\\sync_info.txt"; + + QString zdlogId=""; + + BaseCommonApi dbmang; + QList zdDataSyncList; + QList querydstList; +signals: + void StopRequested(int state); // 定义暂停 停止请求信号 +private: + Ui::SyncDialog *ui; +}; + +#endif // SYNCDIALOG_H diff --git a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro index bf70fab..d9a99ea 100644 --- a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro +++ b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro @@ -35,6 +35,7 @@ create_task.cpp \ createtask_scandevice.cpp \ databaseconnection.cpp \ + databaseconnectionmainsys.cpp \ datasyncview.cpp \ depar_task.cpp \ depar_task_server.cpp \ @@ -55,6 +56,7 @@ newverifymethod.cpp \ rulefileitem.cpp \ standard_deviceitem.cpp \ + syncdialog.cpp \ synctask.cpp \ testdataitem.cpp \ testview.cpp \ @@ -69,6 +71,7 @@ DataProcessingBLL.h \ PageControl.h \ createtask_scandevice.h \ + databaseconnectionmainsys.h \ formaddrsetting.h \ formcommsetting.h \ id/IdWorker.h \ @@ -104,6 +107,7 @@ newverifymethod.h \ rulefileitem.h \ standard_deviceitem.h \ + syncdialog.h \ synctask.h \ testdataitem.h \ testview.h \ @@ -138,6 +142,7 @@ newverifymethod.ui \ rulefileitem.ui \ standard_deviceitem.ui \ + syncdialog.ui \ testdataitem.ui \ testview.ui \ verifydevice.ui \ diff --git a/softwareDirectory/AutoVerScheme/PageControl.cpp b/softwareDirectory/AutoVerScheme/PageControl.cpp index d0fd72b..d1bdddc 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.cpp +++ b/softwareDirectory/AutoVerScheme/PageControl.cpp @@ -22,14 +22,14 @@ } } -void PagedTableWidget::setData(const QList> &data, int rowsPerPage,QTableWidget *table) { - tableWidget=table; - +void PagedTableWidget::setData(int datacount, int rowsPerPage) { + //tableWidget=table; + totaldatacount=datacount; this->rowsPerPage = rowsPerPage; - allData = data; + //allData = data; currentPage = 0; createPageButtons(); - updateTable(); + //updateTable(); } void PagedTableWidget::setCurrentPage(int page) { @@ -39,7 +39,7 @@ button->setChecked(false); }*/ currentPage = page; - updateTable(); + //updateTable(); emit pageChanged(page); } } @@ -89,6 +89,7 @@ setCurrentPage(pageIndex); } } +/* void PagedTableWidget::updateTable() { //tableWidget->clear(); tableWidget->setRowCount(0); @@ -105,7 +106,7 @@ } } } - +*/ void PagedTableWidget::createPageButtons() { int totalPages = calculateTotalPages(); for (auto button : pageButtons) { @@ -150,5 +151,5 @@ } int PagedTableWidget::calculateTotalPages() { - return ((allData.count() + rowsPerPage -1) / rowsPerPage); + return ((totaldatacount + rowsPerPage -1) / rowsPerPage); } diff --git a/softwareDirectory/AutoVerScheme/PageControl.h b/softwareDirectory/AutoVerScheme/PageControl.h index 74ed1ce..2224760 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.h +++ b/softwareDirectory/AutoVerScheme/PageControl.h @@ -15,7 +15,7 @@ explicit PagedTableWidget(QWidget *parent = nullptr,QHBoxLayout *PageLayout=NULL); ~PagedTableWidget(); - void setData(const QList> &data, int rowsPerPage = 10,QTableWidget *table=NULL); + void setData(int datacount, int rowsPerPage = 10); void setCurrentPage(int page); signals: @@ -30,6 +30,7 @@ QHBoxLayout *pageLayout; QList pageButtons; QList> allData; + int totaldatacount; int rowsPerPage; int currentPage; diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.cpp b/softwareDirectory/AutoVerScheme/basecommonapi.cpp index 49cbd7e..6f6fe94 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.cpp +++ b/softwareDirectory/AutoVerScheme/basecommonapi.cpp @@ -13,7 +13,7 @@ } const QString BaseCommonApi::temporary_user_id="1634107227953819649"; const QString BaseCommonApi::measure_person_id="1695282436182188034"; - +static SyncRunStatus syncstate=SyncRunStatus::Stopped; //sys_user表的id转换为measure_person_id 检定人id(meter_staff表id) @@ -167,7 +167,8 @@ "JOIN eqpt_equipment_info eei ON eei.id = blei.sample_id " "JOIN biz_business_order_info bo ON bo.id = blei.order_id " "LEFT JOIN sys_dept sd ON blei.measure_dept_id = sd.ID " - " WHERE blei.measure_person_id = :person_id " + " WHERE blei.measure_person_id = :person_id " + " AND blei.measure_status =3 or blei.measure_status = 4 " " ORDER BY blei.update_time DESC"); // 将参数绑定到占位符 @@ -175,7 +176,8 @@ //query.bindValue(":status", status); if (query.exec()) { while (query.next()) { - MyTask task; + + MyTask task; task.id = query.value("id").toString(); task.sample_name = query.value("sampleName").toString(); task.sample_model = query.value("sampleModel").toString(); @@ -2872,9 +2874,40 @@ return result; } +//保存log信息 +//log文件 + bool BaseCommonApi::SaveLogInfo(QString path,QString Info) +{ + QByteArray utf8Dat; + QString Message=Info; + QFile file(path); + // 如果目录不存在,则创建目录 + // 获取文件所在的目录 + QDir logDir = QDir(QFileInfo(path).absolutePath()); + if (!logDir.exists()) { + if (!logDir.mkpath(".")) { + qDebug() << "Failed to create log directory:" << logDir.absolutePath(); + return false; + } + } + + if (!file.open(QIODevice::Append | QIODevice::Text)) { + qDebug() << "无法打开文件:" << file.errorString(); + return false; + } + QTextStream out(&file); + utf8Dat = Message.toUtf8(); + out << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss") + << "\t" << utf8Dat << "\n"; + file.close(); + return true; + } + + //新增日志表数据 bool BaseCommonApi::InsertzdLog(zdLog log) { + log.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_log(id,is_sync,sync_time,remark,userid,type,create_time,update_time) " " VALUES(:id,:is_sync,:sync_time,:remark,:userid,:type,:create_time,:update_time) "); @@ -2898,6 +2931,7 @@ //根据userid查询日志表数据 QList BaseCommonApi::getzdLogByuserId(QString userid) { + userid=temporary_user_id; QList result; QSqlQuery query; query.prepare("SELECT * FROM zd_log WHERE userid = :userid "); @@ -2922,6 +2956,7 @@ //新增数据同步表 bool BaseCommonApi::InsertzdDataSync(zdDataSync data) { + data.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_data_sync(id,type,ssql,userid,remark,create_time,update_time,log_sync_id,sync_type) " " VALUES " @@ -2945,12 +2980,12 @@ return isSuccess; } //根据userid查询数据同步表 -QList getzdDataSyncByuserId(QString userid) +QList BaseCommonApi::getzdDataSyncByuserId(QString log_sync_id) { QList result; QSqlQuery query; - query.prepare("SELECT * FROM zd_data_sync WHERE userid= :userid "); - query.bindValue(":userid",userid); + query.prepare("SELECT * FROM zd_data_sync WHERE log_sync_id= :log_sync_id "); + query.bindValue(":log_sync_id",log_sync_id); if (query.exec()) { while (query.next()) { zdDataSync data; @@ -2972,3 +3007,4 @@ } + diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.h b/softwareDirectory/AutoVerScheme/basecommonapi.h index 12196fb..4949683 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.h +++ b/softwareDirectory/AutoVerScheme/basecommonapi.h @@ -919,6 +919,7 @@ QDateTime create_time; QDateTime update_time; }; + //数据同步-数据表 class zdDataSync { @@ -935,6 +936,12 @@ }; +enum class SyncRunStatus { + + Running, + Stopped, + Paused +}; using namespace Jiawa::Core; class BaseCommonApi @@ -945,7 +952,6 @@ const static QString temporary_costomer_id; const static QString measure_person_id; - QString encrypt(const QString &str, const QString &publicKey); //判断检定装置表并查询 参数设备id @@ -1137,14 +1143,19 @@ //单独查询任务单表 //更新 任务单 static InsertTask SelectTaskSingle(QString order_id); + + //log文件 + static bool SaveLogInfo(QString path,QString Info); + //新增日志表数据 static bool InsertzdLog(zdLog log); //查询日志表数据 static QList getzdLogByuserId(QString userid); //新增数据同步表 static bool InsertzdDataSync(zdDataSync data); - //根据userid查询数据同步表 - static QList getzdDataSyncByuserId(QString userid); + //根据log_sync_id查询数据同步表 + static QList getzdDataSyncByuserId(QString log_sync_id); + }; diff --git a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp index 00d746b..ae60962 100644 --- a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp @@ -352,6 +352,7 @@ } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -395,6 +396,7 @@ row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.cpp b/softwareDirectory/AutoVerScheme/databaseconnection.cpp index 1d957d9..5284fe6 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.cpp +++ b/softwareDirectory/AutoVerScheme/databaseconnection.cpp @@ -10,17 +10,21 @@ { // 连接数据库 - db = QSqlDatabase::addDatabase("QODBC"); - /*db.setHostName("111.198.10.15"); - db.setDatabaseName("casic_metering_xichang"); - db.setPort(21906); - db.setUserName("zdjdcs"); - db.setPassword("11111111");*/ - db.setHostName("localhost"); - db.setDatabaseName("zdjd"); - db.setPort(3306); - db.setUserName("root"); - db.setPassword("123456"); + localdb = QSqlDatabase::addDatabase("QODBC"); + + localdb.setHostName("localhost"); + localdb.setDatabaseName("zdjd"); + localdb.setPort(3306); + localdb.setUserName("root"); + localdb.setPassword("123456"); + + Maindb = QSqlDatabase::addDatabase("QODBC","Main"); + Maindb.setHostName("111.198.10.15"); + Maindb.setDatabaseName("casic_metering_xichang"); + Maindb.setPort(21906); + Maindb.setUserName("zdjdcs"); + Maindb.setPassword("11111111"); + } @@ -29,18 +33,28 @@ close(); } bool DatabaseConnection::open() { - return db.open(); + return localdb.open(); +} +bool DatabaseConnection::openmain() { + return Maindb.open(); } bool DatabaseConnection::isopen() { - return db.isOpen(); + return localdb.isOpen(); } - +bool DatabaseConnection::isopenmain() { + return Maindb.isOpen(); +} void DatabaseConnection::close() { - db.close(); + localdb.close(); } - +void DatabaseConnection::closemain() { + Maindb.close(); +} QSqlDatabase& DatabaseConnection::getDatabase() { - return db; + return localdb; +} +QSqlDatabase& DatabaseConnection::getDatabaseMain() { + return Maindb; } DatabaseConnection* DatabaseConnection::getInstance() { diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.h b/softwareDirectory/AutoVerScheme/databaseconnection.h index 586b794..5f9810b 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.h +++ b/softwareDirectory/AutoVerScheme/databaseconnection.h @@ -16,8 +16,12 @@ ~DatabaseConnection(); bool open(); bool isopen(); + bool openmain(); void close(); + void closemain(); + bool isopenmain(); QSqlDatabase& getDatabase(); + QSqlDatabase& getDatabaseMain(); private: //单列模式 保证DatabaseConnection的唯一性 static DatabaseConnection* Connect; @@ -33,7 +37,8 @@ //如果尝试这样做,编译器同样会报错。 DatabaseConnection& operator=(const DatabaseConnection&) = delete; //数据库db类 - QSqlDatabase db; + QSqlDatabase Maindb; + QSqlDatabase localdb; }; #endif // DATABASECONNECTION_H diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp new file mode 100644 index 0000000..080288b --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp @@ -0,0 +1,54 @@ +#include "databaseconnectionmainsys.h" + + + + +DatabaseConnectionMainSys* DatabaseConnectionMainSys::Connect = nullptr; +QMutex DatabaseConnectionMainSys::mutex; + +DatabaseConnectionMainSys::DatabaseConnectionMainSys() +{ + + // 连接数据库 + dbmain = QSqlDatabase::addDatabase("QODBC"); + dbmain.setHostName("111.198.10.15"); + dbmain.setDatabaseName("casic_metering_xichang"); + dbmain.setPort(21906); + dbmain.setUserName("zdjdcs"); + dbmain.setPassword("11111111"); + /* db.setHostName("localhost"); + db.setDatabaseName("zdjd"); + db.setPort(3306); + db.setUserName("root"); + db.setPassword("123456");*/ + + +} +DatabaseConnectionMainSys::~DatabaseConnectionMainSys() { + // 在析构函数中关闭数据库连接 + close(); +} +bool DatabaseConnectionMainSys::open() { + return dbmain.open(); +} +bool DatabaseConnectionMainSys::isopen() { + return dbmain.isOpen(); +} + +void DatabaseConnectionMainSys::close() { + dbmain.close(); +} + +QSqlDatabase& DatabaseConnectionMainSys::getDatabase() { + return dbmain; +} +DatabaseConnectionMainSys* DatabaseConnectionMainSys::getInstance() +{ + if (!Connect) { + QMutexLocker locker(&mutex); + if (!Connect) { + Connect = new DatabaseConnectionMainSys(); + } + } + return Connect; +} diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h new file mode 100644 index 0000000..57702ad --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h @@ -0,0 +1,41 @@ +#ifndef DATABASECONNECTIONMAINSYS_H +#define DATABASECONNECTIONMAINSYS_H +#include +#include +#include +#include + + +class DatabaseConnectionMainSys +{ + + +public: + //获取数据库实例 + static DatabaseConnectionMainSys* getInstance(); + + DatabaseConnectionMainSys(); + ~DatabaseConnectionMainSys(); + bool open(); + bool isopen(); + void close(); + QSqlDatabase& getDatabase(); +private: + //单列模式 保证MainSysDatabaseConnection的唯一性 + static DatabaseConnectionMainSys* Connect; + //QMutex 来确保在多线程环境下单例的正确创建。 + static QMutex mutex; + + //这是拷贝构造函数的声明,后面跟着 = delete; 表示这个构造函数被删除了。 + //这意味着你不能通过拷贝另一个 DatabaseConnection 对象来创建新的 DatabaseConnection 对象。 + //如果尝试这样做,编译器会报错。 + DatabaseConnectionMainSys(const DatabaseConnectionMainSys&) = delete; + //这是拷贝赋值运算符的声明,同样后面跟着 = delete; 表示这个运算符被删除了。 + //这意味着你不能将一个 DatabaseConnection 对象赋值给另一个 DatabaseConnection 对象。 + //如果尝试这样做,编译器同样会报错。 + DatabaseConnectionMainSys& operator=(const DatabaseConnectionMainSys&) = delete; + //数据库db类 + QSqlDatabase dbmain; +}; + +#endif // DATABASECONNECTIONMAINSYS_H diff --git a/softwareDirectory/AutoVerScheme/datasyncview.cpp b/softwareDirectory/AutoVerScheme/datasyncview.cpp index fbf4508..06c7f9a 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.cpp +++ b/softwareDirectory/AutoVerScheme/datasyncview.cpp @@ -1,11 +1,10 @@ #include "datasyncview.h" #include "ui_datasyncview.h" -#include "synctask.h" -#include "databaseconnection.h" -#include "mainsysdatabaseconnection.h" +#include "syncdialog.h" - +QString filePath = "C:\\AutoVerScheme\\sync_info.txt"; +// 获取当前时间戳 DataSyncView::DataSyncView(QWidget *parent) : QWidget(parent), ui(new Ui::DataSyncView) @@ -20,7 +19,7 @@ } void DataSyncView::initForm() { - //tableWidget设置 + ui->stackedWidget->setCurrentIndex(0); //设置控件的边框显示 ui->tableWidget->setStyleSheet("QHeaderView::section {" "border: 1px solid grey;" @@ -32,29 +31,129 @@ "}"); ui->tableWidget->setRowCount(10); // 设置10行 - ui->tableWidget->setColumnCount(4); // 设置11列 - ui->tableWidget->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnCount(7); // 设置11列 + ui->tableWidget->setColumnWidth(0, 0); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnWidth(2, 200); // 设置第一列的宽度为100像素 ui->tableWidget->verticalHeader()->setParent(nullptr); //隐藏行头 - QTableWidgetItem *item = new QTableWidgetItem("测试数据"); - item->setTextAlignment(Qt::AlignCenter); - ui->tableWidget->setItem(0, 0, item); //设置数据 + + //初始化TableWidget 设置列 QStringList headers; - headers << "序号" << "同步时间" << "是否同步成功" << "备注" ; + headers <<"id" << "序号" << "同步时间" << "是否同步成功" << "备注" + <<"类型" <<"操作"; ui->tableWidget->setHorizontalHeaderLabels(headers); + //详情内 + + //设置控件的边框显示 + ui->tableWidget_2->setStyleSheet("QHeaderView::section {" + "border: 1px solid grey;" + "border-left:none;" + "border-top:none;" + "background-color:white;" + " color:black;" + "font: bold 18px Arial, sans-serif;" + "}"); + + ui->tableWidget_2->setRowCount(10); // 设置10行 + ui->tableWidget_2->setColumnCount(3); // 设置11列 + ui->tableWidget_2->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget_2->verticalHeader()->setParent(nullptr); //隐藏行头 + ui->tableWidget_2->setColumnWidth(1, 1000); // 设置第一列的宽度为100像素 + + //初始化TableWidget 设置列 + + headers << "序号" << "信息" << "状态" ; + ui->tableWidget_2->setHorizontalHeaderLabels(headers); + + //数据显示 + + //先设置为行为0 + ui->tableWidget->setRowCount(0); + int rowCount=0; + int row=0; + QList zdlog= BaseCommonApi::getzdLogByuserId(""); + for(const zdLog & zd:zdlog) + { + rowCount = ui->tableWidget->rowCount(); + ui->tableWidget->insertRow(rowCount); + ui->tableWidget->setItem(row, 0, new QTableWidgetItem(zd.id)); + ui->tableWidget->setItem(row, 1, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget->setItem(row, 2, new QTableWidgetItem(zd.sync_time.toString())); + ui->tableWidget->setItem(row, 3, new QTableWidgetItem(zd.is_sync)); + ui->tableWidget->setItem(row, 4, new QTableWidgetItem(zd.remark)); + if(zd.type=="1") + { + ui->tableWidget->setItem(row, 5, new QTableWidgetItem("下载")); + }else{ ui->tableWidget->setItem(row, 5, new QTableWidgetItem("上传")); } + + //添加操作按钮 + QPushButton *button = new QPushButton("查询信息"); + button->setIconSize(QSize(16,16)); + button->setIcon(QIcon(":/image/Index/u2327.svg")); + ui->tableWidget->setCellWidget(row, 6, button); + //设置按钮简单样式 + button->setStyleSheet("QPushButton {" + " border: none; /* 无边框 */" + " color: green; /* 文本颜色 */" + " text-decoration: underline; /* 文本下划线 */" + "}"); + + // 设置鼠标悬停时的光标样式为小手图标 + button->setCursor(Qt::PointingHandCursor); + // 连接按钮的 clicked 信号到自定义槽函数 + connect(button, &QPushButton::clicked, this, [this, button, zd]() { + // 获取当前行第一列的 ID + + OnButtonSelectClicked(zd); + + }); + row++; + } } void DataSyncView::on_DownloadDataButton_clicked() { - //从主系统下载 + + SyncDialog *syncDialog = new SyncDialog(this); + syncDialog->exec(); // 显示进度条窗体并阻塞主窗口 + + this->initForm(); + } -void DataSyncView::syncTable() +void DataSyncView::OnButtonSelectClicked(zdLog log) { - //连接两个数据库 - bool IsOpen=false; - DatabaseConnection *Conn=DatabaseConnection::getInstance(); - IsOpen=Conn->open(); - //MainSysDatabaseConnection *MainConn=MainSysDatabaseConnection::getInstance(); - //IsOpen=MainConn->open(); + ui->stackedWidget->setCurrentIndex(1); + ui->tableWidget_2->setRowCount(0); + int rowCount=0; + int row=0; + QList data= BaseCommonApi::getzdDataSyncByuserId(log.id); + for(const zdDataSync & item:data) + { + rowCount = ui->tableWidget_2->rowCount(); + ui->tableWidget_2->insertRow(rowCount); + ui->tableWidget_2->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget_2->setItem(row, 1, new QTableWidgetItem(item.remark)); + QTableWidgetItem *itemRow; + if(item.sync_type=="0"){ + itemRow = new QTableWidgetItem("未同步"); + itemRow->setBackground(QBrush(QColor(255, 255, 192))); + }else if (item.sync_type=="1") + { + itemRow = new QTableWidgetItem("同步成功"); + itemRow->setBackground(QBrush(QColor(173, 255, 47))); // 浅绿色 + }else{ + itemRow = new QTableWidgetItem("同步失败"); + itemRow->setBackground(QBrush(QColor(255, 105, 180))); // 浅红色 + } + itemRow->setTextAlignment(Qt::AlignCenter); + ui->tableWidget_2->setItem(row, 2, itemRow); + + row++; + } +} + +void DataSyncView::on_button_return_clicked() +{ + ui->stackedWidget->setCurrentIndex(0); } diff --git a/softwareDirectory/AutoVerScheme/datasyncview.h b/softwareDirectory/AutoVerScheme/datasyncview.h index 174480e..b2b9847 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.h +++ b/softwareDirectory/AutoVerScheme/datasyncview.h @@ -2,6 +2,16 @@ #define DATASYNCVIEW_H #include +#include +#include "synctask.h" +#include "databaseconnection.h" +#include "basecommonapi.h" +#include "databaseconnectionmainsys.h" +#include +#include +#include +#include +#include namespace Ui { class DataSyncView; @@ -18,8 +28,12 @@ void initForm(); //初始化界面数据 void on_DownloadDataButton_clicked(); - //异步更新 - void syncTable(); + void OnButtonSelectClicked(zdLog log); + void on_button_return_clicked(); + +public: + + private: Ui::DataSyncView *ui; }; diff --git a/softwareDirectory/AutoVerScheme/datasyncview.ui b/softwareDirectory/AutoVerScheme/datasyncview.ui index 53c379c..7c9df8e 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.ui +++ b/softwareDirectory/AutoVerScheme/datasyncview.ui @@ -14,21 +14,9 @@ 数据同步 - background-color:rgba(240, 240, 240, 1); + background-color:white; - - - 0 - - - 0 - - - 0 - - - 0 - + @@ -73,119 +61,173 @@ - - - background-color:white; - - - - - - - 3 - - - - - - 0 - 0 - - - - background-color:white; + + + + + + + background-color:white; + + + + + + + 3 + + + + + + 0 + 0 + + + + background-color:white; border:0; - - - - - - - - - - 0 - 0 - - - - font:bold 20px Arial, sans-serif; + + + + + + + + + + 0 + 0 + + + + font:bold 20px Arial, sans-serif; color:#334582; - - - 同步记录 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - background-color:#334582; + + + 同步记录 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + background-color:#334582; font: bold 18px Arial, sans-serif; color:white; padding:10px; - - - 下载数据 - - - - - - - - 200 - 0 - - - - - 100 - 40 - - - - Qt::RightToLeft - - - background-color:#334582; + + + 下载数据 + + + + + + + + 200 + 0 + + + + + 100 + 40 + + + + Qt::RightToLeft + + + background-color:#334582; font: bold 18px Arial, sans-serif; color:white; padding:10px; - - - 发送同步请求 - - - - :/image/Index/u8458.svg:/image/Index/u8458.svg - - - - - - - - - - - - - - + + + 发送同步请求 + + + + :/image/Index/u8458.svg:/image/Index/u8458.svg + + + + + + + + + + + + + + + + + + + + + + + + background-color:white; + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + color:black; + + + 返回 + + + + + + + + + + + + + diff --git a/softwareDirectory/AutoVerScheme/depar_task.cpp b/softwareDirectory/AutoVerScheme/depar_task.cpp index d551972..d58cf35 100644 --- a/softwareDirectory/AutoVerScheme/depar_task.cpp +++ b/softwareDirectory/AutoVerScheme/depar_task.cpp @@ -113,6 +113,7 @@ else State="否"; ui->tableWidget->setItem(row, 9, new QTableWidgetItem(State)); //设置数据 + SetHomePaheCombox(dept); //添加 PageData数据 TempData.append(QString::number(row+1)); TempData.append(dept.sample_name); @@ -133,9 +134,9 @@ //设置分页控件 // 创建分页表格控件 - PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); +// PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); //data转换位QList> - pagedTable->setData(PageData, 20,ui->tableWidget); // 每页20行 + // pagedTable->setData(PageData, 20,ui->tableWidget); // 每页20行 } void Depar_Task::on_SelectButton_clicked() @@ -155,26 +156,31 @@ if(dept.measure_status=="3" || dept.measure_status=="4"){ bool shouldAddRow = true; // 初始假设应该添加这一行 // 根据设备名称筛选 + QString names; if (ui->name->currentText() != "ALL") { + names=ui->name->currentText(); if (ui->name->currentText() != dept.sample_name) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } if (ui->mode->currentText() != "ALL") { + names=ui->mode->currentText(); if (ui->mode->currentText() != dept.sample_model) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } if (ui->customer->currentText() != "ALL") { + if (ui->customer->currentText() != dept.customer_name) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } - if (ui->dept->currentText() != "") { + if (ui->dept->currentText() != "ALL") { if (ui->dept->currentText() != dept.FULL_NAME) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); ui->tableWidget->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); @@ -193,9 +199,10 @@ State="否"; ui->tableWidget->setItem(row, 9, new QTableWidgetItem(State)); //设置数据 // - SetHomePaheCombox(dept); + //QDebug row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/indexwindow.cpp b/softwareDirectory/AutoVerScheme/indexwindow.cpp index eed192a..060b86e 100644 --- a/softwareDirectory/AutoVerScheme/indexwindow.cpp +++ b/softwareDirectory/AutoVerScheme/indexwindow.cpp @@ -58,7 +58,7 @@ DatabaseConnection *Conn=DatabaseConnection::getInstance(); //数据库连接 目前先放这里 后续需要放到登录界面 - bool IsOpen=Conn->open(); + bool IsOpen=Conn->open(); if(IsOpen) ShowMessageBox("数据库连接","连接成功"); else diff --git a/softwareDirectory/AutoVerScheme/my_task.cpp b/softwareDirectory/AutoVerScheme/my_task.cpp index 1735575..cd735f8 100644 --- a/softwareDirectory/AutoVerScheme/my_task.cpp +++ b/softwareDirectory/AutoVerScheme/my_task.cpp @@ -62,7 +62,8 @@ } void My_Task::Load() { - QList> PageData; + + //QList> PageData; //先设置为行为0 ui->tableWidget->setRowCount(0); //添加comboBox @@ -86,11 +87,29 @@ QString userId=""; data = BaseCommonApi::getMyTasks(userId,"3"); + QString State; + //设置单页显示数量 + page=20; + // 创建分页表格控件 + PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); + pagedTable->setData(data.count(), page); // 每页10行 + connect(pagedTable, &PagedTableWidget::pageChanged, this,&My_Task::onpageChanged); + this->onpageChanged(0); + +} +void My_Task::onpageChanged(int currPage){ + currPage+=1; + // 计算当前页的开始和结束索引 + int start = (currPage - 1) * page; + int end = std::min(start + page, data.size()); + // 从 QList 中筛选出当前页的数据 + QList tempdate = data.mid(start, end - start); int rowCount = 0; int row=0; QString State; - for (const MyTask& myTask : data) { - if(myTask.measure_status=="3" || myTask.measure_status=="4"){ + ui->tableWidget->setRowCount(0); + for (const MyTask& myTask : tempdate) { + QList TempData; rowCount = ui->tableWidget->rowCount(); @@ -118,42 +137,15 @@ ui->tableWidget->setItem(row, 10,new QTableWidgetItem("检测完成")); } - //渲染下拉框 - SetHomePaheCombox(myTask); - //QDebug - - //添加 PageData数据 - TempData.append(QString::number(row+1)); - TempData.append(myTask.sample_name); - TempData.append(myTask.sample_model); - TempData.append(myTask.help_instruction); - TempData.append(myTask.manufacture_no); - TempData.append(myTask.manufacturer); - TempData.append(myTask.customer_name); - TempData.append(myTask.FULL_NAME); - TempData.append(myTask.require_over_time.toString()); - TempData.append(State); - TempData.append(myTask.measure_status); - PageData.append(TempData); + //渲染下拉框 + SetHomePaheCombox(myTask); row++; - } - - } - //设置分页控件 - // 创建分页表格控件 - - PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); - //data转换位QList> - pagedTable->setData(PageData, 20,ui->tableWidget); // 每页10行 - //ui->HBoxPageLayout->addWidget(pagedTable); - //setLayout(ui->HBoxPageLayout); - // 连接信号以处理页码变化 - /* connect(pagedTable, &PagedTableWidget::pageChanged, this, [=](int page) { - // 在这里处理页码变化事件,比如更新UI中的其他部分 - qDebug() << "Page changed to:" << page; - });*/ + }; + //按钮点击事件 + // QMessageBox::information(this, "点击按钮",QString::number(page)); + // qDebug() << "Page changed to:" << page; } void My_Task::SetHomePaheCombox(MyTask entity) { diff --git a/softwareDirectory/AutoVerScheme/my_task.h b/softwareDirectory/AutoVerScheme/my_task.h index 289e7f4..8a4ad07 100644 --- a/softwareDirectory/AutoVerScheme/my_task.h +++ b/softwareDirectory/AutoVerScheme/my_task.h @@ -26,9 +26,11 @@ void on_pushButtonUpdate_clicked(); void on_SeachButton_clicked(); + void onpageChanged(int page); public: QList data; - + int page; + int totalcount; private: Ui::My_Task *ui; }; diff --git a/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp b/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp index e9cfb66..3ef9d60 100644 --- a/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp @@ -3,7 +3,7 @@ #include "InfoBase.h" #include "QMessageBox" #include "basecommonapi.h" - +#include "PageControl.h" //标准设备管理 .cpp Standard_DeviceItem::Standard_DeviceItem(QWidget *parent) : @@ -32,7 +32,7 @@ // ui->tableWidget->setRowCount(10); // 设置10行 ui->tableWidget->setColumnCount(7); // 设置11列 - ui->tableWidget->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnWidth(0, 0); // 设置第一列的宽度为100像素 ui->tableWidget->verticalHeader()->setParent(nullptr); //隐藏行头 //QTableWidgetItem *item = new QTableWidgetItem("测试数据"); //item->setTextAlignment(Qt::AlignCenter); @@ -102,12 +102,32 @@ // 调用数据库管理器的函数获取数据 - int rowCount=0; - int row=0; + data = BaseCommonApi::getBizDeviceManage(); + QString State; + //设置单页显示数量 + page=20; + // 创建分页表格控件 + PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); + pagedTable->setData(data.count(), page); // 每页10行 + connect(pagedTable, &PagedTableWidget::pageChanged, this,&Standard_DeviceItem::onpageChanged); + this->onpageChanged(0); - for (const BizDevice& bizDevice : data) { +} +void Standard_DeviceItem::onpageChanged(int currPage){ + + currPage+=1; + // 计算当前页的开始和结束索引 + int start = (currPage - 1) * page; + int end = std::min(start + page, data.size()); + // 从 QList 中筛选出当前页的数据 + QList tempdate = data.mid(start, end - start); + int rowCount = 0; + int row=0; + QString State; + ui->tableWidget->setRowCount(0); + for (const BizDevice& bizDevice : tempdate) { rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -147,8 +167,9 @@ SetHomePaheCombox(bizDevice); row++; } - } + + void Standard_DeviceItem::OnButtonSelectClicked(QString id) { //添加 diff --git a/softwareDirectory/AutoVerScheme/standard_deviceitem.h b/softwareDirectory/AutoVerScheme/standard_deviceitem.h index f522658..c506728 100644 --- a/softwareDirectory/AutoVerScheme/standard_deviceitem.h +++ b/softwareDirectory/AutoVerScheme/standard_deviceitem.h @@ -30,6 +30,9 @@ void on_pushButton_8_clicked(); public: QList data; + void onpageChanged(int currPage); + int page; + int totalcount; private: Ui::Standard_DeviceItem *ui; }; diff --git a/softwareDirectory/AutoVerScheme/standard_deviceitem.ui b/softwareDirectory/AutoVerScheme/standard_deviceitem.ui index 9b1acd4..861993d 100644 --- a/softwareDirectory/AutoVerScheme/standard_deviceitem.ui +++ b/softwareDirectory/AutoVerScheme/standard_deviceitem.ui @@ -233,6 +233,24 @@ + + + + + + + + Qt::Horizontal + + + + 1108 + 36 + + + + + diff --git a/softwareDirectory/AutoVerScheme/syncdialog.cpp b/softwareDirectory/AutoVerScheme/syncdialog.cpp new file mode 100644 index 0000000..f9195f1 --- /dev/null +++ b/softwareDirectory/AutoVerScheme/syncdialog.cpp @@ -0,0 +1,207 @@ +#include "syncdialog.h" +#include "ui_syncdialog.h" + + +int SyncDialog::m_totalTasks; +int SyncDialog::stepcount; +int SyncDialog::filecount; + + +SyncDialog::SyncDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::SyncDialog) +{ + ui->setupUi(this); + + + +} + +SyncDialog::~SyncDialog() +{ + delete ui; +} + +void SyncDialog::on_button_Start_clicked() +{ + + + //qint64 id = dbmang.generateId(); + //zdlogId=QString::number(id); + zdDataSyncList.clear(); + querydstList.clear(); + //从主系统下载 + //连接两个数据库 + bool IsOpen=false; + bool IsOpenMain=false; + + DatabaseConnection *Conn=DatabaseConnection::getInstance(); + //DatabaseConnectionMainSys *MainConn=DatabaseConnectionMainSys::getInstance(); + if(!Conn->isopen()){IsOpen=Conn->open();}else{IsOpen=true;}; + if(!Conn->isopenmain()){IsOpenMain=Conn->openmain();}else{IsOpenMain=true;}; + + // 记录任务数量 + + m_totalTasks=0; + stepcount=0; + filecount=0; + // 获取第一个数据库的所有表名 + dstDb=Conn->getDatabase(); + srcDb=Conn->getDatabaseMain(); + QSqlQuery querydst(dstDb); + querydst.exec("SHOW TABLES"); + QSqlQuery query(srcDb); + query.exec("SHOW TABLES"); + + while(querydst.next()){ + QString tableName = querydst.value(0).toString(); + if(tableName.contains("act_") ||tableName.contains("flw_ru_")){continue;}; + querydstList.append(tableName);}; + // 创建一个线程池 + threadPool= QThreadPool::globalInstance(); + threadPool->setMaxThreadCount(5); // 设置线程池中的最大线程数 + // 遍历表名,为每个表创建一个任务并提交到线程池 + BaseCommonApi::SaveLogInfo(filePath,"开始下载同步"); + + while (query.next()) { + QString tableName = query.value(0).toString(); + if(!querydstList.contains(tableName)){continue;}; + if(tableName.contains("ACT_") ||tableName.contains("FLW_RU_")){continue;}; + SyncTask *task = new SyncTask(srcDb, dstDb, tableName); + connectTaskSignals(task); + // 提交任务到线程池 + threadPool->start(task); + ++m_totalTasks; + // + + } + //总数量 + ui->lab_sum->setText(QString::number(m_totalTasks)); + progressDecrement=static_cast(100) / m_totalTasks; + +} +void SyncDialog::connectTaskSignals(SyncTask *task) { + connect(task, &SyncTask::taskCompleted, this, &SyncDialog::onTaskCompleted); + connect(task, &SyncTask::TextState, this, &SyncDialog::onTextState); + connect(this,&SyncDialog::StopRequested,task,&SyncTask::UpdateState); + //当前正在执行的 +} +void SyncDialog::onTaskCompleted(int success,QString tableName, const QString& errorMessage) +{ + if(success!=2){ + if(querydstList.contains(tableName)){querydstList.removeAll(tableName);}; + //添加同步表 + //任务完成 任务失败 都需要添加 + qint64 id = dbmang.generateId(); + zdDataSync zdDataSyncentity; + zdDataSyncentity.id=QString::number(id);; + zdDataSyncentity.remark=errorMessage; + zdDataSyncentity.log_sync_id=""; + zdDataSyncentity.sync_type=QString::number(success+1); + zdDataSyncList.append(zdDataSyncentity); + // dbmang.InsertzdDataSync(zdDataSyncentity); + }; + QString mess; + if (success==0) { + // 任务成功完成 + mess = "任务完成"; + mess+=errorMessage; + + } else if(success==1){ + // 任务执行失败 + mess = "任务失败"; + mess +=errorMessage; + filecount++; + //失败数量 + ui->lab_fail->setText(QString::number(filecount));; + }else{ + mess = "正在执行"; + mess +=errorMessage+"....."; + } + //log保存 + BaseCommonApi::SaveLogInfo(filePath,mess); + //界面listview显示 + ui->listWidget->addItem(mess); + // 当添加新项后,滚动到底部 + ui->listWidget->scrollToBottom(); + +} +void SyncDialog::onTextState() +{ + + stepcount++; + //成功数量 + ui->lab_succ->setText(QString::number(stepcount));; + //更新进度条 + int progress = static_cast(progressDecrement * stepcount); + ui->progressBar->setValue(progress); + if(stepcount>=m_totalTasks) + { + this->StopSync(); + } + +} + +void SyncDialog::on_button_Close_clicked() +{ + emit StopRequested(2); + threadPool->waitForDone(); + this->StopSync(); + srcDb.close(); + this->close(); +} +void SyncDialog::StopSync() +{ + ui->progressBar->setValue(100); + srcDb.close(); + //dstDb.close(); + + //添加日志表 + zdLog zlog; + zlog.id=QString::number( dbmang.generateId());; + zlog.type="1"; + if(filecount==0) + { + zlog.is_sync="成功"; + }else + { + zlog.is_sync="失败"; + } + zlog.sync_time=QDateTime::currentDateTime(); + zlog.remark="错误数量"+QString::number(filecount); + dbmang.InsertzdLog(zlog); + //添加记录表 + for (int i=0;ibutton_step->text()=="暂停") + { + ui->button_step->setText("继续"); + emit StopRequested(1); + + + }else{ + ui->button_step->setText("暂停"); + emit StopRequested(0); + }; +} diff --git a/softwareDirectory/AutoVerScheme/syncdialog.h b/softwareDirectory/AutoVerScheme/syncdialog.h new file mode 100644 index 0000000..2d5c41c --- /dev/null +++ b/softwareDirectory/AutoVerScheme/syncdialog.h @@ -0,0 +1,60 @@ +#ifndef SYNCDIALOG_H +#define SYNCDIALOG_H + +#include +#include "databaseconnection.h" +#include "basecommonapi.h" +#include "databaseconnectionmainsys.h" +#include +#include +#include +#include +#include +#include "synctask.h" + +namespace Ui { +class SyncDialog; +} + +class SyncDialog : public QDialog +{ + Q_OBJECT + +public: + explicit SyncDialog(QWidget *parent = nullptr); + ~SyncDialog(); + +private slots: + void on_button_Start_clicked(); + + + void connectTaskSignals(SyncTask *task); + void onTaskCompleted(int success,QString tableName, const QString& errorMessage); + void onTextState(); + void on_button_Close_clicked(); + void StopSync(); + void on_button_step_clicked(); + +public: + static int m_totalTasks; + static int filecount; + static int stepcount; + + QThreadPool *threadPool; + QSqlDatabase dstDb; + QSqlDatabase srcDb; + double progressDecrement; + QString filePath = "C:\\AutoVerScheme\\sync_info.txt"; + + QString zdlogId=""; + + BaseCommonApi dbmang; + QList zdDataSyncList; + QList querydstList; +signals: + void StopRequested(int state); // 定义暂停 停止请求信号 +private: + Ui::SyncDialog *ui; +}; + +#endif // SYNCDIALOG_H diff --git a/softwareDirectory/AutoVerScheme/syncdialog.ui b/softwareDirectory/AutoVerScheme/syncdialog.ui new file mode 100644 index 0000000..54cba8b --- /dev/null +++ b/softwareDirectory/AutoVerScheme/syncdialog.ui @@ -0,0 +1,178 @@ + + + SyncDialog + + + + 0 + 0 + 696 + 485 + + + + Dialog + + + background-color:white;; +color:black; + + + + + + background-color:white; + + + 下载数据 + + + + + + + + 总同步任务: + + + + + + + 0 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 失败任务: + + + + + + + 0 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 完成任务: + + + + + + + 0 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 0 + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 开始 + + + + + + + 暂停 + + + + + + + 关闭 + + + + + + + + + + + + + diff --git a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro index bf70fab..d9a99ea 100644 --- a/softwareDirectory/AutoVerScheme/AutoVerScheme.pro +++ b/softwareDirectory/AutoVerScheme/AutoVerScheme.pro @@ -35,6 +35,7 @@ create_task.cpp \ createtask_scandevice.cpp \ databaseconnection.cpp \ + databaseconnectionmainsys.cpp \ datasyncview.cpp \ depar_task.cpp \ depar_task_server.cpp \ @@ -55,6 +56,7 @@ newverifymethod.cpp \ rulefileitem.cpp \ standard_deviceitem.cpp \ + syncdialog.cpp \ synctask.cpp \ testdataitem.cpp \ testview.cpp \ @@ -69,6 +71,7 @@ DataProcessingBLL.h \ PageControl.h \ createtask_scandevice.h \ + databaseconnectionmainsys.h \ formaddrsetting.h \ formcommsetting.h \ id/IdWorker.h \ @@ -104,6 +107,7 @@ newverifymethod.h \ rulefileitem.h \ standard_deviceitem.h \ + syncdialog.h \ synctask.h \ testdataitem.h \ testview.h \ @@ -138,6 +142,7 @@ newverifymethod.ui \ rulefileitem.ui \ standard_deviceitem.ui \ + syncdialog.ui \ testdataitem.ui \ testview.ui \ verifydevice.ui \ diff --git a/softwareDirectory/AutoVerScheme/PageControl.cpp b/softwareDirectory/AutoVerScheme/PageControl.cpp index d0fd72b..d1bdddc 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.cpp +++ b/softwareDirectory/AutoVerScheme/PageControl.cpp @@ -22,14 +22,14 @@ } } -void PagedTableWidget::setData(const QList> &data, int rowsPerPage,QTableWidget *table) { - tableWidget=table; - +void PagedTableWidget::setData(int datacount, int rowsPerPage) { + //tableWidget=table; + totaldatacount=datacount; this->rowsPerPage = rowsPerPage; - allData = data; + //allData = data; currentPage = 0; createPageButtons(); - updateTable(); + //updateTable(); } void PagedTableWidget::setCurrentPage(int page) { @@ -39,7 +39,7 @@ button->setChecked(false); }*/ currentPage = page; - updateTable(); + //updateTable(); emit pageChanged(page); } } @@ -89,6 +89,7 @@ setCurrentPage(pageIndex); } } +/* void PagedTableWidget::updateTable() { //tableWidget->clear(); tableWidget->setRowCount(0); @@ -105,7 +106,7 @@ } } } - +*/ void PagedTableWidget::createPageButtons() { int totalPages = calculateTotalPages(); for (auto button : pageButtons) { @@ -150,5 +151,5 @@ } int PagedTableWidget::calculateTotalPages() { - return ((allData.count() + rowsPerPage -1) / rowsPerPage); + return ((totaldatacount + rowsPerPage -1) / rowsPerPage); } diff --git a/softwareDirectory/AutoVerScheme/PageControl.h b/softwareDirectory/AutoVerScheme/PageControl.h index 74ed1ce..2224760 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.h +++ b/softwareDirectory/AutoVerScheme/PageControl.h @@ -15,7 +15,7 @@ explicit PagedTableWidget(QWidget *parent = nullptr,QHBoxLayout *PageLayout=NULL); ~PagedTableWidget(); - void setData(const QList> &data, int rowsPerPage = 10,QTableWidget *table=NULL); + void setData(int datacount, int rowsPerPage = 10); void setCurrentPage(int page); signals: @@ -30,6 +30,7 @@ QHBoxLayout *pageLayout; QList pageButtons; QList> allData; + int totaldatacount; int rowsPerPage; int currentPage; diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.cpp b/softwareDirectory/AutoVerScheme/basecommonapi.cpp index 49cbd7e..6f6fe94 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.cpp +++ b/softwareDirectory/AutoVerScheme/basecommonapi.cpp @@ -13,7 +13,7 @@ } const QString BaseCommonApi::temporary_user_id="1634107227953819649"; const QString BaseCommonApi::measure_person_id="1695282436182188034"; - +static SyncRunStatus syncstate=SyncRunStatus::Stopped; //sys_user表的id转换为measure_person_id 检定人id(meter_staff表id) @@ -167,7 +167,8 @@ "JOIN eqpt_equipment_info eei ON eei.id = blei.sample_id " "JOIN biz_business_order_info bo ON bo.id = blei.order_id " "LEFT JOIN sys_dept sd ON blei.measure_dept_id = sd.ID " - " WHERE blei.measure_person_id = :person_id " + " WHERE blei.measure_person_id = :person_id " + " AND blei.measure_status =3 or blei.measure_status = 4 " " ORDER BY blei.update_time DESC"); // 将参数绑定到占位符 @@ -175,7 +176,8 @@ //query.bindValue(":status", status); if (query.exec()) { while (query.next()) { - MyTask task; + + MyTask task; task.id = query.value("id").toString(); task.sample_name = query.value("sampleName").toString(); task.sample_model = query.value("sampleModel").toString(); @@ -2872,9 +2874,40 @@ return result; } +//保存log信息 +//log文件 + bool BaseCommonApi::SaveLogInfo(QString path,QString Info) +{ + QByteArray utf8Dat; + QString Message=Info; + QFile file(path); + // 如果目录不存在,则创建目录 + // 获取文件所在的目录 + QDir logDir = QDir(QFileInfo(path).absolutePath()); + if (!logDir.exists()) { + if (!logDir.mkpath(".")) { + qDebug() << "Failed to create log directory:" << logDir.absolutePath(); + return false; + } + } + + if (!file.open(QIODevice::Append | QIODevice::Text)) { + qDebug() << "无法打开文件:" << file.errorString(); + return false; + } + QTextStream out(&file); + utf8Dat = Message.toUtf8(); + out << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss") + << "\t" << utf8Dat << "\n"; + file.close(); + return true; + } + + //新增日志表数据 bool BaseCommonApi::InsertzdLog(zdLog log) { + log.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_log(id,is_sync,sync_time,remark,userid,type,create_time,update_time) " " VALUES(:id,:is_sync,:sync_time,:remark,:userid,:type,:create_time,:update_time) "); @@ -2898,6 +2931,7 @@ //根据userid查询日志表数据 QList BaseCommonApi::getzdLogByuserId(QString userid) { + userid=temporary_user_id; QList result; QSqlQuery query; query.prepare("SELECT * FROM zd_log WHERE userid = :userid "); @@ -2922,6 +2956,7 @@ //新增数据同步表 bool BaseCommonApi::InsertzdDataSync(zdDataSync data) { + data.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_data_sync(id,type,ssql,userid,remark,create_time,update_time,log_sync_id,sync_type) " " VALUES " @@ -2945,12 +2980,12 @@ return isSuccess; } //根据userid查询数据同步表 -QList getzdDataSyncByuserId(QString userid) +QList BaseCommonApi::getzdDataSyncByuserId(QString log_sync_id) { QList result; QSqlQuery query; - query.prepare("SELECT * FROM zd_data_sync WHERE userid= :userid "); - query.bindValue(":userid",userid); + query.prepare("SELECT * FROM zd_data_sync WHERE log_sync_id= :log_sync_id "); + query.bindValue(":log_sync_id",log_sync_id); if (query.exec()) { while (query.next()) { zdDataSync data; @@ -2972,3 +3007,4 @@ } + diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.h b/softwareDirectory/AutoVerScheme/basecommonapi.h index 12196fb..4949683 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.h +++ b/softwareDirectory/AutoVerScheme/basecommonapi.h @@ -919,6 +919,7 @@ QDateTime create_time; QDateTime update_time; }; + //数据同步-数据表 class zdDataSync { @@ -935,6 +936,12 @@ }; +enum class SyncRunStatus { + + Running, + Stopped, + Paused +}; using namespace Jiawa::Core; class BaseCommonApi @@ -945,7 +952,6 @@ const static QString temporary_costomer_id; const static QString measure_person_id; - QString encrypt(const QString &str, const QString &publicKey); //判断检定装置表并查询 参数设备id @@ -1137,14 +1143,19 @@ //单独查询任务单表 //更新 任务单 static InsertTask SelectTaskSingle(QString order_id); + + //log文件 + static bool SaveLogInfo(QString path,QString Info); + //新增日志表数据 static bool InsertzdLog(zdLog log); //查询日志表数据 static QList getzdLogByuserId(QString userid); //新增数据同步表 static bool InsertzdDataSync(zdDataSync data); - //根据userid查询数据同步表 - static QList getzdDataSyncByuserId(QString userid); + //根据log_sync_id查询数据同步表 + static QList getzdDataSyncByuserId(QString log_sync_id); + }; diff --git a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp index 00d746b..ae60962 100644 --- a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp @@ -352,6 +352,7 @@ } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -395,6 +396,7 @@ row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.cpp b/softwareDirectory/AutoVerScheme/databaseconnection.cpp index 1d957d9..5284fe6 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.cpp +++ b/softwareDirectory/AutoVerScheme/databaseconnection.cpp @@ -10,17 +10,21 @@ { // 连接数据库 - db = QSqlDatabase::addDatabase("QODBC"); - /*db.setHostName("111.198.10.15"); - db.setDatabaseName("casic_metering_xichang"); - db.setPort(21906); - db.setUserName("zdjdcs"); - db.setPassword("11111111");*/ - db.setHostName("localhost"); - db.setDatabaseName("zdjd"); - db.setPort(3306); - db.setUserName("root"); - db.setPassword("123456"); + localdb = QSqlDatabase::addDatabase("QODBC"); + + localdb.setHostName("localhost"); + localdb.setDatabaseName("zdjd"); + localdb.setPort(3306); + localdb.setUserName("root"); + localdb.setPassword("123456"); + + Maindb = QSqlDatabase::addDatabase("QODBC","Main"); + Maindb.setHostName("111.198.10.15"); + Maindb.setDatabaseName("casic_metering_xichang"); + Maindb.setPort(21906); + Maindb.setUserName("zdjdcs"); + Maindb.setPassword("11111111"); + } @@ -29,18 +33,28 @@ close(); } bool DatabaseConnection::open() { - return db.open(); + return localdb.open(); +} +bool DatabaseConnection::openmain() { + return Maindb.open(); } bool DatabaseConnection::isopen() { - return db.isOpen(); + return localdb.isOpen(); } - +bool DatabaseConnection::isopenmain() { + return Maindb.isOpen(); +} void DatabaseConnection::close() { - db.close(); + localdb.close(); } - +void DatabaseConnection::closemain() { + Maindb.close(); +} QSqlDatabase& DatabaseConnection::getDatabase() { - return db; + return localdb; +} +QSqlDatabase& DatabaseConnection::getDatabaseMain() { + return Maindb; } DatabaseConnection* DatabaseConnection::getInstance() { diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.h b/softwareDirectory/AutoVerScheme/databaseconnection.h index 586b794..5f9810b 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.h +++ b/softwareDirectory/AutoVerScheme/databaseconnection.h @@ -16,8 +16,12 @@ ~DatabaseConnection(); bool open(); bool isopen(); + bool openmain(); void close(); + void closemain(); + bool isopenmain(); QSqlDatabase& getDatabase(); + QSqlDatabase& getDatabaseMain(); private: //单列模式 保证DatabaseConnection的唯一性 static DatabaseConnection* Connect; @@ -33,7 +37,8 @@ //如果尝试这样做,编译器同样会报错。 DatabaseConnection& operator=(const DatabaseConnection&) = delete; //数据库db类 - QSqlDatabase db; + QSqlDatabase Maindb; + QSqlDatabase localdb; }; #endif // DATABASECONNECTION_H diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp new file mode 100644 index 0000000..080288b --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp @@ -0,0 +1,54 @@ +#include "databaseconnectionmainsys.h" + + + + +DatabaseConnectionMainSys* DatabaseConnectionMainSys::Connect = nullptr; +QMutex DatabaseConnectionMainSys::mutex; + +DatabaseConnectionMainSys::DatabaseConnectionMainSys() +{ + + // 连接数据库 + dbmain = QSqlDatabase::addDatabase("QODBC"); + dbmain.setHostName("111.198.10.15"); + dbmain.setDatabaseName("casic_metering_xichang"); + dbmain.setPort(21906); + dbmain.setUserName("zdjdcs"); + dbmain.setPassword("11111111"); + /* db.setHostName("localhost"); + db.setDatabaseName("zdjd"); + db.setPort(3306); + db.setUserName("root"); + db.setPassword("123456");*/ + + +} +DatabaseConnectionMainSys::~DatabaseConnectionMainSys() { + // 在析构函数中关闭数据库连接 + close(); +} +bool DatabaseConnectionMainSys::open() { + return dbmain.open(); +} +bool DatabaseConnectionMainSys::isopen() { + return dbmain.isOpen(); +} + +void DatabaseConnectionMainSys::close() { + dbmain.close(); +} + +QSqlDatabase& DatabaseConnectionMainSys::getDatabase() { + return dbmain; +} +DatabaseConnectionMainSys* DatabaseConnectionMainSys::getInstance() +{ + if (!Connect) { + QMutexLocker locker(&mutex); + if (!Connect) { + Connect = new DatabaseConnectionMainSys(); + } + } + return Connect; +} diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h new file mode 100644 index 0000000..57702ad --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h @@ -0,0 +1,41 @@ +#ifndef DATABASECONNECTIONMAINSYS_H +#define DATABASECONNECTIONMAINSYS_H +#include +#include +#include +#include + + +class DatabaseConnectionMainSys +{ + + +public: + //获取数据库实例 + static DatabaseConnectionMainSys* getInstance(); + + DatabaseConnectionMainSys(); + ~DatabaseConnectionMainSys(); + bool open(); + bool isopen(); + void close(); + QSqlDatabase& getDatabase(); +private: + //单列模式 保证MainSysDatabaseConnection的唯一性 + static DatabaseConnectionMainSys* Connect; + //QMutex 来确保在多线程环境下单例的正确创建。 + static QMutex mutex; + + //这是拷贝构造函数的声明,后面跟着 = delete; 表示这个构造函数被删除了。 + //这意味着你不能通过拷贝另一个 DatabaseConnection 对象来创建新的 DatabaseConnection 对象。 + //如果尝试这样做,编译器会报错。 + DatabaseConnectionMainSys(const DatabaseConnectionMainSys&) = delete; + //这是拷贝赋值运算符的声明,同样后面跟着 = delete; 表示这个运算符被删除了。 + //这意味着你不能将一个 DatabaseConnection 对象赋值给另一个 DatabaseConnection 对象。 + //如果尝试这样做,编译器同样会报错。 + DatabaseConnectionMainSys& operator=(const DatabaseConnectionMainSys&) = delete; + //数据库db类 + QSqlDatabase dbmain; +}; + +#endif // DATABASECONNECTIONMAINSYS_H diff --git a/softwareDirectory/AutoVerScheme/datasyncview.cpp b/softwareDirectory/AutoVerScheme/datasyncview.cpp index fbf4508..06c7f9a 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.cpp +++ b/softwareDirectory/AutoVerScheme/datasyncview.cpp @@ -1,11 +1,10 @@ #include "datasyncview.h" #include "ui_datasyncview.h" -#include "synctask.h" -#include "databaseconnection.h" -#include "mainsysdatabaseconnection.h" +#include "syncdialog.h" - +QString filePath = "C:\\AutoVerScheme\\sync_info.txt"; +// 获取当前时间戳 DataSyncView::DataSyncView(QWidget *parent) : QWidget(parent), ui(new Ui::DataSyncView) @@ -20,7 +19,7 @@ } void DataSyncView::initForm() { - //tableWidget设置 + ui->stackedWidget->setCurrentIndex(0); //设置控件的边框显示 ui->tableWidget->setStyleSheet("QHeaderView::section {" "border: 1px solid grey;" @@ -32,29 +31,129 @@ "}"); ui->tableWidget->setRowCount(10); // 设置10行 - ui->tableWidget->setColumnCount(4); // 设置11列 - ui->tableWidget->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnCount(7); // 设置11列 + ui->tableWidget->setColumnWidth(0, 0); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnWidth(2, 200); // 设置第一列的宽度为100像素 ui->tableWidget->verticalHeader()->setParent(nullptr); //隐藏行头 - QTableWidgetItem *item = new QTableWidgetItem("测试数据"); - item->setTextAlignment(Qt::AlignCenter); - ui->tableWidget->setItem(0, 0, item); //设置数据 + + //初始化TableWidget 设置列 QStringList headers; - headers << "序号" << "同步时间" << "是否同步成功" << "备注" ; + headers <<"id" << "序号" << "同步时间" << "是否同步成功" << "备注" + <<"类型" <<"操作"; ui->tableWidget->setHorizontalHeaderLabels(headers); + //详情内 + + //设置控件的边框显示 + ui->tableWidget_2->setStyleSheet("QHeaderView::section {" + "border: 1px solid grey;" + "border-left:none;" + "border-top:none;" + "background-color:white;" + " color:black;" + "font: bold 18px Arial, sans-serif;" + "}"); + + ui->tableWidget_2->setRowCount(10); // 设置10行 + ui->tableWidget_2->setColumnCount(3); // 设置11列 + ui->tableWidget_2->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget_2->verticalHeader()->setParent(nullptr); //隐藏行头 + ui->tableWidget_2->setColumnWidth(1, 1000); // 设置第一列的宽度为100像素 + + //初始化TableWidget 设置列 + + headers << "序号" << "信息" << "状态" ; + ui->tableWidget_2->setHorizontalHeaderLabels(headers); + + //数据显示 + + //先设置为行为0 + ui->tableWidget->setRowCount(0); + int rowCount=0; + int row=0; + QList zdlog= BaseCommonApi::getzdLogByuserId(""); + for(const zdLog & zd:zdlog) + { + rowCount = ui->tableWidget->rowCount(); + ui->tableWidget->insertRow(rowCount); + ui->tableWidget->setItem(row, 0, new QTableWidgetItem(zd.id)); + ui->tableWidget->setItem(row, 1, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget->setItem(row, 2, new QTableWidgetItem(zd.sync_time.toString())); + ui->tableWidget->setItem(row, 3, new QTableWidgetItem(zd.is_sync)); + ui->tableWidget->setItem(row, 4, new QTableWidgetItem(zd.remark)); + if(zd.type=="1") + { + ui->tableWidget->setItem(row, 5, new QTableWidgetItem("下载")); + }else{ ui->tableWidget->setItem(row, 5, new QTableWidgetItem("上传")); } + + //添加操作按钮 + QPushButton *button = new QPushButton("查询信息"); + button->setIconSize(QSize(16,16)); + button->setIcon(QIcon(":/image/Index/u2327.svg")); + ui->tableWidget->setCellWidget(row, 6, button); + //设置按钮简单样式 + button->setStyleSheet("QPushButton {" + " border: none; /* 无边框 */" + " color: green; /* 文本颜色 */" + " text-decoration: underline; /* 文本下划线 */" + "}"); + + // 设置鼠标悬停时的光标样式为小手图标 + button->setCursor(Qt::PointingHandCursor); + // 连接按钮的 clicked 信号到自定义槽函数 + connect(button, &QPushButton::clicked, this, [this, button, zd]() { + // 获取当前行第一列的 ID + + OnButtonSelectClicked(zd); + + }); + row++; + } } void DataSyncView::on_DownloadDataButton_clicked() { - //从主系统下载 + + SyncDialog *syncDialog = new SyncDialog(this); + syncDialog->exec(); // 显示进度条窗体并阻塞主窗口 + + this->initForm(); + } -void DataSyncView::syncTable() +void DataSyncView::OnButtonSelectClicked(zdLog log) { - //连接两个数据库 - bool IsOpen=false; - DatabaseConnection *Conn=DatabaseConnection::getInstance(); - IsOpen=Conn->open(); - //MainSysDatabaseConnection *MainConn=MainSysDatabaseConnection::getInstance(); - //IsOpen=MainConn->open(); + ui->stackedWidget->setCurrentIndex(1); + ui->tableWidget_2->setRowCount(0); + int rowCount=0; + int row=0; + QList data= BaseCommonApi::getzdDataSyncByuserId(log.id); + for(const zdDataSync & item:data) + { + rowCount = ui->tableWidget_2->rowCount(); + ui->tableWidget_2->insertRow(rowCount); + ui->tableWidget_2->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget_2->setItem(row, 1, new QTableWidgetItem(item.remark)); + QTableWidgetItem *itemRow; + if(item.sync_type=="0"){ + itemRow = new QTableWidgetItem("未同步"); + itemRow->setBackground(QBrush(QColor(255, 255, 192))); + }else if (item.sync_type=="1") + { + itemRow = new QTableWidgetItem("同步成功"); + itemRow->setBackground(QBrush(QColor(173, 255, 47))); // 浅绿色 + }else{ + itemRow = new QTableWidgetItem("同步失败"); + itemRow->setBackground(QBrush(QColor(255, 105, 180))); // 浅红色 + } + itemRow->setTextAlignment(Qt::AlignCenter); + ui->tableWidget_2->setItem(row, 2, itemRow); + + row++; + } +} + +void DataSyncView::on_button_return_clicked() +{ + ui->stackedWidget->setCurrentIndex(0); } diff --git a/softwareDirectory/AutoVerScheme/datasyncview.h b/softwareDirectory/AutoVerScheme/datasyncview.h index 174480e..b2b9847 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.h +++ b/softwareDirectory/AutoVerScheme/datasyncview.h @@ -2,6 +2,16 @@ #define DATASYNCVIEW_H #include +#include +#include "synctask.h" +#include "databaseconnection.h" +#include "basecommonapi.h" +#include "databaseconnectionmainsys.h" +#include +#include +#include +#include +#include namespace Ui { class DataSyncView; @@ -18,8 +28,12 @@ void initForm(); //初始化界面数据 void on_DownloadDataButton_clicked(); - //异步更新 - void syncTable(); + void OnButtonSelectClicked(zdLog log); + void on_button_return_clicked(); + +public: + + private: Ui::DataSyncView *ui; }; diff --git a/softwareDirectory/AutoVerScheme/datasyncview.ui b/softwareDirectory/AutoVerScheme/datasyncview.ui index 53c379c..7c9df8e 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.ui +++ b/softwareDirectory/AutoVerScheme/datasyncview.ui @@ -14,21 +14,9 @@ 数据同步 - background-color:rgba(240, 240, 240, 1); + background-color:white; - - - 0 - - - 0 - - - 0 - - - 0 - + @@ -73,119 +61,173 @@ - - - background-color:white; - - - - - - - 3 - - - - - - 0 - 0 - - - - background-color:white; + + + + + + + background-color:white; + + + + + + + 3 + + + + + + 0 + 0 + + + + background-color:white; border:0; - - - - - - - - - - 0 - 0 - - - - font:bold 20px Arial, sans-serif; + + + + + + + + + + 0 + 0 + + + + font:bold 20px Arial, sans-serif; color:#334582; - - - 同步记录 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - background-color:#334582; + + + 同步记录 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + background-color:#334582; font: bold 18px Arial, sans-serif; color:white; padding:10px; - - - 下载数据 - - - - - - - - 200 - 0 - - - - - 100 - 40 - - - - Qt::RightToLeft - - - background-color:#334582; + + + 下载数据 + + + + + + + + 200 + 0 + + + + + 100 + 40 + + + + Qt::RightToLeft + + + background-color:#334582; font: bold 18px Arial, sans-serif; color:white; padding:10px; - - - 发送同步请求 - - - - :/image/Index/u8458.svg:/image/Index/u8458.svg - - - - - - - - - - - - - - + + + 发送同步请求 + + + + :/image/Index/u8458.svg:/image/Index/u8458.svg + + + + + + + + + + + + + + + + + + + + + + + + background-color:white; + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + color:black; + + + 返回 + + + + + + + + + + + + + diff --git a/softwareDirectory/AutoVerScheme/depar_task.cpp b/softwareDirectory/AutoVerScheme/depar_task.cpp index d551972..d58cf35 100644 --- a/softwareDirectory/AutoVerScheme/depar_task.cpp +++ b/softwareDirectory/AutoVerScheme/depar_task.cpp @@ -113,6 +113,7 @@ else State="否"; ui->tableWidget->setItem(row, 9, new QTableWidgetItem(State)); //设置数据 + SetHomePaheCombox(dept); //添加 PageData数据 TempData.append(QString::number(row+1)); TempData.append(dept.sample_name); @@ -133,9 +134,9 @@ //设置分页控件 // 创建分页表格控件 - PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); +// PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); //data转换位QList> - pagedTable->setData(PageData, 20,ui->tableWidget); // 每页20行 + // pagedTable->setData(PageData, 20,ui->tableWidget); // 每页20行 } void Depar_Task::on_SelectButton_clicked() @@ -155,26 +156,31 @@ if(dept.measure_status=="3" || dept.measure_status=="4"){ bool shouldAddRow = true; // 初始假设应该添加这一行 // 根据设备名称筛选 + QString names; if (ui->name->currentText() != "ALL") { + names=ui->name->currentText(); if (ui->name->currentText() != dept.sample_name) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } if (ui->mode->currentText() != "ALL") { + names=ui->mode->currentText(); if (ui->mode->currentText() != dept.sample_model) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } if (ui->customer->currentText() != "ALL") { + if (ui->customer->currentText() != dept.customer_name) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } - if (ui->dept->currentText() != "") { + if (ui->dept->currentText() != "ALL") { if (ui->dept->currentText() != dept.FULL_NAME) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); ui->tableWidget->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); @@ -193,9 +199,10 @@ State="否"; ui->tableWidget->setItem(row, 9, new QTableWidgetItem(State)); //设置数据 // - SetHomePaheCombox(dept); + //QDebug row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/indexwindow.cpp b/softwareDirectory/AutoVerScheme/indexwindow.cpp index eed192a..060b86e 100644 --- a/softwareDirectory/AutoVerScheme/indexwindow.cpp +++ b/softwareDirectory/AutoVerScheme/indexwindow.cpp @@ -58,7 +58,7 @@ DatabaseConnection *Conn=DatabaseConnection::getInstance(); //数据库连接 目前先放这里 后续需要放到登录界面 - bool IsOpen=Conn->open(); + bool IsOpen=Conn->open(); if(IsOpen) ShowMessageBox("数据库连接","连接成功"); else diff --git a/softwareDirectory/AutoVerScheme/my_task.cpp b/softwareDirectory/AutoVerScheme/my_task.cpp index 1735575..cd735f8 100644 --- a/softwareDirectory/AutoVerScheme/my_task.cpp +++ b/softwareDirectory/AutoVerScheme/my_task.cpp @@ -62,7 +62,8 @@ } void My_Task::Load() { - QList> PageData; + + //QList> PageData; //先设置为行为0 ui->tableWidget->setRowCount(0); //添加comboBox @@ -86,11 +87,29 @@ QString userId=""; data = BaseCommonApi::getMyTasks(userId,"3"); + QString State; + //设置单页显示数量 + page=20; + // 创建分页表格控件 + PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); + pagedTable->setData(data.count(), page); // 每页10行 + connect(pagedTable, &PagedTableWidget::pageChanged, this,&My_Task::onpageChanged); + this->onpageChanged(0); + +} +void My_Task::onpageChanged(int currPage){ + currPage+=1; + // 计算当前页的开始和结束索引 + int start = (currPage - 1) * page; + int end = std::min(start + page, data.size()); + // 从 QList 中筛选出当前页的数据 + QList tempdate = data.mid(start, end - start); int rowCount = 0; int row=0; QString State; - for (const MyTask& myTask : data) { - if(myTask.measure_status=="3" || myTask.measure_status=="4"){ + ui->tableWidget->setRowCount(0); + for (const MyTask& myTask : tempdate) { + QList TempData; rowCount = ui->tableWidget->rowCount(); @@ -118,42 +137,15 @@ ui->tableWidget->setItem(row, 10,new QTableWidgetItem("检测完成")); } - //渲染下拉框 - SetHomePaheCombox(myTask); - //QDebug - - //添加 PageData数据 - TempData.append(QString::number(row+1)); - TempData.append(myTask.sample_name); - TempData.append(myTask.sample_model); - TempData.append(myTask.help_instruction); - TempData.append(myTask.manufacture_no); - TempData.append(myTask.manufacturer); - TempData.append(myTask.customer_name); - TempData.append(myTask.FULL_NAME); - TempData.append(myTask.require_over_time.toString()); - TempData.append(State); - TempData.append(myTask.measure_status); - PageData.append(TempData); + //渲染下拉框 + SetHomePaheCombox(myTask); row++; - } - - } - //设置分页控件 - // 创建分页表格控件 - - PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); - //data转换位QList> - pagedTable->setData(PageData, 20,ui->tableWidget); // 每页10行 - //ui->HBoxPageLayout->addWidget(pagedTable); - //setLayout(ui->HBoxPageLayout); - // 连接信号以处理页码变化 - /* connect(pagedTable, &PagedTableWidget::pageChanged, this, [=](int page) { - // 在这里处理页码变化事件,比如更新UI中的其他部分 - qDebug() << "Page changed to:" << page; - });*/ + }; + //按钮点击事件 + // QMessageBox::information(this, "点击按钮",QString::number(page)); + // qDebug() << "Page changed to:" << page; } void My_Task::SetHomePaheCombox(MyTask entity) { diff --git a/softwareDirectory/AutoVerScheme/my_task.h b/softwareDirectory/AutoVerScheme/my_task.h index 289e7f4..8a4ad07 100644 --- a/softwareDirectory/AutoVerScheme/my_task.h +++ b/softwareDirectory/AutoVerScheme/my_task.h @@ -26,9 +26,11 @@ void on_pushButtonUpdate_clicked(); void on_SeachButton_clicked(); + void onpageChanged(int page); public: QList data; - + int page; + int totalcount; private: Ui::My_Task *ui; }; diff --git a/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp b/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp index e9cfb66..3ef9d60 100644 --- a/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp @@ -3,7 +3,7 @@ #include "InfoBase.h" #include "QMessageBox" #include "basecommonapi.h" - +#include "PageControl.h" //标准设备管理 .cpp Standard_DeviceItem::Standard_DeviceItem(QWidget *parent) : @@ -32,7 +32,7 @@ // ui->tableWidget->setRowCount(10); // 设置10行 ui->tableWidget->setColumnCount(7); // 设置11列 - ui->tableWidget->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnWidth(0, 0); // 设置第一列的宽度为100像素 ui->tableWidget->verticalHeader()->setParent(nullptr); //隐藏行头 //QTableWidgetItem *item = new QTableWidgetItem("测试数据"); //item->setTextAlignment(Qt::AlignCenter); @@ -102,12 +102,32 @@ // 调用数据库管理器的函数获取数据 - int rowCount=0; - int row=0; + data = BaseCommonApi::getBizDeviceManage(); + QString State; + //设置单页显示数量 + page=20; + // 创建分页表格控件 + PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); + pagedTable->setData(data.count(), page); // 每页10行 + connect(pagedTable, &PagedTableWidget::pageChanged, this,&Standard_DeviceItem::onpageChanged); + this->onpageChanged(0); - for (const BizDevice& bizDevice : data) { +} +void Standard_DeviceItem::onpageChanged(int currPage){ + + currPage+=1; + // 计算当前页的开始和结束索引 + int start = (currPage - 1) * page; + int end = std::min(start + page, data.size()); + // 从 QList 中筛选出当前页的数据 + QList tempdate = data.mid(start, end - start); + int rowCount = 0; + int row=0; + QString State; + ui->tableWidget->setRowCount(0); + for (const BizDevice& bizDevice : tempdate) { rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -147,8 +167,9 @@ SetHomePaheCombox(bizDevice); row++; } - } + + void Standard_DeviceItem::OnButtonSelectClicked(QString id) { //添加 diff --git a/softwareDirectory/AutoVerScheme/standard_deviceitem.h b/softwareDirectory/AutoVerScheme/standard_deviceitem.h index f522658..c506728 100644 --- a/softwareDirectory/AutoVerScheme/standard_deviceitem.h +++ b/softwareDirectory/AutoVerScheme/standard_deviceitem.h @@ -30,6 +30,9 @@ void on_pushButton_8_clicked(); public: QList data; + void onpageChanged(int currPage); + int page; + int totalcount; private: Ui::Standard_DeviceItem *ui; }; diff --git a/softwareDirectory/AutoVerScheme/standard_deviceitem.ui b/softwareDirectory/AutoVerScheme/standard_deviceitem.ui index 9b1acd4..861993d 100644 --- a/softwareDirectory/AutoVerScheme/standard_deviceitem.ui +++ b/softwareDirectory/AutoVerScheme/standard_deviceitem.ui @@ -233,6 +233,24 @@ + + + + + + + + Qt::Horizontal + + + + 1108 + 36 + + + + + diff --git a/softwareDirectory/AutoVerScheme/syncdialog.cpp b/softwareDirectory/AutoVerScheme/syncdialog.cpp new file mode 100644 index 0000000..f9195f1 --- /dev/null +++ b/softwareDirectory/AutoVerScheme/syncdialog.cpp @@ -0,0 +1,207 @@ +#include "syncdialog.h" +#include "ui_syncdialog.h" + + +int SyncDialog::m_totalTasks; +int SyncDialog::stepcount; +int SyncDialog::filecount; + + +SyncDialog::SyncDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::SyncDialog) +{ + ui->setupUi(this); + + + +} + +SyncDialog::~SyncDialog() +{ + delete ui; +} + +void SyncDialog::on_button_Start_clicked() +{ + + + //qint64 id = dbmang.generateId(); + //zdlogId=QString::number(id); + zdDataSyncList.clear(); + querydstList.clear(); + //从主系统下载 + //连接两个数据库 + bool IsOpen=false; + bool IsOpenMain=false; + + DatabaseConnection *Conn=DatabaseConnection::getInstance(); + //DatabaseConnectionMainSys *MainConn=DatabaseConnectionMainSys::getInstance(); + if(!Conn->isopen()){IsOpen=Conn->open();}else{IsOpen=true;}; + if(!Conn->isopenmain()){IsOpenMain=Conn->openmain();}else{IsOpenMain=true;}; + + // 记录任务数量 + + m_totalTasks=0; + stepcount=0; + filecount=0; + // 获取第一个数据库的所有表名 + dstDb=Conn->getDatabase(); + srcDb=Conn->getDatabaseMain(); + QSqlQuery querydst(dstDb); + querydst.exec("SHOW TABLES"); + QSqlQuery query(srcDb); + query.exec("SHOW TABLES"); + + while(querydst.next()){ + QString tableName = querydst.value(0).toString(); + if(tableName.contains("act_") ||tableName.contains("flw_ru_")){continue;}; + querydstList.append(tableName);}; + // 创建一个线程池 + threadPool= QThreadPool::globalInstance(); + threadPool->setMaxThreadCount(5); // 设置线程池中的最大线程数 + // 遍历表名,为每个表创建一个任务并提交到线程池 + BaseCommonApi::SaveLogInfo(filePath,"开始下载同步"); + + while (query.next()) { + QString tableName = query.value(0).toString(); + if(!querydstList.contains(tableName)){continue;}; + if(tableName.contains("ACT_") ||tableName.contains("FLW_RU_")){continue;}; + SyncTask *task = new SyncTask(srcDb, dstDb, tableName); + connectTaskSignals(task); + // 提交任务到线程池 + threadPool->start(task); + ++m_totalTasks; + // + + } + //总数量 + ui->lab_sum->setText(QString::number(m_totalTasks)); + progressDecrement=static_cast(100) / m_totalTasks; + +} +void SyncDialog::connectTaskSignals(SyncTask *task) { + connect(task, &SyncTask::taskCompleted, this, &SyncDialog::onTaskCompleted); + connect(task, &SyncTask::TextState, this, &SyncDialog::onTextState); + connect(this,&SyncDialog::StopRequested,task,&SyncTask::UpdateState); + //当前正在执行的 +} +void SyncDialog::onTaskCompleted(int success,QString tableName, const QString& errorMessage) +{ + if(success!=2){ + if(querydstList.contains(tableName)){querydstList.removeAll(tableName);}; + //添加同步表 + //任务完成 任务失败 都需要添加 + qint64 id = dbmang.generateId(); + zdDataSync zdDataSyncentity; + zdDataSyncentity.id=QString::number(id);; + zdDataSyncentity.remark=errorMessage; + zdDataSyncentity.log_sync_id=""; + zdDataSyncentity.sync_type=QString::number(success+1); + zdDataSyncList.append(zdDataSyncentity); + // dbmang.InsertzdDataSync(zdDataSyncentity); + }; + QString mess; + if (success==0) { + // 任务成功完成 + mess = "任务完成"; + mess+=errorMessage; + + } else if(success==1){ + // 任务执行失败 + mess = "任务失败"; + mess +=errorMessage; + filecount++; + //失败数量 + ui->lab_fail->setText(QString::number(filecount));; + }else{ + mess = "正在执行"; + mess +=errorMessage+"....."; + } + //log保存 + BaseCommonApi::SaveLogInfo(filePath,mess); + //界面listview显示 + ui->listWidget->addItem(mess); + // 当添加新项后,滚动到底部 + ui->listWidget->scrollToBottom(); + +} +void SyncDialog::onTextState() +{ + + stepcount++; + //成功数量 + ui->lab_succ->setText(QString::number(stepcount));; + //更新进度条 + int progress = static_cast(progressDecrement * stepcount); + ui->progressBar->setValue(progress); + if(stepcount>=m_totalTasks) + { + this->StopSync(); + } + +} + +void SyncDialog::on_button_Close_clicked() +{ + emit StopRequested(2); + threadPool->waitForDone(); + this->StopSync(); + srcDb.close(); + this->close(); +} +void SyncDialog::StopSync() +{ + ui->progressBar->setValue(100); + srcDb.close(); + //dstDb.close(); + + //添加日志表 + zdLog zlog; + zlog.id=QString::number( dbmang.generateId());; + zlog.type="1"; + if(filecount==0) + { + zlog.is_sync="成功"; + }else + { + zlog.is_sync="失败"; + } + zlog.sync_time=QDateTime::currentDateTime(); + zlog.remark="错误数量"+QString::number(filecount); + dbmang.InsertzdLog(zlog); + //添加记录表 + for (int i=0;ibutton_step->text()=="暂停") + { + ui->button_step->setText("继续"); + emit StopRequested(1); + + + }else{ + ui->button_step->setText("暂停"); + emit StopRequested(0); + }; +} diff --git a/softwareDirectory/AutoVerScheme/syncdialog.h b/softwareDirectory/AutoVerScheme/syncdialog.h new file mode 100644 index 0000000..2d5c41c --- /dev/null +++ b/softwareDirectory/AutoVerScheme/syncdialog.h @@ -0,0 +1,60 @@ +#ifndef SYNCDIALOG_H +#define SYNCDIALOG_H + +#include +#include "databaseconnection.h" +#include "basecommonapi.h" +#include "databaseconnectionmainsys.h" +#include +#include +#include +#include +#include +#include "synctask.h" + +namespace Ui { +class SyncDialog; +} + +class SyncDialog : public QDialog +{ + Q_OBJECT + +public: + explicit SyncDialog(QWidget *parent = nullptr); + ~SyncDialog(); + +private slots: + void on_button_Start_clicked(); + + + void connectTaskSignals(SyncTask *task); + void onTaskCompleted(int success,QString tableName, const QString& errorMessage); + void onTextState(); + void on_button_Close_clicked(); + void StopSync(); + void on_button_step_clicked(); + +public: + static int m_totalTasks; + static int filecount; + static int stepcount; + + QThreadPool *threadPool; + QSqlDatabase dstDb; + QSqlDatabase srcDb; + double progressDecrement; + QString filePath = "C:\\AutoVerScheme\\sync_info.txt"; + + QString zdlogId=""; + + BaseCommonApi dbmang; + QList zdDataSyncList; + QList querydstList; +signals: + void StopRequested(int state); // 定义暂停 停止请求信号 +private: + Ui::SyncDialog *ui; +}; + +#endif // SYNCDIALOG_H diff --git a/softwareDirectory/AutoVerScheme/syncdialog.ui b/softwareDirectory/AutoVerScheme/syncdialog.ui new file mode 100644 index 0000000..54cba8b --- /dev/null +++ b/softwareDirectory/AutoVerScheme/syncdialog.ui @@ -0,0 +1,178 @@ + + + SyncDialog + + + + 0 + 0 + 696 + 485 + + + + Dialog + + + background-color:white;; +color:black; + + + + + + background-color:white; + + + 下载数据 + + + + + + + + 总同步任务: + + + + + + + 0 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 失败任务: + + + + + + + 0 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 完成任务: + + + + + + + 0 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 0 + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 开始 + + + + + + + 暂停 + + + + + + + 关闭 + + + + + + + + + + + + + diff --git a/softwareDirectory/AutoVerScheme/synctask.cpp b/softwareDirectory/AutoVerScheme/synctask.cpp index 80ed96f..5729a3e 100644 --- a/softwareDirectory/AutoVerScheme/synctask.cpp +++ b/softwareDirectory/AutoVerScheme/synctask.cpp @@ -1,55 +1,136 @@ #include "synctask.h" #include "QMap" +#include +#include "basecommonapi.h" -SyncTask::SyncTask(const QSqlDatabase &srcDb, - const QSqlDatabase &dstDb, const QString &tableName) + + +SyncTask::SyncTask( QSqlDatabase srcDb, + QSqlDatabase dstDb, + QString tableName) + :srcDb(srcDb),dstDb(dstDb), tableName(tableName) { - sourceDatabase=srcDb; - destinationDatabase=dstDb; - SyncTask::tableName=tableName; + + // + } void SyncTask::run() { + this->syncTable(); } -QMap> SyncTask::syncTable() -{ - QMap> Info; - int errorindex=0; - QList errorinfo; +void SyncTask::syncTable() +{ + + if(syncstate==SyncRunStatus::Stopped){return;}; + + while (syncstate==SyncRunStatus::Paused) { + //等待 + QThread::sleep(1); + } + + emit taskCompleted(2,tableName, "表:"+tableName); // 清空目标数据库中的表数据 - QSqlQuery clearQuery(destinationDatabase); - clearQuery.prepare("DELETE FROM " + tableName); + QSqlQuery clearQuery(dstDb); + + clearQuery.prepare("DELETE FROM "+tableName); + if (!clearQuery.exec()) { - qDebug() << "Error clearing table:" << clearQuery.lastError().text(); - errorindex=1; - errorinfo.append("删除本地表:"+tableName+"时出错"); + qDebug() << "删除错误:" << clearQuery.lastError().text(); + //错误处理 + //触发信号 + + emit taskCompleted(1,tableName,tableName+"|删除本地表时错误:"+clearQuery.lastError().text()); + return; } // 从源数据库复制数据到目标数据库 - QSqlQuery copyQuery(sourceDatabase); + QSqlQuery copyQuery(srcDb); copyQuery.prepare("SELECT * FROM " + tableName); if (!copyQuery.exec()) { - qDebug() << "Error selecting from source table:" << copyQuery.lastError().text(); - errorindex=1; - errorinfo.append("查询主系统表:"+tableName+"时出错"); + qDebug() << tableName+"查询错误:" << copyQuery.lastError().text(); + + emit taskCompleted(1, tableName,tableName+"|查询主系统表时错误:"+copyQuery.lastError().text()); + + + return; } + while (copyQuery.next()) { + if(syncstate==SyncRunStatus::Stopped){return;}; // 构建插入语句并执行 QStringList values; + QString ValueJoin; + QSqlRecord record; + QString ResValue; + record=copyQuery.record(); for (int i = 0; i < copyQuery.record().count(); ++i) { - values << copyQuery.value(i).toString(); // 简化处理,可能需要更复杂的逻辑 + if(syncstate==SyncRunStatus::Stopped){return;}; + while (syncstate==SyncRunStatus::Paused) { + //等待 + QThread::sleep(1); + } + //处理时间类型 + if (record.fieldName(i).count("date")||record.fieldName(i).count("TIME") + ||record.fieldName(i).count("time") + ||record.fieldName(i).count("vaild")|| + record.fieldName(i).count("BIRTHDAY")|| + record.fieldName(i).count("person_id") || + record.fieldName(i).count("valid") ){ + if(copyQuery.value(i).toString()==""){ + if(i==copyQuery.record().count()-1) + { + ValueJoin+="NULL"; + + + }else{ + ValueJoin+="NULL,"; + } + + continue; + }; + } + //处理内容的 "\T + ResValue=copyQuery.value(i).toString(); + // 替换双引号 + ResValue = ResValue.replace("\"", " "); + + ResValue = ResValue.replace("\\", "\\\\"); + // 替换字母T + ResValue = ResValue.replace("T", " "); + + if(i==copyQuery.record().count()-1) + { + ValueJoin+="\""+ResValue+"\""; + + + }else{ + ValueJoin+="\""+ResValue+"\""+","; + } + } - QSqlQuery insertQuery(destinationDatabase); - insertQuery.prepare("INSERT INTO " + tableName + " VALUES (" + values.join(",") + ")"); + QSqlQuery insertQuery(dstDb); + QString str="INSERT INTO " + tableName + " VALUES (" + ValueJoin + ")"; + insertQuery.prepare(str); if (!insertQuery.exec()) { - qDebug() << "Error inserting into destination table:" << insertQuery.lastError().text(); - errorindex=1; - errorinfo.append("添加本地系统表:"+tableName+"时出错"); - break; // 或者可以记录错误并继续 + + emit taskCompleted(1, tableName,tableName+"|添加本地表数据时错误:"+insertQuery.lastError().text()+"\t"+ValueJoin); + qDebug() <> &data, int rowsPerPage,QTableWidget *table) { - tableWidget=table; - +void PagedTableWidget::setData(int datacount, int rowsPerPage) { + //tableWidget=table; + totaldatacount=datacount; this->rowsPerPage = rowsPerPage; - allData = data; + //allData = data; currentPage = 0; createPageButtons(); - updateTable(); + //updateTable(); } void PagedTableWidget::setCurrentPage(int page) { @@ -39,7 +39,7 @@ button->setChecked(false); }*/ currentPage = page; - updateTable(); + //updateTable(); emit pageChanged(page); } } @@ -89,6 +89,7 @@ setCurrentPage(pageIndex); } } +/* void PagedTableWidget::updateTable() { //tableWidget->clear(); tableWidget->setRowCount(0); @@ -105,7 +106,7 @@ } } } - +*/ void PagedTableWidget::createPageButtons() { int totalPages = calculateTotalPages(); for (auto button : pageButtons) { @@ -150,5 +151,5 @@ } int PagedTableWidget::calculateTotalPages() { - return ((allData.count() + rowsPerPage -1) / rowsPerPage); + return ((totaldatacount + rowsPerPage -1) / rowsPerPage); } diff --git a/softwareDirectory/AutoVerScheme/PageControl.h b/softwareDirectory/AutoVerScheme/PageControl.h index 74ed1ce..2224760 100644 --- a/softwareDirectory/AutoVerScheme/PageControl.h +++ b/softwareDirectory/AutoVerScheme/PageControl.h @@ -15,7 +15,7 @@ explicit PagedTableWidget(QWidget *parent = nullptr,QHBoxLayout *PageLayout=NULL); ~PagedTableWidget(); - void setData(const QList> &data, int rowsPerPage = 10,QTableWidget *table=NULL); + void setData(int datacount, int rowsPerPage = 10); void setCurrentPage(int page); signals: @@ -30,6 +30,7 @@ QHBoxLayout *pageLayout; QList pageButtons; QList> allData; + int totaldatacount; int rowsPerPage; int currentPage; diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.cpp b/softwareDirectory/AutoVerScheme/basecommonapi.cpp index 49cbd7e..6f6fe94 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.cpp +++ b/softwareDirectory/AutoVerScheme/basecommonapi.cpp @@ -13,7 +13,7 @@ } const QString BaseCommonApi::temporary_user_id="1634107227953819649"; const QString BaseCommonApi::measure_person_id="1695282436182188034"; - +static SyncRunStatus syncstate=SyncRunStatus::Stopped; //sys_user表的id转换为measure_person_id 检定人id(meter_staff表id) @@ -167,7 +167,8 @@ "JOIN eqpt_equipment_info eei ON eei.id = blei.sample_id " "JOIN biz_business_order_info bo ON bo.id = blei.order_id " "LEFT JOIN sys_dept sd ON blei.measure_dept_id = sd.ID " - " WHERE blei.measure_person_id = :person_id " + " WHERE blei.measure_person_id = :person_id " + " AND blei.measure_status =3 or blei.measure_status = 4 " " ORDER BY blei.update_time DESC"); // 将参数绑定到占位符 @@ -175,7 +176,8 @@ //query.bindValue(":status", status); if (query.exec()) { while (query.next()) { - MyTask task; + + MyTask task; task.id = query.value("id").toString(); task.sample_name = query.value("sampleName").toString(); task.sample_model = query.value("sampleModel").toString(); @@ -2872,9 +2874,40 @@ return result; } +//保存log信息 +//log文件 + bool BaseCommonApi::SaveLogInfo(QString path,QString Info) +{ + QByteArray utf8Dat; + QString Message=Info; + QFile file(path); + // 如果目录不存在,则创建目录 + // 获取文件所在的目录 + QDir logDir = QDir(QFileInfo(path).absolutePath()); + if (!logDir.exists()) { + if (!logDir.mkpath(".")) { + qDebug() << "Failed to create log directory:" << logDir.absolutePath(); + return false; + } + } + + if (!file.open(QIODevice::Append | QIODevice::Text)) { + qDebug() << "无法打开文件:" << file.errorString(); + return false; + } + QTextStream out(&file); + utf8Dat = Message.toUtf8(); + out << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss") + << "\t" << utf8Dat << "\n"; + file.close(); + return true; + } + + //新增日志表数据 bool BaseCommonApi::InsertzdLog(zdLog log) { + log.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_log(id,is_sync,sync_time,remark,userid,type,create_time,update_time) " " VALUES(:id,:is_sync,:sync_time,:remark,:userid,:type,:create_time,:update_time) "); @@ -2898,6 +2931,7 @@ //根据userid查询日志表数据 QList BaseCommonApi::getzdLogByuserId(QString userid) { + userid=temporary_user_id; QList result; QSqlQuery query; query.prepare("SELECT * FROM zd_log WHERE userid = :userid "); @@ -2922,6 +2956,7 @@ //新增数据同步表 bool BaseCommonApi::InsertzdDataSync(zdDataSync data) { + data.userid=temporary_user_id; QSqlQuery query; query.prepare("INSERT INTO zd_data_sync(id,type,ssql,userid,remark,create_time,update_time,log_sync_id,sync_type) " " VALUES " @@ -2945,12 +2980,12 @@ return isSuccess; } //根据userid查询数据同步表 -QList getzdDataSyncByuserId(QString userid) +QList BaseCommonApi::getzdDataSyncByuserId(QString log_sync_id) { QList result; QSqlQuery query; - query.prepare("SELECT * FROM zd_data_sync WHERE userid= :userid "); - query.bindValue(":userid",userid); + query.prepare("SELECT * FROM zd_data_sync WHERE log_sync_id= :log_sync_id "); + query.bindValue(":log_sync_id",log_sync_id); if (query.exec()) { while (query.next()) { zdDataSync data; @@ -2972,3 +3007,4 @@ } + diff --git a/softwareDirectory/AutoVerScheme/basecommonapi.h b/softwareDirectory/AutoVerScheme/basecommonapi.h index 12196fb..4949683 100644 --- a/softwareDirectory/AutoVerScheme/basecommonapi.h +++ b/softwareDirectory/AutoVerScheme/basecommonapi.h @@ -919,6 +919,7 @@ QDateTime create_time; QDateTime update_time; }; + //数据同步-数据表 class zdDataSync { @@ -935,6 +936,12 @@ }; +enum class SyncRunStatus { + + Running, + Stopped, + Paused +}; using namespace Jiawa::Core; class BaseCommonApi @@ -945,7 +952,6 @@ const static QString temporary_costomer_id; const static QString measure_person_id; - QString encrypt(const QString &str, const QString &publicKey); //判断检定装置表并查询 参数设备id @@ -1137,14 +1143,19 @@ //单独查询任务单表 //更新 任务单 static InsertTask SelectTaskSingle(QString order_id); + + //log文件 + static bool SaveLogInfo(QString path,QString Info); + //新增日志表数据 static bool InsertzdLog(zdLog log); //查询日志表数据 static QList getzdLogByuserId(QString userid); //新增数据同步表 static bool InsertzdDataSync(zdDataSync data); - //根据userid查询数据同步表 - static QList getzdDataSyncByuserId(QString userid); + //根据log_sync_id查询数据同步表 + static QList getzdDataSyncByuserId(QString log_sync_id); + }; diff --git a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp index 00d746b..ae60962 100644 --- a/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/beexamined_deviceitem.cpp @@ -352,6 +352,7 @@ } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -395,6 +396,7 @@ row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.cpp b/softwareDirectory/AutoVerScheme/databaseconnection.cpp index 1d957d9..5284fe6 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.cpp +++ b/softwareDirectory/AutoVerScheme/databaseconnection.cpp @@ -10,17 +10,21 @@ { // 连接数据库 - db = QSqlDatabase::addDatabase("QODBC"); - /*db.setHostName("111.198.10.15"); - db.setDatabaseName("casic_metering_xichang"); - db.setPort(21906); - db.setUserName("zdjdcs"); - db.setPassword("11111111");*/ - db.setHostName("localhost"); - db.setDatabaseName("zdjd"); - db.setPort(3306); - db.setUserName("root"); - db.setPassword("123456"); + localdb = QSqlDatabase::addDatabase("QODBC"); + + localdb.setHostName("localhost"); + localdb.setDatabaseName("zdjd"); + localdb.setPort(3306); + localdb.setUserName("root"); + localdb.setPassword("123456"); + + Maindb = QSqlDatabase::addDatabase("QODBC","Main"); + Maindb.setHostName("111.198.10.15"); + Maindb.setDatabaseName("casic_metering_xichang"); + Maindb.setPort(21906); + Maindb.setUserName("zdjdcs"); + Maindb.setPassword("11111111"); + } @@ -29,18 +33,28 @@ close(); } bool DatabaseConnection::open() { - return db.open(); + return localdb.open(); +} +bool DatabaseConnection::openmain() { + return Maindb.open(); } bool DatabaseConnection::isopen() { - return db.isOpen(); + return localdb.isOpen(); } - +bool DatabaseConnection::isopenmain() { + return Maindb.isOpen(); +} void DatabaseConnection::close() { - db.close(); + localdb.close(); } - +void DatabaseConnection::closemain() { + Maindb.close(); +} QSqlDatabase& DatabaseConnection::getDatabase() { - return db; + return localdb; +} +QSqlDatabase& DatabaseConnection::getDatabaseMain() { + return Maindb; } DatabaseConnection* DatabaseConnection::getInstance() { diff --git a/softwareDirectory/AutoVerScheme/databaseconnection.h b/softwareDirectory/AutoVerScheme/databaseconnection.h index 586b794..5f9810b 100644 --- a/softwareDirectory/AutoVerScheme/databaseconnection.h +++ b/softwareDirectory/AutoVerScheme/databaseconnection.h @@ -16,8 +16,12 @@ ~DatabaseConnection(); bool open(); bool isopen(); + bool openmain(); void close(); + void closemain(); + bool isopenmain(); QSqlDatabase& getDatabase(); + QSqlDatabase& getDatabaseMain(); private: //单列模式 保证DatabaseConnection的唯一性 static DatabaseConnection* Connect; @@ -33,7 +37,8 @@ //如果尝试这样做,编译器同样会报错。 DatabaseConnection& operator=(const DatabaseConnection&) = delete; //数据库db类 - QSqlDatabase db; + QSqlDatabase Maindb; + QSqlDatabase localdb; }; #endif // DATABASECONNECTION_H diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp new file mode 100644 index 0000000..080288b --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.cpp @@ -0,0 +1,54 @@ +#include "databaseconnectionmainsys.h" + + + + +DatabaseConnectionMainSys* DatabaseConnectionMainSys::Connect = nullptr; +QMutex DatabaseConnectionMainSys::mutex; + +DatabaseConnectionMainSys::DatabaseConnectionMainSys() +{ + + // 连接数据库 + dbmain = QSqlDatabase::addDatabase("QODBC"); + dbmain.setHostName("111.198.10.15"); + dbmain.setDatabaseName("casic_metering_xichang"); + dbmain.setPort(21906); + dbmain.setUserName("zdjdcs"); + dbmain.setPassword("11111111"); + /* db.setHostName("localhost"); + db.setDatabaseName("zdjd"); + db.setPort(3306); + db.setUserName("root"); + db.setPassword("123456");*/ + + +} +DatabaseConnectionMainSys::~DatabaseConnectionMainSys() { + // 在析构函数中关闭数据库连接 + close(); +} +bool DatabaseConnectionMainSys::open() { + return dbmain.open(); +} +bool DatabaseConnectionMainSys::isopen() { + return dbmain.isOpen(); +} + +void DatabaseConnectionMainSys::close() { + dbmain.close(); +} + +QSqlDatabase& DatabaseConnectionMainSys::getDatabase() { + return dbmain; +} +DatabaseConnectionMainSys* DatabaseConnectionMainSys::getInstance() +{ + if (!Connect) { + QMutexLocker locker(&mutex); + if (!Connect) { + Connect = new DatabaseConnectionMainSys(); + } + } + return Connect; +} diff --git a/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h new file mode 100644 index 0000000..57702ad --- /dev/null +++ b/softwareDirectory/AutoVerScheme/databaseconnectionmainsys.h @@ -0,0 +1,41 @@ +#ifndef DATABASECONNECTIONMAINSYS_H +#define DATABASECONNECTIONMAINSYS_H +#include +#include +#include +#include + + +class DatabaseConnectionMainSys +{ + + +public: + //获取数据库实例 + static DatabaseConnectionMainSys* getInstance(); + + DatabaseConnectionMainSys(); + ~DatabaseConnectionMainSys(); + bool open(); + bool isopen(); + void close(); + QSqlDatabase& getDatabase(); +private: + //单列模式 保证MainSysDatabaseConnection的唯一性 + static DatabaseConnectionMainSys* Connect; + //QMutex 来确保在多线程环境下单例的正确创建。 + static QMutex mutex; + + //这是拷贝构造函数的声明,后面跟着 = delete; 表示这个构造函数被删除了。 + //这意味着你不能通过拷贝另一个 DatabaseConnection 对象来创建新的 DatabaseConnection 对象。 + //如果尝试这样做,编译器会报错。 + DatabaseConnectionMainSys(const DatabaseConnectionMainSys&) = delete; + //这是拷贝赋值运算符的声明,同样后面跟着 = delete; 表示这个运算符被删除了。 + //这意味着你不能将一个 DatabaseConnection 对象赋值给另一个 DatabaseConnection 对象。 + //如果尝试这样做,编译器同样会报错。 + DatabaseConnectionMainSys& operator=(const DatabaseConnectionMainSys&) = delete; + //数据库db类 + QSqlDatabase dbmain; +}; + +#endif // DATABASECONNECTIONMAINSYS_H diff --git a/softwareDirectory/AutoVerScheme/datasyncview.cpp b/softwareDirectory/AutoVerScheme/datasyncview.cpp index fbf4508..06c7f9a 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.cpp +++ b/softwareDirectory/AutoVerScheme/datasyncview.cpp @@ -1,11 +1,10 @@ #include "datasyncview.h" #include "ui_datasyncview.h" -#include "synctask.h" -#include "databaseconnection.h" -#include "mainsysdatabaseconnection.h" +#include "syncdialog.h" - +QString filePath = "C:\\AutoVerScheme\\sync_info.txt"; +// 获取当前时间戳 DataSyncView::DataSyncView(QWidget *parent) : QWidget(parent), ui(new Ui::DataSyncView) @@ -20,7 +19,7 @@ } void DataSyncView::initForm() { - //tableWidget设置 + ui->stackedWidget->setCurrentIndex(0); //设置控件的边框显示 ui->tableWidget->setStyleSheet("QHeaderView::section {" "border: 1px solid grey;" @@ -32,29 +31,129 @@ "}"); ui->tableWidget->setRowCount(10); // 设置10行 - ui->tableWidget->setColumnCount(4); // 设置11列 - ui->tableWidget->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnCount(7); // 设置11列 + ui->tableWidget->setColumnWidth(0, 0); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnWidth(2, 200); // 设置第一列的宽度为100像素 ui->tableWidget->verticalHeader()->setParent(nullptr); //隐藏行头 - QTableWidgetItem *item = new QTableWidgetItem("测试数据"); - item->setTextAlignment(Qt::AlignCenter); - ui->tableWidget->setItem(0, 0, item); //设置数据 + + //初始化TableWidget 设置列 QStringList headers; - headers << "序号" << "同步时间" << "是否同步成功" << "备注" ; + headers <<"id" << "序号" << "同步时间" << "是否同步成功" << "备注" + <<"类型" <<"操作"; ui->tableWidget->setHorizontalHeaderLabels(headers); + //详情内 + + //设置控件的边框显示 + ui->tableWidget_2->setStyleSheet("QHeaderView::section {" + "border: 1px solid grey;" + "border-left:none;" + "border-top:none;" + "background-color:white;" + " color:black;" + "font: bold 18px Arial, sans-serif;" + "}"); + + ui->tableWidget_2->setRowCount(10); // 设置10行 + ui->tableWidget_2->setColumnCount(3); // 设置11列 + ui->tableWidget_2->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget_2->verticalHeader()->setParent(nullptr); //隐藏行头 + ui->tableWidget_2->setColumnWidth(1, 1000); // 设置第一列的宽度为100像素 + + //初始化TableWidget 设置列 + + headers << "序号" << "信息" << "状态" ; + ui->tableWidget_2->setHorizontalHeaderLabels(headers); + + //数据显示 + + //先设置为行为0 + ui->tableWidget->setRowCount(0); + int rowCount=0; + int row=0; + QList zdlog= BaseCommonApi::getzdLogByuserId(""); + for(const zdLog & zd:zdlog) + { + rowCount = ui->tableWidget->rowCount(); + ui->tableWidget->insertRow(rowCount); + ui->tableWidget->setItem(row, 0, new QTableWidgetItem(zd.id)); + ui->tableWidget->setItem(row, 1, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget->setItem(row, 2, new QTableWidgetItem(zd.sync_time.toString())); + ui->tableWidget->setItem(row, 3, new QTableWidgetItem(zd.is_sync)); + ui->tableWidget->setItem(row, 4, new QTableWidgetItem(zd.remark)); + if(zd.type=="1") + { + ui->tableWidget->setItem(row, 5, new QTableWidgetItem("下载")); + }else{ ui->tableWidget->setItem(row, 5, new QTableWidgetItem("上传")); } + + //添加操作按钮 + QPushButton *button = new QPushButton("查询信息"); + button->setIconSize(QSize(16,16)); + button->setIcon(QIcon(":/image/Index/u2327.svg")); + ui->tableWidget->setCellWidget(row, 6, button); + //设置按钮简单样式 + button->setStyleSheet("QPushButton {" + " border: none; /* 无边框 */" + " color: green; /* 文本颜色 */" + " text-decoration: underline; /* 文本下划线 */" + "}"); + + // 设置鼠标悬停时的光标样式为小手图标 + button->setCursor(Qt::PointingHandCursor); + // 连接按钮的 clicked 信号到自定义槽函数 + connect(button, &QPushButton::clicked, this, [this, button, zd]() { + // 获取当前行第一列的 ID + + OnButtonSelectClicked(zd); + + }); + row++; + } } void DataSyncView::on_DownloadDataButton_clicked() { - //从主系统下载 + + SyncDialog *syncDialog = new SyncDialog(this); + syncDialog->exec(); // 显示进度条窗体并阻塞主窗口 + + this->initForm(); + } -void DataSyncView::syncTable() +void DataSyncView::OnButtonSelectClicked(zdLog log) { - //连接两个数据库 - bool IsOpen=false; - DatabaseConnection *Conn=DatabaseConnection::getInstance(); - IsOpen=Conn->open(); - //MainSysDatabaseConnection *MainConn=MainSysDatabaseConnection::getInstance(); - //IsOpen=MainConn->open(); + ui->stackedWidget->setCurrentIndex(1); + ui->tableWidget_2->setRowCount(0); + int rowCount=0; + int row=0; + QList data= BaseCommonApi::getzdDataSyncByuserId(log.id); + for(const zdDataSync & item:data) + { + rowCount = ui->tableWidget_2->rowCount(); + ui->tableWidget_2->insertRow(rowCount); + ui->tableWidget_2->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); + ui->tableWidget_2->setItem(row, 1, new QTableWidgetItem(item.remark)); + QTableWidgetItem *itemRow; + if(item.sync_type=="0"){ + itemRow = new QTableWidgetItem("未同步"); + itemRow->setBackground(QBrush(QColor(255, 255, 192))); + }else if (item.sync_type=="1") + { + itemRow = new QTableWidgetItem("同步成功"); + itemRow->setBackground(QBrush(QColor(173, 255, 47))); // 浅绿色 + }else{ + itemRow = new QTableWidgetItem("同步失败"); + itemRow->setBackground(QBrush(QColor(255, 105, 180))); // 浅红色 + } + itemRow->setTextAlignment(Qt::AlignCenter); + ui->tableWidget_2->setItem(row, 2, itemRow); + + row++; + } +} + +void DataSyncView::on_button_return_clicked() +{ + ui->stackedWidget->setCurrentIndex(0); } diff --git a/softwareDirectory/AutoVerScheme/datasyncview.h b/softwareDirectory/AutoVerScheme/datasyncview.h index 174480e..b2b9847 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.h +++ b/softwareDirectory/AutoVerScheme/datasyncview.h @@ -2,6 +2,16 @@ #define DATASYNCVIEW_H #include +#include +#include "synctask.h" +#include "databaseconnection.h" +#include "basecommonapi.h" +#include "databaseconnectionmainsys.h" +#include +#include +#include +#include +#include namespace Ui { class DataSyncView; @@ -18,8 +28,12 @@ void initForm(); //初始化界面数据 void on_DownloadDataButton_clicked(); - //异步更新 - void syncTable(); + void OnButtonSelectClicked(zdLog log); + void on_button_return_clicked(); + +public: + + private: Ui::DataSyncView *ui; }; diff --git a/softwareDirectory/AutoVerScheme/datasyncview.ui b/softwareDirectory/AutoVerScheme/datasyncview.ui index 53c379c..7c9df8e 100644 --- a/softwareDirectory/AutoVerScheme/datasyncview.ui +++ b/softwareDirectory/AutoVerScheme/datasyncview.ui @@ -14,21 +14,9 @@ 数据同步 - background-color:rgba(240, 240, 240, 1); + background-color:white; - - - 0 - - - 0 - - - 0 - - - 0 - + @@ -73,119 +61,173 @@ - - - background-color:white; - - - - - - - 3 - - - - - - 0 - 0 - - - - background-color:white; + + + + + + + background-color:white; + + + + + + + 3 + + + + + + 0 + 0 + + + + background-color:white; border:0; - - - - - - - - - - 0 - 0 - - - - font:bold 20px Arial, sans-serif; + + + + + + + + + + 0 + 0 + + + + font:bold 20px Arial, sans-serif; color:#334582; - - - 同步记录 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - background-color:#334582; + + + 同步记录 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + background-color:#334582; font: bold 18px Arial, sans-serif; color:white; padding:10px; - - - 下载数据 - - - - - - - - 200 - 0 - - - - - 100 - 40 - - - - Qt::RightToLeft - - - background-color:#334582; + + + 下载数据 + + + + + + + + 200 + 0 + + + + + 100 + 40 + + + + Qt::RightToLeft + + + background-color:#334582; font: bold 18px Arial, sans-serif; color:white; padding:10px; - - - 发送同步请求 - - - - :/image/Index/u8458.svg:/image/Index/u8458.svg - - - - - - - - - - - - - - + + + 发送同步请求 + + + + :/image/Index/u8458.svg:/image/Index/u8458.svg + + + + + + + + + + + + + + + + + + + + + + + + background-color:white; + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + color:black; + + + 返回 + + + + + + + + + + + + + diff --git a/softwareDirectory/AutoVerScheme/depar_task.cpp b/softwareDirectory/AutoVerScheme/depar_task.cpp index d551972..d58cf35 100644 --- a/softwareDirectory/AutoVerScheme/depar_task.cpp +++ b/softwareDirectory/AutoVerScheme/depar_task.cpp @@ -113,6 +113,7 @@ else State="否"; ui->tableWidget->setItem(row, 9, new QTableWidgetItem(State)); //设置数据 + SetHomePaheCombox(dept); //添加 PageData数据 TempData.append(QString::number(row+1)); TempData.append(dept.sample_name); @@ -133,9 +134,9 @@ //设置分页控件 // 创建分页表格控件 - PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); +// PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); //data转换位QList> - pagedTable->setData(PageData, 20,ui->tableWidget); // 每页20行 + // pagedTable->setData(PageData, 20,ui->tableWidget); // 每页20行 } void Depar_Task::on_SelectButton_clicked() @@ -155,26 +156,31 @@ if(dept.measure_status=="3" || dept.measure_status=="4"){ bool shouldAddRow = true; // 初始假设应该添加这一行 // 根据设备名称筛选 + QString names; if (ui->name->currentText() != "ALL") { + names=ui->name->currentText(); if (ui->name->currentText() != dept.sample_name) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } if (ui->mode->currentText() != "ALL") { + names=ui->mode->currentText(); if (ui->mode->currentText() != dept.sample_model) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } if (ui->customer->currentText() != "ALL") { + if (ui->customer->currentText() != dept.customer_name) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } - if (ui->dept->currentText() != "") { + if (ui->dept->currentText() != "ALL") { if (ui->dept->currentText() != dept.FULL_NAME) { shouldAddRow = false; // 设备名称不匹配,不添加这一行 } } + if(shouldAddRow){ rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); ui->tableWidget->setItem(row, 0, new QTableWidgetItem(QString::number(row+1))); @@ -193,9 +199,10 @@ State="否"; ui->tableWidget->setItem(row, 9, new QTableWidgetItem(State)); //设置数据 // - SetHomePaheCombox(dept); + //QDebug row++; + } } } diff --git a/softwareDirectory/AutoVerScheme/indexwindow.cpp b/softwareDirectory/AutoVerScheme/indexwindow.cpp index eed192a..060b86e 100644 --- a/softwareDirectory/AutoVerScheme/indexwindow.cpp +++ b/softwareDirectory/AutoVerScheme/indexwindow.cpp @@ -58,7 +58,7 @@ DatabaseConnection *Conn=DatabaseConnection::getInstance(); //数据库连接 目前先放这里 后续需要放到登录界面 - bool IsOpen=Conn->open(); + bool IsOpen=Conn->open(); if(IsOpen) ShowMessageBox("数据库连接","连接成功"); else diff --git a/softwareDirectory/AutoVerScheme/my_task.cpp b/softwareDirectory/AutoVerScheme/my_task.cpp index 1735575..cd735f8 100644 --- a/softwareDirectory/AutoVerScheme/my_task.cpp +++ b/softwareDirectory/AutoVerScheme/my_task.cpp @@ -62,7 +62,8 @@ } void My_Task::Load() { - QList> PageData; + + //QList> PageData; //先设置为行为0 ui->tableWidget->setRowCount(0); //添加comboBox @@ -86,11 +87,29 @@ QString userId=""; data = BaseCommonApi::getMyTasks(userId,"3"); + QString State; + //设置单页显示数量 + page=20; + // 创建分页表格控件 + PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); + pagedTable->setData(data.count(), page); // 每页10行 + connect(pagedTable, &PagedTableWidget::pageChanged, this,&My_Task::onpageChanged); + this->onpageChanged(0); + +} +void My_Task::onpageChanged(int currPage){ + currPage+=1; + // 计算当前页的开始和结束索引 + int start = (currPage - 1) * page; + int end = std::min(start + page, data.size()); + // 从 QList 中筛选出当前页的数据 + QList tempdate = data.mid(start, end - start); int rowCount = 0; int row=0; QString State; - for (const MyTask& myTask : data) { - if(myTask.measure_status=="3" || myTask.measure_status=="4"){ + ui->tableWidget->setRowCount(0); + for (const MyTask& myTask : tempdate) { + QList TempData; rowCount = ui->tableWidget->rowCount(); @@ -118,42 +137,15 @@ ui->tableWidget->setItem(row, 10,new QTableWidgetItem("检测完成")); } - //渲染下拉框 - SetHomePaheCombox(myTask); - //QDebug - - //添加 PageData数据 - TempData.append(QString::number(row+1)); - TempData.append(myTask.sample_name); - TempData.append(myTask.sample_model); - TempData.append(myTask.help_instruction); - TempData.append(myTask.manufacture_no); - TempData.append(myTask.manufacturer); - TempData.append(myTask.customer_name); - TempData.append(myTask.FULL_NAME); - TempData.append(myTask.require_over_time.toString()); - TempData.append(State); - TempData.append(myTask.measure_status); - PageData.append(TempData); + //渲染下拉框 + SetHomePaheCombox(myTask); row++; - } - - } - //设置分页控件 - // 创建分页表格控件 - - PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); - //data转换位QList> - pagedTable->setData(PageData, 20,ui->tableWidget); // 每页10行 - //ui->HBoxPageLayout->addWidget(pagedTable); - //setLayout(ui->HBoxPageLayout); - // 连接信号以处理页码变化 - /* connect(pagedTable, &PagedTableWidget::pageChanged, this, [=](int page) { - // 在这里处理页码变化事件,比如更新UI中的其他部分 - qDebug() << "Page changed to:" << page; - });*/ + }; + //按钮点击事件 + // QMessageBox::information(this, "点击按钮",QString::number(page)); + // qDebug() << "Page changed to:" << page; } void My_Task::SetHomePaheCombox(MyTask entity) { diff --git a/softwareDirectory/AutoVerScheme/my_task.h b/softwareDirectory/AutoVerScheme/my_task.h index 289e7f4..8a4ad07 100644 --- a/softwareDirectory/AutoVerScheme/my_task.h +++ b/softwareDirectory/AutoVerScheme/my_task.h @@ -26,9 +26,11 @@ void on_pushButtonUpdate_clicked(); void on_SeachButton_clicked(); + void onpageChanged(int page); public: QList data; - + int page; + int totalcount; private: Ui::My_Task *ui; }; diff --git a/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp b/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp index e9cfb66..3ef9d60 100644 --- a/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp +++ b/softwareDirectory/AutoVerScheme/standard_deviceitem.cpp @@ -3,7 +3,7 @@ #include "InfoBase.h" #include "QMessageBox" #include "basecommonapi.h" - +#include "PageControl.h" //标准设备管理 .cpp Standard_DeviceItem::Standard_DeviceItem(QWidget *parent) : @@ -32,7 +32,7 @@ // ui->tableWidget->setRowCount(10); // 设置10行 ui->tableWidget->setColumnCount(7); // 设置11列 - ui->tableWidget->setColumnWidth(0, 80); // 设置第一列的宽度为100像素 + ui->tableWidget->setColumnWidth(0, 0); // 设置第一列的宽度为100像素 ui->tableWidget->verticalHeader()->setParent(nullptr); //隐藏行头 //QTableWidgetItem *item = new QTableWidgetItem("测试数据"); //item->setTextAlignment(Qt::AlignCenter); @@ -102,12 +102,32 @@ // 调用数据库管理器的函数获取数据 - int rowCount=0; - int row=0; + data = BaseCommonApi::getBizDeviceManage(); + QString State; + //设置单页显示数量 + page=20; + // 创建分页表格控件 + PagedTableWidget *pagedTable = new PagedTableWidget(this, ui->HBoxPageLayout); + pagedTable->setData(data.count(), page); // 每页10行 + connect(pagedTable, &PagedTableWidget::pageChanged, this,&Standard_DeviceItem::onpageChanged); + this->onpageChanged(0); - for (const BizDevice& bizDevice : data) { +} +void Standard_DeviceItem::onpageChanged(int currPage){ + + currPage+=1; + // 计算当前页的开始和结束索引 + int start = (currPage - 1) * page; + int end = std::min(start + page, data.size()); + // 从 QList 中筛选出当前页的数据 + QList tempdate = data.mid(start, end - start); + int rowCount = 0; + int row=0; + QString State; + ui->tableWidget->setRowCount(0); + for (const BizDevice& bizDevice : tempdate) { rowCount = ui->tableWidget->rowCount(); ui->tableWidget->insertRow(rowCount); @@ -147,8 +167,9 @@ SetHomePaheCombox(bizDevice); row++; } - } + + void Standard_DeviceItem::OnButtonSelectClicked(QString id) { //添加 diff --git a/softwareDirectory/AutoVerScheme/standard_deviceitem.h b/softwareDirectory/AutoVerScheme/standard_deviceitem.h index f522658..c506728 100644 --- a/softwareDirectory/AutoVerScheme/standard_deviceitem.h +++ b/softwareDirectory/AutoVerScheme/standard_deviceitem.h @@ -30,6 +30,9 @@ void on_pushButton_8_clicked(); public: QList data; + void onpageChanged(int currPage); + int page; + int totalcount; private: Ui::Standard_DeviceItem *ui; }; diff --git a/softwareDirectory/AutoVerScheme/standard_deviceitem.ui b/softwareDirectory/AutoVerScheme/standard_deviceitem.ui index 9b1acd4..861993d 100644 --- a/softwareDirectory/AutoVerScheme/standard_deviceitem.ui +++ b/softwareDirectory/AutoVerScheme/standard_deviceitem.ui @@ -233,6 +233,24 @@ + + + + + + + + Qt::Horizontal + + + + 1108 + 36 + + + + + diff --git a/softwareDirectory/AutoVerScheme/syncdialog.cpp b/softwareDirectory/AutoVerScheme/syncdialog.cpp new file mode 100644 index 0000000..f9195f1 --- /dev/null +++ b/softwareDirectory/AutoVerScheme/syncdialog.cpp @@ -0,0 +1,207 @@ +#include "syncdialog.h" +#include "ui_syncdialog.h" + + +int SyncDialog::m_totalTasks; +int SyncDialog::stepcount; +int SyncDialog::filecount; + + +SyncDialog::SyncDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::SyncDialog) +{ + ui->setupUi(this); + + + +} + +SyncDialog::~SyncDialog() +{ + delete ui; +} + +void SyncDialog::on_button_Start_clicked() +{ + + + //qint64 id = dbmang.generateId(); + //zdlogId=QString::number(id); + zdDataSyncList.clear(); + querydstList.clear(); + //从主系统下载 + //连接两个数据库 + bool IsOpen=false; + bool IsOpenMain=false; + + DatabaseConnection *Conn=DatabaseConnection::getInstance(); + //DatabaseConnectionMainSys *MainConn=DatabaseConnectionMainSys::getInstance(); + if(!Conn->isopen()){IsOpen=Conn->open();}else{IsOpen=true;}; + if(!Conn->isopenmain()){IsOpenMain=Conn->openmain();}else{IsOpenMain=true;}; + + // 记录任务数量 + + m_totalTasks=0; + stepcount=0; + filecount=0; + // 获取第一个数据库的所有表名 + dstDb=Conn->getDatabase(); + srcDb=Conn->getDatabaseMain(); + QSqlQuery querydst(dstDb); + querydst.exec("SHOW TABLES"); + QSqlQuery query(srcDb); + query.exec("SHOW TABLES"); + + while(querydst.next()){ + QString tableName = querydst.value(0).toString(); + if(tableName.contains("act_") ||tableName.contains("flw_ru_")){continue;}; + querydstList.append(tableName);}; + // 创建一个线程池 + threadPool= QThreadPool::globalInstance(); + threadPool->setMaxThreadCount(5); // 设置线程池中的最大线程数 + // 遍历表名,为每个表创建一个任务并提交到线程池 + BaseCommonApi::SaveLogInfo(filePath,"开始下载同步"); + + while (query.next()) { + QString tableName = query.value(0).toString(); + if(!querydstList.contains(tableName)){continue;}; + if(tableName.contains("ACT_") ||tableName.contains("FLW_RU_")){continue;}; + SyncTask *task = new SyncTask(srcDb, dstDb, tableName); + connectTaskSignals(task); + // 提交任务到线程池 + threadPool->start(task); + ++m_totalTasks; + // + + } + //总数量 + ui->lab_sum->setText(QString::number(m_totalTasks)); + progressDecrement=static_cast(100) / m_totalTasks; + +} +void SyncDialog::connectTaskSignals(SyncTask *task) { + connect(task, &SyncTask::taskCompleted, this, &SyncDialog::onTaskCompleted); + connect(task, &SyncTask::TextState, this, &SyncDialog::onTextState); + connect(this,&SyncDialog::StopRequested,task,&SyncTask::UpdateState); + //当前正在执行的 +} +void SyncDialog::onTaskCompleted(int success,QString tableName, const QString& errorMessage) +{ + if(success!=2){ + if(querydstList.contains(tableName)){querydstList.removeAll(tableName);}; + //添加同步表 + //任务完成 任务失败 都需要添加 + qint64 id = dbmang.generateId(); + zdDataSync zdDataSyncentity; + zdDataSyncentity.id=QString::number(id);; + zdDataSyncentity.remark=errorMessage; + zdDataSyncentity.log_sync_id=""; + zdDataSyncentity.sync_type=QString::number(success+1); + zdDataSyncList.append(zdDataSyncentity); + // dbmang.InsertzdDataSync(zdDataSyncentity); + }; + QString mess; + if (success==0) { + // 任务成功完成 + mess = "任务完成"; + mess+=errorMessage; + + } else if(success==1){ + // 任务执行失败 + mess = "任务失败"; + mess +=errorMessage; + filecount++; + //失败数量 + ui->lab_fail->setText(QString::number(filecount));; + }else{ + mess = "正在执行"; + mess +=errorMessage+"....."; + } + //log保存 + BaseCommonApi::SaveLogInfo(filePath,mess); + //界面listview显示 + ui->listWidget->addItem(mess); + // 当添加新项后,滚动到底部 + ui->listWidget->scrollToBottom(); + +} +void SyncDialog::onTextState() +{ + + stepcount++; + //成功数量 + ui->lab_succ->setText(QString::number(stepcount));; + //更新进度条 + int progress = static_cast(progressDecrement * stepcount); + ui->progressBar->setValue(progress); + if(stepcount>=m_totalTasks) + { + this->StopSync(); + } + +} + +void SyncDialog::on_button_Close_clicked() +{ + emit StopRequested(2); + threadPool->waitForDone(); + this->StopSync(); + srcDb.close(); + this->close(); +} +void SyncDialog::StopSync() +{ + ui->progressBar->setValue(100); + srcDb.close(); + //dstDb.close(); + + //添加日志表 + zdLog zlog; + zlog.id=QString::number( dbmang.generateId());; + zlog.type="1"; + if(filecount==0) + { + zlog.is_sync="成功"; + }else + { + zlog.is_sync="失败"; + } + zlog.sync_time=QDateTime::currentDateTime(); + zlog.remark="错误数量"+QString::number(filecount); + dbmang.InsertzdLog(zlog); + //添加记录表 + for (int i=0;ibutton_step->text()=="暂停") + { + ui->button_step->setText("继续"); + emit StopRequested(1); + + + }else{ + ui->button_step->setText("暂停"); + emit StopRequested(0); + }; +} diff --git a/softwareDirectory/AutoVerScheme/syncdialog.h b/softwareDirectory/AutoVerScheme/syncdialog.h new file mode 100644 index 0000000..2d5c41c --- /dev/null +++ b/softwareDirectory/AutoVerScheme/syncdialog.h @@ -0,0 +1,60 @@ +#ifndef SYNCDIALOG_H +#define SYNCDIALOG_H + +#include +#include "databaseconnection.h" +#include "basecommonapi.h" +#include "databaseconnectionmainsys.h" +#include +#include +#include +#include +#include +#include "synctask.h" + +namespace Ui { +class SyncDialog; +} + +class SyncDialog : public QDialog +{ + Q_OBJECT + +public: + explicit SyncDialog(QWidget *parent = nullptr); + ~SyncDialog(); + +private slots: + void on_button_Start_clicked(); + + + void connectTaskSignals(SyncTask *task); + void onTaskCompleted(int success,QString tableName, const QString& errorMessage); + void onTextState(); + void on_button_Close_clicked(); + void StopSync(); + void on_button_step_clicked(); + +public: + static int m_totalTasks; + static int filecount; + static int stepcount; + + QThreadPool *threadPool; + QSqlDatabase dstDb; + QSqlDatabase srcDb; + double progressDecrement; + QString filePath = "C:\\AutoVerScheme\\sync_info.txt"; + + QString zdlogId=""; + + BaseCommonApi dbmang; + QList zdDataSyncList; + QList querydstList; +signals: + void StopRequested(int state); // 定义暂停 停止请求信号 +private: + Ui::SyncDialog *ui; +}; + +#endif // SYNCDIALOG_H diff --git a/softwareDirectory/AutoVerScheme/syncdialog.ui b/softwareDirectory/AutoVerScheme/syncdialog.ui new file mode 100644 index 0000000..54cba8b --- /dev/null +++ b/softwareDirectory/AutoVerScheme/syncdialog.ui @@ -0,0 +1,178 @@ + + + SyncDialog + + + + 0 + 0 + 696 + 485 + + + + Dialog + + + background-color:white;; +color:black; + + + + + + background-color:white; + + + 下载数据 + + + + + + + + 总同步任务: + + + + + + + 0 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 失败任务: + + + + + + + 0 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 完成任务: + + + + + + + 0 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 0 + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 开始 + + + + + + + 暂停 + + + + + + + 关闭 + + + + + + + + + + + + + diff --git a/softwareDirectory/AutoVerScheme/synctask.cpp b/softwareDirectory/AutoVerScheme/synctask.cpp index 80ed96f..5729a3e 100644 --- a/softwareDirectory/AutoVerScheme/synctask.cpp +++ b/softwareDirectory/AutoVerScheme/synctask.cpp @@ -1,55 +1,136 @@ #include "synctask.h" #include "QMap" +#include +#include "basecommonapi.h" -SyncTask::SyncTask(const QSqlDatabase &srcDb, - const QSqlDatabase &dstDb, const QString &tableName) + + +SyncTask::SyncTask( QSqlDatabase srcDb, + QSqlDatabase dstDb, + QString tableName) + :srcDb(srcDb),dstDb(dstDb), tableName(tableName) { - sourceDatabase=srcDb; - destinationDatabase=dstDb; - SyncTask::tableName=tableName; + + // + } void SyncTask::run() { + this->syncTable(); } -QMap> SyncTask::syncTable() -{ - QMap> Info; - int errorindex=0; - QList errorinfo; +void SyncTask::syncTable() +{ + + if(syncstate==SyncRunStatus::Stopped){return;}; + + while (syncstate==SyncRunStatus::Paused) { + //等待 + QThread::sleep(1); + } + + emit taskCompleted(2,tableName, "表:"+tableName); // 清空目标数据库中的表数据 - QSqlQuery clearQuery(destinationDatabase); - clearQuery.prepare("DELETE FROM " + tableName); + QSqlQuery clearQuery(dstDb); + + clearQuery.prepare("DELETE FROM "+tableName); + if (!clearQuery.exec()) { - qDebug() << "Error clearing table:" << clearQuery.lastError().text(); - errorindex=1; - errorinfo.append("删除本地表:"+tableName+"时出错"); + qDebug() << "删除错误:" << clearQuery.lastError().text(); + //错误处理 + //触发信号 + + emit taskCompleted(1,tableName,tableName+"|删除本地表时错误:"+clearQuery.lastError().text()); + return; } // 从源数据库复制数据到目标数据库 - QSqlQuery copyQuery(sourceDatabase); + QSqlQuery copyQuery(srcDb); copyQuery.prepare("SELECT * FROM " + tableName); if (!copyQuery.exec()) { - qDebug() << "Error selecting from source table:" << copyQuery.lastError().text(); - errorindex=1; - errorinfo.append("查询主系统表:"+tableName+"时出错"); + qDebug() << tableName+"查询错误:" << copyQuery.lastError().text(); + + emit taskCompleted(1, tableName,tableName+"|查询主系统表时错误:"+copyQuery.lastError().text()); + + + return; } + while (copyQuery.next()) { + if(syncstate==SyncRunStatus::Stopped){return;}; // 构建插入语句并执行 QStringList values; + QString ValueJoin; + QSqlRecord record; + QString ResValue; + record=copyQuery.record(); for (int i = 0; i < copyQuery.record().count(); ++i) { - values << copyQuery.value(i).toString(); // 简化处理,可能需要更复杂的逻辑 + if(syncstate==SyncRunStatus::Stopped){return;}; + while (syncstate==SyncRunStatus::Paused) { + //等待 + QThread::sleep(1); + } + //处理时间类型 + if (record.fieldName(i).count("date")||record.fieldName(i).count("TIME") + ||record.fieldName(i).count("time") + ||record.fieldName(i).count("vaild")|| + record.fieldName(i).count("BIRTHDAY")|| + record.fieldName(i).count("person_id") || + record.fieldName(i).count("valid") ){ + if(copyQuery.value(i).toString()==""){ + if(i==copyQuery.record().count()-1) + { + ValueJoin+="NULL"; + + + }else{ + ValueJoin+="NULL,"; + } + + continue; + }; + } + //处理内容的 "\T + ResValue=copyQuery.value(i).toString(); + // 替换双引号 + ResValue = ResValue.replace("\"", " "); + + ResValue = ResValue.replace("\\", "\\\\"); + // 替换字母T + ResValue = ResValue.replace("T", " "); + + if(i==copyQuery.record().count()-1) + { + ValueJoin+="\""+ResValue+"\""; + + + }else{ + ValueJoin+="\""+ResValue+"\""+","; + } + } - QSqlQuery insertQuery(destinationDatabase); - insertQuery.prepare("INSERT INTO " + tableName + " VALUES (" + values.join(",") + ")"); + QSqlQuery insertQuery(dstDb); + QString str="INSERT INTO " + tableName + " VALUES (" + ValueJoin + ")"; + insertQuery.prepare(str); if (!insertQuery.exec()) { - qDebug() << "Error inserting into destination table:" << insertQuery.lastError().text(); - errorindex=1; - errorinfo.append("添加本地系统表:"+tableName+"时出错"); - break; // 或者可以记录错误并继续 + + emit taskCompleted(1, tableName,tableName+"|添加本地表数据时错误:"+insertQuery.lastError().text()+"\t"+ValueJoin); + qDebug() < -#include -#include -#include -#include #include +#include +#include "basecommonapi.h" +#include -class SyncTask : public QRunnable { + +class SyncTask :public QObject,public QRunnable { +Q_OBJECT public: - SyncTask(const QSqlDatabase &srcDb, const QSqlDatabase &dstDb, const QString &tableName); - QSqlDatabase sourceDatabase; - QSqlDatabase destinationDatabase; - QString tableName; + SyncTask(QSqlDatabase srcDb,QSqlDatabase dstDb, QString tableName); + + void run() override; + void UpdateState(int state); + +signals: + void taskCompleted(int success,QString tableName, const QString& errorMessage); + void TextState(); + + private: - QMap> syncTable(); + void syncTable(); + +private: + QSqlDatabase srcDb; + QSqlDatabase dstDb; + QString tableName; + SyncRunStatus syncstate; }; #endif // STANDARD_DEVICEITEM_H