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