-
Notifications
You must be signed in to change notification settings - Fork 0
/
porte.cpp
64 lines (56 loc) · 1.37 KB
/
porte.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
#include "porte.h"
Porte::Porte()
{
Reference="p";
Etat="";
}
Porte::Porte(QString ref,QString etat)
{
Reference=ref;
Etat=etat;
}
void Porte::setEtat(QString etat)
{Etat=etat;}
QString Porte::getEtat()
{return Etat;}
void Porte::setReference(QString ref)
{Reference=ref;}
QString Porte::getReference()
{return Reference;}
bool Porte::Ajouter(QString etat)
{
QSqlQueryModel *model=new QSqlQueryModel();
model->setQuery("select * from Porte");
int num=model->rowCount()+1;
QString Reference="p"+QString::number(num);
QSqlQuery query;
qDebug()<<Reference;
query.prepare("Insert INTO Porte(Reference,Etat) VALUES(?,?)");
query.addBindValue(Reference);
query.addBindValue(etat);
if(query.exec()){
return true;}
return false;
}
void Porte::afficher(QTableWidget *t)
{
QSqlQuery qry;
int i;
int j=0;
qry.exec("select * from Porte");
while(qry.next()){
j++;
}
t->setRowCount(j);
t->setColumnCount(2);
t->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
t->setHorizontalHeaderLabels(QString("Etat;Reference").split(";"));
i=1;
qry.exec("select* from Porte");
while(qry.next())
{
t->setItem(i-1,0,new QTableWidgetItem(qry.value(0).toString()));
t->setItem(i-1,1,new QTableWidgetItem(qry.value(1).toString()));
i++;
}
}