Merge origin/master
Conflicts: src/java/bdd/gardeMySQL.java src/java/servlet/PompierServlet.java web/WEB-INF/feuilleGardes.jsp
This commit is contained in:
commit
b4da29af06
@ -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();
|
||||
@ -91,93 +96,105 @@ public class gardeMySQL {
|
||||
System.out.println("Code erreur : " + ex.getErrorCode());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 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()));
|
||||
nbMaj= prepStmt.executeUpdate();
|
||||
|
||||
} catch (SQLException ex) {
|
||||
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) {
|
||||
System.out.println("SQLExeption : " + ex.getMessage());
|
||||
System.out.println("SQLState : " + ex.getSQLState());
|
||||
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;
|
||||
String sql = "UPDATE gardes "
|
||||
+ "SET ventil = ? "
|
||||
+ "WHERE idPompier= ? "
|
||||
String sql = "UPDATE garde "
|
||||
+ "SET disponibilite = ? "
|
||||
+ "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());
|
||||
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);
|
||||
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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class PompierServlet extends HttpServlet {
|
||||
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
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. */
|
||||
out.println("<!DOCTYPE html>");
|
||||
out.println("<html>");
|
||||
@ -74,7 +74,7 @@ public class PompierServlet extends HttpServlet {
|
||||
boolean isNumeric = StringUtils.isStrictlyNumeric(pageEnString);
|
||||
if (isNumeric) {
|
||||
pageDemandee = Integer.parseInt(pageEnString);
|
||||
if (pageDemandee != 2 && pageDemandee != 3 && pageDemandee !=5) { // erreur
|
||||
if (pageDemandee != 2 && pageDemandee != 3 && pageDemandee != 5) { // erreur
|
||||
erreur = true;
|
||||
}
|
||||
} else {
|
||||
@ -101,16 +101,13 @@ 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 {
|
||||
request.setAttribute("page", page);
|
||||
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 le bouton Ajouter du formulaire du choix du pompier (btAfficherPompier = "Ajouter")
|
||||
depuis le bouton de validation de mise à jour d'un pompier (btAfficherPompier = "ValiderMaj")
|
||||
*/
|
||||
*/
|
||||
int erreur = 0;
|
||||
String btValue = null;
|
||||
ArrayList<String> valeursBt = new ArrayList<String>() ;
|
||||
valeursBt.add("Afficher") ;
|
||||
valeursBt.add("Ajouter") ;
|
||||
valeursBt.add("ValiderMaj") ;
|
||||
|
||||
ArrayList<String> valeursBt = new ArrayList<String>();
|
||||
valeursBt.add("Afficher");
|
||||
valeursBt.add("Ajouter");
|
||||
valeursBt.add("ValiderMaj");
|
||||
|
||||
// Test du bouton btAfficherPompier
|
||||
if (request.getParameter("btAfficherPompier")==null) {
|
||||
if (request.getParameter("btAfficherPompier") == null) {
|
||||
erreur = 1;
|
||||
} else {
|
||||
btValue = request.getParameter("btAfficherPompier");
|
||||
@ -152,7 +149,7 @@ public class PompierServlet extends HttpServlet {
|
||||
//response.sendRedirect("/sdis29M1/authentification");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
HttpSession maSession = request.getSession();
|
||||
ArrayList<Pompier> lesPompiers = (ArrayList<Pompier>) maSession.getAttribute("lesPompiers");
|
||||
if (request.getParameter("btAfficherPompier").equals("Afficher")
|
||||
@ -162,12 +159,12 @@ public class PompierServlet extends HttpServlet {
|
||||
maSession.setAttribute("lePompier", lesPompiers.get(noPompier));
|
||||
request.setAttribute("page", 3);
|
||||
}
|
||||
|
||||
|
||||
if (request.getParameter("btAfficherPompier").equals("Ajouter")) {
|
||||
maSession.removeAttribute("lePompier");
|
||||
}
|
||||
|
||||
if (request.getParameter("btAfficherPompier").equals("ValiderMaj")) {
|
||||
|
||||
if (request.getParameter("btAfficherPompier").equals("ValiderMaj")) {
|
||||
PompierForm pf = new PompierForm(request);
|
||||
boolean valid = pf.ctrlPompier();
|
||||
// if (maSession.getAttribute("lePompier")==null) {
|
||||
@ -182,8 +179,8 @@ public class PompierServlet extends HttpServlet {
|
||||
// }
|
||||
// }
|
||||
pf.majBDD();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
getServletContext().getRequestDispatcher("/WEB-INF/pompierJSP.jsp").forward(request, response);
|
||||
}
|
||||
|
||||
|
@ -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>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -175,6 +175,9 @@
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- fin tab disp -->
|
||||
<div class="danger mt-3">${message} </div>
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
${sessionScope.lePompierConnecte.getNom()} (
|
||||
${sessionScope.lePompierConnecte.getLeStatut().getValeur()})
|
||||
</h4>
|
||||
|
||||
|
||||
<button type="button" class="btn btn-warning fs-4" title="Déconnexion">
|
||||
<a href="authentification">
|
||||
<i class="bi bi-box-arrow-right heading" width="32" height="32" fill="currentColor"></i> Déconnexion
|
||||
@ -89,20 +89,16 @@
|
||||
|
||||
</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>
|
||||
<li class="nav-item">
|
||||
|
||||
|
||||
</c:choose>
|
||||
</li>
|
||||
|
||||
<a class="nav-link" href="gardes">Gardes</a>
|
||||
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user