|
|
#include "ModeCountDlg.h"
|
|
|
#include "QMap"
|
|
|
#include "QProgressDialog"
|
|
|
#include "QSqlQuery"
|
|
|
#include "qtimedlg.h"
|
|
|
#include <QDebug>
|
|
|
#include "QFileDialog"
|
|
|
#pragma execution_character_set("utf-8")
|
|
|
ModeCountDlg::ModeCountDlg(QWidget *parent)
|
|
|
: QWidget(parent)
|
|
|
{
|
|
|
ui.setupUi(this);
|
|
|
|
|
|
m_GridLayout = new QGridLayout;
|
|
|
reportdlg = new QReportWidget;
|
|
|
m_GridLayout->addWidget(reportdlg);
|
|
|
m_countwidget = new QWidget;
|
|
|
Hbox = new QVBoxLayout;
|
|
|
m_GridLayout->setMargin(0);
|
|
|
m_GridLayout->addLayout(Hbox, 0, 1);
|
|
|
m_countwidget->setLayout(m_GridLayout);
|
|
|
|
|
|
m_WorkCount = new CountData;
|
|
|
m_WorkCount->moveToThread(&m_WorkThreadCount);
|
|
|
|
|
|
connect(&m_WorkThreadCount, &QThread::finished, m_WorkCount, &QObject::deleteLater);
|
|
|
connect(this, &ModeCountDlg::operateCount, m_WorkCount, &CountData::doWork);
|
|
|
connect(m_WorkCount, &CountData::resultReady, this, &ModeCountDlg::handleResultsCount);
|
|
|
connect(m_WorkCount, SIGNAL(sgShowMsg(QString)), this, SLOT(onShowMessage(QString)));
|
|
|
connect(m_WorkCount, &CountData::sgShowProgress, this, &ModeCountDlg::onProgressForTsk);
|
|
|
m_WorkThreadCount.start();
|
|
|
qDebug() << "start thread m_WorkThreadCount";
|
|
|
|
|
|
nstartTime.setHMS(0, 0, 0);
|
|
|
nEndTime.setHMS(23, 59, 59);
|
|
|
m_startDate_Count = QDateTime::currentDateTime();
|
|
|
m_endDate_Count = QDateTime::currentDateTime();
|
|
|
|
|
|
|
|
|
ui.label_Time1_Count->setText(m_startDate_Count.toString("yyyy-MM-dd hh:mm:ss"));
|
|
|
ui.label_Time2_Count->setText(m_endDate_Count.toString("yyyy-MM-dd hh:mm:ss"));
|
|
|
|
|
|
if (reportdlg)
|
|
|
reportdlg->ClearData();
|
|
|
|
|
|
connect(ui.pushButton_Set1_Count, SIGNAL(clicked()), this, SLOT(SlotEditTime()));
|
|
|
connect(ui.pushButton_Set2_Count, SIGNAL(clicked()), this, SLOT(SlotEditTime()));
|
|
|
connect(ui.pushButton_Checkdata_Calculate, SIGNAL(clicked()), this, SLOT(onCheckButton()));
|
|
|
connect(ui.pushButton_SaveCalculate, SIGNAL(clicked()), this, SLOT(onCheckButton()));
|
|
|
connect(ui.comboBox_Banci_Calculate, SIGNAL(currentIndexChanged(int)), this, SLOT(SlotCombox(int)));
|
|
|
|
|
|
m_Progressdlg.setWindowModality(Qt::ApplicationModal);
|
|
|
m_Progressdlg.setWindowIcon(QIcon(":/image/leaper"));
|
|
|
m_IsRunCountTsk = false;
|
|
|
ui.scrollArea->setLayout(m_GridLayout);
|
|
|
}
|
|
|
|
|
|
ModeCountDlg::~ModeCountDlg()
|
|
|
{
|
|
|
if (m_countwidget)
|
|
|
{
|
|
|
delete m_countwidget;
|
|
|
m_countwidget = NULL;
|
|
|
}
|
|
|
|
|
|
if (m_WorkThreadCount.isRunning())
|
|
|
{
|
|
|
qDebug() << "delete m_WorkThreadCount";
|
|
|
m_WorkThreadCount.quit();
|
|
|
m_WorkThreadCount.wait(50);
|
|
|
qDebug() << "delete m_WorkThreadCount end";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void ModeCountDlg::setDBPtr(class DetectDataDB *ptr)
|
|
|
{
|
|
|
m_pDb = ptr;
|
|
|
if(m_WorkCount)
|
|
|
m_WorkCount->setDB(m_pDb);
|
|
|
}
|
|
|
|
|
|
void ModeCountDlg::initParam(QMap<QString, TimeStruct> timetable, QStringList names)
|
|
|
{
|
|
|
m_Totaltime = timetable;
|
|
|
ui.comboBox_Banci_Calculate->clear();
|
|
|
ui.comboBox_Banci_Calculate->addItem(tr("ȫ<EFBFBD><EFBFBD>"));
|
|
|
ui.comboBox_Banci_Calculate->addItems(m_Totaltime.keys());
|
|
|
}
|
|
|
|
|
|
Q_SLOT void ModeCountDlg::handleResultsCount(const QString &result, const QMap<QString, int> *p)
|
|
|
{
|
|
|
reportdlg->ClearData();
|
|
|
reportdlg->setTitle(tr("ͳ<EFBFBD>ƽ<EFBFBD><EFBFBD><EFBFBD> "));
|
|
|
if (p == NULL) {
|
|
|
m_IsRunCountTsk = false;
|
|
|
return;
|
|
|
}
|
|
|
m_CountNumber = *p;
|
|
|
reportdlg->SetData(QMap<QString, int>(*p)/*m_CountNumber*/);
|
|
|
if (!p->contains(QString("NG")))
|
|
|
reportdlg->AppendData(QString("NG"), 0, true);
|
|
|
reportdlg->AppendData(tr("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"), result.toInt(), true);
|
|
|
reportdlg->UpdateTableView();
|
|
|
//onShowMessage(tr("ͳ<><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
|
|
|
m_IsRunCountTsk = false;
|
|
|
if (p)
|
|
|
delete p;
|
|
|
}
|
|
|
|
|
|
void ModeCountDlg::CheckDataByDate(QString m_strLast, QString m_endLast)
|
|
|
{
|
|
|
if (m_IsRunCountTsk != false)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
m_IsRunCountTsk = true;
|
|
|
m_CountNumber.clear();
|
|
|
m_channels.clear();
|
|
|
|
|
|
QProgressDialog progress;
|
|
|
progress.setWindowModality(Qt::ApplicationModal);
|
|
|
progress.setWindowTitle(tr("<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
|
|
|
progress.setWindowIcon(QIcon(":/image/leaper"));
|
|
|
progress.setLabelText(tr("<EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD>ѯ<EFBFBD><EFBFBD>,<2C><><EFBFBD>Ժ<EFBFBD>....."));
|
|
|
progress.setCancelButton(0);
|
|
|
QSqlQuery sql;
|
|
|
QVariantMap m_Value;
|
|
|
m_Value.insert(_CHECK_TYPE_, EMT_CHECK_BY_COUNT);
|
|
|
m_Value.insert(_CHECK_TIME1_, m_strLast);
|
|
|
m_Value.insert(_CHECK_TIME2_, m_endLast);
|
|
|
m_Value.insert("CheckType", "Count");
|
|
|
QString strCheck = m_pDb->genCheckStr(m_Value);
|
|
|
m_Value.insert(_CHECK_COUNT_, 1);
|
|
|
QString strCount = m_pDb->genCheckStr(m_Value);
|
|
|
QVariantMap m_map;
|
|
|
m_map.insert("SqlCount", strCount);
|
|
|
m_map.insert("SqlCheck", strCheck);
|
|
|
emit operateCount(m_map);
|
|
|
}
|
|
|
|
|
|
Q_SLOT void ModeCountDlg::SlotEditTime()
|
|
|
{
|
|
|
QObject *obj = sender();
|
|
|
QString str = obj->objectName();
|
|
|
if (str == "pushButton_Set1_Count")
|
|
|
{
|
|
|
QTimeDlg dlg;
|
|
|
dlg.SetDateTime(m_startDate_Count);
|
|
|
dlg.setWindowModality(Qt::ApplicationModal);
|
|
|
if (dlg.exec() == QDialog::Accepted)
|
|
|
{
|
|
|
dlg.GetDateTime(m_startDate_Count);
|
|
|
QString m_strLast = m_startDate_Count.toString("yyyy-MM-dd hh:mm:ss");
|
|
|
ui.label_Time1_Count->setText(m_strLast);
|
|
|
}
|
|
|
}
|
|
|
else if (str == "pushButton_Set2_Count")
|
|
|
{
|
|
|
QTimeDlg dlg;
|
|
|
dlg.SetDateTime(m_endDate_Count);
|
|
|
if (dlg.exec() == QDialog::Accepted)
|
|
|
{
|
|
|
dlg.GetDateTime(m_endDate_Count);
|
|
|
QString m_endLast = m_endDate_Count.toString("yyyy-MM-dd hh:mm:ss");
|
|
|
ui.label_Time2_Count->setText(m_endLast);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Q_SLOT void ModeCountDlg::onProgressForTsk(QVariantMap m_map)
|
|
|
{
|
|
|
QString nType = m_map.value("Type").toString();
|
|
|
if (nType == "start")
|
|
|
{
|
|
|
QString strMsg = m_map.value("msg", tr("<EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>")).toString();
|
|
|
m_Progressdlg.setWindowTitle(strMsg);
|
|
|
m_Progressdlg.Start(50, 150),
|
|
|
m_Progressdlg.show();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
m_Progressdlg.Stop();
|
|
|
m_Progressdlg.hide();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Q_SLOT void ModeCountDlg::onCheckButton()
|
|
|
{
|
|
|
QObject *obj = sender();
|
|
|
QString str = obj->objectName();
|
|
|
if ("pushButton_Checkdata_Calculate" == str)
|
|
|
{
|
|
|
static bool checkflags = false;
|
|
|
if (checkflags == false)
|
|
|
{
|
|
|
checkflags = true;
|
|
|
QString strBanci = ui.comboBox_Banci_Calculate->currentText();
|
|
|
if (m_Totaltime.contains(strBanci))
|
|
|
{
|
|
|
if (m_startDate_Count.date() > m_endDate_Count.date())
|
|
|
{
|
|
|
if (m_Totaltime.value(strBanci).m_startTime > m_Totaltime.value(strBanci).m_endTime)
|
|
|
{
|
|
|
onMessageBox(QMessageBox::Information, tr("<EFBFBD><EFBFBD>ʾ"), tr("<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD>İ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>Ǹ<EFBFBD>ҹ<EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD>һ<EFBFBD>µ<EFBFBD>ǰ<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><EFBFBD>ٲ<EFBFBD>ѯ"));
|
|
|
checkflags = false;
|
|
|
return;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
onMessageBox(QMessageBox::Information, tr("<EFBFBD><EFBFBD>ʾ"), tr("<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><EFBFBD>ٲ<EFBFBD>ѯ"));
|
|
|
checkflags = false;
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (m_startDate_Count.date() > m_endDate_Count.date())
|
|
|
{
|
|
|
onMessageBox(QMessageBox::Information, tr("<EFBFBD><EFBFBD>ʾ"), tr("<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD>һ<EFBFBD>µ<EFBFBD>ǰ<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><EFBFBD>ٲ<EFBFBD>ѯ"));
|
|
|
checkflags = false;
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
QString m_strLast = ui.label_Time1_Count->text();
|
|
|
QString m_endLast = ui.label_Time2_Count->text();
|
|
|
//QString strMsg = tr("<22><>ѯ<EFBFBD><D1AF>%1-%2<><32>ͳ<EFBFBD><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>").arg(ui.label_Time1_Count->text()).arg(ui.label_Time2_Count->text());
|
|
|
//SaveLog(strMsg);
|
|
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
|
|
CheckDataByDate(m_strLast, m_endLast);
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
checkflags = false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
onMessageBox(QMessageBox::Information, tr("<EFBFBD><EFBFBD>ʾ"), tr("<EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ժ<EFBFBD>"));
|
|
|
}
|
|
|
}
|
|
|
else if ("pushButton_SaveCalculate" == str)
|
|
|
{
|
|
|
if (m_CountNumber.size() <= 0)
|
|
|
{
|
|
|
onMessageBox(QMessageBox::Warning, tr("<EFBFBD><EFBFBD>ʾ"), tr("û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>²<EFBFBD>ѯ"));
|
|
|
return;
|
|
|
}
|
|
|
QString filename = QString("Data_%1.csv").arg(QDateTime::currentDateTime().toString("yyyy_MM_dd"));
|
|
|
QString fileTitle = tr("<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><EFBFBD>");
|
|
|
QFileDialog *fileDialog = new QFileDialog(NULL, fileTitle, filename);
|
|
|
fileDialog->setWindowTitle("Save As");
|
|
|
fileDialog->setAcceptMode(QFileDialog::AcceptSave);
|
|
|
fileDialog->setFileMode(QFileDialog::AnyFile);
|
|
|
fileDialog->setViewMode(QFileDialog::Detail);
|
|
|
fileDialog->setGeometry(10, 30, 300, 200);
|
|
|
fileDialog->setDirectory(".");
|
|
|
fileDialog->setNameFilter("Execl(*.csv)");
|
|
|
|
|
|
if (fileDialog->exec() == QDialog::Accepted)
|
|
|
{
|
|
|
QString path = fileDialog->selectedFiles()[0];
|
|
|
if (SaveDataToCSV(path, m_CountNumber))
|
|
|
onMessageBox(QMessageBox::Information, tr("<EFBFBD><EFBFBD>ʾ"), tr("<EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
|
|
|
//QString strMsg = tr("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%1-%2<><32>ͳ<EFBFBD><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>").arg(ui.label_Time1_Count->text()).arg(ui.label_Time2_Count->text());
|
|
|
//SaveLog(strMsg);
|
|
|
}
|
|
|
if (fileDialog) {
|
|
|
delete fileDialog;
|
|
|
fileDialog = NULL;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
bool ModeCountDlg::onMessageBox(QMessageBox::Icon ntype, QString strTitle, QString strAtl, int onlyOK)
|
|
|
{
|
|
|
QMessageBox::StandardButton button = QMessageBox::Ok;
|
|
|
|
|
|
if (onlyOK == 1)
|
|
|
button = QMessageBox::Cancel;
|
|
|
QMessageBox infobox(ntype, strTitle, strAtl, QMessageBox::Ok | button, NULL);
|
|
|
infobox.setWindowIcon(QIcon(":/image/leaper"));
|
|
|
infobox.setButtonText(QMessageBox::Ok, tr("ȷ<EFBFBD><EFBFBD>"));
|
|
|
infobox.setButtonText(QMessageBox::Cancel, tr("ȡ<EFBFBD><EFBFBD>"));
|
|
|
return (infobox.exec() == QMessageBox::Ok);
|
|
|
}
|
|
|
|
|
|
bool ModeCountDlg::SaveDataToCSV(QString filePath, QMap<QString, int> &m_mapTable)
|
|
|
{
|
|
|
QFile file(filePath);
|
|
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append))// <><D7B7>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
return false;
|
|
|
QTextStream out(&file);
|
|
|
QString tableData;
|
|
|
QString m_startStr = m_startDate_Count.toString("yyyy-MM-dd ") + m_startTime.toString("hh:mm:ss");
|
|
|
QString m_endStr = m_endDate_Count.toString("yyyy-MM-dd ") + m_endTime.toString("hh:mm:ss");
|
|
|
out << tr("<EFBFBD><EFBFBD>%1<><31>%2ͳ<32>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>").arg(m_startStr).arg(m_endStr) << "\n";
|
|
|
out << tr("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>") << "," << tr("<EFBFBD>ͺ<EFBFBD>") << "," << tr("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>") << "\n";
|
|
|
int index = 1;
|
|
|
int sum = 0;
|
|
|
for (QMap<QString, int>::iterator its = m_mapTable.begin(); its != m_mapTable.end(); ++its)
|
|
|
{
|
|
|
out << (index++) << ",";
|
|
|
tableData = its.key();
|
|
|
out << tableData << ",";
|
|
|
out << QString::number(m_mapTable[tableData]) << ",";
|
|
|
sum += m_mapTable[tableData];
|
|
|
out << "\n";
|
|
|
}
|
|
|
if (!m_mapTable.contains(QString("NG")))
|
|
|
{
|
|
|
out << (index++) << "," << QString("NG") << "," << 0 << "\n";
|
|
|
}
|
|
|
out << (index++) << "," << tr("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>") << "," << QString::number(sum) << "\n";
|
|
|
out << tr("ʱ<EFBFBD><EFBFBD>:") << "," << QDateTime::currentDateTime().toString("yyyy-MM-dd") << "," << QDateTime::currentDateTime().toString("hh:mm:ss") << "\n";
|
|
|
out << tr("<EFBFBD>û<EFBFBD>:") << "," << "username" << "," << "\n";
|
|
|
file.close();
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
Q_SLOT void ModeCountDlg::SlotCombox(int index)
|
|
|
{
|
|
|
QObject *strobj = sender();
|
|
|
QString objname = strobj->objectName();
|
|
|
if ("comboBox_Banci_Calculate" == objname)
|
|
|
{
|
|
|
QString str = ui.comboBox_Banci_Calculate->currentText();
|
|
|
|
|
|
if (m_Totaltime.contains(str))
|
|
|
{
|
|
|
if (m_Totaltime.value(str).m_startTime >= m_Totaltime.value(str).m_endTime)
|
|
|
{
|
|
|
QDate m = m_endDate_Count.date();
|
|
|
m = m.addDays(-1);
|
|
|
QString strdata = m.toString("yyyy-MM-dd");
|
|
|
m_startDate_Count.setDate(m);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
m_startDate_Count.setDate(m_endDate_Count.date());
|
|
|
}
|
|
|
if (m_startDate_Count.date() > m_endDate_Count.date())
|
|
|
m_startDate_Count.setDate(m_endDate_Count.date());
|
|
|
|
|
|
m_startDate_Count.setTime(m_Totaltime.value(str).m_startTime);//
|
|
|
m_endDate_Count.setTime(m_Totaltime.value(str).m_endTime);//
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (str == tr("ȫ<EFBFBD><EFBFBD>"))
|
|
|
{
|
|
|
QString strTime = nstartTime.toString("hh:mm:ss");
|
|
|
if (m_startDate_Count.date() > m_endDate_Count.date())
|
|
|
m_startDate_Count.setDate(m_endDate_Count.date());
|
|
|
|
|
|
m_startDate_Count.setTime(m_startTime);
|
|
|
m_endDate_Count.setTime(nEndTime);
|
|
|
QString strStart = m_startDate_Count.toString("yyyy-MM-dd hh:mm:ss");
|
|
|
}
|
|
|
}
|
|
|
ui.label_Time1_Count->setText(m_startDate_Count.toString("yyyy-MM-dd hh:mm:ss"));
|
|
|
ui.label_Time2_Count->setText(m_endDate_Count.toString("yyyy-MM-dd hh:mm:ss"));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Q_SLOT void ModeCountDlg::onSaveCSVDone(int)
|
|
|
{
|
|
|
emit(sgFinish());
|
|
|
}
|