-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprof.cpp
More file actions
131 lines (112 loc) · 3.07 KB
/
prof.cpp
File metadata and controls
131 lines (112 loc) · 3.07 KB
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
#include "prof.h"
#include "ui_prof.h"
#include "addprof.h"
#include "deleteprof.h"
#include "editprof.h"
#include "navmenu.h"
#include "navmenu.h"
#include <QMessageBox>
#include <QDebug>
#include <QSqlQueryModel>
prof::prof(QWidget *parent) :
QDialog(parent),
ui(new Ui::prof)
{
ui->setupUi(this);
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
// db.setDatabaseName("/home/nadia/Bureau/QT1/DepartmentDB.db");
db.setDatabaseName("C:/Users/lenovo/Documents/QT/DepartmentDB.db");
if(!db.open()){
qDebug()<<"Can't connect to the database !";
}
else{
qDebug()<<"Connected !";
}
// Affichage de la salle juste apres avoir acceder a la fenetre
if(!db.isOpen()){
qDebug()<<"Failed";
return;
}
QSqlQueryModel *model = new QSqlQueryModel();
QSqlQuery *qry = new QSqlQuery(db);
qry->prepare("SELECT * FROM Prof");
qry->exec();
model->setQuery(std::move(*qry));
ui->ProfTable->setModel(model);
qDebug()<<(model->rowCount());
}
prof::~prof()
{
delete ui;
}
void prof::on_AddButton_clicked()
{
addprof addprof;
addprof.exec();
}
void prof::on_EditButton_clicked()
{
editprof editprof;
editprof.exec();
}
void prof::on_DeleteButton_clicked()
{
deleteprof deleteprof;
deleteprof.exec();
}
void prof::on_SearchButton_clicked()
{
QString SearchValue= "%"+ui->SearchValue->text()+"%";
if(!SearchValue.isEmpty())
{
//define the query on the db and the model
QSqlDatabase db;
auto qry = QSqlQuery(db);
QString select{"SELECT * FROM Prof WHERE "
"Prof_ID LIKE '"+SearchValue+"'"
"OR Nom LIKE '"+SearchValue+"'"
"OR Email LIKE '"+SearchValue+"'"
"OR Prenom LIKE '"+SearchValue+"'"};
//execute the query
if(!qry.exec(select))
qDebug() << "Cannot select from salle";
else
{
//define the model
QSqlQueryModel * model = new QSqlQueryModel;
model->setQuery(std::move(qry));
ui->ProfTable->setModel(model);
}
}
else
{
//define the query on the db and the model
QSqlDatabase db;
auto qry = QSqlQuery(db);
QString select{"SELECT * FROM Prof"};
//execute the query
if(!qry.exec(select))
qDebug() << "Cannot select from Prof";
//define the model
QSqlQueryModel * model = new QSqlQueryModel;
model->setQuery(std::move(qry));
ui->ProfTable->setModel(model);
}
}
void prof::on_RefreshTable_clicked()
{
QSqlQueryModel *model = new QSqlQueryModel();
QSqlDatabase db;
QSqlQuery *qry = new QSqlQuery(db);
qry->prepare("SELECT * FROM Prof");
qry->exec();
model->setQuery(std::move(*qry));
ui->ProfTable->setModel(model);
qDebug()<<(model->rowCount());
}
void prof::on_ReturnMenu_clicked()
{
this->hide();
NavMenu NavMenu;
NavMenu.exec();
}