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;
import bean.Caserne;
import bean.Gardes;
import bean.Pompier;
import util.TrmtDate;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import util.TrmtDate;
/**
*
* @author funcha.ahamadi
*/
public class gardeMySQL {
public class GardeMySQL {
private final Connection theConnection = Connexion.getConnect("localhost",
"sdis29",
"adminBDsdis",
@ -36,7 +39,8 @@ public class gardeMySQL {
int indiceDateFin = lesDates.length - 1;
Pompier lePompier;
PompierMySQL pm = new PompierMySQL();
ArrayList<Pompier> lesPompiers = pm.readLesPomprangeiersCaserne(idCaserne);
ArrayList<Pompier> lesPompiers = new ArrayList<>();
for (Pompier unPompier : lesPompiers) {
for (Calendar uneDate : lesDates) {
for (int unePeriode : lesPeriodes) {
@ -64,17 +68,17 @@ public class gardeMySQL {
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"),
while (resultat.next()) {
CaserneMySQL laCaserneMySQL = new CaserneMySQL();
int idCaserne = resultat.getInt("idCaserne");
Caserne laCaserne = laCaserneMySQL.read(idCaserne);
lePompier = new Pompier(laCaserne,
resultat.getInt("id"),
resultat.getString("nom"),
resultat.getString("prenom")
);
resultat.getString("prenom"));
uneDispo = new Gardes(TrmtDate.getCalDate(resultat.getDate("jourGarde")),
resultat.getInt("periode"),
lePompier);
resultat.getInt("periode")
,lePompier);
// Recherche si uneDispo existe dans les Dispos
int indice = lesDispo.indexOf(uneDispo);
if (indice > -1) {
@ -82,6 +86,7 @@ public class gardeMySQL {
laDispoTrouvee.setDisponibilite(resultat.getInt("disponibilite"));
laDispoTrouvee.setIsInBDD(true);
}
}
prepStmt.close();
resultat.close();
@ -92,21 +97,23 @@ public class gardeMySQL {
}
}
/**
* Suppression de la ventilation passé en param
* @param v : ventilation
* @return : nb lignes supprimées
* Suppression de la garde passé en paramètre
*
* @param v ventilation à supprimer
* @return nb ligne a supprimer
*/
public int delete(Gardes v) {
public int delete(Gardes g) {
int nbMaj = -1;
String sql = "DELETE FROM gardes "
+ "WHERE idPompier = ? AND"
+ "periode = ? AND"
+ "jourGarde = ?;";
String sql = "DELETE * FROM gardes "
+ "WHERE idPompiere=?"
+ "AND periode=?"
+ "AND jourGarde= ?;";
try {
PreparedStatement prepStmt = theConnection.prepareStatement(sql);
prepStmt.setInt(1, v.getPompier().getId());
prepStmt.setInt(2, v.getPeriode());
prepStmt.setDate(3, TrmtDate.getSQLDate(v.getJourGarde()));
prepStmt.setInt(1, g.getPompier().getId());
prepStmt.setInt(2, g.getPeriode());
prepStmt.setInt(3, g.getPeriode());
prepStmt.setDate(3, TrmtDate.getSQLDate(g.getJourGarde()));
nbMaj = prepStmt.executeUpdate();
} catch (SQLException ex) {
@ -114,63 +121,73 @@ public class gardeMySQL {
System.out.println("SQLState : " + ex.getSQLState());
System.out.println("Code erreur : " + ex.getErrorCode());
}
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
* @param v : ventil à créer
* @return : id du ventil
* 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 v) {
int nbCre = -1;
String sql = "INSERT INTO gardes "
+ "(jourGarde, periode, idPompier, ventil)"
+ "VALUES (?, ?, ?, ?);";
public int create(Gardes g) {
int idCree = -1;
String sql = "INSERT into gardes "
+ "(jourGarde, periode, idPompier, disponibilite) "
+ "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());
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()) {
nbCre = result.getInt(1);
}
}
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 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;
import bdd.gardeMySQL;
import bdd.GardeMySQL;
import bean.Gardes;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
@ -23,7 +24,7 @@ public class DispoForm {
HttpSession maS = request.getSession();
ArrayList <Gardes> lesG = (ArrayList<Gardes>) maS.getAttribute("lesVentilInit");
gardeMySQL vm = new gardeMySQL();
GardeMySQL vm = new GardeMySQL();
Map<String, String[]> map = request.getParameterMap();
String[] lesNvVentil = map.get("lesAct");
int i = 0;

View File

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

View File

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

View File

@ -3,20 +3,9 @@
Created on : 6 déc. 2021, 15:07:45
Author : funcha.ahamadi
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<legend>
Feuille de gardes
</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>
<%@include file= "jspf/debutJSP.jspf" %>
<body>
</tr>
<tr>
@ -59,4 +48,35 @@
</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>
<!-- fin tab disp -->
<div class="danger mt-3">${message} </div>

View File

@ -90,19 +90,15 @@
</c:choose>
</li>
<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>
</ul>
</div>