Pascal LAFOURCADE 4 years ago
parent 070dc0e1f7
commit 1e4ae742d1

@ -0,0 +1,41 @@
drop table tresultat purge;
create table tresultat(ligne varchar2(200));
variable vnbRef number
prompt nombre de référence?
accept vnbRef
declare
dnbRef number:='&vnbRef';
didRep char(5);
dmessage varchar2(200);
dnbTot number;
inex exception;
cursor CUR is select I.idRep, sum(nbPlacesRes)
from inscription I, representation R
where I.idRep=R.idRep
and dateRep>sysdate
group by I.idRep
having sum(nbPlacesRes) > dnbRef
order by 2 desc;
begin
dmessage:='nombre de reference trop eleve';
insert into tresultat values('Id rep Nb total');
open CUR;
fetch CUR into didRep, dnbTot;
if CUR%notFound then raise inex;end if;
while CUR%FOUND
loop
insert into tresultat values (didRep||' '||dnbTot);
fetch CUR into didRep, dnbTot;
end loop;
close CUR;
exception
when inex then insert into tresultat values (dmessage);
end;
.
/
select * from tresultat;

@ -0,0 +1,42 @@
int main(int argc, char** argv)
{
char vidRep[6];
char vdateRep[11];
char vheureRep[5];
int vnbPlaces;
char vidArtiste[6];
int fin=1;
int vnbMax;
short indic;
EXEC SQL WHENEVER SQLERROR DO sql_error("Pb connexion\n");
printf("\n Appel de la fonction connexion");
connexion();
EXEC SQL DECLARE rep CURSOR FOR SELECT idRep, nbplaces FROM representation;
EXEC SQL OPEN rep;
EXEC SQL FETCH rep INTO :vidRep, :vnbPlaces:indic;
if (sqlca.sqlcode == +1403) {fin = 0;}
while (fin!=0)
{
vidRep[5]='\0';
printf("\n num representation: %s \n",vidRep);
if (indic==-1)
printf("\n nb max?: ");
scanf ("%d%*c", &vnbMax);
EXEC SQL update representation set nbPlaces = :vnbMax where idRep=:vidRep;
EXEC SQL commit;
EXEC SQL FETCH rep INTO :vidRep, :vnbPlaces:indic;
if (sqlca.sqlcode == +1403) {fin = 0;}
}
printf(" Fini \n");
EXEC SQL CLOSE rep;
deconnexion(1);
return(0);
}

@ -0,0 +1,57 @@
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);
}

@ -0,0 +1,60 @@
int main(int argc, char** argv)
{
char vidRepAnc[6];
char vidRepNouv[6];
varchar vadrMail[30];
int nb, nb1, nb2, nb3, vnbP,vnbPlacesRes;
float vtarif, vmont1, vtarif2, vmont2, vdif;
connexion();
// calcul montant payé pour ancienne rep
EXEC SQL select nbPlacesRes,tarif into :vnbP, :vtarif
from inscription I, representation R, artiste A
where I.idRep=R.idRep and R.idartiste=A.idaRtiste and I.idRep=:vidRepAnc and adrMail=:vadrMail;
// avait payé
vmont1=vtarif*vnbP;
// inscription deja faite?
EXEC SQL SELECT count(*) into :nb
FROM inscription
where idRep=:vidRepNouv and adrMail=:vadrMail;
if (nb==1)
{sql_error("\ninscription déjà faite à cette nouvelle\n");}
else {
// nombres places suffisantes?
EXEC SQL SELECT nbPlaces into :nb1
FROM representation
where idRep=:vidRepNouv;
EXEC SQL SELECT sum(nbPlacesRes) into :nb2
FROM inscription
where idRep=:vidRepNouv;
EXEC SQL SELECT nbPlacesRes into :vnbPlacesRes
FROM inscription
where idRep=:vidRepAnc and adrMail=:vadrMail;
// nb places restantes
nb3=nb1-nb2-vnbPlacesRes;
if (nb3<0)
{sql_error("\nplus assez de places");}
else {
EXEC SQL select tarif into :vtarif2
from representation R, artiste A
where R.idArtiste=A.idArtiste and R.idRep=:vidRepNouv;
// devrait payer
vmont2=vtarif2*vnbPlacesRes;
//maj
EXEC SQL UPDATE inscription set idRep=:vidRepNouv
where idRep=:vidRepAnc and adrMail=:vadrMail;
EXEC SQL COMMIT;
// remboursement?
vdif=vmont1-vmont2;
if(vdif>0)
printf("\nmodif faite, on vous doit: %.2f euros", vdif);
else printf("\nmodif faite, vous devez: %.2f euros", vdif*-1);
}
}
deconnexion(1);
return(0);
}
Loading…
Cancel
Save