Skip to content

Commit

Permalink
fixed the UI of IHMRechercheFormation and implemented all of it's fun…
Browse files Browse the repository at this point in the history
…ctionalities
  • Loading branch information
saaya-code committed Mar 18, 2024
1 parent 435f201 commit 7636bf1
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/ExercicesTP/CRUD/FormationDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void addFormation(Formation formation) {

public void deleteFormation(int id) {
try {
st.executeUpdate("DELETE FROM formation WHERE Id = " + id);
st.executeUpdate("DELETE FROM formation WHERE IdF = " + id);
} catch (SQLException e) {
throw new RuntimeException(e);
}
Expand All @@ -44,7 +44,7 @@ public void deleteFormation(int id) {
public void updateFormation(Formation formation) {
PreparedStatement ps = null;
try {
ps = con.prepareStatement("UPDATE formation SET titre = ?, datef = ?, lieu = ?, certification = ? WHERE Id = ?");
ps = con.prepareStatement("UPDATE formation SET titre = ?, datef = ?, lieu = ?, certif = ? WHERE IdF = ?");
ps.setString(1, formation.getTitle());
ps.setDate(2, formation.getDateF());
ps.setString(3, formation.getLieu());
Expand Down
4 changes: 0 additions & 4 deletions src/ExercicesTP/Exercice2.java

This file was deleted.

11 changes: 11 additions & 0 deletions src/ExercicesTP/Formation.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@


import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class Formation {
public int Id;
Expand Down Expand Up @@ -57,4 +59,13 @@ public void setLieu(String lieu) {
this.lieu = lieu;
}

public static java.sql.Date parseDateToSqlDate(String date) {
java.util.Date dateUtil = null;
try {
dateUtil = new SimpleDateFormat("yyyy-MM-dd").parse(date);
} catch (ParseException e) {
throw new RuntimeException(e);
}
return new java.sql.Date(dateUtil.getTime());
}
}
32 changes: 30 additions & 2 deletions src/ExercicesTP/IHM/IHMRechercheFormation.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ private void initializeComponents() {
private void createLayout() {
JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
JPanel panel2 = new JPanel(new GridBagLayout());

// Add labels and corresponding components
c.fill = GridBagConstraints.HORIZONTAL;
addComponent(panel, referenceLabel, c, 0, 0, 1, 1);
addComponent(panel, referenceField, c, 1, 0, 2, 1);
addComponent(panel, rechercheButton, c, 5, 1, 1, 1);
addComponent(panel, titleLabel, c, 0, 1, 1, 1);
addComponent(panel, titleField, c, 1, 1, 2, 1);
addComponent(panel, dateLabel, c, 0, 2, 1, 1);
Expand All @@ -65,9 +65,16 @@ private void createLayout() {
addComponent(panel, lieuTextField, c, 1, 3, 2, 1);
addComponent(panel, certificationLabel, c, 0, 4, 1, 1);
addComponent(panel, certificationCheckbox, c, 1, 4, 1, 1);
addComponent(panel2, rechercheButton, c, 5, 1, 1, 1);
addComponent(panel2, modifierButton, c, 5, 2, 1, 1);
addComponent(panel2, supprimerButton, c, 5, 3, 1, 1);
addComponent(panel2, cancelButton, c, 5, 4, 1, 1);


// Add buttons
getContentPane().add(panel);
getContentPane().add(panel2);
getContentPane().setLayout(new FlowLayout());

setSize(500,250);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Expand All @@ -82,6 +89,13 @@ private void addComponent(JPanel panel, JComponent component, GridBagConstraints
panel.add(component, c);
}

private void clearInputs() {
referenceField.setText("");
titleField.setText("");
dateTextField.setText("");
lieuTextField.setText("");
certificationCheckbox.setSelected(false);
}
private void addEventListeners() {
rechercheButton.addActionListener(e -> {
Formation formation = formationDAO.getFormation(Integer.parseInt(referenceField.getText()));
Expand All @@ -91,12 +105,26 @@ private void addEventListeners() {
lieuTextField.setText(formation.getLieu());
certificationCheckbox.setSelected(formation.getCertification());
} else {
clearInputs();
JOptionPane.showMessageDialog(this, "Formation non trouvée");
}

});

cancelButton.addActionListener(e -> dispose());

modifierButton.addActionListener(e -> {
Formation formation = new Formation(Integer.parseInt(referenceField.getText()), titleField.getText(), Formation.parseDateToSqlDate(dateTextField.getText()), lieuTextField.getText(), certificationCheckbox.isSelected());
formationDAO.updateFormation(formation);
JOptionPane.showMessageDialog(this, "Formation modifiée");
});
supprimerButton.addActionListener(e -> {
formationDAO.deleteFormation(Integer.parseInt(referenceField.getText()));
JOptionPane.showMessageDialog(this, "Formation supprimée");
clearInputs();

});

}


Expand Down

0 comments on commit 7636bf1

Please sign in to comment.