-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTDBClopesModification.cpp
69 lines (49 loc) · 1.78 KB
/
TDBClopesModification.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
#include "TDBClopesModification.h"
TDBClopesModification::TDBClopesModification(QWidget* parent, QString m) : QDialog(parent)
{
setWindowTitle("Modification de clopes");
layout = new QGridLayout(this);
marque_label = new QLabel("marque", this);
prix_label = new QLabel("prix", this);
marque_edit = new QLineEdit();
prix_edit = new QLineEdit();
prix_edit->setValidator(new QDoubleValidator(this));
ok_button = new QPushButton("OK", this);
cancel_button = new QPushButton("Annuler", this);
marque = m;
TDBDatabase::open();
QSqlQuery query;
query.prepare("SELECT prix/100 as prix FROM clopes WHERE marque = :marque");
query.bindValue(":marque", marque);
query.exec();
query.first();
TDBDatabase::close();
marque_edit->setText(marque);
prix_edit->setText(query.record().value("prix").toString());
layout->addWidget(marque_label, 0, 0);
layout->addWidget(prix_label, 1, 0);
layout->addWidget(marque_edit, 0, 1);
layout->addWidget(prix_edit, 1, 1);
layout->addWidget(ok_button, 2, 0);
layout->addWidget(cancel_button, 2, 1);
connect(ok_button, SIGNAL(pressed()), this, SLOT(ok_pressed()));
connect(cancel_button, SIGNAL(pressed()), this, SLOT(cancel_pressed()));
}
TDBClopesModification::~TDBClopesModification()
{}
void TDBClopesModification::cancel_pressed()
{
reject();
}
void TDBClopesModification::ok_pressed()
{
TDBDatabase::open();
QSqlQuery query;
query.prepare("UPDATE clopes SET marque = :marque, prix = :prix WHERE marque = :oldmarque");
query.bindValue(":marque", marque_edit->text());
query.bindValue(":prix", (int)(prix_edit->text().toDouble()*100+0.5));
query.bindValue(":oldmarque", marque);
query.exec();
TDBDatabase::close();
accept();
}