-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindowArticle.cpp
72 lines (60 loc) · 2 KB
/
windowArticle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "windowArticle.h"
#include "ui_windowArticle.h"
#include <QMessageBox>
WindowArticle::WindowArticle(QWidget *parent, Articles *article, DBManager *dbmanager) :
QDialog(parent),
ui(new Ui::WindowArticle),
m_dbManager(dbmanager)
{
ui->setupUi(this);
setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint);
ui->leArtNr->setText(QString::number(article->getArtNr()));
ui->leArtUnit->setText(article->getUnit());
ui->leArtPrice->setText(QLocale().toCurrencyString(article->getPrice()).split(" ").value(0));
ui->ptArtDescription->setPlainText(article->getDescription());
QDoubleValidator* spValidator= new QDoubleValidator(0.0, 9999999999.0, 2, ui->leArtPrice);
spValidator->setLocale(QLocale("de_DE"));
spValidator->setNotation(QDoubleValidator::StandardNotation);
ui->leArtPrice->setValidator(spValidator);
}
WindowArticle::~WindowArticle()
{
delete ui;
}
Articles WindowArticle::getArticle()
{
Articles article;
article.setArtNr(ui->leArtNr->text().toInt());
article.setPrice(ui->leArtPrice->text().toDouble());
article.setUnit(ui->leArtUnit->text());
article.setDescription(ui->ptArtDescription->toPlainText());
return article;
}
void WindowArticle::on_btnArtCancel_clicked()
{
reject();
}
void WindowArticle::on_btnArtSave_clicked()
{
int artnr = ui->leArtNr->text().toInt();
QString unit = ui->leArtUnit->text();
double price = ui->leArtPrice->text().replace(".", "").replace(",", ".").toDouble();
QString description = ui->ptArtDescription->toPlainText();
Articles article(artnr, description, unit, price);
if (m_dbManager->editArticle(QString::number(artnr), article))
{
accept();
}
else
{
QMessageBox::critical(this, "Error", "Fehler beim bearbeiten des Artikels!", QMessageBox::Ok);
reject();
}
}
void WindowArticle::clearArticleEdits()
{
ui->leArtNr->clear();
ui->leArtPrice->clear();
ui->leArtUnit->clear();
ui->ptArtDescription->clear();
}