-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTDBClopes.cpp
75 lines (54 loc) · 1.74 KB
/
TDBClopes.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
73
74
75
#include "TDBClopes.h"
TDBClopes::TDBClopes(QWidget* parent) :
QDialog(parent)
{
marque_combo = new QComboBox(this);
TDBDatabase::open();
QSqlQuery query;
query.prepare("SELECT marque, prix FROM clopes");
query.exec();
if(query.first())
marque_combo->addItem(query.record().value("marque").toString());
while(query.next())
marque_combo->addItem(query.record().value("marque").toString());
TDBDatabase::close();
setWindowTitle("Achat clopes");
marque_label = new QLabel("Marque", this);
quantite_label = new QLabel("Quantité", this);
quantite_spin = new QSpinBox(this);
quantite_spin->setValue(1);
quantite_spin->setMinimum(1);
layout = new QGridLayout(this);
layout->addWidget(marque_label, 0, 0);
layout->addWidget(quantite_label, 1, 0);
layout->addWidget(marque_combo, 0, 1);
layout->addWidget(quantite_spin, 1, 1);
ok_button = new QPushButton("OK", this);
layout->addWidget(ok_button, 2, 0);
cancel_button = new QPushButton("Cancel", this);
layout->addWidget(cancel_button, 2, 1);
setLayout(layout);
connect(cancel_button, SIGNAL(pressed()), this, SLOT(cancel_pressed()));
connect(ok_button, SIGNAL(pressed()), this, SLOT(ok_pressed()));
}
TDBClopes::~TDBClopes()
{
}
void TDBClopes::cancel_pressed()
{
reject();
}
void TDBClopes::ok_pressed()
{
TDBDatabase::open();
marque = marque_combo->currentText();
quantite = quantite_spin->value();
QSqlQuery query;
query.prepare("SELECT prix FROM clopes WHERE marque = :marque");
query.bindValue(":marque", marque);
query.exec();
query.first();
montant = query.record().value("prix").toInt() * quantite;
TDBDatabase::close();
accept();
}