-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileDriver
More file actions
323 lines (253 loc) · 9.57 KB
/
Copy pathFileDriver
File metadata and controls
323 lines (253 loc) · 9.57 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
/** classe contenant le menu et les fonctions de lectures et d'ecriture du fichier texte permettant de sauvegarder les données
*/
public class FileDriver {
static String chemin = "C:/Users/samue/OneDrive/Bureau/Sauvegarde_Inventaire.txt";
/**methode pour lire et afficher ce que contient le fichier texte
* @param chemin du fichier texte ou variable contenant le chemin du fichier txt.
*/
public static void afficherFichierSauvegarde(String chemin) {
File file = new File(chemin);
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
String line = reader.readLine();
while(line!= null )
{
System.out.println(line);
System.out.println();
line = reader.readLine();
}
reader.close();
}catch(IOException e) {
e.printStackTrace();
}
}
/**methode pour afficher ce que contient le fichier texte
* @param chemin du fichier texte ou variable contenant le chemin du fichier txt.
* @param article que l'on veut le fichier texte pour le sauvegarder.
*/
public static void ecrireDansFichier(String chemin, Article article) {
File file = new File(chemin);
try {
FileWriter writer = new FileWriter(file,true);
BufferedWriter bw = new BufferedWriter(writer);
bw.write(article.getNom()+','+article.getPrixAchat()+','+article.getPrixVente()+','+article.getCategorie()+Magasin.getArticles().get(article));
bw.newLine();
bw.close();
} catch(IOException e) {
e.printStackTrace();
}
}
/**fonctipour afficher ce que contient le fichier texte
* @param chemin du fichier texte ou variable contenant le chemin du fichier txt.
* @param map : nom du dictionnaire que l'on veut sauvegarder dans le fichier texte.
*/
public static void ecrireFichier(String chemin,Map<Article, Integer> map ) {
File file = new File(chemin);
for (Entry <Article,Integer> element : map.entrySet()) {
try {
FileWriter writer = new FileWriter(file,true);
BufferedWriter bw = new BufferedWriter(writer);
bw.write(element.getKey().getNom()+','+element.getKey().getPrixAchat()+','+element.getKey().getPrixVente()+','+element.getKey().getCategorie()+','+element.getValue());
bw.newLine();
bw.close();
} catch(IOException e) {
e.printStackTrace();
}
}
}
/**fonction pour lire le fichier txt
* @param chemin du fichier texte ou variable contenant le chemin du fichier txt.
*/
public static void lireFichierSauvegarder(String chemin) { // chemin du fichier que l'on veut afficher //
File file = new File(chemin);
final String SEPARATEUR= ",";
String nomArticle = null;
String categorie = null ;
double prixAchat = 0;
double prixVente = 0;
int stock = 0;
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
String line = reader.readLine();
while(line!= null)
{
String mots [] = line.split(SEPARATEUR);
nomArticle = mots[0];
prixAchat = Double.parseDouble(mots[1]);
prixVente = Double.parseDouble(mots[2]);
categorie = mots[3];
stock = Integer.parseInt(mots[4]);
Magasin.getArticles().put(new Article(nomArticle, prixAchat, prixVente,categorie),stock);// permet d'incrémenter chaque ligne sinon on boucle sur la premiere//
line = reader.readLine();
}
reader.close(); // fermer le fichier //
}catch(IOException e) { // attraper l'exeption //
e.printStackTrace();
}
}
public static void afficherTeteMenu() {
System.out.println( "-----------------------------------");
System.out.println( " Bienvenue ");
System.out.println( " dans notre magasin: ");
System.out.println( " "+Magasin.getNom().toUpperCase()+" ");
System.out.println( "-----------------------------------");
}
/** methode pour afficher le menu 1 dans la console
*/
public static void afficherMenu1() {
System.out.println();
System.out.println( "------ \n Séléction Menu Manager \n ------" );
System.out.println( " Option 0 : Quitter" );
System.out.println( " Option 1 : Ajouter un article" );
System.out.println( " Option 2 : Supprimer un article" );
System.out.println( " Option 3 : Ajouter un employé " );
System.out.println( " Option 4 : Licencier un employé " );
System.out.println( " Option 5 : Afficher Inventaire" );
System.out.println( " Option 6 : Afficher Employés Menage" );
System.out.println( " Option 7 : Afficher Vendeur" );
System.out.println( " Option 8 : Gérer les stocks " );
}
/** methode pour lancer le menu 1, et donc les actions que peut effectuer le manager
*/
public static void lancerMenu1() {
afficherTeteMenu();
Scanner scan = new Scanner(System.in);
boolean menu = true;
do {
afficherMenu1();
int choix = Magasin.objet.nextInt();
switch(choix) {
case(0):
System.out.println( " Bonne journée ! " );
menu = false;
break;
case(1):
System.out.println( " Vous avez séléctionner 1 : Ajouter un article ");
Article a = new Article();
Magasin.ajouterArticle(a);
break;
case(2):
System.out.println( " Vous avez séléctionner 2 : Supprimer un article ");
System.out.print("quel article souhaitez vous supprimer : \n");
String nom = scan.nextLine();
System.out.print("quel est la categrie de votre article : choix entre P:premium, C, confort et E, entré de gamme");
String categorie = scan.nextLine();
if (Magasin.contenu(nom,categorie)){
Magasin.supArticle(nom,categorie);
}
else {
System.out.println("nous ne possedons pas ce produit dans le magasin il est donc impossible de le supprimer ");
}
break;
case(3):
System.out.println( " Vous avez séléctionner 3 : Ajouter un employé ");
Manager.Embaucher();
break;
case(4):
System.out.println( " Vous avez séléctionner 4 : Licencier un employé");
Manager.Licencier();
break;
case(5):
System.out.println( " Vous avez séléctionner 5 : Afficher inventaire ");
Magasin.afficherInventaire();
break;
case(6):
System.out.println( " Vous avez séléctionner 6 : Afficher Employés Menage ");
Manager.afficherEmployeMenage();
break;
case(7):
System.out.println( " Vous avez séléctionner 7 : Afficher Vendeurs");
Manager.afficherEmployeVendeur();
break;
case(8):
System.out.println( " Vous avez séléctionner 8 : Gérer les stocks \n");
System.out.println("Quels produits voulez vous acheter ?\n");
String nomarticle=scan.nextLine();
System.out.println("Quelle catégorie: choix entre P:premium, C, confort et E, entrée de gamme \n");
String cate=scan.nextLine();
if(Magasin.chercherFournisseurbool(nomarticle,cate)==false) {
System.out.println("Pas de fournisseur pour votre produit");
}
else {
Fournisseur f=Magasin.chercherFournisseur(nomarticle,cate);
Magasin.acheterbis(f);
}
break;
default :
System.out.println( " Entrer une option valide ! " );}
}while(menu==true);
}
/** methode pour afficher le menu 1 dans la console
*/
public static void afficherMenu2() {
System.out.println();
System.out.println( "------ \n Séléction Menu Client \n ------" );
System.out.println( " Option 0 : Quitter le magasin" );
System.out.println( " Option 1 : Acheter un produit" );
System.out.println( " Option 2 : Voir les produits" );
System.out.println( " Option 3 : Conseil en fonction de votre budget " );
}
/** methode pour lancer le menu 2, et donc les actions que peut effectuer le client
*/
public static void lancerMenu2() {
afficherTeteMenu();
Scanner scan = new Scanner(System.in);
System.out.print(" Quel est votre nom: \n");
String nomClient = scan.nextLine();
System.out.print("Quel est votre prénom \n");
String prenomClient = scan.nextLine();
System.out.print(" Quel est votre budjet : \n");
int argent = scan.nextInt();
Client c = new Client(nomClient,prenomClient,argent);
if(Magasin.getJour()==30) {
Magasin.finMois();
}
Magasin.setJour(Magasin.getJour()+1);
boolean menu = true;
do {
afficherMenu2();
int choix = Magasin.objet.nextInt();
switch(choix) {
case(0):
System.out.println( " Bonne journée ! " );
menu = false;
break;
case(1):
System.out.println( " Vous avez séléctionné 1 : Acheter un produit \n");
Magasin.afficherInventaire();
Scanner scan2 = new Scanner(System.in);
System.out.print("Quel article souhaitez vous acheter : \n");
String nom = scan2.nextLine();
System.out.print("Quel est la categorie de votre article : choix entre P:premium, C, confort et E, entrée de gamme \n ");
String categorie = scan2.nextLine();
if (Magasin.contenu(nom,categorie)){
Vendeur v = Manager.indiceAuHasard();
Article a = Magasin.traduction(nom, categorie);
Magasin.vendre(c,a,v);
}
else {
System.out.println("Nous ne possedons pas ce produit dans le magasin, desirez vous autre chose ? \n");
}
break;
case(2):
System.out.println( " Vous avez séléctionné 2 : Voir les produits \n");
Magasin.afficherInventaire();
break;
case(3):
Magasin.dirigerClients(c);
break;
default :
System.out.println( " Entrer une option valide ! " );}
}while(menu==true);
}
}