L327
This commit is contained in:
parent
cf1e345e9d
commit
eb51c467a5
200
VANDAMME28.c
200
VANDAMME28.c
|
@ -57,6 +57,7 @@ typedef struct{
|
|||
int fidelite;
|
||||
Panier panier;
|
||||
long ofsetFichierDat;
|
||||
long ofsetFichierTXT;
|
||||
} Client;
|
||||
|
||||
|
||||
|
@ -77,7 +78,7 @@ int itoaDM(int i, char*);
|
|||
Bool clean_keyboard();
|
||||
int ageClient(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 *);
|
||||
void localiserFichiersClients(char *, FILE **, FILE **);
|
||||
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 *);
|
||||
void sauvergarderFacture(FILE *, Date *, Client *);
|
||||
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, 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 *);
|
||||
|
||||
int main()
|
||||
{
|
||||
//printf("%d\n", pointsFidelite(52.23));
|
||||
FILE ** clientDatF = NULL; clientDatF = malloc(sizeof(FILE *));
|
||||
FILE ** clientTXTF = NULL; clientTXTF = malloc(sizeof(FILE *));
|
||||
FILE * clientDatF = NULL;
|
||||
FILE * clientTXTF = NULL;
|
||||
Client * client;
|
||||
long int ofsetFileCurClient = 0;
|
||||
char nomClient[__STRLEN__],prenomClient[__STRLEN__];
|
||||
|
@ -120,7 +121,7 @@ int main()
|
|||
date.annee = locTime->tm_year;
|
||||
// printf("%d/%d/%d\n", date->jour, date->moi, date->annee );
|
||||
}
|
||||
localiserFichiersClients(fichierClientDat, clientDatF, clientTXTF);
|
||||
localiserFichiersClients(fichierClientDat, &clientDatF, &clientTXTF);
|
||||
while(w)
|
||||
{
|
||||
printf("1. Nouveau client\n");
|
||||
|
@ -133,42 +134,41 @@ int main()
|
|||
case 1:
|
||||
client = malloc(sizeof(Client));
|
||||
client->ofsetFichierDat = 0;
|
||||
client->ofsetFichierTXT = 0;
|
||||
encoderClient(client);
|
||||
afficherClient(client, &date);
|
||||
fseek(*clientTXTF, 0, SEEK_END);
|
||||
|
||||
sauvegarderClientFile(*clientTXTF, *clientDatF, client);
|
||||
w = gestionClient(client, &date);
|
||||
fseek(clientTXTF, 0, SEEK_END);
|
||||
sauvegarderClientFile(clientTXTF, clientDatF, client);
|
||||
w = gestionClient(client, &date, clientDatF, clientTXTF);
|
||||
break;
|
||||
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);
|
||||
printf("\npRENOM du client (sensible a la casse) : ");
|
||||
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);
|
||||
w = gestionClient(client, &date, clientDatF, clientTXTF);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Client non trouvé !\n");
|
||||
printf("\nClient non trouvé !\n");
|
||||
printf("%d",(int)sizeof(Client));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(client);
|
||||
fclose(*clientDatF);
|
||||
fclose(*clientTXTF);
|
||||
free(clientDatF);
|
||||
free(clientTXTF);
|
||||
fclose(clientDatF);
|
||||
fclose(clientTXTF);
|
||||
return 0;
|
||||
}
|
||||
void encoderDate(Date * date, char *invite)
|
||||
{
|
||||
do {
|
||||
printf("%s\n", invite);
|
||||
printf("\n%s\n", invite);
|
||||
printf("Entrez la date sous cette forme : jj/mm/aaaa\n");
|
||||
scanf("%d/%d/%d",&(date->jour),&(date->moi),&(date->annee));
|
||||
} while(!dateValide(date));
|
||||
|
@ -176,65 +176,23 @@ void encoderDate(Date * date, char *invite)
|
|||
|
||||
Bool dateValide(Date * date)
|
||||
{
|
||||
int j = date->jour;
|
||||
int m = date->moi;
|
||||
int a = date->annee;
|
||||
int bis;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
int j = date->jour;
|
||||
int m = date->moi;
|
||||
int a = date->annee;
|
||||
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
|
||||
daysinmonth[1]=29;
|
||||
if (m<13)
|
||||
{
|
||||
if( d <= daysinmonth[m-1] )
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
void encoderArticle(Article * article)
|
||||
{
|
||||
printf("\nVeuillez entrer le nom : ");
|
||||
|
@ -250,7 +208,7 @@ void encoderArticle(Article * article)
|
|||
|
||||
void encoderClient(Client * client)
|
||||
{
|
||||
printf("Encoage Client\n");
|
||||
printf("\nEncoage Client\n");
|
||||
client->fidelite = 0;
|
||||
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 && \
|
||||
|
@ -275,7 +233,7 @@ void encoderClient(Client * client)
|
|||
}
|
||||
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("numero : %s\n",client->adresse.numero);
|
||||
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
|
||||
{
|
||||
fprintf(file, "DEBUG2\n");
|
||||
fflush(file);
|
||||
va_list ap;
|
||||
int age = 0;
|
||||
va_start(ap, arg);
|
||||
|
@ -304,7 +260,6 @@ void sauvegarderClientTXT(Client *client, FILE * file, long arg, ...) //EcrireDo
|
|||
}
|
||||
else
|
||||
{
|
||||
printf("SUCCES304\n");
|
||||
fprintf(file, "Client : %s %s \n", client->nom, client->prenom);
|
||||
}
|
||||
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");
|
||||
}
|
||||
printf("YYYYYOOOOOLLLLLOOOOO\n");
|
||||
fflush(file);
|
||||
system("pause");
|
||||
va_end(ap);
|
||||
}
|
||||
void encoderFacture(Panier * panier)
|
||||
|
@ -343,7 +295,7 @@ void encoderFacture(Panier * panier)
|
|||
tempArticle = (Article*)realloc(panier->article, sizeof(Article)*(panier->nbrArt));
|
||||
if(panier->article == NULL)
|
||||
{
|
||||
printf("ERREUR ALLOCATION !");
|
||||
printf("ERREUR ALLOCATION panier->article !");
|
||||
free(tempArticle);
|
||||
free(panier->article);
|
||||
exit(-1);
|
||||
|
@ -373,6 +325,7 @@ FILE * creerFichier(Date * date, Client * client)
|
|||
clean_keyboard();
|
||||
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);
|
||||
|
@ -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)
|
||||
{
|
||||
client = malloc(sizeof(Client));
|
||||
long int ofsetFileCurClient;
|
||||
fseek(clientDatF, sizeof(unsigned long int)+sizeof(Bool), SEEK_SET);
|
||||
clearerr(clientDatF); //Clear EOF
|
||||
|
@ -617,7 +569,7 @@ long int rechercheClient(char nom[__STRLEN__], char prenom[__STRLEN__], FILE * c
|
|||
return ofsetFileCurClient;
|
||||
}
|
||||
|
||||
Bool gestionClient(Client * client, Date * date)
|
||||
Bool gestionClient(Client * client, Date * date, FILE * clientDatF, FILE * clientTXTF)
|
||||
{
|
||||
char choix;
|
||||
while(1)
|
||||
|
@ -637,6 +589,7 @@ Bool gestionClient(Client * client, Date * date)
|
|||
afficherClient(client, date);
|
||||
break;
|
||||
case 'b':
|
||||
modificationClient(client, clientDatF, clientTXTF);
|
||||
break;
|
||||
case 'c':
|
||||
gestionFacture(client, date);
|
||||
|
@ -769,38 +722,45 @@ le standard c n'autorise que l'ajout et la modif */
|
|||
|
||||
void modificationClient(Client * client, FILE * clientDatF, FILE * clientTXTF)
|
||||
{
|
||||
int choix = 0;
|
||||
char ** aModifier = {&client->adresse, &client->contact.telephone, &client->contact.email};
|
||||
char ** aAfficher = {"Adresse", "Telephne", "E-mail"};
|
||||
char choix = 0;
|
||||
void * aModifier[] = {(Adresse *)&client->adresse, (char *)&client->contact.telephone, (char *)&client->contact.email};
|
||||
char * aAfficher[] = {"Adresse", "Telephne", "E-mail"};
|
||||
char w;
|
||||
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 :");clean_keyboard();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))
|
||||
do
|
||||
{
|
||||
printf("\nErreur lors de l'encodage de l'adresse");
|
||||
exit(-1);
|
||||
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 :");clean_keyboard();scanf("%d", (int *)&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);
|
||||
}
|
||||
cleanFgets(client->adresse.rue);cleanFgets(client->adresse.numero);cleanFgets(client->adresse.localite);
|
||||
cleanFgets(client->nom);cleanFgets(client->prenom);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Modification de %s :", aAfficher[choix-1]);
|
||||
clean_keyboard();
|
||||
scanf("%s", aModifier[choix-1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Modification de %s :", aAfficher[choix-1]);
|
||||
clean_keyboard();
|
||||
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