1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
|
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "libb.h"
void Cadre_Deroulant()
{
int i,j;//cadre pour le menu deroulant principal
textbackground(7);textcolor(0);
gotoxy(3,40);cprintf("%c",201); //csg
gotoxy(16,40);cprintf("%c",187); //csd
gotoxy(3,49);cprintf("%c",200); //cig
gotoxy(16,49);cprintf("%c",188); //cid
for(i=4, j=40 ; i<16;i++) //lig verti sup
{
gotoxy(i,j);cprintf("%c",205);
}
for(i=4 , j=49 ; i<16;i++) //lig verti inf
{
gotoxy(i,j);cprintf("%c",205);
}
for(i=3,j=41;j<49;j++)//lig verti de gauche
{
gotoxy(i,j);cprintf("%c",186);
}
for(i=16,j=41;j<49;j++)//lig verti de droite
{
gotoxy(i,j);cprintf("%c",186);
}
}
void Cadre_Logo()
{
int i,j;
gotoxy(3,9);cprintf("%c",201);
for(i=4,j=9;i<78;i++)
{
gotoxy(i,j);cprintf("%c",205);
}
gotoxy(i,j);cprintf("%c",187);
for(i=78,j=10;j<22;j++)
{
gotoxy(i,j);cprintf("%c",186);
}
gotoxy(i,j);cprintf("%c",188);
for(i=4,j=22;i<78;i++)
{
gotoxy(i,j);cprintf("%c",205);
}
for(i=3,j=10;j<22;j++)
{
gotoxy(i,j);cprintf("%c",186);
}
gotoxy(i,j);cprintf("%c",200);
}
void Logo()
{
int PosX=5, PosY=10;
int i,j;
int LongBrancHoriSupDuC=10;
int LongBrancVertDuC=10;
/*for(i=1,j=10;i<PosX;i++)
{
gotoxy(i,j);cprintf("*");
}
for(i=80,j=16;i>76;i--)
{
gotoxy(i,j);cprintf("*");
} */
//grand C
gotoxy(PosX,PosY);cprintf("%c",201);
for(i=PosX+1;i<PosX+LongBrancHoriSupDuC+1;i++) //i<PosX+35+1 correspond a la longueur des branches horiz sup du c
{
gotoxy(i,PosY);cprintf("%c",205);
}
gotoxy(i,PosY);cprintf("%c",187);
for(i=PosX,j=PosY+1;j<PosY+LongBrancVertDuC+1;j++) //j<PosY+20+1 correspond a la branche vertical du c
{
gotoxy(i,j);cprintf("%c",186);
}
gotoxy(i,j);cprintf("%c",200);
for(i=PosX+1,j=PosY+10+1;i<PosX+10+1;i++) // j<PosY+20+1 idem que celui de l'autre for && i<PosX+35+1 correspond a la longueur des branches horiz inf du c
{
gotoxy(i,j);cprintf("%c",205);
}
gotoxy(i,j);cprintf("%c",188);
//ptit C
PosX=PosX+15;
PosY=PosY+3;
LongBrancVertDuC=7; //il faut la modifier pour ajuster le ptit c par rapport au Grd
gotoxy(PosX,PosY);cprintf("%c",201);
for(i=PosX+1;i<PosX+LongBrancHoriSupDuC+1;i++)
{
gotoxy(i,PosY);cprintf("%c",205);
}
gotoxy(i,PosY);cprintf("%c",187);
for(i=PosX,j=PosY+1; j<PosY+LongBrancVertDuC+1;j++)
{
gotoxy(i,j);cprintf("%c",186);
}
gotoxy(i,j);cprintf("%c",200);
for( i=PosX+1 , j=PosY+LongBrancVertDuC+1 ; i<PosX+LongBrancHoriSupDuC+1 ; i++ )
{
gotoxy(i,j);cprintf("%c",205);
}
gotoxy(i,j);cprintf("%c",188);
//c
PosX=PosX+15;
PosY=PosY+3;
LongBrancVertDuC=4;
gotoxy(PosX,PosY);cprintf("%c",201);
for(i=PosX+1 ; i<PosX+LongBrancHoriSupDuC+1 ;i++)
{
gotoxy(i,PosY);cprintf("%c",205);
}
gotoxy(i,PosY);cprintf("%c",187);
for(i=PosX,j=PosY+1 ; j<PosY+LongBrancVertDuC+1;j++)
{
gotoxy(i,j);cprintf("%c",186);
}
gotoxy(i,j);cprintf("%c",200);
for( i=PosX+1 , j=PosY+LongBrancVertDuC+1 ; i<PosX+LongBrancHoriSupDuC+1 ; i++ )
{
gotoxy(i,j);cprintf("%c",205);
}
gotoxy(i,j);cprintf("%c",188);
//a de car
PosX=PosX+15;
//PosY=PosY+3;
gotoxy(PosX,PosY);cprintf("%c",201);
for(i=PosX+1;i<PosX+LongBrancHoriSupDuC+1;i++)
{
gotoxy(i,PosY);cprintf("%c",205);
}
gotoxy(i,PosY);cprintf("%c",187);
for(i=PosX,j=PosY+1; j<PosY+LongBrancVertDuC+1;j++)
{
gotoxy(i,j);cprintf("%c",186);
}
gotoxy(i,j);cprintf("%c",200);
for(i=PosX+LongBrancHoriSupDuC+1,j=PosY+1; j<PosY+LongBrancVertDuC+1;j++)
{
gotoxy(i,j);cprintf("%c",186);
}
gotoxy(i,j);cprintf("%c",202);
for( i=PosX+1 , j=PosY+LongBrancVertDuC+1 ; i<PosX+LongBrancHoriSupDuC+1 ; i++ )
{
gotoxy(i,j);cprintf("%c",205);
}
gotoxy(i+1,j);cprintf("%c",205);
//r de car
PosX=PosX+15;
gotoxy(PosX,PosY);
gotoxy(PosX,PosY);cprintf("%c",201);
for(i=PosX+1;i<PosX+LongBrancHoriSupDuC+1;i++)
{
gotoxy(i,PosY);cprintf("%c",205);
}
gotoxy(i,PosY);cprintf("%c",187);
for(i=PosX,j=PosY+1; j<PosY+LongBrancVertDuC+1;j++)
{
gotoxy(i,j);cprintf("%c",186);
}
gotoxy(i,j);cprintf("%c",202);
}
/******************************************************************************/
void modifier_equipier()
{
char fichier1[]={"equipe.dat"};
char fichier2[]={"equipe2.dat"};
char choix;
char auto_lettre[53]={"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ."};
char autor[69]={"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@_-&|.,"};
char autor2[]={"oOnN"};
char num[11]={"0123456789."};
struct equipe d;
char ch[30];
int i=0;
short s;
FILE *f1, *f2;
f1=fopen(fichier1,"rb");
f2=fopen(fichier2,"wb");
if(f1!=NULL && f2!=NULL)
{
fread(&d,sizeof(struct equipe),1,f1);
while(!feof(f1))
{
clrscr();
printf("\n rec n%d :\n",i+1);
printf("\n NOM : %s",d.c_Nom);
printf("\n PRENOM : %s",d.c_Prenom);
printf("\n PASSWORD : %s",d.c_Pass);
printf("\n NOMBRE DE VEHICULE VENDU : %d",d.i_NbVehiVendu);
if(d.s_Bte==0)
{
printf("\n ADRESSE : %s, %ld",d.c_Rue,d.s_Num);
}
else
{
printf("\n ADRESSE : %s, %ld BTE %ld",d.c_Rue,d.s_Num,d.s_Bte);
}
printf("\n LOCALITE : %ld %s",d.s_CodePost,d.c_Ville);
printf("\n TELEPHONE : %s",d.c_Tel);
printf("\n EMAIL : %s",d.c_Email);
choix=choixon("voulez-vous supprimer le record (o/n) ?",&autor2[0],42, 13);
if(choix=='n'||choix=='N')
{
choix=choixon("voulez-vous modifier le record (o/n) ?",&autor2[0],41 ,15 );
if(choix=='o'||choix=='O')
{
//modification des champs
//modification de tous les champs directement
clrscr();
choix=choixon("voulez-vous modifier le nom (o/n) ?",&autor2[0],38 ,3);
if(choix=='o'||choix=='O')
{
ajout_nom(&ch[0],30,&auto_lettre[0],8,5);
strcpy(d.c_Nom,ch);
}
clrscr();
choix=choixon("voulez-vous modifier le prenom (o/n) ?",&autor2[0],41 ,3);
if(choix=='o'||choix=='O')
{
ajout_prenom(&ch[0],30,&auto_lettre[0],11,5);
strcpy(d.c_Prenom,ch);
}
clrscr();
choix=choixon("voulez-vous modifier le pass (o/n) ?",&autor2[0],39 ,3);
if(choix=='o'||choix=='O')
{
ajout_pass(&ch[0],5,&autor[0],13,5);
strcpy(d.c_Pass,ch);
}
//d.i_NbVehiVendu=0; ne pas modif ce champ
clrscr();
choix=choixon("voulez-vous modifier l adresse (o/n) ?",&autor2[0],41 ,3);
if(choix=='o'||choix=='O')
{
ajout_rue(&ch[0],30,&autor[0],8,5); //lors de l'affichage il affiche que "rue" c tout !!!
strcpy(d.c_Rue,ch);
}
clrscr();
choix=choixon("voulez-vous modifier le num (o/n) ?",&autor2[0],38,3);
if(choix=='o'||choix=='O')
{
ajout_num(&s,7,&num[0],11,10);
d.s_Num=s;
}
clrscr();
choix=choixon("voulez-vous modifier le num (o/n) ?",&autor2[0],38,3);
if(choix=='o'||choix=='O')
{
ajout_numbte(&s,5,&autor[0],12,12);
d.s_Bte=s;
}
clrscr();
choix=choixon("voulez-vous modifier le num (o/n) ?",&autor2[0],38,3);
if(choix=='o'||choix=='O')
{
ajout_cp(&s,6,&num[0],16,14);
d.s_CodePost=s;
}
clrscr();
choix=choixon("voulez-vous modifier le num (o/n) ?",&autor2[0],38,3);
if(choix=='o'||choix=='O')
{
ajout_ville(&ch[0],30,&auto_lettre[0],10,16);
strcpy(d.c_Ville,ch);
}
clrscr();
choix=choixon("voulez-vous modifier le num (o/n) ?",&autor2[0],38,3);
if(choix=='o'||choix=='O')
{
ajout_tel(&ch[0],14,&num[0],18,18);
strcpy(d.c_Tel,ch);
}
clrscr();
choix=choixon("voulez-vous modifier le num (o/n) ?",&autor2[0],38,3);
if(choix=='o'||choix=='O')
{
ajout_mail(&ch[0],30,&autor[0],11,20);
strcpy(d.c_Email,ch);
}
fwrite(&d,sizeof(d),1,f2);
}
else
{
fwrite(&d,sizeof(d),1,f2);
}
}
i++;
fread(&d, sizeof(struct equipe),1,f1);
}
}
else
{
printf("\n fichier innexistant");
}
fclose(f1);
fclose(f2);
renomfich(fichier2,fichier1);
//remove(fichier1);
//rename(fichier2,fichier1);
//getch();
}
/******************************************************************************/
void ajout_equipier()
{
struct equipe d;
char auto_lettre[53]={"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ."};
char autor[70]={"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@_-&|., "};
char autor2[]={"oOnN"};
char num[11]={"0123456789."};
char rep;
short s;
char ch[30];
FILE *f;
f=fopen("equipe.dat","a+b");
do
{
clrscr();
ajout_nom(&ch[0],30,&auto_lettre[0],8 ,2);
strcpy(d.c_Nom,ch);
ajout_prenom(&ch[0],30,&auto_lettre[0],11,4);
strcpy(d.c_Prenom,ch);
ajout_pass(&ch[0],5,&autor[0],13,6);
strcpy(d.c_Pass,ch);
d.i_NbVehiVendu=0;
ajout_rue(&ch[0],30,&autor[0],8,8); //lors de l'affichage il affiche que "rue" c tout !!!
strcpy(d.c_Rue,ch);
ajout_num(&s,7,&num[0],11,10);
d.s_Num=s;
ajout_numbte(&s,5,&autor[0],12,12);
d.s_Bte=s;
ajout_cp(&s,6,&num[0],16,14);
d.s_CodePost=s;
ajout_ville(&ch[0],30,&auto_lettre[0],10,16);
strcpy(d.c_Ville,ch);
ajout_tel(&ch[0],14,&num[0],18,18);
strcpy(d.c_Tel,ch);
ajout_mail(&ch[0],30,&autor[0],11,20);
strcpy(d.c_Email,ch);
//f=fopen("equipe.dat","ab");
fwrite(&d,sizeof(struct equipe),1,f);
rep=choixon("voulez-vous ajouter un autre equipier (o/n) ?",&autor2[0],48,22); //ligne PosX, colone PosY
}
while(rep=='o');
fclose(f);//getch();
}
/******************************************************************************/
//lon vaudra 11 desormais c 5
void ajout_pass(char* chaine,int lon,char* autor, int PosX, int PosY)
{
//char chaine[11];
printf("\n\n PASSWORD : ");
saisie(chaine,autor,lon,PosX,PosY);
//strcpy(d->c_Pass,chaine);
}
/******************************************************************************/
//lon vaudra 30
void ajout_mail(char* chaine,int lon,char* autor,int PosX,int PosY)
{
//char chaine[30];
printf("\n\n E-MAIL : ");
saisie(chaine,autor,lon,PosX,PosY);
}
/*****************************************/
//fct de client
/******************************************************************************/
void creation_index_client(char* fichier, char* index)
{
int flag=0,i=0,j,x ;
struct client d;
struct index_client *dyn=NULL;
FILE *f1, *f2;
f1=fopen(fichier,"rb");
if(f1!=NULL)
{
fread(&d,sizeof(struct client),1,f1);
while(!feof(f1) && flag==0)
{
dyn=(struct client*)realloc(dyn,(i+1)*sizeof(struct client));
if(dyn==NULL)
{
flag=1;
printf("\n allocation dynamique impossible veuillez quitter les autres applications.");
}
else
{
//printf("\n durant l alloc");
dyn[i].s_No=i;
strcpy(dyn[i].c_Nom,d.c_Nom);
strcpy(dyn[i].c_Prenom,d.c_Prenom);
strcpy(dyn[i].c_Tel,d.c_Tel);
i++;
}
fread(&d,sizeof(struct client),1,f1);
}
//printf("\n affichage du fichier apres l alloc dyn .. val de i = %d :\n",i);
// for(j=0;j<i;j++)
//{
//printf("\n rec no %2ld, nom : %-10s, prenom : %-10s, numtel : %-15s",dyn[j].s_No,dyn[j].c_Nom,dyn[j].c_Prenom,dyn[j].c_Tel);
//}//si j'enleve ceci il y a une erreur
f2=fopen(index,"wb");
if(f2!=NULL)
{
//printf("\n\n ecriture dans l index :\n");
for(j=0;j<i;j++)
{
fwrite(&dyn[j],sizeof(dyn[j]),1,f2);
//printf("\n val de retour de fwrite %d pour le %d rec.",x,j);
}
}
fclose(f2);
}
fclose(f1);
}
/******************************************************************************/
void renomfich(char* new_name, char* ancien_name)
{
remove(ancien_name); //on efface
rename(new_name,ancien_name); //on renome le nouveau fichier avec le nom de l'ancien pour tous remettre dans l'ordre
}
/******************************************************************************/
void trier_index_client(char *index)
{
struct index_client d;
struct index_client *dyn=NULL;
char index_trie[]={"indextrieclient.dat"};
FILE *f1,*f2;
int i=0,k,j,flag=0;
f1=fopen(index,"r+b");
if(f1==NULL)//on lit l index et on l'amène dans un vecteur dynamique
{
printf("\n fichier inexistant");
}
else
{
fread(&d,sizeof(struct index_client),1,f1);
while(flag==0 && !feof(f1))
{
dyn=(struct index_client*)realloc(dyn,(i+1)*sizeof(struct index_client));
if(dyn==NULL)
{
flag=1;
printf("\n allocation impossible veuillez quitter les autres applications.");
}
else
{
dyn[i]=d;
i++;
}
fread(&d,sizeof(struct index_client),1,f1);
}
flag=0;
//trie l index
k=i-1;
while(k>=0 && flag==0)
{
flag=1;
for(j=0;j<k;j++)
{
if(strcmpi(dyn[j].c_Nom,dyn[j+1].c_Nom)>0)
{
flag=0;
d=dyn[j];dyn[j]=dyn[j+1];dyn[j+1]=d;
}
else if(strcmpi(dyn[j].c_Nom,dyn[j+1].c_Nom)==0 && strcmpi(dyn[j].c_Prenom,dyn[j+1].c_Prenom)>0 )
{
flag=0;
strcpy(d.c_Prenom,dyn[j].c_Prenom);
strcpy(dyn[j].c_Prenom,dyn[j+1].c_Prenom);
strcpy(dyn[j+1].c_Prenom,d.c_Prenom);
strcpy(d.c_Tel,dyn[j].c_Tel);
strcpy(dyn[j].c_Tel,dyn[j+1].c_Tel);
strcpy(dyn[j+1].c_Tel,d.c_Tel);
}
else if(strcmpi(dyn[j].c_Nom,dyn[j+1].c_Nom)==0 && strcmpi(dyn[j].c_Prenom,dyn[j+1].c_Prenom)==0 && strcmpi(dyn[j].c_Tel,dyn[j+1].c_Tel)>0 )
{
flag=0;
strcpy(d.c_Tel,dyn[j].c_Tel);
strcpy(dyn[j].c_Tel,dyn[j+1].c_Tel);
strcpy(dyn[j+1].c_Tel,d.c_Tel);
}
}
k--;
}
f2=fopen(index_trie,"wb");
if(f2!=NULL)
{
printf("\n ecrit et fin trie");
for(j=0;j<i;j++)
{
d=dyn[j];
fwrite(&d,sizeof(d),1,f2);
//printf("\n rec no %2ld, nom : %-10s, prenom : %-10s, numtel : %-15s",dyn[j].s_No,dyn[j].c_Nom,dyn[j].c_Prenom,dyn[j].c_Tel);
}
}
fclose(f2);
}
fclose(f1);
}
/******************************************************************************/
void ax_dir_client(char* index, char* fichier)
{
struct index_client z[200];
struct client d2;
char rep;
char ch[30];
char ch2[14];
short s;
char aut[]={"onON"};
char num[11]={"0123456789."};
char auto_lettre[53]={"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ."};
int i,j,flag,n,p;
long pos;
FILE *f1,*f2;
char Nom[30],Prenom[30];
f1=fopen("index_client.dat","rb");
if(f1==NULL)
{
printf("\n fichier inexistant");
}
else
{
i=0;
fread(&z[i],sizeof(struct index_client),1,f1);
while(!feof(f1))
{
i++;
fread(&z[i],sizeof(struct index_client),1,f1);
}
//recherche
printf("N O M : ");
ajout_nom(&Nom[0],30,&auto_lettre[0],10,10);
printf("\n entre le prenom a rechercher : ");
ajout_prenom(&Prenom[0],30,&auto_lettre[0],10,11);
j=flag=0;
while(flag==0 && j<i)
{
if(strcmpi(z[j].c_Nom,Nom)==0 && strcmpi(z[j].c_Prenom,Prenom)==0)
{
flag=1;
p=z[j].s_No;
}
j++;
}
if(flag==1)
{
//Ax direct
f2=fopen("client.dat","r+b");
if(f2==NULL)
{
printf("\n fichier inexistant");
}
else
{
fseek(f2,p*sizeof(struct client),1);
pos=ftell(f2);
n=pos/sizeof(struct client);
if(n==p)
{
fread(&d2,sizeof(struct client),1,f2);
clrscr();
printf("\n nom : %s",d2.c_Nom);
printf("\n prenom : %s",d2.c_Prenom);
rep=choixon("voulez-vous modifier ce client (o/n) ?",&aut[0],41,5); //ligne PosX, colone PosY
if(rep=='o' || rep=='O') //modification du champs -> direct...
{
fseek(f2, -1*sizeof(struct client),1);
//modifier les champs
clrscr();
printf("\n modification du Record no%d :\n\n",n);
rep=choixon("voulez-vous modifier le nom (o/n) ?",&aut[0],38,6);
if(rep=='o' || rep=='O')
{
ajout_nom(&ch[0],30,&auto_lettre[0],8,8);
strcpy(d2.c_Nom,ch);
}
clrscr();
printf("\n modification du Record no%d :\n\n",n);
rep=choixon("voulez-vous modifier le prenom (o/n) ?",&aut[0],41,6);
if(rep=='o' || rep=='O')
{
ajout_prenom(&ch[0],30,&auto_lettre[0],11,8);
strcpy(d2.c_Prenom,ch);
}
clrscr();
printf("\n modification du Record no%d :\n\n",n);
rep=choixon("voulez-vous modifier la rue (o/n) ?",&aut[0],38,6);
if(rep=='o' || rep=='O')
{
ajout_rue(&ch[0],30,&auto_lettre[0],8,8);
strcpy(d2.c_Rue,ch);
}
clrscr();
printf("\n modification du Record no%d :\n\n",n);
rep=choixon("voulez-vous modifier le num (o/n) ?",&aut[0],38,6);
if(rep=='o' || rep=='O')
{
ajout_num(&s,7,&num[0],11,8);
d2.s_Num=s;
}
clrscr();
printf("\n modification du Record no%d :\n\n",n);
rep=choixon("voulez-vous modifier le num de bte (o/n) ?",&aut[0],45,6);
if(rep=='o' || rep=='O')
{
ajout_numbte(&s,5,&aut[0],12,8);
d2.s_Bte=s;
}
clrscr();
printf("\n modification du Record no%d :\n\n",n);
rep=choixon("voulez-vous modifier le code postale (o/n) ?",&aut[0],47,6);
if(rep=='o' || rep=='O')
{
ajout_cp(&s,6,&num[0],16,8);
d2.s_CodePost=s;
}
clrscr();
printf("\n modification du Record no%d :\n\n",n);
rep=choixon("voulez-vous modifier la ville (o/n) ?",&aut[0],40,6);
if(rep=='o' || rep=='O')
{
ajout_ville(&ch[0],30,&auto_lettre[0],10,8);
strcpy(d2.c_Ville,ch);
}
clrscr();
printf("\n modification du Record no%d :\n\n",n);
rep=choixon("voulez-vous modifier le num de telephone (o/n) ?",&aut[0],51,6);
if(rep=='o' || rep=='O')
{
ajout_tel(&ch2[0],14,&num[0],18,8);
strcpy(d2.c_Tel,ch2);
}
fwrite(&d2,sizeof(d2),1,f2);
//fin modif
}
}
}
fclose(f2);
}
else
{
printf("\n client inexistant");
}
}
fclose(f1);
getch();
}
/******************************************************************************/
void suppr_client(char* fichier)
{
char rep;
char fichier2[]={"client2.dat"};
char aut[]={"oOnN"};
int flag=0;
struct client d;
FILE *f1, *f2;
f1=fopen(fichier,"rb");
if(f1!=NULL)
{
f2=fopen(fichier2,"wb");
if(f2!=NULL)
{
fread(&d,sizeof(struct client),1,f1);
while(!feof(f1))
{
//listage du client
clrscr();
printf("\n nom : %s",d.c_Nom);
printf("\n Prenom : %s",d.c_Prenom);
rep=choixon("voulez-vous supprimer ce client de la database (o/n) ?",&aut[0],58,4);
if(rep=='n'||rep=='N')
{
flag=1;
fwrite(&d,sizeof(d),1,f2);
}
fread(&d,sizeof(struct client),1,f1);
}
}
fclose(f2);
}
fclose(f1);
if(flag==1)
{
//remove(fichier);
//rename(fichier2,fichier);
}
renomfich(fichier2,fichier);
}
/******************************************************************************/
void ajout_client(char* fichier)
{
struct client d;
char choix;
char autor2[]={"oOnN"};
char autor[70]={"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@_-&|., "};
char auto_lettre[53]={"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ."};
char num[11]={"0123456789."};
FILE *f;
//
char ch[30],ch2[14];
short s;
f=fopen(fichier,"a+b");
if(f!=NULL)
{
do
{
clrscr();
ajout_nom(&ch[0],30,&auto_lettre[0],8,2); //j'envoie ch[30]
strcpy(d.c_Nom,ch);
ajout_prenom(&ch[0],30,&auto_lettre[0],11,4); //idem
strcpy(d.c_Prenom,ch);
ajout_rue(&ch[0],30,&auto_lettre[0],8,6);
strcpy(d.c_Rue,ch);
ajout_num(&s,7,&num[0],11,8);
d.s_Num=s;
ajout_numbte(&s,5,&autor[0],12,10);
d.s_Bte=s;
ajout_cp(&s,6,&num[0],16,12);
d.s_CodePost=s;
ajout_ville(&ch[0],30,&autor[0],10,14);
strcpy(d.c_Ville,ch);
ajout_tel(&ch2[0],14,&num[0],18,16);
strcpy(d.c_Tel,ch2);
fwrite(&d,sizeof(d),1,f);
choix=choixon("voulez-vous ajouter un autre client (o/n) ?",&autor2[0],46,18); //ligne PosX, colone PosY
}
while(choix=='o'||choix=='O');
}
else
{
printf("\n impossible d'ouvrir le fichier");
}
fclose(f);
} |
Partager