2018-07-30 13:40:58 +02:00
|
|
|
#include "settingsdialog.h"
|
|
|
|
|
2018-08-07 08:31:43 +02:00
|
|
|
#include "mainwindow.h"
|
|
|
|
|
2019-10-10 08:09:16 +02:00
|
|
|
#include <core/database.h>
|
|
|
|
#include <printer/posprinter.h>
|
|
|
|
#include <printer/utils.h>
|
|
|
|
#include <core/utils.h>
|
2018-07-30 13:40:58 +02:00
|
|
|
|
2018-08-06 13:39:12 +02:00
|
|
|
#include <exception>
|
2018-08-15 08:50:46 +02:00
|
|
|
#include <stdexcept>
|
2018-08-06 13:39:12 +02:00
|
|
|
|
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-10-19 08:48:25 +02:00
|
|
|
QString commune = settings.value("global/commune", "Dettingen").toString();
|
2018-08-15 08:03:44 +02:00
|
|
|
QString posPrinterDevice = settings.value("global/posPrinterDevice").toString();
|
2018-08-15 10:51:57 +02:00
|
|
|
QString posPrinterEndpoint = settings.value("global/posPrinterEndpoint").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-10-19 08:48:25 +02:00
|
|
|
ui_.communeEdit->setText(commune);
|
2018-08-15 08:03:44 +02:00
|
|
|
ui_.posPrinterDeviceEdit->setText(posPrinterDevice);
|
2018-08-15 10:51:57 +02:00
|
|
|
ui_.posPrinterEndpointEdit->setText(posPrinterEndpoint);
|
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 {
|
2018-08-15 08:03:44 +02:00
|
|
|
if (ui_.posPrinterDeviceEdit->text().isEmpty()) {
|
|
|
|
PosPrinter printer;
|
|
|
|
printer.printTest();
|
|
|
|
} else {
|
2018-08-15 08:50:46 +02:00
|
|
|
std::string posPrinterDeviceString = ui_.posPrinterDeviceEdit->text().toStdString();
|
2018-08-15 10:51:57 +02:00
|
|
|
std::string posPrinterEndpointString =
|
|
|
|
ui_.posPrinterEndpointEdit->text().toStdString();
|
|
|
|
|
2018-08-15 08:50:46 +02:00
|
|
|
try {
|
2018-08-15 10:51:57 +02:00
|
|
|
auto printerDevice =
|
|
|
|
convertToPosPrinterDevice(posPrinterDeviceString, posPrinterEndpointString);
|
|
|
|
|
|
|
|
if (printerDevice) {
|
|
|
|
PosPrinter printer(*printerDevice);
|
|
|
|
printer.printTest();
|
|
|
|
}
|
|
|
|
|
2018-08-15 08:50:46 +02:00
|
|
|
} catch (std::exception&) {
|
|
|
|
QMessageBox(QMessageBox::Icon::Warning, "Falsche Eingabe",
|
2018-08-15 10:51:57 +02:00
|
|
|
QString("Eingabeformat für Device (hexadezimale IDs): "
|
|
|
|
"<VendorID>:<ProductID>\nBeispiel: 0416:5011\n "
|
|
|
|
"Eingabeformat für Endpoint: Hexadezimale Adresse"),
|
2018-08-15 08:50:46 +02:00
|
|
|
QMessageBox::StandardButton::Ok, this)
|
|
|
|
.exec();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
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-10-19 08:48:25 +02:00
|
|
|
settings.setValue("global/commune", ui_.communeEdit->text().trimmed());
|
2018-08-15 10:51:57 +02:00
|
|
|
settings.setValue("global/posPrinterDevice", ui_.posPrinterDeviceEdit->text().trimmed());
|
|
|
|
settings.setValue("global/posPrinterEndpoint", ui_.posPrinterEndpointEdit->text().trimmed());
|
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();
|
2019-10-10 08:09:16 +02:00
|
|
|
}
|