Find seller by sellerno
This commit is contained in:
parent
19375a7752
commit
0ad460346c
5 changed files with 53 additions and 9 deletions
|
@ -42,3 +42,14 @@ int Marketplace::getNumSellersDelete()
|
||||||
}
|
}
|
||||||
|
|
||||||
void Marketplace::sortSellers() { std::sort(sellers_.begin(), sellers_.end()); }
|
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;
|
||||||
|
});
|
||||||
|
if (iter == sellers_.end())
|
||||||
|
return nullptr;
|
||||||
|
return (*iter).get();
|
||||||
|
}
|
|
@ -26,6 +26,7 @@ class Marketplace
|
||||||
int getNextSellerNo();
|
int getNextSellerNo();
|
||||||
int getNumSellersDelete();
|
int getNumSellersDelete();
|
||||||
void sortSellers();
|
void sortSellers();
|
||||||
|
Seller* findSellerWithSellerNo(int sellerNo);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SellersVec sellers_;
|
SellersVec sellers_;
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include "sellerdialog.h"
|
#include "sellerdialog.h"
|
||||||
|
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
constexpr int STATUSBAR_TIMEOUT = 5000;
|
constexpr int STATUSBAR_TIMEOUT = 5000;
|
||||||
|
|
||||||
MainWindow::MainWindow()
|
MainWindow::MainWindow()
|
||||||
|
@ -11,6 +13,8 @@ MainWindow::MainWindow()
|
||||||
connect(ui_.actionQuit, &QAction::triggered, qApp, QApplication::quit);
|
connect(ui_.actionQuit, &QAction::triggered, qApp, QApplication::quit);
|
||||||
connect(ui_.actionEditSeller, &QAction::triggered, this,
|
connect(ui_.actionEditSeller, &QAction::triggered, this,
|
||||||
&MainWindow::on_actionEditSeller_triggered);
|
&MainWindow::on_actionEditSeller_triggered);
|
||||||
|
connect(ui_.sellerNoEdit, &QLineEdit::returnPressed, this,
|
||||||
|
&MainWindow::on_sellerNoEdit_checkSellerNo);
|
||||||
|
|
||||||
marketplace_ = std::make_unique<Marketplace>();
|
marketplace_ = std::make_unique<Marketplace>();
|
||||||
marketplace_->loadFromDb();
|
marketplace_->loadFromDb();
|
||||||
|
@ -32,3 +36,30 @@ void MainWindow::on_actionEditSeller_triggered()
|
||||||
STATUSBAR_TIMEOUT);
|
STATUSBAR_TIMEOUT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_sellerNoEdit_checkSellerNo()
|
||||||
|
{
|
||||||
|
using std::regex, std::regex_match, std::smatch;
|
||||||
|
|
||||||
|
auto inputText = ui_.sellerNoEdit->text().toStdString();
|
||||||
|
|
||||||
|
if (inputText.empty()) {
|
||||||
|
|
||||||
|
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";
|
||||||
|
// TODO: Warenkorb füllen
|
||||||
|
}
|
||||||
|
|
||||||
|
ui_.sellerNoEdit->clear();
|
||||||
|
}
|
|
@ -13,15 +13,16 @@ class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MainWindow();
|
MainWindow();
|
||||||
Marketplace* getMarketplace() {return marketplace_.get();}
|
Marketplace* getMarketplace() { return marketplace_.get(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void on_actionEditSeller_triggered();
|
void on_actionEditSeller_triggered();
|
||||||
|
void on_sellerNoEdit_checkSellerNo();
|
||||||
|
|
||||||
Ui::MainWindow ui_;
|
Ui::MainWindow ui_;
|
||||||
std::unique_ptr<Marketplace> marketplace_;
|
std::unique_ptr<Marketplace> marketplace_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -52,10 +52,10 @@
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="lineEdit"/>
|
<widget class="QLineEdit" name="sellerNoEdit"/>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton_3">
|
<widget class="QPushButton" name="paidButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Bezahlt!</string>
|
<string>Bezahlt!</string>
|
||||||
</property>
|
</property>
|
||||||
|
|
Loading…
Reference in a new issue