-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaddcoord.cpp
More file actions
68 lines (57 loc) · 1.73 KB
/
addcoord.cpp
File metadata and controls
68 lines (57 loc) · 1.73 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 "addcoord.h"
#include "ui_addcoord.h"
#include <QMessageBox>
AddCoord::AddCoord(QWidget *parent) :
QDialog(parent),
ui(new Ui::AddCoord)
{
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 !";
}
}
AddCoord::~AddCoord()
{
delete ui;
}
void AddCoord::on_AddButton_clicked()
{
QString NameCoord,Email,Cycle,Filiere ;
Cycle = ui->Cycle->text();
Filiere = ui->Filiere->text();
NameCoord = ui->NameCoord->text();
Email = ui->Email->text();
if(NameCoord=="" ||Email=="" || Cycle=="" || Filiere==""){
QMessageBox::warning(this,"Coord","Veuillez remplir tout les champs s'il vous plaît.");
}
else{}
//cherche si la salle existe
auto search = QSqlQuery(db);
QString searchCoord = {"SELECT Name FROM Coordinateur WHERE Name='"+NameCoord+"'" };
if(!search.exec(searchCoord))
qDebug() << "Cannot select";
int count = 0;
while(search.next())
count++;
if(count>=1)
QMessageBox::warning(this, "Failed", "Le coordinateur existe deja!");
else {
QSqlQuery *qry = new QSqlQuery() ;
qry->prepare("INSERT INTO Coordinateur (Name,Email,Cycle,Filiere)" "VALUES (?,?,?,?);");
qry->addBindValue(NameCoord);
qry->addBindValue(Email);
qry->addBindValue(Cycle);
qry->addBindValue(Filiere);
qry->exec();
QMessageBox::information(this,"valider","La coordinateur a été ajoutée avec succès");
this->hide();
}
}
void AddCoord::on_CoordReturn_clicked()
{
}