Added warning message when Excel import fails.

This commit is contained in:
Martin Brodbeck 2020-10-15 16:43:00 +02:00
parent 9e6e2eb936
commit a156c5331a
1 changed files with 40 additions and 27 deletions

View File

@ -40,7 +40,7 @@ MainWindow::MainWindow()
QMessageBox(QMessageBox::Icon::Information, "Datenbankinformation", QMessageBox(QMessageBox::Icon::Information, "Datenbankinformation",
"Es wurde eine <b>veraltete</b> Datenbankdatei erkannt.<br />Diese wurde " "Es wurde eine <b>veraltete</b> Datenbankdatei erkannt.<br />Diese wurde "
"umbenannt und eine <b>neue</b> Datei wurde erstellt.") "umbenannt und eine <b>neue</b> Datei wurde erstellt.")
.exec(); .exec();
} }
statusBar()->showMessage("Gespeicherte Daten wurden geladen.", STATUSBAR_TIMEOUT); statusBar()->showMessage("Gespeicherte Daten wurden geladen.", STATUSBAR_TIMEOUT);
@ -63,7 +63,7 @@ MainWindow::MainWindow()
QMessageBox(QMessageBox::Icon::Warning, "Sind Sie sicher?", QMessageBox(QMessageBox::Icon::Warning, "Sind Sie sicher?",
"Möchten Sie wirklich alle gespeicherten Daten verwerfen?", "Möchten Sie wirklich alle gespeicherten Daten verwerfen?",
QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, this) QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, this)
.exec(); .exec();
if (dlgResult == QMessageBox::No) if (dlgResult == QMessageBox::No)
return; return;
@ -126,7 +126,9 @@ MainWindow::MainWindow()
"SOFTWARE ODER SONSTIGER VERWENDUNG DER SOFTWARE ENTSTANDEN."); "SOFTWARE ODER SONSTIGER VERWENDUNG DER SOFTWARE ENTSTANDEN.");
QMessageBox::information(this, "Lizenzinformation", licenseText); QMessageBox::information(this, "Lizenzinformation", licenseText);
}); });
connect(ui_.reportAction, &QAction::triggered, this, [=]() { ReportDialog(this).exec(); }); connect(ui_.reportAction, &QAction::triggered, this, [=]() {
ReportDialog(this).exec();
});
connect(ui_.configAction, &QAction::triggered, this, [=]() { connect(ui_.configAction, &QAction::triggered, this, [=]() {
int result = SettingsDialog(this).exec(); int result = SettingsDialog(this).exec();
if (result == QDialog::Accepted) { if (result == QDialog::Accepted) {
@ -298,7 +300,7 @@ void MainWindow::onGivenSpinBoxValueChanged(double value)
} }
void MainWindow::onBasketViewSelectionChanged(const QItemSelection& selected, void MainWindow::onBasketViewSelectionChanged(const QItemSelection& selected,
[[maybe_unused]] const QItemSelection& deselected) [[maybe_unused]] const QItemSelection& deselected)
{ {
if (selected.size() > 0) { if (selected.size() > 0) {
ui_.cancelArticleButton->setEnabled(true); ui_.cancelArticleButton->setEnabled(true);
@ -308,7 +310,7 @@ void MainWindow::onBasketViewSelectionChanged(const QItemSelection& selected,
} }
void MainWindow::onSalesViewSelectionChanged(const QItemSelection& selected, void MainWindow::onSalesViewSelectionChanged(const QItemSelection& selected,
[[maybe_unused]] const QItemSelection& deselected) [[maybe_unused]] const QItemSelection& deselected)
{ {
if (selected.size() > 0) { if (selected.size() > 0) {
ui_.cancelSaleButton->setEnabled(true); ui_.cancelSaleButton->setEnabled(true);
@ -333,7 +335,7 @@ void MainWindow::onCancelArticleButtonClicked([[maybe_unused]] bool checked)
QMessageBox(QMessageBox::Icon::Warning, "Sind Sie sicher?", QMessageBox(QMessageBox::Icon::Warning, "Sind Sie sicher?",
"Möchten Sie wirklich den Artikel stornieren?", "Möchten Sie wirklich den Artikel stornieren?",
QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, this) QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, this)
.exec(); .exec();
if (dlgResult == QMessageBox::No) if (dlgResult == QMessageBox::No)
return; return;
@ -359,7 +361,7 @@ void MainWindow::onCancelSaleButtonClicked([[maybe_unused]] bool checked)
QMessageBox(QMessageBox::Icon::Warning, "Sind Sie sicher?", QMessageBox(QMessageBox::Icon::Warning, "Sind Sie sicher?",
"Möchten Sie wirklich aus abgeschlossenen Verkäufen stornieren?", "Möchten Sie wirklich aus abgeschlossenen Verkäufen stornieren?",
QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, this) QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, this)
.exec(); .exec();
if (dlgResult == QMessageBox::No) if (dlgResult == QMessageBox::No)
return; return;
@ -422,7 +424,7 @@ void MainWindow::onCancelAllArticlesButtonClicked([[maybe_unused]] bool checked)
QMessageBox(QMessageBox::Icon::Warning, "Sind Sie sicher?", QMessageBox(QMessageBox::Icon::Warning, "Sind Sie sicher?",
"Möchten Sie wirklich *alle* Artikel des aktuellen Einkaufs stornieren?", "Möchten Sie wirklich *alle* Artikel des aktuellen Einkaufs stornieren?",
QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, this) QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, this)
.exec(); .exec();
if (dlgResult == QMessageBox::No) if (dlgResult == QMessageBox::No)
return; return;
@ -432,17 +434,19 @@ void MainWindow::onCancelAllArticlesButtonClicked([[maybe_unused]] bool checked)
ui_.sellerNoEdit->setFocus(); ui_.sellerNoEdit->setFocus();
} }
void MainWindow::onAboutQt() { QMessageBox::aboutQt(this); } void MainWindow::onAboutQt() {
QMessageBox::aboutQt(this);
}
void MainWindow::onAbout() void MainWindow::onAbout()
{ {
QMessageBox::about( QMessageBox::about(
this, "Über", this, "Über",
QString("<p style='text-align:center;'><b>KIMA2</b> - Version ") + PROJECT_VERSION + QString("<p style='text-align:center;'><b>KIMA2</b> - Version ") + PROJECT_VERSION +
"</p>" "</p>"
"<p>KIMA2 ist ein kleines Kassenprogramm für Kindersachenmärkte.<p />" "<p>KIMA2 ist ein kleines Kassenprogramm für Kindersachenmärkte.<p />"
"<p>Copyright © Martin Brodbeck &lt;<a href=mailto:martin@brodbeck-online.de" "<p>Copyright © Martin Brodbeck &lt;<a href=mailto:martin@brodbeck-online.de"
">info@rustysoft.de</a>&gt;</p>"); ">info@rustysoft.de</a>&gt;</p>");
} }
void MainWindow::onImportSellerExcelActionTriggered() void MainWindow::onImportSellerExcelActionTriggered()
@ -451,13 +455,13 @@ void MainWindow::onImportSellerExcelActionTriggered()
QMessageBox(QMessageBox::Icon::Information, "Import nicht möglich", QMessageBox(QMessageBox::Icon::Information, "Import nicht möglich",
"Der Import ist nicht möglich, da schon Verkäufe getätigt wurden.", "Der Import ist nicht möglich, da schon Verkäufe getätigt wurden.",
QMessageBox::StandardButton::Ok, this) QMessageBox::StandardButton::Ok, this)
.exec(); .exec();
return; return;
} }
auto filename = QFileDialog::getOpenFileName( auto filename = QFileDialog::getOpenFileName(
this, "Verkäufer importieren", QString(), this, "Verkäufer importieren", QString(),
"Alle unterstützte Dateien (*.xlsx *.csv);;Excel Dateien (*.xlsx);;CSV Dateien (*.csv)"); "Alle unterstützte Dateien (*.xlsx *.csv);;Excel Dateien (*.xlsx);;CSV Dateien (*.csv)");
if (filename.isEmpty()) if (filename.isEmpty())
return; return;
@ -470,7 +474,16 @@ void MainWindow::onImportSellerExcelActionTriggered()
std::size_t numImported{}; std::size_t numImported{};
if (case_insensitive_match(filePath.extension().string(), std::string(".xlsx"))) { if (case_insensitive_match(filePath.extension().string(), std::string(".xlsx"))) {
numImported = ExcelReader::readSellersFromFile(filePath, marketplace_.get()); try {
numImported = ExcelReader::readSellersFromFile(filePath, marketplace_.get());
} catch (const std::exception& e) {
QMessageBox(QMessageBox::Icon::Critical, "Fehler beim Importieren",
"Beim Import aus der Excel-Datei ist ein Fehler aufgetreten. "
"Sie könnten ggf. versuchen, die Daten aus einer .csv Datei zu imporieren.",
QMessageBox::StandardButton::Ok, this).exec();
std::cerr << e.what() << std::endl;
return;
}
} else { } else {
numImported = CsvReader::readSellersFromFile(filePath, marketplace_.get()); numImported = CsvReader::readSellersFromFile(filePath, marketplace_.get());
} }
@ -483,7 +496,7 @@ void MainWindow::onImportSellerExcelActionTriggered()
<< "</b> Verkäufer importiert."; << "</b> Verkäufer importiert.";
QMessageBox(QMessageBox::Icon::Information, "Verkäufer erfolgreich importiert", QMessageBox(QMessageBox::Icon::Information, "Verkäufer erfolgreich importiert",
msg.str().c_str(), QMessageBox::StandardButton::Ok, this) msg.str().c_str(), QMessageBox::StandardButton::Ok, this)
.exec(); .exec();
} }
void MainWindow::onImportSellerJsonActionTriggered() void MainWindow::onImportSellerJsonActionTriggered()
@ -492,12 +505,12 @@ void MainWindow::onImportSellerJsonActionTriggered()
QMessageBox(QMessageBox::Icon::Information, "Import nicht möglich", QMessageBox(QMessageBox::Icon::Information, "Import nicht möglich",
"Der Import ist nicht möglich, da schon Verkäufe getätigt wurden.", "Der Import ist nicht möglich, da schon Verkäufe getätigt wurden.",
QMessageBox::StandardButton::Ok, this) QMessageBox::StandardButton::Ok, this)
.exec(); .exec();
return; return;
} }
auto filename = QFileDialog::getOpenFileName(this, "Verkäufer importieren", QString(), auto filename = QFileDialog::getOpenFileName(this, "Verkäufer importieren", QString(),
"JSON Dateien (*.json)"); "JSON Dateien (*.json)");
if (filename.isEmpty()) if (filename.isEmpty())
return; return;
@ -519,13 +532,13 @@ void MainWindow::onImportSellerJsonActionTriggered()
<< "</b> Verkäufer importiert."; << "</b> Verkäufer importiert.";
QMessageBox(QMessageBox::Icon::Information, "Verkäufer erfolgreich importiert", QMessageBox(QMessageBox::Icon::Information, "Verkäufer erfolgreich importiert",
msg.str().c_str(), QMessageBox::StandardButton::Ok, this) msg.str().c_str(), QMessageBox::StandardButton::Ok, this)
.exec(); .exec();
} }
void MainWindow::onExportSellerJsonActionTriggered() void MainWindow::onExportSellerJsonActionTriggered()
{ {
auto filename = QFileDialog::getSaveFileName( auto filename = QFileDialog::getSaveFileName(
this, "Verkäufer exportieren", QString("kima2_verkaeufer.json"), "JSON Dateien (*.json)"); this, "Verkäufer exportieren", QString("kima2_verkaeufer.json"), "JSON Dateien (*.json)");
if (filename.isEmpty()) if (filename.isEmpty())
return; return;
@ -544,9 +557,9 @@ void MainWindow::onExportSalesJsonActionTriggered()
QSettings settings; QSettings settings;
auto filename = QFileDialog::getSaveFileName( auto filename = QFileDialog::getSaveFileName(
this, "Umsätze/Transaktionen exportieren", this, "Umsätze/Transaktionen exportieren",
QString("kima2_umsaetze_kasse") + settings.value("global/cashPointNo").toString() + ".json", QString("kima2_umsaetze_kasse") + settings.value("global/cashPointNo").toString() + ".json",
"JSON Dateien (*.json)"); "JSON Dateien (*.json)");
if (filename.isEmpty()) if (filename.isEmpty())
return; return;
@ -566,7 +579,7 @@ void MainWindow::onImportSalesJsonActionTriggered()
QSettings settings; QSettings settings;
auto filename = QFileDialog::getOpenFileName(this, "Umsätze/Transaktionen importieren", auto filename = QFileDialog::getOpenFileName(this, "Umsätze/Transaktionen importieren",
QString(), "JSON Dateien (*.json)"); QString(), "JSON Dateien (*.json)");
if (filename.isEmpty()) if (filename.isEmpty())
return; return;
@ -584,7 +597,7 @@ void MainWindow::onImportSalesJsonActionTriggered()
} catch (std::runtime_error& err) { } catch (std::runtime_error& err) {
QMessageBox(QMessageBox::Icon::Warning, "Import nicht möglich", err.what(), QMessageBox::Ok, QMessageBox(QMessageBox::Icon::Warning, "Import nicht möglich", err.what(), QMessageBox::Ok,
this) this)
.exec(); .exec();
} }
setSaleModel(); setSaleModel();
updateStatLabel(); updateStatLabel();