void ReportManager::processData(QString data) { if( data != EMPTY_DB_ENTRY ) { // View/Edit Report if( processSwitch == 1) { QString report = generateReport(data.split(INCOMING_RESULT_DELIMITER)); // If view is selected, send to viewer if( ui->viewSelector->isChecked() ) { ReportViewer *rv = new ReportViewer(report, this); rv->show(); } // If gen is selected, send to generator if( ui->generateCsvSelector->isChecked() ) { QString dialogTitle = "Select where you would like to save the file"; QString saveName = ("Detailed_Sales_Report_Made_" + QDate::currentDate().toString(STANDARD_DATE_FORMAT_2) + ".csv"); QString filename = QFileDialog::getSaveFileName(this, dialogTitle, saveName, "CSV files (*.csv)", 0, 0); // Initialize and open the file. QFile theFile(filename); if( theFile.open(QFile::WriteOnly |QFile::Truncate)) { QTextStream stream(&theFile); if( ui->idRangeSelector->isChecked() ) stream << "Receipt range " + ui->rangeOne->text() + " to " + ui->rangeTwo->text(); if( ui->dateRangeSelector->isChecked() ) stream << "Date range " + ui->startDate->date().toString(STANDARD_DATE_FORMAT_2) + " to " + ui->endDate->date().toString(STANDARD_DATE_FORMAT_2); stream << "\n"; stream << report; theFile.close(); } else { ui->errLabel->setText("Could not find the file."); } } } // Monthly Depertmental Summary Reports if( processSwitch == 2 ) { generateSummaryReports(data); } } else { ui->errLabel->setText("Database returned empty values"); } }
void ReportList::slotView() { ListView* list = (ListView*)_stack->visibleWidget(); if (list == NULL) return; ListViewItem* item = list->currentItem(); if (item == NULL) return; QApplication::setOverrideCursor(waitCursor); qApp->processEvents(); QString fileName = item->extra[0].toString(); QString filePath; if (!_quasar->resourceFetch("reports", fileName, filePath)) { QApplication::restoreOverrideCursor(); QString message = tr("Error fetching report '%1'").arg(fileName); qApp->beep(); QMessageBox::critical(this, tr("Error"), message); return; } ReportDefn report; if (!report.load(filePath)) { QApplication::restoreOverrideCursor(); QString message = tr("Report '%1' is invalid").arg(fileName); qApp->beep(); QMessageBox::critical(this, tr("Error"), message); return; } QApplication::restoreOverrideCursor(); ParamMap params; if (!report.getParams(this, params)) return; QApplication::setOverrideCursor(waitCursor); qApp->processEvents(); ReportOutput* output = new ReportOutput(); if (!report.generate(params, *output)) { QApplication::restoreOverrideCursor(); delete output; QString message = tr("Report '%1' failed").arg(fileName); qApp->beep(); QMessageBox::critical(this, tr("Error"), message); return; } QApplication::restoreOverrideCursor(); ReportViewer* view = new ReportViewer(report, params, output); view->show(); }