ok
This commit is contained in:
		
							
								
								
									
										417
									
								
								VANDAMME28.c
									
									
									
									
									
								
							
							
						
						
									
										417
									
								
								VANDAMME28.c
									
									
									
									
									
								
							@@ -1,8 +1,9 @@
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Fichier client :
 | 
			
		||||
  ------------------------------------------------------------
 | 
			
		||||
  |UINTL NBClients|Bool Tri| Client 0 | Client 1 | .......ETc|
 | 
			
		||||
  ------------------------------------------------------------
 | 
			
		||||
* Fichier client :
 | 
			
		||||
------------------------------------------------------------
 | 
			
		||||
|UINTL NBClients|Bool Tri| Client 0 | Client 1 | .......ETc|
 | 
			
		||||
------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
*/
 | 
			
		||||
@@ -78,15 +79,15 @@ int ageClient(Client *, Date *);
 | 
			
		||||
long int rechercheClient(char *, char*, FILE *, Client *, Date *);
 | 
			
		||||
Bool gestionClient(Client *, Date *);
 | 
			
		||||
int compNP(char *, char *,char *, char *);
 | 
			
		||||
void localiserFichiersClients(char *, FILE *, FILE *);
 | 
			
		||||
void localiserFichiersClients(char *, FILE **, FILE **);
 | 
			
		||||
int sauvegarderClientFile(FILE *, FILE *, Client *); //enregistre le client dans le fichier dat et txt
 | 
			
		||||
FILE * creerFichier(Date *, Client *);
 | 
			
		||||
Bool fichierExistant(char *);
 | 
			
		||||
void sauvergarderFacture(FILE *, Date *, Client *);
 | 
			
		||||
void sauvegarderClientTXT(Client *, FILE *, long,...); /*EcrireDonneesClient
 | 
			
		||||
si int = 0, n'affiche pas l'age, enregistre a la position courante
 | 
			
		||||
      = 1, affiche l'age qui est repris sur le 4e arguments (int) (pour une facture par ex), enregistre a la position courante
 | 
			
		||||
      > 1, ecris sans l'age mais a la position demandé (3e arg)
 | 
			
		||||
= 1, affiche l'age qui est repris sur le 4e arguments (int) (pour une facture par ex), enregistre a la position courante
 | 
			
		||||
> 1, ecris sans l'age mais a la position demandé (3e arg)
 | 
			
		||||
*/
 | 
			
		||||
void clientBinToTXT(FILE *, FILE*);
 | 
			
		||||
void modificationClient(Client *, FILE *, FILE *);
 | 
			
		||||
@@ -94,70 +95,75 @@ void modificationClient(Client *, FILE *, FILE *);
 | 
			
		||||
int main()
 | 
			
		||||
{
 | 
			
		||||
  //printf("%d\n", pointsFidelite(52.23));
 | 
			
		||||
    FILE * clientDatF = NULL, * clientTXTF = NULL;
 | 
			
		||||
    Date date;
 | 
			
		||||
    char tmp;
 | 
			
		||||
    Bool w;
 | 
			
		||||
    time_t curTimeStamp = time(NULL);
 | 
			
		||||
    struct tm *locTime = localtime(&curTimeStamp);
 | 
			
		||||
    locTime->tm_mon += 1;
 | 
			
		||||
    locTime->tm_year += 1900;
 | 
			
		||||
    printf("Voulez-vous utilisez la date système %d/%d/%d (Y|n)?\n", locTime->tm_mday,locTime->tm_mon,locTime->tm_year);
 | 
			
		||||
    scanf("%c", &tmp);
 | 
			
		||||
    if((tmp|0b00100000) != 'y')
 | 
			
		||||
      encoderDate(&date, "Date facturation");
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
      date.jour = locTime->tm_mday;
 | 
			
		||||
      date.moi = locTime->tm_mon;
 | 
			
		||||
      date.annee = locTime->tm_year;
 | 
			
		||||
  FILE ** clientDatF = NULL; clientDatF = malloc(sizeof(FILE *));
 | 
			
		||||
  FILE ** clientTXTF = NULL; clientTXTF = malloc(sizeof(FILE *));
 | 
			
		||||
  Client * client;
 | 
			
		||||
  long int ofsetFileCurClient = 0;
 | 
			
		||||
  char nomClient[__STRLEN__],prenomClient[__STRLEN__];
 | 
			
		||||
  char fichierClientDat[__STRLEN_FILE__];
 | 
			
		||||
  int choixMenu;
 | 
			
		||||
  Date date;
 | 
			
		||||
  char tmp;
 | 
			
		||||
  Bool w;
 | 
			
		||||
  time_t curTimeStamp = time(NULL);
 | 
			
		||||
  struct tm *locTime = localtime(&curTimeStamp);
 | 
			
		||||
  locTime->tm_mon += 1;
 | 
			
		||||
  locTime->tm_year += 1900;
 | 
			
		||||
  printf("Voulez-vous utilisez la date système %d/%d/%d (Y|n)?\n", locTime->tm_mday,locTime->tm_mon,locTime->tm_year);
 | 
			
		||||
  scanf("%c", &tmp);
 | 
			
		||||
  if((tmp|0b00100000) != 'y')
 | 
			
		||||
  encoderDate(&date, "Date facturation");
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    date.jour = locTime->tm_mday;
 | 
			
		||||
    date.moi = locTime->tm_mon;
 | 
			
		||||
    date.annee = locTime->tm_year;
 | 
			
		||||
    //  printf("%d/%d/%d\n", date->jour, date->moi, date->annee );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Client * client;
 | 
			
		||||
    long int ofsetFileCurClient = 0;
 | 
			
		||||
    char nomClient[__STRLEN__],prenomClient[__STRLEN__];
 | 
			
		||||
    char fichierClientDat[__STRLEN_FILE__];
 | 
			
		||||
    int choixMenu;
 | 
			
		||||
    localiserFichiersClients(fichierClientDat, clientDatF, clientTXTF);
 | 
			
		||||
    while(w)
 | 
			
		||||
  }
 | 
			
		||||
  localiserFichiersClients(fichierClientDat, clientDatF, clientTXTF);
 | 
			
		||||
  while(w)
 | 
			
		||||
  {
 | 
			
		||||
    printf("1. Nouveau client\n");
 | 
			
		||||
    printf("2. Client enregistré\n");
 | 
			
		||||
    do{
 | 
			
		||||
      printf("Choix (1|2):");clean_keyboard();scanf("%d", &choixMenu);
 | 
			
		||||
    }while(!(choixMenu<=2 && choixMenu>=1));
 | 
			
		||||
    switch (choixMenu)
 | 
			
		||||
    {
 | 
			
		||||
      printf("1. Nouveau client\n");
 | 
			
		||||
      printf("2. Client enregistré\n");
 | 
			
		||||
      do{
 | 
			
		||||
        printf("Choix (1|2):");clean_keyboard();scanf("%d", &choixMenu);
 | 
			
		||||
      }while(!(choixMenu<=2 && choixMenu>=1));
 | 
			
		||||
      switch (choixMenu)
 | 
			
		||||
      case 1:
 | 
			
		||||
      client = malloc(sizeof(Client));
 | 
			
		||||
      client->ofsetFichierDat = 0;
 | 
			
		||||
      encoderClient(client);
 | 
			
		||||
      afficherClient(client, &date);
 | 
			
		||||
      fseek(*clientTXTF, 0, SEEK_END);
 | 
			
		||||
 | 
			
		||||
      sauvegarderClientFile(*clientTXTF, *clientDatF, client);
 | 
			
		||||
      w = gestionClient(client, &date);
 | 
			
		||||
      break;
 | 
			
		||||
      case 2:
 | 
			
		||||
      printf("Nom du client (sensible a la casse) : ");
 | 
			
		||||
      clean_keyboard();scanf("%s", nomClient);
 | 
			
		||||
      printf("\npRENOM du client (sensible a la casse) : ");
 | 
			
		||||
      clean_keyboard();scanf("%s", prenomClient);
 | 
			
		||||
      ofsetFileCurClient = rechercheClient(nomClient,prenomClient, *clientDatF, client, &date);
 | 
			
		||||
      if(client != NULL)
 | 
			
		||||
      {
 | 
			
		||||
        case 1:
 | 
			
		||||
          client = malloc(sizeof(Client));
 | 
			
		||||
          client->ofsetFichierDat = 0;
 | 
			
		||||
          encoderClient(client);
 | 
			
		||||
          afficherClient(client, &date);
 | 
			
		||||
          sauvegarderClientFile(clientDatF, clientTXTF, client);
 | 
			
		||||
          w = gestionClient(client, &date);
 | 
			
		||||
          break;
 | 
			
		||||
        case 2:
 | 
			
		||||
          printf("Nom du client (sensible a la casse) : ");
 | 
			
		||||
          clean_keyboard();scanf("%s", nomClient);
 | 
			
		||||
          printf("\npRENOM du client (sensible a la casse) : ");
 | 
			
		||||
          clean_keyboard();scanf("%s", prenomClient);
 | 
			
		||||
          ofsetFileCurClient = rechercheClient(nomClient,prenomClient, clientDatF, client, &date);
 | 
			
		||||
          if(client != NULL)
 | 
			
		||||
          {
 | 
			
		||||
            w = gestionClient(client, &date);
 | 
			
		||||
          }
 | 
			
		||||
          else
 | 
			
		||||
          {
 | 
			
		||||
            printf("Client non trouvé !\n");
 | 
			
		||||
            printf("%d",(int)sizeof(Client));
 | 
			
		||||
          }
 | 
			
		||||
          break;
 | 
			
		||||
        w = gestionClient(client, &date);
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
      {
 | 
			
		||||
        printf("Client non trouvé !\n");
 | 
			
		||||
        printf("%d",(int)sizeof(Client));
 | 
			
		||||
      }
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
    free(client);
 | 
			
		||||
    fclose(clientDatF);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
  free(client);
 | 
			
		||||
  fclose(*clientDatF);
 | 
			
		||||
  fclose(*clientTXTF);
 | 
			
		||||
  free(clientDatF);
 | 
			
		||||
  free(clientTXTF);
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
void encoderDate(Date * date, char *invite)
 | 
			
		||||
{
 | 
			
		||||
@@ -170,63 +176,63 @@ void encoderDate(Date * date, char *invite)
 | 
			
		||||
 | 
			
		||||
Bool dateValide(Date * date)
 | 
			
		||||
{
 | 
			
		||||
    int j = date->jour;
 | 
			
		||||
    int m = date->moi;
 | 
			
		||||
    int a = date->annee;
 | 
			
		||||
    int bis;
 | 
			
		||||
    if(m != 2)
 | 
			
		||||
  int j = date->jour;
 | 
			
		||||
  int m = date->moi;
 | 
			
		||||
  int a = date->annee;
 | 
			
		||||
  int bis;
 | 
			
		||||
  if(m != 2)
 | 
			
		||||
  {
 | 
			
		||||
    if(m >= 1 && m <= 7)
 | 
			
		||||
    {
 | 
			
		||||
        if(m >= 1 && m <= 7)
 | 
			
		||||
        {
 | 
			
		||||
            if(m %2 == 0)
 | 
			
		||||
            {
 | 
			
		||||
                if(j >= 1 && j <= 30) return TRUE;
 | 
			
		||||
                else return FALSE;
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                if(j >= 1 && j <= 31) return TRUE;
 | 
			
		||||
                else return FALSE;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else if(m > 7 && m <= 12)
 | 
			
		||||
        {
 | 
			
		||||
            if(m %2 == 0)
 | 
			
		||||
            {
 | 
			
		||||
                if(j >= 1 && j <= 31) return TRUE;
 | 
			
		||||
                else return FALSE;
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                if(j >= 1 && j <= 30) return TRUE;
 | 
			
		||||
                else return FALSE;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
      if(m %2 == 0)
 | 
			
		||||
      {
 | 
			
		||||
        if(j >= 1 && j <= 30) return TRUE;
 | 
			
		||||
        else return FALSE;
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
      {
 | 
			
		||||
        if(j >= 1 && j <= 31) return TRUE;
 | 
			
		||||
        else return FALSE;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    else if(m > 7 && m <= 12)
 | 
			
		||||
    {
 | 
			
		||||
      if(m %2 == 0)
 | 
			
		||||
      {
 | 
			
		||||
        if(j >= 1 && j <= 31) return TRUE;
 | 
			
		||||
        else return FALSE;
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
      {
 | 
			
		||||
        if(j >= 1 && j <= 30) return TRUE;
 | 
			
		||||
        else return FALSE;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    else return FALSE;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    if(a %100 == 0)
 | 
			
		||||
    {
 | 
			
		||||
      if(a %400 == 0) bis = 1;
 | 
			
		||||
      else bis = FALSE;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        if(a %100 == 0)
 | 
			
		||||
        {
 | 
			
		||||
            if(a %400 == 0) bis = 1;
 | 
			
		||||
            else bis = FALSE;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            if(a %4 == 0)bis = 1;
 | 
			
		||||
            else bis = FALSE;
 | 
			
		||||
        }
 | 
			
		||||
        if(bis == 1)
 | 
			
		||||
        {
 | 
			
		||||
            if(j >= 1  &&  j <= 29) return TRUE;
 | 
			
		||||
            else return FALSE;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            if(j >= 1 && j <= 28) return TRUE;
 | 
			
		||||
            else return FALSE;
 | 
			
		||||
        }
 | 
			
		||||
      if(a %4 == 0)bis = 1;
 | 
			
		||||
      else bis = FALSE;
 | 
			
		||||
    }
 | 
			
		||||
    if(bis == 1)
 | 
			
		||||
    {
 | 
			
		||||
      if(j >= 1  &&  j <= 29) return TRUE;
 | 
			
		||||
      else return FALSE;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
      if(j >= 1 && j <= 28) return TRUE;
 | 
			
		||||
      else return FALSE;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void encoderArticle(Article * article)
 | 
			
		||||
@@ -247,11 +253,11 @@ void encoderClient(Client * client)
 | 
			
		||||
  printf("Encoage Client\n");
 | 
			
		||||
  client->fidelite = 0;
 | 
			
		||||
  if(!(printf("Entrez la rue :") && clean_keyboard() && fgets(client->adresse.rue,__STRLEN__,stdin) != NULL && \
 | 
			
		||||
    printf("\nEntrez le numero :" ) && clean_keyboard() && fgets(client->adresse.numero,__STRLEN__,stdin) != NULL && \
 | 
			
		||||
    printf("\nEntrez la localité :") && clean_keyboard() && fgets(client->adresse.localite,__STRLEN__,stdin) != NULL && \
 | 
			
		||||
    printf("\nEntrez le code postal :") && clean_keyboard() && scanf("%d", &(client->adresse.codePostal)) && \
 | 
			
		||||
    printf("\nNom client :") && clean_keyboard() && fgets(client->nom,__STRLEN__,stdin) != NULL &&\
 | 
			
		||||
    printf("\nPrenom client :") && clean_keyboard() && fgets(client->prenom,__STRLEN__,stdin) != NULL))
 | 
			
		||||
  printf("\nEntrez le numero :" ) && clean_keyboard() && fgets(client->adresse.numero,__STRLEN__,stdin) != NULL && \
 | 
			
		||||
  printf("\nEntrez la localité :") && clean_keyboard() && fgets(client->adresse.localite,__STRLEN__,stdin) != NULL && \
 | 
			
		||||
  printf("\nEntrez le code postal :") && clean_keyboard() && scanf("%d", &(client->adresse.codePostal)) && \
 | 
			
		||||
  printf("\nNom client :") && clean_keyboard() && fgets(client->nom,__STRLEN__,stdin) != NULL &&\
 | 
			
		||||
  printf("\nPrenom client :") && clean_keyboard() && fgets(client->prenom,__STRLEN__,stdin) != NULL))
 | 
			
		||||
  {
 | 
			
		||||
    printf("\nErreur lors de l'encodage de l'adresse");
 | 
			
		||||
    exit(-1);
 | 
			
		||||
@@ -259,7 +265,7 @@ void encoderClient(Client * client)
 | 
			
		||||
  cleanFgets(client->adresse.rue);cleanFgets(client->adresse.numero);cleanFgets(client->adresse.localite);
 | 
			
		||||
  cleanFgets(client->nom);cleanFgets(client->prenom);
 | 
			
		||||
  if(!(printf("\n Entrez le numéro de tél. :") && clean_keyboard() &&fgets(client->contact.telephone,13,stdin) && \
 | 
			
		||||
    printf("\nEntrez l'adresse email :") && clean_keyboard() &&fgets(client->contact.email,__STRLEN__,stdin)))
 | 
			
		||||
  printf("\nEntrez l'adresse email :") && clean_keyboard() &&fgets(client->contact.email,__STRLEN__,stdin)))
 | 
			
		||||
  {
 | 
			
		||||
    printf("\nErreur lors de l'encodage des coo de contact");
 | 
			
		||||
    exit(-1);
 | 
			
		||||
@@ -280,6 +286,8 @@ void afficherClient(Client *client, Date *date)
 | 
			
		||||
}
 | 
			
		||||
void sauvegarderClientTXT(Client *client, FILE * file, long arg, ...) //EcrireDonneesClient
 | 
			
		||||
{
 | 
			
		||||
  fprintf(file, "DEBUG2\n");
 | 
			
		||||
  fflush(file);
 | 
			
		||||
  va_list ap;
 | 
			
		||||
  int age = 0;
 | 
			
		||||
  va_start(ap, arg);
 | 
			
		||||
@@ -294,8 +302,9 @@ void sauvegarderClientTXT(Client *client, FILE * file, long arg, ...) //EcrireDo
 | 
			
		||||
    age = va_arg(ap,int);
 | 
			
		||||
    fprintf(file, "Client : %s %s (%d)\n", client->nom, client->prenom,age);
 | 
			
		||||
  }
 | 
			
		||||
  else if(!arg)
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    printf("SUCCES304\n");
 | 
			
		||||
    fprintf(file, "Client : %s %s \n", client->nom, client->prenom);
 | 
			
		||||
  }
 | 
			
		||||
  fprintf(file, "rue : %s\n",client->adresse.rue);
 | 
			
		||||
@@ -304,7 +313,7 @@ void sauvegarderClientTXT(Client *client, FILE * file, long arg, ...) //EcrireDo
 | 
			
		||||
  fprintf(file, "code postal : %d\n",client->adresse.codePostal);
 | 
			
		||||
  fprintf(file, "numéro de tél. : %s\n",client->contact.telephone);
 | 
			
		||||
  fprintf(file, "adresse email : %s\n",client->contact.email);
 | 
			
		||||
  if(arg)
 | 
			
		||||
  if(arg == 1)
 | 
			
		||||
  {
 | 
			
		||||
    fprintf(file, "\nPoints de fidelite aqui : %d\n", client->fidelite);
 | 
			
		||||
  }
 | 
			
		||||
@@ -312,6 +321,10 @@ void sauvegarderClientTXT(Client *client, FILE * file, long arg, ...) //EcrireDo
 | 
			
		||||
  {
 | 
			
		||||
    fprintf(file, "\n===========================================================================\n");
 | 
			
		||||
  }
 | 
			
		||||
  printf("YYYYYOOOOOLLLLLOOOOO\n");
 | 
			
		||||
  fflush(file);
 | 
			
		||||
  system("pause");
 | 
			
		||||
  va_end(ap);
 | 
			
		||||
}
 | 
			
		||||
void encoderFacture(Panier * panier)
 | 
			
		||||
{
 | 
			
		||||
@@ -374,17 +387,17 @@ FILE * creerFichier(Date * date, Client * client)
 | 
			
		||||
  {
 | 
			
		||||
    char fileNameTmp[__STRLEN__+16+255];
 | 
			
		||||
    sprintf(fileNameTmp,"%s%s%d.txt",dir,fileName,i);
 | 
			
		||||
      if(!fichierExistant(fileNameTmp))
 | 
			
		||||
    if(!fichierExistant(fileNameTmp))
 | 
			
		||||
    {
 | 
			
		||||
      FILE * f = fopen(fileNameTmp,"w");
 | 
			
		||||
      if(f==NULL)
 | 
			
		||||
      {
 | 
			
		||||
        FILE * f = fopen(fileNameTmp,"w");
 | 
			
		||||
        if(f==NULL)
 | 
			
		||||
        {
 | 
			
		||||
          printf("Erreur lors de l'ouverture du fichier");
 | 
			
		||||
         return creerFichier(date, client);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
          return f;
 | 
			
		||||
        printf("Erreur lors de l'ouverture du fichier");
 | 
			
		||||
        return creerFichier(date, client);
 | 
			
		||||
      }
 | 
			
		||||
      else
 | 
			
		||||
      return f;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  return NULL;
 | 
			
		||||
}
 | 
			
		||||
@@ -393,9 +406,9 @@ Bool fichierExistant(char * filename)
 | 
			
		||||
  FILE * f = fopen(filename, "r");
 | 
			
		||||
  fclose(f);
 | 
			
		||||
  if(f==NULL)
 | 
			
		||||
    return FALSE;
 | 
			
		||||
  return FALSE;
 | 
			
		||||
  else
 | 
			
		||||
    return TRUE;
 | 
			
		||||
  return TRUE;
 | 
			
		||||
}
 | 
			
		||||
void sauvergarderFacture(FILE * file, Date * date, Client * client)
 | 
			
		||||
{
 | 
			
		||||
@@ -408,15 +421,15 @@ void sauvergarderFacture(FILE * file, Date * date, Client * client)
 | 
			
		||||
  fprintf(file, "\n Info client :");
 | 
			
		||||
  sauvegarderClientTXT(client, file, 1,ageClient(client,date));
 | 
			
		||||
  fprintf(file,"\n|---------------------------------------------------------------------------------------------|\
 | 
			
		||||
                \n|         Designation              |     prixHTVA    |   Quantite   |   10%%   |   prixTVAC    |\
 | 
			
		||||
                \n|---------------------------------------------------------------------------------------------|");
 | 
			
		||||
  \n|         Designation              |     prixHTVA    |   Quantite   |   10%%   |   prixTVAC    |\
 | 
			
		||||
  \n|---------------------------------------------------------------------------------------------|");
 | 
			
		||||
 | 
			
		||||
  for(i=0;client->panier.nbrArt>i;i++)
 | 
			
		||||
  {
 | 
			
		||||
    fprintf(file,"\n|%34s|%12.2f Eur |%14d|    %c    |%12.2f   |",\
 | 
			
		||||
            client->panier.article[i].deisgnation,client->panier.article[i].prixHTVA,client->panier.article[i].quant\
 | 
			
		||||
            ,(client->panier.article[i].quant>=20)?'x':' ',\
 | 
			
		||||
            (client->panier.article[i].quant>=20)?client->panier.article[i].prixHTVA*__TVA__*__REDUC__*client->panier.article[i].quant:client->panier.article[i].prixHTVA*__TVA__*client->panier.article[i].quant);
 | 
			
		||||
    client->panier.article[i].deisgnation,client->panier.article[i].prixHTVA,client->panier.article[i].quant\
 | 
			
		||||
    ,(client->panier.article[i].quant>=20)?'x':' ',\
 | 
			
		||||
    (client->panier.article[i].quant>=20)?client->panier.article[i].prixHTVA*__TVA__*__REDUC__*client->panier.article[i].quant:client->panier.article[i].prixHTVA*__TVA__*client->panier.article[i].quant);
 | 
			
		||||
    prixTot += (client->panier.article[i].quant>=20)?client->panier.article[i].prixHTVA*__TVA__*__REDUC__*client->panier.article[i].quant:client->panier.article[i].prixHTVA*__TVA__*client->panier.article[i].quant;
 | 
			
		||||
  }
 | 
			
		||||
  fprintf(file,"\n|---------------------------------------------------------------------------------------------|");
 | 
			
		||||
@@ -435,15 +448,15 @@ void afficherFacture(Date * date, Client * client)
 | 
			
		||||
  printf("\n Info client :");
 | 
			
		||||
  afficherClient(client, date);
 | 
			
		||||
  printf("\n|---------------------------------------------------------------------------------------------|\
 | 
			
		||||
          \n|         Designation              |     prixHTVA    |   Quantite   |   10%%   |   prixTVAC    |\
 | 
			
		||||
          \n|---------------------------------------------------------------------------------------------|");
 | 
			
		||||
  \n|         Designation              |     prixHTVA    |   Quantite   |   10%%   |   prixTVAC    |\
 | 
			
		||||
  \n|---------------------------------------------------------------------------------------------|");
 | 
			
		||||
 | 
			
		||||
  for(i=0;client->panier.nbrArt>i;i++)
 | 
			
		||||
  {
 | 
			
		||||
    printf("\n|%34s|%12.2f Eur |%14d|    %c    |%12.2f   |",\
 | 
			
		||||
            client->panier.article[i].deisgnation,client->panier.article[i].prixHTVA,client->panier.article[i].quant\
 | 
			
		||||
            ,(client->panier.article[i].quant>=20)?'x':' ',\
 | 
			
		||||
            (client->panier.article[i].quant>=20)?client->panier.article[i].prixHTVA*__TVA__*__REDUC__*client->panier.article[i].quant:client->panier.article[i].prixHTVA*__TVA__*client->panier.article[i].quant);
 | 
			
		||||
    client->panier.article[i].deisgnation,client->panier.article[i].prixHTVA,client->panier.article[i].quant\
 | 
			
		||||
    ,(client->panier.article[i].quant>=20)?'x':' ',\
 | 
			
		||||
    (client->panier.article[i].quant>=20)?client->panier.article[i].prixHTVA*__TVA__*__REDUC__*client->panier.article[i].quant:client->panier.article[i].prixHTVA*__TVA__*client->panier.article[i].quant);
 | 
			
		||||
    prixTot += (client->panier.article[i].quant>=20)?client->panier.article[i].prixHTVA*__TVA__*__REDUC__*client->panier.article[i].quant:client->panier.article[i].prixHTVA*__TVA__*client->panier.article[i].quant;
 | 
			
		||||
  }
 | 
			
		||||
  printf("\n|---------------------------------------------------------------------------------------------|");
 | 
			
		||||
@@ -458,7 +471,7 @@ void cleanFgets(char * str)
 | 
			
		||||
{
 | 
			
		||||
  char *p = strchr(str, '\n');
 | 
			
		||||
  if(p!=NULL)
 | 
			
		||||
    *p = '\0';
 | 
			
		||||
  *p = '\0';
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    printf("Une erreur est arrivé lors du nettoygae \\0");
 | 
			
		||||
@@ -474,7 +487,7 @@ int itoaY(int i, char * buf)
 | 
			
		||||
  buf [4] = '\0';
 | 
			
		||||
  int j;
 | 
			
		||||
  if(!i)
 | 
			
		||||
    return 1;
 | 
			
		||||
  return 1;
 | 
			
		||||
  buf [3] = '1';
 | 
			
		||||
  for(j=1; j<=i && j<=9999 ; j++)
 | 
			
		||||
  {
 | 
			
		||||
@@ -502,9 +515,9 @@ int itoaY(int i, char * buf)
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  if(j>9999)
 | 
			
		||||
    return 0;
 | 
			
		||||
  return 0;
 | 
			
		||||
  else
 | 
			
		||||
    return 1;
 | 
			
		||||
  return 1;
 | 
			
		||||
}
 | 
			
		||||
int itoaDM(int i, char * buf)
 | 
			
		||||
{
 | 
			
		||||
@@ -513,7 +526,7 @@ int itoaDM(int i, char * buf)
 | 
			
		||||
  buf[2] = '\0';
 | 
			
		||||
  int j;
 | 
			
		||||
  if(!i)
 | 
			
		||||
    return 1;
 | 
			
		||||
  return 1;
 | 
			
		||||
  buf[1]++;
 | 
			
		||||
  for(j=1; j<=i && j<=99 ; j++)
 | 
			
		||||
  {
 | 
			
		||||
@@ -528,21 +541,21 @@ int itoaDM(int i, char * buf)
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  if(j>99)
 | 
			
		||||
    return 0;
 | 
			
		||||
  return 0;
 | 
			
		||||
  else
 | 
			
		||||
    return 1;
 | 
			
		||||
  return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Bool clean_keyboard()
 | 
			
		||||
{
 | 
			
		||||
  fflush(stdin);
 | 
			
		||||
  //  char c;
 | 
			
		||||
//while ((c = getchar()) != '\n' && c != EOF) { }
 | 
			
		||||
  //while ((c = getchar()) != '\n' && c != EOF) { }
 | 
			
		||||
  /*  do {
 | 
			
		||||
        c = getc(stdin);
 | 
			
		||||
        printf("%c\n", c);
 | 
			
		||||
    } while (c != '\n' && c != EOF);*/
 | 
			
		||||
    return 1;
 | 
			
		||||
  c = getc(stdin);
 | 
			
		||||
  printf("%c\n", c);
 | 
			
		||||
} while (c != '\n' && c != EOF);*/
 | 
			
		||||
return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int ageClient(Client * client, Date * date)
 | 
			
		||||
@@ -552,7 +565,7 @@ int ageClient(Client * client, Date * date)
 | 
			
		||||
    return (date->annee - client->anniversaire.annee);
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
    return (date->annee - client->anniversaire.annee - 1);
 | 
			
		||||
  return (date->annee - client->anniversaire.annee - 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int pointsFidelite(float prix)
 | 
			
		||||
@@ -596,11 +609,12 @@ long int rechercheClient(char nom[__STRLEN__], char prenom[__STRLEN__], FILE * c
 | 
			
		||||
  {
 | 
			
		||||
    ofsetFileCurClient = ftell(clientDatF);
 | 
			
		||||
    fread(client, sizeof(Client), 1, clientDatF);
 | 
			
		||||
    afficherClient(client, date);
 | 
			
		||||
  }while(!feof(clientDatF) && compNP(client->nom, client->prenom, nom, prenom));
 | 
			
		||||
  if(feof(clientDatF))
 | 
			
		||||
    return 0;
 | 
			
		||||
  return 0;
 | 
			
		||||
  else
 | 
			
		||||
    return ofsetFileCurClient;
 | 
			
		||||
  return ofsetFileCurClient;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Bool gestionClient(Client * client, Date * date)
 | 
			
		||||
@@ -611,7 +625,7 @@ Bool gestionClient(Client * client, Date * date)
 | 
			
		||||
    do
 | 
			
		||||
    {
 | 
			
		||||
      printf("A. Donnees client\n");
 | 
			
		||||
      printf("B. Modification client\n");
 | 
			
		||||
      printf("B. Modification client\n");//acce au file *
 | 
			
		||||
      printf("C. Facture\n");
 | 
			
		||||
      printf("D. Retour\n");
 | 
			
		||||
      printf("E. Quitter");
 | 
			
		||||
@@ -619,68 +633,74 @@ Bool gestionClient(Client * client, Date * date)
 | 
			
		||||
      choix |= 0b00100000;
 | 
			
		||||
    }while(!(choix == 'a' || choix == 'b' || choix == 'c' || choix == 'd' || choix == 'e'));
 | 
			
		||||
    switch (choix) {
 | 
			
		||||
    case 'a':
 | 
			
		||||
      case 'a':
 | 
			
		||||
      afficherClient(client, date);
 | 
			
		||||
      break;
 | 
			
		||||
    case 'b':
 | 
			
		||||
      case 'b':
 | 
			
		||||
      break;
 | 
			
		||||
    case 'c':
 | 
			
		||||
      case 'c':
 | 
			
		||||
      gestionFacture(client, date);
 | 
			
		||||
      break;
 | 
			
		||||
    case 'd':
 | 
			
		||||
      case 'd':
 | 
			
		||||
      return 1;
 | 
			
		||||
      break;
 | 
			
		||||
    case 'e':
 | 
			
		||||
      case 'e':
 | 
			
		||||
      return 0;
 | 
			
		||||
      break;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void localiserFichiersClients(char * fichierClientDat, FILE * clientDatF, FILE * clientTXTF)
 | 
			
		||||
void localiserFichiersClients(char * fichierClientDat, FILE ** clientDatF, FILE ** clientTXTF)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
  char rep[__STRLEN_FILE__];
 | 
			
		||||
  char repTmp[2][__STRLEN_FILE__];
 | 
			
		||||
  unsigned long int nbClients = 0;
 | 
			
		||||
  Bool tri = 0;
 | 
			
		||||
  printf("Repertoir ou se trouve le fichier client.dat et client.txt");
 | 
			
		||||
  clean_keyboard();
 | 
			
		||||
  scanf("%s", rep);
 | 
			
		||||
  sprintf(repTmp[__TAB_CLIENTDAT_FILE__],"%sclients.dat", rep);
 | 
			
		||||
  sprintf(repTmp[__TAB_CLIENTTXT_FILE__],"%sclients.txt", rep);
 | 
			
		||||
  clientDatF = fopen(repTmp[__TAB_CLIENTDAT_FILE__], "r");
 | 
			
		||||
  clientTXTF = fopen(repTmp[__TAB_CLIENTTXT_FILE__], "r");
 | 
			
		||||
  if(clientDatF == NULL || clientTXTF == NULL)
 | 
			
		||||
  *clientTXTF = fopen(repTmp[__TAB_CLIENTTXT_FILE__], "r"); //A faire Une verification correcte se ferait avec access (voir GNU libc P418)
 | 
			
		||||
  *clientDatF = fopen(repTmp[__TAB_CLIENTDAT_FILE__], "r"); //A faire Une verification correcte se ferait avec access (voir GNU libc P418)
 | 
			
		||||
  if(*clientDatF == NULL || *clientTXTF == NULL) //Si un des fichier n'existe pas
 | 
			
		||||
  {
 | 
			
		||||
    char c;
 | 
			
		||||
    fclose(clientDatF);
 | 
			
		||||
    fclose(clientTXTF);
 | 
			
		||||
    printf("\nUn fichier n'existe pas. Voulez-vous les creers (C) ou changer de repertoir (R). (C|R)?");
 | 
			
		||||
    if(!(clientDatF == NULL && clientTXTF == NULL))
 | 
			
		||||
    if(!(*clientDatF == NULL && *clientTXTF == NULL))
 | 
			
		||||
      printf("Attention un des deux fichier a été détecter ! Il seront remis a 0 si vous les creers\nChoix (C|R):" );
 | 
			
		||||
    clean_keyboard();scanf("%c", &c);
 | 
			
		||||
    if((c|0b00100000) == 'c')
 | 
			
		||||
    {
 | 
			
		||||
      clientDatF = fopen(repTmp[__TAB_CLIENTDAT_FILE__], "wb");
 | 
			
		||||
      clientTXTF = fopen(repTmp[__TAB_CLIENTTXT_FILE__], "w");
 | 
			
		||||
      fclose(clientDatF);
 | 
			
		||||
      fclose(clientTXTF);
 | 
			
		||||
      fclose(*clientDatF);
 | 
			
		||||
      fclose(*clientTXTF);
 | 
			
		||||
      *clientDatF = fopen(repTmp[__TAB_CLIENTDAT_FILE__], "wb");
 | 
			
		||||
      *clientTXTF = fopen(repTmp[__TAB_CLIENTTXT_FILE__], "w");
 | 
			
		||||
      fwrite(&nbClients, sizeof(nbClients), 1, *clientDatF);
 | 
			
		||||
      fwrite(&tri, sizeof(tri), 1, *clientDatF);
 | 
			
		||||
      fclose(*clientDatF);
 | 
			
		||||
      fclose(*clientTXTF);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
       localiserFichiersClients(fichierClientDat, clientDatF, clientTXTF);
 | 
			
		||||
      localiserFichiersClients(fichierClientDat, clientDatF, clientTXTF);
 | 
			
		||||
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    fclose(clientDatF);
 | 
			
		||||
    fclose(clientTXTF);
 | 
			
		||||
    fclose(*clientDatF);
 | 
			
		||||
    fclose(*clientTXTF);
 | 
			
		||||
  }
 | 
			
		||||
  clientDatF = fopen(repTmp[__TAB_CLIENTDAT_FILE__], "r+b");
 | 
			
		||||
  clientTXTF = fopen(repTmp[__TAB_CLIENTTXT_FILE__], "r+");
 | 
			
		||||
  if(clientDatF == NULL || clientTXTF == NULL)
 | 
			
		||||
  clearerr(*clientDatF);clearerr(*clientTXTF);
 | 
			
		||||
  *clientDatF = fopen(repTmp[__TAB_CLIENTDAT_FILE__], "r+b");
 | 
			
		||||
  *clientTXTF = fopen(repTmp[__TAB_CLIENTTXT_FILE__], "r+");
 | 
			
		||||
  strcpy(fichierClientDat, repTmp[__TAB_CLIENTDAT_FILE__]);
 | 
			
		||||
  if(*clientDatF == NULL || *clientTXTF == NULL)
 | 
			
		||||
  {
 | 
			
		||||
    printf("\nErreur ouverture fichier");
 | 
			
		||||
     localiserFichiersClients(fichierClientDat, clientDatF, clientTXTF);
 | 
			
		||||
    localiserFichiersClients(fichierClientDat, clientDatF,  clientTXTF);
 | 
			
		||||
  }
 | 
			
		||||
  strcpy(fichierClientDat, repTmp[__TAB_CLIENTDAT_FILE__]);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int sauvegarderClientFile(FILE * clientTXTF, FILE * clientDatF, Client * client)
 | 
			
		||||
@@ -703,7 +723,7 @@ int sauvegarderClientFile(FILE * clientTXTF, FILE * clientDatF, Client * client)
 | 
			
		||||
    fflush(clientTXTF);
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
    fseek(clientDatF, client->ofsetFichierDat, SEEK_SET);
 | 
			
		||||
  fseek(clientDatF, client->ofsetFichierDat, SEEK_SET);
 | 
			
		||||
  fwrite(client, sizeof(Client), 1, clientDatF);
 | 
			
		||||
  fflush(clientDatF);
 | 
			
		||||
  return client->ofsetFichierDat;
 | 
			
		||||
@@ -715,7 +735,7 @@ int compNP(char *nom1, char *prenom1,char *nom2, char *prenom2)
 | 
			
		||||
  char * tmp;
 | 
			
		||||
  for(strLen1 = 0, tmp = nom1;*tmp++;strLen1++);
 | 
			
		||||
  for(tmp = prenom1;*tmp++;strLen1++);
 | 
			
		||||
  for(strLen1 = 0, tmp = nom2;*tmp++;strLen2++);
 | 
			
		||||
  for(strLen2 = 0, tmp = nom2;*tmp++;strLen2++);
 | 
			
		||||
  for(tmp = prenom2;*tmp++;strLen2++);
 | 
			
		||||
  char * np1 = malloc(strLen1+1);
 | 
			
		||||
  char * np2 = malloc(strLen2+1);
 | 
			
		||||
@@ -724,13 +744,14 @@ int compNP(char *nom1, char *prenom1,char *nom2, char *prenom2)
 | 
			
		||||
  sprintf(np2,"%s%s", nom2, prenom2);
 | 
			
		||||
  renvois = strcmp(np1,np2);
 | 
			
		||||
  if(renvois>0)
 | 
			
		||||
    renvois = 1;
 | 
			
		||||
  renvois = 1;
 | 
			
		||||
  else if(renvois<0)
 | 
			
		||||
    renvois = -1;
 | 
			
		||||
  renvois = -1;
 | 
			
		||||
  return renvois;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void clientBinToTXT(FILE * bin, FILE* txt) //======================================================================
 | 
			
		||||
void clientBinToTXT(FILE * bin, FILE* txt)/*Si je veux sup des client, il fau que j'aie le nom du fichier
 | 
			
		||||
le standard c n'autorise que l'ajout et la modif */
 | 
			
		||||
{
 | 
			
		||||
  Client client;
 | 
			
		||||
  fseek(bin, 0, SEEK_SET);fseek(txt, 0, SEEK_SET);
 | 
			
		||||
@@ -743,7 +764,7 @@ void clientBinToTXT(FILE * bin, FILE* txt) //===================================
 | 
			
		||||
    sauvegarderClientTXT(&client, txt, 0);
 | 
			
		||||
    fprintf(txt, "========================================================================");
 | 
			
		||||
  }
 | 
			
		||||
//  fread()
 | 
			
		||||
  //  fread()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void modificationClient(Client * client, FILE * clientDatF, FILE * clientTXTF)
 | 
			
		||||
@@ -755,7 +776,7 @@ void modificationClient(Client * client, FILE * clientDatF, FILE * clientTXTF)
 | 
			
		||||
  {
 | 
			
		||||
    system("cls");
 | 
			
		||||
    if(choix)
 | 
			
		||||
      printf("Erreur choix errone !\n");
 | 
			
		||||
    printf("Erreur choix errone !\n");
 | 
			
		||||
    printf("MODIFICATION CLIENT %s %s \n", client->nom, client->prenom);
 | 
			
		||||
    printf("1. Adresse\n2. Telephne\n3. E-mail\n");
 | 
			
		||||
    printf("Votre choix :");clean_keyboard();scanf("%d", &choix);
 | 
			
		||||
@@ -764,11 +785,11 @@ void modificationClient(Client * client, FILE * clientDatF, FILE * clientTXTF)
 | 
			
		||||
  if(choix == 1)
 | 
			
		||||
  {
 | 
			
		||||
    if(!(printf("Entrez la rue :") && clean_keyboard() && fgets(client->adresse.rue,__STRLEN__,stdin) != NULL && \
 | 
			
		||||
      printf("\nEntrez le numero :" ) && clean_keyboard() && fgets(client->adresse.numero,__STRLEN__,stdin) != NULL && \
 | 
			
		||||
      printf("\nEntrez la localité :") && clean_keyboard() && fgets(client->adresse.localite,__STRLEN__,stdin) != NULL && \
 | 
			
		||||
      printf("\nEntrez le code postal :") && clean_keyboard() && scanf("%d", &(client->adresse.codePostal)) && \
 | 
			
		||||
      printf("\nNom client :") && clean_keyboard() && fgets(client->nom,__STRLEN__,stdin) != NULL &&\
 | 
			
		||||
      printf("\nPrenom client :") && clean_keyboard() && fgets(client->prenom,__STRLEN__,stdin) != NULL))
 | 
			
		||||
    printf("\nEntrez le numero :" ) && clean_keyboard() && fgets(client->adresse.numero,__STRLEN__,stdin) != NULL && \
 | 
			
		||||
    printf("\nEntrez la localité :") && clean_keyboard() && fgets(client->adresse.localite,__STRLEN__,stdin) != NULL && \
 | 
			
		||||
    printf("\nEntrez le code postal :") && clean_keyboard() && scanf("%d", &(client->adresse.codePostal)) && \
 | 
			
		||||
    printf("\nNom client :") && clean_keyboard() && fgets(client->nom,__STRLEN__,stdin) != NULL &&\
 | 
			
		||||
    printf("\nPrenom client :") && clean_keyboard() && fgets(client->prenom,__STRLEN__,stdin) != NULL))
 | 
			
		||||
    {
 | 
			
		||||
      printf("\nErreur lors de l'encodage de l'adresse");
 | 
			
		||||
      exit(-1);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user