-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCategorie.cpp
More file actions
178 lines (144 loc) · 5.8 KB
/
Categorie.cpp
File metadata and controls
178 lines (144 loc) · 5.8 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include "Categorie.hpp"
Categorie::Categorie(wxPanel* panel_parent, string nom, Commande* commande) : wxStaticBoxSizer(wxVERTICAL, panel_parent, wxString(nom+" : ")), commande(commande), panel_parent(panel_parent), nom(nom)
{
scrole_categorie = new wxScrolledWindow(panel_parent);
sizer_categorie = new wxBoxSizer(wxVERTICAL);
sizer_categorie_button = new wxBoxSizer(wxHORIZONTAL);
ajoute_article = new wxButton(panel_parent, -1, "Ajouter");
sizer_categorie_button->Add(ajoute_article, 1);
scrole_categorie->SetSizer(sizer_categorie);
scrole_categorie->FitInside();
scrole_categorie->SetScrollRate(5, 5);
this->Add(scrole_categorie, 10, wxALL | wxEXPAND, 0);
this->Add(sizer_categorie_button, 1, wxEXPAND, 0);
InitArtilce();
ajoute_article->Bind(wxEVT_BUTTON, &Categorie::EventAjouteArticle, this);
}
void Categorie::InitArtilce(){
vector<Snack> snacks = getSnacks(nom);
for(Snack s : snacks){
Article* tmp;
vector<bool> list_caracterisitque = checkArticleComposition(s.nomSnack);
if(tmp = new Article(scrole_categorie, this, s.nomSnack, s.cheminVersImage, s.prix, s.prixAchat, s.quantite, s.rupture, list_caracterisitque, s.description, commande))
{
liste_aliment.push_back(tmp);
sizer_categorie->Add(tmp, 0, wxALL | wxEXPAND, 0);
panel_parent->Layout();
}
}
}
void Categorie::EventAjouteArticle(wxCommandEvent& event) {
wxTextEntryDialog name_is(panel_parent, wxT("Nom de l'article (sans accents)"), wxT("Ajouter un article"));
name_is.SetTextValidator(wxFILTER_ALPHA);
string nom_snack;
if (name_is.ShowModal() == wxID_OK && ((nom_snack = name_is.GetValue()) != ""))
{
bool init = false;
string descriptif;
vector<bool> caracteristique;
int rupture;
int stock;
double prix;
double prix_achat;
string chemin;
int res;
if(unique_ptr<Snack> s = exiteSnack(nom_snack)){
descriptif = s->description;
caracteristique = checkArticleComposition(nom_snack);
rupture = s->rupture;
stock = s->quantite;
prix = s->prix;
chemin = s->cheminVersImage;
init = true;
replaceSnack(nom_snack);
if(!verifyTypeA(nom_snack, nom)){
updateTypeA(nom_snack, nom);
}
}else if(!chercheSnack(nom_snack)){
InfoArticle dialo(panel_parent, nom_snack);
res = dialo.ShowModal();
if (res == wxID_OK)
{
descriptif = dialo.GetDescriptif();
caracteristique = dialo.GetCaracteristique();
rupture = dialo.GetRupture();
stock = dialo.GetStock();
prix = dialo.GetPrix();
prix_achat = dialo.GetPrixAchat();
chemin = dialo.GetChemin();
createSnack(nom_snack, prix, prix_achat, descriptif, stock, 1, rupture, nom, chemin);
addAttributesToSnack(nom_snack, caracteristique);
init = true;
}
}
Article* tmp;
if(init && res != wxID_CANCEL &&(tmp = new Article(scrole_categorie, this, nom_snack, chemin, prix, prix_achat, stock, rupture, caracteristique, descriptif, commande)))
{
liste_aliment.push_back(tmp);
sizer_categorie->Add(tmp, 0, wxALL | wxEXPAND, 0);
statistiques->UpdateSelectionSnack();
panel_parent->Layout();
}
}
name_is.Destroy();
}
wxString Categorie::CheminsDeFicher() {
wxFileDialog openFileDialog(panel_parent, _("Open PNG file"), "", "", "PNG files (*.png)|*.png", wxFD_OPEN | wxFD_FILE_MUST_EXIST);
if (openFileDialog.ShowModal() == wxID_CANCEL)
return ""; // the user changed idea...
// proceed loading the file chosen by the user;
// this can be done with e.g. wxWidgets input streams:
wxFileInputStream input_stream(openFileDialog.GetPath());
if (!input_stream.IsOk())
{
wxLogError("Cannot open file '%s'.", openFileDialog.GetPath());
return "";
}
return openFileDialog.GetPath();
}
void Categorie::SupprimerArticle(Article* article) {
// Parcours de tous les éléments du sizer
for (unsigned int i = 0; i < sizer_categorie->GetItemCount(); i++) {
// Obtention de l'élément sizer correspondant
wxSizerItem* item = sizer_categorie->GetItem(i);
// Comparaison du pointeur
if (item->GetWindow() == article) {
// Suppression de l'élément du sizer
sizer_categorie->Remove(i);
sizer_categorie->Detach(article);
// Suppression de l'élément du vecteur de liste_aliment
auto it = find_if(liste_aliment.begin(), liste_aliment.end(), [=](Article* a) { return a == article; });
if (it != liste_aliment.end()) {
liste_aliment.erase(it);
}
deleteSnack(wxStringToString(article->GetNom()));
// Destruction de l'objet article
article->Destroy();
break;
}
}
statistiques->UpdateSelectionSnack();
sizer_categorie->Layout();
}
void Categorie::MoodAdmin(){
ajoute_article->Enable(true);
for(Article* art : liste_aliment){
art->MoodAdmin();
}
}
void Categorie::MoodUtilisateur(){
ajoute_article->Enable(false);
for(Article* art : liste_aliment){
art->MoodUtilisateur();
}
}
wxArrayString Categorie::NomSnacks(){
wxArrayString noms;
for(Article* a : liste_aliment){
noms.Add(a->GetNom());
}
return noms;
}
void Categorie::initStatistiques(Statistiques* statistiques){
this->statistiques = statistiques;
}