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 8a155df..7925d39 100644 --- a/src/display.c +++ b/src/display.c @@ -117,7 +117,7 @@ void display_basket(int basket_tab_ref[], int tabItemRef[], int basket_qte[], fl { float total_weight_line[tlog_basket], total_volume_line[tlog_basket], total_price_line[tlog_basket]; float totalWeight = 0, totalVol = 0, total_price = 0, weight[tmaxArticles], volume[tmaxArticles], unitPrice[tmaxArticles]; - int i, found, index, j = 0; + int i, found, index; printf("Récapitulatif de votre panier:\n"); @@ -128,14 +128,13 @@ void display_basket(int basket_tab_ref[], int tabItemRef[], int basket_qte[], fl index = searchTab(tabItemRef, basket_tab_ref[i], tlogItem, &found); if (found == 1) { - weight[j] = tabWeight[index]; - volume[j] = tabVolume[index]; - unitPrice[j] = tabUnitPrice[index]; - j++; + weight[i] = tabWeight[index]; + volume[i] = tabVolume[index]; + unitPrice[i] = tabUnitPrice[index]; } - total_weight_line[i] = basket_qte[i]*weight; - total_volume_line[i] = basket_qte[i]*volume; - total_price_line[i] = basket_qte[i]*unitPrice; + total_weight_line[i] = basket_qte[i]*weight[i]; + total_volume_line[i] = basket_qte[i]*volume[i]; + total_price_line[i] = basket_qte[i]*unitPrice[i]; totalWeight += total_weight_line[i]; totalVol += total_volume_line [i]; total_price += total_price_line[i]; @@ -145,5 +144,5 @@ void display_basket(int basket_tab_ref[], int tabItemRef[], int basket_qte[], fl printf("Prix total: %f€\n", total_price); printf("Poids total: %fkg\n", totalWeight); printf("Volume total: %fm³\n", totalVol); - printf("Cagnotte:%.2f€", cagnotte) + printf("Cagnotte:%.2f€", cagnotte); } diff --git a/src/exe b/src/exe old mode 100644 new mode 100755 index 91811c8..d10b2c6 Binary files a/src/exe and b/src/exe differ diff --git a/src/login.c b/src/login.c index 0232656..3e53c34 100644 --- a/src/login.c +++ b/src/login.c @@ -12,9 +12,9 @@ * @param tlog: Taille logique des Tableaux * @return Est Admin ? (1 > 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; } @@ -78,20 +78,20 @@ int login(int clientID[], int clientPassword[], int isAdmin[], int tlog) * @param tlog: Taille logique des Tableaux * @return 0 > Tout s'est bien passé, -1 > L'utilisateur a quitté, -2 > La taille physique du tableau est dépassée */ -void signup(int clientID[], int clientPassword[], float cagnotte[], int suspended[], 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) { @@ -110,4 +110,5 @@ void signup(int clientID[], int clientPassword[], float cagnotte[], int suspende } 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 0d8c399..3cfefa9 100644 --- a/src/main.h +++ b/src/main.h @@ -28,8 +28,10 @@ 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 void inputClient(int id, int passwd, int index, int clientID[], int clientPassword[], float cagnotte[], int suspended[], int isAdmin[], int *tlog); @@ -53,12 +55,13 @@ int searchTab(int targetTab[], int valSearched, int tLog, int *found); 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); 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 basket_qte[], float weight[], float volume[], float cagnotte[], float unitPrice[], int tlog, int tlog_basket); -void basket_del_article(int basket_tab_ref[], int basket_tab_qte[], 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); -void signup(int clientID[], int clientPassword[], float cagnotte[], int suspended[], 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 int encrypt(int password); @@ -66,4 +69,4 @@ int decrypt(int password); //! MENUS 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[], float tabPrice[], int tlogItem, int *tlogBasket); \ No newline at end of file +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 1b62717..c37aeb3 100644 --- a/src/menu.c +++ b/src/menu.c @@ -5,7 +5,7 @@ #include "main.h" -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[], float tabPrice[], int tlogItem, int *tlogBasket) +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, constraint; while (choice != 6) @@ -29,12 +29,12 @@ void clientMenu(float *weight, float *volume, float *price, int tabItemRef[], fl break; case 2: basket_add(tabItemRef, unitPrice, cagnotte, basket_tab_ref, basket_tab_qte, tlogItem, tlogBasket); - constraint = constraintExceeded(*weight, *volume, price, cagnotte, tabWeight, tabVolume, tabPrice, tabItemRef, 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, tabPrice[], tlogItem, *tlogBasket); + display_basket(basket_tab_ref, tabItemRef, basket_tab_qte, tabWeight, tabVolume, *cagnotte, unitPrice, tlogItem, *tlogBasket); break; case 4: reinit_basket(tlogBasket); diff --git a/src/modif.c b/src/modif.c index 686486d..c442074 100644 --- a/src/modif.c +++ b/src/modif.c @@ -28,10 +28,10 @@ void inputClient(int id, int passwd, int index, int clientID[], int clientPasswo } // 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); diff --git a/src/panier.c b/src/panier.c index 8768f3b..bc97423 100644 --- a/src/panier.c +++ b/src/panier.c @@ -106,7 +106,7 @@ int constraintExceeded(float weightConstraint, float volumeConstraint, float *pr 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, tlogItem, &trouve); @@ -155,12 +155,12 @@ void basket_del_article(int basket_tab_ref[], int basket_tab_qte[], int *tlog_ba 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) { @@ -184,7 +184,7 @@ void basket_del_article(int basket_tab_ref[], int basket_tab_qte[], int *tlog_ba } else if (qte_to_del==basket_tab_qte[index_to_del]) { - for (i=tlog_basket; i>index_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];