diff --git a/app b/app new file mode 100755 index 0000000..1406654 Binary files /dev/null and b/app differ diff --git a/src/app/core_logic/responsable.c b/src/app/core_logic/responsable.c index 27bccca..802bd7f 100644 --- a/src/app/core_logic/responsable.c +++ b/src/app/core_logic/responsable.c @@ -1,5 +1,7 @@ #include +#include #include "responsable.h" +#include "../interface/interface_resp.h" int chargementArticles(int tRef[], float tPoids[], float tVol[], float tPrix[], int tPhysique) { @@ -27,22 +29,19 @@ int chargementArticles(int tRef[], float tPoids[], float tVol[], float tPrix[], return i; } -void sauvegadArticles(int tRef[], float tPoids[], float tVol[], float tPrix[], float tLogique) -{ +void sauvegardArticles(int tRef[], float tPoids[], float tVol[], float tPrix[], int tLogique){ int i; FILE * fe; - fe = fopen("articles.txt","w"); - if ( fe == NULL ) + fe = fopen("donnee/articles.txt", "w"); + if ( fe == NULL) { perror("fopen"); - return -1; + return; } - - for ( i = 0; i < tLogique; ++i) + for ( i = 0; i < tLogique; i++) { - fwritef(fe,"%d\t %.2f\t %.2f\t %.2f\n", ); + fprintf(fe,"%d %f %f %f\n", tRef[i], tPoids[i], tVol[i], tPrix[i]); } - fclose(fe); } diff --git a/src/app/core_logic/responsable.h b/src/app/core_logic/responsable.h index b700dca..4230671 100644 --- a/src/app/core_logic/responsable.h +++ b/src/app/core_logic/responsable.h @@ -1,5 +1,5 @@ - +#include int chargementArticles(int tRef[], float tPoids[], float tVol[], float tPrix[], int tPhysique); -void sauvegadArticles(int tRef[], float tPoids[], float tVol[], float tPrix[], int tLogique); +void sauvegardArticles(int tRef[], float tPoids[], float tVol[], float tPrix[], int tLogique); int ajouterArticle( int tRef[], float tPoids[], float tVol[], float tPrix[], int *tLogique, int tPhysique, int ref, float poids, float volume, float prix); \ No newline at end of file diff --git a/src/app/core_logic/testResponsable.c b/src/app/core_logic/testResponsable.c index 9759553..0b38a9a 100644 --- a/src/app/core_logic/testResponsable.c +++ b/src/app/core_logic/testResponsable.c @@ -1,12 +1,3 @@ #include #include "responsable.h" #include "../interface/interface_resp.h" - -int main (void) -{ - int tPhysique = 10, tRef[10], tLogique = 0; - float tPoids[10], tVol[10], tPrix[10]; - tLogique = chargementArticles( tRef, tPoids, tVol, tPrix, tPhysique); - affichArticles( tRef, tPoids, tVol, tPrix, tLogique); - return 0; -} \ No newline at end of file diff --git a/src/app/interface/interface_client.c b/src/app/interface/interface_client.c index 1718f20..4d14f45 100644 --- a/src/app/interface/interface_client.c +++ b/src/app/interface/interface_client.c @@ -20,30 +20,25 @@ void affiche_client(int a){ /* * Sert à lancer le menu et faire choisir l'utilisateur */ -void menu(int *choix, int jour) { +void menu_client(int *choix, int jour) { affiche_client(jour); printf("Vous choisissez: "); - scanf("%d", choix); - - while (*choix < 0) - { + while (scanf("%d", choix) != 1 || *choix < 0 || *choix > 5) { + while (getchar() != '\n'); // Nettoie le tampon d'entrée en cas de saisie invalide affiche_client(jour); - printf("Vous choisissez: "); - printf("Veuillez entrer un choix valide ! \n"); - scanf("%d", choix); + printf("Veuillez entrer un choix valide : "); } } -void global_client(){ +void global_client() { int choix, jour; - menu(&choix, jour); + menu_client(&choix, jour); switch (choix) { case 1: afficherDonneesClient(); break; default: - printf("Veuillez entrer un choix valide ! \n"); + printf("Veuillez entrer un choix valide !\n"); break; } -} - +} \ No newline at end of file diff --git a/src/app/interface/interface_client.h b/src/app/interface/interface_client.h index a361055..f091e36 100644 --- a/src/app/interface/interface_client.h +++ b/src/app/interface/interface_client.h @@ -1,5 +1,5 @@ #include void affiche_client(int a); -void menu(int *choix, int a); +void menu_client(int *choix, int a); void global_client(); \ No newline at end of file diff --git a/src/app/interface/interface_resp.c b/src/app/interface/interface_resp.c index b1ef8ac..d500cea 100644 --- a/src/app/interface/interface_resp.c +++ b/src/app/interface/interface_resp.c @@ -1,6 +1,22 @@ #include #include "interface_resp.h" +void affiche_resp(int a){ + printf("\n"); + printf("+-------------+ \n"); + printf("|| Bonjour ! ||\n") ; + printf("+-------------+ \n"); + printf("\n"); + printf("+-----------------------------------------------------------------+\n"); + printf("|| Que voulez-vous faire ? \t \t \t \t \t || \n"); + printf("||\t1 : Afficher les articles \t \t \t \t || \n"); + printf("||\t2 : Afficher un article \t \t \t \t || \n"); + printf("||\t3 : Afficher un client \t \t \t \t \t || \n"); + printf("||\t4 : Afficher les clients \t \t \t \t || \n"); + printf("||\t5 : Réinitialiser le panier. \t \t \t \t || \n"); + printf("+-----------------------------------------------------------------+\n"); +} + void affichArticles( int tRef[], float tPoids[], float tVol[], float tPrix[], int tLogique) { int i; @@ -72,7 +88,7 @@ void affichAjoutArticle(int *ref, float *poids, float *volume, float *prix) while ( poids < 0 ) { printf("Entrez un nombre correct !"); - scanf("%d", poids); + scanf("%f", poids); } } printf("Entrez le volume du nouveaux produit"); @@ -82,7 +98,7 @@ void affichAjoutArticle(int *ref, float *poids, float *volume, float *prix) while ( poids < 0 ) { printf("Entrez un nombre correct !"); - scanf("%d", poids); + scanf("%f", poids); } } printf("Entrez le prix du nouveaux produit"); @@ -92,7 +108,33 @@ void affichAjoutArticle(int *ref, float *poids, float *volume, float *prix) while ( prix < 0 ) { printf("Entrez un nombre correct !"); - scanf("%d", prix); + scanf("%f", prix); } } -} \ No newline at end of file +} + + +void menu_resp(int *choix, int jour) { + affiche_resp(jour); + printf("Vous choisissez: "); + while (scanf("%d", choix) != 1 || *choix < 0 || *choix > 5) { + while (getchar() != '\n'); // Nettoie le tampon d'entrée en cas de saisie invalide + affiche_resp(jour); + printf("Veuillez entrer un choix valide : "); + } +} + +void global_resp(){ + int choix, a, tRef[100], tLogique = 0; + float tPoids[100], tVol[100], tPrix[100]; + menu_resp(&choix, a); + switch (choix) { + case 1: + affichArticles(tRef, tPoids, tVol, tPrix, tLogique); + break; + default: + printf("Veuillez entrer un choix valide ! \n"); + break; + } +} + diff --git a/src/app/interface/interface_resp.h b/src/app/interface/interface_resp.h index d62b642..6d7b724 100644 --- a/src/app/interface/interface_resp.h +++ b/src/app/interface/interface_resp.h @@ -2,4 +2,6 @@ void affichArticles( int tRef[], float tPoids[], float tVol[], float tPrix[], in void affichUnArticle(int tRef[], float tPoids[], float tVol[], float tPrix[], int tLogique, int val); void affichUnClient(int tNumClient[], float tCagnotte[], int tSus[], int tLogique, int val); void affichUnClients(int tNumClient[], float tCagnotte[], int tSus[], int tLogique, int val); -void affichAjoutArticle(int *ref, float *poids, float *volume, float *prix); \ No newline at end of file +void affichAjoutArticle(int *ref, float *poids, float *volume, float *prix); +void menu_resp(int *choix, int jour); +void global_resp(); diff --git a/src/main.c b/src/main.c index 106da06..aa376f5 100644 --- a/src/main.c +++ b/src/main.c @@ -15,7 +15,7 @@ int choixInterface(void) { fprintf(stderr,"Veuillez entrer un choix valide ! \n"); } switch (choix) { - case 1: printf("Vous avez choisit l'interface responsable.\n"); break; + case 1: printf("Vous avez choisit l'interface responsable.\n"); case 2: printf("Vous avez choisit l'interface client.\n"); } return choix; @@ -23,7 +23,7 @@ int choixInterface(void) { int main(){ switch (choixInterface()) { - //case 1: global_resp(); + case 1: global_resp(); case 2: global_client(); } return 0;