ADD function rechercheArticle + suprArticle + modifArticle + some interfaces function

pull/2/head^2
yannis.doumir_fernandes 2 years ago
parent 91542d8c75
commit edeb00b697

@ -29,7 +29,8 @@ int chargementArticles(int tRef[], float tPoids[], float tVol[], float tPrix[],
return i;
}
void sauvegardArticles(int tRef[], float tPoids[], float tVol[], float tPrix[], int tLogique){
void sauvegardArticles(int tRef[], float tPoids[], float tVol[], float tPrix[], int tLogique)
{
int i;
FILE * fe;
fe = fopen("donnee/articles.txt", "w");
@ -45,6 +46,8 @@ void sauvegardArticles(int tRef[], float tPoids[], float tVol[], float tPrix[],
fclose(fe);
}
int ajouterArticle( int tRef[], float tPoids[], float tVol[], float tPrix[], int *tLogique, int tPhysique, int ref, float poids, float volume, float prix)
{
int i = *tLogique;
@ -60,5 +63,51 @@ int ajouterArticle( int tRef[], float tPoids[], float tVol[], float tPrix[], int
tPoids[i] = poids;
tVol[i] = volume;
tPrix[i] = prix;
return 0;
}
void rechercheRefArticle(int tRef[], int ref, int *index, int tLogique)
{
for (int i = 0; i<tLogique; i++)
{
if ( ref == tRef[i] )
{
*index = i;
return;
}
}
*index = -1;
return;
}
void supprimerArticle(int tRef[], float tPoids[], float tVol[], float tPrix[], int *tLogique)
{
int ref, index;
affichSupprimerArticle(&ref);
rechercheRefArticle(tRef, ref, &index, *tLogique);
for( int i = index; i< *tLogique-1; ++i)
{
tRef[i] = tRef[i+1];
tPoids[i] = tPoids[i+1];
tVol[i] = tVol[i+1];
tPrix[i] = tPrix[i+1];
}
*tLogique -= 1;
}
void modifierArticle(int tRef[], float tPoids[], float tVol[], float tPrix[], int tLogique)
{
int ref, index;
float poids, volume, prix;
affichModifierArticle( &ref, &poids, &volume, &prix);
rechercheRefArticle(tRef, ref, &index, tLogique);
tPoids[index] = poids;
tVol[index] = volume;
tPrix[index] = prix;
}

@ -2,4 +2,7 @@
int chargementArticles(int tRef[], float tPoids[], float tVol[], float tPrix[], int tPhysique);
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);
int ajouterArticle( int tRef[], float tPoids[], float tVol[], float tPrix[], int *tLogique, int tPhysique, int ref, float poids, float volume, float prix);
void rechercheRefArticle(int tRef[], int ref, int *index, int tLogique);
void supprimerArticle(int tRef[], float tPoids[], float tVol[], float tPrix[], int *tLogique);
void modifierArticle(int tRef[], float tPoids[], float tVol[], float tPrix[], int tLogique);

@ -1,3 +1,11 @@
#include <stdio.h>
#include "responsable.h"
#include "../interface/interface_resp.h"
#include "../interface/interface_client.h"
int main(void)
{
global_resp();
return 0;
}

@ -1,6 +1,31 @@
#include <stdio.h>
#include <stdlib.h>
#include "interface_resp.h"
#include "app/core_logic/responsable.h"
#define MAX_CLIENTS 100
#define MAX_ARTICLES 100
void affiche_resp(void){
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 : Supprimer un article \t \t \t \t || \n");
printf("||\t6 : Modifier un article \t \t \t \t || \n");
printf("||\t7 : Réinitialiser le panier. \t \t \t \t || \n");
printf("+-----------------------------------------------------------------+\n");
}
/*
void affiche_resp(int a){
printf("\n");
printf("+-------------+ \n");
@ -13,128 +38,222 @@ void affiche_resp(int a){
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("||\t5 : Supprimer un article \t \t \t \t || \n");
printf("||\t6 : Modifier un article \t \t \t \t || \n");
printf("||\t7 : 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;
printf("______________________________________\n");
printf("\t Liste des articles \n\n");
for ( i = 0; i < tLogique; ++i)
for ( int i = 0; i < tLogique; ++i)
{
printf("\t %d %.2f %.2f %.2f\n\n", tRef[i], tPoids[i], tVol[i], tPrix[i]);
}
}
void affichUnArticle(int tRef[], float tPoids[], float tVol[], float tPrix[], int tLogique, int val)
void affichUnArticle(int tRef[], float tPoids[], float tVol[], float tPrix[], int tLogique)
{
int i;
for ( i = 0; i < tLogique; ++i)
int ref;
printf("\tQuelle est la référence de l'article à rechercher ?\n");
while(scanf("%d", &ref != 1 || ref <= 0))
{
printf("\tEntrez une référence valide\n");
while(getchar() != '\n');
}
for ( int i = 0; i < tLogique; ++i)
{
if ( val == tRef[i] )
if ( ref == tRef[i] )
{
printf("\t %d %.2f %.2f %.2f\n\n", tRef[i], tPoids[i], tVol[i], tPrix[i]);
return;
}
}
fprintf(stderr, "Article introuvable");
printf("Article introuvable");
return;
printf("\t Article introuvable\n");
}
void affichUnClient(int tNumClient[], float tCagnotte[], int tSus[], int tLogique, int val)
void affichUnClient(int tNumClient[], float tCagnotte[], int tSus[], int tLogique)
{
int i;
for ( i = 0; i < tLogique; ++i)
int numC;
printf("\tVeuillez entrer le numéro du client à rechercher\n");
while(scanf("%d", &numC) != 1 || numC <= 0)
{
if ( val == tNumClient[i] )
printf("\t Veuillez entrez un numéro valide !\n");
while(getchar() != '\n');
}
for ( int i = 0; i < tLogique; ++i)
{
if ( numC == tNumClient[i] )
{
printf("\t %d %.2f %d\n\n", tNumClient[i], tCagnotte[i], tSus[i]);
return;
}
}
fprintf(stderr, "Client introuvable");
printf("Client introuvable");
printf("Client introuvable\n");
}
void affichUnClients(int tNumClient[], float tCagnotte[], int tSus[], int tLogique, int val)
void affichClients(int tNumClient[], float tCagnotte[], int tSus[], int tLogique)
{
int i;
for ( i = 0; i < tLogique; ++i)
printf("\t Liste des clients\n");
for ( int i = 0; i < tLogique; ++i)
{
printf("\t %d %.2f %d\n\n", tNumClient[i], tCagnotte[i], tSus[i]);
}
fprintf(stderr, "Client introuvable");
printf("Client introuvable");
printf("\t Fin de la liste ! \n");
}
void affichAjoutArticle(int *ref, float *poids, float *volume, float *prix)
{
printf("Entrez la ref du nouveaux produit");
printf("Entrez la ref du nouveaux produit\n");
scanf("%d", ref);
if ( ref < 0 )
if ( *ref < 0 )
{
while ( ref < 0 )
while ( *ref < 0 )
{
printf("Entrez un nombre correct !");
printf("Entrez un nombre correct !\n");
scanf("%d", ref);
}
}
printf("Entrez le poids du nouveaux produit");
printf("Entrez le poids du nouveaux produit\n");
scanf("%f", poids);
if ( poids < 0 )
if ( *poids < 0 )
{
while ( poids < 0 )
while ( *poids < 0 )
{
printf("Entrez un nombre correct !");
printf("Entrez un nombre correct !\n");
scanf("%f", poids);
}
}
printf("Entrez le volume du nouveaux produit");
scanf("%f", poids);
if ( poids < 0 )
printf("Entrez le volume du nouveaux produit\n");
scanf("%f", volume);
if ( *volume < 0 )
{
while ( poids < 0 )
while ( *volume < 0 )
{
printf("Entrez un nombre correct !");
printf("Entrez un poids correct !\n");
scanf("%f", poids);
}
}
printf("Entrez le prix du nouveaux produit");
printf("Entrez le prix du nouveaux produit\n");
scanf("%f", prix);
if ( prix < 0 )
if ( *prix < 0 )
{
while ( prix < 0 )
while ( *prix < 0 )
{
printf("Entrez un nombre correct !");
printf("Entrez un prix correct !\n");
scanf("%f", prix);
}
}
}
void affichSupprimerArticle(int *ref)
{
printf("\t Quel est la référence de l'article voulez-vous supprimez\n");
while(scanf("%d", ref == 1 || *ref <= 0))
{
printf("\t Veuillez entrer une référence valide.")
while(getchar() != '\n');
}
}
void affichModifierArticle(int *ref, float *poids, float *volume, float *prix)
{
printf("\t Quel est la référence de l'article voulez-vous modifier ?\n");
while(scanf("%d", ref) != 1 || *ref <=0)
{
printf("\tVeuillez entrer une référence correcte !\n");
while (getchar() != '\n');
}
printf("\t Quel est le nouveau poids à entrer ?\n");
while(scanf("%f", poids) != 1 || *poids <= 0)
{
printf("\t Veuillez entrer un poids correct !");
while (getchar() != '\n');
}
printf("\t Quel est le nouveau volume à entrer ?\n");
while(scanf("%f", volume) != 1 || *volume <= 0)
{
printf("\t Veuillez entrer un volume correct !");
while (getchar() != '\n');
}
printf("\t Quel est le nouveau prix à entrer ?\n");
while(scanf("%f", prix) != 1 || *prix <= 0)
{
printf("\t Veuillez entrer un prix correct !");
while (getchar() != '\n');
}
}
/*
void menu_resp(int *choix, int jour) {
affiche_resp(jour);
affiche_resp();
//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
while (getchar() != '\n');
affiche_resp(jour);
printf("Veuillez entrer un choix valide : ");
}
}
*/
void menu_resp(int *choix) {
affiche_resp();
//affiche_resp(jour);
printf("Vous choisissez: ");
while (scanf("%d", choix) != 1 || *choix < 0 || *choix > 5) {
while (getchar() != '\n');
affiche_resp();
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);
int choix, a;
int tRef[MAX_ARTICLES];
float tPoids[MAX_ARTICLES];
float tVol[MAX_ARTICLES];
float tPrix[MAX_ARTICLES];
int tNumClient[MAX_CLIENTS];
float tCagnotte[MAX_CLIENTS];
int tSus[MAX_CLIENTS];
int tLogArticle = chargementArticles(tRef, tPoids, tVol, tPrix, MAX_ARTICLES);
//int tLogClient = charger_clients(tNumClient, tCagnotte, tSus, MAX_CLIENTS);
menu_resp(&choix);
switch (choix) {
case 1:
affichArticles(tRef, tPoids, tVol, tPrix, tLogique);
affichArticles(tRef, tPoids, tVol, tPrix, tLogArticle);
break;
case 2:
affichUnArticle(tRef, tPoids, tVol, tPrix, tLogArticle);
break;
case 3:
affichUnClient(tNumClient, tCagnotte, tSus, tLogClient);
break;
case 4:
affichClients(tNumClient, tCagnotte, tSus, tLogClient);
break;
case 5:
modifierArticle(tRef, tPoids, tVol, tPrix, tLogArticle);
break;
case 6:
supprimerArticle(tRef, tPoids, tVol, tPrix, &tLogArticle);
break;
case 7:
printf("Ouai tkt ^^'");
break;
default:
printf("Veuillez entrer un choix valide ! \n");
break;
}
}
}

@ -1,7 +1,10 @@
void affichArticles( int tRef[], float tPoids[], float tVol[], float tPrix[], int tLogique);
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 affichUnClient(int tNumClient[], float tCagnotte[], int tSus[], int tLogique);
void affichClients(int tNumClient[], float tCagnotte[], int tSus[], int tLogique);
void affichAjoutArticle(int *ref, float *poids, float *volume, float *prix);
void affichSupprimerArticle(int *ref);
void affichModifierArticle(int *ref, float *poids, float *volume, float *prix);
void menu_resp(int *choix, int jour);
void global_resp();
void affiche_resp(void);

Loading…
Cancel
Save