-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuvadddialog.cpp
More file actions
90 lines (65 loc) · 2.28 KB
/
Copy pathuvadddialog.cpp
File metadata and controls
90 lines (65 loc) · 2.28 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
#include "uvadddialog.h"
#include "ui_uvadddialog.h"
#include "mainutprofiler.h"
const int MAXCREDIT=6;
UVAddDialog::UVAddDialog(QWidget *parent) :QDialog(parent),ui(new Ui::UVAddDialog)
{
ui->setupUi(this);
MainUTProfiler &mainUTProfiler=MainUTProfiler::getUTProfiler();
if(mainUTProfiler.connectDb()){
ui->test->setText("Still Connected ...");
QSqlQueryModel *modelCategorie= new QSqlQueryModel();
QSqlQueryModel *modelSaison= new QSqlQueryModel();
QSqlQuery *query = new QSqlQuery(mainUTProfiler.mydb);
// SET The Possible Categorie Values
query->prepare("SELECT uvType FROM categorie");
query->exec();
modelCategorie->setQuery(*query);
ui->categorieComb->setModel(modelCategorie);
// SET The Possible Saison Values
query->prepare("SELECT SaisonType FROM saison");
query->exec();
modelSaison->setQuery(*query);
ui->saisonComb->setModel(modelSaison);
// Disconnection
}
else
ui->test->setText("Failed ... ");
mainUTProfiler.deconnect();
}
UVAddDialog::~UVAddDialog()
{
delete ui;
}
void UVAddDialog::on_insertUV_clicked()
{
MainUTProfiler &mainUTProfiler=MainUTProfiler::getUTProfiler();
QString code,titre,categorie,saison;
int nbCredit=-1;
code= ui->codeLine->text();
titre= ui->titreLine->text();
categorie= ui->categorieComb->currentText();
saison= ui->saisonComb->currentText();
nbCredit = ui->nbCreditspinBox->value();
mainUTProfiler.deconnect();
if(!mainUTProfiler.connectDb() || code.isEmpty() || categorie.isEmpty() || saison.isEmpty() ||(nbCredit<=-1 || nbCredit>MAXCREDIT )){
qDebug()<<"Insertion Failed";
return;
}
QSqlQuery *query = new QSqlQuery(mainUTProfiler.mydb);
query->prepare("INSERT INTO UV (code,titre,uvCategorie,nbCredits,saison)"
"VALUES (:code,:titre,:uvCategorie,:nbCredits,:saison)");
query->bindValue(0,code);
query->bindValue(1,titre);
query->bindValue(2,categorie);
query->bindValue(3,nbCredit);
query->bindValue(4,saison);
if(query->exec()){
ui->test->setText(code +" " + " added !");
}
else
{
ui->test->setText("Failed...");
}
mainUTProfiler.disconnect();
}