-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparking.cpp
105 lines (86 loc) · 2.51 KB
/
parking.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "parking.h"
#include <QMessageBox>
Parking::Parking(int Reference, int Place, QString Nom)
{
reference=Reference;
place=Place;
this->nom=Nom;
}
bool Parking::ajouter()
{
QSqlQuery query;
QString res = QString::number(reference);
query.prepare("INSERT INTO PARKING (REFERENCE, PLACE, NOM) "
"VALUES (:reference, :place, :nom)");
query.bindValue(":reference",reference);
query.bindValue(":place",place);
query.bindValue(":nom",nom);
return query.exec();
}
QSqlQueryModel * Parking::afficher()
{
QSqlQueryModel * model = new QSqlQueryModel();
model->setQuery("select * from parking");
model->setHeaderData(0,Qt::Horizontal,QObject::tr("reference"));
model->setHeaderData(1,Qt::Horizontal,QObject::tr("place"));
model->setHeaderData(2,Qt::Horizontal,QObject::tr("nom"));
return model;
}
bool Parking::supprimer(int reference)
{
QSqlQuery query;
QString res = QString::number(reference);
query.prepare("Delete from parking where reference=:reference");
query.bindValue(":reference",res);
return query.exec();
}
QSqlQueryModel * Parking::trier(int test)
{
QSqlQueryModel *model=new QSqlQueryModel() ;
QSqlQuery query ;
model->setHeaderData(0, Qt::Horizontal, QObject::tr("REFERENCE"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("PLACE "));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("nom"));
if(test==1)
{
query.prepare("SELECT * FROM parking ORDER BY REFERENCE ASC ") ;
}
else if(test==2)
{
query.prepare("SELECT * FROM parking ORDER BY NOM ASC ") ;
}
else if(test==3)
{
query.prepare("SELECT * FROM parking ORDER BY PLACE ASC ") ;
}
if (query.exec()&&query.next())
{
model->setQuery(query) ;
}
return model;
}
QSqlQueryModel *Parking::recherche(QString nom,int place)
{
QSqlQuery query;
QSqlQueryModel *model = new QSqlQueryModel();
int c=0;
query.prepare("SELECT *from parking where NOM=:nom or place=:place ");
query.bindValue(":place",place);
query.bindValue(":nom",nom);
if(query.exec())
{
while(query.next())
{
c++;
}
if(c==1)
{
model->setQuery(query);
}
if(c<1)
{
model=0;
}
}
return model;
}