Merge origin/master
Conflicts: src/java/bdd/PompierMySql.java src/java/com/test/servlets/authentifServlet.java web/WEB-INF/CreaPompier.jsp
This commit is contained in:
		
							
								
								
									
										199
									
								
								src/java/bdd/GardeMySQL.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										199
									
								
								src/java/bdd/GardeMySQL.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,199 @@
 | 
			
		||||
/*
 | 
			
		||||
 * To change this license header, choose License Headers in Project Properties.
 | 
			
		||||
 * To change this template file, choose Tools | Templates
 | 
			
		||||
 * and open the template in the editor.
 | 
			
		||||
 */
 | 
			
		||||
package bdd;
 | 
			
		||||
 | 
			
		||||
import bean.Caserne;
 | 
			
		||||
import bean.Gardes;
 | 
			
		||||
import bean.Pompier;
 | 
			
		||||
import com.sdis29a.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;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 *
 | 
			
		||||
 * @author funcha.ahamadi
 | 
			
		||||
 */
 | 
			
		||||
public class GardeMySQL {
 | 
			
		||||
    private final Connection theConnection = Connexion.getConnect("localhost",
 | 
			
		||||
            "sdis29",
 | 
			
		||||
            "adminBDsdis",
 | 
			
		||||
            "mdpBDsdis");
 | 
			
		||||
      public ArrayList<Gardes> getLesDisponibilite(Calendar[] lesDates, int[] lesPeriodes) {
 | 
			
		||||
        ArrayList<Gardes> lesDispo = new ArrayList<>();
 | 
			
		||||
        Gardes uneDispo;
 | 
			
		||||
 | 
			
		||||
        /* a. Initialisation de la collection lesVentil pour la période, 
 | 
			
		||||
            création d'une ventil par salarié, par date et période 
 | 
			
		||||
         */
 | 
			
		||||
        int indiceDateFin = lesDates.length - 1;
 | 
			
		||||
        Pompier lePompier;
 | 
			
		||||
        PompierMySQL pm = new PompierMySQL();
 | 
			
		||||
        
 | 
			
		||||
        ArrayList<Pompier> lesPompiers = new ArrayList<>();
 | 
			
		||||
        for (Pompier unPompier : lesPompiers) {
 | 
			
		||||
            for (Calendar uneDate : lesDates) {
 | 
			
		||||
                for (int unePeriode : lesPeriodes) {
 | 
			
		||||
                    uneDispo = new Gardes(uneDate, unePeriode, unPompier);
 | 
			
		||||
                    lesDispo.add(uneDispo);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* b) Maj de la collection lesVentil        
 | 
			
		||||
         */
 | 
			
		||||
       readAll(lesDispo, lesDates[0], lesDates[indiceDateFin]);
 | 
			
		||||
        //System.out.println("lesDispo : " + lesDispo);
 | 
			
		||||
        return lesDispo;
 | 
			
		||||
    }
 | 
			
		||||
        public void readAll(ArrayList<Gardes> lesDispo, Calendar d1, Calendar d2) {
 | 
			
		||||
        Pompier lePompier;
 | 
			
		||||
        Gardes uneDispo;
 | 
			
		||||
        Gardes laDispoTrouvee;
 | 
			
		||||
        String sql = "SELECT * FROM gardes "
 | 
			
		||||
                + "INNER JOIN pompier on idPompier = id "
 | 
			
		||||
                + "WHERE jourGarde BETWEEN ? and ?;";
 | 
			
		||||
        try {
 | 
			
		||||
            PreparedStatement prepStmt = theConnection.prepareStatement(sql);
 | 
			
		||||
            prepStmt.setDate(1, TrmtDate.getSQLDate(d1));
 | 
			
		||||
            prepStmt.setDate(2, TrmtDate.getSQLDate(d2));
 | 
			
		||||
            ResultSet resultat = prepStmt.executeQuery();
 | 
			
		||||
            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"));
 | 
			
		||||
                uneDispo = new Gardes(TrmtDate.getCalDate(resultat.getDate("jourGarde")),
 | 
			
		||||
                        resultat.getInt("periode")
 | 
			
		||||
                        ,lePompier);
 | 
			
		||||
                // Recherche si uneDispo existe dans les Dispos
 | 
			
		||||
                int indice = lesDispo.indexOf(uneDispo);
 | 
			
		||||
                if (indice > -1) {
 | 
			
		||||
                    laDispoTrouvee = lesDispo.get(indice);
 | 
			
		||||
                    laDispoTrouvee.setDisponibilite(resultat.getInt("disponibilite"));
 | 
			
		||||
                    laDispoTrouvee.setIsInBDD(true);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
            prepStmt.close();
 | 
			
		||||
            resultat.close();
 | 
			
		||||
        } catch (SQLException ex) {
 | 
			
		||||
            System.out.println("SQLExeption : " + ex.getMessage());
 | 
			
		||||
            System.out.println("SQLState : " + ex.getSQLState());
 | 
			
		||||
            System.out.println("Code erreur : " + ex.getErrorCode());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
            /**
 | 
			
		||||
     * Suppression de la garde passé en paramètre
 | 
			
		||||
     *
 | 
			
		||||
     * @param v ventilation à supprimer
 | 
			
		||||
     * @return nb ligne a supprimer
 | 
			
		||||
     */
 | 
			
		||||
    public int delete(Gardes g) {
 | 
			
		||||
        int nbMaj = -1;
 | 
			
		||||
        String sql = "DELETE * FROM gardes "
 | 
			
		||||
                + "WHERE idPompiere=?"
 | 
			
		||||
                + "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) {
 | 
			
		||||
            System.out.println("SQLExeption : " + ex.getMessage());
 | 
			
		||||
            System.out.println("SQLState : " + ex.getSQLState());
 | 
			
		||||
            System.out.println("Code erreur : " + ex.getErrorCode());
 | 
			
		||||
        }
 | 
			
		||||
        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 (?, ?, ?,?)";
 | 
			
		||||
 | 
			
		||||
        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 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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
      
 | 
			
		||||
      
 | 
			
		||||
      
 | 
			
		||||
      
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,98 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * To change this license header, choose License Headers in Project Properties.
 | 
			
		||||
 * To change this template file, choose Tools | Templates
 | 
			
		||||
 * and open the template in the editor.
 | 
			
		||||
 */
 | 
			
		||||
package bdd;
 | 
			
		||||
 | 
			
		||||
import bean.Gardes;
 | 
			
		||||
import bean.Pompier;
 | 
			
		||||
import com.sdis29a.util.TrmtDate;
 | 
			
		||||
import java.sql.Connection;
 | 
			
		||||
import java.sql.PreparedStatement;
 | 
			
		||||
import java.sql.ResultSet;
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Calendar;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 *
 | 
			
		||||
 * @author funcha.ahamadi
 | 
			
		||||
 */
 | 
			
		||||
public class gardeMySQL {
 | 
			
		||||
    private final Connection theConnection = Connexion.getConnect("localhost",
 | 
			
		||||
            "sdis29",
 | 
			
		||||
            "adminBDsdis",
 | 
			
		||||
            "mdpBDsdis");
 | 
			
		||||
      public ArrayList<Gardes> getLesDisponibilite(Calendar[] lesDates, int[] lesPeriodes) {
 | 
			
		||||
        ArrayList<Gardes> lesDispo = new ArrayList<>();
 | 
			
		||||
        Gardes uneDispo;
 | 
			
		||||
 | 
			
		||||
        /* a. Initialisation de la collection lesVentil pour la période, 
 | 
			
		||||
            création d'une ventil par salarié, par date et période 
 | 
			
		||||
         */
 | 
			
		||||
        int indiceDateFin = lesDates.length - 1;
 | 
			
		||||
        Pompier lePompier;
 | 
			
		||||
        PompierMySQL pm = new PompierMySQL();
 | 
			
		||||
        ArrayList<Pompier> lesPompiers = pm.readLesPompiersCaserne(idCaserne);
 | 
			
		||||
        for (Pompier unPompier : lesPompiers) {
 | 
			
		||||
            for (Calendar uneDate : lesDates) {
 | 
			
		||||
                for (int unePeriode : lesPeriodes) {
 | 
			
		||||
                    uneDispo = new Gardes(uneDate, unePeriode, unPompier);
 | 
			
		||||
                    lesDispo.add(uneDispo);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* b) Maj de la collection lesVentil        
 | 
			
		||||
         */
 | 
			
		||||
       readAll(lesDispo, lesDates[0], lesDates[indiceDateFin]);
 | 
			
		||||
        //System.out.println("lesDispo : " + lesDispo);
 | 
			
		||||
        return lesDispo;
 | 
			
		||||
    }
 | 
			
		||||
        public void readAll(ArrayList<Gardes> lesDispo, Calendar d1, Calendar d2) {
 | 
			
		||||
        Pompier lePompier;
 | 
			
		||||
        Gardes uneDispo;
 | 
			
		||||
        Gardes laDispoTrouvee;
 | 
			
		||||
        String sql = "SELECT * FROM gardes "
 | 
			
		||||
                + "INNER JOIN pompier on idPompier = id "
 | 
			
		||||
                + "WHERE jourGarde BETWEEN ? and ?;";
 | 
			
		||||
        try {
 | 
			
		||||
            PreparedStatement prepStmt = theConnection.prepareStatement(sql);
 | 
			
		||||
            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"),
 | 
			
		||||
                        resultat.getString("nom"),
 | 
			
		||||
                        resultat.getString("prenom");
 | 
			
		||||
                uneDispo = new Gardes(TrmtDate.getCalDate(resultat.getDate("jourGarde")),
 | 
			
		||||
                        resultat.getInt("periode")
 | 
			
		||||
                        ,lePompier);
 | 
			
		||||
                // Recherche si uneDispo existe dans les Dispos
 | 
			
		||||
                int indice = lesDispo.indexOf(uneDispo);
 | 
			
		||||
                if (indice > -1) {
 | 
			
		||||
                    laDispoTrouvee = lesDispo.get(indice);
 | 
			
		||||
                    laDispoTrouvee.setActivite(resultat.getInt("disponibilite"));
 | 
			
		||||
                    laDispoTrouvee.setIsInDB(true);
 | 
			
		||||
                }
 | 
			
		||||
            
 | 
			
		||||
            prepStmt.close();
 | 
			
		||||
            resultat.close();
 | 
			
		||||
        } catch (SQLException ex) {
 | 
			
		||||
            System.out.println("SQLExeption : " + ex.getMessage());
 | 
			
		||||
            System.out.println("SQLState : " + ex.getSQLState());
 | 
			
		||||
            System.out.println("Code erreur : " + ex.getErrorCode());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
      
 | 
			
		||||
      
 | 
			
		||||
      
 | 
			
		||||
      
 | 
			
		||||
      
 | 
			
		||||
      
 | 
			
		||||
      
 | 
			
		||||
      
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -13,11 +13,11 @@ import java.util.Objects;
 | 
			
		||||
 * @author funcha.ahamadi
 | 
			
		||||
 */
 | 
			
		||||
public class Gardes {
 | 
			
		||||
    private Calendar jourGarde;
 | 
			
		||||
    private int periode;
 | 
			
		||||
    private Pompier pompier;
 | 
			
		||||
    private int disponibilite;
 | 
			
		||||
    private boolean isInBDD;
 | 
			
		||||
    public Calendar jourGarde;
 | 
			
		||||
    public int periode;
 | 
			
		||||
    public Pompier pompier;
 | 
			
		||||
    public int disponibilite;
 | 
			
		||||
    public boolean isInBDD;
 | 
			
		||||
 | 
			
		||||
    public Gardes(Calendar jourGarde, int periode, Pompier pompier, int disponibilite, boolean isInBDD) {
 | 
			
		||||
        this.jourGarde = jourGarde;
 | 
			
		||||
 
 | 
			
		||||
@@ -81,7 +81,7 @@ public class GardesServlet extends HttpServlet {
 | 
			
		||||
 | 
			
		||||
        
 | 
			
		||||
         /* Affichage de la page de ventilation */
 | 
			
		||||
        getServletContext().getRequestDispatcher("/WEB-INF/ventilJSP.jsp").forward(request, response);
 | 
			
		||||
        getServletContext().getRequestDispatcher("/WEB-INF/feuilleGardes.jsp").forward(request, response);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -89,6 +89,21 @@
 | 
			
		||||
                               
 | 
			
		||||
                            </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>                            
 | 
			
		||||
                        </li>
 | 
			
		||||
 | 
			
		||||
                    </ul>
 | 
			
		||||
 | 
			
		||||
                </div>    
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user