-
Notifications
You must be signed in to change notification settings - Fork 0
/
historique.cpp
90 lines (76 loc) · 2.99 KB
/
historique.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
#include "historique.h"
Historique::Historique()
{
IdHist=0;
DateHist="";
HeureHist="";
Id=0;
Action="";
}
bool Historique::ajouterHistorique(int id, QString action)
{
int ajout=0,existe,num=100;
QSqlQuery query;
DateHist=QDateTime::currentDateTime().toString("dd/MM/yy");
HeureHist=QDateTime::currentDateTime().toString("hh:mm:ss");
while (!ajout) {
existe=0;
query.prepare("select id_hist from historique where id_hist=:id_hist");
query.bindValue(":id_hist",num);
query.exec();
while (query.next()) {
existe=1;
}
if(existe==0)
{
query.prepare("insert into historique (id_hist,date_hist,heure_hist,id,action) values (:id_hist,TO_DATE(:date_hist,'DD/MM/YY'),:heure_hist,:id,:action)");
query.bindValue(":id_hist",num);
query.bindValue(":date_hist",DateHist);
query.bindValue(":heure_hist",HeureHist);
query.bindValue(":id",id);
query.bindValue(":action",action);
return query.exec();
ajout++;
}
num++;
}
}
QSqlQueryModel *Historique::afficherHistorique()
{
QSqlQueryModel * model = new QSqlQueryModel();
model->setQuery("select h.id_hist,TO_CHAR(h.date_hist,'DD/MM/YYYY'),h.heure_hist,h.action,m.nom from historique h left outer join "
"membre m on h.id=m.id order by h.date_hist desc,h.heure_hist desc");
model->setHeaderData(0,Qt::Horizontal,"ID_HIST");
model->setHeaderData(1,Qt::Horizontal,"DATE");
model->setHeaderData(2,Qt::Horizontal,"HEURE");
model->setHeaderData(3,Qt::Horizontal,"ACTION");
model->setHeaderData(4,Qt::Horizontal,"ACTEUR");
return model;
}
bool Historique::supprimerAllHistorique()
{
QSqlQuery query;
return query.exec("delete from historique");
}
bool Historique::supprimerIntervalleHistorique(QString debut, QString fin)
{
QSqlQuery query;
query.prepare("delete from historique where date_hist between TO_DATE(:debut,'DD/MM/YY') and TO_DATE(:fin,'DD/MM/YY')");
query.bindValue(":debut",debut);
query.bindValue(":fin",fin);
return query.exec();
}
QSqlQueryModel *Historique::rechercheRapide(QString valeur)
{
QSqlQueryModel * model = new QSqlQueryModel();
model->setQuery("select h.id_hist,TO_CHAR(h.date_hist,'DD/MM/YYYY'),h.heure_hist,h.action,m.nom from historique h left outer join "
"membre m on h.id=m.id where (h.id_hist like '%"+valeur+"%' or TO_CHAR(h.date_hist,'DD/MM/YYYY') like '%"+valeur+"%'"
" or h.heure_hist like '%"+valeur+"%' or m.nom like '%"+valeur+"%' or h.action like '%"+valeur+"%' ) "
"order by h.date_hist desc,h.heure_hist desc");
model->setHeaderData(0,Qt::Horizontal,"ID_HIST");
model->setHeaderData(1,Qt::Horizontal,"DATE");
model->setHeaderData(2,Qt::Horizontal,"HEURE");
model->setHeaderData(3,Qt::Horizontal,"ACTION");
model->setHeaderData(4,Qt::Horizontal,"ACTEUR");
return model;
}