labo 24 fin
This commit is contained in:
parent
afae5d9ad2
commit
af258367ba
215
VANDAMME24.c
215
VANDAMME24.c
|
@ -1,10 +1,10 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#define __TVA__ 1.21
|
||||
#define __REDUC__ 0.9
|
||||
#define __MAXNBRART__ 3
|
||||
|
@ -42,16 +42,17 @@ typedef struct{
|
|||
|
||||
|
||||
|
||||
void EncoderDate(Date *);
|
||||
int DateValide (Date *);
|
||||
void afficherArticle(Article * article, unsigned int nbrArt, FILE * file);
|
||||
void encoderArticle(Article * article);
|
||||
void encoderDate(Date *);
|
||||
Bool dateValide (Date *);
|
||||
void encoderArticle(Article *);
|
||||
void encoderClient(Client *);
|
||||
void sauvegarderClient(Client *, FILE *);
|
||||
void afficherClient(Client *);
|
||||
void encoderFacture(Panier *);
|
||||
FILE * creerFichier(Date *, Client *);
|
||||
Bool fichierExistant(char *);
|
||||
void genererFacture(FILE *, Date *, Client *);
|
||||
void sauvergarderFacture(FILE *, Date *, Client *);
|
||||
void afficherFacture(Date *, Client *);
|
||||
void cleanFgets(char*);
|
||||
int itoaY(int i, char*);
|
||||
int itoaDM(int i, char*);
|
||||
|
@ -59,56 +60,42 @@ int itoaDM(int i, char*);
|
|||
|
||||
int main()
|
||||
{
|
||||
char buf[5];
|
||||
itoaY(1999,buf);
|
||||
printf("%s\n", buf);
|
||||
Date date;
|
||||
FILE * file;
|
||||
Client client;
|
||||
do
|
||||
EncoderDate(&date);
|
||||
while(!DateValide(&date));
|
||||
encoderDate(&date);
|
||||
while(!dateValide(&date));
|
||||
|
||||
encoderClient(&client);
|
||||
afficherClient(&client);
|
||||
|
||||
file = creerFichier(&date, &client);
|
||||
if(file == NULL)
|
||||
{
|
||||
printf("Erreur lors de l'ouvertur !\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
client.panier.article = (Article *)malloc(sizeof(Article));
|
||||
client.panier.nbrArt = 1;
|
||||
if(client.panier.article == NULL)
|
||||
{
|
||||
printf("ERREUR ALLOCATION !");
|
||||
printf("ERREUR ALLOCATION ARTICLE!");
|
||||
free(client.panier.article);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//En t<>te de la facture
|
||||
printf("La Bulle Informatique\nRoute du Condroz 78, 4123 Neupre\n");
|
||||
printf("\nFacture a payer\n");
|
||||
printf("Date de facturation :");
|
||||
printf("%02d/%02d/%02d", date.jour, date.moi, date.annee);
|
||||
printf("%u\n", client.panier.nbrArt);
|
||||
afficherArticle(client.panier.article,client.panier.nbrArt, file);
|
||||
encoderFacture(&client.panier);
|
||||
afficherFacture(&date, &client);
|
||||
sauvergarderFacture(file, &date, &client);
|
||||
getch();
|
||||
fclose(file);
|
||||
free(client.panier.article);
|
||||
return 0;
|
||||
}
|
||||
void EncoderDate(Date * date)
|
||||
void encoderDate(Date * date)
|
||||
{
|
||||
printf("Entrez la date sous cette forme : jj/mm/aaaa\n");
|
||||
fflush(stdin); scanf("%d/%d/%d",&(date->jour),&(date->moi),&(date->annee));
|
||||
}
|
||||
|
||||
int DateValide(Date * date)
|
||||
Bool dateValide(Date * date)
|
||||
{
|
||||
int j = date->jour;
|
||||
int m = date->moi;
|
||||
|
@ -120,82 +107,55 @@ int DateValide(Date * date)
|
|||
{
|
||||
if(m %2 == 0)
|
||||
{
|
||||
if(j >= 1 && j <= 30) return 1;
|
||||
else return 0;
|
||||
if(j >= 1 && j <= 30) return TRUE;
|
||||
else return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(j >= 1 && j <= 31) return 1;
|
||||
else return 0;
|
||||
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 1;
|
||||
else return 0;
|
||||
if(j >= 1 && j <= 31) return TRUE;
|
||||
else return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(j >= 1 && j <= 30) return 1;
|
||||
else return 0;
|
||||
if(j >= 1 && j <= 30) return TRUE;
|
||||
else return FALSE;
|
||||
}
|
||||
}
|
||||
else return 0;
|
||||
else return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(a %100 == 0)
|
||||
{
|
||||
if(a %400 == 0) bis = 1;
|
||||
else bis = 0;
|
||||
else bis = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(a %4 == 0)bis = 1;
|
||||
else bis = 0;
|
||||
else bis = FALSE;
|
||||
}
|
||||
if(bis == 1)
|
||||
{
|
||||
if(j >= 1 && j <= 29) return 1;
|
||||
else return 0;
|
||||
if(j >= 1 && j <= 29) return TRUE;
|
||||
else return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(j >= 1 && j <= 28) return 1;
|
||||
else return 0;
|
||||
if(j >= 1 && j <= 28) return TRUE;
|
||||
else return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void afficherArticle(Article * article, unsigned int nbrArt,FILE * file)
|
||||
{
|
||||
unsigned int i;
|
||||
float prixTot=0;
|
||||
fprintf(file,"\n|---------------------------------------------------------------------------------------------|\
|
||||
\n| Designation | prixHTVA | Quantite | 10%% | prixTVAC |");
|
||||
printf("\n|---------------------------------------------------------------------------------------------|\
|
||||
\n| Designation | prixHTVA | Quantite | 10%% | prixTVAC |");
|
||||
for(i=0;i<nbrArt;i++)
|
||||
{
|
||||
printf("\n|%34s|%12.2f Eur |%14d| %c |%12.2f |",\
|
||||
article[i].deisgnation,article[i].prixHTVA,article[i].quant\
|
||||
,(article[i].quant>=20)?'x':' ',\
|
||||
(article[i].quant>=20)?article[i].prixHTVA*__TVA__*__REDUC__*article[i].quant:article[i].prixHTVA*__TVA__*article[i].quant);
|
||||
fprintf(file,"\n|%34s|%12.2f Eur |%14d| %c |%12.2f |",\
|
||||
article[i].deisgnation,article[i].prixHTVA,article[i].quant\
|
||||
,(article[i].quant>=20)?'x':' ',\
|
||||
(article[i].quant>=20)?article[i].prixHTVA*__TVA__*__REDUC__*article[i].quant:article[i].prixHTVA*__TVA__*article[i].quant);
|
||||
|
||||
prixTot += (article[i].quant>=20)?article[i].prixHTVA*__TVA__*__REDUC__*article[i].quant:article[i].prixHTVA*__TVA__*article[i].quant;
|
||||
}
|
||||
printf("\n|---------------------------------------------------------------------------------------------|");
|
||||
printf("\nPrix totale :%f", prixTot);
|
||||
|
||||
fprintf(file,"\n|---------------------------------------------------------------------------------------------|");
|
||||
fprintf(file,"\nPrix totale :%f", prixTot);
|
||||
}
|
||||
void encoderArticle(Article * article)
|
||||
{
|
||||
printf("\nVeuillez entrer le nom : ");
|
||||
|
@ -207,9 +167,6 @@ void encoderArticle(Article * article)
|
|||
scanf("%d", &article->quant);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void encoderClient(Client * client)
|
||||
{
|
||||
printf("Encoage Client\n");
|
||||
|
@ -234,8 +191,8 @@ void encoderClient(Client * client)
|
|||
cleanFgets(client->contact.telephone);cleanFgets(client->contact.email);
|
||||
printf("\n Anniversaire client :");
|
||||
do
|
||||
EncoderDate(&(client->anniversaire));
|
||||
while(!DateValide(&(client->anniversaire)));
|
||||
encoderDate(&(client->anniversaire));
|
||||
while(!dateValide(&(client->anniversaire)));
|
||||
}
|
||||
void afficherClient(Client *client)
|
||||
{
|
||||
|
@ -246,7 +203,16 @@ void afficherClient(Client *client)
|
|||
printf("code postal : %d",client->adresse.codePostal);
|
||||
printf("numéro de tél. : %s",client->contact.telephone);
|
||||
printf("adresse email : %s",client->contact.email);
|
||||
|
||||
}
|
||||
void sauvegarderClient(Client *client, FILE * file)
|
||||
{
|
||||
fprintf(file, "Client : %s\n", client->nom);
|
||||
fprintf(file, "rue : %s",client->adresse.rue);
|
||||
fprintf(file, "numero : %s",client->adresse.numero);
|
||||
fprintf(file, "localité : %s",client->adresse.localite);
|
||||
fprintf(file, "code postal : %d",client->adresse.codePostal);
|
||||
fprintf(file, "numéro de tél. : %s",client->contact.telephone);
|
||||
fprintf(file, "adresse email : %s",client->contact.email);
|
||||
}
|
||||
void encoderFacture(Panier * panier)
|
||||
{
|
||||
|
@ -258,7 +224,7 @@ void encoderFacture(Panier * panier)
|
|||
printf("Y-a-t-il encore un article ?(Y|n)");
|
||||
fflush(stdin);
|
||||
scanf("%c", &continuer);
|
||||
if(panier->nbrArt < 3 && (continuer|0b00100000) == 'y')
|
||||
if(panier->nbrArt < __MAXNBRART__ && (continuer|0b00100000) == 'y')
|
||||
{
|
||||
panier->nbrArt++;
|
||||
Article * tempArticle;
|
||||
|
@ -275,57 +241,48 @@ void encoderFacture(Panier * panier)
|
|||
panier->article = tempArticle;
|
||||
}
|
||||
}
|
||||
else
|
||||
else if((continuer|0b00100000) == 'y')
|
||||
{
|
||||
system("cls");
|
||||
printf("Vous avez ateint le nombre d'article maximum !\n\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}while((continuer|0b00100000) == 'y');
|
||||
}while((continuer|0b00100000) == 'y' && panier->nbrArt <= __MAXNBRART__);
|
||||
}
|
||||
FILE * creerFichier(Date * date, Client * client)
|
||||
{
|
||||
char cat[__STRLEN__*+15]; //Dans l'ideal malloc pour un nombre de fichier illimiter mais flem ...
|
||||
cat[0] = '\0';
|
||||
char i;
|
||||
char fileName[__STRLEN__*+16];
|
||||
fileName[0] = '\0';
|
||||
int i;
|
||||
char buf[5];
|
||||
strcat(cat,client->nom);
|
||||
printf("%s\n", cat);
|
||||
|
||||
//Toute cette partie aurais pus être remplacé par un sprintf
|
||||
strcat(fileName,client->nom);
|
||||
itoaY(date->annee, buf);
|
||||
printf("%s %s\n", cat, buf);
|
||||
strcat(cat,buf);
|
||||
printf("%s\n", cat);
|
||||
strcat(fileName,buf);
|
||||
itoaDM(date->moi, buf);
|
||||
strcat(cat, buf);
|
||||
printf("%s\n", cat);
|
||||
strcat(fileName, buf);
|
||||
itoaDM(date->jour, buf);
|
||||
strcat(cat, buf);
|
||||
printf("%s\n", cat);
|
||||
strcat(cat,"_");
|
||||
for(i='1'; i<= '9'; i++)//Le caractère 10 n'existe pas, flem de coder pour avoir plus que 9 et aloc dynamique nécessaire
|
||||
strcat(fileName, buf);
|
||||
strcat(fileName,"_");
|
||||
|
||||
|
||||
for(i=1; i<= 99; i++)//Le caractère 10 n'existe pas, flem de coder pour avoir plus que 9 et aloc dynamique nécessaire
|
||||
{
|
||||
char itmp[2] = {i,'\0'};
|
||||
strcat(cat,itmp);
|
||||
if(fichierExistant(cat))
|
||||
char fileNameTmp[__STRLEN__*+16];
|
||||
sprintf(fileNameTmp,"%s%d",fileName,i);
|
||||
if(!fichierExistant(fileNameTmp))
|
||||
{
|
||||
char * p = strchr(cat, i); //Renvois l'adresse de i\0
|
||||
//cat contient actuellement nom+date+_i\0
|
||||
*p = '\0';
|
||||
//Maintenant cat contient actuellement nom+date+_\0\0
|
||||
//Si on remplace par '' strcat va ajouter au \0 donc on aura nom+date+_+''+QQChose\0
|
||||
//On aura donc un caractère en plus a chaque tour de boucle ...
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s\n", cat);
|
||||
FILE * f = fopen(cat,"w");
|
||||
printf("%s\n", fileNameTmp);
|
||||
FILE * f = fopen(fileNameTmp,"w");
|
||||
if(f==NULL)
|
||||
{
|
||||
printf("Erreur lors de l'ouverture du fichier");
|
||||
exit(-1);
|
||||
return f;
|
||||
}
|
||||
else
|
||||
return f;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
@ -334,11 +291,11 @@ Bool fichierExistant(char * filename)
|
|||
{
|
||||
FILE * f = fopen(filename, "r");
|
||||
if(f==NULL)
|
||||
return 0;
|
||||
return FALSE;
|
||||
else
|
||||
return 1;
|
||||
return TRUE;
|
||||
}
|
||||
void genererFacture(FILE * file, Date * date, Client * client)
|
||||
void sauvergarderFacture(FILE * file, Date * date, Client * client)
|
||||
{
|
||||
int i;
|
||||
float prixTot = 0;
|
||||
|
@ -346,8 +303,11 @@ void genererFacture(FILE * file, Date * date, Client * client)
|
|||
fprintf(file,"\nFacture a payer\n");
|
||||
fprintf(file,"Date de facturation :");
|
||||
fprintf(file,"%02d/%02d/%02d", date->jour, date->moi, date->annee);
|
||||
fprintf(file, "\n Info client :");
|
||||
sauvegarderClient(&client, file)
|
||||
fprintf(file,"\n|---------------------------------------------------------------------------------------------|\
|
||||
\n| Designation | prixHTVA | Quantite | 10%% | prixTVAC |");
|
||||
\n| Designation | prixHTVA | Quantite | 10%% | prixTVAC |\
|
||||
\n|---------------------------------------------------------------------------------------------|");
|
||||
|
||||
for(i=0;client->panier.nbrArt>i;i++)
|
||||
{
|
||||
|
@ -361,6 +321,32 @@ void genererFacture(FILE * file, Date * date, Client * client)
|
|||
fprintf(file,"\nPrix totale :%f", prixTot);
|
||||
}
|
||||
|
||||
void afficherFacture(Date * date, Client * client)
|
||||
{
|
||||
int i;
|
||||
float prixTot = 0;
|
||||
printf("La Bulle Informatique\nRoute du Condroz 78, 4123 Neupre\n");
|
||||
printf("\nFacture a payer\n");
|
||||
printf("Date de facturation :");
|
||||
printf("%02d/%02d/%02d", date->jour, date->moi, date->annee);
|
||||
printf("\n Info client :");
|
||||
afficherClient(client);
|
||||
printf("\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);
|
||||
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("\nPrix totale :%f", prixTot);
|
||||
}
|
||||
|
||||
|
||||
void cleanFgets(char * str)
|
||||
{
|
||||
|
@ -408,7 +394,6 @@ int itoaY(int i, char * buf)
|
|||
{
|
||||
buf[3]++;
|
||||
}
|
||||
//printf("%s, %d, %d, %d, %d, j%d\n",buf,buf[3],buf[2],buf[1],buf[0],j );
|
||||
}
|
||||
if(j>9999)
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue