BUILD&TEST OK
This commit is contained in:
parent
eb51c467a5
commit
a5f3357e8a
116
VANDAMME28.c
116
VANDAMME28.c
|
@ -1,11 +1,11 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fichier client :
|
* Fichier client :
|
||||||
------------------------------------------------------------
|
*------------------------------------------------------------
|
||||||
|UINTL NBClients|Bool Tri| Client 0 | Client 1 | .......ETc|
|
*|UINTL NBClients|Bool Tri| Client 0 | Client 1 | .......ETc|
|
||||||
------------------------------------------------------------
|
*------------------------------------------------------------
|
||||||
|
*
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -100,6 +100,7 @@ int main()
|
||||||
FILE * clientTXTF = NULL;
|
FILE * clientTXTF = NULL;
|
||||||
Client * client;
|
Client * client;
|
||||||
long int ofsetFileCurClient = 0;
|
long int ofsetFileCurClient = 0;
|
||||||
|
if(ofsetFileCurClient);//Pour ne pas avoir de warn
|
||||||
char nomClient[__STRLEN__],prenomClient[__STRLEN__];
|
char nomClient[__STRLEN__],prenomClient[__STRLEN__];
|
||||||
char fichierClientDat[__STRLEN_FILE__];
|
char fichierClientDat[__STRLEN_FILE__];
|
||||||
int choixMenu;
|
int choixMenu;
|
||||||
|
@ -176,9 +177,9 @@ void encoderDate(Date * date, char *invite)
|
||||||
|
|
||||||
Bool dateValide(Date * date)
|
Bool dateValide(Date * date)
|
||||||
{
|
{
|
||||||
int j = date->jour;
|
int m = date->jour;
|
||||||
int m = date->moi;
|
int d = date->moi;
|
||||||
int a = date->annee;
|
int y = date->annee;
|
||||||
int daysinmonth[12]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
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
|
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';
|
fileName[0] = '\0';
|
||||||
char dir[__STRLEN__];
|
char dir[__STRLEN__];
|
||||||
int i;
|
int i;
|
||||||
char buf[5];
|
|
||||||
printf("Dossier d'enregistrement : ");
|
printf("Dossier d'enregistrement : ");
|
||||||
clean_keyboard();
|
clean_keyboard();
|
||||||
scanf("%s", dir);
|
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++)
|
for(i=1; i<= 99; i++)
|
||||||
{
|
{
|
||||||
|
@ -431,73 +422,6 @@ void cleanFgets(char * str)
|
||||||
exit(-1);
|
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()
|
Bool clean_keyboard()
|
||||||
{
|
{
|
||||||
|
@ -531,7 +455,6 @@ void gestionFacture(Client * client, Date * date)
|
||||||
{
|
{
|
||||||
FILE * file;
|
FILE * file;
|
||||||
|
|
||||||
|
|
||||||
printf("%d/%d/%d\n", date->jour, date->moi, date->annee );
|
printf("%d/%d/%d\n", date->jour, date->moi, date->annee );
|
||||||
file = creerFichier(date, client);
|
file = creerFichier(date, client);
|
||||||
|
|
||||||
|
@ -547,12 +470,12 @@ void gestionFacture(Client * client, Date * date)
|
||||||
encoderFacture(&client->panier);
|
encoderFacture(&client->panier);
|
||||||
afficherFacture(date, client);
|
afficherFacture(date, client);
|
||||||
sauvergarderFacture(file, date, client);
|
sauvergarderFacture(file, date, client);
|
||||||
// getch();
|
getch();
|
||||||
fclose(file);
|
fclose(file);
|
||||||
free(client->panier.article);
|
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;
|
long int ofsetFileCurClient;
|
||||||
fseek(clientDatF, sizeof(unsigned long int)+sizeof(Bool), SEEK_SET);
|
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);
|
gestionFacture(client, date);
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
|
sauvegarderClientFile(clientTXTF, clientDatF, client);
|
||||||
return 1;
|
return 1;
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
|
sauvegarderClientFile(clientTXTF, clientDatF, client);
|
||||||
return 0;
|
return 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -672,6 +597,7 @@ int sauvegarderClientFile(FILE * clientTXTF, FILE * clientDatF, Client * client)
|
||||||
fseek(clientDatF, 0, SEEK_END);
|
fseek(clientDatF, 0, SEEK_END);
|
||||||
fseek(clientTXTF, 0, SEEK_END);
|
fseek(clientTXTF, 0, SEEK_END);
|
||||||
client->ofsetFichierDat = ftell(clientDatF);
|
client->ofsetFichierDat = ftell(clientDatF);
|
||||||
|
client->ofsetFichierTXT = ftell(clientTXTF);
|
||||||
sauvegarderClientTXT(client, clientTXTF, 0);
|
sauvegarderClientTXT(client, clientTXTF, 0);
|
||||||
fflush(clientTXTF);
|
fflush(clientTXTF);
|
||||||
}
|
}
|
||||||
|
@ -700,11 +626,12 @@ int compNP(char *nom1, char *prenom1,char *nom2, char *prenom2)
|
||||||
renvois = 1;
|
renvois = 1;
|
||||||
else if(renvois<0)
|
else if(renvois<0)
|
||||||
renvois = -1;
|
renvois = -1;
|
||||||
|
free(np1);free(np2);
|
||||||
return renvois;
|
return renvois;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clientBinToTXT(FILE * bin, FILE* txt)/*Si je veux sup des client, il fau que j'aie le nom du fichier
|
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;
|
Client client;
|
||||||
fseek(bin, 0, SEEK_SET);fseek(txt, 0, SEEK_SET);
|
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;
|
char choix = 0;
|
||||||
void * aModifier[] = {(Adresse *)&client->adresse, (char *)&client->contact.telephone, (char *)&client->contact.email};
|
void * aModifier[] = {(Adresse *)&client->adresse, (char *)&client->contact.telephone, (char *)&client->contact.email};
|
||||||
char * aAfficher[] = {"Adresse", "Telephne", "E-mail"};
|
char * aAfficher[] = {"Adresse", "Telephne", "E-mail"};
|
||||||
char w;
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
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 && \
|
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("\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);
|
||||||
}
|
}
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("Modification de %s :", aAfficher[choix-1]);
|
|
||||||
clean_keyboard();
|
clean_keyboard();
|
||||||
scanf("%s", (char *)aModifier[choix-1]);
|
scanf("%s", (char *)aModifier[choix-1]);
|
||||||
}
|
}
|
||||||
printf("Y-a-til encore des Modification (y|n) ?");
|
printf("Y-a-til encore des Modification (y|n) ?");
|
||||||
clean_keyboard();scanf("%c", &choix);
|
clean_keyboard();scanf("%c", &choix);
|
||||||
}while((choix&0b00100000) == 'y');
|
}while((choix|0b00100000) == 'y');
|
||||||
sauvegarderClientFile(clientTXTF, clientDatF, client);
|
sauvegarderClientFile(clientTXTF, clientDatF, client);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue