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
|
#include <mysql/mysql.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
int main (int argc, char **argv){
MYSQL *mysql, *mysql2;
MYSQL_RES *res,*res2;
MYSQL_ROW row,row2;
char *query,*query2,tmp[1000000],tmp2[1000000];
int i,t,r,montant,total_montant,indice;
int boolean;
int tab_offre [1000][3];
int compteur;
indice=1000000;
total_montant=0;
mysql_server_init(0, NULL, NULL);
mysql = mysql_init(NULL);
mysql2 = mysql_init(NULL);
if (!mysql_real_connect(mysql,"localhost","toto","aaaaa","wifiland",0,NULL,0)){
printf("Erreur de conncetion a la base : %s\n",mysql_error(mysql));
exit(1);
}
if (!mysql_real_connect(mysql2,"localhost","toto","aaaaa","wifi",0,NULL,0)){
printf("Erreur de conncetion a la base : %s\n",mysql_error(mysql));
exit(1);
}
query="select nom,code_guichet,num_compte,code_banque,idpersonne,cle_rib from personne";
t=mysql_real_query(mysql,query,(unsigned int) strlen(query));
if(t){
printf("Erreur requete sql: %s\n",mysql_error(mysql));
exit(1);
}
query2="SELECT personne_idpersonne,facturation,montant FROM compte";
t=mysql_real_query(mysql2,query2,(unsigned int) strlen(query2));
if(t){
printf("Erreur requete sql: %s\n",mysql_error(mysql));
exit(1);
}
/*premiere ligne : correspond "en-tete prelevement" */
printf("0308 497816 %sWIFILAND PR%s E 0152900010239340 30004 \n",argv[1],argv[1]);
/*les lignes qui suivent correspondent au "detail prelevement"*/
res=mysql_use_result(mysql);
res2=mysql_use_result(mysql2);
i=0;
while((row2=mysql_fetch_row(res2))){
if(atoi(row2[1])==1){
tab_offre[i][0]=atoi(row2[0]);
tab_offre[i][1]=atoi(row2[1]);
tab_offre[i][2]=atoi(row2[2]);
i++;
}
}
compteur=i;
while((row=mysql_fetch_row(res))){
if(atoi(row[5])!=0){
boolean=0;
i=0;
while((i<compteur)&&(boolean==0)){
if(tab_offre[i][0]==atoi(row[4])) {
boolean=1;
montant=tab_offre[i][2];
total_montant=total_montant+montant;
}
i++;
}
if(boolean==1){
printf("0608 497816%s%d%s",argv[1],indice,row[0]);
indice=indice+1;
for(i=0;i<(24-strlen(row[0]));i++) printf(" ");
for(i=0;i<32;i++) printf(" ");
printf("%s%s",row[1],row[2]);
sprintf(tmp2,"%d",montant);
for(i=0;i<(16-strlen(tmp2));i++) printf("0");
printf("%dWIFILAND PRELEVEMENT %s %s \n",montant,argv[1],row[3]);
}
}
}
/*derniere ligne qui correspond a "total prelevement"*/
sprintf(tmp,"%d",total_montant);
printf("0808 497816");
for(i=0;i<84;i++) printf(" ");
for(i=0;i<(16-strlen(tmp));i++) printf(" ");
printf("%d",total_montant);
for(i=0;i<42;i++) printf(" ");
printf("\n");
mysql_close(mysql);
} |
Partager