-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindowrayon.cpp
111 lines (100 loc) · 3.06 KB
/
windowrayon.cpp
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
/**
* @file windowrayon.cpp
* @brief Fenêtre d'ajout, d'affichage, de suppression des rayons
* @author tromanin
* @date vendredi 11 septembre 2015, 08:12:00
*
* Fenêtre d'ajout, d'affichage, de suppression des rayons.
*/
#include "windowrayon.h"
#include "ui_windowrayon.h"
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlTableModel>
#include <QMessageBox>
#include <QtSql/QSqlRecord>
#include <QLineEdit>
#include <windowmenu.h>
#include <QSqlQuery>
#include <QCheckBox>
/**
* @brief windowRayon::windowRayon
* @param parent
*
* C'est ici que sont affichés les rayons, on prend les données directement dans la BDD.
*/
windowRayon::windowRayon(QWidget *parent) :
QDialog(parent),
ui(new Ui::windowRayon)
{
ui->setupUi(this);
// Construction de la base
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
maBase = new QSqlDatabase(db);
maBase->setHostName("************");
maBase->setDatabaseName("************");
maBase->setUserName("***********");
maBase->setPassword("*************");
bool ok = maBase->open();
if(!ok)
{
QMessageBox::warning(this,"New World BackOffice", "La connexion à la base de données a échouée\n Veuillez vérifier que le service mysql est lancé sur localhost", QMessageBox::Ok|QMessageBox::Cancel, QMessageBox::Ok);
}
else
{
modelRayon = new QSqlTableModel(this,*maBase);
modelRayon->setTable("SurType");
modelRayon->setHeaderData(0, Qt::Horizontal, trUtf8("Id du rayon"));
modelRayon->setHeaderData(1, Qt::Horizontal, trUtf8("Libellé du rayon"));
ui->tableViewRayon->setModel(modelRayon);
modelRayon->select();
modelRayon->setEditStrategy(QSqlTableModel::OnFieldChange);
ui->tableViewRayon->hideColumn(0);
ui->tableViewRayon->setColumnWidth(1,300);
}
}
/**
* @brief windowRayon::~windowRayon
*
* Suppression de l'interface utilisateur.
*/
windowRayon::~windowRayon()
{
delete ui;
}
/**
* @brief windowRayon::on_pushButtonRetour_clicked
*
* Bouton de retour au menu et de fermeture de la fenêtre.
*/
void windowRayon::on_pushButtonRetour_clicked()
{
WindowMenu *allerMenu = new WindowMenu();
allerMenu->setModal(true);
allerMenu->show();
this->reject();
}
/**
* @brief windowRayon::on_pushButtonAjouterRayon_clicked
*
* Bouton d'ajout d'un rayon.
*/
void windowRayon::on_pushButtonAjouterRayon_clicked()
{
QString nomRayon = ui->lineEditRayon->text();
QSqlRecord record = modelRayon->record();
// L'id n'est pas bon, un rayon doit avoir un nouvel id même quand on ajoute un rayon après avoir supprimé un précédent
record.setValue(0,modelRayon->rowCount()+1);
record.setValue(1,nomRayon);
modelRayon->insertRecord(modelRayon->rowCount(), record);
ui->lineEditRayon->clear();
}
/**
* @brief windowRayon::on_pushButtonSupprimerRayon_clicked
*
* Bouton de suppression d'un rayon.
*/
void windowRayon::on_pushButtonSupprimerRayon_clicked()
{
int ligne = ui->tableViewRayon->currentIndex().row();
modelRayon->removeRows(ligne,1);
}