-
Notifications
You must be signed in to change notification settings - Fork 0
/
bibliotheque.cpp
127 lines (98 loc) · 3.28 KB
/
bibliotheque.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
#include "bibliotheque.h"
#include "eleves.h"
Bibliotheque::Bibliotheque()
{
id=0;
nom="";
auteur="";
langue="";
eleve=0;
}
Bibliotheque::Bibliotheque(int id,QString nom,QString auteur,QString langue,int eleve)
{
this->id=id;
this->nom=nom;
this->auteur=auteur;
this->langue=langue;
this->eleve=eleve;
}
QString Bibliotheque::get_nom(){return nom;}
QString Bibliotheque::get_auteur(){return auteur;}
QString Bibliotheque::get_langue(){return langue;}
int Bibliotheque::get_id(){return id;}
int Bibliotheque::get_eleve(){return eleve;}
bool Bibliotheque::ajouter_livre()
{
QSqlQuery query;
QString res= QString::number(id);
query.prepare("INSERT INTO bibliotheque (ID, NOM, AUTEUR, LANGUE, ELEVE) "
"VALUES (:id, :nom, :auteur, :langue, :eleve)");
query.bindValue(":id", res);
query.bindValue(":nom", nom);
query.bindValue(":auteur", auteur);
query.bindValue(":langue", langue);
query.bindValue(":eleve", eleve);
return query.exec();
}
QSqlQueryModel * Bibliotheque::afficher_livre()
{QSqlQueryModel * model= new QSqlQueryModel();
model->setQuery("select * from bibliotheque");
model->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("Nom "));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("Auteur"));
model->setHeaderData(3, Qt::Horizontal, QObject::tr("Langue"));
model->setHeaderData(4, Qt::Horizontal, QObject::tr("Eleve"));
return model;
}
bool Bibliotheque::supprimer_livre(int idd)
{
QSqlQuery query;
QString res= QString::number(idd);
query.prepare("Delete from bibliotheque where ID = :id ");
query.bindValue(":id", res);
return query.exec();
}
bool Bibliotheque::modifier_livre(int id,QString nom,QString auteur,QString langue,int eleve)
{
QSqlQuery qry;
qry.prepare("UPDATE bibliotheque set NOM=(?),AUTEUR=(?),LANGUE=(?),ELEVE=(?) where ID=(?) ");
qry.addBindValue(nom);
qry.addBindValue(auteur);
qry.addBindValue(langue);
qry.addBindValue(eleve);
qry.addBindValue(id);
return qry.exec();
}
QSqlQuery Bibliotheque::rechercher_id_livre(int id)
{
QSqlQuery query;
query.prepare("SELECT * from bibliotheque where ID = :id");
query.bindValue(":id", id);
query.exec();
return query;
}
QSqlQueryModel * Bibliotheque::rechercher_livre (const QString &aux)
{
QSqlQueryModel * model = new QSqlQueryModel();
model->setQuery("select * from bibliotheque where ( LOWER (ID || NOM || AUTEUR || LANGUE ) LIKE '%"+aux+"%')");
model->setHeaderData(0, Qt::Horizontal, QObject::tr("Id"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("Nom "));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("Auteur"));
model->setHeaderData(3, Qt::Horizontal, QObject::tr("Langue"));
model->setHeaderData(4, Qt::Horizontal, QObject::tr("Eleve"));
return model;
}
QSqlQueryModel * Bibliotheque::afficher_eleve(){
QSqlQueryModel * model= new QSqlQueryModel();
model->setQuery("select ID from eleves");
model->setHeaderData(0, Qt::Horizontal, QObject::tr("eleve"));
return model;
}
QSqlQuery Bibliotheque::rechercher_eleve(int id)
{
QSqlQuery query;
query.prepare("SELECT * from bibliotheque where ELEVE = :id");
query.bindValue(":id", id);
query.exec();
return query;
}