2018-07-30 13:40:58 +02:00
|
|
|
#include "settingsdialog.h"
|
|
|
|
|
2018-08-07 08:31:43 +02:00
|
|
|
#include "mainwindow.h"
|
|
|
|
|
2018-07-30 13:40:58 +02:00
|
|
|
#include <database.h>
|
2018-08-06 09:59:06 +02:00
|
|
|
#include <posprinter.h>
|
2018-07-30 13:40:58 +02:00
|
|
|
|
2018-08-06 13:39:12 +02:00
|
|
|
#include <exception>
|
|
|
|
|
2018-07-30 13:40:58 +02:00
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QSettings>
|
|
|
|
|
|
|
|
SettingsDialog::SettingsDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f)
|
|
|
|
{
|
|
|
|
ui_.setupUi(this);
|
|
|
|
|
|
|
|
QSettings settings{};
|
|
|
|
int cashPointNo = settings.value("global/cashPointNo").toInt();
|
2018-08-06 20:57:12 +02:00
|
|
|
// QString posPrinterDevice = settings.value("global/posPrinterDevice").toString();
|
2018-07-30 13:40:58 +02:00
|
|
|
int feeInPercent = settings.value("global/feeInPercent").toInt();
|
|
|
|
int maxFeeInEuro = settings.value("global/maxFeeInEuro").toInt();
|
|
|
|
|
2018-08-07 20:39:15 +02:00
|
|
|
if (parent)
|
|
|
|
market_ = dynamic_cast<MainWindow*>(parent)->getMarketplace();
|
2018-08-07 08:31:43 +02:00
|
|
|
|
2018-07-30 13:40:58 +02:00
|
|
|
ui_.cashPointNoSpinBox->setValue(cashPointNo);
|
2018-08-06 20:57:12 +02:00
|
|
|
// ui_.posPrinterDeviceEdit->setText(posPrinterDevice);
|
2018-07-30 13:40:58 +02:00
|
|
|
ui_.feePercentSpinBox->setValue(feeInPercent);
|
|
|
|
ui_.maxFeeSpinBox->setValue(maxFeeInEuro);
|
2018-08-06 09:59:06 +02:00
|
|
|
|
2018-08-06 13:39:12 +02:00
|
|
|
connect(ui_.testPosPrinterButton, &QPushButton::clicked, this, [=]() {
|
|
|
|
using namespace std::string_literals;
|
|
|
|
try {
|
|
|
|
PosPrinter printer;
|
|
|
|
printer.printTest();
|
2018-08-06 20:57:12 +02:00
|
|
|
if (printer.isValid())
|
|
|
|
this->ui_.posPrinterDeviceEdit->setText("<gefunden>");
|
|
|
|
else
|
|
|
|
this->ui_.posPrinterDeviceEdit->setText("<nicht gefunden>");
|
|
|
|
|
2018-08-06 13:39:12 +02:00
|
|
|
} catch (std::runtime_error& err) {
|
|
|
|
QMessageBox(QMessageBox::Icon::Warning, "Bondrucker Fehler",
|
2018-08-06 20:57:12 +02:00
|
|
|
QString("Test schlug fehl: ") + err.what(), QMessageBox::StandardButton::Ok,
|
|
|
|
this)
|
2018-08-06 13:39:12 +02:00
|
|
|
.exec();
|
2018-08-06 20:57:12 +02:00
|
|
|
this->ui_.posPrinterDeviceEdit->setText("<Fehler>");
|
|
|
|
return;
|
2018-08-06 13:39:12 +02:00
|
|
|
}
|
2018-08-06 09:59:06 +02:00
|
|
|
});
|
2018-07-30 13:40:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SettingsDialog::accept()
|
|
|
|
{
|
|
|
|
QSettings settings;
|
|
|
|
|
|
|
|
int oldCashPointNo = settings.value("global/cashPointNo").toInt();
|
|
|
|
int newCashPointNo = ui_.cashPointNoSpinBox->value();
|
|
|
|
|
2018-08-06 20:57:12 +02:00
|
|
|
// settings.setValue("global/posPrinterDevice", ui_.posPrinterDeviceEdit->text());
|
2018-07-30 13:40:58 +02:00
|
|
|
settings.setValue("global/feeInPercent", ui_.feePercentSpinBox->value());
|
|
|
|
settings.setValue("global/maxFeeInEuro", ui_.maxFeeSpinBox->value());
|
|
|
|
|
|
|
|
if (oldCashPointNo != newCashPointNo) {
|
2018-08-07 08:31:43 +02:00
|
|
|
int result{0};
|
2018-08-07 20:39:15 +02:00
|
|
|
if (market_ && market_->getSales().size() > 0) {
|
2018-08-07 08:31:43 +02:00
|
|
|
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;
|
|
|
|
}
|
2018-07-30 13:40:58 +02:00
|
|
|
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());
|
2018-08-06 13:39:12 +02:00
|
|
|
QMessageBox(QMessageBox::Icon::Critical, "Fehler", errMsg.c_str(),
|
|
|
|
QMessageBox::StandardButton::Ok, this)
|
2018-07-30 13:40:58 +02:00
|
|
|
.exec();
|
|
|
|
QDialog::accept();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
settings.setValue("global/cashPointNo", ui_.cashPointNoSpinBox->value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QDialog::accept();
|
|
|
|
}
|