From f34ab4444f8de794fd06e7608599fd98677917e6 Mon Sep 17 00:00:00 2001 From: Vincent ASTOLFI Date: Wed, 19 Oct 2022 06:56:29 +0200 Subject: [PATCH 1/4] 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) { From e692cbf73e51f0ef446eef447f62fdb2935fbf76 Mon Sep 17 00:00:00 2001 From: Vincent ASTOLFI Date: Thu, 20 Oct 2022 06:50:28 +0200 Subject: [PATCH 2/4] correction de bug lors de la supression de banque --- Code/IHM/MainWindow.xaml.cs | 18 +++++++-- Code/LinqToPgSQL/PersLinqToPgSQL.cs | 62 ++++++++++++++++++++--------- Code/Model/IPersistanceManager.cs | 2 +- Code/Model/Inscrit.cs | 1 + Code/Model/Manager.cs | 4 +- 5 files changed, 62 insertions(+), 25 deletions(-) diff --git a/Code/IHM/MainWindow.xaml.cs b/Code/IHM/MainWindow.xaml.cs index a346163..1bcdaec 100644 --- a/Code/IHM/MainWindow.xaml.cs +++ b/Code/IHM/MainWindow.xaml.cs @@ -59,15 +59,25 @@ namespace IHM MessageBox.Show("Suppression ok"); } - public void testSupressionBdd(Banque b) + public void testSupressionBanqueBdd() { - + foreach (Inscrit i in ListedesInscrits.ListedesInscrits) + { + if(i.Id == "00001") + { + MessageBox.Show("Suppression ok"); + Banque b = new Banque("BNP PARIBAS", "mabanque", "bite"); + ListedesInscrits.supprimerBanqueBdd(i, b); + MessageBox.Show("Suppression ok"); + } + } } private void test_Click(object sender, RoutedEventArgs e) { - testSelect(); - /* testSuppression();*/ + // testSelect(); + // testSuppression(); + testSupressionBanqueBdd(); } } diff --git a/Code/LinqToPgSQL/PersLinqToPgSQL.cs b/Code/LinqToPgSQL/PersLinqToPgSQL.cs index f7f274e..0496ce2 100644 --- a/Code/LinqToPgSQL/PersLinqToPgSQL.cs +++ b/Code/LinqToPgSQL/PersLinqToPgSQL.cs @@ -60,6 +60,38 @@ namespace LinqToPgSQL return ListeInscrits; } + public IEnumerable LoadBanque() + { + List ListeBanques = new List(); + + var conn = new NpgsqlConnection(connString); + Console.Out.WriteLine("Ouverture de la connection"); try + { + conn.Open(); + } + catch + { + conn.Close(); + Environment.Exit(0); + + } + + + NpgsqlDataReader dbReader = new NpgsqlCommand("SELECT * FROM Banque", conn).ExecuteReader(); + + while (dbReader.Read()) + { + + ListeBanques.Add(new Banque(dbReader.GetString(0), dbReader.GetString(1), dbReader.GetString(2))); + + } + + + dbReader.Close(); + + return ListeBanques; + } + /*Revoir la BDD, probleme de clé étrangère de devise*/ public async void SupprimerInscritBdd(Inscrit i) @@ -85,31 +117,25 @@ namespace LinqToPgSQL command.Parameters.AddWithValue("p", i.Id); await command.ExecuteNonQueryAsync(); } - - - } - public async void SupprimerBanqueBdd(Banque b) + public async void SupprimerBanqueBdd(Inscrit i, 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)) + await using var cmd = new NpgsqlCommand("DELETE FROM InscrBanque WHERE nombanque=(@b) AND idinscrit=(@i)", 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(); - } + Parameters = + { + new("b", b.Nom), + new("i", i.Id) + } + }; + await cmd.ExecuteNonQueryAsync(); + + // attente des autres supression } } -} +} \ No newline at end of file diff --git a/Code/Model/IPersistanceManager.cs b/Code/Model/IPersistanceManager.cs index a7784aa..949073d 100644 --- a/Code/Model/IPersistanceManager.cs +++ b/Code/Model/IPersistanceManager.cs @@ -11,6 +11,6 @@ namespace Model IEnumerable LoadInscrit(); IEnumerable LoadBanque(); void SupprimerInscritBdd(Inscrit inscrit); - void SupprimerBanqueBdd(Banque banque); + void SupprimerBanqueBdd(Inscrit inscrit, Banque banque); } } diff --git a/Code/Model/Inscrit.cs b/Code/Model/Inscrit.cs index c952c38..ed5abe8 100644 --- a/Code/Model/Inscrit.cs +++ b/Code/Model/Inscrit.cs @@ -60,6 +60,7 @@ namespace Model public void SupprimerBanque(Banque banque) { LesBanques.Remove(banque); + } public void ChoisirDevise(Devises devise) diff --git a/Code/Model/Manager.cs b/Code/Model/Manager.cs index 9e69976..d50c340 100644 --- a/Code/Model/Manager.cs +++ b/Code/Model/Manager.cs @@ -82,9 +82,9 @@ namespace Model Pers.SupprimerInscritBdd(i); } - public void supprimerBanqueBdd(Banque b) + public void supprimerBanqueBdd(Inscrit i, Banque b) { - Pers.SupprimerBanqueBdd(b); + Pers.SupprimerBanqueBdd(i, b); } /* public void supprimerInscritBdd(Inscrit i) From d79ac4cf32dc534fa15c719c90d7498c62a46887 Mon Sep 17 00:00:00 2001 From: Hugo LIVET Date: Thu, 20 Oct 2022 11:48:18 +0200 Subject: [PATCH 3/4] Ajout de Sonnar --- .drone.yml | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index f2bfbc5..dc9711e 100644 --- a/.drone.yml +++ b/.drone.yml @@ -20,4 +20,24 @@ steps: - cd Code - dotnet restore CI_CONSECO.sln - dotnet test CI_CONSECO.sln --no-restore - depends_on: [build] \ No newline at end of file + depends_on: [build] + - name: code-analysis + image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dronesonarplugin-dotnet6 + commands: + - cd Code/ + - dotnet restore CI_CONSECO.sln + - dotnet sonarscanner begin /k:ConsEco /d:sonar.host.url=$${PLUGIN_SONAR_HOST} /d:sonar.coverageReportPaths="coveragereport/SonarQube.xml" /d:sonar.coverage.exclusions="Tests/**" /d:sonar.login=$${PLUGIN_SONAR_TOKEN} + - dotnet build CI_CONSECO.sln -c Release --no-restore + - dotnet test CI_CONSECO.sln --logger trx --no-restore /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura --collect "XPlat Code Coverage" + - reportgenerator -reports:"**/coverage.cobertura.xml" -reporttypes:SonarQube -targetdir:"coveragereport" + - dotnet publish CI_CONSECO.sln -c Release --no-restore -o CI_PROJECT_DIR/build/release + - dotnet sonarscanner end /d:sonar.login=$${PLUGIN_SONAR_TOKEN} + secrets: [ SECRET_SONAR_LOGIN ] + settings: + # accessible en ligne de commande par ${PLUGIN_SONAR_HOST} + sonar_host: https://codefirst.iut.uca.fr/sonar/ + # accessible en ligne de commande par ${PLUGIN_SONAR_TOKEN} + sonar_token: + from_secret: SECRET_SONAR_LOGIN + depends_on: [tests] + \ No newline at end of file From 5b1a4d0e9a244e125c95faaccbbe5ba09c72dfdc Mon Sep 17 00:00:00 2001 From: Vincent ASTOLFI Date: Thu, 20 Oct 2022 06:55:02 +0200 Subject: [PATCH 4/4] correction bug bdd --- Code/LinqToPgSQL/PersLinqToPgSQL.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/LinqToPgSQL/PersLinqToPgSQL.cs b/Code/LinqToPgSQL/PersLinqToPgSQL.cs index 73dcfd6..93a225e 100644 --- a/Code/LinqToPgSQL/PersLinqToPgSQL.cs +++ b/Code/LinqToPgSQL/PersLinqToPgSQL.cs @@ -111,7 +111,7 @@ namespace LinqToPgSQL using (var command1 = new NpgsqlCommand(requete, conn)) { - command1.Parameters.AddWithValue("p2", i.Id); + command1.Parameters.AddWithValue("p", i.Id); await command1.ExecuteNonQueryAsync(); }