-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeleteprof.cpp
More file actions
71 lines (60 loc) · 1.7 KB
/
deleteprof.cpp
File metadata and controls
71 lines (60 loc) · 1.7 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
#include "deleteprof.h"
#include "ui_deleteprof.h"
#include <QMessageBox>
#include <QDebug>
#include <QSqlQueryModel>
deleteprof::deleteprof(QWidget *parent) :
QDialog(parent),
ui(new Ui::deleteprof)
{
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 !";
}
}
deleteprof::~deleteprof()
{
delete ui;
}
void deleteprof::on_DeleteButton_clicked()
{
QString Prof_ID;
Prof_ID = ui->Prof_ID->text();
QSqlQuery *qry = new QSqlQuery() ;
if(!Prof_ID.isEmpty()){
qry->prepare("DELETE FROM Prof WHERE Prof_ID = '"+Prof_ID+"'");
qry->exec();
QMessageBox::information(this, "Found", "La salle a été supprimée avec succès!");
this->hide();
}
}
void deleteprof::on_SalleReturn_clicked()
{
this->hide();
}
void deleteprof::on_SearchButton_clicked()
{
QString Prof_ID;
Prof_ID = ui->Prof_ID->text();
if(!Prof_ID.isEmpty()){
auto qry = QSqlQuery(db);
QString searchID = {"SELECT * FROM Prof WHERE Prof_ID='"+Prof_ID+"'" };
if(!qry.exec(searchID.arg(Prof_ID)))
qDebug() << "Cannot select from prof";
int count=0;
while(qry.next())
count++;
if(count != 1)
{
QMessageBox::warning(this, "Not Found", "Le professeur ne se trouve pas!");
ui->Prof_ID->clear();
}
else QMessageBox::information(this, "Found", "Le professeur est selectionné!");
}
}