diff --git a/src/core/marketplace.cpp b/src/core/marketplace.cpp index 8f39498..bf77cec 100644 --- a/src/core/marketplace.cpp +++ b/src/core/marketplace.cpp @@ -45,10 +45,8 @@ void Marketplace::sortSellers() { std::sort(sellers_.begin(), sellers_.end()); } Seller* Marketplace::findSellerWithSellerNo(int sellerNo) { - auto iter = - std::find_if(sellers_.begin(), sellers_.end(), [sellerNo](const auto& a) { - return a->getSellerNo() == sellerNo; - }); + auto iter = std::find_if(sellers_.begin(), sellers_.end(), + [sellerNo](const auto& a) { return a->getSellerNo() == sellerNo; }); if (iter == sellers_.end()) return nullptr; return (*iter).get(); @@ -57,4 +55,21 @@ Seller* Marketplace::findSellerWithSellerNo(int sellerNo) void Marketplace::addArticleToBasket(std::unique_ptr
article) { basket_.push_back(std::move(article)); +} + +size_t Marketplace::basketSize() { return basket_.size(); } + +void Marketplace::finishCurrentSale() +{ + if (basket_.size() == 0) + return; + + auto sale = std::make_unique(); + + for (auto iter = basket_.begin(); iter != basket_.end(); ++iter) { + sale->addArticle((*iter).get()); + (*iter)->getSeller()->addArticle(std::move(*iter)); + } + + sales_.push_back(std::move(sale)); } \ No newline at end of file diff --git a/src/core/marketplace.h b/src/core/marketplace.h index 790b404..9887e4f 100644 --- a/src/core/marketplace.h +++ b/src/core/marketplace.h @@ -21,6 +21,7 @@ class Marketplace { public: Marketplace(); + void storeToDb(bool onlyDelete = false); void loadFromDb(); SellersVec& getSellers(); @@ -29,6 +30,8 @@ class Marketplace void sortSellers(); Seller* findSellerWithSellerNo(int sellerNo); void addArticleToBasket(std::unique_ptr
article); + size_t basketSize(); + void finishCurrentSale(); private: SellersVec sellers_; diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 90899c4..ce0bab3 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -11,9 +11,12 @@ find_package(Qt5Widgets CONFIG REQUIRED) set(GUI_SOURCES kima2.cpp mainwindow.cpp + mainwindow.ui sellerdialog.cpp + sellerdialog.ui sellermodel.cpp pricedialog.cpp + pricedialog.ui ) add_executable(kima2 ${GUI_SOURCES}) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index d25c088..77c063e 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -1,7 +1,7 @@ #include "mainwindow.h" -#include "sellerdialog.h" #include "pricedialog.h" +#include "sellerdialog.h" #include @@ -45,28 +45,30 @@ void MainWindow::on_sellerNoEdit_checkSellerNo() auto inputText = ui_.sellerNoEdit->text().toStdString(); if (inputText.empty()) { - + if (marketplace_->basketSize() > 0) { + marketplace_->finishCurrentSale(); + } return; } regex pattern{R"(\d{1,5})"}; smatch result; + if (!regex_match(inputText, result, pattern)) { return; } + int sellerNo = std::stoi(result[0]); auto seller = marketplace_->findSellerWithSellerNo(sellerNo); if (seller) { - std::cout << "!!! Seller gefunden: " << seller->getFirstName() << "\n"; PriceDialog priceDialog(this); auto dialogResult = priceDialog.exec(); - if (dialogResult == QDialog::Accepted) - { + if (dialogResult == QDialog::Accepted) { int price = priceDialog.getPrice(); auto article = std::make_unique
(price); article->setSeller(seller); - std::cout << "!!! Neuer Artikel: " << article->getPrice() << "Cent \n"; + std::cout << "!!! Neuer Artikel: " << article->getPrice() << " Cent \n"; marketplace_->addArticleToBasket(std::move(article)); } } diff --git a/src/gui/mainwindow.ui b/src/gui/mainwindow.ui index 44fe7db..2e26e5f 100644 --- a/src/gui/mainwindow.ui +++ b/src/gui/mainwindow.ui @@ -52,7 +52,54 @@ - + + + + + + + + 197 + 255 + 169 + + + + + + + + + 197 + 255 + 169 + + + + + + + + + 239 + 239 + 239 + + + + + + + + + 75 + true + + + + Eingabe Verk.-Nr. + +