...
This commit is contained in:
parent
e1654ee12e
commit
879ac887ce
176
VANDAMME28.c
176
VANDAMME28.c
|
@ -55,6 +55,7 @@ typedef struct{
|
||||||
Date anniversaire;
|
Date anniversaire;
|
||||||
int fidelite;
|
int fidelite;
|
||||||
Panier panier;
|
Panier panier;
|
||||||
|
long ofsetFichierDat;
|
||||||
} Client;
|
} Client;
|
||||||
|
|
||||||
|
|
||||||
|
@ -74,22 +75,26 @@ int itoaY(int i, char*);
|
||||||
int itoaDM(int i, char*);
|
int itoaDM(int i, char*);
|
||||||
Bool clean_keyboard();
|
Bool clean_keyboard();
|
||||||
int ageClient(Client *, Date *);
|
int ageClient(Client *, Date *);
|
||||||
unsigned 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 **);
|
void localiserFichiersClients(char *, FILE *, FILE *);
|
||||||
int sauvegarderClientFile(FILE **, Client * client);
|
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 *);
|
||||||
void sauvergarderFacture(FILE *, Date *, Client *);
|
void sauvergarderFacture(FILE *, Date *, Client *);
|
||||||
void sauvegarderClientTXT(Client *, FILE *, Bool,...); //EcrireDonneesClient
|
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)
|
||||||
|
*/
|
||||||
void clientBinToTXT(FILE *, FILE*);
|
void clientBinToTXT(FILE *, FILE*);
|
||||||
void modificationClient(Client *, FILE *);
|
void modificationClient(Client *, FILE *, FILE *);
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
//printf("%d\n", pointsFidelite(52.23));
|
//printf("%d\n", pointsFidelite(52.23));
|
||||||
FILE * clientF[2];//0=DAT;1=TXT
|
FILE * clientDatF = NULL, * clientTXTF = NULL;
|
||||||
Date date;
|
Date date;
|
||||||
char tmp;
|
char tmp;
|
||||||
Bool w;
|
Bool w;
|
||||||
|
@ -110,11 +115,11 @@ int main()
|
||||||
}
|
}
|
||||||
|
|
||||||
Client * client;
|
Client * client;
|
||||||
unsigned int ofsetFileCurClient;
|
long int ofsetFileCurClient = 0;
|
||||||
char nomClient[__STRLEN__],prenomClient[__STRLEN__];
|
char nomClient[__STRLEN__],prenomClient[__STRLEN__];
|
||||||
char fichierClientDat[__STRLEN_FILE__];
|
char fichierClientDat[__STRLEN_FILE__];
|
||||||
int choixMenu;
|
int choixMenu;
|
||||||
localiserFichiersClients(fichierClientDat, clientF);
|
localiserFichiersClients(fichierClientDat, clientDatF, clientTXTF);
|
||||||
while(w)
|
while(w)
|
||||||
{
|
{
|
||||||
printf("1. Nouveau client\n");
|
printf("1. Nouveau client\n");
|
||||||
|
@ -126,9 +131,10 @@ int main()
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
client = malloc(sizeof(Client));
|
client = malloc(sizeof(Client));
|
||||||
|
client->ofsetFichierDat = 0;
|
||||||
encoderClient(client);
|
encoderClient(client);
|
||||||
afficherClient(client, &date);
|
afficherClient(client, &date);
|
||||||
sauvegarderClientFile(clientF, client);
|
sauvegarderClientFile(clientDatF, clientTXTF, client);
|
||||||
w = gestionClient(client, &date);
|
w = gestionClient(client, &date);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
@ -136,7 +142,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, clientF[__TAB_CLIENTDAT_FILE__], client, &date);
|
ofsetFileCurClient = rechercheClient(nomClient,prenomClient, clientDatF, client, &date);
|
||||||
if(client != NULL)
|
if(client != NULL)
|
||||||
{
|
{
|
||||||
w = gestionClient(client, &date);
|
w = gestionClient(client, &date);
|
||||||
|
@ -150,10 +156,10 @@ int main()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(client);
|
free(client);
|
||||||
fclose(clientF[__TAB_CLIENTDAT_FILE__]);
|
fclose(clientDatF);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
void encoderDate(Date * date, char invite[__STRLEN__])
|
void encoderDate(Date * date, char *invite)
|
||||||
{
|
{
|
||||||
do {
|
do {
|
||||||
printf("%s\n", invite);
|
printf("%s\n", invite);
|
||||||
|
@ -272,26 +278,33 @@ void afficherClient(Client *client, Date *date)
|
||||||
printf("adresse email : %s\n",client->contact.email);
|
printf("adresse email : %s\n",client->contact.email);
|
||||||
printf("\nPoints de fidelite aqui : %d\n", client->fidelite);
|
printf("\nPoints de fidelite aqui : %d\n", client->fidelite);
|
||||||
}
|
}
|
||||||
void sauvegarderClientTXT(Client *client, FILE * file, Bool ageAff, ...) //EcrireDonneesClient
|
void sauvegarderClientTXT(Client *client, FILE * file, long arg, ...) //EcrireDonneesClient
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int age = 0;
|
int age = 0;
|
||||||
va_start(ap, ageAff);
|
va_start(ap, arg);
|
||||||
fprintf(file, "Client : %s %s", client->nom, client->prenom);
|
if(arg>1)
|
||||||
if(ageAff)
|
{
|
||||||
|
fseek(file, arg, SEEK_SET);
|
||||||
|
fprintf(file, "Client : %s %s", client->nom, client->prenom);
|
||||||
|
fprintf(file, "\n");
|
||||||
|
}
|
||||||
|
else if(arg == 1)
|
||||||
{
|
{
|
||||||
age = va_arg(ap,int);
|
age = va_arg(ap,int);
|
||||||
fprintf(file," (%d)\n",age);
|
fprintf(file, "Client : %s %s (%d)\n", client->nom, client->prenom,age);
|
||||||
|
}
|
||||||
|
else if(!arg)
|
||||||
|
{
|
||||||
|
fprintf(file, "Client : %s %s \n", client->nom, client->prenom);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
fprintf(file,"\n");
|
|
||||||
fprintf(file, "rue : %s\n",client->adresse.rue);
|
fprintf(file, "rue : %s\n",client->adresse.rue);
|
||||||
fprintf(file, "numero : %s\n",client->adresse.numero);
|
fprintf(file, "numero : %s\n",client->adresse.numero);
|
||||||
fprintf(file, "localité : %s\n",client->adresse.localite);
|
fprintf(file, "localité : %s\n",client->adresse.localite);
|
||||||
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(ageAff)
|
if(arg)
|
||||||
{
|
{
|
||||||
fprintf(file, "\nPoints de fidelite aqui : %d\n", client->fidelite);
|
fprintf(file, "\nPoints de fidelite aqui : %d\n", client->fidelite);
|
||||||
}
|
}
|
||||||
|
@ -573,19 +586,21 @@ void gestionFacture(Client * client, Date * date)
|
||||||
free(client->panier.article);
|
free(client->panier.article);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int rechercheClient(char nom[__STRLEN__], char prenom[__STRLEN__], FILE * clientF, Client * client, Date * date)
|
long int rechercheClient(char nom[__STRLEN__], char prenom[__STRLEN__], FILE * clientDatF, Client * client, Date * date)
|
||||||
{
|
{
|
||||||
client = malloc(sizeof(Client));
|
client = malloc(sizeof(Client));
|
||||||
fseek(clientF, 0, SEEK_SET);
|
long int ofsetFileCurClient;
|
||||||
clearerr(clientF); //Clear EOF
|
fseek(clientDatF, 0, SEEK_SET);
|
||||||
|
clearerr(clientDatF); //Clear EOF
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
fread(client, sizeof(Client), 1, clientF);
|
ofsetFileCurClient = ftell(clientDatF);
|
||||||
}while(!feof(clientF) && compNP(client->nom, client->prenom, nom, prenom));
|
fread(client, sizeof(Client), 1, clientDatF);
|
||||||
if(feof(clientF))
|
}while(!feof(clientDatF) && compNP(client->nom, client->prenom, nom, prenom));
|
||||||
return NULL;
|
if(feof(clientDatF))
|
||||||
|
return 0;
|
||||||
else
|
else
|
||||||
return client;
|
return ofsetFileCurClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bool gestionClient(Client * client, Date * date)
|
Bool gestionClient(Client * client, Date * date)
|
||||||
|
@ -622,7 +637,7 @@ Bool gestionClient(Client * client, Date * date)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void localiserFichiersClients(char fichierClientDat[__STRLEN_FILE__], FILE ** clientF)
|
void localiserFichiersClients(char * fichierClientDat, FILE * clientDatF, FILE * clientTXTF)
|
||||||
{
|
{
|
||||||
|
|
||||||
char rep[__STRLEN_FILE__];
|
char rep[__STRLEN_FILE__];
|
||||||
|
@ -632,60 +647,66 @@ void localiserFichiersClients(char fichierClientDat[__STRLEN_FILE__], FILE ** cl
|
||||||
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);
|
||||||
clientF[__TAB_CLIENTDAT_FILE__] = fopen(repTmp[__TAB_CLIENTDAT_FILE__], "r");
|
clientDatF = fopen(repTmp[__TAB_CLIENTDAT_FILE__], "r");
|
||||||
clientF[__TAB_CLIENTTXT_FILE__] = fopen(repTmp[__TAB_CLIENTTXT_FILE__], "r");
|
clientTXTF = fopen(repTmp[__TAB_CLIENTTXT_FILE__], "r");
|
||||||
if(clientF[__TAB_CLIENTDAT_FILE__] == NULL || clientF[__TAB_CLIENTTXT_FILE__] == NULL)
|
if(clientDatF == NULL || clientTXTF == NULL)
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
fclose(clientF[__TAB_CLIENTDAT_FILE__]);
|
fclose(clientDatF);
|
||||||
fclose(clientF[__TAB_CLIENTTXT_FILE__]);
|
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(!(clientF[__TAB_CLIENTDAT_FILE__] == NULL && clientF[__TAB_CLIENTTXT_FILE__] == 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')
|
||||||
{
|
{
|
||||||
clientF[__TAB_CLIENTDAT_FILE__] = fopen(repTmp[__TAB_CLIENTDAT_FILE__], "wb");
|
clientDatF = fopen(repTmp[__TAB_CLIENTDAT_FILE__], "wb");
|
||||||
clientF[__TAB_CLIENTTXT_FILE__] = fopen(repTmp[__TAB_CLIENTTXT_FILE__], "w");
|
clientTXTF = fopen(repTmp[__TAB_CLIENTTXT_FILE__], "w");
|
||||||
fclose(clientF[__TAB_CLIENTDAT_FILE__]);
|
fclose(clientDatF);
|
||||||
fclose(clientF[__TAB_CLIENTTXT_FILE__]);
|
fclose(clientTXTF);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
localiserFichiersClients(fichierClientDat, clientF);
|
localiserFichiersClients(fichierClientDat, clientDatF, clientTXTF);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fclose(clientF[__TAB_CLIENTDAT_FILE__]);
|
fclose(clientDatF);
|
||||||
fclose(clientF[__TAB_CLIENTTXT_FILE__]);
|
fclose(clientTXTF);
|
||||||
}
|
}
|
||||||
clientF[__TAB_CLIENTDAT_FILE__] = fopen(repTmp[__TAB_CLIENTDAT_FILE__], "r+b");
|
clientDatF = fopen(repTmp[__TAB_CLIENTDAT_FILE__], "r+b");
|
||||||
clientF[__TAB_CLIENTTXT_FILE__] = fopen(repTmp[__TAB_CLIENTTXT_FILE__], "r+");
|
clientTXTF = fopen(repTmp[__TAB_CLIENTTXT_FILE__], "r+");
|
||||||
if(clientF[__TAB_CLIENTDAT_FILE__] == NULL || clientF[__TAB_CLIENTTXT_FILE__] == NULL)
|
if(clientDatF == NULL || clientTXTF == NULL)
|
||||||
{
|
{
|
||||||
printf("\nErreur ouverture fichier");
|
printf("\nErreur ouverture fichier");
|
||||||
localiserFichiersClients(fichierClientDat, clientF);
|
localiserFichiersClients(fichierClientDat, clientDatF, clientTXTF);
|
||||||
}
|
}
|
||||||
strcpy(fichierClientDat, repTmp[__TAB_CLIENTDAT_FILE__]);
|
strcpy(fichierClientDat, repTmp[__TAB_CLIENTDAT_FILE__]);
|
||||||
}
|
}
|
||||||
|
|
||||||
int sauvegarderClientFile(FILE ** clientF, Client * client)
|
int sauvegarderClientFile(FILE * clientTXTF, FILE * clientDatF, Client * client)
|
||||||
{
|
{
|
||||||
int posi;
|
/* Si Nouveau client ofsetFichierDat = 0 donc fin fichier sinon on decale de l'ofset */
|
||||||
unsigned long int nbrClient;
|
if(!client->ofsetFichierDat)
|
||||||
fseek(clientF[__TAB_CLIENTDAT_FILE__], 0, SEEK_SET);
|
{
|
||||||
fread(&nbrClient,sizeof(nbrClient),1,clientF[__TAB_CLIENTDAT_FILE__]);
|
unsigned long int nbrClient;
|
||||||
nbrClient++;
|
fseek(clientDatF, 0, SEEK_SET);
|
||||||
fseek(clientF[__TAB_CLIENTDAT_FILE__], 0, SEEK_SET);
|
|
||||||
fwrite(&nbrClient,sizeof(nbrClient),1,clientF[__TAB_CLIENTDAT_FILE__]);
|
|
||||||
|
|
||||||
fseek(clientF[__TAB_CLIENTDAT_FILE__], 0, SEEK_END);
|
fread(&nbrClient,sizeof(nbrClient),1,clientDatF);
|
||||||
fseek(clientF[__TAB_CLIENTTXT_FILE__], 0, SEEK_END);
|
nbrClient++;
|
||||||
posi = ftell(clientF[__TAB_CLIENTDAT_FILE__]);
|
fseek(clientDatF, 0, SEEK_SET);
|
||||||
fwrite(client, sizeof(Client), 1, clientF[__TAB_CLIENTDAT_FILE__]);
|
fwrite(&nbrClient,sizeof(nbrClient),1,clientDatF);
|
||||||
fflush(clientF[__TAB_CLIENTDAT_FILE__]);
|
|
||||||
sauvegarderClientTXT(client, clientF[__TAB_CLIENTTXT_FILE__], 0);
|
fseek(clientDatF, 0, SEEK_END);
|
||||||
fflush(clientF[__TAB_CLIENTTXT_FILE__]);
|
fseek(clientTXTF, 0, SEEK_END);
|
||||||
return posi;
|
client->ofsetFichierDat = ftell(clientDatF);
|
||||||
|
sauvegarderClientTXT(client, clientTXTF, 0);
|
||||||
|
fflush(clientTXTF);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
fseek(clientDatF, client->ofsetFichierDat, SEEK_SET);
|
||||||
|
fwrite(client, sizeof(Client), 1, clientDatF);
|
||||||
|
fflush(clientDatF);
|
||||||
|
return client->ofsetFichierDat;
|
||||||
}
|
}
|
||||||
|
|
||||||
int compNP(char *nom1, char *prenom1,char *nom2, char *prenom2)
|
int compNP(char *nom1, char *prenom1,char *nom2, char *prenom2)
|
||||||
|
@ -720,11 +741,40 @@ void clientBinToTXT(FILE * bin, FILE* txt) //===================================
|
||||||
{
|
{
|
||||||
fread(&client, sizeof(Client), 1,bin);
|
fread(&client, sizeof(Client), 1,bin);
|
||||||
sauvegarderClientTXT(&client, txt, 0);
|
sauvegarderClientTXT(&client, txt, 0);
|
||||||
|
fprintf(txt, "========================================================================");
|
||||||
}
|
}
|
||||||
// fread()
|
// fread()
|
||||||
}
|
}
|
||||||
|
|
||||||
void modificationClient(Client * client, FILE * clientF)
|
void modificationClient(Client * client, FILE * clientDatF, FILE * clientTXTF)
|
||||||
{
|
{
|
||||||
|
int choix = 0;
|
||||||
|
char ** aModifier = {&client->adresse, &client->contact.telephne, &client->contact.email};
|
||||||
|
char ** aAfficher = {"Adresse", "Telephne", "E-mail"};
|
||||||
|
do
|
||||||
|
{
|
||||||
|
system("cls");
|
||||||
|
if(choix)
|
||||||
|
printf("Erreur choix errone !\n");
|
||||||
|
printf("MODIFICATION CLIENT %s %s \n", client->nom, client->prenom);
|
||||||
|
printf("1. Adresse\n2. Telephne\n3. E-mail\n");
|
||||||
|
printf("Votre choix :");scanf("%d", &choix);
|
||||||
|
}while(!(choix == 1 || choix == 2 || choix == 3));
|
||||||
|
printf("Modification %s :", aAfficher[choix-1]);
|
||||||
|
if(choix == 1)
|
||||||
|
{
|
||||||
|
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("\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);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue