This commit is contained in:
parent
5db75ac97e
commit
f45f74fab6
87
VANDAMME28.c
87
VANDAMME28.c
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fichier client :
|
* Fichier client :
|
||||||
------------------------------------------------------------
|
------------------------------------------------------------
|
||||||
|
@ -78,7 +79,7 @@ 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 *);
|
||||||
|
@ -94,7 +95,13 @@ 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 *));
|
||||||
|
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;
|
Date date;
|
||||||
char tmp;
|
char tmp;
|
||||||
Bool w;
|
Bool w;
|
||||||
|
@ -113,12 +120,6 @@ int main()
|
||||||
date.annee = locTime->tm_year;
|
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 );
|
||||||
}
|
}
|
||||||
|
|
||||||
Client * client;
|
|
||||||
long int ofsetFileCurClient = 0;
|
|
||||||
char nomClient[__STRLEN__],prenomClient[__STRLEN__];
|
|
||||||
char fichierClientDat[__STRLEN_FILE__];
|
|
||||||
int choixMenu;
|
|
||||||
localiserFichiersClients(fichierClientDat, clientDatF, clientTXTF);
|
localiserFichiersClients(fichierClientDat, clientDatF, clientTXTF);
|
||||||
while(w)
|
while(w)
|
||||||
{
|
{
|
||||||
|
@ -134,7 +135,9 @@ int main()
|
||||||
client->ofsetFichierDat = 0;
|
client->ofsetFichierDat = 0;
|
||||||
encoderClient(client);
|
encoderClient(client);
|
||||||
afficherClient(client, &date);
|
afficherClient(client, &date);
|
||||||
sauvegarderClientFile(clientDatF, clientTXTF, client);
|
fseek(*clientTXTF, 0, SEEK_END);
|
||||||
|
|
||||||
|
sauvegarderClientFile(*clientTXTF, *clientDatF, client);
|
||||||
w = gestionClient(client, &date);
|
w = gestionClient(client, &date);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
@ -142,7 +145,7 @@ int main()
|
||||||
clean_keyboard();scanf("%s", nomClient);
|
clean_keyboard();scanf("%s", nomClient);
|
||||||
printf("\npRENOM du client (sensible a la casse) : ");
|
printf("\npRENOM du client (sensible a la casse) : ");
|
||||||
clean_keyboard();scanf("%s", prenomClient);
|
clean_keyboard();scanf("%s", prenomClient);
|
||||||
ofsetFileCurClient = rechercheClient(nomClient,prenomClient, clientDatF, client, &date);
|
ofsetFileCurClient = rechercheClient(nomClient,prenomClient, *clientDatF, client, &date);
|
||||||
if(client != NULL)
|
if(client != NULL)
|
||||||
{
|
{
|
||||||
w = gestionClient(client, &date);
|
w = gestionClient(client, &date);
|
||||||
|
@ -156,7 +159,10 @@ int main()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(client);
|
free(client);
|
||||||
fclose(clientDatF);
|
fclose(*clientDatF);
|
||||||
|
fclose(*clientTXTF);
|
||||||
|
free(clientDatF);
|
||||||
|
free(clientTXTF);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
void encoderDate(Date * date, char *invite)
|
void encoderDate(Date * date, char *invite)
|
||||||
|
@ -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)
|
||||||
{
|
{
|
||||||
|
@ -596,6 +609,7 @@ 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;
|
||||||
|
@ -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");
|
||||||
|
@ -637,50 +651,56 @@ Bool gestionClient(Client * client, Date * date)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
@ -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);
|
||||||
|
@ -730,7 +750,8 @@ int compNP(char *nom1, char *prenom1,char *nom2, char *prenom2)
|
||||||
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);
|
||||||
|
|
Loading…
Reference in New Issue