

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);
}
