From badd1595e1a489417dda22f586b9cd7b037f0e00 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Wed, 8 Aug 2018 10:22:38 +0200 Subject: [PATCH] allow to clear database --- src/core/marketplace.cpp | 16 ++++++++++++++++ src/core/marketplace.h | 2 ++ src/gui/mainwindow.cpp | 25 ++++++++++++++++++++++++- src/gui/mainwindow.ui | 7 +++++++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/core/marketplace.cpp b/src/core/marketplace.cpp index ec852af..a298e29 100644 --- a/src/core/marketplace.cpp +++ b/src/core/marketplace.cpp @@ -248,4 +248,20 @@ std::string escapeCsvValue(const std::string& value, const char delimiter) } return output.str(); +} + +void Marketplace::clear() +{ + std::for_each(sellers_.begin(), sellers_.end(), [](auto& seller) { + if (seller->getUuidAsString() == "11111111-1111-1111-1111-111111111111") { + for (auto& article : seller->getArticles()) { + article->setState(Article::State::DELETE); + } + } else { + seller->setState(Seller::State::DELETE); + } + }); + std::for_each(sales_.begin(), sales_.end(), + [](auto& sale) { sale->setState(Sale::State::DELETE); }); + storeToDb(); } \ No newline at end of file diff --git a/src/core/marketplace.h b/src/core/marketplace.h index 172caec..3dd848f 100644 --- a/src/core/marketplace.h +++ b/src/core/marketplace.h @@ -48,6 +48,8 @@ class Marketplace std::string getOverallPaymentAsString(int percent, int maxFee); std::string getOverallRevenueAsString(int percent, int maxFee); + void clear(); + void exportReportToCSV(const std::string& filename, int feeInPercent, int maxFeeInEuro); friend class ExcelReader; diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index df18ae1..9db1bd9 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -40,6 +40,24 @@ MainWindow::MainWindow() setSaleModel(); connect(ui_.actionQuit, &QAction::triggered, qApp, QApplication::quit); + connect(ui_.newAction, &QAction::triggered, this, [=]() { + if (marketplace_->getSellers().size() == 0 && marketplace_->getSales().size() == 0) { + return; + } + auto dlgResult = + QMessageBox(QMessageBox::Icon::Warning, "Sind Sie sicher?", + "Möchten Sie wirklich alle gespeicherten Daten verwerfen?", + QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, this) + .exec(); + + if (dlgResult == QMessageBox::No) + return; + + delete ui_.salesView->model(); + dynamic_cast(ui_.basketView->model())->cancelSale(); + marketplace_->clear(); + setSaleModel(); + }); connect(ui_.actionEditSeller, &QAction::triggered, this, &MainWindow::onActionEditSellerTriggered); connect(ui_.sellerNoEdit, &QLineEdit::returnPressed, this, @@ -61,7 +79,9 @@ MainWindow::MainWindow() auto locations = QStandardPaths::standardLocations(QStandardPaths::DataLocation); for (auto location : locations) { if (QFile::exists(location + QString("/Benutzerhandbuch.pdf"))) { - QDesktopServices::openUrl(QUrl(QString("file:///") + location + QString("/Benutzerhandbuch.pdf"), QUrl::TolerantMode)); + QDesktopServices::openUrl( + QUrl(QString("file:///") + location + QString("/Benutzerhandbuch.pdf"), + QUrl::TolerantMode)); } } }); @@ -298,6 +318,9 @@ void MainWindow::onImportSellerExcelActionTriggered() auto filename = QFileDialog::getOpenFileName(this, "Verkäufer importieren", QString(), "Excel Dateien (*.xlsx *.xls)"); + if (filename.isEmpty()) + return; + ExcelReader::readSellersFromFile(filename.toStdString(), marketplace_.get()); } diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 4171501..76efbb2 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -395,6 +395,8 @@ drucken &Datei + + @@ -500,6 +502,11 @@ drucken Handbuch + + + Neu + +