

int main(int argc, char** argv)
{
char vdateRep[11];
char vheureRep[6];
char vidRep[6];
int vnbPlaces;
int vnbPlacesRes;
int vTabNbPlacesRes[500];
int i, nb, fin=1;

connexion();
EXEC SQL DECLARE REP CURSOR FOR SELECT to_char(dateRep, 'dd/mm/yyyy'), heureRep, idRep, nbPlaces 
FROM representation 
where dateRep>sysdate order by 1, 2;

printf("\n liste des représentations");
printf("\n dateRep    Heure Rep    Id Rep    Nb places rés./Insc.");
// traitement curseur pour en tete représentation
	EXEC SQL OPEN REP;
	EXEC SQL FETCH REP INTO :vdateRep, :vheureRep, :vidRep, :vnbPlaces;
	if (sqlca.sqlcode == +1403) {fin = 0;}
	while  (fin!=0)
        {       
		vdateRep[10]='\0'; vheureRep[5]='\0';vidRep[5]='\0';
		printf("\n %s.....%s......%s\n",vdateRep,vheureRep,vidRep); // en tete rep
		
		// gestion détail places
			EXEC SQL SELECT count(nbPlacesRes)
			into :nb
			FROM inscription I, representation R
			where dateRep>sysdate and R.idRep=I.idRep and I.idRep=:vidRep;
			
			vnbPlacesRes=vnbPlaces;
			if (nb>0){					// si on a des inscriptions
				EXEC SQL SELECT nbPlacesRes
				into :vTabNbPlacesRes
				FROM inscription I, representation R
				where dateRep>sysdate and R.idRep=I.idRep and I.idRep=:vidRep;
			for (i=0; i<nb;i++)
				{
				printf("\n ................%d\n",vTabNbPlacesRes[i]);	// detail
				vnbPlacesRes=vnbPlacesRes - vTabNbPlacesRes[i];
				}
			printf("\nNombre de places disponibles: %d\n",vnbPlacesRes); // fin rep
			}
		EXEC SQL FETCH REP INTO :vdateRep, :vheureRep, :vidRep, :vnbPlaces;
		if (sqlca.sqlcode == +1403) {fin = 0;}
		}
	EXEC SQL CLOSE REP;

	deconnexion(1);
	return(0);
}


