-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaddprof.cpp
More file actions
67 lines (57 loc) · 1.58 KB
/
addprof.cpp
File metadata and controls
67 lines (57 loc) · 1.58 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
#include "addprof.h"
#include "ui_addprof.h"
#include <QMessageBox>
addprof::addprof(QWidget *parent) :
QDialog(parent),
ui(new Ui::addprof)
{
ui->setupUi(this);
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("C:/Users/lenovo/Documents/QT/DepartmentDB.db");
if(!db.open()){
qDebug()<<"Can't connect to the database !";
}
else{
qDebug()<<"Connected !";
}
}
addprof::~addprof()
{
delete ui;
}
void addprof::on_AddButton_clicked()
{
QString Nom,Email,Prenom;
Nom = ui->Nom->text();
Email = ui->Email->text();
Prenom= ui->Prenom->text();
if(Nom=="" || Email=="" || Prenom=="" ){
QMessageBox::warning(this,"Prof","Veuillez remplir tout les champs s'il vous plaît.");
}
else{
//cherche si la salle existe
auto search = QSqlQuery(db);
QString searchAcc = {"SELECT Nom FROM Prof WHERE Nom='"+Nom+"'" };
if(!search.exec(searchAcc))
qDebug() << "Cannot select";
int count = 0;
while(search.next())
count++;
if(count>=1)
QMessageBox::warning(this, "Failed", "Le professeur existe deja!");
else {
QSqlQuery *qry = new QSqlQuery() ;
qry->prepare("INSERT INTO Prof (Nom,Email,Prenom)" "VALUES (?,?,?);");
qry->addBindValue(Nom);
qry->addBindValue(Email);
qry->addBindValue(Prenom);
qry->exec();
QMessageBox::information(this,"valider","Le professeur a été ajouté avec succès");
this->hide();
}
}
}
void addprof::on_SalleReturn_clicked()
{
this->hide();
}