2018-07-14 14:03:35 +02:00
|
|
|
#include "mainwindow.h"
|
|
|
|
|
2018-07-22 20:10:22 +02:00
|
|
|
#include "basketmodel.h"
|
2018-07-21 19:24:56 +02:00
|
|
|
#include "pricedialog.h"
|
2018-07-21 21:18:22 +02:00
|
|
|
#include "sellerdialog.h"
|
2018-07-16 12:00:17 +02:00
|
|
|
|
2018-07-20 22:07:42 +02:00
|
|
|
#include <regex>
|
|
|
|
|
2018-07-17 10:37:21 +02:00
|
|
|
constexpr int STATUSBAR_TIMEOUT = 5000;
|
|
|
|
|
2018-07-14 14:03:35 +02:00
|
|
|
MainWindow::MainWindow()
|
|
|
|
{
|
2018-07-14 15:54:29 +02:00
|
|
|
ui_.setupUi(this);
|
|
|
|
|
|
|
|
connect(ui_.actionQuit, &QAction::triggered, qApp, QApplication::quit);
|
2018-07-17 10:37:21 +02:00
|
|
|
connect(ui_.actionEditSeller, &QAction::triggered, this,
|
|
|
|
&MainWindow::on_actionEditSeller_triggered);
|
2018-07-20 22:07:42 +02:00
|
|
|
connect(ui_.sellerNoEdit, &QLineEdit::returnPressed, this,
|
|
|
|
&MainWindow::on_sellerNoEdit_checkSellerNo);
|
2018-07-23 08:21:28 +02:00
|
|
|
connect(ui_.paidButton, &QPushButton::clicked, this, &MainWindow::on_paidButton_triggered);
|
2018-07-14 15:54:29 +02:00
|
|
|
|
|
|
|
marketplace_ = std::make_unique<Marketplace>();
|
2018-07-17 10:37:21 +02:00
|
|
|
marketplace_->loadFromDb();
|
|
|
|
statusBar()->showMessage("Gespeicherte Daten wurden geladen.", STATUSBAR_TIMEOUT);
|
2018-07-22 20:10:22 +02:00
|
|
|
|
|
|
|
BasketModel* model = new BasketModel(getMarketplace(), ui_.basketView);
|
|
|
|
ui_.basketView->setModel(model);
|
|
|
|
ui_.basketView->setColumnHidden(0, true); // hide the uuid
|
2018-07-14 15:54:29 +02:00
|
|
|
}
|
|
|
|
|
2018-07-16 12:00:17 +02:00
|
|
|
void MainWindow::on_actionEditSeller_triggered()
|
|
|
|
{
|
|
|
|
auto dialog = std::make_unique<SellerDialog>(this);
|
2018-07-16 18:04:25 +02:00
|
|
|
int retCode = dialog->exec();
|
|
|
|
if (retCode == QDialog::Accepted) {
|
2018-07-18 09:00:46 +02:00
|
|
|
marketplace_->sortSellers();
|
2018-07-16 18:04:25 +02:00
|
|
|
marketplace_->storeToDb();
|
2018-07-17 10:37:21 +02:00
|
|
|
statusBar()->showMessage("Änderungen an den Verkäufer-Stammdaten gespeichert.",
|
|
|
|
STATUSBAR_TIMEOUT);
|
2018-07-16 18:04:25 +02:00
|
|
|
} else {
|
|
|
|
marketplace_->loadFromDb();
|
2018-07-17 11:09:35 +02:00
|
|
|
statusBar()->showMessage("Änderungen an den Verkäufer-Stammdaten verworfen!",
|
2018-07-17 10:37:21 +02:00
|
|
|
STATUSBAR_TIMEOUT);
|
2018-07-16 18:04:25 +02:00
|
|
|
}
|
2018-07-20 22:07:42 +02:00
|
|
|
}
|
|
|
|
|
2018-07-23 08:21:28 +02:00
|
|
|
void MainWindow::on_paidButton_triggered()
|
|
|
|
{
|
|
|
|
if (marketplace_->basketSize() > 0) {
|
|
|
|
dynamic_cast<BasketModel*>(ui_.basketView->model())->finishSale();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-20 22:07:42 +02:00
|
|
|
void MainWindow::on_sellerNoEdit_checkSellerNo()
|
|
|
|
{
|
|
|
|
using std::regex, std::regex_match, std::smatch;
|
|
|
|
|
|
|
|
auto inputText = ui_.sellerNoEdit->text().toStdString();
|
|
|
|
|
|
|
|
if (inputText.empty()) {
|
2018-07-21 21:18:22 +02:00
|
|
|
if (marketplace_->basketSize() > 0) {
|
2018-07-22 20:10:22 +02:00
|
|
|
dynamic_cast<BasketModel*>(ui_.basketView->model())->finishSale();
|
2018-07-21 21:18:22 +02:00
|
|
|
}
|
2018-07-20 22:07:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
regex pattern{R"(\d{1,5})"};
|
|
|
|
smatch result;
|
2018-07-22 20:10:22 +02:00
|
|
|
|
2018-07-20 22:07:42 +02:00
|
|
|
if (!regex_match(inputText, result, pattern)) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-21 21:18:22 +02:00
|
|
|
|
2018-07-20 22:07:42 +02:00
|
|
|
int sellerNo = std::stoi(result[0]);
|
|
|
|
|
|
|
|
auto seller = marketplace_->findSellerWithSellerNo(sellerNo);
|
|
|
|
if (seller) {
|
2018-07-21 19:24:56 +02:00
|
|
|
PriceDialog priceDialog(this);
|
|
|
|
auto dialogResult = priceDialog.exec();
|
2018-07-21 21:18:22 +02:00
|
|
|
if (dialogResult == QDialog::Accepted) {
|
2018-07-21 19:24:56 +02:00
|
|
|
int price = priceDialog.getPrice();
|
2018-07-22 20:10:22 +02:00
|
|
|
dynamic_cast<BasketModel*>(ui_.basketView->model())->addArticle(seller, price);
|
2018-07-21 19:24:56 +02:00
|
|
|
}
|
2018-07-20 22:07:42 +02:00
|
|
|
}
|
2018-07-20 22:10:05 +02:00
|
|
|
|
2018-07-20 22:07:42 +02:00
|
|
|
ui_.sellerNoEdit->clear();
|
2018-07-16 12:00:17 +02:00
|
|
|
}
|