-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.cpp
361 lines (309 loc) · 11.6 KB
/
client.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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#include "client.h"
#include <QSqlQuery>
#include <QtDebug>
#include <QString>
#include <QSqlQueryModel>
#include <QObject>
#include <QPdfWriter>
#include <QPainter>
client::client()
{
nom="";
prenom="";
telephone=0;
adresse="";
id=0;
bonus=0;
reclamation=0;
email="";
cin=0;
}
client::client(int id,QString nom,QString prenom,int cin,QString adresse,int telephone,QString email,int bonus,int reclamation)
{
this->id=id;
this->cin=cin;
this->nom=nom;
this->prenom=prenom;
this->email=email;
this->adresse=adresse;
this->bonus=bonus;
this->telephone=telephone;
this->reclamation=reclamation;
}
//set
void client::setID(int id){this->id=id;}
void client::setnom(QString nom){this->nom=nom;}
void client::setprenom(QString prenom){this->prenom=prenom;}
void client::setcin(int cin){this->cin=cin;}
void client::setadresse(QString adresse){this->adresse=adresse;}
void client::settelephone(int telephone){this->telephone=telephone;}
void client::setemail(QString email){this->email=email;}
void client::setbonus(int bonus){this->bonus=bonus;}
void client::setreclamation(int reclamation){this->reclamation=reclamation;}
//get
int client::get_id(){return id;}
QString client::get_nom(){return nom;}
QString client::get_prenom(){return prenom;}
int client::get_cin(){return cin;}
QString client::get_adresse(){return adresse;}
int client::get_telephone(){return telephone;}
QString client::get_email(){return email;}
int client::get_bonus(){return bonus;}
int client::get_reclamation(){return reclamation;}
//functions
bool client::ajouter_client()
{
QString id_string= QString::number(id);
QString id_cin= QString::number(cin);
QString id_bonus= QString::number(bonus);
QString id_reclamation= QString::number(reclamation);
QString id_telephone= QString::number(telephone);
QSqlQuery query;
query.prepare("INSERT INTO client (ID_CLIENT, NOM, PRENOM, CIN, ADRESSE, TELEPHONE, EMAIL, BONUS, RECLAMATION) "
"VALUES (:id, :nom, :prenom, :cin, :adresse, :telephone, :email, :bonus, :reclamation)");
query.bindValue(":id", id_string);
query.bindValue(":nom", nom);
query.bindValue(":prenom", prenom);
query.bindValue(":cin", cin);
query.bindValue(":adresse", adresse);
query.bindValue(":telephone", telephone);
query.bindValue(":email", email);
query.bindValue(":bonus", bonus);
query.bindValue(":reclamation", reclamation);
return query.exec();
}
QSqlQueryModel* client::afficher()
{
QSqlQueryModel* Model= new QSqlQueryModel();
Model->setQuery("SELECT* FROM client");
Model->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
Model->setHeaderData(1, Qt::Horizontal, QObject::tr("Nom"));
Model->setHeaderData(2, Qt::Horizontal, QObject::tr("Prenom"));
Model->setHeaderData(3, Qt::Horizontal, QObject::tr("Cin"));
Model->setHeaderData(4, Qt::Horizontal, QObject::tr("Adresse"));
Model->setHeaderData(5, Qt::Horizontal, QObject::tr("Telephone"));
Model->setHeaderData(6, Qt::Horizontal, QObject::tr("Email"));
Model->setHeaderData(7, Qt::Horizontal, QObject::tr("Bonus (DT)"));
Model->setHeaderData(8, Qt::Horizontal, QObject::tr("Reclamation"));
return Model;
}
QSqlQueryModel* client::afficher_d()
{
QSqlQueryModel* Model= new QSqlQueryModel();
Model->setQuery("SELECT* FROM client order by ID_CLIENT DESC");
Model->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
Model->setHeaderData(1, Qt::Horizontal, QObject::tr("Nom"));
Model->setHeaderData(2, Qt::Horizontal, QObject::tr("Prenom"));
Model->setHeaderData(3, Qt::Horizontal, QObject::tr("Cin"));
Model->setHeaderData(4, Qt::Horizontal, QObject::tr("Adresse"));
Model->setHeaderData(5, Qt::Horizontal, QObject::tr("Telephone"));
Model->setHeaderData(6, Qt::Horizontal, QObject::tr("Email"));
Model->setHeaderData(7, Qt::Horizontal, QObject::tr("Bonus (DT)"));
Model->setHeaderData(8, Qt::Horizontal, QObject::tr("Reclamation"));
return Model;
}
QSqlQueryModel* client::afficher_c()
{
QSqlQueryModel* Model= new QSqlQueryModel();
Model->setQuery("SELECT* FROM client order by ID_CLIENT ASC");
Model->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
Model->setHeaderData(1, Qt::Horizontal, QObject::tr("Nom"));
Model->setHeaderData(2, Qt::Horizontal, QObject::tr("Prenom"));
Model->setHeaderData(3, Qt::Horizontal, QObject::tr("Cin"));
Model->setHeaderData(4, Qt::Horizontal, QObject::tr("Adresse"));
Model->setHeaderData(5, Qt::Horizontal, QObject::tr("Telephone"));
Model->setHeaderData(6, Qt::Horizontal, QObject::tr("Email"));
Model->setHeaderData(7, Qt::Horizontal, QObject::tr("Bonus (DT)"));
Model->setHeaderData(8, Qt::Horizontal, QObject::tr("Reclamation"));
return Model;
}
bool client::supprimer_client(int id)
{
QSqlQuery query;
query.prepare("DELETE FROM CLIENT WHERE ID_CLIENT=:id");
query.bindValue(0, id);
return query.exec();
}
bool client::modifier_client(int id)
{
QSqlQuery query;
QString id_string= QString::number(id);
QString id_cin= QString::number(cin);
QString id_bonus= QString::number(bonus);
QString id_reclamation= QString::number(reclamation);
QString id_telephone= QString::number(telephone);
query.prepare("UPDATE CLIENT SET ID_CLIENT=:id , NOM=:nom , PRENOM=:prenom , CIN=:cin , ADRESSE=:adresse , TELEPHONE=:telephone , EMAIL=:email WHERE ID_CLIENT=:id");
query.bindValue(":id", id_string);
query.bindValue(":nom", nom);
query.bindValue(":prenom", prenom);
query.bindValue(":cin", id_cin);
query.bindValue(":adresse", adresse);
query.bindValue(":telephone", id_telephone);
query.bindValue(":email", email);
return query.exec();
}
bool client::ajouter_averti(int id,int recl)
{
QSqlQuery query;
int r;
QString id_string= QString::number(id);
//QString id_reclamation= QString::number(recl);
//QString id_reclamation= QString::number(reclamation);
//reclamation
query.prepare("SELECT* FROM client WHERE ID_CLIENT=:id");
query.bindValue(":id", id);
query.exec();
while (query.next()) {
r=query.value("RECLAMATION").toInt();
}
recl=recl+r;
//update reclamation
query.prepare("UPDATE CLIENT SET RECLAMATION=:reclamation WHERE ID_CLIENT=:id");
query.bindValue(":reclamation", recl);
query.bindValue(":id", id);
return query.exec();
}
int client::reduction_averti(int id,int recl)
{
QSqlQuery query;
int b=0,r=0;
QString id_string= QString::number(id);
//QString id_reclamation= QString::number(recl);
//QString id_reclamation= QString::number(reclamation);
query.prepare("SELECT* FROM client WHERE ID_CLIENT=:id");
query.bindValue(":id", id);
query.exec();
while (query.next()) {
b=query.value("BONUS").toInt();
//recl = query.value("RECLAMATION").toInt();
b=b-(recl*2);
}
query.prepare("UPDATE CLIENT SET BONUS=:bonus WHERE ID_CLIENT=:id");
query.bindValue(":bonus", b);
query.bindValue(":id", id);
query.exec();
return r;
}
bool client::update_bonus(int id)
{
QSqlQuery query;
int bon=0,qte=0;
QString id_string= QString::number(id);
//QString id_reclamation= QString::number(recl);
//QString id_reclamation= QString::number(reclamation);
//quantité
query.prepare("SELECT * FROM VOITURE JOIN CLIENT ON VOITURE.ID_CLIENT=CLIENT.ID_CLIENT WHERE VOITURE.ID_CLIENT=:id");
query.bindValue(":id", id);
query.exec();
while (query.next()) {
qte = query.value("QUNATITE").toInt();
}
//bonus
query.prepare("SELECT* FROM client WHERE ID_CLIENT=:id");
query.bindValue(":id", id);
query.exec();
while (query.next()) {
bon=query.value("BONUS").toInt();
}
bon=bon+(qte*3);
qDebug() << "bon =" << bon;
//update bonus
query.prepare("UPDATE CLIENT SET BONUS=:bonus WHERE ID_CLIENT=:id");
query.bindValue(":bonus", bon);
query.bindValue(":id", id);
query.exec();
//
query.prepare("UPDATE VOITURE SET QUNATITE=:quantite WHERE ID_CLIENT=:id");
query.bindValue(":quantite", 0);
query.bindValue(":id", id);
query.exec();
}
bool client::happy_hour(int id)
{
QSqlQuery query;
int recl;
query.prepare("SELECT* FROM client WHERE ID_CLIENT=:id");
query.bindValue(":id", id);
query.exec();
while (query.next()) {
recl=query.value("RECLAMATION").toInt();
qDebug()<<"hello"<<recl;
}
if (recl<15)
{
return true;
}
else{ return false;}
}
void client::pdf()
{
QPdfWriter pdf("C:/Users/youss/OneDrive/Documents/Pro/work.pdf");
QPainter painter(&pdf);
int i = 4000;
painter.setPen(Qt::green);
painter.setFont(QFont("Arial",30));
painter.drawText(2400,1600,"GESTION CLIENT");
painter.setPen(Qt::Key_Blue);
painter.setFont(QFont("Arial",14));
painter.drawRect(100,100,9600,2600);
painter.drawRect(0,3000,9600,500);
painter.setFont(QFont("Arial",11));
painter.drawText(200,3300,"ID");
painter.drawText(800,3300,"NOM");
painter.drawText(1600,3300,"PRENOM");
painter.drawText(2800,3300,"CIN");
painter.drawText(3500,3300,"ADRESSE");
painter.drawText(4600,3300,"TELEPHONE");
painter.drawText(6000,3300,"EMAIL");
painter.drawText(6900,3300,"BONUS");
painter.drawText(7800,3300,"RECLAMATION");
QSqlQuery query;
query.prepare("SELECT * FROM CLIENT");
query.exec();
while (query.next())
{
painter.drawText(200,i,query.value(0).toString());
painter.drawText(800,i,query.value(1).toString());
painter.drawText(1800,i,query.value(2).toString());
painter.drawText(2800,i,query.value(3).toString());
painter.drawText(3500,i,query.value(4).toString());
painter.drawText(4500,i,query.value(5).toString());
painter.drawText(6000,i,query.value(6).toString());
painter.drawText(7000,i,query.value(7).toString());
painter.drawText(7800,i,query.value(8).toString());
i = i + 500;
}
}
QSqlQueryModel * client::afficher_search(QString ch)
{
QSqlQueryModel * model=new QSqlQueryModel();
model->setQuery("SELECT * from CLIENT WHERE PRENOM LIKE '%"+ch+"%'");
model->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("Nom"));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("Prenom"));
model->setHeaderData(3, Qt::Horizontal, QObject::tr("Cin"));
model->setHeaderData(4, Qt::Horizontal, QObject::tr("Adresse"));
model->setHeaderData(5, Qt::Horizontal, QObject::tr("Telephone"));
model->setHeaderData(6, Qt::Horizontal, QObject::tr("Email"));
model->setHeaderData(7, Qt::Horizontal, QObject::tr("Bonus (DT)"));
model->setHeaderData(8, Qt::Horizontal, QObject::tr("Reclamation"));
return model;
}
bool client::delete_all(){
QSqlQuery query;
query.prepare("Delete from CLIENT");
return query.exec();
}
bool client::test_maintenance(int id){
QSqlQuery query;
query.prepare("SELECT ID_MAINTENANCE FROM MAINTENANCE WHERE ID_MAINTENANCE=:idd");
query.bindValue(":idd", id);
query.exec();
if (query.next()){
return true;
}
else
{
return false;
}
}