allow to clear database

This commit is contained in:
Martin Brodbeck 2018-08-08 10:22:38 +02:00
parent 95a89e568c
commit badd1595e1
4 changed files with 49 additions and 1 deletions

View file

@ -249,3 +249,19 @@ std::string escapeCsvValue(const std::string& value, const char delimiter)
return output.str(); 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();
}

View file

@ -48,6 +48,8 @@ class Marketplace
std::string getOverallPaymentAsString(int percent, int maxFee); std::string getOverallPaymentAsString(int percent, int maxFee);
std::string getOverallRevenueAsString(int percent, int maxFee); std::string getOverallRevenueAsString(int percent, int maxFee);
void clear();
void exportReportToCSV(const std::string& filename, int feeInPercent, int maxFeeInEuro); void exportReportToCSV(const std::string& filename, int feeInPercent, int maxFeeInEuro);
friend class ExcelReader; friend class ExcelReader;

View file

@ -40,6 +40,24 @@ MainWindow::MainWindow()
setSaleModel(); setSaleModel();
connect(ui_.actionQuit, &QAction::triggered, qApp, QApplication::quit); 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<BasketModel*>(ui_.basketView->model())->cancelSale();
marketplace_->clear();
setSaleModel();
});
connect(ui_.actionEditSeller, &QAction::triggered, this, connect(ui_.actionEditSeller, &QAction::triggered, this,
&MainWindow::onActionEditSellerTriggered); &MainWindow::onActionEditSellerTriggered);
connect(ui_.sellerNoEdit, &QLineEdit::returnPressed, this, connect(ui_.sellerNoEdit, &QLineEdit::returnPressed, this,
@ -61,7 +79,9 @@ MainWindow::MainWindow()
auto locations = QStandardPaths::standardLocations(QStandardPaths::DataLocation); auto locations = QStandardPaths::standardLocations(QStandardPaths::DataLocation);
for (auto location : locations) { for (auto location : locations) {
if (QFile::exists(location + QString("/Benutzerhandbuch.pdf"))) { 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(), auto filename = QFileDialog::getOpenFileName(this, "Verkäufer importieren", QString(),
"Excel Dateien (*.xlsx *.xls)"); "Excel Dateien (*.xlsx *.xls)");
if (filename.isEmpty())
return;
ExcelReader::readSellersFromFile(filename.toStdString(), marketplace_.get()); ExcelReader::readSellersFromFile(filename.toStdString(), marketplace_.get());
} }

View file

@ -395,6 +395,8 @@ drucken</string>
<property name="title"> <property name="title">
<string>&amp;Datei</string> <string>&amp;Datei</string>
</property> </property>
<addaction name="newAction"/>
<addaction name="separator"/>
<addaction name="configAction"/> <addaction name="configAction"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionQuit"/> <addaction name="actionQuit"/>
@ -500,6 +502,11 @@ drucken</string>
<string>Handbuch</string> <string>Handbuch</string>
</property> </property>
</action> </action>
<action name="newAction">
<property name="text">
<string>Neu</string>
</property>
</action>
</widget> </widget>
<resources/> <resources/>
<connections/> <connections/>