123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797 |
- #include "mainwidget.h"
- #include "exceptionbatchitem.h"
- #include "bindschoolinfo.h"
- #include "../Util/Util.h"
- #include "../Util/typedef_struct.h"
- #include <QFileDialog>
- #include <QMessageBox>
- #include <QDateTime>
- #include <QFileDialog>
- #include <QTimer>
- #include "../ZLibWrapLib/ZLibWrapLib.h"
- #include <QNetworkRequest>
- #include <QNetworkReply>
- #include <QJsonObject>
- #include <QJsonParseError>
- #include <QJsonArray>
- #include <QSettings>
- #include "updatedlg.h"
- #include <QProcess>
- 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<batch_info> 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<paper_info>& vct)
- {
- if (vct.size() == 0)
- {
- return;
- }
- m_batchpaperList.clear();
- //每次重新插入数据前释放Item的内存
- ui.tableWidget_uploadfail->clearContents();
- 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("失败原因") << 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);
- QString strIndex = QString("%1,%2").arg(m_curBatch.id).arg(vct[i].id);
- QString strShownText = QString::fromLocal8Bit("上传失败");
- int nStatus = m_mapUploadItemsStatus.value(strIndex);
- if (nStatus == 1)
- strShownText = QString::fromLocal8Bit("上传中");
- else if (nStatus == 2)
- strShownText = QString::fromLocal8Bit("上传完成");
- ui.tableWidget_uploadfail->setItem(i, 7, new QTableWidgetItem(strShownText));
- ui.tableWidget_uploadfail->item(i, 7)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
- if (nStatus != 2)
- {
- m_mapUploadItemsStatus[strIndex] = nStatus;
- m_batchpaperList.push_back(strIndex);
- }
- }
-
- }
- 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(UtfToGbk(m_curBatch.work_dir).c_str());
- ShellExecute(NULL, L"open", NULL, NULL, _papersdir.c_str(), SW_SHOWNORMAL);
- }
- else if (send == ui.pushButton_page_unhandle_batch_picwrong_check)
- {
- wstring _papersdir = GB2312ToUnicode(UtfToGbk(m_curBatch.work_dir).c_str());
- _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(UtfToGbk(m_curBatch.work_dir).c_str());
- _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(UtfToGbk(m_curBatch.work_dir).c_str());
- _papersdir.append(L"papers");
- vector<string> _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(UtfToGbk(m_curBatch.work_dir).c_str());
- _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();
- //将所有上传失败项置为上传中状态
- for (auto strIndex : m_batchpaperList)
- {
- //非上传完成状态的项才需置为上传中状态
- if (m_mapUploadItemsStatus[strIndex] != 2)
- m_mapUploadItemsStatus[strIndex] = 1;
- }
- bind_unloadfaild(m_mapPapers[paper_exc_upload]);
- //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<wstring>* pVctBath = (vector<wstring>*)lpThreadParameter;
- vector<wstring> vct = *pVctBath;
- delete pVctBath;
- for (auto& iter : vct )
- {
- DeleteDirectory(iter);
- }
- return 0;
- }
- void MainWidget::clear_cache()
- {
- vector<wstring> vctBatch = m_dataBaseService.GetCashBatch();
- if (vctBatch.size() == 0)
- {
- return;
- }
- vector<wstring>* pVctBath = new vector<wstring>(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 = UtfToGbk(m_curBatch.work_dir);
- _zip_path.append(UtfToGbk(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/", UtfToGbk(m_curBatch.work_dir), GetTickCount());
- ::CreateDirectoryA(_paper_export, 0);
- auto create_path = [&](const 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 strPage0 = UtfToGbk(file.page0_path);
- string strPage1 = UtfToGbk(file.page1_path);
- string page0_path = create_path(strPage0.c_str());
- string page1_path = create_path(strPage1.c_str());
- CopyFileA(strPage0.c_str(), page0_path.c_str(), FALSE);
- CopyFileA(strPage1.c_str(), 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<paper_info> 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 (version.compare(m_localVersion) > 0)
- {
- ui.label_new->setText("new");
- vector<batch_info> 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();
- }
- }
- }
- }
- }
|