232 lines
8.7 KiB
C++
232 lines
8.7 KiB
C++
#include "ReportPage.h"
|
|
#include "ui_ReportPage.h"
|
|
#include <QMessageBox>
|
|
#include <QFileDialog>
|
|
#include <QString>
|
|
#include "ZTStats.h"
|
|
#include <QScrollBar>
|
|
#include <QDesktopServices>
|
|
|
|
|
|
CReportPage::CReportPage(QWidget *parent) :
|
|
QWidget(parent),
|
|
ui(new Ui::CReportPage)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
ui->mReportStartDateEdit->setCalendarPopup(true);
|
|
ui->mReportStartDateEdit->setDate(QDate::currentDate());
|
|
ui->mReportStartDateEdit->setMaximumDate(QDate::currentDate());
|
|
ui->mReportEndDateEdit->setCalendarPopup(true);
|
|
ui->mReportEndDateEdit->setDate(QDate::currentDate());
|
|
ui->mReportEndDateEdit->setMaximumDate(QDate::currentDate());
|
|
|
|
ui->mReportFunctionFNChkBx->setCheckState(Qt::Checked);
|
|
|
|
|
|
connect(ui->mGenerateReportBtn,&QPushButton::clicked,this,&CReportPage::GenerateReportBtnClicked);
|
|
connect(ui->mSelectAllFuncZT1Btn,&QPushButton::clicked,this,&CReportPage::FunctionSelectionBtnPressed);
|
|
connect(ui->mSelectAllFuncZT2Btn,&QPushButton::clicked,this,&CReportPage::FunctionSelectionBtnPressed);
|
|
connect(ui->mSelectNoneFuncZT1Btn,&QPushButton::clicked,this,&CReportPage::FunctionSelectionBtnPressed);
|
|
connect(ui->mSelectNoneFuncZT2Btn,&QPushButton::clicked,this,&CReportPage::FunctionSelectionBtnPressed);
|
|
connect(ui->mOpenReportBtn,&QPushButton::clicked,this,&CReportPage::OpenReportBtnClicked);
|
|
|
|
|
|
mTimeCounter = new QTimer;
|
|
mTimeCounter->setSingleShot(false);
|
|
mTimeCounter->setInterval(1000);
|
|
// connect(mTimeCounter,&QTimer::timeout,this,&CReportPage::TimerExpired);
|
|
connect(mTimeCounter,SIGNAL(timeout()),this,SLOT(TimerExpired()));
|
|
|
|
ui->mTimerLable->setText("");
|
|
|
|
ui->mOpenReportBtn->hide();
|
|
ui->mReportPathLabel->hide();
|
|
|
|
ui->mReportProgressBarr->setMinimum(0);
|
|
ui->mReportProgressBarr->setMaximum(1);
|
|
ui->mReportProgressBarr->setValue(0);
|
|
|
|
|
|
}
|
|
|
|
CReportPage::~CReportPage()
|
|
{
|
|
delete ui;
|
|
delete mTimeCounter;
|
|
}
|
|
|
|
CReportConfigData CReportPage::GetReportFiltersConfig()
|
|
{
|
|
CReportConfigData FiltersConfig;
|
|
|
|
FiltersConfig.mReportStartDate = ui->mReportStartDateEdit->date();
|
|
FiltersConfig.mReportEndDate = ui->mReportEndDateEdit->date();
|
|
|
|
|
|
|
|
FiltersConfig.mReportFilterIncludeFN = ui->mReportFunctionFNChkBx->isChecked();
|
|
FiltersConfig.mReportfilterIncludePEQ1 = ui->mReportFunctionPEQ1ChkBx->isChecked();
|
|
FiltersConfig.mReportfilterIncludePG = ui->mReportFunctionPGChkBx->isChecked();
|
|
FiltersConfig.mReportfilterIncludeComptage1 = ui->mReportFunctionComptage_1ChkBx->isChecked();
|
|
FiltersConfig.mReportfilterIncludePPE1 = ui->mReportFunctionPPE_1ChkBx->isChecked();
|
|
FiltersConfig.mReportfilterIncludePPI1 = ui->mReportFunctionPPI_1ChkBx->isChecked();
|
|
|
|
FiltersConfig.mReportfilterIncludeComptage2 = ui->mReportFunctionComptage_2ChkBx->isChecked();
|
|
FiltersConfig.mReportfilterIncludePEQ2 = ui->mReportFunctionPEQ2ChkBx->isChecked();
|
|
FiltersConfig.mReportfilterIncludePPE2 = ui->mReportFunctionPPE_2ChkBx->isChecked();
|
|
FiltersConfig.mReportfilterIncludePPI2 = ui->mReportFunctionPPI_2ChkBx->isChecked();
|
|
|
|
|
|
FiltersConfig.mReportStationAngrignon = ui->mReportStationAngrignonChkBx->isChecked();
|
|
FiltersConfig.mReportStationBeaugrand = ui->mReportStationBeaugrandChkBx->isChecked();
|
|
FiltersConfig.mReportStationBerri = ui->mReportStationBerriChkBx->isChecked();
|
|
FiltersConfig.mReportStationBourassa = ui->mReportStationBourassaChkBx->isChecked();
|
|
FiltersConfig.mReportStationLongueuil = ui->mReportStationLongueuilChkBx->isChecked();
|
|
FiltersConfig.mReportStationMontmorency = ui->mReportStationMontmorencyChkBx->isChecked();
|
|
FiltersConfig.mReportStationSnowdon = ui->mReportStationSnowdonChkBx->isChecked();
|
|
FiltersConfig.mReportStationStMichel = ui->mReportStationStMichelChkBx->isChecked();
|
|
FiltersConfig.mReportStationVertu = ui->mReportStationVertuChkBx->isChecked();
|
|
|
|
FiltersConfig.mReportIncludeSansDeclZT1 = ui->mReportFunctionNoDecl1ChkBx->isChecked();
|
|
FiltersConfig.mReportIncludeSansDeclZT2 = ui->mReportFunctionNoDecl2ChkBx->isChecked();
|
|
|
|
return FiltersConfig;
|
|
}
|
|
|
|
void CReportPage::GenerateReportBtnClicked()
|
|
{
|
|
if(ui->mGenerateReportBtn->text() == "Annuler")
|
|
{
|
|
mProgramHandle->AbortReportCreationRequest();
|
|
}
|
|
else
|
|
{
|
|
//Sanity check first...
|
|
CReportConfigData ConfigFilters = GetReportFiltersConfig();
|
|
|
|
if(ConfigFilters.IsAnyFilterSelected() == false)
|
|
{
|
|
QMessageBox::critical(this,"Erreur","Vous devez sélectionner au moins 1 alarme à analyser");
|
|
return;
|
|
}
|
|
|
|
if(ConfigFilters.IsAnyStationSelected() == false)
|
|
{
|
|
QMessageBox::critical(this,"Erreur","Vous devez sélectionner au moins 1 station");
|
|
return;
|
|
}
|
|
|
|
if(ConfigFilters.IsDateRangeValid() == false)
|
|
{
|
|
QMessageBox::critical(this,"Erreur","Vous devez sélectionner une période valide (dates)");
|
|
return;
|
|
}
|
|
|
|
QString ExcelFile = QFileDialog::getSaveFileName(this, tr("Fichier rapport"), QString(),tr("Excel (*.xlsx)"));
|
|
// qDebug("%s",qPrintable(ExcelFile));
|
|
if(ExcelFile.isEmpty())
|
|
{
|
|
return;
|
|
}
|
|
|
|
ClearProgressStatus();
|
|
ui->mReportProgressBarr->setMinimum(0);
|
|
ui->mReportProgressBarr->setMaximum(0);
|
|
mProgressTime.setHMS(0,0,0,0);
|
|
mTimeCounter->start();
|
|
UpdateProgressStatus("Création du rapport en cours... ça peut être long!!!");
|
|
ui->mGenerateReportBtn->setText("Annuler");
|
|
mProgramHandle->GenerateReportRequest(ExcelFile,ConfigFilters);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CReportPage::UpdateProgressStatus(QString Status)
|
|
{
|
|
Status.append("\n");
|
|
ui->mReportProgressTextEdit->setPlainText(ui->mReportProgressTextEdit->document()->toPlainText().append(Status));
|
|
ui->mReportProgressTextEdit->verticalScrollBar()->setValue(ui->mReportProgressTextEdit->verticalScrollBar()->maximum());
|
|
}
|
|
|
|
void CReportPage::ClearProgressStatus()
|
|
{
|
|
ui->mReportProgressTextEdit->clear();
|
|
ui->mReportProgressBarr->setMinimum(0);
|
|
ui->mReportProgressBarr->setMaximum(1);
|
|
ui->mReportProgressBarr->setValue(0);
|
|
}
|
|
|
|
void CReportPage::ReportCreationFinished(QString ReportFilePath)
|
|
{
|
|
// ClearProgressStatus();
|
|
ui->mReportProgressBarr->setMinimum(0);
|
|
ui->mReportProgressBarr->setMaximum(1);
|
|
ui->mReportProgressBarr->setValue(0);
|
|
ui->mGenerateReportBtn->setText("Générer Rapport");
|
|
mTimeCounter->stop();
|
|
|
|
if(ReportFilePath.isEmpty() == false)
|
|
{
|
|
mReportFilePath = ReportFilePath;
|
|
ui->mReportPathLabel->setText(ReportFilePath);
|
|
ui->mReportPathLabel->show();
|
|
ui->mOpenReportBtn->show();
|
|
}
|
|
}
|
|
|
|
void CReportPage::TimerExpired()
|
|
{
|
|
mProgressTime = mProgressTime.addSecs(1);
|
|
ui->mTimerLable->setText(mProgressTime.toString("hh:mm:ss"));
|
|
}
|
|
|
|
void CReportPage::FunctionSelectionBtnPressed()
|
|
{
|
|
QObject *CallerBtn = sender();
|
|
|
|
if(CallerBtn == ui->mSelectAllFuncZT1Btn)
|
|
{
|
|
ui->mReportFunctionFNChkBx->setCheckState(Qt::Checked);
|
|
ui->mReportFunctionPEQ1ChkBx->setCheckState(Qt::Checked);
|
|
ui->mReportFunctionPGChkBx->setCheckState(Qt::Checked);
|
|
ui->mReportFunctionComptage_1ChkBx->setCheckState(Qt::Checked);
|
|
ui->mReportFunctionPPI_1ChkBx->setCheckState(Qt::Checked);
|
|
ui->mReportFunctionPPE_1ChkBx->setCheckState(Qt::Checked);
|
|
}
|
|
else if(CallerBtn == ui->mSelectAllFuncZT2Btn)
|
|
{
|
|
ui->mReportFunctionComptage_2ChkBx->setCheckState(Qt::Checked);
|
|
ui->mReportFunctionComptage_2ChkBx->setCheckState(Qt::Checked);
|
|
ui->mReportFunctionPEQ2ChkBx->setCheckState(Qt::Checked);
|
|
ui->mReportFunctionPPE_2ChkBx->setCheckState(Qt::Checked);
|
|
ui->mReportFunctionPPI_2ChkBx->setCheckState(Qt::Checked);
|
|
}
|
|
else if(CallerBtn == ui->mSelectNoneFuncZT1Btn)
|
|
{
|
|
ui->mReportFunctionFNChkBx->setCheckState(Qt::Unchecked);
|
|
ui->mReportFunctionPEQ1ChkBx->setCheckState(Qt::Unchecked);
|
|
ui->mReportFunctionPGChkBx->setCheckState(Qt::Unchecked);
|
|
ui->mReportFunctionComptage_1ChkBx->setCheckState(Qt::Unchecked);
|
|
ui->mReportFunctionPPI_1ChkBx->setCheckState(Qt::Unchecked);
|
|
ui->mReportFunctionPPE_1ChkBx->setCheckState(Qt::Unchecked);
|
|
}
|
|
else if(CallerBtn == ui->mSelectNoneFuncZT2Btn)
|
|
{
|
|
ui->mReportFunctionComptage_2ChkBx->setCheckState(Qt::Unchecked);
|
|
ui->mReportFunctionComptage_2ChkBx->setCheckState(Qt::Unchecked);
|
|
ui->mReportFunctionPEQ2ChkBx->setCheckState(Qt::Unchecked);
|
|
ui->mReportFunctionPPE_2ChkBx->setCheckState(Qt::Unchecked);
|
|
ui->mReportFunctionPPI_2ChkBx->setCheckState(Qt::Unchecked);
|
|
}
|
|
}
|
|
|
|
void CReportPage::OpenReportBtnClicked()
|
|
{
|
|
// system(qPrintable(mReportFilePath));
|
|
// QProcess::execute(mReportFilePath);
|
|
QDesktopServices::openUrl(QUrl::fromLocalFile(mReportFilePath));
|
|
}
|