remove addusers
This commit is contained in:
parent
383cd0c865
commit
da793d64f4
2 changed files with 1 additions and 109 deletions
|
@ -1,108 +0,0 @@
|
||||||
package controller;
|
|
||||||
|
|
||||||
import database.DatabaseConnection;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
public class AjoutUtilisateur extends JFrame {
|
|
||||||
private JTextField nomField;
|
|
||||||
private JTextField emailField;
|
|
||||||
private JComboBox<String> typeComboBox;
|
|
||||||
private JButton ajouterButton;
|
|
||||||
private JButton retourAccueilButton;
|
|
||||||
|
|
||||||
public AjoutUtilisateur() {
|
|
||||||
setTitle("Ajouter un utilisateur");
|
|
||||||
setSize(400, 300);
|
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
setLocationRelativeTo(null);
|
|
||||||
setLayout(new GridBagLayout());
|
|
||||||
|
|
||||||
GridBagConstraints gbc = new GridBagConstraints();
|
|
||||||
gbc.insets = new Insets(10, 10, 10, 10);
|
|
||||||
gbc.fill = GridBagConstraints.HORIZONTAL;
|
|
||||||
|
|
||||||
JLabel nomLabel = new JLabel("Nom :");
|
|
||||||
gbc.gridx = 0;
|
|
||||||
gbc.gridy = 0;
|
|
||||||
add(nomLabel, gbc);
|
|
||||||
|
|
||||||
nomField = new JTextField();
|
|
||||||
gbc.gridx = 1;
|
|
||||||
gbc.gridy = 0;
|
|
||||||
gbc.gridwidth = 2;
|
|
||||||
add(nomField, gbc);
|
|
||||||
|
|
||||||
JLabel emailLabel = new JLabel("Email :");
|
|
||||||
gbc.gridx = 0;
|
|
||||||
gbc.gridy = 1;
|
|
||||||
add(emailLabel, gbc);
|
|
||||||
|
|
||||||
emailField = new JTextField();
|
|
||||||
gbc.gridx = 1;
|
|
||||||
gbc.gridy = 1;
|
|
||||||
gbc.gridwidth = 2;
|
|
||||||
add(emailField, gbc);
|
|
||||||
|
|
||||||
JLabel typeLabel = new JLabel("Type d'utilisateur :");
|
|
||||||
gbc.gridx = 0;
|
|
||||||
gbc.gridy = 2;
|
|
||||||
add(typeLabel, gbc);
|
|
||||||
|
|
||||||
typeComboBox = new JComboBox<>(new String[]{"benevole", "personne_besoin", "validateur"});
|
|
||||||
gbc.gridx = 1;
|
|
||||||
gbc.gridy = 2;
|
|
||||||
gbc.gridwidth = 2;
|
|
||||||
add(typeComboBox, gbc);
|
|
||||||
|
|
||||||
ajouterButton = new JButton("Ajouter");
|
|
||||||
gbc.gridx = 1;
|
|
||||||
gbc.gridy = 3;
|
|
||||||
add(ajouterButton, gbc);
|
|
||||||
|
|
||||||
retourAccueilButton = new JButton("Retour à l'accueil");
|
|
||||||
gbc.gridx = 1;
|
|
||||||
gbc.gridy = 4;
|
|
||||||
add(retourAccueilButton, gbc);
|
|
||||||
|
|
||||||
ajouterButton.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
ajouterUtilisateur();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
retourAccueilButton.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
MainMenu menu = new MainMenu();
|
|
||||||
menu.setVisible(true);
|
|
||||||
dispose();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ajouterUtilisateur() {
|
|
||||||
String nom = nomField.getText();
|
|
||||||
String email = emailField.getText();
|
|
||||||
String typeUtilisateur = (String) typeComboBox.getSelectedItem();
|
|
||||||
|
|
||||||
try (Connection connection = DatabaseConnection.getConnection()) {
|
|
||||||
String sql = "INSERT INTO utilisateurs (nom, email, type_utilisateur) VALUES (?, ?, ?)";
|
|
||||||
PreparedStatement statement = connection.prepareStatement(sql);
|
|
||||||
statement.setString(1, nom);
|
|
||||||
statement.setString(2, email);
|
|
||||||
statement.setString(3, typeUtilisateur);
|
|
||||||
statement.executeUpdate();
|
|
||||||
JOptionPane.showMessageDialog(this, "Utilisateur ajouté avec succès !");
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -53,7 +53,7 @@ public class LoginPage extends JFrame {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// suprime de main menu
|
||||||
// Méthode pour gérer la connexion de l'utilisateur
|
// Méthode pour gérer la connexion de l'utilisateur
|
||||||
private void loginUser() {
|
private void loginUser() {
|
||||||
String email = emailField.getText();
|
String email = emailField.getText();
|
||||||
|
|
Loading…
Reference in a new issue