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
| package Mypackage;
import javax.jws.WebService;
import java.sql.*;
@WebService()
public class MoteurStatistiques
{
Connection con;
//-------------------------------------------------------
// Initialisation du driver OBCD.
//-------------------------------------------------------
public void Database(String Driver)
{
try
{
Class.forName(Driver);
}
catch(Exception e)
{
System.out.println("Erreur lors du chargement du driver:"+ e.getMessage());
}
}
//-------------------------------------------------------
// Connection à la base de données.
//-------------------------------------------------------
public void Open(String url,String login,String password)
{
try
{
con = DriverManager.getConnection(url,login,password);
}
catch(Exception e)
{
System.out.println("echec d'ouverture:"+e.getMessage());
}
}
//-------------------------------------------------------
// Fermeture de la connection à la base de données.
//-------------------------------------------------------
public void Close()
{
try
{
con.close();
}
catch(Exception e)
{
System.out.println("echec lors de la fermeture:"+e.getMessage());
}
}
//-------------------------------------------------------
// Calcul du taux d'inscrit par service.
//-------------------------------------------------------
private int NombrePotentielIncrit(int service) throws SQLException
{
int nbrInscritP = 0;
String sql =
"SELECT COUNT(ID_usager) AS nb_inscription_potentielle " +
"FROM usager, service WHERE (Age_min_service<=ROUND(DATEDIFF(NOW(),Date_naissance)/365.25,0)" +
"<=Age_max_service) AND ID_service=" + service + ";";
Statement stmt = con.createStatement();
ResultSet r = stmt.executeQuery(sql);
while(r.next())
{
nbrInscritP = Integer.parseInt(r.getString(1));
}
return nbrInscritP;
}
private int NombreInscrit(int service) throws SQLException
{
int nbrInscrit = 0;
String sql = "SELECT COUNT(*) FROM inscription WHERE id_service = " + service + ";";
Statement stmt = con.createStatement();
ResultSet r = stmt.executeQuery(sql);
while(r.next())
{
nbrInscrit = Integer.parseInt(r.getString(1));
}
return nbrInscrit;
}
public String tauxInscriptionService(int service) throws SQLException
{
double taux = 0;
double nbrPI = 0;
double nbrI = 0;
nbrPI = new Double(NombrePotentielIncrit(service));
nbrI = new Double(NombreInscrit(service));
taux = (nbrI / nbrPI)*100;
String s = format(taux,2,1);
return s;
}
//-------------------------------------------------------
// Fonction de formatage de Double au centième.
//-------------------------------------------------------
static final String ZEROES = "000000000000";
static final String BLANKS = " ";
static String format( double val, int n, int w)
{
double incr = 0.5;
for( int j=n; j>0; j--) incr /= 10;
val += incr;
String s = Double.toString(val);
int n1 = s.indexOf('.');
int n2 = s.length() - n1 - 1;
if (n>n2) s = s+ZEROES.substring(0, n-n2);
else if (n2>n) s = s.substring(0,n1+n+1);
if( w>0 & w>s.length() ) s = BLANKS.substring(0,w-s.length()) + s;
else if ( w<0 & (-w)>s.length() )
{
w=-w;
s = s + BLANKS.substring(0,w-s.length()) ;
}
return s;
}
//------------------------------------------------------------------
// Fonction de calcul du Taux de personnes ayant réglé la cantine.
//------------------------------------------------------------------
private int NombreInscritRegles() throws SQLException
{
int nbrInscritR = 0;
String sql = "SELECT COUNT(*) FROM inscription, inscription_usager " +
"WHERE inscription.ID_inscription_usager= inscription_usager.ID_inscription_usager " +
"AND YEAR( Date_paiement_periode ) = YEAR( Date_dernier_paiement ) " +
"AND (MONTH( Date_dernier_paiement ) = MONTH( Date_paiement_periode ) " +
"OR (MONTH( Date_dernier_paiement )-1) = MONTH( Date_paiement_periode )) " +
"AND (01 <= DAY( Date_dernier_paiement ) <= 03) AND ID_service = 5;";
Statement stmt = con.createStatement();
ResultSet r = stmt.executeQuery(sql);
while(r.next())
{
nbrInscritR = Integer.parseInt(r.getString(1));
}
return nbrInscritR;
}
public String tauxPaiementsCantineRegles() throws SQLException
{
double taux = 0;
double nbrI = 0;
double nbrIR = 0;
nbrI = new Double(NombreInscrit(5));
nbrIR = new Double(NombreInscritRegles());
taux = (nbrIR / nbrI)*100;
String s = format(taux,2,1);
return s;
}
//------------------------------------------------------------------
// Fonction de calcul du Taux de personnes étant en retard pour
// le paiment de la cantine.
//------------------------------------------------------------------
public String tauxPaiementsCantineRetard() throws SQLException
{
double taux = 0;
double nbrI = 0;
double nbrIR = 0;
double nbrINR = 0;
nbrI = new Double(NombreInscrit(5));
nbrIR = new Double(NombreInscritRegles());
nbrINR = nbrI - nbrIR;
taux = (nbrINR / nbrI)*100;
String s = format(taux,2,1);
return s;
}
//---------------------------------------------------------------------------
// Fonction de calcul du Taux de paiement de la cantine non réglé à l'année.
//---------------------------------------------------------------------------
private int NombreInscritNonReglesAnnee(int annee) throws SQLException
{
int nbrInscritNR = 0;
String sql = "SELECT SUM(nb_non_paiement) FROM non_paiement" +
" WHERE YEAR(Date)=" + annee + ";";
Statement stmt = con.createStatement();
ResultSet r = stmt.executeQuery(sql);
while(r.next())
{
nbrInscritNR = Integer.parseInt(r.getString(1));
}
return nbrInscritNR;
}
private int NombreInscritAnnee(int annee) throws SQLException
{
int nbrInscritAnnee = 0;
String sql = "SELECT SUM(nb_personne_inscrite) FROM non_paiement" +
" WHERE YEAR(Date)=" + annee + ";";
Statement stmt = con.createStatement();
ResultSet r = stmt.executeQuery(sql);
while(r.next())
{
nbrInscritAnnee = Integer.parseInt(r.getString(1));
}
return nbrInscritAnnee;
}
public String tauxPaiementsCantineNonRegles(int annee) throws SQLException
{
double taux = 0;
double nbrI = 0;
double nbrINR = 0;
nbrI = new Double(NombreInscritAnnee(annee));
nbrINR = new Double(NombreInscritNonReglesAnnee(annee));
taux = (nbrINR / nbrI)*100;
String s = format(taux,2,1);
return s;
}
} |
Partager