-
Notifications
You must be signed in to change notification settings - Fork 0
/
eleves.cpp
110 lines (90 loc) · 3.03 KB
/
eleves.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
#include "eleves.h"
#include <QDebug>
eleves::eleves()
{
id=0;
nomprenom="";
QDate dateNaissance(1995, 5, 17);
parent="";
numParent=0;
niveau=0;
}
eleves::eleves(int id,QString nomp,QDate dN,int n,QString p,int nP)
{
this->id=id;
this->nomprenom=nomp;
this->dateNaissance=dN;
this->niveau=n;
this->parent=p;
this->numParent=nP;
}
QString eleves::get_nomprenom(){return nomprenom;}
QDate eleves::get_date(){return dateNaissance;}
int eleves::get_niv(){return niveau;}
int eleves::get_num(){return numParent;}
QString eleves::get_parent(){return parent;}
bool eleves::ajouter()
{
QSqlQuery query;
QString res= QString::number(id);
query.prepare("INSERT INTO eleves (ID,NOMPRENOM,PARENT,DATENAISSANCE,NIV,NUM) "
"VALUES (:id,:nomprenom,:parent,:dateNaissance,:niveau,:numParent)");
query.bindValue(":id", res);
query.bindValue(":nomprenom", nomprenom);
query.bindValue(":dateNaissance", dateNaissance);
query.bindValue(":niveau", niveau);
query.bindValue(":numParent", numParent);
query.bindValue(":parent", parent);
return query.exec();
}
QSqlQueryModel * eleves::afficher()
{QSqlQueryModel * model= new QSqlQueryModel();
model->setQuery("select * from eleves");
model->setHeaderData(0, Qt::Horizontal, QObject::tr("Id"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("NomPrenom "));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("Niveau"));
model->setHeaderData(3, Qt::Horizontal, QObject::tr("Parent"));
model->setHeaderData(4, Qt::Horizontal, QObject::tr("NumParent"));
model->setHeaderData(5, Qt::Horizontal, QObject::tr("DateNaissance"));
return model;
}
bool eleves::supprimer(int idd)
{
QSqlQuery query;
QString res= QString::number(idd);
query.prepare("Delete from eleves where ID = :id ");
query.bindValue(":id", res);
return query.exec();
}
bool eleves:: modifier(int id,QString nom,QDate dNaissance,int niv,QString nomp,int num)
{
QSqlQuery qry;
qry.prepare("UPDATE eleves set NOMPRENOM=(?),PARENT=(?),DATENAISSANCE=(?),NIV=(?),NUM=(?) where ID=(?) ");
qry.addBindValue(nom);
qry.addBindValue(nomp);
qry.addBindValue(dNaissance);
qry.addBindValue(niv);
qry.addBindValue(num);
qry.addBindValue(id);
return qry.exec();
}
QSqlQueryModel * eleves::rechercher (const QString &aux)
{
QSqlQueryModel * model = new QSqlQueryModel();
model->setQuery("select * from eleves where ((ID || NOMPRENOM ) LIKE '%"+aux+"%')");
model->setHeaderData(0, Qt::Horizontal, QObject::tr("Id"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("NomPrenom "));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("Niveau"));
model->setHeaderData(3, Qt::Horizontal, QObject::tr("Parent"));
model->setHeaderData(4, Qt::Horizontal, QObject::tr("NumParent"));
model->setHeaderData(5, Qt::Horizontal, QObject::tr("DateNaissance"));
return model;
}
QSqlQuery eleves::rechercher_id(int id)
{
QSqlQuery query;
query.prepare("SELECT * from eleves where ID = :id");
query.bindValue(":id", id);
query.exec();
return query;
}