BUILD&TEST OK
This commit is contained in:
parent
eb51c467a5
commit
a5f3357e8a
124
VANDAMME28.c
124
VANDAMME28.c
|
@ -1,12 +1,12 @@
|
|||
|
||||
/*
|
||||
* Fichier client :
|
||||
------------------------------------------------------------
|
||||
|UINTL NBClients|Bool Tri| Client 0 | Client 1 | .......ETc|
|
||||
------------------------------------------------------------
|
||||
|
||||
|
||||
*/
|
||||
* Fichier client :
|
||||
*------------------------------------------------------------
|
||||
*|UINTL NBClients|Bool Tri| Client 0 | Client 1 | .......ETc|
|
||||
*------------------------------------------------------------
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -100,6 +100,7 @@ int main()
|
|||
FILE * clientTXTF = NULL;
|
||||
Client * client;
|
||||
long int ofsetFileCurClient = 0;
|
||||
if(ofsetFileCurClient);//Pour ne pas avoir de warn
|
||||
char nomClient[__STRLEN__],prenomClient[__STRLEN__];
|
||||
char fichierClientDat[__STRLEN_FILE__];
|
||||
int choixMenu;
|
||||
|
@ -176,9 +177,9 @@ void encoderDate(Date * date, char *invite)
|
|||
|
||||
Bool dateValide(Date * date)
|
||||
{
|
||||
int j = date->jour;
|
||||
int m = date->moi;
|
||||
int a = date->annee;
|
||||
int m = date->jour;
|
||||
int d = date->moi;
|
||||
int y = date->annee;
|
||||
int daysinmonth[12]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||
|
||||
if(y % 400 == 0 || (y % 100 != 0 && y % 4 == 0))//Si bis février = 29
|
||||
|
@ -320,21 +321,11 @@ FILE * creerFichier(Date * date, Client * client)
|
|||
fileName[0] = '\0';
|
||||
char dir[__STRLEN__];
|
||||
int i;
|
||||
char buf[5];
|
||||
printf("Dossier d'enregistrement : ");
|
||||
clean_keyboard();
|
||||
scanf("%s", dir);
|
||||
//Toute cette partie aurais pus être remplacé par un sprintf
|
||||
sprintf(fileName, "%s%d%d%d%d_", client->nom, date->anne, date->moi, date->jour);
|
||||
strcat(fileName,client->nom);
|
||||
itoaY(date->annee, buf);
|
||||
strcat(fileName,buf);
|
||||
itoaDM(date->moi, buf);
|
||||
strcat(fileName, buf);
|
||||
itoaDM(date->jour, buf);
|
||||
strcat(fileName, buf);
|
||||
strcat(fileName,"_");
|
||||
|
||||
sprintf(fileName, "%s%d%d%d_", client->nom, date->annee, date->moi, date->jour);
|
||||
|
||||
for(i=1; i<= 99; i++)
|
||||
{
|
||||
|
@ -431,73 +422,6 @@ void cleanFgets(char * str)
|
|||
exit(-1);
|
||||
}
|
||||
}
|
||||
int itoaY(int i, char * buf)
|
||||
{
|
||||
buf [0] = '0';
|
||||
buf [1] = '0';
|
||||
buf [2] = '0';
|
||||
buf [3] = '0';
|
||||
buf [4] = '\0';
|
||||
int j;
|
||||
if(!i)
|
||||
return 1;
|
||||
buf [3] = '1';
|
||||
for(j=1; j<=i && j<=9999 ; j++)
|
||||
{
|
||||
if(!(j%1000))
|
||||
{
|
||||
buf[0]++;
|
||||
buf[1]='0';
|
||||
buf[2]='0';
|
||||
buf[3]='0';
|
||||
}
|
||||
else if(!(j%100))
|
||||
{
|
||||
buf[1]++;
|
||||
buf[2]='0';
|
||||
buf[3]='0';
|
||||
}
|
||||
else if(!(j%10))
|
||||
{
|
||||
buf[2]++;
|
||||
buf[3]='0';
|
||||
}
|
||||
else
|
||||
{
|
||||
buf[3]++;
|
||||
}
|
||||
}
|
||||
if(j>9999)
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
int itoaDM(int i, char * buf)
|
||||
{
|
||||
buf[0] = '0';
|
||||
buf[1] = '0';
|
||||
buf[2] = '\0';
|
||||
int j;
|
||||
if(!i)
|
||||
return 1;
|
||||
buf[1]++;
|
||||
for(j=1; j<=i && j<=99 ; j++)
|
||||
{
|
||||
if(!(j%10))
|
||||
{
|
||||
(buf[0])++;
|
||||
(buf[1])='0';
|
||||
}
|
||||
else
|
||||
{
|
||||
(buf[1])++;
|
||||
}
|
||||
}
|
||||
if(j>99)
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
Bool clean_keyboard()
|
||||
{
|
||||
|
@ -518,7 +442,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)
|
||||
|
@ -531,7 +455,6 @@ void gestionFacture(Client * client, Date * date)
|
|||
{
|
||||
FILE * file;
|
||||
|
||||
|
||||
printf("%d/%d/%d\n", date->jour, date->moi, date->annee );
|
||||
file = creerFichier(date, client);
|
||||
|
||||
|
@ -547,12 +470,12 @@ void gestionFacture(Client * client, Date * date)
|
|||
encoderFacture(&client->panier);
|
||||
afficherFacture(date, client);
|
||||
sauvergarderFacture(file, date, client);
|
||||
// getch();
|
||||
getch();
|
||||
fclose(file);
|
||||
free(client->panier.article);
|
||||
}
|
||||
|
||||
long int rechercheClient(char nom[__STRLEN__], char prenom[__STRLEN__], FILE * clientDatF, Client * client, Date * date)
|
||||
long int rechercheClient(char *nom, char *prenom, FILE * clientDatF, Client * client, Date * date)
|
||||
{
|
||||
long int ofsetFileCurClient;
|
||||
fseek(clientDatF, sizeof(unsigned long int)+sizeof(Bool), SEEK_SET);
|
||||
|
@ -595,9 +518,11 @@ Bool gestionClient(Client * client, Date * date, FILE * clientDatF, FILE * clien
|
|||
gestionFacture(client, date);
|
||||
break;
|
||||
case 'd':
|
||||
sauvegarderClientFile(clientTXTF, clientDatF, client);
|
||||
return 1;
|
||||
break;
|
||||
case 'e':
|
||||
sauvegarderClientFile(clientTXTF, clientDatF, client);
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
|
@ -672,11 +597,12 @@ int sauvegarderClientFile(FILE * clientTXTF, FILE * clientDatF, Client * client)
|
|||
fseek(clientDatF, 0, SEEK_END);
|
||||
fseek(clientTXTF, 0, SEEK_END);
|
||||
client->ofsetFichierDat = ftell(clientDatF);
|
||||
client->ofsetFichierTXT = ftell(clientTXTF);
|
||||
sauvegarderClientTXT(client, clientTXTF, 0);
|
||||
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;
|
||||
|
@ -700,11 +626,12 @@ int compNP(char *nom1, char *prenom1,char *nom2, char *prenom2)
|
|||
renvois = 1;
|
||||
else if(renvois<0)
|
||||
renvois = -1;
|
||||
free(np1);free(np2);
|
||||
return renvois;
|
||||
}
|
||||
|
||||
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 */
|
||||
le standard c n'autorise que l'ajout et la modif EN COURS*/
|
||||
{
|
||||
Client client;
|
||||
fseek(bin, 0, SEEK_SET);fseek(txt, 0, SEEK_SET);
|
||||
|
@ -725,7 +652,6 @@ void modificationClient(Client * client, FILE * clientDatF, FILE * clientTXTF)
|
|||
char choix = 0;
|
||||
void * aModifier[] = {(Adresse *)&client->adresse, (char *)&client->contact.telephone, (char *)&client->contact.email};
|
||||
char * aAfficher[] = {"Adresse", "Telephne", "E-mail"};
|
||||
char w;
|
||||
do
|
||||
{
|
||||
do
|
||||
|
@ -743,24 +669,20 @@ void modificationClient(Client * client, FILE * clientDatF, FILE * clientTXTF)
|
|||
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 code postal :") && clean_keyboard() && scanf("%d", &(client->adresse.codePostal))))
|
||||
{
|
||||
printf("\nErreur lors de l'encodage de l'adresse");
|
||||
exit(-1);
|
||||
}
|
||||
cleanFgets(client->adresse.rue);cleanFgets(client->adresse.numero);cleanFgets(client->adresse.localite);
|
||||
cleanFgets(client->nom);cleanFgets(client->prenom);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Modification de %s :", aAfficher[choix-1]);
|
||||
clean_keyboard();
|
||||
scanf("%s", (char *)aModifier[choix-1]);
|
||||
}
|
||||
printf("Y-a-til encore des Modification (y|n) ?");
|
||||
clean_keyboard();scanf("%c", &choix);
|
||||
}while((choix&0b00100000) == 'y');
|
||||
}while((choix|0b00100000) == 'y');
|
||||
sauvegarderClientFile(clientTXTF, clientDatF, client);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue