This commit is contained in:
parent
5db75ac97e
commit
f45f74fab6
107
VANDAMME28.c
107
VANDAMME28.c
|
@ -1,8 +1,9 @@
|
|||
|
||||
/*
|
||||
* Fichier client :
|
||||
------------------------------------------------------------
|
||||
|UINTL NBClients|Bool Tri| Client 0 | Client 1 | .......ETc|
|
||||
------------------------------------------------------------
|
||||
* Fichier client :
|
||||
------------------------------------------------------------
|
||||
|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 *);
|
||||
Bool gestionClient(Client *, Date *);
|
||||
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
|
||||
FILE * creerFichier(Date *, Client *);
|
||||
Bool fichierExistant(char *);
|
||||
void sauvergarderFacture(FILE *, Date *, Client *);
|
||||
void sauvegarderClientTXT(Client *, FILE *, long,...); /*EcrireDonneesClient
|
||||
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, ecris sans l'age mais a la position demandé (3e arg)
|
||||
= 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)
|
||||
*/
|
||||
void clientBinToTXT(FILE *, FILE*);
|
||||
void modificationClient(Client *, FILE *, FILE *);
|
||||
|
@ -94,7 +95,13 @@ void modificationClient(Client *, FILE *, FILE *);
|
|||
int main()
|
||||
{
|
||||
//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;
|
||||
char tmp;
|
||||
Bool w;
|
||||
|
@ -113,12 +120,6 @@ int main()
|
|||
date.annee = locTime->tm_year;
|
||||
// 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);
|
||||
while(w)
|
||||
{
|
||||
|
@ -134,7 +135,9 @@ int main()
|
|||
client->ofsetFichierDat = 0;
|
||||
encoderClient(client);
|
||||
afficherClient(client, &date);
|
||||
sauvegarderClientFile(clientDatF, clientTXTF, client);
|
||||
fseek(*clientTXTF, 0, SEEK_END);
|
||||
|
||||
sauvegarderClientFile(*clientTXTF, *clientDatF, client);
|
||||
w = gestionClient(client, &date);
|
||||
break;
|
||||
case 2:
|
||||
|
@ -142,7 +145,7 @@ int main()
|
|||
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);
|
||||
ofsetFileCurClient = rechercheClient(nomClient,prenomClient, *clientDatF, client, &date);
|
||||
if(client != NULL)
|
||||
{
|
||||
w = gestionClient(client, &date);
|
||||
|
@ -156,7 +159,10 @@ int main()
|
|||
}
|
||||
}
|
||||
free(client);
|
||||
fclose(clientDatF);
|
||||
fclose(*clientDatF);
|
||||
fclose(*clientTXTF);
|
||||
free(clientDatF);
|
||||
free(clientTXTF);
|
||||
return 0;
|
||||
}
|
||||
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
|
||||
{
|
||||
fprintf(file, "DEBUG2\n");
|
||||
fflush(file);
|
||||
va_list ap;
|
||||
int age = 0;
|
||||
va_start(ap, arg);
|
||||
|
@ -294,8 +302,9 @@ void sauvegarderClientTXT(Client *client, FILE * file, long arg, ...) //EcrireDo
|
|||
age = va_arg(ap,int);
|
||||
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, "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, "numéro de tél. : %s\n",client->contact.telephone);
|
||||
fprintf(file, "adresse email : %s\n",client->contact.email);
|
||||
if(arg)
|
||||
if(arg == 1)
|
||||
{
|
||||
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");
|
||||
}
|
||||
printf("YYYYYOOOOOLLLLLOOOOO\n");
|
||||
fflush(file);
|
||||
system("pause");
|
||||
va_end(ap);
|
||||
}
|
||||
void encoderFacture(Panier * panier)
|
||||
{
|
||||
|
@ -537,12 +550,12 @@ Bool clean_keyboard()
|
|||
{
|
||||
fflush(stdin);
|
||||
// char c;
|
||||
//while ((c = getchar()) != '\n' && c != EOF) { }
|
||||
//while ((c = getchar()) != '\n' && c != EOF) { }
|
||||
/* do {
|
||||
c = getc(stdin);
|
||||
printf("%c\n", c);
|
||||
} while (c != '\n' && c != EOF);*/
|
||||
return 1;
|
||||
} while (c != '\n' && c != EOF);*/
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ageClient(Client * client, Date * date)
|
||||
|
@ -596,6 +609,7 @@ long int rechercheClient(char nom[__STRLEN__], char prenom[__STRLEN__], FILE * c
|
|||
{
|
||||
ofsetFileCurClient = ftell(clientDatF);
|
||||
fread(client, sizeof(Client), 1, clientDatF);
|
||||
afficherClient(client, date);
|
||||
}while(!feof(clientDatF) && compNP(client->nom, client->prenom, nom, prenom));
|
||||
if(feof(clientDatF))
|
||||
return 0;
|
||||
|
@ -611,7 +625,7 @@ Bool gestionClient(Client * client, Date * date)
|
|||
do
|
||||
{
|
||||
printf("A. Donnees client\n");
|
||||
printf("B. Modification client\n");
|
||||
printf("B. Modification client\n");//acce au file *
|
||||
printf("C. Facture\n");
|
||||
printf("D. Retour\n");
|
||||
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 repTmp[2][__STRLEN_FILE__];
|
||||
unsigned long int nbClients = 0;
|
||||
Bool tri = 0;
|
||||
printf("Repertoir ou se trouve le fichier client.dat et client.txt");
|
||||
clean_keyboard();
|
||||
scanf("%s", rep);
|
||||
sprintf(repTmp[__TAB_CLIENTDAT_FILE__],"%sclients.dat", rep);
|
||||
sprintf(repTmp[__TAB_CLIENTTXT_FILE__],"%sclients.txt", rep);
|
||||
clientDatF = fopen(repTmp[__TAB_CLIENTDAT_FILE__], "r");
|
||||
clientTXTF = fopen(repTmp[__TAB_CLIENTTXT_FILE__], "r");
|
||||
if(clientDatF == NULL || clientTXTF == NULL)
|
||||
*clientTXTF = fopen(repTmp[__TAB_CLIENTTXT_FILE__], "r"); //A faire Une verification correcte se ferait avec access (voir GNU libc P418)
|
||||
*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) //Si un des fichier n'existe pas
|
||||
{
|
||||
char c;
|
||||
fclose(clientDatF);
|
||||
fclose(clientTXTF);
|
||||
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):" );
|
||||
clean_keyboard();scanf("%c", &c);
|
||||
if((c|0b00100000) == 'c')
|
||||
{
|
||||
clientDatF = fopen(repTmp[__TAB_CLIENTDAT_FILE__], "wb");
|
||||
clientTXTF = fopen(repTmp[__TAB_CLIENTTXT_FILE__], "w");
|
||||
fclose(clientDatF);
|
||||
fclose(clientTXTF);
|
||||
fclose(*clientDatF);
|
||||
fclose(*clientTXTF);
|
||||
*clientDatF = fopen(repTmp[__TAB_CLIENTDAT_FILE__], "wb");
|
||||
*clientTXTF = fopen(repTmp[__TAB_CLIENTTXT_FILE__], "w");
|
||||
fwrite(&nbClients, sizeof(nbClients), 1, *clientDatF);
|
||||
fwrite(&tri, sizeof(tri), 1, *clientDatF);
|
||||
fclose(*clientDatF);
|
||||
fclose(*clientTXTF);
|
||||
}
|
||||
else
|
||||
localiserFichiersClients(fichierClientDat, clientDatF, clientTXTF);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
fclose(clientDatF);
|
||||
fclose(clientTXTF);
|
||||
fclose(*clientDatF);
|
||||
fclose(*clientTXTF);
|
||||
}
|
||||
clientDatF = fopen(repTmp[__TAB_CLIENTDAT_FILE__], "r+b");
|
||||
clientTXTF = fopen(repTmp[__TAB_CLIENTTXT_FILE__], "r+");
|
||||
if(clientDatF == NULL || clientTXTF == NULL)
|
||||
clearerr(*clientDatF);clearerr(*clientTXTF);
|
||||
*clientDatF = fopen(repTmp[__TAB_CLIENTDAT_FILE__], "r+b");
|
||||
*clientTXTF = fopen(repTmp[__TAB_CLIENTTXT_FILE__], "r+");
|
||||
strcpy(fichierClientDat, repTmp[__TAB_CLIENTDAT_FILE__]);
|
||||
if(*clientDatF == NULL || *clientTXTF == NULL)
|
||||
{
|
||||
printf("\nErreur ouverture fichier");
|
||||
localiserFichiersClients(fichierClientDat, clientDatF, clientTXTF);
|
||||
}
|
||||
strcpy(fichierClientDat, repTmp[__TAB_CLIENTDAT_FILE__]);
|
||||
}
|
||||
|
||||
int sauvegarderClientFile(FILE * clientTXTF, FILE * clientDatF, Client * client)
|
||||
|
@ -715,7 +735,7 @@ int compNP(char *nom1, char *prenom1,char *nom2, char *prenom2)
|
|||
char * tmp;
|
||||
for(strLen1 = 0, tmp = nom1;*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++);
|
||||
char * np1 = malloc(strLen1+1);
|
||||
char * np2 = malloc(strLen2+1);
|
||||
|
@ -730,7 +750,8 @@ int compNP(char *nom1, char *prenom1,char *nom2, char *prenom2)
|
|||
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;
|
||||
fseek(bin, 0, SEEK_SET);fseek(txt, 0, SEEK_SET);
|
||||
|
@ -743,7 +764,7 @@ void clientBinToTXT(FILE * bin, FILE* txt) //===================================
|
|||
sauvegarderClientTXT(&client, txt, 0);
|
||||
fprintf(txt, "========================================================================");
|
||||
}
|
||||
// fread()
|
||||
// fread()
|
||||
}
|
||||
|
||||
void modificationClient(Client * client, FILE * clientDatF, FILE * clientTXTF)
|
||||
|
|
Loading…
Reference in New Issue