L327
This commit is contained in:
parent
cf1e345e9d
commit
eb51c467a5
144
VANDAMME28.c
144
VANDAMME28.c
|
@ -57,6 +57,7 @@ typedef struct{
|
||||||
int fidelite;
|
int fidelite;
|
||||||
Panier panier;
|
Panier panier;
|
||||||
long ofsetFichierDat;
|
long ofsetFichierDat;
|
||||||
|
long ofsetFichierTXT;
|
||||||
} Client;
|
} Client;
|
||||||
|
|
||||||
|
|
||||||
|
@ -77,7 +78,7 @@ int itoaDM(int i, char*);
|
||||||
Bool clean_keyboard();
|
Bool clean_keyboard();
|
||||||
int ageClient(Client *, Date *);
|
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 *, FILE *, FILE *);
|
||||||
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
|
||||||
|
@ -85,18 +86,18 @@ FILE * creerFichier(Date *, Client *);
|
||||||
Bool fichierExistant(char *);
|
Bool fichierExistant(char *);
|
||||||
void sauvergarderFacture(FILE *, Date *, Client *);
|
void sauvergarderFacture(FILE *, Date *, Client *);
|
||||||
void sauvegarderClientTXT(Client *, FILE *, long,...); /*EcrireDonneesClient
|
void sauvegarderClientTXT(Client *, FILE *, long,...); /*EcrireDonneesClient
|
||||||
si int = 0, n'affiche pas l'age, enregistre a la position courante
|
si long = 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, 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, ecris sans l'age mais a la position demandé (3e arg, long)
|
||||||
*/
|
*/
|
||||||
void clientBinToTXT(FILE *, FILE*);
|
void clientBinToTXT(FILE *, FILE*);//En cours de dev
|
||||||
void modificationClient(Client *, FILE *, FILE *);
|
void modificationClient(Client *, FILE *, FILE *);
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
//printf("%d\n", pointsFidelite(52.23));
|
//printf("%d\n", pointsFidelite(52.23));
|
||||||
FILE ** clientDatF = NULL; clientDatF = malloc(sizeof(FILE *));
|
FILE * clientDatF = NULL;
|
||||||
FILE ** clientTXTF = NULL; clientTXTF = malloc(sizeof(FILE *));
|
FILE * clientTXTF = NULL;
|
||||||
Client * client;
|
Client * client;
|
||||||
long int ofsetFileCurClient = 0;
|
long int ofsetFileCurClient = 0;
|
||||||
char nomClient[__STRLEN__],prenomClient[__STRLEN__];
|
char nomClient[__STRLEN__],prenomClient[__STRLEN__];
|
||||||
|
@ -120,7 +121,7 @@ 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 );
|
||||||
}
|
}
|
||||||
localiserFichiersClients(fichierClientDat, clientDatF, clientTXTF);
|
localiserFichiersClients(fichierClientDat, &clientDatF, &clientTXTF);
|
||||||
while(w)
|
while(w)
|
||||||
{
|
{
|
||||||
printf("1. Nouveau client\n");
|
printf("1. Nouveau client\n");
|
||||||
|
@ -133,42 +134,41 @@ int main()
|
||||||
case 1:
|
case 1:
|
||||||
client = malloc(sizeof(Client));
|
client = malloc(sizeof(Client));
|
||||||
client->ofsetFichierDat = 0;
|
client->ofsetFichierDat = 0;
|
||||||
|
client->ofsetFichierTXT = 0;
|
||||||
encoderClient(client);
|
encoderClient(client);
|
||||||
afficherClient(client, &date);
|
afficherClient(client, &date);
|
||||||
fseek(*clientTXTF, 0, SEEK_END);
|
fseek(clientTXTF, 0, SEEK_END);
|
||||||
|
sauvegarderClientFile(clientTXTF, clientDatF, client);
|
||||||
sauvegarderClientFile(*clientTXTF, *clientDatF, client);
|
w = gestionClient(client, &date, clientDatF, clientTXTF);
|
||||||
w = gestionClient(client, &date);
|
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
printf("Nom du client (sensible a la casse) : ");
|
client = malloc(sizeof(Client));
|
||||||
|
printf("\nNom du client (sensible a la casse) : ");
|
||||||
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, clientDatF, clientTXTF);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("Client non trouvé !\n");
|
printf("\nClient non trouvé !\n");
|
||||||
printf("%d",(int)sizeof(Client));
|
printf("%d",(int)sizeof(Client));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(client);
|
free(client);
|
||||||
fclose(*clientDatF);
|
fclose(clientDatF);
|
||||||
fclose(*clientTXTF);
|
fclose(clientTXTF);
|
||||||
free(clientDatF);
|
|
||||||
free(clientTXTF);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
void encoderDate(Date * date, char *invite)
|
void encoderDate(Date * date, char *invite)
|
||||||
{
|
{
|
||||||
do {
|
do {
|
||||||
printf("%s\n", invite);
|
printf("\n%s\n", invite);
|
||||||
printf("Entrez la date sous cette forme : jj/mm/aaaa\n");
|
printf("Entrez la date sous cette forme : jj/mm/aaaa\n");
|
||||||
scanf("%d/%d/%d",&(date->jour),&(date->moi),&(date->annee));
|
scanf("%d/%d/%d",&(date->jour),&(date->moi),&(date->annee));
|
||||||
} while(!dateValide(date));
|
} while(!dateValide(date));
|
||||||
|
@ -179,62 +179,20 @@ Bool dateValide(Date * date)
|
||||||
int j = date->jour;
|
int j = date->jour;
|
||||||
int m = date->moi;
|
int m = date->moi;
|
||||||
int a = date->annee;
|
int a = date->annee;
|
||||||
int bis;
|
int daysinmonth[12]={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||||
if(m != 2)
|
|
||||||
{
|
|
||||||
if(m >= 1 && m <= 7)
|
|
||||||
{
|
|
||||||
if(m %2 == 0)
|
|
||||||
{
|
|
||||||
if(j >= 1 && j <= 30) return TRUE;
|
|
||||||
else return FALSE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(j >= 1 && j <= 31) return TRUE;
|
|
||||||
else return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(m > 7 && m <= 12)
|
|
||||||
{
|
|
||||||
if(m %2 == 0)
|
|
||||||
{
|
|
||||||
if(j >= 1 && j <= 31) return TRUE;
|
|
||||||
else return FALSE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(j >= 1 && j <= 30) return TRUE;
|
|
||||||
else return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else return FALSE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(a %100 == 0)
|
|
||||||
{
|
|
||||||
if(a %400 == 0) bis = 1;
|
|
||||||
else bis = FALSE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(a %4 == 0)bis = 1;
|
|
||||||
else bis = FALSE;
|
|
||||||
}
|
|
||||||
if(bis == 1)
|
|
||||||
{
|
|
||||||
if(j >= 1 && j <= 29) return TRUE;
|
|
||||||
else return FALSE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(j >= 1 && j <= 28) return TRUE;
|
|
||||||
else return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if(y % 400 == 0 || (y % 100 != 0 && y % 4 == 0))//Si bis février = 29
|
||||||
|
daysinmonth[1]=29;
|
||||||
|
if (m<13)
|
||||||
|
{
|
||||||
|
if( d <= daysinmonth[m-1] )
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
void encoderArticle(Article * article)
|
void encoderArticle(Article * article)
|
||||||
{
|
{
|
||||||
printf("\nVeuillez entrer le nom : ");
|
printf("\nVeuillez entrer le nom : ");
|
||||||
|
@ -250,7 +208,7 @@ void encoderArticle(Article * article)
|
||||||
|
|
||||||
void encoderClient(Client * client)
|
void encoderClient(Client * client)
|
||||||
{
|
{
|
||||||
printf("Encoage Client\n");
|
printf("\nEncoage Client\n");
|
||||||
client->fidelite = 0;
|
client->fidelite = 0;
|
||||||
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 && \
|
||||||
|
@ -275,7 +233,7 @@ void encoderClient(Client * client)
|
||||||
}
|
}
|
||||||
void afficherClient(Client *client, Date *date)
|
void afficherClient(Client *client, Date *date)
|
||||||
{
|
{
|
||||||
printf("Client : %s %s (%d)\n", client->nom, client->prenom, ageClient(client, date));
|
printf("\nClient : %s %s (%d)\n", client->nom, client->prenom, ageClient(client, date));
|
||||||
printf("rue : %s\n",client->adresse.rue);
|
printf("rue : %s\n",client->adresse.rue);
|
||||||
printf("numero : %s\n",client->adresse.numero);
|
printf("numero : %s\n",client->adresse.numero);
|
||||||
printf("localité : %s\n",client->adresse.localite);
|
printf("localité : %s\n",client->adresse.localite);
|
||||||
|
@ -286,8 +244,6 @@ 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);
|
||||||
|
@ -304,7 +260,6 @@ void sauvegarderClientTXT(Client *client, FILE * file, long arg, ...) //EcrireDo
|
||||||
}
|
}
|
||||||
else
|
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);
|
||||||
|
@ -321,9 +276,6 @@ 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);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
void encoderFacture(Panier * panier)
|
void encoderFacture(Panier * panier)
|
||||||
|
@ -343,7 +295,7 @@ void encoderFacture(Panier * panier)
|
||||||
tempArticle = (Article*)realloc(panier->article, sizeof(Article)*(panier->nbrArt));
|
tempArticle = (Article*)realloc(panier->article, sizeof(Article)*(panier->nbrArt));
|
||||||
if(panier->article == NULL)
|
if(panier->article == NULL)
|
||||||
{
|
{
|
||||||
printf("ERREUR ALLOCATION !");
|
printf("ERREUR ALLOCATION panier->article !");
|
||||||
free(tempArticle);
|
free(tempArticle);
|
||||||
free(panier->article);
|
free(panier->article);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
|
@ -373,6 +325,7 @@ FILE * creerFichier(Date * date, Client * client)
|
||||||
clean_keyboard();
|
clean_keyboard();
|
||||||
scanf("%s", dir);
|
scanf("%s", dir);
|
||||||
//Toute cette partie aurais pus être remplacé par un sprintf
|
//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);
|
strcat(fileName,client->nom);
|
||||||
itoaY(date->annee, buf);
|
itoaY(date->annee, buf);
|
||||||
strcat(fileName,buf);
|
strcat(fileName,buf);
|
||||||
|
@ -601,7 +554,6 @@ void gestionFacture(Client * client, Date * date)
|
||||||
|
|
||||||
long int rechercheClient(char nom[__STRLEN__], char prenom[__STRLEN__], FILE * clientDatF, Client * client, Date * date)
|
long int rechercheClient(char nom[__STRLEN__], char prenom[__STRLEN__], FILE * clientDatF, Client * client, Date * date)
|
||||||
{
|
{
|
||||||
client = malloc(sizeof(Client));
|
|
||||||
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);
|
||||||
clearerr(clientDatF); //Clear EOF
|
clearerr(clientDatF); //Clear EOF
|
||||||
|
@ -617,7 +569,7 @@ long int rechercheClient(char nom[__STRLEN__], char prenom[__STRLEN__], FILE * c
|
||||||
return ofsetFileCurClient;
|
return ofsetFileCurClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bool gestionClient(Client * client, Date * date)
|
Bool gestionClient(Client * client, Date * date, FILE * clientDatF, FILE * clientTXTF)
|
||||||
{
|
{
|
||||||
char choix;
|
char choix;
|
||||||
while(1)
|
while(1)
|
||||||
|
@ -637,6 +589,7 @@ Bool gestionClient(Client * client, Date * date)
|
||||||
afficherClient(client, date);
|
afficherClient(client, date);
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
|
modificationClient(client, clientDatF, clientTXTF);
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
gestionFacture(client, date);
|
gestionFacture(client, date);
|
||||||
|
@ -769,9 +722,12 @@ le standard c n'autorise que l'ajout et la modif */
|
||||||
|
|
||||||
void modificationClient(Client * client, FILE * clientDatF, FILE * clientTXTF)
|
void modificationClient(Client * client, FILE * clientDatF, FILE * clientTXTF)
|
||||||
{
|
{
|
||||||
int choix = 0;
|
char choix = 0;
|
||||||
char ** aModifier = {&client->adresse, &client->contact.telephone, &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
|
||||||
{
|
{
|
||||||
system("cls");
|
system("cls");
|
||||||
|
@ -779,7 +735,7 @@ void modificationClient(Client * client, FILE * clientDatF, FILE * clientTXTF)
|
||||||
printf("Erreur choix errone !\n");
|
printf("Erreur choix errone !\n");
|
||||||
printf("MODIFICATION CLIENT %s %s \n", client->nom, client->prenom);
|
printf("MODIFICATION CLIENT %s %s \n", client->nom, client->prenom);
|
||||||
printf("1. Adresse\n2. Telephne\n3. E-mail\n");
|
printf("1. Adresse\n2. Telephne\n3. E-mail\n");
|
||||||
printf("Votre choix :");clean_keyboard();scanf("%d", &choix);
|
printf("Votre choix :");clean_keyboard();scanf("%d", (int *)&choix);
|
||||||
}while(!(choix == 1 || choix == 2 || choix == 3));
|
}while(!(choix == 1 || choix == 2 || choix == 3));
|
||||||
printf("Modification %s :", aAfficher[choix-1]);
|
printf("Modification %s :", aAfficher[choix-1]);
|
||||||
if(choix == 1)
|
if(choix == 1)
|
||||||
|
@ -801,6 +757,10 @@ void modificationClient(Client * client, FILE * clientDatF, FILE * clientTXTF)
|
||||||
{
|
{
|
||||||
printf("Modification de %s :", aAfficher[choix-1]);
|
printf("Modification de %s :", aAfficher[choix-1]);
|
||||||
clean_keyboard();
|
clean_keyboard();
|
||||||
scanf("%s", aModifier[choix-1]);
|
scanf("%s", (char *)aModifier[choix-1]);
|
||||||
}
|
}
|
||||||
|
printf("Y-a-til encore des Modification (y|n) ?");
|
||||||
|
clean_keyboard();scanf("%c", &choix);
|
||||||
|
}while((choix&0b00100000) == 'y');
|
||||||
|
sauvegarderClientFile(clientTXTF, clientDatF, client);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue