-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.cpp
141 lines (122 loc) · 2.9 KB
/
login.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
#include "login.h"
#include <QSqlQuery>
#include <QMessageBox>
#include <QSqlQueryModel>
#include "ui_mainwindow.h"
#include <QTextStream>
#include <iostream>
#include "qmessagebox.h"
#include <QObject>
#include "mainwindow.h"
Login::Login()
{
code="";
type="";
pseudo="";
MotDePasse="";
}
Login::Login(QString code, QString type,QString pseudo, QString MotDePasse)
{
this->pseudo=pseudo;
this->MotDePasse=pseudo;
this->code=code;
this->type=type;
}
bool Login::connection(QString pseu,QString mdp)
{
QSqlQuery q;
q.prepare("select * from login where pseudo=:pseudo and motdepasse=:motdepasse");
q.bindValue(":pseudo",pseu);
q.bindValue(":motdepasse",mdp);
q.exec();
q.next();
{
if((q.value(1)==pseu)&&(q.value(2)==mdp))
{
type=q.value(3).toString();
return true;
}
else {
return false;
}
}
}
bool Login::ajouter()
{
QSqlQuery q;
q.prepare("insert into login VALUES (:code,:pseudo,:motdepasse,:type)");
q.bindValue(":code",code);
q.bindValue(":pseudo",pseudo);
q.bindValue(":motdepasse",MotDePasse);
q.bindValue(":type",type);
if (q.exec())
{
std::cout << "Ça marche ! 🙂" << std::endl;
return true;
}
else
{
std::cout<< "Ça marche pas ! 😞" <<std::endl;
return false;
}
}
bool Login::modifier()
{
QSqlQuery q;
q.prepare("update login set pseudo=:pseudo,motdepasse=:motdepasse,type=:type where code=:code");
q.bindValue(":code",code);
q.bindValue(":pseudo",pseudo);
q.bindValue(":motdepasse",MotDePasse);
q.bindValue(":type",type);
if(q.exec())
{
return true;
}
else return false;
}
QSqlQueryModel* Login::afficher()
{
QSqlQueryModel *modal=new QSqlQueryModel();
QSqlQuery q;
q.prepare("select * from login");
q.exec();
modal->setQuery(q);
return modal;
}
/*bool Login::supprimer()
{
QSqlQuery q;
q.prepare("DELETE FROM login WHERE CODE =:CODE");
q.bindValue(":CODE",code);
if(q.exec())
{
return true;
}
else return false;
}*/
bool Login::supprimer()
{
QSqlQuery q,k;
q.prepare("select * FROM login WHERE CODE =:CODE");
q.bindValue(":CODE",code);
q.exec();
q.next();
type=q.value(3).toString();
if(type=="ADMIN")
{
k.prepare("select count(*) from login where type='ADMIN'");
k.exec();
k.next();
if(k.value(0).toInt()>1)
{
q.prepare("delete from login where CODE=:CODE");
q.bindValue(":CODE",code);
}
}
else if(type!="ADMIN")
{
q.prepare("delete from login where CODE=:CODE");
q.bindValue(":CODE",code);
}
return q.exec();
}