From 58e1f540a3b3da7146e23bc7fbcb277eb084ffe6 Mon Sep 17 00:00:00 2001 From: Nicolas MAYE Date: Sat, 15 Oct 2022 22:31:45 +0100 Subject: [PATCH] ajout fonction de suppression d'identifiant dans la bdd (en attente de modification des tables) --- Code/IHM/MainWindow.xaml.cs | 27 ++++++++++++++-------- Code/LinqToPgSQL/PersLinqToPgSQL.cs | 35 +++++++++++++++++++++++++---- Code/Model/IPersistanceManager.cs | 1 + Code/Model/Inscrit.cs | 6 +++-- Code/Model/Manager.cs | 11 +++++++++ 5 files changed, 65 insertions(+), 15 deletions(-) diff --git a/Code/IHM/MainWindow.xaml.cs b/Code/IHM/MainWindow.xaml.cs index 9239b99..7fb459a 100644 --- a/Code/IHM/MainWindow.xaml.cs +++ b/Code/IHM/MainWindow.xaml.cs @@ -23,6 +23,7 @@ namespace IHM public partial class MainWindow : Window { public Manager ListedesInscrits => ((App)Application.Current).AllInscrits; + public MainWindow() { InitializeComponent(); @@ -32,27 +33,35 @@ namespace IHM } - public void test() + public void testSelect() { foreach (Inscrit i in ListedesInscrits.ListedesInscrits) { - if(i.Nom == "YOUVOI") - { - MessageBox.Show($"{i.Id} + {i.Nom} + {i.Mdp} + {i.Mail} + {i.Dev}"); - } + + + MessageBox.Show($"{i.Id} + {i.Nom} + {i.Mdp} + {i.Mail} + {i.Dev}"); + } } - private void test_Click(object sender, RoutedEventArgs e) + public void testSuppression() { + foreach (Inscrit i in ListedesInscrits.ListedesInscrits) + { + if (i.Nom == "YOUVOI") + { + ListedesInscrits.supprimerInscritBdd(i); + } - test(); - - + } + } + private void test_Click(object sender, RoutedEventArgs e) + { + testSelect(); } } } diff --git a/Code/LinqToPgSQL/PersLinqToPgSQL.cs b/Code/LinqToPgSQL/PersLinqToPgSQL.cs index 2255c03..a7306e1 100644 --- a/Code/LinqToPgSQL/PersLinqToPgSQL.cs +++ b/Code/LinqToPgSQL/PersLinqToPgSQL.cs @@ -42,28 +42,55 @@ namespace LinqToPgSQL { Console.WriteLine( string.Format( - "({0}, {1}, {2}, {3}, {4})", + "({0}, {1}, {2}, {3}, {4}", reader.GetString(0), reader.GetString(1), reader.GetString(2), reader.GetString(3), reader.GetString(4) - /*reader.GetString(5)*/ /*reader.GetInt32(2).ToString()*/ ) ); foreach (var EltInscrit in reader) { - ListeInscrits.Add(new(reader.GetString(0), reader.GetString(1), reader.GetString(2), reader.GetString(3), reader.GetString(4))); + ListeInscrits.Add(new(reader.GetString(0), reader.GetString(1), reader.GetString(3), reader.GetString(2), reader.GetString(4))); } } reader.Close(); + return ListeInscrits; + } - return ListeInscrits; + /*Revoir la BDD, probleme de clé étrangère de devise*/ + public async void SupprimerInscritBdd(Inscrit i) + { + /*List ListeInscrits = new List(LoadInscrit());*/ + + var conn = new NpgsqlConnection(connString); + Console.Out.WriteLine("Ouverture de la connection"); + conn.Open(); + + + string requete = $"DELETE FROM INSCRIT WHERE id=(@p)"; + string requeteFKey = $"DELETE FROM DEVISE WHERE id=(@p2)"; + + using (var command1 = new NpgsqlCommand(requeteFKey, conn)) + { + command1.Parameters.AddWithValue("p2", i.Dev); + await command1.ExecuteNonQueryAsync(); + } + + using (var command = new NpgsqlCommand(requete, conn)) + { + command.Parameters.AddWithValue("p", i.Id); + await command.ExecuteNonQueryAsync(); + } + + + } } } diff --git a/Code/Model/IPersistanceManager.cs b/Code/Model/IPersistanceManager.cs index f5a8a75..fe3121c 100644 --- a/Code/Model/IPersistanceManager.cs +++ b/Code/Model/IPersistanceManager.cs @@ -9,5 +9,6 @@ namespace Model public interface IPersistanceManager { IEnumerable LoadInscrit(); + void SupprimerInscritBdd(Inscrit inscrit); } } diff --git a/Code/Model/Inscrit.cs b/Code/Model/Inscrit.cs index fcac7ae..4a495fa 100644 --- a/Code/Model/Inscrit.cs +++ b/Code/Model/Inscrit.cs @@ -17,9 +17,9 @@ namespace Model Mail = mail; Prenom = prenom; Mdp = mdp; - + } - + public Inscrit(string id, string nom, string mail, string prenom, string mdp, double soldeTotal) @@ -50,6 +50,8 @@ namespace Model public Devises Dev { get; private set; } public List LesBanques { get; private set; } = new List(); + + public void ajouterBanque(Banque banque) { LesBanques.Add(banque); diff --git a/Code/Model/Manager.cs b/Code/Model/Manager.cs index b1d16e7..7e86094 100644 --- a/Code/Model/Manager.cs +++ b/Code/Model/Manager.cs @@ -52,6 +52,17 @@ namespace Model Pers = persistance; } + public void supprimerInscritBdd(Inscrit i) + { + Pers.SupprimerInscritBdd(i); + } + + /* public void supprimerInscritBdd(Inscrit i) + { + + + }*/ + }