content: /*
   * 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 view;
  
  import classes.Categorie;
  import java.io.IOException;
  import java.net.URL;
  import java.sql.SQLException;
  import java.util.ResourceBundle;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  import javafx.animation.TranslateTransition;
  import javafx.event.ActionEvent;
  import javafx.fxml.FXML;
  import javafx.fxml.FXMLLoader;
  
  import javafx.fxml.Initializable;
  import javafx.scene.Node;
  import javafx.scene.Parent;
  import javafx.scene.Scene;
  import javafx.scene.control.Alert;
  import javafx.scene.control.Button;
  import javafx.scene.control.ChoiceBox;
  import javafx.scene.control.Label;
  import javafx.scene.control.TextField;
  import javafx.scene.input.MouseEvent;
  import javafx.scene.layout.BorderPane;
  import javafx.scene.layout.VBox;
  import javafx.stage.Stage;
  import javafx.util.Duration;
  import service.CategorieService;
  
  /**
   * FXML Controller class
   *
   * @author ASUS
   */
  public class AjouterController implements Initializable {
  @FXML
      private VBox slider;
      @FXML
      private Label menu;
      @FXML
      private Label menuclose;
      @FXML
      private TextField NomCat;
      @FXML
      private TextField DescCat;
      private String[] choix ={"sport","natation"} ;
      @FXML
      private ChoiceBox<String> choicefx;
      @FXML
      private Button AddBtn;
      private Object choiceBox;
  
      /**
       * Initializes the controller class.
       * @param url
       * @param rb
       * 
       
       */
      // private String[] choix ={"sport","loisir"} ;
      @Override
      public void initialize(URL url, ResourceBundle rb) {
          slider.setTranslateX(0);
          menuclose.setVisible(true);
          menu.setVisible(false);
          choicefx.getItems().addAll(choix);
      }    
     
  @FXML
    
     private void AddCategorie(ActionEvent event)  {
         
     try {
      String nom = NomCat.getText();
      String description = DescCat.getText();
      String type = (String) choicefx.getValue();
  
      if (type != null) { // Vérifiez que type n'est pas nul
          CategorieService ca = new CategorieService();
          Categorie categorie1 = new Categorie(nom, description, type);
          ca.ajout(categorie1);
          System.out.println("Categorie added successfully");
          
          Alert alert = new Alert(Alert.AlertType.INFORMATION);
          alert.setTitle("Succès");
          alert.setHeaderText("Catégorie ajoutée avec succès");
          alert.setContentText("Une nouvelle catégorie a été ajoutée.");
          alert.show();
      } else {
          // Gérez l'erreur si le type est nul
          Alert alert = new Alert(Alert.AlertType.ERROR);
          alert.setTitle("Erreur");
          alert.setHeaderText("Erreur de saisie !");
          alert.setContentText("Veuillez sélectionner un type de catégorie.");
          alert.show();
      }
  } catch (SQLException e) {
      System.out.println(e.getMessage());
  }
  
      }   
  
      void setBorderPane(BorderPane borderPane) {
      }
  
    
  
    @FXML
      private void Retour(ActionEvent event) {
      
      try {
      Parent root = FXMLLoader.load(getClass().getResource("Gestion categorie.fxml"));
      Scene scene = new Scene(root);
      Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
      stage.setScene(scene);
      stage.show();} catch (IOException ex) {
              Logger.getLogger(GestionProduitController.class.getName()).log(Level.SEVERE, null, ex);
          }}
   @FXML
      private void onmenuclicked(MouseEvent event) {
          TranslateTransition slide = new TranslateTransition();
          slide.setDuration(Duration.seconds(0.4));
          slide.setNode(slider);
          slide.setToX(0);
          slide.play();
          slider.setTranslateX(-176);
          
          menu.setVisible(false);
          menuclose.setVisible(true);
          
      }
      @FXML
      private void onmenuclickedclose(MouseEvent event) {
          TranslateTransition slide = new TranslateTransition();
          slide.setDuration(Duration.seconds(0.4));
          slide.setNode(slider);
          slide.setToX(-176);
          slide.play();
          slider.setTranslateX(0);
          
          menuclose.setVisible(false);
          menu.setVisible(true);
          
      } 
       @FXML
      private void home(ActionEvent event) {
      
      try {
      Parent root = FXMLLoader.load(getClass().getResource("Homeproduit.fxml"));
      Scene scene = new Scene(root);
      Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
      stage.setScene(scene);
      stage.show();} catch (IOException ex) {
              Logger.getLogger(GestionProduitController.class.getName()).log(Level.SEVERE, null, ex);
          }}
     
      @FXML
      private void evenement(ActionEvent event) {
      
      try {
      Parent root = FXMLLoader.load(getClass().getResource("evenementview.fxml"));
      Scene scene = new Scene(root);
      Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
      stage.setScene(scene);
      stage.show();} catch (IOException ex) {
              Logger.getLogger(GestionProduitController.class.getName()).log(Level.SEVERE, null, ex);
          }}
      @FXML
      private void reclamation(ActionEvent event) {
      
      try {
      Parent root = FXMLLoader.load(getClass().getResource("ajout_rec.fxml"));
      Scene scene = new Scene(root);
      Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
      stage.setScene(scene);
      stage.show();} catch (IOException ex) {
              Logger.getLogger(GestionProduitController.class.getName()).log(Level.SEVERE, null, ex);
          }}
      @FXML
      private void activite(ActionEvent event) {
      
      try {
      Parent root = FXMLLoader.load(getClass().getResource("activité.fxml"));
      Scene scene = new Scene(root);
      Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
      stage.setScene(scene);
      stage.show();} catch (IOException ex) {
              Logger.getLogger(GestionProduitController.class.getName()).log(Level.SEVERE, null, ex);
          }}
      @FXML
      private void channel(ActionEvent event) {
      
      try {
      Parent root = FXMLLoader.load(getClass().getResource("Dashboard.fxml"));
      Scene scene = new Scene(root);
      Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
      stage.setScene(scene);
      stage.show();} catch (IOException ex) {
              Logger.getLogger(GestionProduitController.class.getName()).log(Level.SEVERE, null, ex);
          }}
      
  }
  
     
  
  
  
      
     
     
  
  
  