KIMA2 ist ein kleines Kassenprogramm für Kindersachenmärkte. https://www.rustysoft.de/?01_kima2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

75 lines
2.3 KiB

#include "mainwindow.h"
#include "sellerdialog.h"
#include "pricedialog.h"
#include <regex>
constexpr int STATUSBAR_TIMEOUT = 5000;
MainWindow::MainWindow()
{
ui_.setupUi(this);
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();
statusBar()->showMessage("Gespeicherte Daten wurden geladen.", STATUSBAR_TIMEOUT);
}
void MainWindow::on_actionEditSeller_triggered()
{
auto dialog = std::make_unique<SellerDialog>(this);
int retCode = dialog->exec();
if (retCode == QDialog::Accepted) {
marketplace_->sortSellers();
marketplace_->storeToDb();
statusBar()->showMessage("Änderungen an den Verkäufer-Stammdaten gespeichert.",
STATUSBAR_TIMEOUT);
} else {
marketplace_->loadFromDb();
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";
PriceDialog priceDialog(this);
auto dialogResult = priceDialog.exec();
if (dialogResult == QDialog::Accepted)
{
int price = priceDialog.getPrice();
auto article = std::make_unique<Article>(price);
article->setSeller(seller);
std::cout << "!!! Neuer Artikel: " << article->getPrice() << "Cent \n";
marketplace_->addArticleToBasket(std::move(article));
}
}
ui_.sellerNoEdit->clear();
}