diff --git a/donnee/articles.txt b/donnee/articles.txt index cd18332..915db85 100644 --- a/donnee/articles.txt +++ b/donnee/articles.txt @@ -1,3 +1,3 @@ - 464 50.00 25.50 60.00 + 464 50.00 50.00 0.00 958 4.75 60.00 32.00 - 101 2.00 2.00 2.00 + 101 2.00 2.00 3.00 diff --git a/donnee/client.txt b/donnee/client.txt index 90cc676..8f5b29f 100644 --- a/donnee/client.txt +++ b/donnee/client.txt @@ -1,4 +1,4 @@ 32 69.00 1 660 5351.40 0 5079 75.50 0 -53 0.00 0 +53 0.00 0 \ No newline at end of file diff --git a/donnee/mdp.txt b/donnee/mdp.txt index 83d37f7..9aa531e 100644 --- a/donnee/mdp.txt +++ b/donnee/mdp.txt @@ -1 +1 @@ -flz 17 \ No newline at end of file +bhv 65 \ No newline at end of file diff --git a/donnee/promotion.txt b/donnee/promotion.txt index e69de29..706fabb 100644 --- a/donnee/promotion.txt +++ b/donnee/promotion.txt @@ -0,0 +1,2 @@ +958 50 +101 25 diff --git a/src/app/core_logic/client.c b/src/app/core_logic/client.c index 40cb08e..e9c7f63 100644 --- a/src/app/core_logic/client.c +++ b/src/app/core_logic/client.c @@ -96,4 +96,4 @@ void verifFloat(float *var) { fprintf(stderr, "\x1B[31mERREUR : Veuillez entrer une valeur valide (valeur positive) :\x1B[0m "); while (getchar() != '\n'); } -} +} \ No newline at end of file diff --git a/src/app/core_logic/client.h b/src/app/core_logic/client.h index 6c49951..8481f59 100644 --- a/src/app/core_logic/client.h +++ b/src/app/core_logic/client.h @@ -88,4 +88,4 @@ void verifInt(int *var); */ void verifFloat(float *var); -#endif // CLIENT_H +#endif // CLIENT_H \ No newline at end of file diff --git a/src/app/core_logic/responsable.c b/src/app/core_logic/responsable.c index c5be947..8c91598 100644 --- a/src/app/core_logic/responsable.c +++ b/src/app/core_logic/responsable.c @@ -47,7 +47,7 @@ void sauvegardArticles(int tRef[], float tPoids[], float tVol[], float tPrix[], fprintf(stderr, "\n Problème ouverture ficher\n"); return; } - + for ( i = 0; i < tLogique; i++) { fprintf(fe,"\t %d\t %.2f\t %.2f\t %.2f\n", tRef[i], tPoids[i], tVol[i], tPrix[i]); @@ -124,7 +124,7 @@ void modifierArticle(int tRef[], float tPoids[], float tVol[], float tPrix[], in } -void ajouterClient(int tNumClient[], float tCagnotte[], int tSus[], int *tLogique, int tPhysique) +void ajouterClient(int tNumClient[], float tCagnotte[], int tSus[], int *tLogique) { int numC = 0; affichAjoutClient(tNumClient, *tLogique, &numC); @@ -180,11 +180,11 @@ int decodageMDP(char *mdpEnter) void chiffrementCesar(char *mdp, int decalage) { int i; int longueur = strlen(mdp); - for (i = 0; i < longueur; ++i) - { + for (i = 0; i < longueur; ++i) + { if (mdp[i] >= 'a' && mdp[i] <= 'z') { mdp[i] = 'a' + (mdp[i] - 'a' + decalage) % 26; - } else if (mdp[i] >= 'A' && mdp[i] <= 'Z') + } else if (mdp[i] >= 'A' && mdp[i] <= 'Z') { mdp[i] = 'A' + (mdp[i] - 'A' + decalage) % 26; } @@ -200,14 +200,14 @@ int verifModifMDP(char *mdp, char *confirmMDP, int decalage) } fprintf(stderr, "\tLes mot de passe ne sont pas identiques !\n"); return -1; - + } -int enregistrerMotDePasse(char *mdp, int decalage) +int enregistrerMotDePasse(char *mdp, int decalage) { FILE *fe; fe = fopen("donnee/mdp.txt", "w"); - if (fe == NULL) + if (fe == NULL) { fprintf(stderr,"Erreur lors de l'ouverture du fichier.\n"); return -1; @@ -219,22 +219,64 @@ int enregistrerMotDePasse(char *mdp, int decalage) fclose(fe); return 0; } -/* -int chargementReduc( int tRefProm[], int tReduc[]) + +int chargementReduc( int tRefProm[], int tReduc[], int tPhysique) { int i = 0, ref, reduc; FILE *fe; - fe = fopen("promotion.txt", "r"); + fe = fopen("donnee/promotion.txt", "r"); if ( fe == NULL ) - { + { fprintf(fe, "Problème ouverture fichier"); return -1; } - while ( scanf("%d %d", &ref, &reduc) == 2) + while ( i < tPhysique && fscanf(fe, "%d %d", &ref, &reduc) == 2 ) { tRefProm[i] = ref; tReduc[i] = reduc; ++i; } + fclose(fe); + return i; +} + +void sauvegardeReduc( int tRefReduc[], int tReduc[], int tLogReduc) +{ + FILE * fe; + fe = fopen("donnee/promotion.txt", "w"); + if ( fe == NULL ) + { + fprintf(stderr, "Problème ouverture fichier.\n"); + return; + } + + for ( int i = 0; i < tLogReduc; ++i) + { + fprintf(fe, "%d\t%d\n", tRefReduc[i], tReduc[i]); + } + fclose(fe); + return; } -*/ + +float retrouvePrix(float prixReduit, int reduction) +{ + printf("BLABLA%d", reduction); + return prixReduit / (1.0 - (reduction / 100.0)); +} + +void suppressionReduc(int tRefReduc[], int tReduc[], int *tLogReduc, int tRef[], float tPrix[], int tLogArticle) +{ + int indexReduc, indexPrix, ref; + float temp; + ref = affichSuprReduc( tRefReduc, *tLogReduc, &indexReduc); + for ( int i = indexReduc; i < *tLogReduc-1; ++i) + { + tRefReduc[i] = tRefReduc[i+1]; + tReduc[i] = tReduc[i+1]; + } + + --(*tLogReduc); + indexPrix = trouver_index_article(ref, tRef, tLogArticle); + tPrix[indexPrix] = retrouvePrix(tPrix[indexPrix], tReduc[indexReduc]); + +} \ No newline at end of file diff --git a/src/app/core_logic/responsable.h b/src/app/core_logic/responsable.h index 18dcfd5..6de26e5 100644 --- a/src/app/core_logic/responsable.h +++ b/src/app/core_logic/responsable.h @@ -107,12 +107,12 @@ void modifierArticle(int tRef[], float tPoids[], float tVol[], float tPrix[], in * @param tLogique Pointeur vers la taille logique des tableaux. * @param tPhysique Taille physique des tableaux. */ -void ajouterClient(int tNumClient[], float tCagnotte[], int tSus[], int *tLogique, int tPhysique); +void ajouterClient(int tNumClient[], float tCagnotte[], int tSus[], int *tLogique); /** * @brief Décode le mot de passe du fichier mdp.txt pour le comparer avec le mdp entré. * @author Yannis Doumir Fernandes - * + * * @param mdpEnter Mot de passe entrer par l'utilisateur. */ int decodageMDP(char *mdpEnter); @@ -120,7 +120,7 @@ int decodageMDP(char *mdpEnter); /** * @brief Lis le mot de passe codé dans le fichier mdp.txt, le compare au mot de passe entré à laide de decodageMDP * @author Yannis Doumir Fernandes - * + * * @param texte chaine de caractère comparé avec le mot de passe du fichier. * @param decalage entier qui sert de clé pour déchiffrer le mot de passe. */ @@ -129,3 +129,7 @@ void dechiffrerCesar(char *texte, int decalage); void chiffrementCesar(char *mdp, int decalage); int verifModifMDP(char *mdp, char *confirmMDP, int decalage); int enregistrerMotDePasse(char *mdp, int decalage); +int chargementReduc( int tRefProm[], int tReduc[], int tPhysique); +void sauvegardeReduc(int tRefReduc[], int tReduc[], int tLogReduc); +float retrouvePrix(float prixReduit, int reduction); +void suppressionReduc(int tRefReduc[], int tReduc[], int *tLogReduc, int tRef[], float tPrix[], int tLogArticle); \ No newline at end of file diff --git a/src/app/interface/interface_client.c b/src/app/interface/interface_client.c index ac03a2c..fe36ce3 100644 --- a/src/app/interface/interface_client.c +++ b/src/app/interface/interface_client.c @@ -277,8 +277,8 @@ void deduire_cagnotte(int numClient, float montant, int tNumClient[], float tCag } void quitter_application(int tPanier[], int tLogPanier, int tRef[], float tPoid[], float tVol[], - float tPrixUnitaire[], int tQuantite[], float tCagnotte[], int numClient, - int tNumClient[], int tLogClient, float budget, int tSus[], float volumeCoffre, float chargeMaximale) { + float tPrixUnitaire[], int tQuantite[], float tCagnotte[], int numClient, + int tNumClient[], int tLogClient, float budget, int tSus[], float volumeCoffre, float chargeMaximale) { int reference, articleIndex, quantite, clientIndex, choixCagnotte = 0; float montantTotal = 0, prixArticle = 0, montantDeduction = 0, depassement = 0 , poidsTotal = 0, volumeTotal = 0, poidsArticle = 0, volumeArticle = 0; @@ -425,10 +425,10 @@ void menu_client(int *choix) { void global_client(void) { int choix, tRef[MAX_ARTICLES], tNumClient[MAX_CLIENTS], tSus[MAX_CLIENTS], tLogArticle, tLogClient, - numClient, tQuantite[MAX_ARTICLES], tPanier[MAX_ARTICLES], tLogPanier = 0; + numClient, tQuantite[MAX_ARTICLES], tPanier[MAX_ARTICLES], tLogPanier = 0; float tPoids[MAX_ARTICLES], tVol[MAX_ARTICLES], tPrixUnitaire[MAX_ARTICLES], tCagnotte[MAX_CLIENTS], - volumeCoffre, chargeMaximale; + volumeCoffre, chargeMaximale; double budget = -1.0; @@ -469,4 +469,4 @@ void global_client(void) { return; } } while (choix != 9); -} +} \ No newline at end of file diff --git a/src/app/interface/interface_client.h b/src/app/interface/interface_client.h index 94207a6..9508aa2 100644 --- a/src/app/interface/interface_client.h +++ b/src/app/interface/interface_client.h @@ -171,4 +171,4 @@ void menu_client(int *choix); */ void global_client(void); -#endif // INTERFACE_CLIENT_H +#endif // INTERFACE_CLIENT_H \ No newline at end of file diff --git a/src/app/interface/interface_resp.c b/src/app/interface/interface_resp.c index b07ae55..52eb37f 100644 --- a/src/app/interface/interface_resp.c +++ b/src/app/interface/interface_resp.c @@ -1,15 +1,15 @@ - - #include #include #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_ARTICLES 100 +#define MAX_REDUCTION 100 #define MAX_SIZE_MDP 21 -#define MENU_QUIT 12 +#define MENU_QUIT 14 void affiche_resp(void) { @@ -20,18 +20,31 @@ void affiche_resp(void) { 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\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 : Ajouter un article\t\t\t\t\t||\n"); - printf("||\t6 : Supprimer un article\t\t\t\t||\n"); - printf("||\t7 : Modifier un article\t\t\t\t\t||\n"); - printf("||\t8 : Ajouter un client\t\t\t\t\t||\n"); - printf("||\t9 : Modifier le statut du client\t\t\t||\n"); - printf("||\t10 : Supprimer un client\t\t\t\t||\n"); - printf("||\t11 : Modifier le mot de passe\t\t\t\t||\n"); - printf("||\t12 : Quittez.\t\t\t\t\t\t||\n"); + printf("|| \t\t - Clients -\t\t\t\t\t||\n"); + printf("||\t\t\t\t\t\t\t\t||\n"); + printf("||\t1 : Afficher un client\t\t\t\t\t||\n"); + printf("||\t2 : Afficher les clients\t\t\t\t||\n"); + printf("||\t3 : Ajouter un client\t\t\t\t\t||\n"); + printf("||\t4 : Supprimer un client\t\t\t\t\t||\n"); + printf("||\t5 : Modifier le statut du client\t\t\t||\n"); + printf("||\t\t\t\t\t\t\t\t||\n"); + printf("|| \t\t - Articles -\t\t\t\t\t||\n"); + printf("||\t\t\t\t\t\t\t\t||\n"); + printf("||\t6 : Afficher un article\t\t\t\t\t||\n"); + printf("||\t7 : Afficher les articles\t\t\t\t||\n"); + printf("||\t8 : Ajouter un article\t\t\t\t\t||\n"); + printf("||\t9 : Supprimer un article\t\t\t\t||\n"); + printf("||\t10 : Modifier un article\t\t\t\t||\n"); + printf("||\t\t\t\t\t\t\t\t||\n"); + printf("|| \t\t - Réductions -\t\t\t\t\t||\n"); + printf("||\t\t\t\t\t\t\t\t||\n"); + printf("||\t11 : Ajouter réduction\t\t\t\t\t||\n"); + printf("||\t12 : Supprimer réduction\t\t\t\t||\n"); + printf("||\t\t\t\t\t\t\t\t||\n"); + printf("|| \t\t - Autres -\t\t\t\t\t||\n"); + printf("||\t\t\t\t\t\t\t\t||\n"); + printf("||\t13 : Modifier le mot de passe\t\t\t\t||\n"); + printf("||\t14 : Quittez.\t\t\t\t\t\t||\n"); printf("+----------------------------------------------------------------+\n"); } @@ -51,7 +64,7 @@ void affichUnArticle(int tRef[], float tPoids[], float tVol[], float tPrix[], in printf("\tEntrez une référence valide\n"); while (getchar() != '\n'); } - + for (int i = 0; i < tLogique; ++i) { if (ref == tRef[i]) { printf("\t Ref\t Poids\t Volume\t Prix\n"); @@ -92,40 +105,41 @@ void affichClients(int tNumClient[], float tCagnotte[], int tSus[], int tLogique void affichAjoutArticle(int *ref, float *poids, float *volume, float *prix, int tRef[], int tLogArticle) { printf("\t Entrez la ref du nouveau produit\n"); while (scanf("%d", ref) != 1 || *ref <= 0) { - + printf("\t Veuillez entrer une référence valide.\n"); while (getchar() != '\n'); } if ( trouver_index_article(*ref, tRef, tLogArticle) != -1) { + 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) + 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 (scanf("%f", volume) != 1 || *volume <= 0) + printf("\t Entrez le volume du nouveau produit\n"); + while (scanf("%f", volume) != 1 || *volume <= 0) { printf("\t Veuillez entrer un volume valide.\n"); while (getchar() != '\n'); } - printf("\t Entrez le prix du nouveau produit\n"); - while (scanf("%f", prix) != 1 || *prix <= 0) + printf("\t Entrez le prix du nouveau produit\n"); + while (scanf("%f", prix) != 1 || *prix <= 0) { printf("\t Veuillez entrer un prix valide.\n"); while (getchar() != '\n'); } } - + } void affichSupprimerArticle(int *ref) { @@ -184,7 +198,7 @@ int affichageConnexion(void) scanf("%s", mdpEnter); int verif = decodageMDP(mdpEnter); - + if ( verif == 0 ) { printf("+--------------------------------------------+\n"); @@ -212,7 +226,7 @@ void affichModifClient(int tNumClient[], int tSus[], int tLogique) printf("\t Entrez une valeur valide ! \n"); while (getchar() != '\n'); } - + for ( int i = 0; i <= tLogique; i++) { if ( numC == tNumClient[i] ) @@ -273,8 +287,8 @@ void suppressionClient(int tNumClient[], float tCagnotte[], int tSus[], int *tLo printf("\t Entrez une valeur valide ! \n"); while (getchar() != '\n'); } - - + + for ( int i = 0; i < *tLogique; ++i) { if ( numC == tNumClient[i] ) @@ -348,14 +362,14 @@ void affichModifMDP(void) printf("Veuillez recommencer la saisie : "); while (getchar() != '\n'); } - + printf("\t Veuillez entrer le nouveau décalage\n"); while (scanf("%d", &decalage) != 1 || decalage < 0) { printf("\t Veuillez entrer un nombre valide : "); while (getchar() != '\n'); } - int verif = verifModifMDP(newMDP, confirmMDP, decalage); + int verif = verifModifMDP(newMDP, confirmMDP, decalage); if ( verif == 0 ) { printf("\t Mot de passe modifié !\n"); @@ -368,18 +382,74 @@ void affichModifMDP(void) } } } -/* -void appliquerReduc( int tRefProm[], int tReduc[], int *tLogReduc, int tPhysiqueReduc) + +void creerReduc( int tRefReduc[], int tReduc[], int *tLogReduc, int tPhysiqueReduc, int tRef[], float tPrix[], int tLogArticle) { - int i, ref; + int indexReduc, indexPrix, ref; + float newPrix, reduc; + + if ( *tLogReduc == tPhysiqueReduc) + { + fprintf(stderr, "\tTableau pleins !\n"); + return; + } + printf("\tA quel article voulez-vous ajouter une promotion ?\n"); while (scanf("%d", &ref) !=1 || ref < 0) { - fprintf("\t Entrez une référence correcte !\n"); + printf("\t Entrez une référence correcte !\n"); + while (getchar() != '\n'); } - if () + + int verif = trouver_index_article(ref, tRef, tLogArticle); + + while ( (verif = trouver_index_article(ref, tRef, tLogArticle)) == -1 ) + { + printf("\t Entrez une référence existante !\n"); + while (scanf("%d", &ref) !=1 || ref < 0) + { + printf("\t Entrez une référence correcte !\n"); + while (getchar() != '\n'); + } + } + + printf("\tQuel pourcentage ?\n"); + while (scanf("%f", &reduc) !=1 || reduc < 0 || reduc > 100) + { + printf("\t Entrez un nombre correcte !\n"); + while (getchar() != '\n'); + } + + indexPrix = trouver_index_article(ref, tRef, tLogArticle); + tPrix[indexPrix] = tPrix[indexPrix]*(1-reduc/100); + tReduc[*tLogReduc] = reduc; + tRefReduc[*tLogReduc] = ref; + printf("\n\tModification réussi !\n\n"); + ++(*tLogReduc); +} + +int affichSuprReduc(int tRefReduc[], int tLogReduc, int *indexReduc) +{ + int ref; + printf("\tQuel est la référence de l'article auquel il faut supprimer la réduction ?\n"); + while (scanf("%d", &ref) !=1 || ref < 0) + { + fprintf(stderr, "\t Entrez une référence correcte !\n"); + while (getchar() != '\n'); + } + + while( ( *indexReduc = trouver_index_article(ref, tRefReduc, tLogReduc) )== -1 ) + { + printf("\t Entrez une référence qui a une réduction !\n"); + while (scanf("%d", &ref) !=1 || ref < 0) + { + printf("\t Entrez une référence correcte !\n"); + while (getchar() != '\n'); + } + } + printf("\t Suppression réussi !\n"); + return ref; } -*/ void menu_resp(int *choix) { affiche_resp(); @@ -401,51 +471,64 @@ void global_resp(void) { int tNumClient[MAX_CLIENTS]; float tCagnotte[MAX_CLIENTS]; int tSus[MAX_CLIENTS]; + int tRefReduc[MAX_REDUCTION]; + int tReduc[MAX_REDUCTION]; int tLogArticle = chargementArticles(tRef, tPoids, tVol, tPrix, MAX_ARTICLES); int tLogClient = charger_clients(tNumClient, tCagnotte, tSus, MAX_CLIENTS); + int tLogReduc = chargementReduc(tRefReduc, tReduc, MAX_REDUCTION); // system("clear"); do { menu_resp(&choix); switch (choix) { + + case 1: - affichArticles(tRef, tPoids, tVol, tPrix, tLogArticle); + affichUnClient(tNumClient, tCagnotte, tSus, tLogClient); break; case 2: - affichUnArticle(tRef, tPoids, tVol, tPrix, tLogArticle); + affichClients(tNumClient, tCagnotte, tSus, tLogClient); break; case 3: - affichUnClient(tNumClient, tCagnotte, tSus, tLogClient); + ajouterClient(tNumClient, tCagnotte, tSus, &tLogClient); break; case 4: - affichClients(tNumClient, tCagnotte, tSus, tLogClient); + suppressionClient(tNumClient, tCagnotte ,tSus , &tLogClient); break; case 5: - ajouterArticle(tRef, tPoids, tVol, tPrix, &tLogArticle, MAX_ARTICLES, ref, poids, volume, prix); + affichModifClient(tNumClient, tSus, tLogClient); break; case 6: - supprimerArticle(tRef, tPoids, tVol, tPrix, &tLogArticle); + affichUnArticle(tRef, tPoids, tVol, tPrix, tLogArticle); break; case 7: - modifierArticle(tRef, tPoids, tVol, tPrix, tLogArticle); + affichArticles(tRef, tPoids, tVol, tPrix, tLogArticle); break; case 8: - ajouterClient(tNumClient, tCagnotte, tSus, &tLogClient, MAX_CLIENTS); + ajouterArticle(tRef, tPoids, tVol, tPrix, &tLogArticle, MAX_ARTICLES, ref, poids, volume, prix); break; case 9: - affichModifClient(tNumClient, tSus, tLogClient); + supprimerArticle(tRef, tPoids, tVol, tPrix, &tLogArticle); break; case 10: - suppressionClient(tNumClient, tCagnotte ,tSus , &tLogClient); + modifierArticle(tRef, tPoids, tVol, tPrix, tLogArticle); break; case 11: - affichModifMDP(); + creerReduc( tRefReduc, tReduc, &tLogReduc, MAX_REDUCTION, tRef, tPrix, tLogArticle); break; case 12: + suppressionReduc(tRefReduc, tReduc, &tLogReduc, tRef, tPrix, tLogArticle); + break; + case 13: + affichModifMDP(); + break; + case 14: sauvegardArticles(tRef, tPoids, tVol, tPrix, tLogArticle); sauvegarde_clients(tNumClient, tCagnotte, tSus, tLogClient); + sauvegardeReduc(tRefReduc, tReduc, tLogReduc); printf("Sauvegarde des articles effectuée.\n"); printf("Sauvegarde des clients effectuée.\n"); + printf("Sauvegarde des réductions effectuée.\n"); printf("Au revoir !\n"); return; default: @@ -453,5 +536,5 @@ void global_resp(void) { break; } } while (choix != MENU_QUIT); - -} + +} \ No newline at end of file diff --git a/src/app/interface/interface_resp.h b/src/app/interface/interface_resp.h index 05cd078..f4bebc5 100644 --- a/src/app/interface/interface_resp.h +++ b/src/app/interface/interface_resp.h @@ -135,3 +135,6 @@ void global_resp(void); * @author Yannis Doumir Fernandes */ void affiche_resp(void); + +void creerReduc( int tRefReduc[], int tReduc[], int *tLogReduc, int tPhysiqueReduc, int tRef[], float tPrix[], int tLogArticle); +int affichSuprReduc(int tRefReduc[], int tLogReduc, int *indexReduc); \ No newline at end of file