Merge origin/master

Conflicts:
	src/java/bdd/gardeMySQL.java
	src/java/servlet/PompierServlet.java
	web/WEB-INF/feuilleGardes.jsp
This commit is contained in:
clementine.desrucques 2021-12-13 15:09:34 +01:00
commit b4da29af06
7 changed files with 170 additions and 127 deletions

View File

@ -5,23 +5,26 @@
*/ */
package bdd; package bdd;
import bean.Caserne;
import bean.Gardes; import bean.Gardes;
import bean.Pompier; import bean.Pompier;
import util.TrmtDate;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import util.TrmtDate;
/** /**
* *
* @author funcha.ahamadi * @author funcha.ahamadi
*/ */
public class gardeMySQL { public class GardeMySQL {
private final Connection theConnection = Connexion.getConnect("localhost", private final Connection theConnection = Connexion.getConnect("localhost",
"sdis29", "sdis29",
"adminBDsdis", "adminBDsdis",
@ -36,7 +39,8 @@ public class gardeMySQL {
int indiceDateFin = lesDates.length - 1; int indiceDateFin = lesDates.length - 1;
Pompier lePompier; Pompier lePompier;
PompierMySQL pm = new PompierMySQL(); PompierMySQL pm = new PompierMySQL();
ArrayList<Pompier> lesPompiers = pm.readLesPomprangeiersCaserne(idCaserne);
ArrayList<Pompier> lesPompiers = new ArrayList<>();
for (Pompier unPompier : lesPompiers) { for (Pompier unPompier : lesPompiers) {
for (Calendar uneDate : lesDates) { for (Calendar uneDate : lesDates) {
for (int unePeriode : lesPeriodes) { for (int unePeriode : lesPeriodes) {
@ -64,17 +68,17 @@ public class gardeMySQL {
prepStmt.setDate(1, TrmtDate.getSQLDate(d1)); prepStmt.setDate(1, TrmtDate.getSQLDate(d1));
prepStmt.setDate(2, TrmtDate.getSQLDate(d2)); prepStmt.setDate(2, TrmtDate.getSQLDate(d2));
ResultSet resultat = prepStmt.executeQuery(); ResultSet resultat = prepStmt.executeQuery();
while (resultat.next()) while (resultat.next()) {
// public Pompier(Caserne laCaserne, int id, String nom, String prenom) { CaserneMySQL laCaserneMySQL = new CaserneMySQL();
lePompier = new Pompier( int idCaserne = resultat.getInt("idCaserne");
resultat.getCaserne("laCaserne"), Caserne laCaserne = laCaserneMySQL.read(idCaserne);
lePompier = new Pompier(laCaserne,
resultat.getInt("id"), resultat.getInt("id"),
resultat.getString("nom"), resultat.getString("nom"),
resultat.getString("prenom") resultat.getString("prenom"));
);
uneDispo = new Gardes(TrmtDate.getCalDate(resultat.getDate("jourGarde")), uneDispo = new Gardes(TrmtDate.getCalDate(resultat.getDate("jourGarde")),
resultat.getInt("periode"), resultat.getInt("periode")
lePompier); ,lePompier);
// Recherche si uneDispo existe dans les Dispos // Recherche si uneDispo existe dans les Dispos
int indice = lesDispo.indexOf(uneDispo); int indice = lesDispo.indexOf(uneDispo);
if (indice > -1) { if (indice > -1) {
@ -82,6 +86,7 @@ public class gardeMySQL {
laDispoTrouvee.setDisponibilite(resultat.getInt("disponibilite")); laDispoTrouvee.setDisponibilite(resultat.getInt("disponibilite"));
laDispoTrouvee.setIsInBDD(true); laDispoTrouvee.setIsInBDD(true);
} }
}
prepStmt.close(); prepStmt.close();
resultat.close(); resultat.close();
@ -92,21 +97,23 @@ public class gardeMySQL {
} }
} }
/** /**
* Suppression de la ventilation passé en param * Suppression de la garde passé en paramètre
* @param v : ventilation *
* @return : nb lignes supprimées * @param v ventilation à supprimer
* @return nb ligne a supprimer
*/ */
public int delete(Gardes v) { public int delete(Gardes g) {
int nbMaj = -1; int nbMaj = -1;
String sql = "DELETE FROM gardes " String sql = "DELETE * FROM gardes "
+ "WHERE idPompier = ? AND" + "WHERE idPompiere=?"
+ "periode = ? AND" + "AND periode=?"
+ "jourGarde = ?;"; + "AND jourGarde= ?;";
try { try {
PreparedStatement prepStmt = theConnection.prepareStatement(sql); PreparedStatement prepStmt = theConnection.prepareStatement(sql);
prepStmt.setInt(1, v.getPompier().getId()); prepStmt.setInt(1, g.getPompier().getId());
prepStmt.setInt(2, v.getPeriode()); prepStmt.setInt(2, g.getPeriode());
prepStmt.setDate(3, TrmtDate.getSQLDate(v.getJourGarde())); prepStmt.setInt(3, g.getPeriode());
prepStmt.setDate(3, TrmtDate.getSQLDate(g.getJourGarde()));
nbMaj = prepStmt.executeUpdate(); nbMaj = prepStmt.executeUpdate();
} catch (SQLException ex) { } catch (SQLException ex) {
@ -114,63 +121,73 @@ public class gardeMySQL {
System.out.println("SQLState : " + ex.getSQLState()); System.out.println("SQLState : " + ex.getSQLState());
System.out.println("Code erreur : " + ex.getErrorCode()); System.out.println("Code erreur : " + ex.getErrorCode());
} }
return nbMaj; return nbMaj;
} }
public int update(Gardes v) {
int nbMAJ = -1;
String sql = "UPDATE gardes "
+ "SET ventil = ? "
+ "WHERE idPompier= ? "
+ "AND jourGarde = ? "
+ "AND periode = ?";
try {
PreparedStatement prepStmt = theConnection.prepareStatement(sql);
prepStmt.setInt(1, v.getDisponibilite());
prepStmt.setInt(2, v.getPompier().getId());
prepStmt.setDate(3, TrmtDate.getSQLDate(v.getJourGarde()));
prepStmt.setInt(4, v.getPeriode());
System.out.println("update : " + prepStmt);
nbMAJ = prepStmt.executeUpdate();
} catch (SQLException ex) {
Logger.getLogger(gardeMySQL.class.getName()).log(Level.SEVERE, null, ex);
}
return nbMAJ;
}
/** /**
* Création d'un ventil * Creation de la ventilation passé en paramètre ventilation à créer
* @param v : ventil à créer *
* @return : id du ventil * @return : identifiant de la ventilation créé, ou -1 si erreur
*/ */
public int create(Gardes v) { public int create(Gardes g) {
int nbCre = -1; int idCree = -1;
String sql = "INSERT INTO gardes " String sql = "INSERT into gardes "
+ "(jourGarde, periode, idPompier, ventil)" + "(jourGarde, periode, idPompier, disponibilite) "
+ "VALUES (?, ?, ?, ?);"; + "VALUES (?, ?, ?,?)";
try { try {
PreparedStatement prepStmt = theConnection.prepareStatement(sql); PreparedStatement prepStmt = null;
prepStmt.setDate(1, TrmtDate.getSQLDate(v.getJourGarde())); prepStmt = theConnection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
prepStmt.setInt(2, v.getPeriode()); prepStmt.setDate(1, TrmtDate.getSQLDate(g.getJourGarde()));
prepStmt.setInt(3, v.getPompier().getId()); prepStmt.setInt(2, g.getPeriode());
prepStmt.setInt(4, v.getDisponibilite()); prepStmt.setInt(3, g.getPompier().getId());
prepStmt.setInt(4, g.getDisponibilite());
System.out.println(prepStmt);
int nbLigne = prepStmt.executeUpdate(); int nbLigne = prepStmt.executeUpdate();
// Recherche du no du pompier créé
if (nbLigne > 0) { if (nbLigne > 0) {
ResultSet result = prepStmt.getGeneratedKeys(); ResultSet result = prepStmt.getGeneratedKeys();
if (result.next()) { if (result.next()) {
nbCre = result.getInt(1); idCree = result.getInt(1);
}
}
}
}
prepStmt.close();
} catch (SQLException ex) { } catch (SQLException ex) {
System.out.println("SQLExeption : " + ex.getMessage()); System.out.println("SQLExeption : " + ex.getMessage());
System.out.println("SQLState : " + ex.getSQLState()); System.out.println("SQLState : " + ex.getSQLState());
System.out.println("Code erreur : " + ex.getErrorCode()); System.out.println("Code erreur : " + ex.getErrorCode());
} }
return nbCre; return idCree;
}
/**
* Mise à jour de la ventilation passée en paramètre
*
* @param v : ventilation à mettre à jour
* @return : nb lignes mises à jour, -1 si erreur
*/
public int update(Gardes g) {
int nbMAJ = -1;
String sql = "UPDATE garde "
+ "SET disponibilite = ? "
+ "WHERE idPompier = ? "
+ "AND jourGarde = ? "
+ "AND periode = ?";
try {
PreparedStatement prepStmt = theConnection.prepareStatement(sql);
prepStmt.setInt(1, g.getDisponibilite());
prepStmt.setInt(2, g.getPompier().getId());
prepStmt.setDate(3, TrmtDate.getSQLDate(g.getJourGarde()));
prepStmt.setInt(4, g.getPeriode());
System.out.println("update : " + prepStmt);
nbMAJ = prepStmt.executeUpdate();
} catch (SQLException ex) {
Logger.getLogger(GardeMySQL.class.getName()).log(Level.SEVERE, null, ex);
}
return nbMAJ;
} }

View File

@ -5,7 +5,8 @@
*/ */
package form; package form;
import bdd.gardeMySQL; import bdd.GardeMySQL;
import bean.Gardes; import bean.Gardes;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession; import jakarta.servlet.http.HttpSession;
@ -23,7 +24,7 @@ public class DispoForm {
HttpSession maS = request.getSession(); HttpSession maS = request.getSession();
ArrayList <Gardes> lesG = (ArrayList<Gardes>) maS.getAttribute("lesVentilInit"); ArrayList <Gardes> lesG = (ArrayList<Gardes>) maS.getAttribute("lesVentilInit");
gardeMySQL vm = new gardeMySQL(); GardeMySQL vm = new GardeMySQL();
Map<String, String[]> map = request.getParameterMap(); Map<String, String[]> map = request.getParameterMap();
String[] lesNvVentil = map.get("lesAct"); String[] lesNvVentil = map.get("lesAct");
int i = 0; int i = 0;

View File

@ -5,7 +5,8 @@
*/ */
package servlet; package servlet;
import bdd.gardeMySQL; import bdd.GardeMySQL;
import bean.Gardes; import bean.Gardes;
import bean.Pompier; import bean.Pompier;
import form.DispoForm; import form.DispoForm;
@ -66,6 +67,8 @@ public class GardesServlet extends HttpServlet {
throws ServletException, IOException { throws ServletException, IOException {
//processRequest(request, response); //processRequest(request, response);
HttpSession maSession = request.getSession(); HttpSession maSession = request.getSession();
if(maSession.getAttribute("lesVentilInit") == null){
ArrayList<Pompier> lesPompiers = (ArrayList<Pompier>) maSession.getAttribute("lesPompiers"); ArrayList<Pompier> lesPompiers = (ArrayList<Pompier>) maSession.getAttribute("lesPompiers");
Calendar[] lesDates = new Calendar[7]; Calendar[] lesDates = new Calendar[7];
String[] lesDatesEnString = new String[7]; String[] lesDatesEnString = new String[7];
@ -77,19 +80,25 @@ public class GardesServlet extends HttpServlet {
lesDatesEnString[i] = TrmtDate.getDateAAfficher(lesDates[i]); lesDatesEnString[i] = TrmtDate.getDateAAfficher(lesDates[i]);
} }
maSession.setAttribute("lesDates", lesDates); maSession.setAttribute("lesDates", lesDates);
maSession.setAttribute("lesDatesEnString", lesDatesEnString); maSession.setAttribute("lesDatesEnString", lesDatesEnString);
System.out.println(lesDatesEnString.toString());
/*Initialisation des periodes */ /*Initialisation des periodes */
int[] lesPeriodes = {1,2,3,4}; int[] lesPeriodes = {1,2,3,4};
maSession.setAttribute("lesPeriodes", lesPeriodes); maSession.setAttribute("lesPeriodes", lesPeriodes);
System.out.println(lesPeriodes.toString());
/* Recherche des ventilations */ /* Recherche des ventilations */
gardeMySQL vm = new gardeMySQL();
GardeMySQL vm = new GardeMySQL();
ArrayList<Gardes> lesVentilInit = vm.getLesDisponibilite(lesDates, lesPeriodes); ArrayList<Gardes> lesVentilInit = vm.getLesDisponibilite(lesDates, lesPeriodes);
//System.out.println("lesVentilInit : " + lesVentilInit); //System.out.println("lesVentilInit : " + lesVentilInit);
maSession.setAttribute("lesVentilInit", lesVentilInit); maSession.setAttribute("lesVentilInit", lesVentilInit);
/* Initialisation des couleurs */ /* Initialisation des couleurs */
String[] lesCouleurs = {"blanc", "gris", "jaune"}; String[] lesCouleurs = {"blanc", "gris", "jaune"};
maSession.setAttribute("lesCouleurs", lesCouleurs); maSession.setAttribute("lesCouleurs", lesCouleurs);
}
/* Affichage de la page de ventilation */ /* Affichage de la page de ventilation */
getServletContext().getRequestDispatcher("/WEB-INF/feuilleGardes.jsp").forward(request, response); getServletContext().getRequestDispatcher("/WEB-INF/feuilleGardes.jsp").forward(request, response);
} }

View File

@ -101,10 +101,7 @@ public class PompierServlet extends HttpServlet {
page = 3; page = 3;
} }
} }
if(erreur==false && pageDemandee==5){ //page gardes
getServletContext().getRequestDispatcher("/WEB-INF/feuilleGardes.jsp").forward(request, response);
}
if (erreur) { if (erreur) {
request.getRequestDispatcher("/authentification").forward(request, response); // redirection servlet request.getRequestDispatcher("/authentification").forward(request, response); // redirection servlet
} else { } else {

View File

@ -3,20 +3,9 @@
Created on : 6 déc. 2021, 15:07:45 Created on : 6 déc. 2021, 15:07:45
Author : funcha.ahamadi Author : funcha.ahamadi
--%> --%>
<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@page contentType="text/html" pageEncoding="UTF-8"%>
<legend> <%@include file= "jspf/debutJSP.jspf" %>
Feuille de gardes <body>
</legend>
<form action="gardes" method="POST">
<table class="table">
<thead>
<tr>
<th rowspan="2">N° de BIP</th>
<th rowspan="2">Nom Prenom</th>
<c:forEach items='${sessionScope.lesDatesEnString}' var="uneDate" varStatus="status">
<th colspan="2" class="text-center"> ${uneDate}</th>
</c:forEach>
</tr> </tr>
<tr> <tr>
@ -59,4 +48,35 @@
</table> </table>
</form><!-- comment --> <fieldset class="row mt-1 mb-10">
<legend>
Feuille de gardes
</legend>
<form action="gardes" method="POST">
<table class="table">
<thead>
<tr>
<th rowspan="2">No</th>
<th rowspan="2">Nom Prenom</th>
<c:forEach items='${sessionScope.lesDatesEnString}' var="uneDate" varStatus="status">
<th colspan="4" class="text-center"> ${uneDate}</th>
</c:forEach>
</tr>
<tr>
<c:forEach var="i" begin="0" end="6" step="1">
<c:forEach items='${sessionScope.lesPeriodes}' var="unePeriode" varStatus="status">
<td class="text-center">${unePeriode}</td>
</c:forEach>
</c:forEach>
</tr>
</thead>
</table>
</form>
</fieldset>

View File

@ -175,6 +175,9 @@
</div> </div>
</div> </div>
<!-- fin tab disp --> <!-- fin tab disp -->
<div class="danger mt-3">${message} </div> <div class="danger mt-3">${message} </div>

View File

@ -90,19 +90,15 @@
</c:choose> </c:choose>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<c:choose>
<c:when test="${page eq 5}">
<a class="nav-link active" href="pompier?pageDemandee=5">Gardes</a>
</c:when>
<c:when test="${sessionScope.lePompierConnecte.getLeStatut().getCode() eq 2}">
<a class="nav-link" href="pompier?pageDemandee=5">Gardes</a>
</c:when>
<c:otherwise>
</c:otherwise>
</c:choose>
<a class="nav-link" href="gardes">Gardes</a>
</li> </li>
</ul> </ul>
</div> </div>