diff options
Diffstat (limited to 'src/main/java/vue/AfficheAdmin.java')
| -rw-r--r-- | src/main/java/vue/AfficheAdmin.java | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/src/main/java/vue/AfficheAdmin.java b/src/main/java/vue/AfficheAdmin.java new file mode 100644 index 0000000..565a18a --- /dev/null +++ b/src/main/java/vue/AfficheAdmin.java | |||
| @@ -0,0 +1,151 @@ | |||
| 1 | package vue; | ||
| 2 | |||
| 3 | import javafx.geometry.Pos; | ||
| 4 | import javafx.scene.Scene; | ||
| 5 | import javafx.scene.control.Alert; | ||
| 6 | import javafx.scene.control.Button; | ||
| 7 | import javafx.scene.control.DatePicker; | ||
| 8 | import javafx.scene.image.Image; | ||
| 9 | import javafx.scene.image.ImageView; | ||
| 10 | import javafx.scene.layout.HBox; | ||
| 11 | import javafx.scene.layout.VBox; | ||
| 12 | import javafx.scene.paint.Color; | ||
| 13 | import javafx.scene.text.Font; | ||
| 14 | import javafx.scene.text.Text; | ||
| 15 | import javafx.stage.FileChooser; | ||
| 16 | import javafx.stage.Stage; | ||
| 17 | import modele.Evenement; | ||
| 18 | import modele.User; | ||
| 19 | import javafx.scene.control.TextField; | ||
| 20 | //import java.awt.TextArea; | ||
| 21 | import java.io.File; | ||
| 22 | import java.io.IOException; | ||
| 23 | import java.nio.file.Files; | ||
| 24 | import java.nio.file.Paths; | ||
| 25 | import java.time.LocalDate; | ||
| 26 | import java.time.ZoneId; | ||
| 27 | import java.time.format.DateTimeFormatter; | ||
| 28 | import java.util.Date; | ||
| 29 | |||
| 30 | import controlleur.BDD; | ||
| 31 | import controlleur.ControllerAdmin; | ||
| 32 | import controlleur.EvenementController; | ||
| 33 | |||
| 34 | public class AfficheAdmin { | ||
| 35 | private static VBox events; | ||
| 36 | private static Stage stage; | ||
| 37 | private static User sess; | ||
| 38 | |||
| 39 | public static Stage getStage() { | ||
| 40 | return stage; | ||
| 41 | } | ||
| 42 | |||
| 43 | public static void setStage(Stage stage) { | ||
| 44 | AfficheAdmin.stage = stage; | ||
| 45 | } | ||
| 46 | |||
| 47 | public static User getSess() { | ||
| 48 | return sess; | ||
| 49 | } | ||
| 50 | |||
| 51 | public static void setSess(User sess) { | ||
| 52 | AfficheAdmin.sess = sess; | ||
| 53 | } | ||
| 54 | |||
| 55 | public static VBox getEvents() { | ||
| 56 | return events; | ||
| 57 | } | ||
| 58 | |||
| 59 | public static void affiche(Stage primaryStage, User session) { | ||
| 60 | stage = primaryStage; | ||
| 61 | sess = session; | ||
| 62 | events = EvenementController.EvenementVBox(); | ||
| 63 | AfficheTopMenu menu = new AfficheTopMenu(stage,sess); | ||
| 64 | Text titre = new Text("Mes évènements"); | ||
| 65 | titre.setFont(Font.font("Arial", 30)); | ||
| 66 | titre.setFill(Color.web("#2C3E50")); | ||
| 67 | titre.setStroke(Color.web("#34495E")); | ||
| 68 | titre.setStrokeWidth(1); | ||
| 69 | |||
| 70 | |||
| 71 | // Création du DatePicker | ||
| 72 | DatePicker date = new DatePicker(); | ||
| 73 | date.setMaxWidth(60); | ||
| 74 | |||
| 75 | VBox vTitre = new VBox(titre); | ||
| 76 | Button parcourir = new Button("Parcourir"); | ||
| 77 | Button valider = new Button("Valider"); | ||
| 78 | TextField nom = new TextField(""); | ||
| 79 | nom.setPromptText("Nom de l'évènement"); | ||
| 80 | TextField descEvent = new TextField(); | ||
| 81 | descEvent.setPromptText("Quelques mots pour votre évènement ?"); | ||
| 82 | descEvent.setPrefWidth(250); | ||
| 83 | |||
| 84 | // Création d'un ImageView pour afficher l'image | ||
| 85 | ImageView imageView = new ImageView(); | ||
| 86 | imageView.setPreserveRatio(true); | ||
| 87 | imageView.setFitWidth(80); | ||
| 88 | |||
| 89 | // Action des boutons | ||
| 90 | parcourir.setOnAction(e -> { | ||
| 91 | ControllerAdmin.parcourir(stage, imageView); | ||
| 92 | }); | ||
| 93 | |||
| 94 | valider.setOnAction(e -> { | ||
| 95 | if (nom.getText().isEmpty() || descEvent.getText().isEmpty()||ControllerAdmin.getFile() == null){ | ||
| 96 | |||
| 97 | // Affichage du message d'erreur si n champ est vide | ||
| 98 | showErrorMessage("Tous les champs doivent être remplis."); | ||
| 99 | } | ||
| 100 | else { | ||
| 101 | // Récupération de la date sélectionnée | ||
| 102 | LocalDate localDate = date.getValue(); | ||
| 103 | |||
| 104 | if (localDate != null) { | ||
| 105 | // Formater la date en chaîne de caractères au format "yyyy-MM-dd" | ||
| 106 | String dateString = localDate.format(DateTimeFormatter.ISO_LOCAL_DATE); | ||
| 107 | System.out.println("Date sélectionnée : " + dateString); | ||
| 108 | System.out.println(dateString); | ||
| 109 | System.out.println("Date sélectionnée (java.util.Date) : " + dateString); | ||
| 110 | events = ControllerAdmin.valider(nom.getText(),ControllerAdmin.getFile().getName(),descEvent.getText(), dateString); | ||
| 111 | AfficheAdmin.affiche(stage, sess); | ||
| 112 | } | ||
| 113 | else { | ||
| 114 | |||
| 115 | // Affichage du message d'erreur si n champ est vide | ||
| 116 | showErrorMessage("Tous les champs doivent être remplis."); | ||
| 117 | } | ||
| 118 | } | ||
| 119 | }); | ||
| 120 | |||
| 121 | // VBox principal | ||
| 122 | HBox hbox = new HBox(20); | ||
| 123 | hbox.getChildren().addAll(nom, imageView, descEvent, date, parcourir, valider); | ||
| 124 | hbox.setAlignment(Pos.CENTER); | ||
| 125 | |||
| 126 | VBox root = new VBox(); | ||
| 127 | root.getChildren().addAll(menu,vTitre,hbox,events); | ||
| 128 | |||
| 129 | // Ajout du VBox à la scène | ||
| 130 | Scene scene = new Scene(root, 800, 600); | ||
| 131 | |||
| 132 | // Ajout d'un titre à la fenêtre | ||
| 133 | primaryStage.setTitle("StatHammer : Admin"); | ||
| 134 | primaryStage.setScene(scene); | ||
| 135 | primaryStage.show(); | ||
| 136 | } | ||
| 137 | |||
| 138 | public static void setEvents(VBox events) { | ||
| 139 | AfficheAdmin.events = events; | ||
| 140 | } | ||
| 141 | |||
| 142 | // Méthode pour afficher une erreur | ||
| 143 | private static void showErrorMessage(String message) { | ||
| 144 | Alert alert = new Alert(Alert.AlertType.ERROR); | ||
| 145 | alert.setTitle("StatHammer : Erreur dans le formulaire"); | ||
| 146 | alert.setHeaderText(null); | ||
| 147 | alert.setContentText(message); | ||
| 148 | alert.showAndWait(); | ||
| 149 | } | ||
| 150 | |||
| 151 | } | ||
