-
Notifications
You must be signed in to change notification settings - Fork 0
/
placeparking.cpp
244 lines (214 loc) · 7.42 KB
/
placeparking.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#include "placeparking.h"
#include "connexion.h"
#include <QSqlQuery>
#include <QDebug>
PlaceParking::PlaceParking()
{
NumeroPlace=0;
Etat="libre";
Type="proprietaire";
}
PlaceParking::PlaceParking(int numero, QString etat, QString type)
{
NumeroPlace=numero;
Etat=etat;
Type=type;
}
bool PlaceParking::ajouterVehiculeSurParking(int numero_place,QString type,QString etat)
{
QSqlQuery query;
query.prepare("update place_parking set etat=:etat,type=:type where(numero_place=:numero_place)");
query.bindValue(":etat",etat);
query.bindValue(":type",type);
query.bindValue(":numero_place",numero_place);
return query.exec();
}
/*bool PlaceParking::supprimerInviteSurParking(int numero_place,QString type,QString etat)
{
QSqlQuery query;
query.prepare("update place_parking set etat=:etat,type=:type where(numero_place=:numero_place)");
query.bindValue(":etat",etat);
query.bindValue(":type",type);
query.bindValue(":numero_place",numero_place);
return query.exec();
}*/
void PlaceParking::ajouterPlace(int nombre_place)
{
int ajout=0,existe,num=1;
QSqlQuery query;
while (ajout<nombre_place) {
existe=0;
query.prepare("select numero_place from place_parking where numero_place=:numero_place");
query.bindValue(":numero_place",num);
query.exec();
while (query.next()) {
existe=1;
}
if(existe==0)
{
query.prepare("insert into place_parking (numero_place,etat,type) values (:numero_place,:etat,:type)");
query.bindValue(":numero_place",num);
query.bindValue(":etat","libre");
query.bindValue(":type","invite");
query.exec();
ajout++;
}
num++;
}
}
void PlaceParking::nbrPlaces(int* total, int* invite, int *propritaire, int *invitep, int *proprietairep)
{
QSqlQuery query;
query.exec("select * from place_parking");
while (query.next()) {
(*total)++;
}
query.exec("select * from place_parking where type='invite'");
while (query.next()) {
(*invite)++;
}
query.exec("select * from place_parking where type='proprietaire'");
while (query.next()) {
(*propritaire)++;
}
query.exec("select * from place_parking where (type='invite'and etat='occupe')");
while (query.next()) {
(*invitep)++;
}
query.exec("select * from place_parking where (type='proprietaire' and etat='occupe')");
while (query.next()) {
(*proprietairep)++;
}
}
int PlaceParking::calculerNbrPlace()
{
int n=0;
QSqlQuery query;
query.prepare("select * from place_parking");
query.exec();
while (query.next()) {
n++;
}
return n;
}
bool PlaceParking::verifierProprietaire(int numero, QString matricule, int idPro)
{
QSqlQuery query;
query.prepare("select id from vehicule_proprietaire where (numero_place=:numero_place or matricule=:matricule)");
query.bindValue(":numero_place",numero);
query.bindValue(":matricule",matricule);
query.exec();
while (query.next()) {
if(query.value(0).toInt()==idPro)
return true;
qDebug()<< query.value(0).toInt();
}
return false;
}
bool PlaceParking::supprimerToutesPlaceInvite()
{
QSqlQuery query;
return query.exec("delete from place_parking where type='invite'");
}
QSqlQueryModel *PlaceParking::emplacementVIde()
{
QSqlQueryModel *model=new QSqlQueryModel();
model->setQuery("select numero_place from place_parking where (etat='libre' and type='invite') order by numero_place");
model->setHeaderData(0,Qt::Horizontal,"Numero libre");
model->setHeaderData(1,Qt::Horizontal,"Num_invité_present");
return model;
}
QSqlQueryModel *PlaceParking::afficherParking()
{
QSqlQueryModel *model1=new QSqlQueryModel();
//model1->setQuery("select p.numero_place,p.etat,p.type,v.matricule,v.marque, v.id from place_parking p left outer join vehicule_proprietaire v on p.numero_place=v.numero_place order by p.numero_place ");
model1->setQuery("select p.numero_place,p.etat,p.type,v.matricule,v.marque, v.id,m.nom from place_parking p left outer join vehicule_proprietaire v on p.numero_place=v.numero_place left outer join membre m on v.id=m.id order by p.numero_place ");
model1->setHeaderData(0,Qt::Horizontal,"Numero_Place");
model1->setHeaderData(1,Qt::Horizontal,"Etat");
model1->setHeaderData(2,Qt::Horizontal,"Type");
model1->setHeaderData(3,Qt::Horizontal,"Matricule");
return model1;
}
bool PlaceParking::supprimerPlace(int numero_place,QString etat)
{
QSqlQuery query;
QString typ;
query.prepare("select type,numero_place from place_parking where numero_place=:numero_place");
query.bindValue(":numero_place",numero_place);
query.exec();
while (query.next()) {
if(query.value(1).toInt()==numero_place)
{
typ=query.value(0).toString();
}
}
if(typ=="proprietaire")
{
return false;
}
else
{
query.prepare("update place_parking set etat=:etat where(numero_place=:numero_place)");
query.bindValue(":etat",etat);
query.bindValue(":numero_place",numero_place);
return query.exec();
}
}
bool PlaceParking::supprimerPlaceLibre()
{
QSqlQuery query;
return query.exec("delete from place_parking where (type='invite' and etat='libre')");
}
QSqlQueryModel* PlaceParking::rechercheRapide(QString valeur)
{
QSqlQueryModel *model2=new QSqlQueryModel();
model2->setQuery("select p.numero_place,p.etat,p.type,v.matricule,v.marque, v.id,m.nom "
"from place_parking p left outer join vehicule_proprietaire v on p.numero_place=v.numero_place "
"left outer join membre m on v.id=m.id "
"where (p.type like '%"+valeur+"%' or p.etat like '%"+valeur+"%' or p.numero_place like '%"+valeur+"%'"
"or v.matricule like '%"+valeur+"%' or v.marque like '%"+valeur+"%' or v.id like '%"+valeur+"%'"
" or m.nom like '%"+valeur+"%' ) order by p.numero_place");
model2->setHeaderData(0,Qt::Horizontal,"Numero_Place");
model2->setHeaderData(1,Qt::Horizontal,"Etat");
model2->setHeaderData(2,Qt::Horizontal,"Type");
return model2;
}
bool PlaceParking::modifierEtatParking(int numero_place)
{
QSqlQuery query;
QString Nvetat;
query.prepare("select etat from place_parking where (type='proprietaire' and numero_place=:numero) ");
query.bindValue(":numero",numero_place);
query.exec();
while (query.next()) {
if(query.value(0).toString()=="libre")
{
Nvetat="occupe";
}
else if(query.value(0).toString()=="occupe")
{
Nvetat="libre";
}
}
query.prepare("update place_parking set etat=:etat where(numero_place=:numero_place and type='proprietaire' )");
query.bindValue(":etat",Nvetat);
query.bindValue(":numero_place",numero_place);
return query.exec();
}
int PlaceParking::recupererEtat(int numero)
{
QSqlQuery query;
query.prepare("select etat from place_parking where (type='proprietaire' and numero_place=:numero) ");
query.bindValue(":numero",numero);
query.exec();
while (query.next()) {
if(query.value(0).toString()=="libre")
{
return 0;
}
else if(query.value(0).toString()=="occupe")
{
return 1;
}
}
}