-
Notifications
You must be signed in to change notification settings - Fork 0
/
assurance.cpp
84 lines (72 loc) · 2.21 KB
/
assurance.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
#include "assurance.h"
#include <QMessageBox>
Assurance::Assurance(QString compagnie,int Prix,QString type,int Reference)
{
this->compagnie=compagnie;
this->type=type;
reference=Reference;
prix=Prix;
}
bool Assurance::ajouter()
{
QSqlQuery query;
QString res = QString::number(reference);
query.prepare("INSERT INTO ASSURANCE (COMPAGNIE, TYPE, PRIX, REFERENCE) "
"VALUES (:compagnie, :type, :prix, :reference)");
query.bindValue(":compagnie",compagnie);
query.bindValue(":type", type);
query.bindValue(":prix",prix);
query.bindValue(":reference", reference);
return query.exec();
}
QSqlQueryModel * Assurance::afficher()
{
QSqlQueryModel * model = new QSqlQueryModel();
model->setQuery("select * from assurance");
model->setHeaderData(0,Qt::Horizontal,QObject::tr("compagnie"));
model->setHeaderData(2,Qt::Horizontal,QObject::tr("prix"));
model->setHeaderData(1,Qt::Horizontal,QObject::tr("type"));
model->setHeaderData(3,Qt::Horizontal,QObject::tr("reference"));
return model;
}
bool Assurance::supprimer(int reference)
{
QSqlQuery query;
QString res = QString::number(reference);
query.prepare("Delete from assurance where reference=:reference");
query.bindValue(":reference",res);
return query.exec();
}
QSqlQueryModel *Assurance::recherche(int reference, QString type, QString compagnie)
{
QSqlQuery query;
QSqlQueryModel *model = new QSqlQueryModel();
int c=0;
query.prepare("SELECT *from assurance where reference=:reference or type=:type or compagnie=:compagnie");
query.bindValue(":reference",reference);
query.bindValue(":type",type);
query.bindValue(":compagnie",compagnie);
if(query.exec())
{
while(query.next())
{
c++;
}
if(c==1)
{
QMessageBox boxt;
boxt.setText("trouvé");
boxt.exec();
model->setQuery(query);
}
else
if(c<1)
{
QMessageBox boxpt;
boxpt.setText("pas trouvé");
boxpt.exec();
model=0;
}
}
return model;
}