diff --git a/src/decalage.c b/src/decalage.c index 59ac7b5..483a0cd 100644 --- a/src/decalage.c +++ b/src/decalage.c @@ -8,18 +8,26 @@ #include "main.h" -void decalageADroite(int tab[], int index, int tlog) +void decalageADroiteInt(int tab[], int index, int tlog) { for (int i = tlog; i > index; i--) - { tab[i] = tab[i-1]; - } } -void decalageAGauche(int tab[], int index, int tlog) +void decalageAGaucheInt(int tab[], int index, int tlog) +{ + for (int i = index; i < tlog; i++) + tab[i] = tab[i+1]; +} + +void decalageADroiteFloat(float tab[], int index, int tlog) +{ + for (int i = tlog; i > index; i--) + tab[i] = tab[i-1]; +} + +void decalageAGaucheFloat(float tab[], int index, int tlog) { for (int i = index; i < tlog; i++) - { tab[i] = tab[i+1]; - } } \ No newline at end of file diff --git a/src/display.c b/src/display.c index 38c678b..7925d39 100644 --- a/src/display.c +++ b/src/display.c @@ -108,33 +108,41 @@ void displayClientList(int clientID[], float cagnotte[], int suspended[], int is * @param weight: tableau des poids des articles * @param volume: tableau du volume des articles * @param unitPrice: tableau du prix unitaire des articles - * @param cagnotte: pointeur indiquant la valeur de la cagnotte + * @param cagnotte: valeur de la cagnotte * @param tlog: taille logique du tableau `tab_reference` * @param tlog_basket: taille logique du panier * @return void */ -void display_basket(int basket_tab_ref[], int basket_qte[], float weight[], float volume[], float cagnotte[], float unitPrice[], int tlog, int tlog_basket) +void display_basket(int basket_tab_ref[], int tabItemRef[], int basket_qte[], float tabWeight[], float tabVolume[], float cagnotte, float tabUnitPrice[], int tlogItem, int tlog_basket) { float total_weight_line[tlog_basket], total_volume_line[tlog_basket], total_price_line[tlog_basket]; - float totalWeight = 0, totalVol = 0, total_price = 0; - int i; + float totalWeight = 0, totalVol = 0, total_price = 0, weight[tmaxArticles], volume[tmaxArticles], unitPrice[tmaxArticles]; + int i, found, index; + + + printf("Récapitulatif de votre panier:\n"); + printf("Référence\tQuantité\tPoids\tVolume\tPrix unitaire\tPoids Total\tVol Total\tPrix Total\n"); + for (i=0; i Oui, 0 > Non, -1 > Quitter) */ -int login(int clientID[], int clientPassword[], int isAdmin[], int tlog) +int login(int clientID[], int clientPassword[], int isAdmin[], int tlog, int *index) { - int id, password, index, found, tentative=3; + int id, password, found, tentative=3; printf("Entrez votre identifiant: "); scanf("%d%*c", &id); while (id < 0) @@ -22,7 +22,7 @@ int login(int clientID[], int clientPassword[], int isAdmin[], int tlog) printf("Erreur, l'identifiant doit être positif, entrez votre identifiant: "); scanf("%d%*c", &id); } - index = searchTab(clientID, id, tlog, &found); + *index = searchTab(clientID, id, tlog, &found); while(found == 0) { printf("Erreur, l'identifiant n'existe pas, entrez votre identifiant: "); @@ -39,7 +39,7 @@ int login(int clientID[], int clientPassword[], int isAdmin[], int tlog) } printf("Il vous reste %d tentatives.\n", tentative); - index = searchTab(clientID, id, tlog, &found); + *index = searchTab(clientID, id, tlog, &found); } printf("Entrez votre mot de passe: "); @@ -50,9 +50,9 @@ int login(int clientID[], int clientPassword[], int isAdmin[], int tlog) scanf("%d%*c", &password); } - if (password == decrypt(clientPassword[index])) + if (password == decrypt(clientPassword[*index])) { - if (isAdmin[index] == 1) + if (isAdmin[*index] == 1) { return 1; } @@ -80,18 +80,18 @@ int login(int clientID[], int clientPassword[], int isAdmin[], int tlog) */ int signup(int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[], int *tlog) { - int id, password, index, found, status; - printf("Entrez votre identifiant: "); + int id, password, index, found; + printf("Entrez votre identifiant ou 0 si vous souhaitez quitter: "); scanf("%d%*c", &id); while (id < 0) { - printf("Erreur, l'identifiant doit être positif, entrez votre identifiant: "); + printf("Erreur, l'identifiant doit être positif, entrez votre identifiant ou 0 si vous souhaitez quitter: "); scanf("%d%*c", &id); } index = searchTab(clientID, id, *tlog, &found); while(found == 1) { - printf("Erreur, l'identifiant existe déjà, entrez votre identifiant: "); + printf("Erreur, l'identifiant existe déjà, entrez votre identifiant ou 0 si vous souhaitez quitter: "); scanf("%d%*c", &id); if (id == 0) { @@ -109,5 +109,6 @@ int signup(int clientID[], int clientPassword[], float cagnotte[], int suspended scanf("%d%*c", &password); } - return inputClient(id, password, index, clientID, clientPassword, cagnotte, suspended, isAdmin, tlog); + inputClient(id, password, index, clientID, clientPassword, cagnotte, suspended, isAdmin, tlog); + return 0; } \ No newline at end of file diff --git a/src/main.c b/src/main.c index a94bbc0..73224b8 100644 --- a/src/main.c +++ b/src/main.c @@ -50,11 +50,11 @@ int displayMenu(void) void global(void) { // Déclaration des variables - int tLogArticle, tLogClient, choice, status, currentUser; - int reference[tmaxArticles], clientID[tmaxClients], clientPassword[tmaxClients], suspended[tmaxClients], isAdmin[tmaxClients]; + int tLogItem, tLogClient, tlogBasket, choice, status, currentUser, index; + int reference[tmaxArticles], clientID[tmaxClients], clientPassword[tmaxClients], suspended[tmaxClients], isAdmin[tmaxClients], basket_tab_ref[tmaxArticles], basket_tab_qte[tmaxArticles]; float weight[tmaxArticles], volume[tmaxArticles], unitPrice[tmaxArticles], cagnotte[tmaxClients]; // Chargement de toute les données - chargeDonnees(&tLogArticle, &tLogClient, reference, weight, volume, unitPrice, clientID, clientPassword, cagnotte, suspended, isAdmin); + chargeDonnees(&tLogItem, &tLogClient, reference, weight, volume, unitPrice, clientID, clientPassword, cagnotte, suspended, isAdmin); // Affichage du menu choice = displayMenu(); @@ -63,16 +63,14 @@ void global(void) switch(choice) { case 1: - status = login(clientID, clientPassword, isAdmin, tLogClient); + status = login(clientID, clientPassword, isAdmin, tLogClient, &index); if(status == 1) { - //TODO > Menu Admin - //adminMenu(); + adminMenu(clientID, clientPassword, cagnotte, suspended, isAdmin, reference, weight, volume, unitPrice, &tLogItem, &tLogClient); } else if(status == 0) { - //TODO > Menu Client - //clientMenu(); + clientMenu(&weight[index], &volume[index], &unitPrice[index], reference, unitPrice, &cagnotte[index], basket_tab_ref, basket_tab_qte, weight, volume, tLogItem, &tlogBasket); } else { @@ -98,10 +96,10 @@ void global(void) //opposition(); break; case 4: - sauvegardeDonnees(tLogArticle, tLogClient, reference, weight, volume, unitPrice, clientID, clientPassword, cagnotte, isAdmin, suspended); + sauvegardeDonnees(tLogItem, tLogClient, reference, weight, volume, unitPrice, clientID, clientPassword, cagnotte, isAdmin, suspended); return; case 9: - debugMenu(reference, weight, volume, unitPrice, clientID, cagnotte, suspended, isAdmin, tLogArticle, tLogClient); + debugMenu(reference, weight, volume, unitPrice, clientID, cagnotte, suspended, isAdmin, tLogItem, tLogClient); break; default: printf("Erreur, veuillez entrer un choix valide.\n"); diff --git a/src/main.h b/src/main.h index ff64698..3cfefa9 100644 --- a/src/main.h +++ b/src/main.h @@ -28,11 +28,13 @@ void sauvegardeArticles(int reference[], float weight[], float volume[], float u void sauvegardeClients(int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[], int tLogClient); //! DECALAGES TABLEAUX -void decalageADroite(int tab[], int index, int tlog); -void decalageAGauche(int tab[], int index, int tlog); +void decalageADroiteInt(int tab[], int index, int tlog); +void decalageAGaucheInt(int tab[], int index, int tlog); +void decalageADroiteFloat(float tab[], int index, int tlog); +void decalageAGaucheFloat(float tab[], int index, int tlog); //! GESTION CLIENTS -int inputClient(int id, int passwd, int index, int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[], int *tlog); +void inputClient(int id, int passwd, int index, int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[], int *tlog); void modifyClient(int clientID[], float cagnotte[], int suspended[], int isAdmin[], int tlog); void deleteClient(int clientID[], float cagnotte[], int suspended[], int isAdmin[], int *tlog); @@ -52,12 +54,13 @@ int searchTab(int targetTab[], int valSearched, int tLog, int *found); //! PANIER void clientConstraint(float *weight, float *volume, float *price); int constraintExceeded(float weightConstraint, float volumeConstraint, float *priceConstraint, float *cagnotte, float tabWeight[], float tabVolume[], float tabPrice[], int tabItemRef[], int tabBasketRef[], int tabBasketQuantity[], int tlogItem, int tlogBasket); -int basket_add (int tab_reference[], float unitPrice[], float *cagnotte, int basket_tab_ref[], int basket_tab_qte[], int tlog, int tlog_basket); -void display_basket(int basket_tab_ref[], int basket_qte[], float weight[], float volume[], float cagnotte[], float unitPrice[], int tlog, int tlog_basket); -int basket_del_article( int basket_tab_ref[], int basket_tab_qte[], int tlog_basket); +void basket_add(int tab_reference[], float unitPrice[], float *cagnotte, int basket_tab_ref[], int basket_tab_qte[], int tlogItem, int *tlog_basket); +void display_basket(int basket_tab_ref[], int tabItemRef[], int basket_qte[], float tabWeight[], float tabVolume[], float cagnotte, float tabUnitPrice[], int tlogItem, int tlog_basket); +void reinit_basket(int *tlog_basket); +void basket_del_article(int basket_tab_ref[], int basket_tab_qte[], int *tlog_basket); //! LOGIN -int login(int clientID[], int clientPassword[], int isAdmin[], int tlog); +int login(int clientID[], int clientPassword[], int isAdmin[], int tlog, int *index); int signup(int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[], int *tlog); //! MOT DE PASSE @@ -65,5 +68,5 @@ int encrypt(int password); int decrypt(int password); //! MENUS -void adminMenu(void); -void clientMenu(float *weight, float *volume, float *price); \ No newline at end of file +void adminMenu(int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[], int tabReference[], float tabWeight[], float tabVolume[], float unitPrice[], int *tlogItem, int *tlogClient); +void clientMenu(float *weight, float *volume, float *price, int tabItemRef[], float unitPrice[], float *cagnotte, int basket_tab_ref[], int basket_tab_qte[], float tabWeight[], float tabVolume[], int tlogItem, int *tlogBasket); \ No newline at end of file diff --git a/src/menu.c b/src/menu.c index 9304dbc..c37aeb3 100644 --- a/src/menu.c +++ b/src/menu.c @@ -5,9 +5,9 @@ #include "main.h" -void clientMenu(float *weight, float *volume, float *price) +void clientMenu(float *weight, float *volume, float *price, int tabItemRef[], float unitPrice[], float *cagnotte, int basket_tab_ref[], int basket_tab_qte[], float tabWeight[], float tabVolume[], int tlogItem, int *tlogBasket) { - int choice = 0; + int choice = 0, constraint; while (choice != 6) { printf("\n=================================\n"); @@ -28,12 +28,19 @@ void clientMenu(float *weight, float *volume, float *price) clientConstraint(weight, volume, price); break; case 2: + basket_add(tabItemRef, unitPrice, cagnotte, basket_tab_ref, basket_tab_qte, tlogItem, tlogBasket); + constraint = constraintExceeded(*weight, *volume, price, cagnotte, tabWeight, tabVolume, unitPrice, tabItemRef, basket_tab_ref, basket_tab_qte, tlogItem, *tlogBasket); + if (constraint == -1) + basket_del_article(basket_tab_ref, basket_tab_qte, tlogBasket); break; case 3: + display_basket(basket_tab_ref, tabItemRef, basket_tab_qte, tabWeight, tabVolume, *cagnotte, unitPrice, tlogItem, *tlogBasket); break; case 4: + reinit_basket(tlogBasket); break; case 5: + basket_del_article(basket_tab_ref, basket_tab_qte, tlogBasket); break; case 6: return; @@ -44,7 +51,61 @@ void clientMenu(float *weight, float *volume, float *price) } } -void adminMenu(void) +void adminMenu(int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[], int tabReference[], float tabWeight[], float tabVolume[], float unitPrice[], int *tlogItem, int *tlogClient) { - + int choice = 0; + while (choice != 10) + { + printf("\n=================================\n"); + printf(" Menu Client\n"); + printf("=================================\n"); + printf("1\u2022 Ajouter un client\n"); + printf("2\u2022 Modifier les données d'un client\n"); + printf("3\u2022 Supprimer un client\n"); + printf("4\u2022 Ajouter un article\n"); + printf("5\u2022 Supprimer un article\n"); + printf("6\u2022 Afficher les données d'un article\n"); + printf("7\u2022 Afficher la liste des articles\n"); + printf("8\u2022 Afficher les données d'un client\n"); + printf("9\u2022 Afficher la liste des clients\n"); + printf("10\u2022 Quitter\n"); + printf("=================================\n"); + printf("Votre choix: "); + scanf("%d", &choice); + switch (choice) + { + case 1: + signup(clientID, clientPassword, cagnotte, suspended, isAdmin, tlogClient); + break; + case 2: + modifyClient(clientID, cagnotte, suspended, isAdmin, *tlogClient); + break; + case 3: + deleteClient(clientID, cagnotte, suspended, isAdmin, tlogClient); + break; + case 4: + inputItem(tabReference, tabWeight, tabVolume, unitPrice, tlogItem); + break; + case 5: + deleteItem(tabReference, tabWeight, tabVolume, unitPrice, tlogItem); + break; + case 6: + displayItem(tabReference, tabWeight, tabVolume, unitPrice, *tlogItem); + break; + case 7: + displayItemList(tabReference, tabWeight, tabVolume, unitPrice, *tlogItem); + break; + case 8: + displayClient(clientID, cagnotte, suspended, isAdmin, *tlogClient); + break; + case 9: + displayClientList(clientID, cagnotte, suspended, isAdmin, *tlogClient); + break; + case 10: + return; + default: + printf("Erreur, veuillez entrer un choix valide.\n"); + break; + } + } } \ No newline at end of file diff --git a/src/modif.c b/src/modif.c index 78e6595..c442074 100644 --- a/src/modif.c +++ b/src/modif.c @@ -18,20 +18,20 @@ * @param tlog: Taille logique des tableaux * @return 0 si tout s'est bien passé, -2 si la taille physique du tableau est dépassée */ -int inputClient(int id, int passwd, int index, int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[], int *tlog) +void inputClient(int id, int passwd, int index, int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[], int *tlog) { // Vérification du dépassement de la taille physique du tableau if (*tlog == tmaxClients) { printf("[ERREUR] - La taille physique du tableau est dépassée, impossible d'ajouter un nouveau client.\n"); - return -2; + return; } // Décalage - decalageADroite(clientID, index, *tlog); - decalageADroite(cagnotte, index, *tlog); - decalageADroite(suspended, index, *tlog); - decalageADroite(isAdmin, index, *tlog); + decalageADroiteInt(clientID, index, *tlog); + decalageADroiteFloat(cagnotte, index, *tlog); + decalageADroiteInt(suspended, index, *tlog); + decalageADroiteInt(isAdmin, index, *tlog); clientID[index] = id; clientPassword[index] = encrypt(passwd); @@ -40,7 +40,6 @@ int inputClient(int id, int passwd, int index, int clientID[], int clientPasswor isAdmin[index] = 0; *tlog++; - return 0; // Tout s'est bien passé } /** diff --git a/src/panier.c b/src/panier.c index bbcd628..74982b5 100644 --- a/src/panier.c +++ b/src/panier.c @@ -103,18 +103,18 @@ int constraintExceeded(float weightConstraint, float volumeConstraint, float *pr * @param tlog_basket: taille logique du panier * @return taille logique du panier */ -int basket_add (int tab_reference[], float unitPrice[], float *cagnotte, int basket_tab_ref[], int basket_tab_qte[], int tlog, int tlog_basket) +void basket_add(int tab_reference[], float unitPrice[], float *cagnotte, int basket_tab_ref[], int basket_tab_qte[], int tlogItem, int *tlog_basket) { int ref_to_add, qte_to_add, trouve, index_ajout; - float total_weight[tlog_basket], total_volume[tlog_basket], total_price[tlog_basket], total_cagnotte[tlog_basket]; + float total_weight[tmaxArticles], total_volume[tmaxArticles], total_price[tmaxArticles], total_cagnotte[tmaxArticles]; printf("Quelle référence souhaitez-vous ajouter au panier?"); scanf("%d", &ref_to_add); - index_ajout = searchTab(tab_reference, ref_to_add, tlog, &trouve); + index_ajout = searchTab(tab_reference, ref_to_add, tlogItem, &trouve); while (trouve == 0) { printf("L'élément que vous souhaitez ajouter n'existe pas, ressayez s'il vous plaît"); scanf("%d", &ref_to_add); - index_ajout = searchTab(tab_reference, ref_to_add, tlog, &trouve); + index_ajout = searchTab(tab_reference, ref_to_add, tlogItem, &trouve); } basket_tab_ref[index_ajout] = ref_to_add; printf("Quelle quantité de cet article souhaitez-vous ajouter au panier?"); @@ -127,9 +127,7 @@ int basket_add (int tab_reference[], float unitPrice[], float *cagnotte, int ba basket_tab_qte[index_ajout] = ref_to_add; *cagnotte += (unitPrice[index_ajout]*qte_to_add) *0.1; - tlog_basket = tlog_basket+1; - - return tlog_basket; + *tlog_basket += 1; } /** @@ -141,7 +139,9 @@ void reinit_basket(int *tlog_basket) { *tlog_basket=0; // En mettant tlog_basket à 0, - // on fait comme si la taille logique était à 0, faisant que l'on ne considère plus aucun élément des tableaux + // on fait comme si la taille logique était à 0, faisant que l'on ne considère plus aucun élément des tableaux, + //et donc qu'il est désormais vide. + return tlog_basket; } /** @@ -151,18 +151,18 @@ void reinit_basket(int *tlog_basket) * @param tlog_basket: taille logique du panier * @return taille logique du panier */ -int basket_del_article( int basket_tab_ref[], int basket_tab_qte[], int tlog_basket) +void basket_del_article(int basket_tab_ref[], int basket_tab_qte[], int *tlog_basket) { int ref_to_del, trouve, index_to_del, qte_to_del, i; printf("Quelle référence voulez vous supprimer de votre panier?\n"); scanf("%d",&ref_to_del); - index_to_del = searchTab(basket_tab_ref, ref_to_del, tlog_basket, &trouve); + index_to_del = searchTab(basket_tab_ref, ref_to_del, *tlog_basket, &trouve); while (trouve == 0) { printf("Erreur, la valeur que vous voulez supprimer n'existe pas, réssayez"); scanf("%d",&ref_to_del); - index_to_del = searchTab(basket_tab_ref, ref_to_del, tlog_basket, &trouve); + index_to_del = searchTab(basket_tab_ref, ref_to_del, *tlog_basket, &trouve); } if (basket_tab_qte[index_to_del]>1) { @@ -183,16 +183,15 @@ int basket_del_article( int basket_tab_ref[], int basket_tab_qte[], int tlog_bas if (qte_to_delindex_to_del; i--) + for (i=*tlog_basket; i>index_to_del; i--) { basket_tab_ref[i]=basket_tab_ref[i+1]; basket_tab_qte[i]=basket_tab_qte[i+1]; } - return tlog_basket-1; + *tlog_basket -= 1; } }