sdisM2/src/java/bdd/gardeMySQL.java
funcha.ahamadi 68bf428f4f Merge origin/master
Conflicts:
	src/java/bdd/PompierMySql.java
	src/java/com/test/servlets/authentifServlet.java
	web/WEB-INF/CreaPompier.jsp
2021-12-13 10:28:40 +01:00

99 lines
3.5 KiB
Java

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package bdd;
import bean.Gardes;
import bean.Pompier;
import com.sdis29a.util.TrmtDate;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
/**
*
* @author funcha.ahamadi
*/
public class gardeMySQL {
private final Connection theConnection = Connexion.getConnect("localhost",
"sdis29",
"adminBDsdis",
"mdpBDsdis");
public ArrayList<Gardes> getLesDisponibilite(Calendar[] lesDates, int[] lesPeriodes) {
ArrayList<Gardes> lesDispo = new ArrayList<>();
Gardes uneDispo;
/* a. Initialisation de la collection lesVentil pour la période,
création d'une ventil par salarié, par date et période
*/
int indiceDateFin = lesDates.length - 1;
Pompier lePompier;
PompierMySQL pm = new PompierMySQL();
ArrayList<Pompier> lesPompiers = pm.readLesPompiersCaserne(idCaserne);
for (Pompier unPompier : lesPompiers) {
for (Calendar uneDate : lesDates) {
for (int unePeriode : lesPeriodes) {
uneDispo = new Gardes(uneDate, unePeriode, unPompier);
lesDispo.add(uneDispo);
}
}
}
/* b) Maj de la collection lesVentil
*/
readAll(lesDispo, lesDates[0], lesDates[indiceDateFin]);
//System.out.println("lesDispo : " + lesDispo);
return lesDispo;
}
public void readAll(ArrayList<Gardes> lesDispo, Calendar d1, Calendar d2) {
Pompier lePompier;
Gardes uneDispo;
Gardes laDispoTrouvee;
String sql = "SELECT * FROM gardes "
+ "INNER JOIN pompier on idPompier = id "
+ "WHERE jourGarde BETWEEN ? and ?;";
try {
PreparedStatement prepStmt = theConnection.prepareStatement(sql);
prepStmt.setDate(1, TrmtDate.getSQLDate(d1));
prepStmt.setDate(2, TrmtDate.getSQLDate(d2));
ResultSet resultat = prepStmt.executeQuery();
while (resultat.next())
// public Pompier(Caserne laCaserne, int id, String nom, String prenom) {
lePompier = new Pompier(resultat.getCaserne("laCaserne"),
resultat.getString("nom"),
resultat.getString("prenom");
uneDispo = new Gardes(TrmtDate.getCalDate(resultat.getDate("jourGarde")),
resultat.getInt("periode")
,lePompier);
// Recherche si uneDispo existe dans les Dispos
int indice = lesDispo.indexOf(uneDispo);
if (indice > -1) {
laDispoTrouvee = lesDispo.get(indice);
laDispoTrouvee.setActivite(resultat.getInt("disponibilite"));
laDispoTrouvee.setIsInDB(true);
}
prepStmt.close();
resultat.close();
} catch (SQLException ex) {
System.out.println("SQLExeption : " + ex.getMessage());
System.out.println("SQLState : " + ex.getSQLState());
System.out.println("Code erreur : " + ex.getErrorCode());
}
}
}