#include "settingsdialog.h" #include "mainwindow.h" #include #include #include #include #include SettingsDialog::SettingsDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f) { ui_.setupUi(this); QSettings settings{}; int cashPointNo = settings.value("global/cashPointNo").toInt(); // QString posPrinterDevice = settings.value("global/posPrinterDevice").toString(); int feeInPercent = settings.value("global/feeInPercent").toInt(); int maxFeeInEuro = settings.value("global/maxFeeInEuro").toInt(); if (parent) market_ = dynamic_cast(parent)->getMarketplace(); ui_.cashPointNoSpinBox->setValue(cashPointNo); // ui_.posPrinterDeviceEdit->setText(posPrinterDevice); ui_.feePercentSpinBox->setValue(feeInPercent); ui_.maxFeeSpinBox->setValue(maxFeeInEuro); connect(ui_.testPosPrinterButton, &QPushButton::clicked, this, [=]() { using namespace std::string_literals; try { PosPrinter printer; printer.printTest(); if (printer.isValid()) this->ui_.posPrinterDeviceEdit->setText(""); else this->ui_.posPrinterDeviceEdit->setText(""); } catch (std::runtime_error& err) { QMessageBox(QMessageBox::Icon::Warning, "Bondrucker Fehler", QString("Test schlug fehl: ") + err.what(), QMessageBox::StandardButton::Ok, this) .exec(); this->ui_.posPrinterDeviceEdit->setText(""); return; } }); } void SettingsDialog::accept() { QSettings settings; int oldCashPointNo = settings.value("global/cashPointNo").toInt(); int newCashPointNo = ui_.cashPointNoSpinBox->value(); // settings.setValue("global/posPrinterDevice", ui_.posPrinterDeviceEdit->text()); settings.setValue("global/feeInPercent", ui_.feePercentSpinBox->value()); settings.setValue("global/maxFeeInEuro", ui_.maxFeeSpinBox->value()); if (oldCashPointNo != newCashPointNo) { int result{0}; if (market_ && market_->getSales().size() > 0) { result = QMessageBox(QMessageBox::Icon::Question, "Sind Sie sicher?", "Möchten Sie die Kassen-Nr wirklich ändern? Diese muss über alle " "Installationen hinweg eindeutig sein.", QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, this) .exec(); } else { result = QMessageBox::Yes; } if (result == QMessageBox::Yes) { try { Database().updateCashPointNo(oldCashPointNo, newCashPointNo); } catch (std::exception& ex) { std::string errMsg("Das Ändern der Kassen-Nr. ist fehlgeschlagen: "); errMsg.append(ex.what()); QMessageBox(QMessageBox::Icon::Critical, "Fehler", errMsg.c_str(), QMessageBox::StandardButton::Ok, this) .exec(); QDialog::accept(); return; } settings.setValue("global/cashPointNo", ui_.cashPointNoSpinBox->value()); } } QDialog::accept(); }