diff options
| author | polo <ordipolo@gmx.fr> | 2026-07-02 00:14:17 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2026-07-02 00:14:17 +0200 |
| commit | 0c2c3ee5a55f36d270171f2f67938542e251fdc5 (patch) | |
| tree | 8ea4d6a7ad09a5b1389b829980a7a5476982e754 /src/main/java/controlleur | |
| download | ppe_javafx-0c2c3ee5a55f36d270171f2f67938542e251fdc5.tar.gz ppe_javafx-0c2c3ee5a55f36d270171f2f67938542e251fdc5.tar.bz2 ppe_javafx-0c2c3ee5a55f36d270171f2f67938542e251fdc5.zip | |
fork utilisant maven
Diffstat (limited to 'src/main/java/controlleur')
| -rw-r--r-- | src/main/java/controlleur/BDD.java | 322 | ||||
| -rw-r--r-- | src/main/java/controlleur/Connexion.java | 65 | ||||
| -rw-r--r-- | src/main/java/controlleur/ControllerAdmin.java | 119 | ||||
| -rw-r--r-- | src/main/java/controlleur/ControllerTopMenu.java | 58 | ||||
| -rw-r--r-- | src/main/java/controlleur/ControlleurSimu.java | 218 | ||||
| -rw-r--r-- | src/main/java/controlleur/CreationCompte.java | 38 | ||||
| -rw-r--r-- | src/main/java/controlleur/EvenementController.java | 267 | ||||
| -rw-r--r-- | src/main/java/controlleur/GestionListe.java | 82 | ||||
| -rw-r--r-- | src/main/java/controlleur/Instanciation.java | 304 | ||||
| -rw-r--r-- | src/main/java/controlleur/ModificationListe.java | 214 | ||||
| -rw-r--r-- | src/main/java/controlleur/StockageCreerListe.java | 75 | ||||
| -rw-r--r-- | src/main/java/controlleur/SupprListe.java | 27 |
12 files changed, 1789 insertions, 0 deletions
diff --git a/src/main/java/controlleur/BDD.java b/src/main/java/controlleur/BDD.java new file mode 100644 index 0000000..af1a754 --- /dev/null +++ b/src/main/java/controlleur/BDD.java | |||
| @@ -0,0 +1,322 @@ | |||
| 1 | package controlleur; | ||
| 2 | |||
| 3 | import java.sql.Connection; | ||
| 4 | import java.sql.Date; | ||
| 5 | import java.sql.DriverManager; | ||
| 6 | import java.sql.PreparedStatement; | ||
| 7 | import java.sql.ResultSet; | ||
| 8 | import java.sql.ResultSetMetaData; | ||
| 9 | import java.sql.SQLException; | ||
| 10 | import java.sql.Statement; | ||
| 11 | import java.util.ArrayList; | ||
| 12 | import java.util.List; | ||
| 13 | |||
| 14 | import javafx.scene.layout.VBox; | ||
| 15 | import modele.Arme; | ||
| 16 | import modele.ArmeeListe; | ||
| 17 | import modele.Evenement; | ||
| 18 | import modele.Unit; | ||
| 19 | import modele.User; | ||
| 20 | |||
| 21 | public class BDD { | ||
| 22 | |||
| 23 | private Connection connec; | ||
| 24 | private PreparedStatement stat = null; | ||
| 25 | private ResultSet rs ; | ||
| 26 | |||
| 27 | private static String user; | ||
| 28 | private static String password; | ||
| 29 | private static String dbname; | ||
| 30 | |||
| 31 | public BDD() { | ||
| 32 | try { | ||
| 33 | //Class.forName("com.mysql.cj.jdbc.Driver"); | ||
| 34 | Class.forName("org.mariadb.jdbc.Driver"); | ||
| 35 | //String host = "mysql-stathammer.alwaysdata.net"; | ||
| 36 | String host = "localhost"; | ||
| 37 | //this.connec = DriverManager.getConnection("jdbc:mysql://" + host + ":3306/"+ dbname, user, password); | ||
| 38 | this.connec = DriverManager.getConnection("jdbc:mariadb://" + host + ":3306/"+ dbname, user, password); | ||
| 39 | this.rs = connec.prepareStatement("SELECT * FROM faction;").executeQuery(); | ||
| 40 | } catch (ClassNotFoundException e) { | ||
| 41 | // TODO: handle exception | ||
| 42 | |||
| 43 | e.printStackTrace(); | ||
| 44 | } catch (SQLException e) { | ||
| 45 | System.err.println(e.getMessage()); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | public static void setInfos(String login, String pwd, String base) | ||
| 50 | { | ||
| 51 | user = login; | ||
| 52 | password = pwd; | ||
| 53 | dbname = base; | ||
| 54 | } | ||
| 55 | |||
| 56 | public Statement getStatement() throws SQLException | ||
| 57 | { | ||
| 58 | return connec.createStatement(); | ||
| 59 | } | ||
| 60 | |||
| 61 | public PreparedStatement getPreparedStatement(String sql, Object... params) throws SQLException | ||
| 62 | { | ||
| 63 | stat = connec.prepareStatement(sql); | ||
| 64 | if(params.length > 0) | ||
| 65 | { | ||
| 66 | for (int i = 0; i < params.length; i++) { | ||
| 67 | stat.setObject(i + 1, params[i]); | ||
| 68 | } | ||
| 69 | } | ||
| 70 | return stat; | ||
| 71 | } | ||
| 72 | |||
| 73 | public ArrayList<Object> selectUtilisateur(String nom, String mdp) { | ||
| 74 | ArrayList<Object> rendu = new ArrayList<Object>(); | ||
| 75 | try { | ||
| 76 | |||
| 77 | String requete = "SELECT id_utilisateur, nom_utilisateur, role_utilisateur FROM utilisateur WHERE nom_utilisateur=? AND mdp_utilisateur = ?;"; | ||
| 78 | stat = connec.prepareStatement(requete); | ||
| 79 | stat.setString(1, nom); | ||
| 80 | stat.setString(2,String.valueOf(mdp)); | ||
| 81 | //stat.setString(2,String.valueOf(mdp.hashCode())); | ||
| 82 | |||
| 83 | ResultSet rs = stat.executeQuery(); | ||
| 84 | ResultSetMetaData md = rs.getMetaData(); | ||
| 85 | ArrayList<String> column = new ArrayList<String>(); | ||
| 86 | |||
| 87 | for (int i = 1; i <= md.getColumnCount(); i++) { | ||
| 88 | column.add(md.getColumnName(i)); | ||
| 89 | } | ||
| 90 | while (rs.next()) { | ||
| 91 | rendu.add(rs.getString("nom_utilisateur")); | ||
| 92 | rendu.add(rs.getInt("id_utilisateur")); | ||
| 93 | rendu.add(rs.getString("role_utilisateur")); | ||
| 94 | } | ||
| 95 | return rendu; | ||
| 96 | |||
| 97 | } catch (SQLException e) { | ||
| 98 | // TODO: handle exception | ||
| 99 | System.err.println(e.getMessage()); | ||
| 100 | |||
| 101 | } | ||
| 102 | return rendu; | ||
| 103 | } | ||
| 104 | |||
| 105 | public ArrayList<String> creerUtilisateur(String adresse, String nom, String mdp) { | ||
| 106 | ArrayList<String> crea = new ArrayList<String>(); | ||
| 107 | |||
| 108 | String creationRequete = "INSERT INTO utilisateur" + " (nom_utilisateur, email_utilisateur, mdp_utilisateur)" | ||
| 109 | + "VALUES (?, ?, ?);"; | ||
| 110 | try { | ||
| 111 | if (connec == null || connec.isClosed()) { | ||
| 112 | System.err.println("La connexion à la bdd n'est pas possible."); | ||
| 113 | return crea; | ||
| 114 | } | ||
| 115 | PreparedStatement stat = connec.prepareStatement(creationRequete); | ||
| 116 | stat.setString(1, nom); | ||
| 117 | stat.setString(2, adresse); | ||
| 118 | stat.setString(3, mdp); | ||
| 119 | |||
| 120 | int rowsInserted = stat.executeUpdate(); | ||
| 121 | |||
| 122 | if (rowsInserted > 0) { | ||
| 123 | crea.add(adresse); | ||
| 124 | } | ||
| 125 | stat.close(); | ||
| 126 | } catch (SQLException e) { | ||
| 127 | System.err.println("Erreur SQL : " + e.getMessage()); | ||
| 128 | } | ||
| 129 | return crea; | ||
| 130 | } | ||
| 131 | |||
| 132 | public Connection getConnection() { | ||
| 133 | return this.connec; | ||
| 134 | } | ||
| 135 | |||
| 136 | public void close() { | ||
| 137 | try { | ||
| 138 | connec.close(); | ||
| 139 | } catch (SQLException e) { | ||
| 140 | // TODO Auto-generated catch block | ||
| 141 | e.printStackTrace(); | ||
| 142 | } | ||
| 143 | } | ||
| 144 | |||
| 145 | public ArrayList<String> select(String requete,String... param ) throws SQLException{ | ||
| 146 | ArrayList<String> rendu = new ArrayList<String>(); | ||
| 147 | try { | ||
| 148 | PreparedStatement pstat = null; | ||
| 149 | |||
| 150 | pstat = connec.prepareStatement(requete); | ||
| 151 | if(param.length>0) { | ||
| 152 | for(int i = 1;i<=param.length;i++) { | ||
| 153 | pstat.setString(i, param[i-1]); | ||
| 154 | } | ||
| 155 | } | ||
| 156 | |||
| 157 | rs.close(); | ||
| 158 | rs = pstat.executeQuery(); | ||
| 159 | ResultSetMetaData md = rs.getMetaData(); | ||
| 160 | ArrayList<String> column = new ArrayList<String>(); | ||
| 161 | |||
| 162 | |||
| 163 | for(int i =1;i<=md.getColumnCount();i++) { | ||
| 164 | column.add(md.getColumnName(i)); | ||
| 165 | } | ||
| 166 | while(rs.next()) { | ||
| 167 | for (String col : column) { | ||
| 168 | rendu.add(rs.getString(col)); | ||
| 169 | } | ||
| 170 | |||
| 171 | |||
| 172 | |||
| 173 | } | ||
| 174 | |||
| 175 | return rendu; | ||
| 176 | |||
| 177 | } catch (SQLException e) { | ||
| 178 | // TODO: handle exception | ||
| 179 | System.err.println(e.getMessage()); | ||
| 180 | |||
| 181 | |||
| 182 | } | ||
| 183 | return rendu; | ||
| 184 | } | ||
| 185 | |||
| 186 | public void updateUtilisateur(String pseudo,int id) { | ||
| 187 | try { | ||
| 188 | stat = this.getPreparedStatement("UPDATE `utilisateur` SET nom_utilisateur=? WHERE id_utilisateur=?;",pseudo,id); | ||
| 189 | stat.executeUpdate(); | ||
| 190 | |||
| 191 | } catch (SQLException e) { | ||
| 192 | // TODO: handle exception | ||
| 193 | System.err.println(e.getMessage()); | ||
| 194 | } | ||
| 195 | } | ||
| 196 | public void insertListe(ArmeeListe armee,User session) { | ||
| 197 | try { | ||
| 198 | int id; | ||
| 199 | ArrayList<String> rendu = new ArrayList<String>(); | ||
| 200 | String requete = "INSERT INTO liste VALUES(DEFAULT,?,?,?,?);"; | ||
| 201 | stat = this.getPreparedStatement(requete); | ||
| 202 | stat.setString(1, armee.getName()); | ||
| 203 | stat.setString(2, armee.getDescription()); | ||
| 204 | stat.setString(3, armee.getData()); | ||
| 205 | stat.setInt(4, session.getId()); | ||
| 206 | stat.executeUpdate(); | ||
| 207 | |||
| 208 | requete = "SELECT id_liste FROM liste WHERE nom_liste = ?;"; | ||
| 209 | |||
| 210 | rendu = this.select(requete,armee.getName()); | ||
| 211 | |||
| 212 | id = Integer.parseInt(rendu.getFirst()); | ||
| 213 | requete = "INSERT INTO contenir VALUES(?,?);"; | ||
| 214 | |||
| 215 | for(Unit unit : armee.getUnits()) { | ||
| 216 | |||
| 217 | |||
| 218 | stat = this.getPreparedStatement(requete); | ||
| 219 | stat.setInt(1, unit.getId()); | ||
| 220 | stat.setInt(2, id); | ||
| 221 | stat.executeUpdate(); | ||
| 222 | } | ||
| 223 | |||
| 224 | } catch (SQLException e) { | ||
| 225 | // TODO: handle exception | ||
| 226 | } | ||
| 227 | } | ||
| 228 | |||
| 229 | |||
| 230 | public void updateMp(String mdp,int id) { | ||
| 231 | try { | ||
| 232 | //stat = this.getPreparedStatement("UPDATE `utilisateur` SET mdp_utilisateur=? WHERE id_utilisateur=?;",mdp.hashCode(),id); | ||
| 233 | stat = this.getPreparedStatement("UPDATE `utilisateur` SET mdp_utilisateur=? WHERE id_utilisateur=?;",mdp.hashCode(),id); | ||
| 234 | stat.executeUpdate(); | ||
| 235 | |||
| 236 | } catch (SQLException e) { | ||
| 237 | // TODO: handle exception | ||
| 238 | System.err.println(e.getMessage()); | ||
| 239 | } | ||
| 240 | } | ||
| 241 | |||
| 242 | public int UtilisateurID(String nom, String mdp) { | ||
| 243 | try { | ||
| 244 | stat = this.getPreparedStatement("SELECT id_utilisateur FROM utilisateur WHERE nom_utilisateur=? AND mdp_utilisateur = ?;", | ||
| 245 | nom, mdp); | ||
| 246 | |||
| 247 | ResultSet rs = stat.executeQuery(); | ||
| 248 | rs.next(); | ||
| 249 | int id = rs.getInt("id_utilisateur"); | ||
| 250 | |||
| 251 | return id; | ||
| 252 | |||
| 253 | } catch (SQLException e) { | ||
| 254 | // TODO: handle exception | ||
| 255 | System.err.println(e.getMessage()); | ||
| 256 | |||
| 257 | return 0; | ||
| 258 | } | ||
| 259 | } | ||
| 260 | public String UtilisateurRole(String nom, String mdp) { | ||
| 261 | String role = "null"; | ||
| 262 | try { | ||
| 263 | |||
| 264 | stat = this.getPreparedStatement("SELECT role_utilisateur FROM utilisateur WHERE nom_utilisateur=? AND mdp_utilisateur = ?;", | ||
| 265 | nom, mdp); | ||
| 266 | |||
| 267 | ResultSet rs = stat.executeQuery(); | ||
| 268 | rs.next(); | ||
| 269 | role = rs.getString("role_utilisateur"); | ||
| 270 | |||
| 271 | return role; | ||
| 272 | |||
| 273 | } catch (SQLException e) { | ||
| 274 | // TODO: handle exception | ||
| 275 | System.err.println(e.getMessage()); | ||
| 276 | |||
| 277 | |||
| 278 | } | ||
| 279 | return role; | ||
| 280 | } | ||
| 281 | |||
| 282 | public String UtilisateurMdp(int id) { | ||
| 283 | String mdp = "test null"; | ||
| 284 | try { | ||
| 285 | stat = this.getPreparedStatement("SELECT mdp_utilisateur FROM utilisateur WHERE id_utilisateur=?;", | ||
| 286 | id); | ||
| 287 | |||
| 288 | ResultSet rs = stat.executeQuery(); | ||
| 289 | rs.next(); | ||
| 290 | mdp = rs.getString("mdp_utilisateur"); | ||
| 291 | |||
| 292 | return mdp; | ||
| 293 | |||
| 294 | } catch (SQLException e) { | ||
| 295 | // TODO: handle exception | ||
| 296 | System.err.println(e.getMessage()); | ||
| 297 | |||
| 298 | |||
| 299 | } | ||
| 300 | return mdp; | ||
| 301 | } | ||
| 302 | |||
| 303 | |||
| 304 | public void ajouter(Arme a) { | ||
| 305 | try { | ||
| 306 | stat.executeUpdate("INSERT INTO arme (id,prenom,login,password,statut,age) VALUES (NULL,"); | ||
| 307 | } catch (SQLException e) { | ||
| 308 | // TODO Auto-generated catch block | ||
| 309 | e.printStackTrace(); | ||
| 310 | } | ||
| 311 | } | ||
| 312 | |||
| 313 | public void supprimer(Arme a) { | ||
| 314 | try { | ||
| 315 | stat.executeUpdate("DELETE FROM acces WHERE login =''"); | ||
| 316 | } catch (SQLException e) { | ||
| 317 | // TODO Auto-generated catch block | ||
| 318 | e.printStackTrace(); | ||
| 319 | } | ||
| 320 | |||
| 321 | } | ||
| 322 | } | ||
diff --git a/src/main/java/controlleur/Connexion.java b/src/main/java/controlleur/Connexion.java new file mode 100644 index 0000000..f8c6b4f --- /dev/null +++ b/src/main/java/controlleur/Connexion.java | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | package controlleur; | ||
| 2 | |||
| 3 | import java.sql.SQLException; | ||
| 4 | import java.util.ArrayList; | ||
| 5 | |||
| 6 | import javafx.stage.Stage; | ||
| 7 | import modele.Evenement; | ||
| 8 | import modele.User; | ||
| 9 | import vue.AfficheAccueil; | ||
| 10 | import vue.AfficheConnexionFailed; | ||
| 11 | |||
| 12 | public class Connexion { | ||
| 13 | public static EvenementController eventC ; | ||
| 14 | public static Evenement event ; | ||
| 15 | public static void verif(String login, String mdp,Stage primaryStage) { | ||
| 16 | |||
| 17 | login = login.trim(); | ||
| 18 | mdp = Integer.toString(mdp.hashCode()); | ||
| 19 | BDD conec = new BDD(); | ||
| 20 | |||
| 21 | eventC = new EvenementController(); | ||
| 22 | event = new Evenement(eventC.getNom_event().get(0), | ||
| 23 | eventC.getNom_image().get(0), | ||
| 24 | eventC.getDesc_event().get(0), | ||
| 25 | eventC.getDate_event().get(0)); | ||
| 26 | System.out.println(eventC.getNom_image().get(0)); | ||
| 27 | ArrayList<Object> rendu = conec.selectUtilisateur(login, mdp); | ||
| 28 | int id = conec.UtilisateurID(login, mdp); | ||
| 29 | String role = conec.UtilisateurRole(login, mdp); | ||
| 30 | //System.out.println(role); | ||
| 31 | conec.close(); | ||
| 32 | |||
| 33 | try { | ||
| 34 | if (login.equals(rendu.get(0))) { | ||
| 35 | User session = new User(login,id,role); | ||
| 36 | |||
| 37 | //primaryStage.close(); | ||
| 38 | AfficheAccueil.affiche(primaryStage,session); | ||
| 39 | } | ||
| 40 | else { | ||
| 41 | System.out.println(rendu); | ||
| 42 | } | ||
| 43 | } | ||
| 44 | catch(Exception e) { | ||
| 45 | AfficheConnexionFailed.affiche(primaryStage); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | public static void updatePseudo(String pseudo,int id) throws SQLException { | ||
| 50 | BDD conec = new BDD(); | ||
| 51 | conec.updateUtilisateur(pseudo,id); | ||
| 52 | conec.close(); | ||
| 53 | } | ||
| 54 | public static void updateMdp(String mdp,int id) throws SQLException { | ||
| 55 | BDD conec = new BDD(); | ||
| 56 | conec.updateMp(mdp,id); | ||
| 57 | conec.close(); | ||
| 58 | } | ||
| 59 | public static String selectMdp(int id) throws SQLException { | ||
| 60 | BDD conec = new BDD(); | ||
| 61 | String mdp =conec.UtilisateurMdp(id); | ||
| 62 | conec.close(); | ||
| 63 | return mdp; | ||
| 64 | } | ||
| 65 | } \ No newline at end of file | ||
diff --git a/src/main/java/controlleur/ControllerAdmin.java b/src/main/java/controlleur/ControllerAdmin.java new file mode 100644 index 0000000..a12f01c --- /dev/null +++ b/src/main/java/controlleur/ControllerAdmin.java | |||
| @@ -0,0 +1,119 @@ | |||
| 1 | package controlleur; | ||
| 2 | |||
| 3 | import java.io.File; | ||
| 4 | import java.io.IOException; | ||
| 5 | import java.nio.file.Files; | ||
| 6 | import java.sql.PreparedStatement; | ||
| 7 | import java.sql.ResultSet; | ||
| 8 | import java.sql.SQLException; | ||
| 9 | import java.time.LocalDate; | ||
| 10 | import java.util.ArrayList; | ||
| 11 | import java.util.Date; | ||
| 12 | import java.util.List; | ||
| 13 | |||
| 14 | import javafx.geometry.Pos; | ||
| 15 | import javafx.scene.control.Alert; | ||
| 16 | import javafx.scene.control.Button; | ||
| 17 | import javafx.scene.control.Label; | ||
| 18 | import javafx.scene.image.Image; | ||
| 19 | import javafx.scene.image.ImageView; | ||
| 20 | import javafx.scene.layout.HBox; | ||
| 21 | import javafx.scene.layout.VBox; | ||
| 22 | import javafx.scene.text.Text; | ||
| 23 | import javafx.stage.FileChooser; | ||
| 24 | import javafx.stage.Stage; | ||
| 25 | import vue.AfficheAccueil; | ||
| 26 | import vue.AfficheAdmin; | ||
| 27 | import vue.AfficheConnexionFailed; | ||
| 28 | import modele.Evenement; | ||
| 29 | import modele.User; | ||
| 30 | |||
| 31 | public class ControllerAdmin { | ||
| 32 | private static String destinationDir; | ||
| 33 | private static File destinationFile ; | ||
| 34 | private static File file; | ||
| 35 | |||
| 36 | public static void parcourir(Stage primaryStage, ImageView imageView) { | ||
| 37 | FileChooser fileChooser = new FileChooser(); | ||
| 38 | fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Fichiers Images", "*.png", "*.jpg")); | ||
| 39 | |||
| 40 | // Ouvrir le file chooser et obtenir le fichier sélectionné | ||
| 41 | file = fileChooser.showOpenDialog(primaryStage); | ||
| 42 | |||
| 43 | boolean nomFich = true; | ||
| 44 | |||
| 45 | if (file != null) { | ||
| 46 | |||
| 47 | for (int i = 0 ; i < Connexion.eventC.getNbrEvt();i++) { | ||
| 48 | |||
| 49 | if (file.getName().equals(Connexion.eventC.getNom_image().get(i))) { | ||
| 50 | |||
| 51 | Alert alert = new Alert(Alert.AlertType.ERROR); | ||
| 52 | alert.setTitle("StatHammer : Nom d'image déjà existant"); | ||
| 53 | alert.setHeaderText(null); | ||
| 54 | alert.setContentText("Le nom de l'image est déjà prise."); | ||
| 55 | alert.showAndWait(); | ||
| 56 | nomFich = false; | ||
| 57 | |||
| 58 | } | ||
| 59 | } | ||
| 60 | if (nomFich) { | ||
| 61 | System.out.println("Fichier sélectionné : " + file.getName()); | ||
| 62 | System.out.println("Chemin du fichier : " + file.getAbsolutePath()); | ||
| 63 | |||
| 64 | // Créer une nouvelle image à partir du chemin absolu du fichier | ||
| 65 | Image image = new Image("file:" + file.getAbsolutePath()); | ||
| 66 | |||
| 67 | // Définir l'image dans l'ImageView | ||
| 68 | imageView.setImage(image); | ||
| 69 | |||
| 70 | // Destination pour sauvegarder l'image | ||
| 71 | destinationDir = "src\\images"; | ||
| 72 | File destinationFolder = new File(destinationDir); | ||
| 73 | |||
| 74 | // Créez le répertoire s'il n'existe pas | ||
| 75 | if (!destinationFolder.exists()) { | ||
| 76 | destinationFolder.mkdirs(); | ||
| 77 | } | ||
| 78 | |||
| 79 | File nouveauNom = new File(file.getName()); | ||
| 80 | destinationFile = new File(destinationFolder, nouveauNom.getName()); | ||
| 81 | |||
| 82 | } | ||
| 83 | |||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | |||
| 88 | //méthode "valider" | ||
| 89 | public static VBox valider(String nom_evt, String nom_img, String desc, String date) { | ||
| 90 | Evenement evt = new Evenement(nom_evt, nom_img, desc, date); | ||
| 91 | VBox event = new VBox(); | ||
| 92 | event.setPrefHeight(50); | ||
| 93 | event.setAlignment(Pos.CENTER); | ||
| 94 | try { | ||
| 95 | // Copier le fichier dans le dossier de destination | ||
| 96 | Files.copy(file.toPath(), destinationFile.toPath()); | ||
| 97 | System.out.println("Fichier enregistré à : " + destinationFile.getAbsolutePath()); | ||
| 98 | EvenementController.insererEvenement(evt); | ||
| 99 | event = EvenementController.EvenementVBox(); | ||
| 100 | |||
| 101 | } catch (IOException ioException) { | ||
| 102 | System.out.println("Probleme sur Valider"); | ||
| 103 | ioException.printStackTrace(); | ||
| 104 | } | ||
| 105 | return event; | ||
| 106 | } | ||
| 107 | |||
| 108 | public static File getFile() { | ||
| 109 | return file; | ||
| 110 | } | ||
| 111 | |||
| 112 | |||
| 113 | public static String getDestinationDir() { | ||
| 114 | return destinationDir; | ||
| 115 | } | ||
| 116 | |||
| 117 | |||
| 118 | |||
| 119 | } \ No newline at end of file | ||
diff --git a/src/main/java/controlleur/ControllerTopMenu.java b/src/main/java/controlleur/ControllerTopMenu.java new file mode 100644 index 0000000..baef8df --- /dev/null +++ b/src/main/java/controlleur/ControllerTopMenu.java | |||
| @@ -0,0 +1,58 @@ | |||
| 1 | package controlleur; | ||
| 2 | |||
| 3 | import application.Battle; | ||
| 4 | import javafx.stage.Stage; | ||
| 5 | import modele.Evenement; | ||
| 6 | import modele.User; | ||
| 7 | import vue.AfficheAccueil; | ||
| 8 | import vue.AfficheAdmin; | ||
| 9 | import vue.AfficheConnexion; | ||
| 10 | import vue.AfficheCreerListe; | ||
| 11 | import vue.AfficheGestionCompte; | ||
| 12 | import vue.GestionListe.AfficheGestionListe; | ||
| 13 | import vue.simulation.AfficheSimulation; | ||
| 14 | |||
| 15 | public class ControllerTopMenu { | ||
| 16 | static BDD db = new BDD(); | ||
| 17 | |||
| 18 | public static void go_accueil(Stage primaryStage,User session) { | ||
| 19 | //primaryStage.close(); pour fermer stage | ||
| 20 | AfficheAccueil.affiche(primaryStage,session); | ||
| 21 | } | ||
| 22 | public static void go_gestion_compte(Stage primaryStage,User session) { | ||
| 23 | AfficheGestionCompte.affiche(primaryStage,session); | ||
| 24 | } | ||
| 25 | public static void go_gestion_listes(Stage primaryStage,User session) { | ||
| 26 | |||
| 27 | // db.getArmyLists(session); | ||
| 28 | AfficheGestionListe.affiche(primaryStage, session); | ||
| 29 | |||
| 30 | // | ||
| 31 | |||
| 32 | } | ||
| 33 | public static void go_deco(Stage primaryStage, User session) { | ||
| 34 | AfficheSimulation.cleanWeaponsAtitudesMenu(); | ||
| 35 | Battle.clean(); // VRAIMENT ?! | ||
| 36 | session = null; | ||
| 37 | AfficheConnexion.affiche(primaryStage); | ||
| 38 | } | ||
| 39 | public static void go_simulation(Stage primaryStage, User session){ | ||
| 40 | |||
| 41 | |||
| 42 | Instanciation.getArmyLists(session); | ||
| 43 | |||
| 44 | AfficheSimulation.affiche(primaryStage, session); | ||
| 45 | } | ||
| 46 | public static void go_admin(Stage primaryStage,User session) { | ||
| 47 | AfficheAdmin.affiche(primaryStage,session); | ||
| 48 | } | ||
| 49 | public static void go_creer_liste(Stage primaryStage, User session) { | ||
| 50 | AfficheCreerListe.afficheCreerListe(primaryStage, session); | ||
| 51 | } | ||
| 52 | // public static void go_gestionliste(Stage primaryStage,User session) { | ||
| 53 | // AfficheGestionListe.affiche(primaryStage,session); | ||
| 54 | // } | ||
| 55 | } | ||
| 56 | |||
| 57 | |||
| 58 | |||
diff --git a/src/main/java/controlleur/ControlleurSimu.java b/src/main/java/controlleur/ControlleurSimu.java new file mode 100644 index 0000000..a349036 --- /dev/null +++ b/src/main/java/controlleur/ControlleurSimu.java | |||
| @@ -0,0 +1,218 @@ | |||
| 1 | package controlleur; | ||
| 2 | |||
| 3 | import java.util.ArrayList; | ||
| 4 | import java.util.HashMap; | ||
| 5 | import application.Battle; | ||
| 6 | import javafx.scene.control.Button; | ||
| 7 | import javafx.scene.control.ChoiceBox; | ||
| 8 | import javafx.scene.image.Image; | ||
| 9 | import javafx.scene.image.ImageView; | ||
| 10 | import javafx.scene.layout.FlowPane; | ||
| 11 | import javafx.scene.layout.HBox; | ||
| 12 | import javafx.scene.layout.Pane; | ||
| 13 | import modele.Aptitude; | ||
| 14 | import modele.Arme; | ||
| 15 | import modele.ArmeeListe; | ||
| 16 | import modele.Calcul; | ||
| 17 | import modele.Figurine; | ||
| 18 | import modele.Unit; | ||
| 19 | import vue.simulation.AfficheSimulation; | ||
| 20 | import vue.simulation.SimAptAndWeaponsVBox; | ||
| 21 | import vue.simulation.SimFigurinesVBox; | ||
| 22 | import vue.simulation.SimHistogramme; | ||
| 23 | import vue.simulation.SimUnitsVBox; | ||
| 24 | |||
| 25 | public class ControlleurSimu | ||
| 26 | { | ||
| 27 | // déroulement des unités d'une liste (appui sur lists_drop_down.get(i) dans AfficheSimulation) | ||
| 28 | public static void selectAList(int num_list, ArrayList<ArmeeListe> lists, String choice) | ||
| 29 | { | ||
| 30 | // choix de la liste | ||
| 31 | for(ArmeeListe one_list : lists) | ||
| 32 | { | ||
| 33 | if(one_list.getName().equals(choice)) { | ||
| 34 | // "copie profonde" d'une liste | ||
| 35 | ArmeeListe list = new ArmeeListe(one_list.getName(), one_list.getDescription(), one_list.getData()); | ||
| 36 | Battle.setSelectedList(num_list, list); | ||
| 37 | break; // choix unique | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | // obtenir les unités, l'armée, les figurines, armes et aptitudes | ||
| 42 | Instanciation.getUnitsOfAList(Battle.getSelectedList(num_list)); | ||
| 43 | |||
| 44 | Battle.setArmy(num_list, Battle.getSelectedList(num_list).getUnits().get(0).getArmee()); | ||
| 45 | |||
| 46 | } | ||
| 47 | |||
| 48 | // déroulement des figurines d'une unité (appui sur buttons.get(i) dans SimUnitsVBox) | ||
| 49 | public static void PullDownUnits(int num_list, HBox dropdown_menu_box, SimUnitsVBox list_box) { | ||
| 50 | ArmeeListe list = Battle.getSelectedList(num_list); | ||
| 51 | |||
| 52 | // noms des unités | ||
| 53 | String[] unit_names = new String[list.getUnits().size()]; | ||
| 54 | for(int i = 0; i < list.getUnits().size(); i++) { | ||
| 55 | unit_names[i] = list.getUnits().get(i).getName(); | ||
| 56 | } | ||
| 57 | |||
| 58 | // supprimer l'ancien logo | ||
| 59 | if(dropdown_menu_box.getChildren().size() == 2){ | ||
| 60 | dropdown_menu_box.getChildren().remove(1); | ||
| 61 | } | ||
| 62 | |||
| 63 | // logo de faction | ||
| 64 | Image logo_faction = null; | ||
| 65 | if(Battle.getArmy(num_list) != null) // possibilité d'une liste vide | ||
| 66 | { | ||
| 67 | String file_name = Battle.getArmy(num_list).getLogo(); | ||
| 68 | logo_faction = new Image("/images/armees/" + file_name); | ||
| 69 | } | ||
| 70 | ImageView logo_box = new ImageView(); | ||
| 71 | |||
| 72 | logo_box.setPreserveRatio(true); | ||
| 73 | logo_box.fitHeightProperty().bind(dropdown_menu_box.heightProperty()); | ||
| 74 | logo_box.setImage(logo_faction); | ||
| 75 | dropdown_menu_box.getChildren().add(logo_box); | ||
| 76 | |||
| 77 | // effacer la zone armes et aptitudes | ||
| 78 | AfficheSimulation.getWeaponsAtitudesMenu().setStyle("-fx-border-width: 0;"); | ||
| 79 | AfficheSimulation.getWeaponsAtitudesMenu().getChildren().clear(); | ||
| 80 | |||
| 81 | // effacer et recréer les unités | ||
| 82 | list_box.getButtons().clear(); | ||
| 83 | list_box.getFigBoxes().clear(); | ||
| 84 | list_box.getChildren().clear(); | ||
| 85 | list_box.setList(num_list); | ||
| 86 | } | ||
| 87 | |||
| 88 | // déroulement des figurines d'une unité (appui sur buttons.get(i) dans SimUnitsVBox) | ||
| 89 | public static void selectAnUnit(SimUnitsVBox lists, int col, int j) | ||
| 90 | { | ||
| 91 | ArrayList<Button> buttons = lists.getButtons(); | ||
| 92 | SimFigurinesVBox old_fig_boxes = null; | ||
| 93 | SimFigurinesVBox new_fig_boxes = lists.getFigBoxes().get(j); | ||
| 94 | |||
| 95 | // il y a déjà une unité sélectionnée | ||
| 96 | if(Battle.getSelectedUnitIndex(col) > -1) | ||
| 97 | { | ||
| 98 | buttons.get(Battle.getSelectedUnitIndex(col)).setStyle("-fx-border-width: 0;");// retirer bordure unité sélectionnée | ||
| 99 | AfficheSimulation.getWeaponsAtitudesMenu().getChildren().clear(); // supprimer fenêtre combat si existe | ||
| 100 | |||
| 101 | // bouton même unité => ferme | ||
| 102 | if(Battle.getSelectedUnitIndex(col) == j) | ||
| 103 | { | ||
| 104 | new_fig_boxes.getChildren().clear(); | ||
| 105 | Battle.setSelectedUnit(col, -1); | ||
| 106 | } | ||
| 107 | // bouton autre unité | ||
| 108 | else | ||
| 109 | { | ||
| 110 | old_fig_boxes = lists.getFigBoxes().get(Battle.getSelectedUnitIndex(col)); | ||
| 111 | if(old_fig_boxes != null) { | ||
| 112 | old_fig_boxes.getChildren().clear(); // supprimer ancienne zone de figurines | ||
| 113 | } | ||
| 114 | Battle.setSelectedUnit(col, j); | ||
| 115 | buttons.get(j).setStyle("-fx-border-width: 2; -fx-border-color: yellow; -fx-border-radius: 2;"); // bordure unité sélectionnée | ||
| 116 | new_fig_boxes.setFigurines(); // on ouvre | ||
| 117 | } | ||
| 118 | } | ||
| 119 | // pas d'unité sélectionnée => on ouvre | ||
| 120 | else | ||
| 121 | { | ||
| 122 | Battle.setSelectedUnit(col, j); | ||
| 123 | buttons.get(j).setStyle("-fx-border-width: 2; -fx-border-color: yellow; -fx-border-radius: 2;"); // bordure unité sélectionnée | ||
| 124 | new_fig_boxes.setFigurines(); | ||
| 125 | } | ||
| 126 | } | ||
| 127 | |||
| 128 | // slider des PV des figurines | ||
| 129 | public static void hpUpdate(int hp, Figurine fig, ImageView one_image_box) { | ||
| 130 | int old_hp = fig.getHP(); | ||
| 131 | fig.setHP(hp); | ||
| 132 | |||
| 133 | Image one_image; | ||
| 134 | if(old_hp == 0 && fig.getHP() > 0) { | ||
| 135 | one_image = new Image("/images/android-fill.png"); | ||
| 136 | one_image_box.setImage(one_image); | ||
| 137 | } | ||
| 138 | else if(old_hp > 0 && fig.getHP() == 0){ // utile? | ||
| 139 | one_image = new Image("/images/android-line.png"); | ||
| 140 | one_image_box.setImage(one_image); | ||
| 141 | } | ||
| 142 | } | ||
| 143 | |||
| 144 | // afficher la zone des armes et aptitudes | ||
| 145 | public static void makeWeaponsAndAptitudeZone(ArrayList<Figurine> fig_group, SimAptAndWeaponsVBox weapons_aptitudes_menu) { | ||
| 146 | ArrayList<Arme> weapon_list = fig_group.get(0).getArmes(); | ||
| 147 | ArrayList<Aptitude> aptitude_list = fig_group.get(0).getAptitudes(); | ||
| 148 | |||
| 149 | weapons_aptitudes_menu.setArmes(weapon_list); | ||
| 150 | weapons_aptitudes_menu.setAptitudes(aptitude_list); | ||
| 151 | weapons_aptitudes_menu.setAptAndWeapons(fig_group); // contenu de la vue | ||
| 152 | AfficheSimulation.refreshWeaponAndAptitude(weapons_aptitudes_menu); // insersion dans la vue principale | ||
| 153 | } | ||
| 154 | |||
| 155 | public static void selectAWeapon(SimAptAndWeaponsVBox view, String weapon_name, ArrayList<Figurine> fig_group, FlowPane weapon_stats) { | ||
| 156 | Arme weapon = fig_group.get(0).getWeaponByName(weapon_name); // recherche dans les armes de la 1ère figurine | ||
| 157 | // on équipe le groupe | ||
| 158 | for(Figurine fig : fig_group) { | ||
| 159 | fig.setWeapon(weapon); | ||
| 160 | } | ||
| 161 | weapon_stats.getChildren().clear(); | ||
| 162 | view.setWeaponStats(weapon, weapon_stats); | ||
| 163 | } | ||
| 164 | |||
| 165 | public static void AliveFigsChoice(int col, int value, String group_name) { | ||
| 166 | // on considère que ceux qui n'attaquent pas sont morts | ||
| 167 | ArrayList<Figurine> fig_group = Battle.getSelectedUnit(col).getIdenticalFigsGroups().get(group_name); | ||
| 168 | for(int i = 0; i < value; i++) { | ||
| 169 | fig_group.get(i).setHP(fig_group.get(i).getHPMax()); | ||
| 170 | } | ||
| 171 | for(int i = value; i < fig_group.size(); i++) { | ||
| 172 | fig_group.get(i).setHP(0); | ||
| 173 | } | ||
| 174 | |||
| 175 | System.out.println("weaponNumberChoice => trouver un moyen de modifier instantanément les images"); | ||
| 176 | } | ||
| 177 | |||
| 178 | public static void checkOrUncheckAnAptitude(boolean isSelected, String aptitude_name, ArrayList<Figurine> fig_group) { | ||
| 179 | for(Aptitude apti : fig_group.get(0).getAptitudes()) // recherche dans les aptitudes de la 1ère figurine | ||
| 180 | { | ||
| 181 | if(apti.getName() == aptitude_name) { | ||
| 182 | for(Figurine fig : fig_group) | ||
| 183 | { | ||
| 184 | HashMap<String, Aptitude> selectedAptitudes = fig.getSelectedAptitudes(); | ||
| 185 | if(isSelected) { | ||
| 186 | selectedAptitudes.put(aptitude_name, apti); | ||
| 187 | } | ||
| 188 | else { | ||
| 189 | if(selectedAptitudes.containsKey(aptitude_name)) { | ||
| 190 | selectedAptitudes.remove(aptitude_name); | ||
| 191 | } | ||
| 192 | } | ||
| 193 | } | ||
| 194 | break; // on ne gère pas le cas où deux aptitudes ont le même nom | ||
| 195 | } | ||
| 196 | } | ||
| 197 | } | ||
| 198 | |||
| 199 | // histogramme | ||
| 200 | public static void afficheSimu(Pane p,Unit u1,Unit u2) { | ||
| 201 | p.getChildren().clear(); | ||
| 202 | Calcul c =Calcul.bataille(u1, u2); | ||
| 203 | |||
| 204 | SimHistogramme.setHist(c.getTabdegat1(), c.getTabmort1(), c.getDegat_moyen1(), c.getMort_moyen1(),p); | ||
| 205 | } | ||
| 206 | |||
| 207 | public static void reverseArmies(ArrayList<ChoiceBox<String>> lists_drop_down) { | ||
| 208 | Battle.reverseArmies(); | ||
| 209 | AfficheSimulation.inversion = true; | ||
| 210 | for(int i = 0; i < 2; i++) | ||
| 211 | { | ||
| 212 | // déclenche la sélection d'une liste dans le menu déroulant, mais avec du code | ||
| 213 | lists_drop_down.get(i).getSelectionModel().select(Battle.getSelectedList(i + 1).getName()); | ||
| 214 | Battle.setSelectedUnit(i + 1, -1); // plus d'unité sélectionnée | ||
| 215 | } | ||
| 216 | AfficheSimulation.inversion = false; | ||
| 217 | } | ||
| 218 | } | ||
diff --git a/src/main/java/controlleur/CreationCompte.java b/src/main/java/controlleur/CreationCompte.java new file mode 100644 index 0000000..0cd78ba --- /dev/null +++ b/src/main/java/controlleur/CreationCompte.java | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | package controlleur; | ||
| 2 | |||
| 3 | import java.util.ArrayList; | ||
| 4 | |||
| 5 | import javafx.stage.Stage; | ||
| 6 | import modele.User; | ||
| 7 | import vue.AfficheAccueil; | ||
| 8 | import vue.AfficheConnexion; | ||
| 9 | import vue.AfficheConnexionFailed; | ||
| 10 | |||
| 11 | public class CreationCompte { | ||
| 12 | public static void verif(String Email, String Pseudo, String Mdp, Stage primaryStage) { | ||
| 13 | |||
| 14 | Email = Email.trim(); | ||
| 15 | Pseudo = Pseudo.trim(); | ||
| 16 | Mdp = Mdp.trim(); | ||
| 17 | BDD conec = new BDD(); | ||
| 18 | ArrayList<String> crea = conec.creerUtilisateur(Email, Pseudo, Mdp); | ||
| 19 | int id = conec.UtilisateurID(Pseudo, Mdp); | ||
| 20 | String role = conec.UtilisateurRole(Pseudo, Mdp); | ||
| 21 | User session = new User(Pseudo,id,role); | ||
| 22 | conec.close(); | ||
| 23 | if (!crea.isEmpty() && Email.equals(crea.getFirst().trim())) { | ||
| 24 | |||
| 25 | System.out.println("Compté créé" + crea); | ||
| 26 | primaryStage.close(); | ||
| 27 | AfficheAccueil.affiche(primaryStage, session); | ||
| 28 | } else { | ||
| 29 | System.out.println("échec de la création de compte" + crea); | ||
| 30 | AfficheConnexionFailed.affiche(primaryStage); | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | public static void getBack(Stage primaryStage) { | ||
| 35 | AfficheConnexion.affiche(primaryStage); | ||
| 36 | } | ||
| 37 | |||
| 38 | } | ||
diff --git a/src/main/java/controlleur/EvenementController.java b/src/main/java/controlleur/EvenementController.java new file mode 100644 index 0000000..ad21353 --- /dev/null +++ b/src/main/java/controlleur/EvenementController.java | |||
| @@ -0,0 +1,267 @@ | |||
| 1 | package controlleur; | ||
| 2 | |||
| 3 | import java.io.IOException; | ||
| 4 | import java.nio.file.Files; | ||
| 5 | import java.nio.file.Paths; | ||
| 6 | import java.sql.PreparedStatement; | ||
| 7 | import java.sql.ResultSet; | ||
| 8 | import java.sql.SQLException; | ||
| 9 | import java.util.ArrayList; | ||
| 10 | import java.io.IOException; | ||
| 11 | import java.nio.file.Files; | ||
| 12 | import java.nio.file.Path; | ||
| 13 | import java.nio.file.Paths; | ||
| 14 | import javafx.geometry.Pos; | ||
| 15 | import javafx.scene.control.Button; | ||
| 16 | import javafx.scene.control.Label; | ||
| 17 | import javafx.scene.layout.HBox; | ||
| 18 | import javafx.scene.layout.VBox; | ||
| 19 | import modele.Evenement; | ||
| 20 | import vue.AfficheAdmin; | ||
| 21 | |||
| 22 | |||
| 23 | public class EvenementController { | ||
| 24 | private static int nbrEvt; | ||
| 25 | |||
| 26 | public void setNbrEvt(int nbrEvt) { | ||
| 27 | EvenementController.nbrEvt = nbrEvt; | ||
| 28 | } | ||
| 29 | |||
| 30 | private static ArrayList<String> nom_event; | ||
| 31 | private static ArrayList<String> nom_image; | ||
| 32 | private static ArrayList<String> desc_event; | ||
| 33 | private static ArrayList<String> date_event; | ||
| 34 | |||
| 35 | |||
| 36 | public ArrayList<String> getNom_event() { | ||
| 37 | return nom_event; | ||
| 38 | } | ||
| 39 | |||
| 40 | public ArrayList<String> getNom_image() { | ||
| 41 | return nom_image; | ||
| 42 | } | ||
| 43 | |||
| 44 | public ArrayList<String> getDesc_event() { | ||
| 45 | return desc_event; | ||
| 46 | } | ||
| 47 | |||
| 48 | public ArrayList<String> getDate_event() { | ||
| 49 | return date_event; | ||
| 50 | } | ||
| 51 | |||
| 52 | //EvenementController permet de recenser tous les évènements sous forme d'ArrayList<String> | ||
| 53 | //Le rôle de ce constructeur a changé pas mal de fois, d'où un nom peu cohérent... | ||
| 54 | public EvenementController() { | ||
| 55 | |||
| 56 | nbrEvt = 0; | ||
| 57 | |||
| 58 | nom_event= new ArrayList<String>(); | ||
| 59 | nom_image= new ArrayList<String>(); | ||
| 60 | desc_event= new ArrayList<String>(); | ||
| 61 | date_event= new ArrayList<String>(); | ||
| 62 | |||
| 63 | |||
| 64 | // Créer une instance de BDD | ||
| 65 | BDD bdd = new BDD(); | ||
| 66 | |||
| 67 | try { | ||
| 68 | // Requête SQL | ||
| 69 | String sql = "SELECT * FROM evenement"; // Requête | ||
| 70 | PreparedStatement ps = bdd.getPreparedStatement(sql); | ||
| 71 | |||
| 72 | // Exécution de la requête | ||
| 73 | ResultSet rs = ps.executeQuery(); | ||
| 74 | |||
| 75 | |||
| 76 | // Traiter les résultats | ||
| 77 | while (rs.next()) { | ||
| 78 | int i=0; | ||
| 79 | nbrEvt = getNbrEvt() + 1; | ||
| 80 | |||
| 81 | String nom_evt = rs.getString("nom_evenement"); | ||
| 82 | String nom_img = rs.getString("nom_image"); | ||
| 83 | String desc_evt = rs.getString("description_evenement"); | ||
| 84 | String date_evt = rs.getString("date_evenement"); | ||
| 85 | |||
| 86 | nom_event.add(nom_evt); | ||
| 87 | nom_image.add(nom_img); | ||
| 88 | desc_event.add(desc_evt); | ||
| 89 | date_event.add(date_evt); | ||
| 90 | |||
| 91 | // Afficher les résultats ou les ajouter à une liste/structure de données | ||
| 92 | System.out.println("Image : " + nom_img); | ||
| 93 | System.out.println("Événement : " + nom_evt); | ||
| 94 | System.out.println("Description : " + desc_evt); | ||
| 95 | System.out.println("Date : " + date_evt); | ||
| 96 | i++; | ||
| 97 | } | ||
| 98 | } catch (SQLException e) { | ||
| 99 | System.err.println("Erreur lors de l'accès à la base de données : " + e.getMessage()); | ||
| 100 | } finally { | ||
| 101 | // Être sûr de fermer la connexion à la base de données | ||
| 102 | bdd.close(); | ||
| 103 | } | ||
| 104 | } | ||
| 105 | |||
| 106 | //Méthode pour insérer un évènement dans la BDD ainsi que d'ajouter cet évènement dans EvenementController | ||
| 107 | public static void insererEvenement(Evenement evt) { | ||
| 108 | // Créer une instance de BDD | ||
| 109 | BDD bdd = new BDD(); | ||
| 110 | try { | ||
| 111 | // Requête SQL | ||
| 112 | String sql = "INSERT INTO evenement (nom_evenement, nom_image, description_evenement, date_evenement, id_utilisateur) VALUES (?, ?, ?, ?, 3)"; // Requête | ||
| 113 | PreparedStatement ps = bdd.getPreparedStatement(sql); | ||
| 114 | |||
| 115 | // Associer les valeurs aux paramètres | ||
| 116 | ps.setString(1, evt.getNom_evenement()); | ||
| 117 | ps.setString(2, evt.getNom_image()); | ||
| 118 | ps.setString(3, evt.getDescritption_evenement()); | ||
| 119 | ps.setString(4, evt.getData_evenement()); | ||
| 120 | |||
| 121 | Connexion.eventC.getNom_event().add(evt.getNom_evenement()); | ||
| 122 | Connexion.eventC.getNom_image().add(evt.getNom_image()); | ||
| 123 | Connexion.eventC.getDesc_event().add(evt.getDescritption_evenement()); | ||
| 124 | Connexion.eventC.getDate_event().add(evt.getData_evenement()); | ||
| 125 | |||
| 126 | Connexion.eventC.setNbrEvt(Connexion.eventC.getNbrEvt()+1); | ||
| 127 | |||
| 128 | // Exécution de la requête | ||
| 129 | ps.executeUpdate(); | ||
| 130 | System.out.println("Insertion réussiedans la base données"); | ||
| 131 | |||
| 132 | } catch (SQLException e) { | ||
| 133 | System.err.println("Erreur lors de l'accès à la base de données : " + e.getMessage()); | ||
| 134 | } finally { | ||
| 135 | // Être sûr de fermer la connexion à la base de données | ||
| 136 | bdd.close(); | ||
| 137 | } | ||
| 138 | } | ||
| 139 | |||
| 140 | |||
| 141 | public static VBox EvenementVBox() { | ||
| 142 | VBox event = new VBox(); | ||
| 143 | event.setPrefHeight(50); | ||
| 144 | event.setAlignment(Pos.CENTER); | ||
| 145 | |||
| 146 | for (int i = 0; i < Connexion.eventC.getNbrEvt() ; i++) { | ||
| 147 | |||
| 148 | HBox hevent = new HBox(); | ||
| 149 | hevent.setAlignment(Pos.CENTER); | ||
| 150 | hevent.setPrefHeight(50); | ||
| 151 | |||
| 152 | String num_evt = new String(i+1+". "); | ||
| 153 | Label numLabel = new Label(num_evt); | ||
| 154 | numLabel.setPrefWidth(25); | ||
| 155 | hevent.getChildren().add(numLabel); | ||
| 156 | |||
| 157 | |||
| 158 | String nom_evt = Connexion.eventC.getNom_event().get(i); | ||
| 159 | Label nomLabel = new Label(nom_evt); | ||
| 160 | nomLabel.setPrefWidth(150); | ||
| 161 | hevent.getChildren().add(nomLabel); | ||
| 162 | |||
| 163 | String nom_img = Connexion.eventC.getNom_image().get(i); | ||
| 164 | Label imgLabel = new Label(nom_img); | ||
| 165 | imgLabel.setPrefWidth(150); | ||
| 166 | hevent.getChildren().add(imgLabel); | ||
| 167 | |||
| 168 | String desc_evt = Connexion.eventC.getDesc_event().get(i); | ||
| 169 | Label descLabel = new Label(desc_evt); | ||
| 170 | descLabel.setPrefWidth(150); | ||
| 171 | hevent.getChildren().add(descLabel); | ||
| 172 | |||
| 173 | String date_evt = Connexion.eventC.getDate_event().get(i); | ||
| 174 | Label dateLabel = new Label(date_evt); | ||
| 175 | dateLabel.setPrefWidth(100); | ||
| 176 | hevent.getChildren().add(dateLabel); | ||
| 177 | |||
| 178 | Button bouton = new Button("X"); | ||
| 179 | hevent.getChildren().add(bouton); | ||
| 180 | |||
| 181 | Evenement evt = new Evenement(nom_evt,nom_img,desc_evt,date_evt); | ||
| 182 | |||
| 183 | bouton.setOnAction(e -> { | ||
| 184 | EvenementController.supprimerEvenement(evt); | ||
| 185 | |||
| 186 | }); | ||
| 187 | |||
| 188 | event.getChildren().add(hevent); | ||
| 189 | |||
| 190 | } | ||
| 191 | |||
| 192 | return event; | ||
| 193 | } | ||
| 194 | |||
| 195 | |||
| 196 | // Méthode "supprimer" modifiée pour accepter un argument | ||
| 197 | public static void supprimerEvenement(Evenement evt) { | ||
| 198 | // Créer une instance de BDD | ||
| 199 | BDD bdd = new BDD(); | ||
| 200 | try { | ||
| 201 | // Requête SQL | ||
| 202 | String sql = "DELETE FROM evenement WHERE nom_evenement = ?"; // Requête DELETE | ||
| 203 | PreparedStatement ps = bdd.getPreparedStatement(sql); | ||
| 204 | |||
| 205 | // Associer l'ID de l'événement à supprimer | ||
| 206 | ps.setString(1, evt.getNom_evenement()); | ||
| 207 | |||
| 208 | // Exécution de la requête | ||
| 209 | int rowsAffected = ps.executeUpdate(); | ||
| 210 | if (rowsAffected > 0) { | ||
| 211 | EvenementController.effacerImage(evt.getNom_image()); | ||
| 212 | |||
| 213 | Connexion.eventC.getNom_event().remove(evt.getNom_evenement()); | ||
| 214 | Connexion.eventC.getNom_image().remove(evt.getNom_image()); | ||
| 215 | Connexion.eventC.getDesc_event().remove(evt.getDescritption_evenement()); | ||
| 216 | Connexion.eventC.getDate_event().remove(evt.getData_evenement()); | ||
| 217 | |||
| 218 | Connexion.eventC.setNbrEvt(Connexion.eventC.getNbrEvt()-1); | ||
| 219 | |||
| 220 | |||
| 221 | AfficheAdmin.setEvents(EvenementController.EvenementVBox()); | ||
| 222 | Connexion.event = new Evenement(Connexion.eventC.getNom_event().get(0), | ||
| 223 | Connexion.eventC.getNom_image().get(0), | ||
| 224 | Connexion.eventC.getDesc_event().get(0), | ||
| 225 | Connexion.eventC.getDate_event().get(0)); | ||
| 226 | System.out.println(Connexion.eventC.getNom_image().get(0)); | ||
| 227 | AfficheAdmin.affiche(AfficheAdmin.getStage(), AfficheAdmin.getSess()); | ||
| 228 | |||
| 229 | |||
| 230 | System.out.println("Suppression réussie dans la base de données"); | ||
| 231 | |||
| 232 | |||
| 233 | } else { | ||
| 234 | System.out.println("Aucun événement trouvé avec cet ID."); | ||
| 235 | } | ||
| 236 | |||
| 237 | |||
| 238 | |||
| 239 | } catch (SQLException e) { | ||
| 240 | System.err.println("Erreur lors de l'accès à la base de données : " + e.getMessage()); | ||
| 241 | } finally { | ||
| 242 | // Être sûr de fermer la connexion à la base de données | ||
| 243 | bdd.close(); | ||
| 244 | } | ||
| 245 | |||
| 246 | } | ||
| 247 | |||
| 248 | public static void effacerImage(String nom_img) { | ||
| 249 | String file_name = ControllerAdmin.getDestinationDir()+"/"+nom_img; | ||
| 250 | |||
| 251 | Path path = Paths.get(file_name); | ||
| 252 | try { | ||
| 253 | boolean result = Files.deleteIfExists(path); | ||
| 254 | if (result) { | ||
| 255 | System.out.println("Image effacée !"); | ||
| 256 | } else { | ||
| 257 | System.out.println("Oups, impossible d'effacer."); | ||
| 258 | } | ||
| 259 | } catch (IOException e) { | ||
| 260 | e.printStackTrace(); | ||
| 261 | } | ||
| 262 | } | ||
| 263 | |||
| 264 | public int getNbrEvt() { | ||
| 265 | return nbrEvt; | ||
| 266 | } | ||
| 267 | } | ||
diff --git a/src/main/java/controlleur/GestionListe.java b/src/main/java/controlleur/GestionListe.java new file mode 100644 index 0000000..bd37589 --- /dev/null +++ b/src/main/java/controlleur/GestionListe.java | |||
| @@ -0,0 +1,82 @@ | |||
| 1 | package controlleur; | ||
| 2 | |||
| 3 | import java.io.File; | ||
| 4 | import java.sql.Connection; | ||
| 5 | import java.sql.PreparedStatement; | ||
| 6 | import java.sql.ResultSet; | ||
| 7 | import java.sql.SQLException; | ||
| 8 | import java.util.ArrayList; | ||
| 9 | import java.util.HashMap; | ||
| 10 | |||
| 11 | import javafx.stage.FileChooser; | ||
| 12 | import javafx.stage.Stage; | ||
| 13 | import modele.ArmeeListe; | ||
| 14 | |||
| 15 | public class GestionListe { | ||
| 16 | |||
| 17 | // Objet pour gérer la connexion à la bdd | ||
| 18 | private BDD conec; | ||
| 19 | |||
| 20 | // Constructeur de la clasee qui initialise la connexion à la bdd | ||
| 21 | public GestionListe() { | ||
| 22 | this.conec = new BDD(); | ||
| 23 | } | ||
| 24 | |||
| 25 | // récupération de l'id utilisateur et les listes d'armée | ||
| 26 | public ArrayList<ArmeeListe> getArmeeListe(int idUtilisateur) { | ||
| 27 | ArrayList<ArmeeListe> listes = new ArrayList<>(); | ||
| 28 | // Requête pour récupérer les listes d'armée avec leurs unités associées | ||
| 29 | String requete = """ | ||
| 30 | SELECT l.id_liste, l.nom_liste, l.description_liste, l.data_liste, u.nom_unite, u.id_armee | ||
| 31 | FROM liste l | ||
| 32 | LEFT JOIN contenir c ON l.id_liste = c.id_liste | ||
| 33 | LEFT JOIN unite u ON c.id_unite = u.id_unite | ||
| 34 | WHERE l.id_utilisateur = ? | ||
| 35 | """; | ||
| 36 | |||
| 37 | try (Connection conn = conec.getConnection(); | ||
| 38 | PreparedStatement stmt = conn.prepareStatement(requete)) { | ||
| 39 | |||
| 40 | stmt.setInt(1, idUtilisateur); | ||
| 41 | ResultSet recup = stmt.executeQuery(); | ||
| 42 | // Stocker les objets ArmeeListe par ID pour éviter les doublons | ||
| 43 | HashMap<Integer, ArmeeListe> mapListes = new HashMap<>(); | ||
| 44 | System.out.print(stmt + "côté controlleur"); | ||
| 45 | while (recup.next()) { | ||
| 46 | int id = recup.getInt("id_liste"); | ||
| 47 | String nom = recup.getString("nom_liste"); | ||
| 48 | String description = recup.getString("description_liste"); | ||
| 49 | String data = recup.getString("data_liste"); | ||
| 50 | String nomUnite = recup.getString("nom_unite"); | ||
| 51 | int idArmee = recup.getInt("id_armee"); | ||
| 52 | // Vérifier si la liste existe déjà dans la map | ||
| 53 | ArmeeListe liste = mapListes.get(id); | ||
| 54 | if (liste == null) { | ||
| 55 | liste = new ArmeeListe(id, idArmee, nom, description, data, idArmee); | ||
| 56 | liste.setUniteListe(new ArrayList<>()); // Initialiser la liste des unités | ||
| 57 | mapListes.put(id, liste); | ||
| 58 | } | ||
| 59 | |||
| 60 | // Ajouter l'unité si elle existe (éviter null) | ||
| 61 | if (nomUnite != null) { | ||
| 62 | liste.getUniteListe().add(nomUnite); | ||
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 66 | listes.addAll(mapListes.values()); | ||
| 67 | |||
| 68 | } catch (SQLException e) { | ||
| 69 | e.printStackTrace(); | ||
| 70 | } | ||
| 71 | |||
| 72 | return listes; | ||
| 73 | } | ||
| 74 | |||
| 75 | public static void importer(Stage primaryStage, File file) { | ||
| 76 | FileChooser fileChooser = new FileChooser(); | ||
| 77 | fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Fichier de liste d'armée", "*.*")); | ||
| 78 | file = fileChooser.showOpenDialog(primaryStage); | ||
| 79 | |||
| 80 | // parsing du fichier | ||
| 81 | } | ||
| 82 | } | ||
diff --git a/src/main/java/controlleur/Instanciation.java b/src/main/java/controlleur/Instanciation.java new file mode 100644 index 0000000..3ee39d0 --- /dev/null +++ b/src/main/java/controlleur/Instanciation.java | |||
| @@ -0,0 +1,304 @@ | |||
| 1 | package controlleur; | ||
| 2 | |||
| 3 | import java.sql.PreparedStatement; | ||
| 4 | import java.sql.ResultSet; | ||
| 5 | import java.sql.SQLException; | ||
| 6 | import java.util.ArrayList; | ||
| 7 | |||
| 8 | |||
| 9 | import application.Battle; | ||
| 10 | import modele.Aptitude; | ||
| 11 | import modele.AptitudeArme; | ||
| 12 | import modele.Arme; | ||
| 13 | import modele.ArmeDist; | ||
| 14 | import modele.ArmeMelee; | ||
| 15 | import modele.Armee; | ||
| 16 | import modele.ArmeeListe; | ||
| 17 | import modele.Faction; | ||
| 18 | import modele.Figurine; | ||
| 19 | import modele.Unit; | ||
| 20 | import modele.User; | ||
| 21 | |||
| 22 | public class Instanciation { | ||
| 23 | |||
| 24 | |||
| 25 | //classe qui fait des appel à la BDD pour instancier les classes modele | ||
| 26 | |||
| 27 | private static BDD conec; | ||
| 28 | private static Battle battle_data = new Battle(); | ||
| 29 | |||
| 30 | public static Battle getBattleData() { | ||
| 31 | return battle_data; | ||
| 32 | } | ||
| 33 | public static void resetBattle() { | ||
| 34 | battle_data = null; | ||
| 35 | battle_data = new Battle(); | ||
| 36 | } | ||
| 37 | |||
| 38 | //recupere la liste des faction de la BDD | ||
| 39 | public static ArrayList<Faction> getFaction() { | ||
| 40 | |||
| 41 | ArrayList<Faction> rendu = new ArrayList<Faction>(); | ||
| 42 | ArrayList<String> nom = new ArrayList<String>(); | ||
| 43 | try { | ||
| 44 | conec = new BDD(); | ||
| 45 | nom = conec.select("SELECT nom_faction FROM faction;" ); | ||
| 46 | |||
| 47 | for (String string : nom) { | ||
| 48 | rendu.add(new Faction(string)); | ||
| 49 | } | ||
| 50 | |||
| 51 | }catch(SQLException e) { | ||
| 52 | |||
| 53 | } | ||
| 54 | conec.close(); | ||
| 55 | return rendu; | ||
| 56 | } | ||
| 57 | |||
| 58 | //recupere la liste des armée d'une Faction précise | ||
| 59 | public static ArrayList<Armee> getArmee(Faction faction){ | ||
| 60 | ArrayList<Armee> rendu = new ArrayList<Armee>(); | ||
| 61 | ArrayList<String> nom = new ArrayList<String>(); | ||
| 62 | try { | ||
| 63 | conec = new BDD(); | ||
| 64 | |||
| 65 | nom = conec.select("SELECT a.nom_armee,a.logo_armee FROM armee a JOIN faction f USING (id_faction) WHERE f.nom_faction = ?;",faction.getNom() ); | ||
| 66 | |||
| 67 | |||
| 68 | for (int i = 0;i<nom.size();i = i+2) { | ||
| 69 | |||
| 70 | rendu.add(new Armee(nom.get(i),nom.get(i+1),faction)); | ||
| 71 | } | ||
| 72 | |||
| 73 | }catch(SQLException e) { | ||
| 74 | |||
| 75 | } | ||
| 76 | conec.close(); | ||
| 77 | return rendu; | ||
| 78 | } | ||
| 79 | |||
| 80 | //Récupere la liste des unités d'une armée précise | ||
| 81 | public static ArrayList<Unit> getUniteOfArmy(Armee armee){ | ||
| 82 | ArrayList<Unit> rendu = new ArrayList<Unit>(); | ||
| 83 | ArrayList<String> nom = new ArrayList<String>(); | ||
| 84 | try { | ||
| 85 | conec = new BDD(); | ||
| 86 | nom = conec.select("SELECT u.id_unite, u.nom_unite, u.points_unite,u.logo_unite FROM unite u JOIN armee a USING (id_armee) WHERE a.nom_armee = ? LIMIT 20;",armee.getName() ); | ||
| 87 | |||
| 88 | |||
| 89 | for (int i = 0;i<nom.size();i = i+4) { | ||
| 90 | rendu.add(new Unit(Instanciation.getFigurine(nom.get(i+1)),Integer.parseInt(nom.get(i)),nom.get(i+1), Integer.parseInt(nom.get(i+2)),nom.get(i+3),armee)); | ||
| 91 | } | ||
| 92 | |||
| 93 | |||
| 94 | |||
| 95 | |||
| 96 | }catch(SQLException e) { | ||
| 97 | |||
| 98 | } | ||
| 99 | conec.close(); | ||
| 100 | return rendu; | ||
| 101 | } | ||
| 102 | |||
| 103 | public static ArrayList<Unit> getUniteOfArmyLimited(Armee armee){ | ||
| 104 | ArrayList<Unit> rendu = new ArrayList<Unit>(); | ||
| 105 | ArrayList<String> nom = new ArrayList<String>(); | ||
| 106 | try { | ||
| 107 | conec = new BDD(); | ||
| 108 | nom = conec.select("SELECT u.id_unite, u.nom_unite, u.points_unite,u.logo_unite FROM unite u JOIN armee a USING (id_armee) WHERE a.nom_armee = ? LIMIT 20;",armee.getName() ); | ||
| 109 | |||
| 110 | |||
| 111 | for (int i = 0;i<nom.size();i = i+4) { | ||
| 112 | rendu.add(new Unit(null,Integer.parseInt(nom.get(i)),nom.get(i+1), Integer.parseInt(nom.get(i+2)),nom.get(i+3),armee)); | ||
| 113 | } | ||
| 114 | |||
| 115 | |||
| 116 | |||
| 117 | |||
| 118 | }catch(SQLException e) { | ||
| 119 | |||
| 120 | } | ||
| 121 | conec.close(); | ||
| 122 | return rendu; | ||
| 123 | } | ||
| 124 | |||
| 125 | |||
| 126 | public static void getArmyLists(User session) | ||
| 127 | { | ||
| 128 | conec = new BDD(); | ||
| 129 | String sql = "SELECT nom_liste, description_liste, data_liste FROM liste WHERE id_utilisateur = ?;"; | ||
| 130 | try { | ||
| 131 | PreparedStatement stat = conec.getPreparedStatement(sql, session.getId()); | ||
| 132 | ResultSet rs = stat.executeQuery(); | ||
| 133 | session.getListes().clear(); | ||
| 134 | while(rs.next()){ | ||
| 135 | ArmeeListe one_list = new ArmeeListe(rs.getString("nom_liste"), rs.getString("description_liste"), rs.getString("data_liste")); | ||
| 136 | session.addArmee(one_list); | ||
| 137 | } | ||
| 138 | } catch (SQLException e) { | ||
| 139 | e.printStackTrace(); | ||
| 140 | } | ||
| 141 | conec.close(); | ||
| 142 | } | ||
| 143 | |||
| 144 | public static void getUnitsOfAList(ArmeeListe list) { | ||
| 145 | conec = new BDD(); | ||
| 146 | String sql = "SELECT nom_unite, points_unite, logo_unite, nom_armee, logo_armee" | ||
| 147 | + " FROM unite JOIN contenir USING (id_unite) JOIN liste USING (id_liste) JOIN armee USING (id_armee)" | ||
| 148 | + " WHERE liste.nom_liste = ? AND unite.id_unite = contenir.id_unite AND contenir.id_liste = liste.id_liste;"; | ||
| 149 | |||
| 150 | try { | ||
| 151 | PreparedStatement stat = conec.getPreparedStatement(sql, list.getName()); | ||
| 152 | ResultSet rs = stat.executeQuery(); | ||
| 153 | |||
| 154 | while(rs.next()) { | ||
| 155 | list.addUnit(new Unit(Instanciation.getFigurine(rs.getString(1)), | ||
| 156 | rs.getString(1), rs.getInt(2), rs.getString(3), | ||
| 157 | new Armee(rs.getString(4), rs.getString(5)))); | ||
| 158 | } | ||
| 159 | } | ||
| 160 | catch (SQLException e) { | ||
| 161 | // TODO Auto-generated catch block | ||
| 162 | e.printStackTrace(); | ||
| 163 | } | ||
| 164 | conec.close(); | ||
| 165 | } | ||
| 166 | |||
| 167 | //Récupere les Figurine présente dans une unité précise | ||
| 168 | public static ArrayList<Figurine> getFigurine(String unitName){ | ||
| 169 | ArrayList<Figurine> rendu = new ArrayList<Figurine>(); | ||
| 170 | ArrayList<String> temp = new ArrayList<String>(); | ||
| 171 | try { | ||
| 172 | |||
| 173 | temp = conec.select("SELECT f.nom_figurine,f.M,f.E,f.SV,f.PV,f.CD,f.CO,r.nb_figurine FROM figurine f " | ||
| 174 | + "JOIN remplir r USING (id_figurine) JOIN unite u USING(id_unite) WHERE u.nom_unite = ?;",unitName ); | ||
| 175 | |||
| 176 | |||
| 177 | for (int i = 0;i<temp.size();i = i+8) { | ||
| 178 | for (int j =0;j< Integer.parseInt(temp.get(7));j++) { | ||
| 179 | rendu.add(new Figurine(Instanciation.getArme(temp.get(i)),Instanciation.getAptitude(temp.get(i)),temp.get(i),"",temp.get(i+1),Integer.parseInt(temp.get(i+2)),Integer.parseInt(temp.get(i+3)),Integer.parseInt(temp.get(i+4)),Integer.parseInt(temp.get(i+5)),Integer.parseInt(temp.get(i+6)))); | ||
| 180 | |||
| 181 | } | ||
| 182 | } | ||
| 183 | |||
| 184 | |||
| 185 | |||
| 186 | |||
| 187 | }catch(SQLException e) { | ||
| 188 | |||
| 189 | } | ||
| 190 | |||
| 191 | return rendu; | ||
| 192 | } | ||
| 193 | |||
| 194 | public static ArrayList<Figurine> getFigurine2(String unitName){ | ||
| 195 | ArrayList<Figurine> rendu = new ArrayList<Figurine>(); | ||
| 196 | ArrayList<String> temp = new ArrayList<String>(); | ||
| 197 | try { | ||
| 198 | conec = new BDD(); | ||
| 199 | temp = conec.select("SELECT f.nom_figurine,f.M,f.E,f.SV,f.PV,f.CD,f.CO,r.nb_figurine FROM figurine f " | ||
| 200 | + "JOIN remplir r USING (id_figurine) JOIN unite u USING(id_unite) WHERE u.nom_unite = ?;",unitName ); | ||
| 201 | |||
| 202 | |||
| 203 | for (int i = 0;i<temp.size();i = i+8) { | ||
| 204 | for (int j =0;j< Integer.parseInt(temp.get(7));j++) { | ||
| 205 | rendu.add(new Figurine(Instanciation.getArme(temp.get(i)),Instanciation.getAptitude(temp.get(i)),temp.get(i),"",temp.get(i+1),Integer.parseInt(temp.get(i+2)),Integer.parseInt(temp.get(i+3)),Integer.parseInt(temp.get(i+4)),Integer.parseInt(temp.get(i+5)),Integer.parseInt(temp.get(i+6)))); | ||
| 206 | |||
| 207 | } | ||
| 208 | } | ||
| 209 | |||
| 210 | |||
| 211 | |||
| 212 | |||
| 213 | }catch(SQLException e) { | ||
| 214 | |||
| 215 | } | ||
| 216 | conec.close(); | ||
| 217 | return rendu; | ||
| 218 | } | ||
| 219 | |||
| 220 | //Récupère les armes d'une figurine donnée | ||
| 221 | public static ArrayList<Arme> getArme(String figNom){ | ||
| 222 | ArrayList<Arme> rendu = new ArrayList<Arme>(); | ||
| 223 | ArrayList<String> nom = new ArrayList<String>(); | ||
| 224 | try { | ||
| 225 | |||
| 226 | nom = conec.select("SELECT a.nom_arme,a.PORTEE,a.A,a.F,a.PA,a.D,t.CT,m.CC FROM figurine f JOIN equiper e USING(id_figurine) JOIN arme a USING (id_arme) LEFT JOIN tir t USING (id_tir) LEFT JOIN melee m USING(id_melee) WHERE f.nom_figurine = ?;",figNom ); | ||
| 227 | |||
| 228 | |||
| 229 | for (int i = 0;i<nom.size();i = i+8) { | ||
| 230 | if (nom.get(i+7) == null) { | ||
| 231 | rendu.add(new ArmeDist(nom.get(i),Instanciation.getAptitudeArme(nom.get(i)),nom.get(i+1),nom.get(i+2),Integer.parseInt(nom.get(i+3)),Integer.parseInt(nom.get(i+4)),nom.get(i+5),Integer.parseInt(nom.get(i+6)))); | ||
| 232 | }else { | ||
| 233 | rendu.add(new ArmeMelee(nom.get(i),Instanciation.getAptitudeArme(nom.get(i)),nom.get(i+1),nom.get(i+2),Integer.parseInt(nom.get(i+3)),Integer.parseInt(nom.get(i+4)),nom.get(i+5),Integer.parseInt(nom.get(i+7)))); | ||
| 234 | } | ||
| 235 | } | ||
| 236 | |||
| 237 | |||
| 238 | |||
| 239 | |||
| 240 | |||
| 241 | }catch(SQLException e) { | ||
| 242 | |||
| 243 | } | ||
| 244 | |||
| 245 | return rendu; | ||
| 246 | } | ||
| 247 | |||
| 248 | //Récupère les Aptitude d'une figurine donnée | ||
| 249 | public static ArrayList<Aptitude> getAptitude(String figNom){ | ||
| 250 | ArrayList<Aptitude> rendu = new ArrayList<Aptitude>(); | ||
| 251 | ArrayList<String> nom = new ArrayList<String>(); | ||
| 252 | try { | ||
| 253 | |||
| 254 | nom = conec.select("SELECT a.nom_aptitude FROM aptitude a JOIN permettre USING (id_aptitude) JOIN figurine f USING(id_figurine) WHERE f.nom_figurine = ?;",figNom ); | ||
| 255 | |||
| 256 | |||
| 257 | for (int i = 0;i<nom.size(); i++) { | ||
| 258 | rendu.add(new Aptitude(nom.get(i))); | ||
| 259 | } | ||
| 260 | |||
| 261 | |||
| 262 | |||
| 263 | |||
| 264 | |||
| 265 | |||
| 266 | }catch(SQLException e) { | ||
| 267 | |||
| 268 | } | ||
| 269 | |||
| 270 | return rendu; | ||
| 271 | } | ||
| 272 | |||
| 273 | //Récupère les Aptitude d'une arme donnée | ||
| 274 | public static ArrayList<AptitudeArme> getAptitudeArme(String armeNom){ | ||
| 275 | ArrayList<AptitudeArme> rendu = new ArrayList<AptitudeArme>(); | ||
| 276 | ArrayList<String> nom = new ArrayList<String>(); | ||
| 277 | try { | ||
| 278 | |||
| 279 | nom = conec.select("SELECT a.nom_aptitude_arme FROM aptitude_arme a JOIN posseder USING (id_aptitude_arme) JOIN arme ar USING(id_arme) WHERE ar.nom_arme = ?;",armeNom ); | ||
| 280 | |||
| 281 | |||
| 282 | for (int i = 0;i<nom.size();i = i++) { | ||
| 283 | rendu.add(new AptitudeArme(nom.get(i))); | ||
| 284 | } | ||
| 285 | |||
| 286 | |||
| 287 | |||
| 288 | |||
| 289 | |||
| 290 | }catch(SQLException e) { | ||
| 291 | |||
| 292 | } | ||
| 293 | |||
| 294 | return rendu; | ||
| 295 | } | ||
| 296 | |||
| 297 | //Insert une Armée crée dans l'application dans la base de donée en la liant à un utilisateur | ||
| 298 | public static void insertListe(ArmeeListe armee,User session) { | ||
| 299 | conec = new BDD(); | ||
| 300 | conec.insertListe(armee, session); | ||
| 301 | conec.close(); | ||
| 302 | } | ||
| 303 | |||
| 304 | } | ||
diff --git a/src/main/java/controlleur/ModificationListe.java b/src/main/java/controlleur/ModificationListe.java new file mode 100644 index 0000000..7de1b59 --- /dev/null +++ b/src/main/java/controlleur/ModificationListe.java | |||
| @@ -0,0 +1,214 @@ | |||
| 1 | package controlleur; | ||
| 2 | |||
| 3 | import java.sql.Connection; | ||
| 4 | import java.sql.PreparedStatement; | ||
| 5 | import java.sql.ResultSet; | ||
| 6 | import java.sql.SQLException; | ||
| 7 | import java.util.ArrayList; | ||
| 8 | import java.util.HashMap; | ||
| 9 | |||
| 10 | import modele.ArmeeListe; | ||
| 11 | import modele.Figurine; | ||
| 12 | |||
| 13 | public class ModificationListe { | ||
| 14 | |||
| 15 | private BDD conec; // Instance de la classe BDD qui gère la connexion à la bdd | ||
| 16 | |||
| 17 | public ModificationListe() { | ||
| 18 | this.conec = new BDD(); | ||
| 19 | } | ||
| 20 | |||
| 21 | // Récupère la liste des armées en fonction de l'id de la liste choisie | ||
| 22 | public ArrayList<ArmeeListe> getArmeeListe(int idListe) { | ||
| 23 | ArrayList<ArmeeListe> listes = new ArrayList<>(); | ||
| 24 | String requete = """ | ||
| 25 | SELECT l.id_liste, l.nom_liste, l.description_liste, l.data_liste, u.nom_unite | ||
| 26 | FROM liste l | ||
| 27 | LEFT JOIN contenir c ON l.id_liste = c.id_liste | ||
| 28 | LEFT JOIN unite u ON c.id_unite = u.id_unite | ||
| 29 | WHERE l.id_liste = ?; | ||
| 30 | """; | ||
| 31 | |||
| 32 | try (Connection conn = reopenConnection(); | ||
| 33 | PreparedStatement stmt = conn.prepareStatement(requete)) { | ||
| 34 | |||
| 35 | stmt.setInt(1, idListe); | ||
| 36 | ResultSet recup = stmt.executeQuery(); | ||
| 37 | HashMap<Integer, ArmeeListe> mapListes = new HashMap<>(); | ||
| 38 | |||
| 39 | while (recup.next()) { | ||
| 40 | int id = recup.getInt("id_liste"); | ||
| 41 | String nom = recup.getString("nom_liste"); | ||
| 42 | String description = recup.getString("description_liste"); | ||
| 43 | String data = recup.getString("data_liste"); | ||
| 44 | String nomUnite = recup.getString("nom_unite"); | ||
| 45 | |||
| 46 | ArmeeListe liste = mapListes.get(id); | ||
| 47 | if (liste == null) { | ||
| 48 | liste = new ArmeeListe(id, id, nom, description, data, id); | ||
| 49 | liste.setUniteListe(new ArrayList<>()); | ||
| 50 | mapListes.put(id, liste); | ||
| 51 | } | ||
| 52 | |||
| 53 | if (nomUnite != null) { | ||
| 54 | liste.getUniteListe().add(nomUnite); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | listes.addAll(mapListes.values()); | ||
| 58 | |||
| 59 | } catch (SQLException e) { | ||
| 60 | e.printStackTrace(); | ||
| 61 | } | ||
| 62 | return listes; | ||
| 63 | } | ||
| 64 | |||
| 65 | public ArrayList<Figurine> getFigurineListe(int idListe, String nomUnit) { | ||
| 66 | ArrayList<Figurine> listesFigurine = new ArrayList<>(); | ||
| 67 | String requete = """ | ||
| 68 | SELECT f.nom_figurine, f.M, f.E, f.SV, f.PV, f.CD, f.CO | ||
| 69 | FROM liste l | ||
| 70 | JOIN contenir c ON l.id_liste = c.id_liste | ||
| 71 | JOIN unite u ON c.id_unite = u.id_unite | ||
| 72 | JOIN remplir r ON u.id_unite = r.id_unite | ||
| 73 | JOIN figurine f ON r.id_figurine = f.id_figurine | ||
| 74 | WHERE l.id_liste = ? AND u.nom_unite = ?; | ||
| 75 | """; | ||
| 76 | |||
| 77 | try (Connection conn = reopenConnection(); | ||
| 78 | PreparedStatement stmt = conn.prepareStatement(requete)) { | ||
| 79 | |||
| 80 | stmt.setInt(1, idListe); | ||
| 81 | stmt.setString(2, nomUnit); | ||
| 82 | ResultSet recup = stmt.executeQuery(); | ||
| 83 | |||
| 84 | while (recup.next()) { // récupère toutes les info de la figurine | ||
| 85 | String nomFigurine = recup.getString("nom_figurine"); | ||
| 86 | String M = recup.getString("M"); | ||
| 87 | int E = recup.getInt("E"); | ||
| 88 | int SV = recup.getInt("SV"); | ||
| 89 | int PV = recup.getInt("PV"); | ||
| 90 | int CD = recup.getInt("CD"); | ||
| 91 | int CO = recup.getInt("CO"); | ||
| 92 | |||
| 93 | Figurine figurine = new Figurine(new ArrayList<>(), new ArrayList<>(), nomFigurine, "", M, E, SV, PV, CD, CO); | ||
| 94 | listesFigurine.add(figurine); | ||
| 95 | } | ||
| 96 | } catch (SQLException e) { | ||
| 97 | e.printStackTrace(); | ||
| 98 | } | ||
| 99 | return listesFigurine; | ||
| 100 | } | ||
| 101 | |||
| 102 | public ArrayList<ArmeeListe> getAllUnites(int idArmee, int idListe) { | ||
| 103 | ArrayList<ArmeeListe> toutesUnites = new ArrayList<>(); | ||
| 104 | String requete = "SELECT u.nom_unite\r\n" | ||
| 105 | + "FROM unite u\r\n" | ||
| 106 | + "WHERE u.id_armee = ?\r\n" | ||
| 107 | + "AND u.nom_unite NOT IN (\r\n" | ||
| 108 | + " SELECT un.nom_unite\r\n" | ||
| 109 | + " FROM unite un\r\n" | ||
| 110 | + " JOIN contenir c ON un.id_unite = c.id_unite\r\n" | ||
| 111 | + " WHERE c.id_liste = ?\r\n" | ||
| 112 | + ");"; | ||
| 113 | |||
| 114 | try (Connection conn = reopenConnection(); | ||
| 115 | PreparedStatement stmt = conn.prepareStatement(requete)) { | ||
| 116 | |||
| 117 | stmt.setInt(1, idArmee); | ||
| 118 | stmt.setInt(2, idListe); | ||
| 119 | ResultSet recup = stmt.executeQuery(); | ||
| 120 | |||
| 121 | while (recup.next()) { | ||
| 122 | String nomUnite = recup.getString("nom_unite"); | ||
| 123 | ArmeeListe armee = new ArmeeListe(idArmee, idArmee, nomUnite, nomUnite, nomUnite, idListe); | ||
| 124 | armee.setUniteListe(new ArrayList<>()); | ||
| 125 | armee.getUniteListe().add(nomUnite); | ||
| 126 | toutesUnites.add(armee); | ||
| 127 | } | ||
| 128 | } catch (SQLException e) { | ||
| 129 | e.printStackTrace(); | ||
| 130 | } | ||
| 131 | return toutesUnites; | ||
| 132 | } | ||
| 133 | |||
| 134 | public ArrayList<Figurine> getAllFigurineListe(int idArmee, String unit) { | ||
| 135 | ArrayList<Figurine> listesAllFigurine = new ArrayList<>(); | ||
| 136 | String requete = """ | ||
| 137 | SELECT DISTINCT f.nom_figurine, f.M, f.E, f.SV, f.PV, f.CD, f.CO | ||
| 138 | FROM unite u | ||
| 139 | JOIN remplir r ON u.id_unite = r.id_unite | ||
| 140 | JOIN figurine f ON r.id_figurine = f.id_figurine | ||
| 141 | WHERE u.id_armee = ? AND u.nom_unite = ?; | ||
| 142 | """; | ||
| 143 | |||
| 144 | try (Connection conn = reopenConnection(); | ||
| 145 | PreparedStatement stmt = conn.prepareStatement(requete)) { | ||
| 146 | |||
| 147 | stmt.setInt(1, idArmee); | ||
| 148 | stmt.setString(2, unit); | ||
| 149 | ResultSet recup = stmt.executeQuery(); | ||
| 150 | |||
| 151 | while (recup.next()) { // récupère toutes les info de la figurine | ||
| 152 | String nomFigurine = recup.getString("nom_figurine"); | ||
| 153 | String M = recup.getString("M"); | ||
| 154 | int E = recup.getInt("E"); | ||
| 155 | int SV = recup.getInt("SV"); | ||
| 156 | int PV = recup.getInt("PV"); | ||
| 157 | int CD = recup.getInt("CD"); | ||
| 158 | int CO = recup.getInt("CO"); | ||
| 159 | |||
| 160 | Figurine figurine = new Figurine(new ArrayList<>(), new ArrayList<>(), nomFigurine, "", M, E, SV, PV, CD, CO); | ||
| 161 | listesAllFigurine.add(figurine); | ||
| 162 | } | ||
| 163 | } catch (SQLException e) { | ||
| 164 | e.printStackTrace(); | ||
| 165 | } | ||
| 166 | return listesAllFigurine; | ||
| 167 | } | ||
| 168 | |||
| 169 | private Connection reopenConnection() throws SQLException { | ||
| 170 | if (conec.getConnection().isClosed()) { | ||
| 171 | conec = new BDD(); | ||
| 172 | } | ||
| 173 | return conec.getConnection(); | ||
| 174 | } | ||
| 175 | |||
| 176 | public void ajouterUnites(int idListe, ArrayList<String> unites) { | ||
| 177 | String query = """ | ||
| 178 | INSERT INTO contenir (id_unite, id_liste) | ||
| 179 | SELECT id_unite, ? FROM unite WHERE nom_unite = ? LIMIT 1 | ||
| 180 | """; | ||
| 181 | try (Connection conn = reopenConnection(); | ||
| 182 | PreparedStatement pstmt = conn.prepareStatement(query)) { | ||
| 183 | |||
| 184 | for (String unite : unites) { | ||
| 185 | pstmt.setInt(1, idListe); | ||
| 186 | pstmt.setString(2, unite); | ||
| 187 | System.out.println("Requête: " + pstmt); | ||
| 188 | pstmt.addBatch(); | ||
| 189 | } | ||
| 190 | pstmt.executeBatch(); | ||
| 191 | |||
| 192 | } catch (SQLException e) { | ||
| 193 | e.printStackTrace(); | ||
| 194 | } | ||
| 195 | } | ||
| 196 | |||
| 197 | public void supprimerUnites(int idListe, ArrayList<String> unites) { | ||
| 198 | String query = "DELETE FROM contenir WHERE id_liste = ? AND id_unite = (SELECT id_unite FROM unite WHERE nom_unite = ? LIMIT 1)"; | ||
| 199 | try (Connection conn = reopenConnection(); | ||
| 200 | PreparedStatement pstmt = conn.prepareStatement(query)) { | ||
| 201 | |||
| 202 | for (String unite : unites) { | ||
| 203 | pstmt.setInt(1, idListe); | ||
| 204 | pstmt.setString(2, unite); | ||
| 205 | System.out.println("Requête: " + pstmt); | ||
| 206 | pstmt.addBatch(); | ||
| 207 | } | ||
| 208 | pstmt.executeBatch(); | ||
| 209 | |||
| 210 | } catch (SQLException e) { | ||
| 211 | e.printStackTrace(); | ||
| 212 | } | ||
| 213 | } | ||
| 214 | } | ||
diff --git a/src/main/java/controlleur/StockageCreerListe.java b/src/main/java/controlleur/StockageCreerListe.java new file mode 100644 index 0000000..82f4448 --- /dev/null +++ b/src/main/java/controlleur/StockageCreerListe.java | |||
| @@ -0,0 +1,75 @@ | |||
| 1 | package controlleur; | ||
| 2 | |||
| 3 | import java.util.ArrayList; | ||
| 4 | import java.util.HashMap; | ||
| 5 | |||
| 6 | import modele.Armee; | ||
| 7 | import modele.ArmeeListe; | ||
| 8 | import modele.Faction; | ||
| 9 | import modele.Unit; | ||
| 10 | |||
| 11 | public class StockageCreerListe { | ||
| 12 | |||
| 13 | //sauvegarde les nom des armée, des unités et des factions pour ne pas refaire appel à la BDD en boucle | ||
| 14 | |||
| 15 | private static final HashMap<String,Faction> faction = new HashMap<String, Faction>(); | ||
| 16 | private static final HashMap<String,Armee> armee = new HashMap<String, Armee>(); | ||
| 17 | private static final HashMap<String,Unit> unit = new HashMap<String, Unit>(); | ||
| 18 | private static ArmeeListe armeeListe; | ||
| 19 | |||
| 20 | |||
| 21 | public static void initFaction() { | ||
| 22 | faction.clear(); | ||
| 23 | for(Faction fac : Instanciation.getFaction()) { | ||
| 24 | faction.put(fac.getNom(), fac); | ||
| 25 | } | ||
| 26 | } | ||
| 27 | |||
| 28 | public static ArrayList<String> getNomFac(){ | ||
| 29 | ArrayList<String> rendu = new ArrayList<String>(); | ||
| 30 | for(Faction fac :faction.values() ) { | ||
| 31 | rendu.add(fac.getNom()); | ||
| 32 | } | ||
| 33 | return rendu; | ||
| 34 | } | ||
| 35 | |||
| 36 | public static void initArmee(String nomFaction) { | ||
| 37 | armee.clear(); | ||
| 38 | for(Armee arm:Instanciation.getArmee(faction.get(nomFaction))) { | ||
| 39 | armee.put(arm.getName(), arm); | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | public static ArrayList<String> getNomArmee() { | ||
| 44 | ArrayList<String> rendu = new ArrayList<String>(); | ||
| 45 | |||
| 46 | for(String arm : armee.keySet()) { | ||
| 47 | rendu.add(arm); | ||
| 48 | } | ||
| 49 | //rendu.add(rendu.removeFirst()); | ||
| 50 | return rendu; | ||
| 51 | } | ||
| 52 | public static void initUnit(String nomArmee) { | ||
| 53 | unit.clear(); | ||
| 54 | for(Unit uni:Instanciation.getUniteOfArmyLimited(armee.get(nomArmee))) { | ||
| 55 | unit.put(uni.getName(), uni); | ||
| 56 | } | ||
| 57 | } | ||
| 58 | public static ArrayList<String> getNomUnit() { | ||
| 59 | ArrayList<String> rendu = new ArrayList<String>(); | ||
| 60 | for(Unit uni : unit.values()) { | ||
| 61 | rendu.add(uni.getName()); | ||
| 62 | } | ||
| 63 | |||
| 64 | return rendu; | ||
| 65 | } | ||
| 66 | public static void initArmeeListe() { | ||
| 67 | armeeListe = new ArmeeListe(new ArrayList<Unit>(),"nom_temp","desc","data"); | ||
| 68 | } | ||
| 69 | public static ArmeeListe getArmeeListe() { | ||
| 70 | return armeeListe; | ||
| 71 | } | ||
| 72 | public static Unit getUnit(String nomUnit) { | ||
| 73 | return unit.get(nomUnit); | ||
| 74 | } | ||
| 75 | } | ||
diff --git a/src/main/java/controlleur/SupprListe.java b/src/main/java/controlleur/SupprListe.java new file mode 100644 index 0000000..6e2f488 --- /dev/null +++ b/src/main/java/controlleur/SupprListe.java | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | package controlleur; | ||
| 2 | |||
| 3 | import java.sql.Connection; | ||
| 4 | import java.sql.PreparedStatement; | ||
| 5 | import java.sql.SQLException; | ||
| 6 | |||
| 7 | public class SupprListe { | ||
| 8 | private BDD conec; | ||
| 9 | |||
| 10 | public SupprListe() { | ||
| 11 | this.conec = new BDD(); | ||
| 12 | } | ||
| 13 | |||
| 14 | public void Suppression(int idListe) { | ||
| 15 | |||
| 16 | String requeteSuppr = "DELETE FROM liste WHERE id_liste=?;"; | ||
| 17 | |||
| 18 | try (Connection conn = conec.getConnection(); PreparedStatement stmt = conn.prepareStatement(requeteSuppr)) { | ||
| 19 | |||
| 20 | stmt.setInt(1, idListe); | ||
| 21 | stmt.executeUpdate(); | ||
| 22 | } catch (SQLException e) { | ||
| 23 | e.printStackTrace(); | ||
| 24 | } | ||
| 25 | } | ||
| 26 | |||
| 27 | } | ||
