#include "mainwidget.h" #include "exceptionbatchitem.h" #include "bindschoolinfo.h" #include "../Util/Util.h" #include "../Util/typedef_struct.h" #include #include #include #include #include #include "../ZLibWrapLib/ZLibWrapLib.h" #include #include #include #include #include #include #include "updatedlg.h" #include extern wstring g_strConfigPath; #define qrcodeunmatch L"二维码不匹配(%1)" #define locationexception L"定位点异常(%1)" #define uploadfail L"上传失败(%1)" #define scan_paper_normal L"识别" #define scan_paper_identi L"识别中..." #define scan_batch_normal L"批量识别" #define scan_batch_identi L"批量识别中..." #define alert_delete(){ QString msg = QString::fromLocal8Bit("确定执行该删除操作吗?"); \ QMessageBox::StandardButton result = QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), msg, QMessageBox::Yes | QMessageBox::No); \ if (result != QMessageBox::Yes) \ { \ return; \ }} \ void MainWidget::bind_signlslot() { connect(ui.pushButton_bindschool, SIGNAL(clicked()), this, SLOT(slots_bindschool())); connect(ui.pushButton_head_modify_school, SIGNAL(clicked()), this, SLOT(slots_bindschool())); connect(ui.pushButton_batch_unzipfail, SIGNAL(clicked()), this, SLOT(slots_handleclick())); connect(ui.pushButton_batch_picwrong, SIGNAL(clicked()), this, SLOT(slots_handleclick())); connect(ui.pushButton_batch_qrcodeinvalid, SIGNAL(clicked()), this, SLOT(slots_handleclick())); connect(ui.pushButton_batch_pagermissing, SIGNAL(clicked()), this, SLOT(slots_handleclick())); connect(ui.pushButton_paper_qrcodeunmatch, SIGNAL(clicked()), this, SLOT(slots_handleclick())); connect(ui.pushButton_paper_locationexception, SIGNAL(clicked()), this, SLOT(slots_handleclick())); connect(ui.pushButton_paper_uploadfail, SIGNAL(clicked()), this, SLOT(slots_handleclick())); connect(ui.pushButton_paper_exportimg, SIGNAL(clicked()), this, SLOT(slots_handleclick())); connect(ui.pushButton_paper_deleteall, SIGNAL(clicked()), this, SLOT(slots_handleclick())); connect(ui.pushButton_reload_unhandle, SIGNAL(clicked()), this, SLOT(slots_bindUnHandle())); connect(ui.listWidget, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(slots_listclick(QListWidgetItem*))); connect(ui.listWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(slots_listchange(QListWidgetItem*, QListWidgetItem*))); connect(ui.pushButton_page_unhandle_batch_picwrong_check, SIGNAL(clicked()), this, SLOT(slots_pageclick())); connect(ui.pushButton_page_unhandle_batch_picwrong_scan, SIGNAL(clicked()), this, SLOT(slots_pageclick())); connect(ui.pushButton_page_unhandle_batch_unzipfail_extract, SIGNAL(clicked()), this, SLOT(slots_pageclick())); connect(ui.pushButton_page_unhandle_batch_unzipfail_scan, SIGNAL(clicked()), this, SLOT(slots_pageclick())); connect(ui.pushButton_page_unhandle_batch_papermissing_check, SIGNAL(clicked()), this, SLOT(slots_pageclick())); connect(ui.pushButton_page_unhandle_batch_papermissing_scan, SIGNAL(clicked()), this, SLOT(slots_pageclick())); connect(ui.pushButton_locationexception_rescan, SIGNAL(clicked()), this, SLOT(slots_scanclick())); connect(ui.pushButton_qrcodeinvalid_delete_paper, SIGNAL(clicked()), this, SLOT(slots_scanclick())); connect(ui.pushButton_qrcodeunmatch_delete_paper, SIGNAL(clicked()), this, SLOT(slots_scanclick())); connect(ui.pushButton_locationexception_delete_paper, SIGNAL(clicked()), this, SLOT(slots_scanclick())); connect(ui.pushButton_qrcodeunmatch_rescan, SIGNAL(clicked()), this, SLOT(slots_scanclick())); connect(ui.pushButton_qrcodeinvalid_batch_rescan, SIGNAL(clicked()), this, SLOT(slots_scanclick())); connect(ui.pushButton_qrcodeunmatch_delete_all, SIGNAL(clicked()), this, SLOT(slots_scanclick())); connect(ui.pushButton_locationexception_delete_all, SIGNAL(clicked()), this, SLOT(slots_scanclick())); connect(ui.pushButton_uploadfail_delete_all, SIGNAL(clicked()), this, SLOT(slots_scanclick())); connect(ui.pushButton_reupload, SIGNAL(clicked()), this, SLOT(slots_scanclick())); connect(ui.pushButton_page_unhandle_batch_unzipfail_delete, SIGNAL(clicked()), this, SLOT(slots_scanclick())); connect(ui.pushButton_page_unhandle_batch_picwrong_delete, SIGNAL(clicked()), this, SLOT(slots_scanclick())); connect(ui.pushButton_page_unhandle_batch_papermissing_delete, SIGNAL(clicked()), this, SLOT(slots_scanclick())); connect(ui.toolButton_checkUpdate, SIGNAL(clicked()), this, SLOT(slots_checkUpdateclick())); } void MainWidget::slots_bindUnHandle() { ui.listWidget->clear(); vector vct = m_dataBaseService.GetFailedBatch(); for (int i = 0; i < vct.size(); i++) { CExceptionBatchItem* bt = new CExceptionBatchItem(); bt->SetBatchInfo(vct[i]); QListWidgetItem* pListWidgetItem = new QListWidgetItem; pListWidgetItem->setSizeHint(QSize(230, 56)); ui.listWidget->addItem(pListWidgetItem); ui.listWidget->setItemWidget(pListWidgetItem, bt); } ui.label_left_unhandle_batchs->setText(QString::number(vct.size())); ui.label_page_unhandle_batchs->setText(QString::number(vct.size())); ui.stackedWidget_exception->setCurrentWidget(ui.page_wellcome); } void MainWidget::slots_listclick(QListWidgetItem* item) { ui.stackedWidget_exception->setCurrentWidget(ui.page_unhandle); CExceptionBatchItem* batch_item = (CExceptionBatchItem*)ui.listWidget->itemWidget(item); batch_item->GetBatchInfo(m_curBatch); load_exception(); } void MainWidget::load_exception() { ui.pushButton_batch_unzipfail->hide(); ui.pushButton_batch_picwrong->hide(); ui.pushButton_batch_qrcodeinvalid->hide(); ui.pushButton_batch_pagermissing->hide(); ui.pushButton_paper_qrcodeunmatch->hide(); ui.pushButton_paper_locationexception->hide(); ui.pushButton_paper_uploadfail->hide(); ui.pushButton_paper_deleteall->show(); ui.label_qrcodeinvalid_tip->hide(); ui.label_qrcodeunmatch_tip->hide(); m_dataBaseService.GetBatchInfo(m_curBatch); if (m_curBatch.state == -1) { slots_bindUnHandle(); return; } ParsePapers(); if (batch_exc_unzip == m_curBatch.state) { ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_batch_unzipfail); ui.pushButton_batch_unzipfail->show(); ui.pushButton_batch_unzipfail->setChecked(true); ui.pushButton_paper_deleteall->hide(); } else if (batch_exc_multiple == m_curBatch.state) { ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_batch_picwrong); ui.pushButton_batch_picwrong->show(); ui.pushButton_batch_picwrong->setChecked(true); ui.label_zip_paper_count->setText(QString::number(m_curBatch.zipfile_cnt)); ui.pushButton_paper_deleteall->hide(); } else if (batch_exc_pages_missed == m_curBatch.state) { ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_batch_pagermissing); ui.pushButton_batch_pagermissing->show(); ui.pushButton_batch_pagermissing->setChecked(true); ui.pushButton_paper_deleteall->hide(); } else if (batch_exc_invalid_qrcode == m_curBatch.state) { if (m_mapPapers.size() == 0) // 没有试卷了 { m_dataBaseService.DeleteIndex(m_curBatch.id); slots_bindUnHandle(); return; } ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_batch_qrcodeinvalid); ui.pushButton_batch_qrcodeinvalid->show(); ui.pushButton_batch_qrcodeinvalid->setChecked(true); ui.widget_qrcodeinvalid_edithandle->setCurrentBatch(&m_curBatch, &m_mapPapers.begin()->second); // ui.widget_qrcodeinvalid_edithandle->setCurrentBatch(&m_curBatch, &m_mapPapers[paper_exc_ori]); } else if (batch_exc_scan_excption == m_curBatch.state) { bool _exist_exception(false); // 是否还在有异常信息 for (auto& iter : m_mapPapers) { if (iter.first > 0 && iter.second.size() > 0) { _exist_exception = true; } } if (!_exist_exception) { m_dataBaseService.DeleteIndex(m_curBatch.id); slots_bindUnHandle(); return; } bool _bclicked(false); int _count = m_mapPapers[paper_exc_qrcode_unmatch].size(); if (_count > 0) { ui.pushButton_paper_qrcodeunmatch->show(); ui.pushButton_paper_qrcodeunmatch->setText(QString::fromStdWString(qrcodeunmatch).arg(_count)); ui.pushButton_paper_qrcodeunmatch->click(); ui.widget_qrcodeunmatch_edithandle->setCurrentBatch(&m_curBatch, &m_mapPapers[paper_exc_qrcode_unmatch]); _bclicked = true; } _count = m_mapPapers[paper_exc_locate].size(); if (_count > 0) { ui.pushButton_paper_locationexception->show(); ui.pushButton_paper_locationexception->setText(QString::fromStdWString(locationexception).arg(_count)); if (!_bclicked) { ui.pushButton_paper_locationexception->click(); ui.widget_locationexception_edithandle->setCurrentBatch(&m_curBatch, &m_mapPapers[paper_exc_locate]); _bclicked = true; } } _count = m_mapPapers[paper_exc_upload].size(); if (_count > 0) { ui.pushButton_paper_uploadfail->show(); ui.pushButton_paper_uploadfail->setText(QString::fromStdWString(uploadfail).arg(_count)); if (!_bclicked) { ui.pushButton_paper_uploadfail->click(); _bclicked = true; bind_unloadfaild(m_mapPapers[paper_exc_upload]); } } } } void MainWidget::bind_unloadfaild(vector& vct) { if (vct.size() == 0) { return; } ui.tableWidget_uploadfail->horizontalHeader()->setVisible(true); ui.tableWidget_uploadfail->verticalHeader()->setVisible(false); QStringList header; header << QString::fromLocal8Bit("序号") << QString::fromLocal8Bit("二维码ID") << QString::fromLocal8Bit("作业名称") << QString::fromLocal8Bit("学科") << QString::fromLocal8Bit("学号") << QString::fromLocal8Bit("扫描时间") << QString::fromLocal8Bit("失败原因"); ui.tableWidget_uploadfail->setHorizontalHeaderLabels(header); ui.tableWidget_uploadfail->setEditTriggers(QAbstractItemView::NoEditTriggers); ui.tableWidget_uploadfail->setSelectionMode(QAbstractItemView::NoSelection); ui.tableWidget_uploadfail->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); //x先自适应宽度 ui.tableWidget_uploadfail->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents); //然后设置要根据内容使用宽度的列 ui.tableWidget_uploadfail->horizontalHeader()->setStyleSheet("border:1px solid rgb(216,216,216)"); ui.tableWidget_uploadfail->setRowCount(vct.size()); for (int i = 0; i < vct.size(); i++) { QDateTime scan_time = QDateTime::fromTime_t(vct[i].scan_time); ui.tableWidget_uploadfail->setItem(i, 0, new QTableWidgetItem(QString::number(i+1))); ui.tableWidget_uploadfail->item(i, 0)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); ui.tableWidget_uploadfail->setItem(i, 1, new QTableWidgetItem(vct[i].qr_code)); ui.tableWidget_uploadfail->item(i, 1)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); ui.tableWidget_uploadfail->setItem(i, 2, new QTableWidgetItem(QString::fromLocal8Bit(vct[i].exam_name))); ui.tableWidget_uploadfail->item(i, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); ui.tableWidget_uploadfail->setItem(i, 3, new QTableWidgetItem(QString::fromLocal8Bit(vct[i].subject_name))); ui.tableWidget_uploadfail->item(i, 3)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); ui.tableWidget_uploadfail->setItem(i, 4, new QTableWidgetItem(vct[i].student_id)); ui.tableWidget_uploadfail->item(i, 4)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); ui.tableWidget_uploadfail->setItem(i, 5, new QTableWidgetItem(scan_time.toString("yyyy-MM-dd hh:mm:ss"))); ui.tableWidget_uploadfail->item(i, 5)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); QString err_msg = QString::fromLocal8Bit("网络异常"); if (strlen(vct[i].err_msg) > 0) { err_msg = QString::fromLocal8Bit(vct[i].err_msg); } ui.tableWidget_uploadfail->setItem(i, 6, new QTableWidgetItem(err_msg)); ui.tableWidget_uploadfail->item(i, 6)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); } } void MainWidget::slots_listchange(QListWidgetItem* current, QListWidgetItem* pre) { } void MainWidget::slots_bindschool() { CBindSchoolInfo info(this); int rlt = info.exec(); if (rlt == QDialog::Accepted) { ui.stackedWidget_init->setCurrentWidget(ui.page_main); load_schoolinfo(); } } void MainWidget::slots_handleclick() { QObject* send = this->sender(); if (send == ui.pushButton_batch_unzipfail) { ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_batch_unzipfail); } else if (send == ui.pushButton_batch_picwrong) { ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_batch_picwrong); } else if (send == ui.pushButton_batch_qrcodeinvalid) { ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_batch_qrcodeinvalid); } else if (send == ui.pushButton_paper_qrcodeunmatch) { ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_paper_qrcodeunmatch); ui.widget_qrcodeunmatch_edithandle->setCurrentBatch(&m_curBatch, &m_mapPapers[paper_exc_qrcode_unmatch]); } else if (send == ui.pushButton_paper_locationexception) { ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_paper_locationexception); ui.widget_locationexception_edithandle->setCurrentBatch(&m_curBatch, &m_mapPapers[paper_exc_locate]); } else if (send == ui.pushButton_batch_pagermissing) { ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_batch_pagermissing); } else if (send == ui.pushButton_paper_uploadfail) { ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_paper_uploadfail); bind_unloadfaild(m_mapPapers[paper_exc_upload]); } else if (send == ui.pushButton_paper_exportimg) { Save_FileAs(); } else if (send == ui.pushButton_paper_deleteall) { QString msg = QString::fromLocal8Bit("确定删除该批次吗?"); QMessageBox::StandardButton result = QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), msg, QMessageBox::Yes | QMessageBox::No); if (result == QMessageBox::Yes) { m_dataBaseService.DeleteIndex(m_curBatch.id); slots_bindUnHandle(); } } //QWidget* _page = ui.stackedWidget_unhandle_page->currentWidget(); //QSize _size = _page->size(); //_page->resize(_size - QSize(1, 1)); //_page->resize(_size + QSize(1, 1)); } void MainWidget::slots_pageclick() { QObject* send = this->sender(); if (send == ui.pushButton_page_unhandle_batch_unzipfail_extract) { wstring _papersdir = GB2312ToUnicode(m_curBatch.work_dir); ShellExecute(NULL, L"open", NULL, NULL, _papersdir.c_str(), SW_SHOWNORMAL); } else if (send == ui.pushButton_page_unhandle_batch_picwrong_check) { wstring _papersdir = GB2312ToUnicode(m_curBatch.work_dir); _papersdir.append(L"papers"); ShellExecute(NULL, L"open", NULL, NULL, _papersdir.c_str(), SW_SHOWNORMAL); } else if (send == ui.pushButton_page_unhandle_batch_papermissing_check) { wstring _papersdir = GB2312ToUnicode(m_curBatch.work_dir); _papersdir.append(L"papers"); ShellExecute(NULL, L"open", NULL, NULL, _papersdir.c_str(), SW_SHOWNORMAL); } else if (send == ui.pushButton_page_unhandle_batch_picwrong_scan || // 已手动解压完成去识别 与 已检查完成去识别不同点是一个是更新index.db3,一个是插件index.db3 send == ui.pushButton_page_unhandle_batch_unzipfail_scan || send == ui.pushButton_page_unhandle_batch_papermissing_scan) { wstring _papersdir = GB2312ToUnicode(m_curBatch.work_dir); _papersdir.append(L"papers"); vector _listPapers; DetectDirectory(_papersdir, _listPapers); if (_listPapers.size() == 0 || _listPapers.size() % 2 == 1) { QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("试卷非偶数倍(仅支持JPG格式的图片)"), QMessageBox::Ok); return; } HWND hWndUnzip = NULL; HANDLE hMapFile = OpenFileMapping(FILE_MAP_ALL_ACCESS, NULL, SHARE_MEMORY_NAME); if (hMapFile) { LPVOID lpBase = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 0); share_memory_block* _data_block = (share_memory_block*)lpBase; hWndUnzip = (HWND)strtol(_data_block->unzip_handle, 0, 16); UnmapViewOfFile(lpBase); CloseHandle(hMapFile); } if (!IsWindow(hWndUnzip)) { QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("监控程序未开启"), QMessageBox::Ok); return; } wstring _batchpath = GB2312ToUnicode(m_curBatch.work_dir); _batchpath.append(L"batch.db3"); bool rlt_batch = m_dataBaseService.InsertPapers(_batchpath, _listPapers); if (rlt_batch) { bool rlt_index = m_dataBaseService.UpdateIndexPicWrong(_listPapers.size() / 2, m_curBatch.id); if (rlt_index) { HWND local_hwnd = (HWND)this->winId(); char buf[128] = { 0 }; sprintf(buf, "%s:%d", UNHANDL_RESCAN, m_curBatch.id); COPYDATASTRUCT cpd; cpd.dwData = strlen(buf) + sizeof(COPYDATASTRUCT); cpd.cbData = strlen(buf); cpd.lpData = (void*)buf; ::SendMessage(hWndUnzip, WM_COPYDATA, (WPARAM)local_hwnd, (LPARAM)&cpd); slots_bindUnHandle(); } else { QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("更新batch.db3失败"), QMessageBox::Ok); } } else { QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("更新index.db3失败"), QMessageBox::Ok); } } } void MainWidget::slots_scanclick() { QObject* send = this->sender(); if (send == ui.pushButton_qrcodeinvalid_delete_paper) { alert_delete(); paper_info _paper; ui.widget_qrcodeinvalid_edithandle->GetCurrentPaper(_paper); m_dataBaseService.DeletePaper(GB2312ToUnicode(m_curBatch.batchdb_path), _paper.id); load_exception(); } else if(send == ui.pushButton_qrcodeunmatch_delete_paper) { alert_delete(); paper_info _paper; ui.widget_qrcodeunmatch_edithandle->GetCurrentPaper(_paper); m_dataBaseService.DeletePaper(GB2312ToUnicode(m_curBatch.batchdb_path), _paper.id); load_exception(); } else if(send == ui.pushButton_locationexception_delete_paper) { alert_delete(); paper_info _paper; ui.widget_locationexception_edithandle->GetCurrentPaper(_paper); m_dataBaseService.DeletePaper(GB2312ToUnicode(m_curBatch.batchdb_path), _paper.id); load_exception(); } else if (send == ui.pushButton_qrcodeinvalid_batch_rescan) { QString _qrcode = ui.lineEdit_qrcodeinvalid_batch_qrcode->text(); _qrcode = _qrcode.trimmed(); if (_qrcode.length() == 0) { QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("未输入批次二维码ID"), QMessageBox::Ok); return; } ui.pushButton_qrcodeinvalid_batch_rescan->setText(QString::fromStdWString(scan_batch_identi)); ui.pushButton_qrcodeinvalid_batch_rescan->setEnabled(false); QTimer::singleShot(50, this, [&, _qrcode](){ ReBatchScan(m_curBatch.id, _qrcode.toStdString()); load_exception(); ui.pushButton_qrcodeinvalid_batch_rescan->setText(QString::fromStdWString(scan_batch_normal)); ui.pushButton_qrcodeinvalid_batch_rescan->setEnabled(true); }); } else if (send == ui.pushButton_qrcodeunmatch_rescan) { QString _qrcode = ui.lineEdit_qrcodeunmatch_qrcode->text(); _qrcode = _qrcode.trimmed(); if (_qrcode.length() == 0) { QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("输入二维码ID"), QMessageBox::Ok); return; } ui.pushButton_qrcodeunmatch_rescan->setText(QString::fromStdWString(scan_paper_identi)); ui.pushButton_qrcodeunmatch_rescan->setEnabled(false); QTimer::singleShot(50, this, [&, _qrcode](){ paper_info _paper; ui.widget_qrcodeunmatch_edithandle->GetCurrentPaper(_paper); ReScan(m_curBatch.id, _paper.id, _paper.page0_path, _paper.page1_path, _qrcode.toStdString()); m_dataBaseService.UpdatePapersPath(GB2312ToUnicode(m_curBatch.batchdb_path), _paper); load_exception(); m_dataBaseService.GetPaperByID(GB2312ToUnicode(m_curBatch.batchdb_path), _paper.id, _paper); if ((_paper.state & paper_exc_qrcode_unmatch) == paper_exc_qrcode_unmatch) { ui.label_qrcodeunmatch_tip->show(); } ui.pushButton_qrcodeunmatch_rescan->setText(QString::fromStdWString(scan_paper_normal)); ui.pushButton_qrcodeunmatch_rescan->setEnabled(true); }); } else if (send == ui.pushButton_locationexception_rescan) { ui.pushButton_locationexception_rescan->setText(QString::fromStdWString(scan_paper_identi)); ui.pushButton_locationexception_rescan->setEnabled(false); QTimer::singleShot(50, this, [&](){ paper_info _paper; ui.widget_locationexception_edithandle->GetCurrentPaper(_paper); ReScan(m_curBatch.id, _paper.id, _paper.page0_path, _paper.page1_path); m_dataBaseService.UpdatePapersPath(GB2312ToUnicode(m_curBatch.batchdb_path), _paper); load_exception(); ui.pushButton_locationexception_rescan->setText(QString::fromStdWString(scan_paper_normal)); ui.pushButton_locationexception_rescan->setEnabled(true); }); } else if (send == ui.pushButton_qrcodeunmatch_delete_all || send == ui.pushButton_locationexception_delete_all || send == ui.pushButton_uploadfail_delete_all) { alert_delete(); int state = -1; if (ui.pushButton_paper_qrcodeunmatch->isChecked()) { state = paper_exc_qrcode_unmatch; } else if (ui.pushButton_paper_locationexception->isChecked()) { state = paper_exc_locate; } else { state = paper_exc_upload; } m_dataBaseService.DeletePaperAll(GB2312ToUnicode(m_curBatch.batchdb_path), state); load_exception(); } else if (send == ui.pushButton_reupload) { ReUploadAllFailed(); slots_bindUnHandle(); } else if (send == ui.pushButton_page_unhandle_batch_unzipfail_delete || send == ui.pushButton_page_unhandle_batch_picwrong_delete || send == ui.pushButton_page_unhandle_batch_papermissing_delete) { QString msg = QString::fromLocal8Bit("确定删除该批次吗?"); QMessageBox::StandardButton result = QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), msg, QMessageBox::Yes | QMessageBox::No); if (result == QMessageBox::Yes) { m_dataBaseService.DeleteIndex(m_curBatch.id); slots_bindUnHandle(); } } } void MainWidget::load_schoolinfo() { WCHAR school_name[MAX_PATH] = { 0 }; GetPrivateProfileString(_T("USER"), _T("school_name"), _T(""), school_name, MAX_PATH, g_strConfigPath.c_str()); if (_tcsclen(school_name) == 0) { return; } ui.label_top_school->setText(QString::fromStdWString(school_name)); ui.label_main_school->setText(QString::fromStdWString(school_name)); ui.stackedWidget_init->setCurrentWidget(ui.page_main); ui.label_top_school_static->show(); ui.label_top_school->show(); ui.widget_index_page->show(); clear_cache(); slots_bindUnHandle(); } DWORD WINAPI ThreadDeleteDir(LPVOID lpThreadParameter) { vector* pVctBath = (vector*)lpThreadParameter; vector vct = *pVctBath; delete pVctBath; for (auto& iter : vct ) { DeleteDirectory(iter); } return 0; } void MainWidget::clear_cache() { vector vctBatch = m_dataBaseService.GetCashBatch(); if (vctBatch.size() == 0) { return; } vector* pVctBath = new vector(vctBatch); CreateThread(NULL, 0, ThreadDeleteDir, pVctBath, 0, NULL); } void MainWidget::Save_FileAs() //另存为 { QString dirpath = QFileDialog::getExistingDirectory(this, QString::fromLocal8Bit("选择文件存放路径"), "./", QFileDialog::ShowDirsOnly); if (dirpath.size() == 0) { return; } QString export_image_path = QString("%1/exception_image_%2.zip").arg(dirpath).arg(GetTickCount()); if (m_curBatch.state == batch_exc_invalid_qrcode || m_curBatch.state == batch_exc_multiple || m_curBatch.state == batch_exc_unzip) { string _zip_path = m_curBatch.work_dir; _zip_path.append(m_curBatch.zipfile_name); _zip_path.append(".zip"); BOOL rlt = CopyFileA(_zip_path.c_str(), export_image_path.toStdString().c_str(), FALSE); if (rlt) { QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("异常图片导出成功,路径:%1").arg(export_image_path), QMessageBox::Ok); } else { QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("异常图片导出失败"), QMessageBox::Ok); } return; } char _paper_export[MAX_PATH] = { 0 }; sprintf(_paper_export, "%sexport_tmp_%d/", m_curBatch.work_dir, GetTickCount()); ::CreateDirectoryA(_paper_export, 0); auto create_path = [&](char* path){ string _source = path; string _file_name = _source.substr(_source.rfind('/')+1); string _path = _paper_export; _path.append(_file_name); return _path; }; auto stringReplace = [](std::wstring& strContent, std::wstring strReplace, std::wstring strDest) { while (true) { size_t pos = strContent.find(strReplace); if (pos != std::wstring::npos) { WCHAR pBuf[1] = { L'\0' }; strContent.replace(pos, strReplace.length(), pBuf, 0); strContent.insert(pos, strDest); } else { break; } } return 0; }; for (auto& iter : m_mapPapers) { if (iter.first > 0) { for (auto& file : iter.second) { string page0_path = create_path(file.page0_path); string page1_path = create_path(file.page1_path); CopyFileA(file.page0_path, page0_path.c_str(), FALSE); CopyFileA(file.page1_path, page1_path.c_str(), FALSE); } } } wstring _export_dir = GB2312ToUnicode(_paper_export); wstring _export_files = _export_dir + L"*.*"; stringReplace(_export_files, L"/", L"\\"); BOOL rlt = ZipCompress(_export_files.c_str(), export_image_path.toStdWString().c_str()); if (rlt) { QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("异常图片导出成功,路径:%1").arg(export_image_path), QMessageBox::Ok); } else { QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("异常图片导出失败"), QMessageBox::Ok); } //ShellExecute(NULL, L"open", NULL, NULL, _papersdir.c_str(), SW_SHOWNORMAL); } void MainWidget::ParsePapers() { m_mapPapers.clear(); wstring _papersdir = GB2312ToUnicode(m_curBatch.batchdb_path); vector vctPapers; m_dataBaseService.GetBatchPapers(_papersdir, vctPapers); if (vctPapers.size() == 0) { return; } for (auto& iter : vctPapers) { m_mapPapers[iter.state].push_back(iter); } } void MainWidget::slots_checkUpdateclick() // 检查更新 { WCHAR server_url[MAX_PATH] = { 0 }; GetPrivateProfileString(L"USER", L"server_url", L"", server_url, MAX_PATH, g_strConfigPath.c_str()); QString url(QString::fromStdWString(server_url)); url.append("/teacher/third/get/latestVersion?appType=0"); QNetworkRequest request; request.setUrl(url); request.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("application/json;charset=utf-8")); request.setRawHeader("Authorization", "Basic ZnhiLXNoOmVDbGo0TlRoSHlMY05USE0wZWl3ZWpVUExCcGFlZQ==");//Authorization身份验证 QNetworkAccessManager manager; manager.setNetworkAccessible(QNetworkAccessManager::Accessible); QNetworkReply* reply = manager.get(request); QEventLoop eventLoop; QObject::connect(&manager, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit())); eventLoop.exec(); QByteArray bytes = reply->readAll(); // bytes QString response = QString::fromUtf8(bytes); QJsonParseError json_error; QJsonDocument jsonDoc = QJsonDocument::fromJson(bytes, &json_error); QString message; if (jsonDoc.isObject()) { QJsonObject json_obj = jsonDoc.object(); if (json_obj.contains("code") && json_obj.value("code").toInt() == 200) { if (json_obj.contains("data")) { QJsonObject json_data = json_obj.value("data").toObject(); QString version = json_data.value("versionNumber").toString(); QString changeLog = json_data.value("changeLog").toString(); QString fileUrl = json_data.value("fileUrl").toString(); if (m_localVersion!=version) { ui.label_new->setText("new"); vector vct = m_dataBaseService.GetFailedBatch(); UpdateDlg *updateDlg = new UpdateDlg(changeLog, version, fileUrl, vct.size()>0?true:false); updateDlg->setAttribute(Qt::WA_ShowModal, true); updateDlg->show(); int ret = updateDlg->exec(); } else { ui.label_new->setText(""); QMessageBox box(QMessageBox::Warning, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("当前已是最新版本")); box.setStandardButtons(QMessageBox::Ok); box.setButtonText(QMessageBox::Ok, QString::fromLocal8Bit("确定")); box.exec(); } } } } }