From 4ac96b4a7af17b5b86417cdf5ee9603714f34c9c Mon Sep 17 00:00:00 2001 From: yolou Date: Sun, 19 Oct 2025 22:11:18 +0200 Subject: [PATCH] ajout du controleur GestionRappel (CRUD potentiellement complet) --- .../papillon/controller/GestionRappel.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/fr/iutfbleau/papillon/controller/GestionRappel.java diff --git a/src/fr/iutfbleau/papillon/controller/GestionRappel.java b/src/fr/iutfbleau/papillon/controller/GestionRappel.java new file mode 100644 index 0000000..73970d9 --- /dev/null +++ b/src/fr/iutfbleau/papillon/controller/GestionRappel.java @@ -0,0 +1,59 @@ +package fr.iutfbleau.papillon.controller; + +import fr.iutfbleau.papillon.model.BaseDeDonnees; +import fr.iutfbleau.papillon.model.Rappel; + +import java.sql.*; +import java.util.ArrayList; +import java.util.List; + +public class GestionRappel { + + public void ajouter(Rappel r) throws SQLException { + String sql = "INSERT INTO rappel (titre, contenu, theme, rang) VALUES (?, ?, ?, ?)"; + Connection cnx = BaseDeDonnees.getConnexion(); + PreparedStatement pst = cnx.prepareStatement(sql); + pst.setString(1, r.getTitre()); + pst.setString(2, r.getContenu()); + pst.setString(3, r.getTheme()); + pst.setInt(4, r.getRang()); + pst.executeUpdate(); + pst.close(); + } + + public List lister() throws SQLException { + String sql = "SELECT id, titre, theme, rang FROM rappel ORDER BY id DESC"; + List res = new ArrayList<>(); + Connection cnx = BaseDeDonnees.getConnexion(); + PreparedStatement pst = cnx.prepareStatement(sql); + ResultSet rs = pst.executeQuery(); + while (rs.next()) { + res.add(rs.getInt("id") + " | " + rs.getString("titre") + " | " + rs.getString("theme") + " | " + rs.getInt("rang")); + } + rs.close(); + pst.close(); + return res; + } + + public void supprimerParId(int id) throws SQLException { + String sql = "DELETE FROM rappel WHERE id = ?"; + Connection cnx = BaseDeDonnees.getConnexion(); + PreparedStatement pst = cnx.prepareStatement(sql); + pst.setInt(1, id); + pst.executeUpdate(); + pst.close(); + } + + public void modifierParId(int id, Rappel r) throws SQLException { + String sql = "UPDATE rappel SET titre = ?, contenu = ?, theme = ?, rang = ? WHERE id = ?"; + Connection cnx = BaseDeDonnees.getConnexion(); + PreparedStatement pst = cnx.prepareStatement(sql); + pst.setString(1, r.getTitre()); + pst.setString(2, r.getContenu()); + pst.setString(3, r.getTheme()); + pst.setInt(4, r.getRang()); + pst.setInt(5, id); + pst.executeUpdate(); + pst.close(); + } +}