From ad612c663c8b77153407d71a79b9d7ef1c5ce3f4 Mon Sep 17 00:00:00 2001
From: "clementine.desrucques" <clementine.desrucques@sio211-11.sio.lan>
Date: Wed, 15 Dec 2021 10:39:48 +0100
Subject: [PATCH] Merge origin/master

Conflicts:
	web/WEB-INF/feuilleGardes.jsp
	web/css/mycss.css
---
 src/java/bdd/GardeMySQL.java  | 38 +++++++++++++++++++----------------
 src/java/bean/Gardes.java     | 33 ++++++++++++++++++++++--------
 src/java/form/DispoForm.java  | 20 ++++++++++--------
 web/WEB-INF/feuilleGardes.jsp |  2 ++
 4 files changed, 60 insertions(+), 33 deletions(-)

diff --git a/src/java/bdd/GardeMySQL.java b/src/java/bdd/GardeMySQL.java
index 43afbbc..7a92759 100644
--- a/src/java/bdd/GardeMySQL.java
+++ b/src/java/bdd/GardeMySQL.java
@@ -61,8 +61,10 @@ public class GardeMySQL {
         /* b) Maj de la collection lesVentil        
          */
        readAll(lesDispo, lesDates[0], lesDates[indiceDateFin]);
-        //System.out.println("lesDispo : " + lesDispo);
+        System.out.println("lesDispo : " + lesDispo);
+        
         return lesDispo;
+        
     }
         public void readAll(ArrayList<Gardes> lesDispo, Calendar d1, Calendar d2) {
         Pompier lePompier;
@@ -107,21 +109,21 @@ public class GardeMySQL {
             /**
      * Suppression de la garde passé en paramètre
      *
-     * @param v ventilation à supprimer
+     * @param g ventilation à supprimer
      * @return nb ligne a supprimer
      */
     public int delete(Gardes g) {
         int nbMaj = -1;
-        String sql = "DELETE * FROM gardes "
+        String sql = "DELETE FROM gardes "
                 + "WHERE idPompier=?"
-                + "AND periode=?"
-                + "AND jourGarde= ?;";
+                + " AND periode=?"
+                + " AND jourGarde= ?;";
         try {
             PreparedStatement prepStmt = theConnection.prepareStatement(sql);
             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) {
@@ -140,16 +142,18 @@ public class GardeMySQL {
         int idCree = -1;
         String sql = "INSERT into gardes "
                 + "(jourGarde, periode, idPompier, disponibilite, deGarde) "
-                + "VALUES (?, ?, ?,?,?)";
+                + "VALUES (?, ?, ?,?,?);";
 
         try {
-            PreparedStatement prepStmt = null;
-            prepStmt = theConnection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
+//            PreparedStatement prepStmt = null;
+//            prepStmt = theConnection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
+            PreparedStatement prepStmt = theConnection.prepareStatement(sql);
             prepStmt.setDate(1, TrmtDate.getSQLDate(g.getJourGarde()));
             prepStmt.setInt(2, g.getPeriode());
             prepStmt.setInt(3, g.getPompier().getId());
             prepStmt.setInt(4, g.getDisponibilite());
-
+            prepStmt.setBoolean(5, g.isDeGarde());
+            
             System.out.println(prepStmt);
             int nbLigne = prepStmt.executeUpdate();
 
@@ -180,18 +184,18 @@ public class GardeMySQL {
 
         int nbMAJ = -1;
         String sql = "UPDATE gardes "
-                + "SET disponibilite = ? "
+                + "SET disponibilite = ?, deGarde = ? "
                 + "WHERE idPompier = ? "
                 + "AND jourGarde = ? "
-                + "AND periode = ?"
-                + "AND deGarde = ?"
-                ;
+                + "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());
+            prepStmt.setBoolean(2, g.isDeGarde());
+            prepStmt.setInt(3, g.getPompier().getId());
+            prepStmt.setDate(4, TrmtDate.getSQLDate(g.getJourGarde()));
+            prepStmt.setInt(5, g.getPeriode());
+            
             System.out.println("update : " + prepStmt);
             nbMAJ = prepStmt.executeUpdate();
         } catch (SQLException ex) {
diff --git a/src/java/bean/Gardes.java b/src/java/bean/Gardes.java
index f2c3d9d..41eca71 100644
--- a/src/java/bean/Gardes.java
+++ b/src/java/bean/Gardes.java
@@ -18,13 +18,15 @@ public class Gardes {
     Pompier pompier;
     int disponibilite;
     boolean isInBDD;
+    boolean deGarde;
 
-    public Gardes(Calendar jourGarde, int periode, Pompier pompier, int disponibilite, boolean isInBDD) {
+    public Gardes(Calendar jourGarde, int periode, Pompier pompier, int disponibilite, boolean isInBDD, boolean deGarde) {
         this.jourGarde = jourGarde;
         this.periode = periode;
         this.pompier = pompier;
         this.disponibilite = disponibilite;
         this.isInBDD = isInBDD;
+        this.deGarde = deGarde;
     }
 
     public Gardes(Calendar jourGarde, int periode, Pompier pompier) {
@@ -32,7 +34,9 @@ public class Gardes {
         this.periode = periode;
         this.pompier = pompier;
     }
+    
 
+    
     public Calendar getJourGarde() {
         return jourGarde;
     }
@@ -73,14 +77,23 @@ public class Gardes {
         this.isInBDD = isInBDD;
     }
 
+    public boolean isDeGarde() {
+        return deGarde;
+    }
+
+    public void setDeGarde(boolean deGarde) {
+        this.deGarde = deGarde;
+    }
+
     @Override
     public int hashCode() {
-        int hash = 7;
-        hash = 43 * hash + Objects.hashCode(this.jourGarde);
-        hash = 43 * hash + this.periode;
-        hash = 43 * hash + Objects.hashCode(this.pompier);
-        hash = 43 * hash + this.disponibilite;
-        hash = 43 * hash + (this.isInBDD ? 1 : 0);
+        int hash = 5;
+        hash = 37 * hash + Objects.hashCode(this.jourGarde);
+        hash = 37 * hash + this.periode;
+        hash = 37 * hash + Objects.hashCode(this.pompier);
+        hash = 37 * hash + this.disponibilite;
+        hash = 37 * hash + (this.isInBDD ? 1 : 0);
+        hash = 37 * hash + (this.deGarde ? 1 : 0);
         return hash;
     }
 
@@ -105,6 +118,9 @@ public class Gardes {
         if (this.isInBDD != other.isInBDD) {
             return false;
         }
+        if (this.deGarde != other.deGarde) {
+            return false;
+        }
         if (!Objects.equals(this.jourGarde, other.jourGarde)) {
             return false;
         }
@@ -116,8 +132,9 @@ public class Gardes {
 
     @Override
     public String toString() {
-        return "Gardes{" + "jourGarde=" + jourGarde + ", periode=" + periode + ", pompier=" + pompier + ", disponibilite=" + disponibilite + ", isInBDD=" + isInBDD + '}';
+        return "\nGardes{" + "jourGarde=" + jourGarde.getTime() + ", periode=" + periode + ", pompier=" + pompier + ", disponibilite=" + disponibilite + ", isInBDD=" + isInBDD + ", deGarde=" + deGarde + '}';
     }
+
     
     
 }
diff --git a/src/java/form/DispoForm.java b/src/java/form/DispoForm.java
index cd68265..ae66fab 100644
--- a/src/java/form/DispoForm.java
+++ b/src/java/form/DispoForm.java
@@ -18,24 +18,27 @@ import java.util.Map;
  * @author clementine.desrucques
  */
 public class DispoForm {
+
     HttpServletRequest request;
-    
-    public void verifDispo(HttpServletRequest request){
+
+    public void verifDispo(HttpServletRequest request) {
         HttpSession maS = request.getSession();
-        ArrayList <Gardes> lesG = (ArrayList<Gardes>) maS.getAttribute("lesVentilInit");
-        
+        ArrayList<Gardes> lesG = (ArrayList<Gardes>) maS.getAttribute("lesVentilInit");
+
         GardeMySQL vm = new GardeMySQL();
         Map<String, String[]> map = request.getParameterMap();
         String[] lesNvVentil = map.get("lesActivites");
         int i = 0;
-        for(Gardes uneGarde : lesG){
+        for (Gardes uneGarde : lesG) {
             int oldAct = uneGarde.getDisponibilite();
             int newAct = Integer.parseInt(lesNvVentil[i]);
-            if(oldAct != newAct){
-                if(uneGarde.isIsInBDD()){
-                    if(newAct == 0){
+            if (oldAct != newAct) {
+                if (uneGarde.isIsInBDD()) {
+
+                    if (newAct == 0) {
                         vm.delete(uneGarde);
                         uneGarde.setIsInBDD(false);
+                        uneGarde.setDisponibilite(newAct);
                     } else {
                         uneGarde.setDisponibilite(newAct);
                         vm.update(uneGarde);
@@ -45,6 +48,7 @@ public class DispoForm {
                     vm.create(uneGarde);
                     uneGarde.setIsInBDD(true);
                 }
+
             }
             i++;
         }
diff --git a/web/WEB-INF/feuilleGardes.jsp b/web/WEB-INF/feuilleGardes.jsp
index 1ce51d3..5d8da88 100644
--- a/web/WEB-INF/feuilleGardes.jsp
+++ b/web/WEB-INF/feuilleGardes.jsp
@@ -55,6 +55,8 @@
                         <c:set var="activite" value='${uneVentil.getDisponibilite()}' scope="page"/>
                         <td>
                             <input readonly type="text" value='${activite}' name="lesActivites"class="ztVentil ${sessionScope.lesCouleurs[activite]}"/>
+                            <input type="checkbox" id="cbGarde"/>
+                           
                         </td>
                     </c:forEach>
                 </tr>