From f34ab4444f8de794fd06e7608599fd98677917e6 Mon Sep 17 00:00:00 2001 From: Vincent ASTOLFI Date: Wed, 19 Oct 2022 06:56:29 +0200 Subject: [PATCH] ajout supression des banques --- Code/IHM/MainWindow.xaml.cs | 5 +++++ Code/LinqToPgSQL/PersLinqToPgSQL.cs | 22 +++++++++++++++++++++ Code/Model/IPersistanceManager.cs | 2 ++ Code/Model/Manager.cs | 30 +++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+) diff --git a/Code/IHM/MainWindow.xaml.cs b/Code/IHM/MainWindow.xaml.cs index a6ea73f..4fe0295 100644 --- a/Code/IHM/MainWindow.xaml.cs +++ b/Code/IHM/MainWindow.xaml.cs @@ -59,6 +59,11 @@ namespace IHM MessageBox.Show("Suppression ok"); } + public void testSupressionBdd(Banque b) + { + + } + private void test_Click(object sender, RoutedEventArgs e) { testSelect(); diff --git a/Code/LinqToPgSQL/PersLinqToPgSQL.cs b/Code/LinqToPgSQL/PersLinqToPgSQL.cs index 9c5d4c6..dc41c6d 100644 --- a/Code/LinqToPgSQL/PersLinqToPgSQL.cs +++ b/Code/LinqToPgSQL/PersLinqToPgSQL.cs @@ -92,5 +92,27 @@ namespace LinqToPgSQL } + + public async void SupprimerBanqueBdd(Banque b) + { + var conn = new NpgsqlConnection(connString); + Console.Out.WriteLine("Ouverture de la connection"); + conn.Open(); + + string requete = $"DELETE FROM Banque WHERE nom=(@n)"; + string requeteFKey = $"DELETE From Compte WHERE nomBanque=(@n2)"; + + using (var commandFKey = new NpgsqlCommand(requeteFKey, conn)) + { + commandFKey.Parameters.AddWithValue("n2", b.Nom); + await commandFKey.ExecuteNonQueryAsync(); + } + + using (var command = new NpgsqlCommand(requete, conn)) + { + command.Parameters.AddWithValue("n", b.Nom); + await command.ExecuteNonQueryAsync(); + } + } } } diff --git a/Code/Model/IPersistanceManager.cs b/Code/Model/IPersistanceManager.cs index fe3121c..a7784aa 100644 --- a/Code/Model/IPersistanceManager.cs +++ b/Code/Model/IPersistanceManager.cs @@ -9,6 +9,8 @@ namespace Model public interface IPersistanceManager { IEnumerable LoadInscrit(); + IEnumerable LoadBanque(); void SupprimerInscritBdd(Inscrit inscrit); + void SupprimerBanqueBdd(Banque banque); } } diff --git a/Code/Model/Manager.cs b/Code/Model/Manager.cs index 7e86094..9e69976 100644 --- a/Code/Model/Manager.cs +++ b/Code/Model/Manager.cs @@ -16,6 +16,8 @@ namespace Model public IReadOnlyCollection ListedesInscrits { get; private set; } private List TousLesInscrits { get; set; } = new List(); + public IReadOnlyCollection ListeDesBanques { get; private set; } + private List TouteLesBanques { get; set; } = new List(); public IPersistanceManager Pers { get; private set; } @@ -34,6 +36,20 @@ namespace Model } private Inscrit selectedInscrits; + public Banque SelectedBanque + { + get => SelectedBanque; + set + { + if(SelectedBanque != value) + { + SelectedBanque = value; + OnPropertyChanged(nameof(SelectedBanque)); + } + } + } + private Banque selectedBanque; + void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); @@ -46,9 +62,18 @@ namespace Model } + public void LoadBanque() + { + TouteLesBanques.Clear(); + TouteLesBanques.AddRange(Pers.LoadBanque()); + if (TouteLesBanques.Count > 0) + SelectedBanque = TouteLesBanques.First(); + } + public Manager(IPersistanceManager persistance) { ListedesInscrits = new ReadOnlyCollection(TousLesInscrits); + ListeDesBanques = new ReadOnlyCollection(TouteLesBanques); Pers = persistance; } @@ -57,6 +82,11 @@ namespace Model Pers.SupprimerInscritBdd(i); } + public void supprimerBanqueBdd(Banque b) + { + Pers.SupprimerBanqueBdd(b); + } + /* public void supprimerInscritBdd(Inscrit i) {