You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1423 lines
47 KiB
C++
1423 lines
47 KiB
C++
#include "lpReport.h"
|
|
#include "qtimedlg.h"
|
|
#include <QSqlQuery>
|
|
#include <QFileDialog>
|
|
#include <QTextStream>
|
|
#include "QProgressDialog"
|
|
#include "qsavecsvthread.h"
|
|
#include "checkthread.h"
|
|
#include "QCompleter"
|
|
#include "qreportwidget.h"
|
|
#include <QDebug>
|
|
#include "ModelDB.h"
|
|
|
|
#pragma execution_character_set("utf-8")
|
|
|
|
#define WHEEL_PIC_SIZE 150
|
|
enum EM_TYPE_TIME
|
|
{
|
|
em_Time_Year = 1,
|
|
em_Time_Moth,
|
|
em_Time_Day
|
|
};
|
|
#define _QSQLITE_WHEELHUBWF_NAME "wheelhubwf.db"
|
|
#define WHEEL_DB_FILE "\\pattern\\modelTemplate.db"
|
|
|
|
lpReport::lpReport(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
{
|
|
//加载语言设置
|
|
QSettings languageSetting("hubdetect.ini", QSettings::IniFormat);
|
|
QString strLanguage = languageSetting.value("language", "Chinese").toString();
|
|
SetLanguage(strLanguage);
|
|
|
|
qRegisterMetaType<QSqlQuery>("QSqlQuery");
|
|
ui.setupUi(this);
|
|
onInitUI();
|
|
QString strDbPath = QApplication::applicationDirPath() + "\\" + _QSQLITE_WHEELHUBWF_NAME;
|
|
m_pDb = new DetectDataDB(strDbPath);
|
|
m_pDb->InitDatabase();
|
|
m_pDb->ReadOutTimeData(m_Totaltime);
|
|
|
|
QString strModelPath = QApplication::applicationDirPath() + "\\" + WHEEL_DB_FILE;
|
|
m_pModeDB = new ModelDB(strModelPath);
|
|
m_pModeDB->InitDatabase();
|
|
QStringList strList = m_pModeDB->ReadAllModes();
|
|
|
|
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);
|
|
nstartTime.setHMS(0, 0, 0);
|
|
nEndTime.setHMS(23, 59, 59);
|
|
m_tableModel = new QStandardItemModel;
|
|
|
|
m_WorkDB = new WorkForDB;
|
|
m_WorkDB->moveToThread(&m_Workthread);
|
|
m_WorkDB->setDB(m_pDb);
|
|
connect(&m_Workthread, &QThread::finished, m_WorkDB, &QObject::deleteLater);
|
|
connect(this, &lpReport::operate, m_WorkDB, &WorkForDB::doWork);
|
|
connect(m_WorkDB, &WorkForDB::resultReady, this, &lpReport::handleResults);
|
|
m_Workthread.start();
|
|
qDebug() << "start thread m_Workthread";
|
|
|
|
m_WorkCount = new CountData;
|
|
m_WorkCount->moveToThread(&m_WorkThreadCount);
|
|
m_WorkCount->setDB(m_pDb);
|
|
connect(&m_WorkThreadCount, &QThread::finished, m_WorkCount, &QObject::deleteLater);
|
|
connect(this, &lpReport::operateCount, m_WorkCount, &CountData::doWork);
|
|
connect(m_WorkCount, &CountData::resultReady, this, &lpReport::handleResultsCount);
|
|
connect(m_WorkCount, SIGNAL(sgShowMsg(QString)), this, SLOT(onShowMessage(QString)));
|
|
connect(m_WorkCount, &CountData::sgShowProgress, this, &lpReport::onProgressForTsk);
|
|
m_WorkThreadCount.start();
|
|
qDebug() << "start thread m_WorkThreadCount";
|
|
|
|
m_WorkHistory = new CheckData;
|
|
m_WorkHistory->moveToThread(&m_WorkThreadCheckHistory);
|
|
m_WorkHistory->setDB(m_pDb);
|
|
connect(&m_WorkThreadCheckHistory, &QThread::finished, m_WorkHistory, &QObject::deleteLater);
|
|
connect(this, &lpReport::operateHistory, m_WorkHistory, &CheckData::doWork);
|
|
connect(m_WorkHistory, &CheckData::resultReady, this, &lpReport::handleResultsHistory);
|
|
connect(m_WorkHistory, &CheckData::sgShowProgress, this, &lpReport::onProgressForTsk);
|
|
m_WorkThreadCheckHistory.start();
|
|
qDebug() << "start thread m_WorkThreadCheckHistory";
|
|
|
|
m_Progressdlg.setWindowModality(Qt::ApplicationModal);
|
|
m_Progressdlg.setWindowIcon(QIcon(":/image/leaper"));
|
|
m_IsRunCountTsk = false;
|
|
ui.scrollArea->setWidget(m_countwidget);
|
|
|
|
InitUIParam();
|
|
SetModelNames(strList);
|
|
|
|
setWindowTitle(tr("数据记录查看"));
|
|
|
|
setWindowIcon(QIcon(":/lpReport/Resources/Log.png"));
|
|
}
|
|
|
|
lpReport::~lpReport()
|
|
{
|
|
if (m_Workthread.isRunning())
|
|
{
|
|
qDebug() << "delete m_Workthread";
|
|
m_Workthread.quit();
|
|
m_Workthread.wait(50);
|
|
qDebug() << "delete m_Workthread end";
|
|
}
|
|
if (m_WorkThreadCount.isRunning())
|
|
{
|
|
qDebug() << "delete m_WorkThreadCount";
|
|
m_WorkThreadCount.quit();
|
|
m_WorkThreadCount.wait(50);
|
|
qDebug() << "delete m_WorkThreadCount end";
|
|
}
|
|
if (m_WorkThreadCheckHistory.isRunning())
|
|
{
|
|
qDebug() << "delete m_WorkThreadCheckHistory";
|
|
m_WorkThreadCheckHistory.quit();
|
|
m_WorkThreadCheckHistory.wait(50);
|
|
qDebug() << "delete m_WorkThreadCheckHistory end";
|
|
}
|
|
if (m_tableWarnModel) {
|
|
delete m_tableWarnModel;
|
|
m_tableWarnModel = NULL;
|
|
}
|
|
if (m_tableModel) {
|
|
delete m_tableModel;
|
|
m_tableModel = NULL;
|
|
}
|
|
if (_pCompleter) {
|
|
delete _pCompleter;
|
|
_pCompleter = NULL;
|
|
}
|
|
if (m_countwidget)
|
|
{
|
|
delete m_countwidget;
|
|
m_countwidget = NULL;
|
|
}
|
|
|
|
}
|
|
|
|
void lpReport::onInitUI()
|
|
{
|
|
connect(ui.pushButton_Set1_Warning, SIGNAL(clicked()), this, SLOT(SlotEditTime()));
|
|
connect(ui.pushButton_Set2_Warning, SIGNAL(clicked()), this, SLOT(SlotEditTime()));
|
|
connect(ui.pushButton_Set1_History, SIGNAL(clicked()), this, SLOT(SlotEditTime()));
|
|
connect(ui.pushButton_Set2_History, SIGNAL(clicked()), this, SLOT(SlotEditTime()));
|
|
connect(ui.pushButton_Set1_Count, SIGNAL(clicked()), this, SLOT(SlotEditTime()));
|
|
connect(ui.pushButton_Set2_Count, SIGNAL(clicked()), this, SLOT(SlotEditTime()));
|
|
|
|
connect(ui.pushButton_Checkdata, SIGNAL(clicked()), this, SLOT(onCheckButton()));
|
|
connect(ui.pushButton_SaveHistory, SIGNAL(clicked()), this, SLOT(onCheckButton()));
|
|
connect(ui.pushButton_Wandring, SIGNAL(clicked()), this, SLOT(onCheckButton()));
|
|
connect(ui.pushButton_SaveWaring, SIGNAL(clicked()), this, SLOT(onCheckButton()));
|
|
connect(ui.pushButton_Checkdata_Calculate, SIGNAL(clicked()), this, SLOT(onCheckButton()));
|
|
connect(ui.pushButton_SaveCalculate, SIGNAL(clicked()), this, SLOT(onCheckButton()));
|
|
connect(this, SIGNAL(sgSetCurrentIndex(int)), ui.stackedWidget, SLOT(setCurrentIndex(int)));
|
|
connect(ui.comboBox_Banci_Calculate, SIGNAL(currentIndexChanged(int)), this, SLOT(SlotCombox(int)));
|
|
connect(ui.comboBox_Banci, SIGNAL(currentIndexChanged(int)), this, SLOT(SlotCombox(int)));
|
|
|
|
ui.comboBox_Model->setEditable(true);
|
|
|
|
connect(ui.Prev_checkShengchang, SIGNAL(clicked()), this, SLOT(onHistoryButton()));
|
|
connect(ui.Next_checkShengchang, SIGNAL(clicked()), this, SLOT(onHistoryButton()));
|
|
|
|
ui.LineNumber_checkShengchang->setText("50");
|
|
QValidator *validator = new QIntValidator(1, 9999, this);
|
|
ui.LineNumber_checkShengchang->setValidator(validator);
|
|
|
|
ui.showNum_Label_Checkdata->setText(tr("共显示%1条记录").arg(0));
|
|
ui.showPage_Label_Checkdata->setText(tr("第%1页 共%2页").arg(0).arg(0));
|
|
|
|
int nItenCount = ui.check_listWidget->count();
|
|
for (int nIndex = 0; nIndex < nItenCount; nIndex++)
|
|
{
|
|
QListWidgetItem *itenn = ui.check_listWidget->item(nIndex);
|
|
QSize s = itenn->sizeHint();
|
|
itenn->setSizeHint(QSize(s.width(), 45));
|
|
}
|
|
connect(ui.check_listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(onSetCurrentIndex(int)));
|
|
|
|
|
|
ui.LineNumber_log->setText("50");
|
|
QValidator *validatorlog = new QIntValidator(1, 9999, this);
|
|
ui.LineNumber_log->setValidator(validatorlog);
|
|
|
|
connect(ui.Prev_checklog, SIGNAL(clicked()), this, SLOT(onLogButton()));
|
|
connect(ui.Next_checklog, SIGNAL(clicked()), this, SLOT(onLogButton()));
|
|
|
|
ui.showPage_Label_Checkdata_2->setText(tr("第%1页 共%2页").arg(0).arg(0));
|
|
ui.showNum_Label_Checkdata_2->setText(tr("共显示%1条记录").arg(0));
|
|
}
|
|
|
|
void lpReport::timerEvent(QTimerEvent *event)
|
|
{
|
|
|
|
}
|
|
|
|
Q_SLOT void lpReport::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);
|
|
}
|
|
}
|
|
else if (str == "pushButton_Set1_Warning")
|
|
{
|
|
QTimeDlg dlg;
|
|
dlg.SetDateTime(m_startDate_Warning);
|
|
if (dlg.exec() == QDialog::Accepted)
|
|
{
|
|
dlg.GetDateTime(m_startDate_Warning);
|
|
QString m_endLast = m_startDate_Warning.toString("yyyy-MM-dd hh:mm:ss");
|
|
ui.label_Time1_warning->setText(m_endLast);
|
|
}
|
|
}
|
|
else if (str == "pushButton_Set2_Warning")
|
|
{
|
|
QTimeDlg dlg;
|
|
dlg.SetDateTime(m_endDate_Warning);
|
|
if (dlg.exec() == QDialog::Accepted)
|
|
{
|
|
dlg.GetDateTime(m_endDate_Warning);
|
|
QString m_endLast = m_endDate_Warning.toString("yyyy-MM-dd hh:mm:ss");
|
|
ui.label_Time2_warning->setText(m_endLast);
|
|
}
|
|
}
|
|
else if (str == "pushButton_Set1_History")
|
|
{
|
|
QTimeDlg dlg(NULL);
|
|
dlg.SetDateTime(m_startDate_History);
|
|
if (dlg.exec() == QDialog::Accepted)
|
|
{
|
|
dlg.GetDateTime(m_startDate_History);
|
|
QString m_endLast = m_startDate_History.toString("yyyy-MM-dd hh:mm:ss");
|
|
ui.label_Time1_History->setText(m_endLast);
|
|
}
|
|
}
|
|
else if (str == "pushButton_Set2_History")
|
|
{
|
|
QTimeDlg dlg;
|
|
dlg.SetDateTime(m_endDate_History);
|
|
if (dlg.exec() == QDialog::Accepted)
|
|
{
|
|
dlg.GetDateTime(m_endDate_History);
|
|
QString m_endLast = m_endDate_History.toString("yyyy-MM-dd hh:mm:ss");
|
|
ui.label_Time2_History->setText(m_endLast);
|
|
}
|
|
}
|
|
}
|
|
|
|
Q_SLOT void lpReport::onCheckButton()
|
|
{
|
|
QObject *obj = sender();
|
|
QString str = obj->objectName();
|
|
if ("pushButton_Checkdata" == str)//查询生产数据
|
|
{/*这里需要做数据分页显示 减少内存泄露*/
|
|
static bool checkflags = false;
|
|
if (checkflags == false)
|
|
{
|
|
checkflags = true;
|
|
QString strBanci = ui.comboBox_Banci->currentText();
|
|
QString modelName = ui.comboBox_Model->currentText();
|
|
if (m_Totaltime.contains(strBanci))
|
|
{
|
|
if (m_startDate_History.date() > m_endDate_History.date())
|
|
{
|
|
if (m_Totaltime.value(strBanci).m_startTime > m_Totaltime.value(strBanci).m_endTime)
|
|
{
|
|
onMessageBox(QMessageBox::Information, tr("提示"), tr("您选择的班次时间是隔夜的,请您重新选择一下当前查询的日期,再查询"));
|
|
checkflags = false;
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
onMessageBox(QMessageBox::Information, tr("提示"), tr("您选择的日期不合理,请您重新选择一下当前查询的日期,再查询"));
|
|
checkflags = false;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (m_startDate_History.date() > m_endDate_History.date())
|
|
{
|
|
onMessageBox(QMessageBox::Information, tr("提示"), tr("您选择的日期不合理,请您重新选择一下当前查询的日期,再查询"));
|
|
checkflags = false;
|
|
return;
|
|
}
|
|
}
|
|
|
|
QString m_strLast = ui.label_Time1_History->text();
|
|
QString m_endLast = ui.label_Time2_History->text();
|
|
QString strMsg = tr("查询了%1-%2的生产数据").arg(m_strLast).arg(m_endLast);
|
|
SaveLog(strMsg);
|
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
|
QFont font;
|
|
font.setPixelSize(14);
|
|
ui.label_Tab2_Title->setFont(font);
|
|
QString m_Title = tr("起始时间:%1 到 结束时间:%2 的历史记录").arg(m_strLast).arg(m_endLast);
|
|
ui.label_Tab2_Title->setText(m_Title);
|
|
if (modelName == tr("全部"))
|
|
CheckDataHistoryByDate(m_strLast, m_endLast, "*");
|
|
else
|
|
CheckDataHistoryByDate(m_strLast, m_endLast, modelName);
|
|
QApplication::restoreOverrideCursor();
|
|
checkflags = false;
|
|
}
|
|
else
|
|
{
|
|
onMessageBox(QMessageBox::Information, tr("提示"), tr("正在查询数据,请稍后"));
|
|
}
|
|
}
|
|
else if ("pushButton_SaveHistory" == str)
|
|
{
|
|
if (m_tableModel == NULL)
|
|
return;
|
|
if (m_tableModel->rowCount() <= 0)
|
|
{
|
|
onMessageBox(QMessageBox::Warning, tr("提示"), tr("没有数据,请重新查询"));
|
|
return;
|
|
}
|
|
|
|
QString filename = QString("History_%1.csv").arg(QDateTime::currentDateTime().toString("yyyy_MM_dd"));
|
|
QString fileTitle = tr("请选择保存文件的路径");
|
|
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];
|
|
|
|
QString strString = getHistoryCheckString();
|
|
QSaveCSVThread *workerThread = new QSaveCSVThread(this);
|
|
workerThread->setInform(ui.label_Tab2_Title->text(), "username");
|
|
workerThread->setCheckStr(m_pDb, strString, path, 0);
|
|
connect(workerThread, SIGNAL(resultReady(int)), this, SLOT(onSaveCSVDone(int)));
|
|
connect(workerThread, &QSaveCSVThread::finished, workerThread, &QObject::deleteLater);
|
|
workerThread->start();
|
|
|
|
onEventLoop(tr("正在导出数据,请稍等"));
|
|
|
|
QString strMsg = tr("导出了%1-%2的生产数据").arg(ui.label_Time1_History->text()).arg(ui.label_Time2_History->text());
|
|
SaveLog(strMsg);
|
|
onMessageBox(QMessageBox::Information, tr("提示"), tr("数据导出完成"));
|
|
}
|
|
if (fileDialog) {
|
|
delete fileDialog;
|
|
fileDialog = NULL;
|
|
}
|
|
}
|
|
else if (str == "pushButton_Wandring")
|
|
{
|
|
static bool checkflags = false;
|
|
if (checkflags == false)
|
|
{
|
|
checkflags = true;
|
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
|
QString m_strLast = ui.label_Time1_warning->text();
|
|
QString m_endLast = ui.label_Time2_warning->text();
|
|
QString strMsg = tr("查询了%1-%2的日志数据").arg(m_strLast).arg(m_endLast);
|
|
QString strCombox = ui.comboBox_Wandring_Log->currentText();
|
|
int mType = 0;
|
|
if (strCombox == tr("使用记录查询")) {
|
|
mType = (int)emTypeUseState;
|
|
}
|
|
else if (strCombox == tr("报警记录查询")) {
|
|
mType = (int)emTypeWaring;
|
|
}
|
|
else if (strCombox == tr("运行状态查询")) {
|
|
mType = (int)emTypeRunState;
|
|
}
|
|
SaveLog(strMsg);
|
|
QFont font;
|
|
font.setPixelSize(14);
|
|
ui.label_Tab3_Title->setFont(font);
|
|
QString m_Title = tr("起始时间:%1 到 结束时间:%2 的历史记录").arg(m_strLast).arg(m_endLast);
|
|
ui.label_Tab3_Title->setText(m_Title);
|
|
|
|
CheckDataWarningByDate(mType, m_strLast, m_endLast);
|
|
QApplication::restoreOverrideCursor();
|
|
checkflags = false;
|
|
}
|
|
else
|
|
{
|
|
onMessageBox(QMessageBox::Information, tr("提示"), tr("正在查询数据,请稍后"));
|
|
}
|
|
}
|
|
else if (str == "pushButton_SaveWaring")
|
|
{
|
|
if (m_tableWarnModel == NULL)
|
|
{
|
|
onMessageBox(QMessageBox::Warning, tr("提示"), tr("没有数据,请重新查询"));
|
|
return;
|
|
}
|
|
if (m_tableWarnModel->rowCount() <= 0)
|
|
{
|
|
onMessageBox(QMessageBox::Warning, tr("提示"), tr("没有数据,请重新查询"));
|
|
return;
|
|
}
|
|
QString filename = QString("WarnMessage_%1.csv").arg(QDateTime::currentDateTime().toString("yyyy_MM_dd"));
|
|
QString fileTitle = tr("请选择保存文件的路径");
|
|
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];
|
|
QString strString = getLogCheckString();
|
|
QSaveCSVThread *workerThread = new QSaveCSVThread(this);
|
|
workerThread->setInform(ui.label_Tab3_Title->text(), "username");
|
|
workerThread->setCheckStr(m_pDb, strString, path, 1);
|
|
connect(workerThread, SIGNAL(resultReady(int)), this, SLOT(onSaveCSVDone(int)));
|
|
connect(workerThread, &QSaveCSVThread::finished, workerThread, &QObject::deleteLater);
|
|
workerThread->start();
|
|
|
|
onEventLoop(tr("正在导出数据,请稍等"));
|
|
|
|
QString strMsg = tr("导出了%1-%2的日志数据").arg(ui.label_Time1_warning->text()).arg(ui.label_Time2_warning->text());
|
|
SaveLog(strMsg);
|
|
onMessageBox(QMessageBox::Information, tr("提示"), tr("数据导出完成"));
|
|
}
|
|
if (fileDialog) {
|
|
delete fileDialog;
|
|
fileDialog = NULL;
|
|
}
|
|
}
|
|
else if ("pushButton_Checkdata_Calculate" == str)
|
|
{
|
|
static bool checkflags = false;
|
|
if (checkflags == false)
|
|
{
|
|
checkflags = true;
|
|
QString strBanci = ui.comboBox_Banci_Calculate->currentText();
|
|
QString modelName = ui.comboBox_Model->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("提示"), tr("您选择的班次时间是隔夜的,请您重新选择一下当前查询的日期,再查询"));
|
|
checkflags = false;
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
onMessageBox(QMessageBox::Information, tr("提示"), tr("您选择的日期不合理,请您重新起始日期,再查询"));
|
|
checkflags = false;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (m_startDate_Count.date() > m_endDate_Count.date())
|
|
{
|
|
onMessageBox(QMessageBox::Information, tr("提示"), tr("您选择的日期不合理,请您重新选择一下当前查询的日期,再查询"));
|
|
checkflags = false;
|
|
return;
|
|
}
|
|
}
|
|
QString m_strLast = ui.label_Time1_Count->text();
|
|
QString m_endLast = ui.label_Time2_Count->text();
|
|
QString strMsg = tr("查询了%1-%2的统计数据").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("提示"), tr("正在查询数据,请稍后"));
|
|
}
|
|
}
|
|
else if ("pushButton_SaveCalculate" == str)
|
|
{
|
|
if (m_CountNumber.size() <= 0)
|
|
{
|
|
onMessageBox(QMessageBox::Warning, tr("提示"), tr("没有数据,请重新查询"));
|
|
return;
|
|
}
|
|
QString filename = QString("Data_%1.csv").arg(QDateTime::currentDateTime().toString("yyyy_MM_dd"));
|
|
QString fileTitle = tr("请选择保存文件的路径");
|
|
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("提示"), tr("数据导出完成"));
|
|
QString strMsg = tr("导出了%1-%2的统计数据").arg(ui.label_Time1_Count->text()).arg(ui.label_Time2_Count->text());
|
|
SaveLog(strMsg);
|
|
}
|
|
if (fileDialog) {
|
|
delete fileDialog;
|
|
fileDialog = NULL;
|
|
}
|
|
}
|
|
}
|
|
|
|
bool lpReport::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("确认"));
|
|
infobox.setButtonText(QMessageBox::Cancel, tr("取消"));
|
|
return (infobox.exec() == QMessageBox::Ok);
|
|
}
|
|
|
|
void lpReport::CheckDataHistoryByDate(QString m_strLast, QString m_endLast, QString modelname)
|
|
{
|
|
QSqlQuery sql;
|
|
QVariantMap m_Value;
|
|
m_Value.insert(_CHECK_TYPE_, EMT_CHECK_BY_NAME);
|
|
m_Value.insert(_CHECK_TIME1_, m_strLast);
|
|
m_Value.insert(_CHECK_TIME2_, m_endLast);
|
|
m_Value.insert(_CHECK_NAME_, modelname);
|
|
m_Value.insert(_CHECK_COUNT_, 1);
|
|
if (modelname == "*")
|
|
m_Value.insert(_CHECK_TYPE_, EMT_CHECK_BY_SAE);
|
|
else
|
|
m_Value.insert(_CHECK_TYPE_, EMT_CHECK_BY_NAME);
|
|
QString strString;
|
|
strString = m_pDb->genCheckStr(m_Value);
|
|
int nlimit = ui.LineNumber_checkShengchang->text().toInt();
|
|
if (nlimit <= 0)
|
|
{
|
|
nlimit = 10;
|
|
ui.LineNumber_checkShengchang->setText("10");
|
|
}
|
|
m_totlaNum = 0;
|
|
m_PrevNum = 0;
|
|
QString strStringcheck;
|
|
if (modelname == "*")
|
|
strStringcheck = QString("select * from wftable where time >'%1' and time <'%2' LIMIT %4 OFFSET %5").arg(m_strLast).arg(m_endLast).arg(nlimit).arg(m_PrevNum);
|
|
else
|
|
strStringcheck = QString("select * from wftable where time >'%1' and time <'%2' and model = '%3' LIMIT %4 OFFSET %5").arg(m_strLast).arg(m_endLast).arg(modelname).arg(nlimit).arg(m_PrevNum);
|
|
QVariantMap m_mapVarite;
|
|
m_mapVarite.insert("SqlCount", strString);
|
|
m_mapVarite.insert("SqlCheck", strStringcheck);
|
|
m_mapVarite.insert("limit", nlimit);
|
|
emit operateHistory(m_mapVarite);
|
|
|
|
}
|
|
|
|
bool lpReport::SaveDataToCSV(QString filePath, QMap<QString, int> &m_mapTable)
|
|
{
|
|
QFile file(filePath);
|
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append))// 追加写入数据
|
|
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("从%1到%2统计的数据如下").arg(m_startStr).arg(m_endStr) << "\n";
|
|
out << tr("序号") << "," << tr("型号") << "," << tr("数量") << "\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("总数") << "," << QString::number(sum) << "\n";
|
|
out << tr("时间:") << "," << QDateTime::currentDateTime().toString("yyyy-MM-dd") << "," << QDateTime::currentDateTime().toString("hh:mm:ss") << "\n";
|
|
//out << tr("用户:") << "," << "username" << "," << "\n";
|
|
file.close();
|
|
return true;
|
|
}
|
|
|
|
void lpReport::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("查询进度"));
|
|
progress.setWindowIcon(QIcon(":/image/leaper"));
|
|
progress.setLabelText(tr("数据查询中,请稍后....."));
|
|
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);
|
|
}
|
|
|
|
void lpReport::onEventLoop(QString strMsg)
|
|
{
|
|
WaitingDialog dlg;
|
|
dlg.setWindowModality(Qt::ApplicationModal);
|
|
dlg.setWindowIcon(QIcon(":/image/leaper"));
|
|
dlg.setWindowTitle(strMsg);
|
|
dlg.Start(50, 150),
|
|
dlg.show();
|
|
QEventLoop eventloop;
|
|
connect(this, SIGNAL(sgFinish()), &eventloop, SLOT(quit()));
|
|
eventloop.exec();
|
|
}
|
|
|
|
|
|
void lpReport::SaveLog(QString str)
|
|
{
|
|
// QString strMsg = m_pCtrl->getUserName() + ":" + str;
|
|
// m_pCtrl->addLog(strMsg, emTypeUseState);
|
|
}
|
|
|
|
QString lpReport::getHistoryCheckString()
|
|
{
|
|
QString m_strLast = ui.label_Time1_History->text();
|
|
QString m_endLast = ui.label_Time2_History->text();
|
|
QString modelName = ui.comboBox_Model->currentText();
|
|
QString strString;
|
|
if (modelName == tr("全部"))
|
|
strString = QString("select * from wftable where time >'%1' and time <'%2'").arg(m_strLast).arg(m_endLast);
|
|
else
|
|
strString = QString("select * from wftable where time >'%1' and time <'%2' and model = '%3'").arg(m_strLast).arg(m_endLast).arg(modelName);
|
|
return strString;
|
|
}
|
|
|
|
Q_SLOT void lpReport::onHistoryButton()
|
|
{
|
|
QString strObj = sender()->objectName();
|
|
if ("Prev_checkShengchang" == strObj) {
|
|
|
|
if (m_PrevNum <= 0)
|
|
return;
|
|
int limitNum = ui.LineNumber_checkShengchang->text().toInt();
|
|
if (limitNum <= 0)
|
|
{
|
|
limitNum = 10;
|
|
ui.LineNumber_checkShengchang->setText("10");
|
|
}
|
|
QString strString = getHistoryCheckString();
|
|
m_PrevNum -= limitNum;
|
|
if (m_PrevNum <= 0)
|
|
m_PrevNum = 0;
|
|
strString = strString + QString(" LIMIT %1 OFFSET %2").arg(limitNum).arg(m_PrevNum);
|
|
|
|
/*启用线程查询数据 减少界面卡顿*/
|
|
CheckThread *workerThread = new CheckThread(this);
|
|
workerThread->setCheckStr(m_pDb, strString);
|
|
connect(workerThread, SIGNAL(resultReady(QSqlQuery)), this, SLOT(onUpdateTableViewShow(QSqlQuery)));
|
|
connect(workerThread, &CheckThread::finished, workerThread, &QObject::deleteLater);
|
|
workerThread->start();
|
|
|
|
m_totalPage = (m_totlaNum / limitNum);
|
|
m_page = ((m_PrevNum) / limitNum) + 1;
|
|
ui.showPage_Label_Checkdata->setText(tr("第%1页 共%2页").arg(m_page).arg(m_totalPage + 1));
|
|
if (m_PrevNum <= 0)
|
|
{
|
|
m_PrevNum = 0;
|
|
ui.Prev_checkShengchang->setDisabled(true);
|
|
}
|
|
ui.Next_checkShengchang->setDisabled(false);
|
|
}
|
|
else if ("Next_checkShengchang" == strObj) {
|
|
if (m_PrevNum >= m_totlaNum)
|
|
return;
|
|
int limitNum = ui.LineNumber_checkShengchang->text().toInt();
|
|
if (limitNum <= 0)
|
|
{
|
|
limitNum = 10;
|
|
ui.LineNumber_checkShengchang->setText("10");
|
|
}
|
|
m_PrevNum += limitNum;
|
|
if (m_PrevNum >= m_totlaNum)
|
|
m_PrevNum = m_totlaNum - limitNum;
|
|
QString strString = getHistoryCheckString();
|
|
strString = strString + QString(" LIMIT %1 OFFSET %2").arg(limitNum).arg(m_PrevNum);
|
|
|
|
/*启用线程查询数据 减少界面卡顿*/
|
|
CheckThread *workerThread = new CheckThread(this);
|
|
workerThread->setCheckStr(m_pDb, strString);
|
|
connect(workerThread, SIGNAL(resultReady(QSqlQuery)), this, SLOT(onUpdateTableViewShow(QSqlQuery)));
|
|
connect(workerThread, &CheckThread::finished, workerThread, &QObject::deleteLater);
|
|
workerThread->start();
|
|
|
|
m_totalPage = (m_totlaNum / limitNum);
|
|
m_page = (m_PrevNum + limitNum) / limitNum;
|
|
ui.showPage_Label_Checkdata->setText(tr("第%1页 共%2页").arg(m_page).arg(m_totalPage + 1));
|
|
if ((m_PrevNum + limitNum) >= m_totlaNum)
|
|
{
|
|
m_PrevNum = m_totlaNum;
|
|
ui.Next_checkShengchang->setDisabled(true);
|
|
}
|
|
ui.Prev_checkShengchang->setDisabled(false);
|
|
}
|
|
}
|
|
|
|
void lpReport::cleanHistorycal()
|
|
{
|
|
m_PrevNum = 0;
|
|
m_NextNum = 0;
|
|
m_totlaNum = 0;
|
|
m_page = 0;
|
|
m_totalPage = 0;
|
|
|
|
m_PrevNumlog = 0;
|
|
m_NextNumlog = 0;
|
|
m_totlaNumlog = 0;
|
|
m_pagelog = 0;
|
|
m_totalPagelog = 0;
|
|
|
|
ui.showNum_Label_Checkdata->setText(tr("共显示%1条记录").arg(0));
|
|
ui.showPage_Label_Checkdata->setText(tr("第%1页 共%2页").arg(0).arg(0));
|
|
ui.Prev_checkShengchang->setDisabled(true);
|
|
ui.Next_checkShengchang->setDisabled(true);
|
|
|
|
ui.showNum_Label_Checkdata_2->setText(tr("共显示%1条记录").arg(0));
|
|
ui.showPage_Label_Checkdata_2->setText(tr("第%1页 共%2页").arg(0).arg(0));
|
|
ui.Prev_checklog->setDisabled(true);
|
|
ui.Next_checklog->setDisabled(true);
|
|
}
|
|
|
|
Q_SLOT void lpReport::onSetCurrentIndex(int nIndex)
|
|
{
|
|
ui.label_Title->setText(ui.check_listWidget->item(nIndex)->data(0).toString());
|
|
emit(sgSetCurrentIndex(nIndex));
|
|
}
|
|
|
|
Q_SLOT void lpReport::onSaveCSVDone(int)
|
|
{
|
|
emit(sgFinish());
|
|
}
|
|
|
|
Q_SLOT void lpReport::handleResults(QString str)
|
|
{
|
|
//QString strMsg = "username" + ":" + tr("系统自动定时查询了一次数据完成,目标是清除超期的数据");
|
|
//m_pCtrl->addLog(strMsg, emTypeRunState);
|
|
onShowMessage(tr("系统自动进行清理完成"));
|
|
}
|
|
Q_SLOT void lpReport::onShowMessage(QString str)
|
|
{
|
|
// QPulpewidget *pw = new QPulpewidget();
|
|
// pw->showmessage(str);
|
|
// pw->setParent(m_pDlgCheck);
|
|
// connect(pw, SIGNAL(finished()), pw, SLOT(deleteLater()));//
|
|
}
|
|
|
|
|
|
Q_SLOT void lpReport::onProgressForTsk(QVariantMap m_map)
|
|
{
|
|
QString nType = m_map.value("Type").toString();
|
|
if (nType == "start")
|
|
{
|
|
QString strMsg = m_map.value("msg", tr("正在查询数据")).toString();
|
|
m_Progressdlg.setWindowTitle(strMsg);
|
|
m_Progressdlg.Start(50, 150),
|
|
m_Progressdlg.show();
|
|
}
|
|
else
|
|
{
|
|
m_Progressdlg.Stop();
|
|
m_Progressdlg.hide();
|
|
}
|
|
}
|
|
|
|
Q_SLOT void lpReport::handleResultsHistory(QVariantMap Mapstr, QSqlQuery sql)
|
|
{
|
|
updateModelShowHistory(sql);
|
|
QString m_strLast = ui.label_Time1_History->text();
|
|
QString m_endLast = ui.label_Time2_History->text();
|
|
m_totlaNum = Mapstr.value("sum").toInt();
|
|
int nlimit = Mapstr.value("limit").toInt();
|
|
int nIndex = Mapstr.value("nIndex").toInt();
|
|
QString m_Title = tr("起始时间:%1 到 结束时间:%2 的历史记录 共%3条").arg(m_strLast).arg(m_endLast).arg(m_totlaNum);
|
|
ui.label_Number->setText(QString::number(m_totlaNum));
|
|
QFont font;
|
|
font.setPixelSize(14);
|
|
font.setBold(true);
|
|
ui.label_Tab2_Title->setFont(font);
|
|
ui.label_Tab2_Title->setText(m_Title);
|
|
ui.Next_checkShengchang->setDisabled(false);
|
|
m_totalPage = (m_totlaNum / nlimit);
|
|
if (m_totlaNum > 0)
|
|
{
|
|
m_totalPage = m_totalPage + 1;
|
|
m_page = 1;
|
|
nIndex = m_totlaNum;
|
|
}
|
|
else
|
|
{
|
|
m_totlaNum = 0;
|
|
m_page = 0;
|
|
}
|
|
ui.showPage_Label_Checkdata->setText(tr("第%1页 共%2页").arg(m_page).arg(m_totalPage));
|
|
ui.showNum_Label_Checkdata->setText(tr("共显示%1条记录").arg(nIndex));
|
|
onShowMessage(tr("数据查询完成"));
|
|
}
|
|
|
|
Q_SLOT void lpReport::onShowMsg()
|
|
{
|
|
onMessageBox(QMessageBox::Information, tr("提示"), tr("操作已生效"));
|
|
}
|
|
|
|
Q_SLOT void lpReport::handleResultsCount(const QString &result, const QMap<QString, int> *p)
|
|
{
|
|
reportdlg->ClearData();
|
|
reportdlg->setTitle(tr("统计结果 "));
|
|
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("总数"), result.toInt(), true);
|
|
reportdlg->UpdateTableView();
|
|
onShowMessage(tr("统计完成"));
|
|
m_IsRunCountTsk = false;
|
|
if (p)
|
|
delete p;
|
|
}
|
|
|
|
Q_SLOT void lpReport::onLogButton()
|
|
{
|
|
QString strObj = sender()->objectName();
|
|
if ("Prev_checklog" == strObj) {
|
|
if (m_PrevNumlog <= 0)
|
|
return;
|
|
int limitNum = ui.LineNumber_log->text().toInt();
|
|
if (limitNum <= 0)
|
|
{
|
|
limitNum = 10;
|
|
ui.LineNumber_log->setText("10");
|
|
}
|
|
m_PrevNumlog -= limitNum;
|
|
if (m_PrevNumlog <= 0)
|
|
m_PrevNumlog = 0;
|
|
QString strString = getLogCheckString();
|
|
strString += QString(" LIMIT %1 OFFSET %2 ").arg(limitNum).arg(m_PrevNumlog);
|
|
/*启用线程查询数据 减少界面卡顿*/
|
|
CheckThread *workerThread = new CheckThread(this);
|
|
workerThread->setCheckStr(m_pDb, strString);
|
|
connect(workerThread, SIGNAL(resultReady(QSqlQuery)), this, SLOT(onUpdateTableViewShowlog(QSqlQuery)));
|
|
connect(workerThread, &CheckThread::finished, workerThread, &QObject::deleteLater);
|
|
workerThread->start();
|
|
|
|
m_totalPagelog = (m_totlaNumlog / limitNum);
|
|
m_pagelog = ((m_PrevNumlog) / limitNum) + 1;
|
|
ui.showPage_Label_Checkdata_2->setText(tr("第%1页 共%2页").arg(m_pagelog).arg(m_totalPagelog + 1));
|
|
if (m_PrevNumlog <= 0)
|
|
{
|
|
m_PrevNumlog = 0;
|
|
ui.Prev_checklog->setDisabled(true);
|
|
}
|
|
ui.Next_checklog->setDisabled(false);
|
|
}
|
|
else if ("Next_checklog" == strObj) {
|
|
if (m_PrevNumlog >= m_totlaNumlog)
|
|
return;
|
|
int limitNum = ui.LineNumber_log->text().toInt();
|
|
if (limitNum <= 0)
|
|
{
|
|
limitNum = 10;
|
|
ui.LineNumber_log->setText("10");
|
|
}
|
|
m_PrevNumlog += limitNum;
|
|
if (m_PrevNumlog >= m_totlaNumlog)
|
|
m_PrevNumlog = m_totlaNumlog - limitNum;
|
|
QString strString = getLogCheckString();
|
|
|
|
strString += QString(" LIMIT %1 OFFSET %2 ").arg(limitNum).arg(m_PrevNumlog);
|
|
/*启用线程查询数据 减少界面卡顿*/
|
|
CheckThread *workerThread = new CheckThread(this);
|
|
workerThread->setCheckStr(m_pDb, strString);
|
|
connect(workerThread, SIGNAL(resultReady(QSqlQuery)), this, SLOT(onUpdateTableViewShowlog(QSqlQuery)));
|
|
connect(workerThread, &CheckThread::finished, workerThread, &QObject::deleteLater);
|
|
workerThread->start();
|
|
|
|
m_totalPagelog = (m_totlaNumlog / limitNum);
|
|
m_pagelog = (m_PrevNumlog + limitNum) / limitNum;
|
|
ui.showPage_Label_Checkdata_2->setText(tr("第%1页 共%2页").arg(m_pagelog).arg(m_totalPagelog + 1));
|
|
if ((m_PrevNumlog + limitNum) >= m_totlaNumlog)
|
|
{
|
|
m_PrevNumlog = m_totlaNumlog;
|
|
ui.Next_checklog->setDisabled(true);
|
|
}
|
|
ui.Prev_checklog->setDisabled(false);
|
|
}
|
|
}
|
|
|
|
QString lpReport::getLogCheckString(int nCheckCount/*=0*/)
|
|
{
|
|
QString m_strLast = ui.label_Time1_warning->text();
|
|
QString m_endLast = ui.label_Time2_warning->text();
|
|
QString strCombox = ui.comboBox_Wandring_Log->currentText();
|
|
int mType = 0;
|
|
if (strCombox == tr("使用记录查询")) {
|
|
mType = (int)emTypeUseState;
|
|
}
|
|
else if (strCombox == tr("报警记录查询")) {
|
|
mType = (int)emTypeWaring;
|
|
}
|
|
else if (strCombox == tr("运行状态查询")) {
|
|
mType = (int)emTypeRunState;
|
|
}
|
|
QVariantMap m_vlaue;
|
|
m_vlaue.insert(_CHECK_TIME1_, m_strLast);
|
|
m_vlaue.insert(_CHECK_TIME2_, m_endLast);
|
|
m_vlaue.insert(_CHECK_LOGTYPE, mType);
|
|
m_vlaue.insert(_CHECK_TYPE_, EMT_CHECK_BY_LOG);
|
|
if (nCheckCount == 1)
|
|
m_vlaue.insert(_CHECK_COUNT_, 1);
|
|
return m_pDb->genCheckStr(m_vlaue);
|
|
}
|
|
|
|
Q_SLOT void lpReport::onUpdateTableViewShow(QSqlQuery sql)
|
|
{
|
|
updateModelShowHistory(sql);
|
|
}
|
|
|
|
void lpReport::updateModelShowHistory(QSqlQuery &sql)
|
|
{
|
|
QStandardItemModel *testmodel = new QStandardItemModel;
|
|
ui.tableView_checkShengchang->setModel(testmodel);//先将模型插入后在一次性显示 可以提高显示速率
|
|
ui.tableView_checkShengchang->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
ui.tableView_checkShengchang->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
ui.tableView_checkShengchang->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);//自适应行宽
|
|
ui.tableView_checkShengchang->horizontalHeader()->setMaximumHeight(100);
|
|
|
|
if (m_tableModel == NULL)
|
|
m_tableModel = new QStandardItemModel;
|
|
m_tableModel->clear();
|
|
ui.CheckDlg_label_Pic->clear();
|
|
m_tableModel->setHorizontalHeaderItem(0, new QStandardItem(tr("日期时间")));
|
|
m_tableModel->setHorizontalHeaderItem(1, new QStandardItem(tr("匹配型号")));
|
|
m_tableModel->setHorizontalHeaderItem(2, new QStandardItem(tr("相似度")));
|
|
m_tableModel->setHorizontalHeaderItem(3, new QStandardItem(tr("消耗时间s")));
|
|
m_tableModel->setHorizontalHeaderItem(4, new QStandardItem(tr("直径mm")));
|
|
m_tableModel->setHorizontalHeaderItem(5, new QStandardItem(tr("厚度mm")));
|
|
m_tableModel->setHorizontalHeaderItem(6, new QStandardItem(tr("缩略图")));
|
|
m_tableModel->setHorizontalHeaderItem(7, new QStandardItem(tr("uid")));
|
|
int nIndex = 0;
|
|
|
|
while (sql.next())
|
|
{
|
|
/*这里下面是统计查询到的通道对应的产品总数*/
|
|
int uid = sql.value("uid").toInt();
|
|
QString time = sql.value("time").toString();
|
|
QString model = sql.value("model").toString();
|
|
double dCorrelate = sql.value("correlate").toDouble();
|
|
QString correlate;
|
|
if (dCorrelate >= 1.7976931348623158e+308)
|
|
dCorrelate = 0;
|
|
correlate = QString::number(dCorrelate * 100, 'f', 3) + "%";
|
|
double dDetecttime = sql.value("detecttime").toDouble();
|
|
QString detecttime = QString::number(dDetecttime, 'f', 3);
|
|
double dDiameter = sql.value("diameter").toDouble();
|
|
QString diameter = QString::number(dDiameter, 'f', 3);
|
|
double dHight = sql.value("hight").toDouble();
|
|
QString hight = QString::number(dHight, 'f', 3);
|
|
QByteArray pic = sql.value("pic").toByteArray();
|
|
QImage img = QImage::fromData(pic);
|
|
QSize s = img.size();
|
|
QPixmap m_Pix = QPixmap::fromImage(img);
|
|
ui.CheckDlg_label_Pic->setPixmap(m_Pix.scaled(WHEEL_PIC_SIZE, WHEEL_PIC_SIZE));
|
|
m_tableModel->setItem(nIndex, 0, new QStandardItem(time));
|
|
m_tableModel->setItem(nIndex, 1, new QStandardItem(model));
|
|
m_tableModel->setItem(nIndex, 2, new QStandardItem(correlate));
|
|
m_tableModel->setItem(nIndex, 3, new QStandardItem(detecttime));
|
|
m_tableModel->setItem(nIndex, 4, new QStandardItem(diameter));
|
|
m_tableModel->setItem(nIndex, 5, new QStandardItem(hight));
|
|
m_tableModel->setItem(nIndex, 6, new QStandardItem(QIcon(m_Pix.scaled(50, 50)), ""));
|
|
m_tableModel->setItem(nIndex, 7, new QStandardItem(QString("%1").arg(uid)));
|
|
nIndex++;
|
|
}
|
|
ui.showNum_Label_Checkdata->setText(tr("共显示%1条记录").arg(nIndex));
|
|
ui.tableView_checkShengchang->setModel(m_tableModel);
|
|
ui.tableView_checkShengchang->hideColumn(7);
|
|
ui.tableView_checkShengchang->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
|
connect(ui.tableView_checkShengchang, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(onTableViewClick(QModelIndex)));
|
|
delete testmodel;
|
|
testmodel = NULL;
|
|
}
|
|
|
|
Q_SLOT void lpReport::onUpdateTableViewShowlog(QSqlQuery sql)
|
|
{
|
|
updateModelShowLog(sql);
|
|
}
|
|
|
|
Q_SLOT void lpReport::onResultCountlog(int nCount)
|
|
{
|
|
m_totlaNumlog = nCount;
|
|
emit(sgFinish());
|
|
}
|
|
|
|
Q_SLOT void lpReport::onResultCount(int nCount)
|
|
{
|
|
m_totlaNum = nCount;
|
|
emit(sgFinish());
|
|
}
|
|
|
|
void lpReport::CheckDataWarningByDate(int nType, QString m_strLast, QString m_endLast)
|
|
{
|
|
QString strString = getLogCheckString(1);
|
|
m_PrevNumlog = 0;
|
|
m_totlaNumlog = 0;
|
|
CheckThread *workThread = new CheckThread(this);
|
|
workThread->setCheckStr(m_pDb, strString);
|
|
workThread->setModelFlags(true);
|
|
connect(workThread, SIGNAL(resultCount(int)), this, SLOT(onResultCountlog(int)));
|
|
connect(workThread, &CheckThread::finished, workThread, &QObject::deleteLater);
|
|
workThread->start();
|
|
onEventLoop(tr("正在查询记录,请稍等"));
|
|
|
|
strString = getLogCheckString();
|
|
int nlimit = ui.LineNumber_log->text().toInt();
|
|
if (nlimit <= 0)
|
|
{
|
|
nlimit = 10;
|
|
ui.LineNumber_log->setText("10");
|
|
}
|
|
strString += QString(" LIMIT %1 OFFSET %2 ").arg(nlimit).arg(m_PrevNumlog);
|
|
CheckThread *workerThread = new CheckThread(this);
|
|
workerThread->setCheckStr(m_pDb, strString);
|
|
connect(workerThread, SIGNAL(resultReady(QSqlQuery)), this, SLOT(onUpdateTableViewShowlog(QSqlQuery)));
|
|
connect(workerThread, &CheckThread::finished, workerThread, &QObject::deleteLater);
|
|
workerThread->start();
|
|
|
|
QString m_Title = tr("从%1 到 %2 的记录 共%3条").arg(m_strLast).arg(m_endLast).arg(m_totlaNumlog);
|
|
QFont font;
|
|
font.setPixelSize(14);
|
|
font.setBold(true);
|
|
ui.label_Tab3_Title->setFont(font);
|
|
ui.label_Tab3_Title->setText(m_Title);
|
|
|
|
ui.Next_checklog->setDisabled(false);
|
|
m_totalPagelog = (m_totlaNumlog / nlimit);
|
|
if (m_totlaNumlog > 0)
|
|
{
|
|
m_totalPagelog = m_totalPagelog + 1;
|
|
m_pagelog = 1;
|
|
}
|
|
else
|
|
{
|
|
m_totlaNumlog = 0;
|
|
m_pagelog = 0;
|
|
}
|
|
ui.showPage_Label_Checkdata_2->setText(tr("第%1页 共%2页").arg(m_pagelog).arg(m_totalPagelog));
|
|
}
|
|
|
|
void lpReport::updateModelShowLog(QSqlQuery &sql)
|
|
{
|
|
QStandardItemModel *testmodel = new QStandardItemModel;
|
|
ui.tableView_TWarning->setModel(testmodel);//先将模型插入后在一次性显示 可以提高显示速率
|
|
ui.tableView_TWarning->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
ui.tableView_TWarning->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
ui.tableView_TWarning->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);//自适应行宽
|
|
if (m_tableWarnModel == NULL)
|
|
m_tableWarnModel = new QStandardItemModel;
|
|
m_tableWarnModel->clear();
|
|
m_tableWarnModel->setHorizontalHeaderItem(0, new QStandardItem(tr("时间")));
|
|
m_tableWarnModel->setHorizontalHeaderItem(1, new QStandardItem(tr("信息")));
|
|
|
|
int nIndex = 0;
|
|
while (sql.next())
|
|
{
|
|
/*这里下面是统计查询到的通道对应的产品总数*/
|
|
QString time = sql.value("time").toString();
|
|
QString message = sql.value("message").toString();
|
|
QString classd = sql.value("class").toString();
|
|
m_tableWarnModel->setItem(nIndex, 0, new QStandardItem(time));
|
|
m_tableWarnModel->setItem(nIndex, 1, new QStandardItem(message));
|
|
nIndex++;
|
|
}
|
|
ui.showNum_Label_Checkdata_2->setText(tr("共显示%1条记录").arg(nIndex));
|
|
ui.tableView_TWarning->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
|
ui.tableView_TWarning->setModel(m_tableWarnModel);
|
|
delete testmodel;
|
|
testmodel = NULL;
|
|
}
|
|
|
|
Q_SLOT void lpReport::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("全天"))
|
|
{
|
|
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"));
|
|
}
|
|
else if ("comboBox_Banci" == objname)
|
|
{
|
|
QString str = ui.comboBox_Banci->currentText();
|
|
|
|
if (m_Totaltime.contains(str))
|
|
{
|
|
if (m_Totaltime.value(str).m_startTime >= m_Totaltime.value(str).m_endTime)
|
|
{
|
|
QDate m = m_endDate_History.date();
|
|
m = m.addDays(-1);
|
|
QString strdata = m.toString("yyyy-MM-dd");
|
|
m_startDate_History.setDate(m);
|
|
}
|
|
else
|
|
{
|
|
m_startDate_History.setDate(m_endDate_History.date());
|
|
}
|
|
if (m_startDate_History.date() > m_endDate_History.date())
|
|
m_startDate_History.setDate(m_endDate_History.date());
|
|
m_startDate_History.setTime(m_Totaltime.value(str).m_startTime);//
|
|
m_endDate_History.setTime(m_Totaltime.value(str).m_endTime);//
|
|
}
|
|
else
|
|
{
|
|
if (str == tr("全天"))
|
|
{
|
|
QString strTime = nstartTime.toString("hh:mm:ss");
|
|
if (m_startDate_History.date() > m_endDate_History.date())
|
|
m_startDate_History.setDate(m_endDate_History.date());
|
|
m_startDate_History.setTime(m_startTime);
|
|
m_endDate_History.setTime(nEndTime);
|
|
QString strStart = m_startDate_History.toString("yyyy-MM-dd hh:mm:ss");
|
|
}
|
|
}
|
|
ui.label_Time1_History->setText(m_startDate_History.toString("yyyy-MM-dd hh:mm:ss"));
|
|
ui.label_Time2_History->setText(m_endDate_History.toString("yyyy-MM-dd hh:mm:ss"));
|
|
}
|
|
}
|
|
|
|
Q_SLOT void lpReport::onSlowPixmap(QSqlQuery sql)
|
|
{
|
|
static bool nFlag = false;
|
|
if (nFlag == true)
|
|
return;
|
|
nFlag = true;
|
|
|
|
sql.next();
|
|
double dHight = sql.value("hight").toDouble();
|
|
QByteArray pic = sql.value("pic").toByteArray();
|
|
QImage img = QImage::fromData(pic);
|
|
QSize s = img.size();
|
|
QPixmap m_Pix = QPixmap::fromImage(img);
|
|
|
|
{
|
|
int dhight = m_Pix.height();
|
|
int dwidth = m_Pix.width();
|
|
double nRate = m_Pix.width()*1.0 / m_Pix.height();
|
|
int scarew = 150;
|
|
int scareh = 150 * 1.0 / nRate;
|
|
|
|
if (scareh > 150)
|
|
{
|
|
scarew = 150;
|
|
scareh = 150 * 1.0 / nRate;
|
|
}
|
|
ui.CheckDlg_label_Pic->setPixmap(m_Pix.scaled(scarew, scareh));
|
|
}
|
|
nFlag = false;
|
|
}
|
|
|
|
Q_SLOT void lpReport::onTableViewClick(QModelIndex mIndex)
|
|
{
|
|
QString strObj = sender()->objectName();
|
|
if ("tableView_checkShengchang" == strObj) {
|
|
if (m_tableModel)
|
|
{
|
|
QModelIndex ItemIndex = m_tableModel->index(mIndex.row(), 7);
|
|
QString strdata = ItemIndex.data().toString();
|
|
if (m_pDb)
|
|
{
|
|
QVariantMap m_value;
|
|
m_value.insert(_CHECK_UID_, strdata);
|
|
m_value.insert(_CHECK_TYPE_, EMT_CHECK_BY_UID);
|
|
QString seletcStr = m_pDb->genCheckStr(m_value);
|
|
|
|
/*启用线程查询数据 减少界面卡顿*/
|
|
CheckThread *workerThread = new CheckThread(this);
|
|
workerThread->setCheckStr(m_pDb, seletcStr);
|
|
connect(workerThread, SIGNAL(resultReady(QSqlQuery)), this, SLOT(onSlowPixmap(QSqlQuery)));
|
|
connect(workerThread, &CheckThread::finished, workerThread, &QObject::deleteLater);
|
|
workerThread->start();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//初始化UI参数
|
|
void lpReport::InitUIParam()
|
|
{
|
|
m_startDate_History = QDateTime::currentDateTime();
|
|
m_endDate_History = QDateTime::currentDateTime();
|
|
QString strstartDate = m_startDate_History.toString("yyyy-MM-dd hh:mm:ss");
|
|
ui.label_Time1_History->setText(m_startDate_History.toString("yyyy-MM-dd hh:mm:ss"));
|
|
ui.label_Time2_History->setText(m_endDate_History.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"));
|
|
|
|
m_startDate_Count = QDateTime::currentDateTime();
|
|
m_endDate_Count = QDateTime::currentDateTime();
|
|
m_endDate_Warning = m_startDate_Warning = QDateTime::currentDateTime();
|
|
m_startDate_Warning.setTime(nstartTime);
|
|
ui.label_Time1_warning->setText(m_startDate_Warning.toString("yyyy-MM-dd hh:mm:ss"));
|
|
ui.label_Time2_warning->setText(m_endDate_Warning.toString("yyyy-MM-dd hh:mm:ss"));
|
|
|
|
ui.comboBox_Banci->clear();
|
|
ui.comboBox_Banci->addItem(tr("全天"));
|
|
ui.comboBox_Banci->addItems(m_Totaltime.keys());
|
|
ui.comboBox_Banci_Calculate->clear();
|
|
ui.comboBox_Banci_Calculate->addItem(tr("全天"));
|
|
ui.comboBox_Banci_Calculate->addItems(m_Totaltime.keys());
|
|
|
|
ui.comboBox_Wandring_Log->clear();
|
|
ui.comboBox_Wandring_Log->addItem(tr("报警记录查询"));
|
|
ui.comboBox_Wandring_Log->addItem(tr("运行状态查询"));
|
|
ui.comboBox_Wandring_Log->addItem(tr("使用记录查询"));
|
|
|
|
ui.label_Title->setText(tr("生产数据查询"));
|
|
ui.stackedWidget->setCurrentIndex(0);
|
|
|
|
if (m_tableModel)
|
|
{
|
|
m_tableModel->clear();
|
|
}
|
|
if (m_tableWarnModel)
|
|
m_tableWarnModel->clear();
|
|
|
|
ui.label_Number->setText("0");
|
|
ui.CheckDlg_label_Pic->clear();
|
|
|
|
if (reportdlg)
|
|
reportdlg->ClearData();
|
|
}
|
|
|
|
void lpReport::SetModelNames(QStringList models)
|
|
{
|
|
ui.comboBox_Model->clear();
|
|
ui.comboBox_Model->addItem(tr("全部"));
|
|
if (!models.contains("NG"))
|
|
ui.comboBox_Model->addItem(tr("NG"));
|
|
ui.comboBox_Model->addItems(models);
|
|
if (_pCompleter)
|
|
delete _pCompleter;
|
|
_pCompleter = new QCompleter(models);
|
|
_pCompleter->setCaseSensitivity(Qt::CaseInsensitive);
|
|
ui.comboBox_Model->setCompleter(_pCompleter);
|
|
}
|
|
|
|
void lpReport::SetLanguage(QString strLanguage)
|
|
{
|
|
QString strDirPath = QString(QCoreApplication::applicationDirPath() + "/language/");
|
|
QString translatorFileName = strLanguage;
|
|
if (!translatorFileName.isEmpty())
|
|
{
|
|
if (m_VecTranPtr.size() > 0)
|
|
{
|
|
while (m_VecTranPtr.size())
|
|
{
|
|
QTranslator *pVa = m_VecTranPtr.takeFirst();
|
|
qApp->removeTranslator(pVa);
|
|
delete pVa;
|
|
pVa = NULL;
|
|
}
|
|
}
|
|
//if (strLangage == "Chinese")
|
|
// return;
|
|
QLocale::setDefault(QLocale(translatorFileName));
|
|
|
|
QString transDir = strDirPath + translatorFileName;
|
|
SearchQmFile(transDir);
|
|
}
|
|
}
|
|
|
|
void lpReport::SearchQmFile(const QString & strDir)
|
|
{
|
|
QDir dir(strDir);
|
|
if (!dir.exists())
|
|
{
|
|
return;
|
|
}
|
|
dir.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
|
|
dir.setSorting(QDir::DirsFirst); // 文件夹优先
|
|
// 转换成一个List
|
|
QFileInfoList list = dir.entryInfoList();
|
|
if (list.size() < 1)
|
|
{
|
|
return;
|
|
}
|
|
int i = 0;
|
|
do
|
|
{
|
|
QFileInfo fileInfo = list.at(i);
|
|
QString tt = fileInfo.fileName();
|
|
// 如果是文件夹
|
|
bool bisDir = fileInfo.isDir();
|
|
if (bisDir)
|
|
{
|
|
SearchQmFile(fileInfo.filePath());
|
|
}
|
|
else
|
|
{
|
|
bool bQm = fileInfo.fileName().endsWith(".qm");
|
|
SetTranslator(fileInfo.filePath());
|
|
}
|
|
i++;
|
|
} while (i < list.size());
|
|
}
|
|
|
|
void lpReport::SetTranslator(const QString strPath)
|
|
{
|
|
if (strPath.isEmpty())
|
|
{
|
|
return;
|
|
}
|
|
QTranslator *pTrans = new QTranslator;
|
|
if (pTrans->load(strPath)) // 如果加载成功
|
|
{
|
|
qApp->installTranslator(pTrans);
|
|
m_VecTranPtr.append(pTrans);
|
|
}
|
|
else
|
|
{
|
|
delete pTrans;
|
|
pTrans = NULL;
|
|
}
|
|
}
|