Find seller by sellerno

This commit is contained in:
Martin Brodbeck 2018-07-20 22:07:42 +02:00
parent 19375a7752
commit 0ad460346c
5 changed files with 53 additions and 9 deletions

View file

@ -2,6 +2,8 @@
#include "sellerdialog.h"
#include <regex>
constexpr int STATUSBAR_TIMEOUT = 5000;
MainWindow::MainWindow()
@ -11,6 +13,8 @@ MainWindow::MainWindow()
connect(ui_.actionQuit, &QAction::triggered, qApp, QApplication::quit);
connect(ui_.actionEditSeller, &QAction::triggered, this,
&MainWindow::on_actionEditSeller_triggered);
connect(ui_.sellerNoEdit, &QLineEdit::returnPressed, this,
&MainWindow::on_sellerNoEdit_checkSellerNo);
marketplace_ = std::make_unique<Marketplace>();
marketplace_->loadFromDb();
@ -31,4 +35,31 @@ void MainWindow::on_actionEditSeller_triggered()
statusBar()->showMessage("Änderungen an den Verkäufer-Stammdaten verworfen!",
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();
}