MAJ
This commit is contained in:
+60
-60
@@ -1,60 +1,60 @@
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class GestionRappel {
|
public class GestionRappel {
|
||||||
|
|
||||||
public List<Rappel> lister() throws Exception {
|
public List<Rappel> lister() throws Exception {
|
||||||
return BaseDeDonnees.lister();
|
return BaseDeDonnees.lister();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int ajouter(Rappel r) throws Exception {
|
public int ajouter(Rappel r) throws Exception {
|
||||||
return BaseDeDonnees.ajouter(r);
|
return BaseDeDonnees.ajouter(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int modifierParId(int id, Rappel r) throws Exception {
|
public int modifierParId(int id, Rappel r) throws Exception {
|
||||||
return BaseDeDonnees.modifier(id, r);
|
return BaseDeDonnees.modifier(id, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int supprimerParId(int id) throws Exception {
|
public int supprimerParId(int id) throws Exception {
|
||||||
return BaseDeDonnees.supprimer(id);
|
return BaseDeDonnees.supprimer(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// === petit main pour test rapide ===
|
// === petit main pour test rapide ===
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
try {
|
||||||
GestionRappel g = new GestionRappel();
|
GestionRappel g = new GestionRappel();
|
||||||
|
|
||||||
// Ajouter
|
// Ajouter
|
||||||
Rappel r = new Rappel("Acheter du café", "avant 17h", "Urgent", 1);
|
Rappel r = new Rappel("Acheter du café", "avant 17h", "Urgent", 1);
|
||||||
int id = g.ajouter(r);
|
int id = g.ajouter(r);
|
||||||
System.out.println("Ajouté : " + id);
|
System.out.println("Ajouté : " + id);
|
||||||
|
|
||||||
// Lister
|
// Lister
|
||||||
System.out.println("\nListe des rappels :");
|
System.out.println("\nListe des rappels :");
|
||||||
for (Rappel x : g.lister()) {
|
for (Rappel x : g.lister()) {
|
||||||
System.out.println(" - " + x);
|
System.out.println(" - " + x);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modifier
|
// Modifier
|
||||||
r.setTitre("Acheter du café (bio)");
|
r.setTitre("Acheter du café (bio)");
|
||||||
r.setRang(3);
|
r.setRang(3);
|
||||||
|
|
||||||
g.modifierParId(r.getId(), r);
|
g.modifierParId(r.getId(), r);
|
||||||
System.out.println("\nAprès modification :");
|
System.out.println("\nAprès modification :");
|
||||||
|
|
||||||
for (Rappel x : g.lister()) {
|
for (Rappel x : g.lister()) {
|
||||||
System.out.println(" - " + x);
|
System.out.println(" - " + x);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Supprimer
|
// Supprimer
|
||||||
// g.supprimerParId(r.getId());
|
// g.supprimerParId(r.getId());
|
||||||
// System.out.println("\nAprès suppression :");
|
// System.out.println("\nAprès suppression :");
|
||||||
|
|
||||||
// for (Rappel x : g.lister()) {
|
// for (Rappel x : g.lister()) {
|
||||||
// System.out.println(" - " + x);
|
// System.out.println(" - " + x);
|
||||||
|
|
||||||
// }
|
// }
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
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<String> lister() throws SQLException {
|
|
||||||
String sql = "SELECT id, titre, theme, rang FROM rappel ORDER BY id DESC";
|
|
||||||
List<String> 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user