-
Notifications
You must be signed in to change notification settings - Fork 0
/
membre.cpp
215 lines (203 loc) · 5.25 KB
/
membre.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
#include"membre.h"
//#include "connexion.h"
#include<QTime>
Membre::Membre()
{
Nom="";
Prenom="";
MotPass="";
Id=0;
}
Membre::Membre( int id,QString nom, QString prenom, QString mdp,QString email)
{
Id=id;
Nom=nom;
Prenom=prenom;
MotPass=mdp;
Email=email;
}
void Membre::setNom(QString nom)
{
Nom=nom;
}
void Membre::setPrenom(QString prenom)
{
Prenom=prenom;
}
void Membre::setMot_de_passe(QString mdp)
{
MotPass=mdp;
}
QString Membre ::getNom()
{
return Nom;
}
QString Membre ::getPrenom()
{
return Prenom;
}
QString Membre ::getMot_de_passe()
{
return MotPass;
}
void Membre::setId(int id)
{
Id=id;
}
int Membre::getId()
{
return Id;
}
bool Membre::Ajouter(int id, QString nom, QString prenom, QString mdp )
{
QSqlQuery query;
QString res= QString::number(id);
query.prepare("Insert INTO Membre(Id,Nom,Prenom,MotPass) VALUES(?,?,?,?)");
query.addBindValue(res);
query.addBindValue(nom) ;
query.addBindValue(prenom);
query.addBindValue(mdp);
if(query.exec())
return true;
return false;
}
bool Membre::verifierAdmin(int id)
{
QSqlQuery query;
query.prepare("select id from admin where id=:id");
query.bindValue(":id",id);
query.exec();
while (query.next()) {
if(query.value(0).toInt()==id)
return true;
}
return false;
}
void Membre::afficher(QTableWidget *t)
{
QSqlQuery qry;
int i;
int j=0;
qry.exec("select * from Membre");
while(qry.next()){
j++;
}
t->setRowCount(j);
t->setColumnCount(4);
t->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
t->setHorizontalHeaderLabels(QString("Id;Nom;Prenom;MotPass").split(";"));
i=1;
qry.exec("select* from Membre");
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()));
t->setItem(i-1,2,new QTableWidgetItem(qry.value(2).toString()));
t->setItem(i-1,3,new QTableWidgetItem(qry.value(3).toString()));
i++;
}
}
bool Membre::suprimer(int id)
{
QSqlQuery query;
QString res=QString ::number(id);
query.prepare("Delete from Membre where Id=:id");
query.addBindValue(res);
return query.exec();
}
bool Membre::Modifier(QString mdp,int id)
{
QSqlQuery query;
query.prepare("Update Membre set MotPass=:mdp where Id=:id");
setMot_de_passe(mdp);
query.bindValue(":mdp",mdp);
query.bindValue(":id",id);
return query.exec();
}
bool Membre::Historique(QTableWidget *t,int id,QString mdp)
{ if(verifier(id,mdp))
{
QSqlQuery qry;
QDate date;
t->setRowCount(25);
t->setColumnCount(2);
t->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
t->setHorizontalHeaderLabels(QString("Nom;Date").split(";"));
int i=1;
t->setItem(i-1,0,new QTableWidgetItem(QString::number(id)));
t->setItem(i-1,1,new QTableWidgetItem(date.currentDate().toString()));
i++;
return true;
}
return false ;
}
bool Membre::verifier(int id ,QString mdp)
{
QSqlQuery qry;
qry.exec("select * from Membre");
while (qry.next())
{
if(id==qry.value(0) && mdp==qry.value(3).toString())
return true;
}
return false;
}
bool Membre::verifier_existance(int id)
{
QSqlQuery qry;
qry.exec("select * from Membre");
while (qry.next())
{
if(id==qry.value(0) )
return true;
}
return false;
}
void Membre::rechercher(QString r,QTableWidget *t)
{
QSqlQuery qry;
int i;
int j=0;
qry.exec("select * from Membre where id like '%"+r+"%' or nom like '%"+r+"%' or prenom like '%"+r+"%' or MotPass like '%"+r+"%'");
while(qry.next()){
j++;
}
t->setRowCount(j);
t->setColumnCount(4);
t->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
t->setHorizontalHeaderLabels(QString("Id;Nom;Prenom;MotPass").split(";"));
i=1;
qry.exec("select * from Membre where id like '%"+r+"%' or nom like '%"+r+"%' or prenom like '%"+r+"%' or MotPass like '%"+r+"%'");
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()));
t->setItem(i-1,2,new QTableWidgetItem(qry.value(2).toString()));
t->setItem(i-1,3,new QTableWidgetItem(qry.value(3).toString()));
i++;
}
}
void Membre::tri(QTableWidget *t)
{
QSqlQuery qry;
int i;
int j=0;
qry.exec("select * from Membre");
while(qry.next()){
j++;
}
t->setRowCount(j);
t->setColumnCount(4);
t->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
t->setHorizontalHeaderLabels(QString("Id;Nom;Prenom;MotPass").split(";"));
i=1;
qry.exec("select* from Membre order by Prenom ASC");
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()));
t->setItem(i-1,2,new QTableWidgetItem(qry.value(2).toString()));
t->setItem(i-1,3,new QTableWidgetItem(qry.value(3).toString()));
i++;
}
}