diff options
Diffstat (limited to 'src/main/java/controlleur/ControllerAdmin.java')
| -rw-r--r-- | src/main/java/controlleur/ControllerAdmin.java | 119 |
1 files changed, 119 insertions, 0 deletions
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 | ||
