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();
@ -91,93 +96,105 @@ public class gardeMySQL {
System.out.println("Code erreur : " + ex.getErrorCode()); System.out.println("Code erreur : " + ex.getErrorCode());
} }
} }
/** /**
* 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());
nbMaj= prepStmt.executeUpdate(); prepStmt.setDate(3, TrmtDate.getSQLDate(g.getJourGarde()));
nbMaj = prepStmt.executeUpdate();
} 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 nbMaj;
return nbMaj; }
} /**
* Creation de la ventilation passé en paramètre ventilation à créer
*
* @return : identifiant de la ventilation créé, ou -1 si erreur
*/
public int create(Gardes g) {
int idCree = -1;
String sql = "INSERT into gardes "
+ "(jourGarde, periode, idPompier, disponibilite) "
+ "VALUES (?, ?, ?,?)";
public int update(Gardes v) { try {
PreparedStatement prepStmt = null;
prepStmt = theConnection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
prepStmt.setDate(1, TrmtDate.getSQLDate(g.getJourGarde()));
prepStmt.setInt(2, g.getPeriode());
prepStmt.setInt(3, g.getPompier().getId());
prepStmt.setInt(4, g.getDisponibilite());
System.out.println(prepStmt);
int nbLigne = prepStmt.executeUpdate();
// Recherche du no du pompier créé
if (nbLigne > 0) {
ResultSet result = prepStmt.getGeneratedKeys();
if (result.next()) {
idCree = result.getInt(1);
}
}
prepStmt.close();
} catch (SQLException ex) {
System.out.println("SQLExeption : " + ex.getMessage());
System.out.println("SQLState : " + ex.getSQLState());
System.out.println("Code erreur : " + ex.getErrorCode());
}
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; int nbMAJ = -1;
String sql = "UPDATE gardes " String sql = "UPDATE garde "
+ "SET ventil = ? " + "SET disponibilite = ? "
+ "WHERE idPompier= ? " + "WHERE idPompier = ? "
+ "AND jourGarde = ? " + "AND jourGarde = ? "
+ "AND periode = ?"; + "AND periode = ?";
try { try {
PreparedStatement prepStmt = theConnection.prepareStatement(sql); PreparedStatement prepStmt = theConnection.prepareStatement(sql);
prepStmt.setInt(1, v.getDisponibilite()); prepStmt.setInt(1, g.getDisponibilite());
prepStmt.setInt(2, v.getPompier().getId()); prepStmt.setInt(2, g.getPompier().getId());
prepStmt.setDate(3, TrmtDate.getSQLDate(v.getJourGarde())); prepStmt.setDate(3, TrmtDate.getSQLDate(g.getJourGarde()));
prepStmt.setInt(4, v.getPeriode()); prepStmt.setInt(4, g.getPeriode());
System.out.println("update : " + prepStmt); System.out.println("update : " + prepStmt);
nbMAJ = prepStmt.executeUpdate(); nbMAJ = prepStmt.executeUpdate();
} catch (SQLException ex) { } catch (SQLException ex) {
Logger.getLogger(gardeMySQL.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(GardeMySQL.class.getName()).log(Level.SEVERE, null, ex);
} }
return nbMAJ; return nbMAJ;
} }
/**
* Création d'un ventil
* @param v : ventil à créer
* @return : id du ventil
*/
public int create(Gardes v) {
int nbCre = -1;
String sql = "INSERT INTO gardes "
+ "(jourGarde, periode, idPompier, ventil)"
+ "VALUES (?, ?, ?, ?);";
try {
PreparedStatement prepStmt = theConnection.prepareStatement(sql);
prepStmt.setDate(1, TrmtDate.getSQLDate(v.getJourGarde()));
prepStmt.setInt(2, v.getPeriode());
prepStmt.setInt(3, v.getPompier().getId());
prepStmt.setInt(4, v.getDisponibilite());
int nbLigne= prepStmt.executeUpdate();
if (nbLigne > 0) {
ResultSet result = prepStmt.getGeneratedKeys();
if (result.next()) {
nbCre = result.getInt(1);
}
}
} catch (SQLException ex) {
System.out.println("SQLExeption : " + ex.getMessage());
System.out.println("SQLState : " + ex.getSQLState());
System.out.println("Code erreur : " + ex.getErrorCode());
}
return nbCre;
}
} }

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

@ -36,7 +36,7 @@ public class PompierServlet extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response) protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8"); response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) { try ( PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */ /* TODO output your page here. You may use following sample code. */
out.println("<!DOCTYPE html>"); out.println("<!DOCTYPE html>");
out.println("<html>"); out.println("<html>");
@ -74,7 +74,7 @@ public class PompierServlet extends HttpServlet {
boolean isNumeric = StringUtils.isStrictlyNumeric(pageEnString); boolean isNumeric = StringUtils.isStrictlyNumeric(pageEnString);
if (isNumeric) { if (isNumeric) {
pageDemandee = Integer.parseInt(pageEnString); pageDemandee = Integer.parseInt(pageEnString);
if (pageDemandee != 2 && pageDemandee != 3 && pageDemandee !=5) { // erreur if (pageDemandee != 2 && pageDemandee != 3 && pageDemandee != 5) { // erreur
erreur = true; erreur = true;
} }
} else { } else {
@ -101,16 +101,13 @@ 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 {
request.setAttribute("page", page); request.setAttribute("page", page);
maSession.setAttribute("lePompier", lePompier); maSession.setAttribute("lePompier", lePompier);
getServletContext().getRequestDispatcher("/WEB-INF/" + jsp).forward(request, response); getServletContext().getRequestDispatcher("/WEB-INF/" + jsp).forward(request, response);
} }
} }
@ -130,16 +127,16 @@ public class PompierServlet extends HttpServlet {
depuis la validation du formulaire de choix du pompier à afficher (btAfficherPompier = "Afficher") depuis la validation du formulaire de choix du pompier à afficher (btAfficherPompier = "Afficher")
depuis le bouton Ajouter du formulaire du choix du pompier (btAfficherPompier = "Ajouter") depuis le bouton Ajouter du formulaire du choix du pompier (btAfficherPompier = "Ajouter")
depuis le bouton de validation de mise à jour d'un pompier (btAfficherPompier = "ValiderMaj") depuis le bouton de validation de mise à jour d'un pompier (btAfficherPompier = "ValiderMaj")
*/ */
int erreur = 0; int erreur = 0;
String btValue = null; String btValue = null;
ArrayList<String> valeursBt = new ArrayList<String>() ; ArrayList<String> valeursBt = new ArrayList<String>();
valeursBt.add("Afficher") ; valeursBt.add("Afficher");
valeursBt.add("Ajouter") ; valeursBt.add("Ajouter");
valeursBt.add("ValiderMaj") ; valeursBt.add("ValiderMaj");
// Test du bouton btAfficherPompier // Test du bouton btAfficherPompier
if (request.getParameter("btAfficherPompier")==null) { if (request.getParameter("btAfficherPompier") == null) {
erreur = 1; erreur = 1;
} else { } else {
btValue = request.getParameter("btAfficherPompier"); btValue = request.getParameter("btAfficherPompier");
@ -152,7 +149,7 @@ public class PompierServlet extends HttpServlet {
//response.sendRedirect("/sdis29M1/authentification"); //response.sendRedirect("/sdis29M1/authentification");
return; return;
} }
HttpSession maSession = request.getSession(); HttpSession maSession = request.getSession();
ArrayList<Pompier> lesPompiers = (ArrayList<Pompier>) maSession.getAttribute("lesPompiers"); ArrayList<Pompier> lesPompiers = (ArrayList<Pompier>) maSession.getAttribute("lesPompiers");
if (request.getParameter("btAfficherPompier").equals("Afficher") if (request.getParameter("btAfficherPompier").equals("Afficher")
@ -162,12 +159,12 @@ public class PompierServlet extends HttpServlet {
maSession.setAttribute("lePompier", lesPompiers.get(noPompier)); maSession.setAttribute("lePompier", lesPompiers.get(noPompier));
request.setAttribute("page", 3); request.setAttribute("page", 3);
} }
if (request.getParameter("btAfficherPompier").equals("Ajouter")) { if (request.getParameter("btAfficherPompier").equals("Ajouter")) {
maSession.removeAttribute("lePompier"); maSession.removeAttribute("lePompier");
} }
if (request.getParameter("btAfficherPompier").equals("ValiderMaj")) { if (request.getParameter("btAfficherPompier").equals("ValiderMaj")) {
PompierForm pf = new PompierForm(request); PompierForm pf = new PompierForm(request);
boolean valid = pf.ctrlPompier(); boolean valid = pf.ctrlPompier();
// if (maSession.getAttribute("lePompier")==null) { // if (maSession.getAttribute("lePompier")==null) {
@ -182,8 +179,8 @@ public class PompierServlet extends HttpServlet {
// } // }
// } // }
pf.majBDD(); pf.majBDD();
} }
getServletContext().getRequestDispatcher("/WEB-INF/pompierJSP.jsp").forward(request, response); getServletContext().getRequestDispatcher("/WEB-INF/pompierJSP.jsp").forward(request, response);
} }

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

@ -16,7 +16,7 @@
${sessionScope.lePompierConnecte.getNom()} ( ${sessionScope.lePompierConnecte.getNom()} (
${sessionScope.lePompierConnecte.getLeStatut().getValeur()}) ${sessionScope.lePompierConnecte.getLeStatut().getValeur()})
</h4> </h4>
<button type="button" class="btn btn-warning fs-4" title="Déconnexion"> <button type="button" class="btn btn-warning fs-4" title="Déconnexion">
<a href="authentification"> <a href="authentification">
<i class="bi bi-box-arrow-right heading" width="32" height="32" fill="currentColor"></i> Déconnexion <i class="bi bi-box-arrow-right heading" width="32" height="32" fill="currentColor"></i> Déconnexion
@ -89,20 +89,16 @@
</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>
</li> <a class="nav-link" href="gardes">Gardes</a>
</li>
</ul> </ul>
</div> </div>