better error handling in resp

pull/14/head
Mathéo Hersan 1 year ago
parent 2a284d1ac7
commit 065d51bbb4
No known key found for this signature in database
GPG Key ID: 4EF19C64D78EC91B

BIN
app

Binary file not shown.

@ -1,4 +1,3 @@
32 69.00 1 32 69.00 1
660 5351.40 0
5079 75.50 0 5079 75.50 0
53 0.00 0 53 0.00 0

@ -8,6 +8,7 @@
#include <string.h> #include <string.h>
#include "responsable.h" #include "responsable.h"
#include "../interface/interface_resp.h" #include "../interface/interface_resp.h"
#include "client.h"
#define MAX_SIZE_MDP 21 #define MAX_SIZE_MDP 21

@ -1,9 +1,4 @@
#include <stdio.h>
#include <stdlib.h>
#include "interface_resp.h" #include "interface_resp.h"
#include "../core_logic/responsable.h"
#include "../core_logic/client.h"
#include "../interface/interface_client.h"
#define MAX_CLIENTS 100 #define MAX_CLIENTS 100
#define MAX_ARTICLES 100 #define MAX_ARTICLES 100
@ -11,7 +6,6 @@
#define MAX_SIZE_MDP 21 #define MAX_SIZE_MDP 21
#define MENU_QUIT 14 #define MENU_QUIT 14
void affiche_resp(void) { void affiche_resp(void) {
printf("\n"); printf("\n");
printf("+-------------+\n"); printf("+-------------+\n");
@ -59,11 +53,8 @@ void affichArticles(int tRef[], float tPoids[], float tVol[], float tPrix[], int
void affichUnArticle(int tRef[], float tPoids[], float tVol[], float tPrix[], int tLogique) { void affichUnArticle(int tRef[], float tPoids[], float tVol[], float tPrix[], int tLogique) {
int ref; int ref;
printf("\tQuelle est la référence de l'article à rechercher ?\n"); printf("Entrez la référence de l'article à rechercher : ");
while (scanf("%d", &ref) != 1 || ref <= 0) { verifInt(&ref);
printf("\tEntrez une référence valide\n");
while (getchar() != '\n');
}
for (int i = 0; i < tLogique; ++i) { for (int i = 0; i < tLogique; ++i) {
if (ref == tRef[i]) { if (ref == tRef[i]) {
@ -78,11 +69,10 @@ void affichUnArticle(int tRef[], float tPoids[], float tVol[], float tPrix[], in
void affichUnClient(int tNumClient[], float tCagnotte[], int tSus[], int tLogique) { void affichUnClient(int tNumClient[], float tCagnotte[], int tSus[], int tLogique) {
int numC; int numC;
printf("\tVeuillez entrer le numéro du client à rechercher\n"); printf("Veuillez entrer le numéro du client à rechercher : ");
while (scanf("%d", &numC) != 1 || numC <= 0) {
printf("\t Veuillez entrez un numéro valide !\n"); verifInt(&numC);
while (getchar() != '\n');
}
for (int i = 0; i < tLogique; ++i) { for (int i = 0; i < tLogique; ++i) {
if (numC == tNumClient[i]) { if (numC == tNumClient[i]) {
printf("\t NumClient\t Cagnotte\t Etat\n"); printf("\t NumClient\t Cagnotte\t Etat\n");
@ -103,99 +93,75 @@ void affichClients(int tNumClient[], float tCagnotte[], int tSus[], int tLogique
} }
void affichAjoutArticle(int *ref, float *poids, float *volume, float *prix, int tRef[], int tLogArticle) { void affichAjoutArticle(int *ref, float *poids, float *volume, float *prix, int tRef[], int tLogArticle) {
printf("\t Entrez la ref du nouveau produit\n"); int articleIndex;
while (scanf("%d", ref) != 1 || *ref <= 0) { printf("Entrez la ref du nouveau produit : ");
printf("\t Veuillez entrer une référence valide.\n"); verifInt(ref);
while (getchar() != '\n');
}
if ( trouver_index_article(*ref, tRef, tLogArticle) != -1) articleIndex = trouver_index_article(*ref, tRef, tLogArticle);
{
printf("\t L'article existe déjà\n");
return;
}
else
{
printf("\t Entrez le poids du nouveau produit\n");
while (scanf("%f", poids) != 1 || *poids <= 0)
{
printf("\t Veuillez entrer un poids valide.\n");
while (getchar() != '\n');
}
printf("\t Entrez le volume du nouveau produit\n"); while (articleIndex != -1) {
while (scanf("%f", volume) != 1 || *volume <= 0) fprintf(stderr, "\x1B[31mERREUR : Article déjà présent. Veuillez entrer une référence valide :\x1B[0m ");
{ verifInt(ref);
printf("\t Veuillez entrer un volume valide.\n"); articleIndex = trouver_index_article(*ref, tRef, tLogArticle);
while (getchar() != '\n');
} }
printf("\t Entrez le prix du nouveau produit\n"); printf("Entrez le poids du nouveau produit : ");
while (scanf("%f", prix) != 1 || *prix <= 0) verifFloat(poids);
{
printf("\t Veuillez entrer un prix valide.\n"); printf("Entrez le volume du nouveau produit : ");
while (getchar() != '\n'); verifFloat(volume);
}
} printf("Entrez le prix du nouveau produit : ");
verifFloat(prix);
} }
void affichSupprimerArticle(int *ref) { void affichSupprimerArticle(int *ref) {
printf("\t Quelle est la référence de l'article que vous voulez supprimer ?\n"); printf("Entrez la référence de l'article que vous voulez supprimer : ");
while (scanf("%d", ref) != 1 || *ref <= 0) { verifInt(ref);
printf("\t Veuillez entrer une référence valide.\n");
while (getchar() != '\n');
}
} }
void affichModifierArticle(int *ref, float *poids, float *volume, float *prix) { void affichModifierArticle(int *ref, float *poids, float *volume, float *prix) {
int articleIndex;
printf("\t Quelle est la référence de l'article que vous voulez modifier ?\n"); printf("\t Quelle est la référence de l'article que vous voulez modifier ?\n");
while (scanf("%d", ref) != 1 || *ref <= 0) { verifInt(ref);
printf("\t Veuillez entrer une référence correcte !\n");
while (getchar() != '\n');
}
printf("\t Quel est le nouveau poids à entrer ?\n"); printf("\t Quel est le nouveau poids à entrer ?\n");
while (scanf("%f", poids) != 1 || *poids <= 0) { verifFloat(poids);
printf("\t Veuillez entrer un poids correct !\n");
while (getchar() != '\n');
}
printf("\t Quel est le nouveau volume à entrer ?\n"); printf("\t Quel est le nouveau volume à entrer ?\n");
while (scanf("%f", volume) != 1 || *volume <= 0) { verifFloat(volume);
printf("\t Veuillez entrer un volume correct !\n");
while (getchar() != '\n');
}
printf("\t Quel est le nouveau prix à entrer ?\n"); printf("\t Quel est le nouveau prix à entrer ?\n");
while (scanf("%f", prix) != 1 || *prix <= 0) { verifFloat(prix);
printf("\t Veuillez entrer un prix correct !\n");
while (getchar() != '\n');
}
} }
void affichAjoutClient(int tNumClient[], int tLogique, int *numC) { void affichAjoutClient(int tNumClient[], int tLogique, int *numC) {
printf("\t Veuillez entrer le numéro du nouveau client\n"); int clientIndex;
while (scanf("%d", numC) != 1 || *numC <= 0) { printf("Veuillez entrer le numéro du nouveau client : ");
printf("Entrez un numéro valide !\n"); verifInt(numC);
while (getchar() != '\n');
} clientIndex = trouver_index_client(*numC, tNumClient, tLogique);
for (int i = 0; i < tLogique; ++i) {
if (*numC == tNumClient[i]) { while (clientIndex != -1) {
fprintf(stderr, "\t /!/ Client déjà existant. /!/\n"); fprintf(stderr, "\x1B[31mERREUR : Client déjà existant. Veuillez entrer un numéro valide :\x1B[0m ");
return; verifInt(numC);
} clientIndex = trouver_index_client(*numC, tNumClient, tLogique);
} }
} }
int affichageConnexion(void) int affichageConnexion(void)
{ {
char mdpEnter[20]; char mdpEnter[20];
printf("Entrer le mot de passe responsable : "); char* mdp= getpass("Entrer le mot de passe responsable : ");
scanf("%s", mdpEnter); // printf("Entrer le mot de passe responsable : ");
// scanf("%s", mdpEnter);
strcpy(mdpEnter, mdp);
int verif = decodageMDP(mdpEnter); int verif = decodageMDP(mdpEnter);
@ -219,107 +185,96 @@ int affichageConnexion(void)
void affichModifClient(int tNumClient[], int tSus[], int tLogique) void affichModifClient(int tNumClient[], int tSus[], int tLogique)
{ {
int choix, numC; int choix, numC, indexClient;
printf("\tEntrez le numéro du client : "); printf("Entrez le numéro du client : ");
while( scanf("%d", &numC) != 1 || numC <=0 ) verifInt(&numC);
indexClient = trouver_index_client(numC, tNumClient, tLogique);
while ( indexClient == -1 )
{ {
printf("\t Entrez une valeur valide ! \n"); fprintf(stderr, "\x1B[31mERREUR : Client non trouvé. Veuillez entrer un numéro valide :\x1B[0m ");
while (getchar() != '\n'); verifInt(&numC);
indexClient = trouver_index_client(numC, tNumClient, tLogique);
} }
for ( int i = 0; i <= tLogique; i++) if ( tSus[indexClient] == 0)
{
if ( numC == tNumClient[i] )
{ {
if ( tSus[i] == 0 ) printf("La cagnotte du client n'est pas suspendu, voulez-vous le suspendre ? ( Oui = 1 / Non = 0 ) : ");
{
printf("\t La cagnotte du client n'est pas suspendu, voulez-vous le suspendre ?\n ( Oui = 0 / Non = 1 )\n ");
while(scanf("%d", &choix) != 1 || choix < 0 || choix > 1) while(scanf("%d", &choix) != 1 || choix < 0 || choix > 1)
{ {
printf("\t Veuillez entrer un choix valide ! \n"); fprintf(stderr, "\x1B[31mERREUR : Veuillez entrer un choix valide ! : \x1B[0m");
while (getchar() != '\n'); while (getchar() != '\n');
} }
if ( choix == 0 ) if ( choix == 1 )
{ {
tSus[i] = 1; tSus[indexClient] = 1;
printf("\t La cagnotte est maintenant suspendu\n"); printf("La cagnotte est maintenant suspendu\n");
return; return;
} }
else else
{ {
printf("\t La cagnotte n'a pas été changé. Au revoir ! \n"); printf("La cagnotte n'a pas été changé. Au revoir ! \n");
return; return;
} }
} }
else else
{ {
printf("\t La cagnotte du client %d est suspendue, voulez-vous l'activer à nouveau ?\n ( Oui = 0 / Non = 1 )\n", tNumClient[i]); printf("La cagnotte du client %d est suspendue, voulez-vous l'activer à nouveau ? ( Oui = 1 / Non = 0 ) : ", tNumClient[indexClient]);
while(scanf("%d", &choix) != 1 || choix < 0 || choix > 1) while(scanf("%d", &choix) != 1 || choix < 0 || choix > 1)
{ {
printf("\t Veuillez entrer un choix valide ! \n"); fprintf(stderr, "\x1B[31mERREUR : Veuillez entrer un choix valide ! : \x1B[0m");
while (getchar() != '\n'); while (getchar() != '\n');
} }
if ( choix == 0 ) if ( choix == 1 )
{ {
tSus[i] = 0; tSus[indexClient] = 0;
printf("\t La cagnotte n'est plus suspendu\n"); printf("La cagnotte n'est plus suspendu\n");
return; return;
} }
else else
{ {
printf("\t La cagnotte n'a pas été changé. Au revoir ! \n"); printf("La cagnotte n'a pas été changé. Au revoir ! \n");
return; return;
} }
} }
} }
}
printf("\t Le client %d n'a pas été trouvé. \n", numC);
return;
}
void suppressionClient(int tNumClient[], float tCagnotte[], int tSus[], int *tLogique) void suppressionClient(int tNumClient[], float tCagnotte[], int tSus[], int *tLogique) {
{ int choix, numC, indexClient;
int choix, numC; printf("Entrez le numéro du client : ");
printf("\tEntrez le numéro du client : "); verifInt(&numC);
while( scanf("%d", &numC) != 1 || numC <=0 )
{
printf("\t Entrez une valeur valide ! \n");
while (getchar() != '\n');
}
indexClient = trouver_index_client(numC, tNumClient, *tLogique);
for ( int i = 0; i < *tLogique; ++i) while (indexClient == -1)
{
if ( numC == tNumClient[i] )
{
printf("\tÊtes-vous sur de vouloir supprimer ce client ? ( Oui = 0 / Non = 1 )\n");
while(scanf("%d", &choix) != 1 || choix < 0 || choix > 1)
{ {
printf("\t Veuillez entrer un choix valide ! \n"); fprintf(stderr, "\x1B[31mERREUR : Client %d non trouvé. Veuillez entrer un numéro valide :\x1B[0m ", numC);
verifInt(&numC);
indexClient = trouver_index_client(numC, tNumClient, *tLogique);
} }
if ( choix == 0 )
{ printf("Êtes-vous sur de vouloir supprimer ce client ? ( Oui = 1 / Non = 0 ) : ");
while ( i < *tLogique-1 ) while (scanf("%d", &choix) != 1 || choix < 0 || choix > 1) {
{ fprintf(stderr, "\x1B[31mERREUR : Veuillez entrer un choix valide ! : \x1B[0m");
tNumClient[i] = tNumClient[i+1];
tCagnotte[i] = tCagnotte[i+1];
tSus[i] = tSus[i+1];
i++;
} }
printf("Le client %d a été supprimé.\n", tNumClient[i]);
if (choix == 1) {
while (indexClient < *tLogique - 1) {
tNumClient[indexClient] = tNumClient[indexClient + 1];
tCagnotte[indexClient] = tCagnotte[indexClient + 1];
tSus[indexClient] = tSus[indexClient + 1];
indexClient++;
}
printf("\033[32mLe client %d a été supprimé avec succès.\033[0m\n", tNumClient[indexClient]);
(*tLogique)--; (*tLogique)--;
return; return;
} } else {
else printf("\t Le client %d n'a pas été supprimé.\n", tNumClient[indexClient]);
{
printf("\t Le client %d n'a pas été supprimé.\n", tNumClient[i]);
return; return;
} }
}
}
printf("\t Le client %d n'a pas été trouvé. \n", numC);
return;
} }
void affichModifMDP(void) void affichModifMDP(void)
@ -327,13 +282,13 @@ void affichModifMDP(void)
int choix, decalage; int choix, decalage;
char newMDP[MAX_SIZE_MDP], confirmMDP[MAX_SIZE_MDP]; char newMDP[MAX_SIZE_MDP], confirmMDP[MAX_SIZE_MDP];
printf("\t /!/ Vous entrez dans le menu de modification du mot de passe /!/\n"); printf("\t /!/ Vous entrez dans le menu de modification du mot de passe /!/\n");
printf("\t Êtes-vous sur de vouloir changer le mot de passe ?\n Si oui, entrez 0 et sinon entrez 1\n"); printf("\t Êtes-vous sur de vouloir changer le mot de passe ?\n Si oui, entrez 1 et sinon entrez 0\n");
while (scanf("%d", &choix) !=1 || choix < 0 || choix > 1) while (scanf("%d", &choix) !=1 || choix < 0 || choix > 1)
{ {
printf("/!/ Entrez une valeur valide /!/"); fprintf(stderr, "\x1B[31mERREUR : /!/ Entrez une valeur valide : /!/ \x1B[0m");
while (getchar() != '\n'); while (getchar() != '\n');
} }
if ( choix == 1 ) if ( choix == 0 )
{ {
printf("\t Vous quittez le menu de modification du mot de passe.\n"); printf("\t Vous quittez le menu de modification du mot de passe.\n");
return; return;
@ -372,7 +327,7 @@ void affichModifMDP(void)
int verif = verifModifMDP(newMDP, confirmMDP, decalage); int verif = verifModifMDP(newMDP, confirmMDP, decalage);
if ( verif == 0 ) if ( verif == 0 )
{ {
printf("\t Mot de passe modifié !\n"); printf("\t\033[32mMot de passe modifié avec succès!\033[0m\n");
return; return;
} }
else else
@ -390,33 +345,25 @@ void creerReduc( int tRefReduc[], int tReduc[], int *tLogReduc, int tPhysiqueRed
if ( *tLogReduc == tPhysiqueReduc) if ( *tLogReduc == tPhysiqueReduc)
{ {
fprintf(stderr, "\tTableau pleins !\n"); fprintf(stderr, "\x1B[31mERREUR : Tableau pleins !\n \x1B[0m");
return; return;
} }
printf("\tA quel article voulez-vous ajouter une promotion ?\n"); printf("A quel article voulez-vous ajouter une promotion : ");
while (scanf("%d", &ref) !=1 || ref < 0) verifInt(&ref);
{
printf("\t Entrez une référence correcte !\n");
while (getchar() != '\n');
}
int verif = trouver_index_article(ref, tRef, tLogArticle); int verif = trouver_index_article(ref, tRef, tLogArticle);
while ( (verif = trouver_index_article(ref, tRef, tLogArticle)) == -1 ) while ( (verif = trouver_index_article(ref, tRef, tLogArticle)) == -1 )
{ {
printf("\t Entrez une référence existante !\n"); printf("\x1B[31mERREUR : Entrez une référence existante ! : \x1B[0m");
while (scanf("%d", &ref) !=1 || ref < 0) verifInt(&ref);
{
printf("\t Entrez une référence correcte !\n");
while (getchar() != '\n');
}
} }
printf("\tQuel pourcentage ?\n"); printf("Entrez le pourcentage pourcentage : ");
while (scanf("%f", &reduc) !=1 || reduc < 0 || reduc > 100) while (scanf("%f", &reduc) !=1 || reduc < 0 || reduc > 100)
{ {
printf("\t Entrez un nombre correcte !\n"); printf("\x1B[31mERREUR : Entrez un nombre correcte ! : \x1B[0m");
while (getchar() != '\n'); while (getchar() != '\n');
} }
@ -424,30 +371,22 @@ void creerReduc( int tRefReduc[], int tReduc[], int *tLogReduc, int tPhysiqueRed
tPrix[indexPrix] = tPrix[indexPrix]*(1-reduc/100); tPrix[indexPrix] = tPrix[indexPrix]*(1-reduc/100);
tReduc[*tLogReduc] = reduc; tReduc[*tLogReduc] = reduc;
tRefReduc[*tLogReduc] = ref; tRefReduc[*tLogReduc] = ref;
printf("\n\tModification réussi !\n\n"); printf("\n\t\033[32mModification réussi !\033[0m\n\n");
++(*tLogReduc); ++(*tLogReduc);
} }
int affichSuprReduc(int tRefReduc[], int tLogReduc, int *indexReduc) int affichSuprReduc(int tRefReduc[], int tLogReduc, int *indexReduc)
{ {
int ref; int ref;
printf("\tQuel est la référence de l'article auquel il faut supprimer la réduction ?\n"); printf("Entrez la référence de l'article auquel il faut supprimer la réduction : ");
while (scanf("%d", &ref) !=1 || ref < 0) verifInt(&ref);
{
fprintf(stderr, "\t Entrez une référence correcte !\n");
while (getchar() != '\n');
}
while( ( *indexReduc = trouver_index_article(ref, tRefReduc, tLogReduc) )== -1 ) while( ( *indexReduc = trouver_index_article(ref, tRefReduc, tLogReduc) )== -1 )
{ {
printf("\t Entrez une référence qui a une réduction !\n"); printf("\x1B[31mERREUR : Entrez une référence qui a une réduction ! : \x1B[0m");
while (scanf("%d", &ref) !=1 || ref < 0) verifInt(&ref);
{
printf("\t Entrez une référence correcte !\n");
while (getchar() != '\n');
}
} }
printf("\t Suppression réussi !\n"); printf("\n\t\033[32mSuppression réussi !\033[0m\n");
return ref; return ref;
} }

@ -3,6 +3,11 @@
* @brief En-tête des fonctions liées à l'interface du responsable. * @brief En-tête des fonctions liées à l'interface du responsable.
*/ */
#include <stdio.h>
#include <unistd.h>
#include "../core_logic/responsable.h"
#include "../core_logic/client.h"
/** /**
* @brief Affiche la liste des articles. * @brief Affiche la liste des articles.
* @author Yannis Doumir Fernandes * @author Yannis Doumir Fernandes

Loading…
Cancel
Save