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 diff --git a/Code/IHM/MainWindow.xaml.cs b/Code/IHM/MainWindow.xaml.cs index 09786c4..1bcdaec 100644 --- a/Code/IHM/MainWindow.xaml.cs +++ b/Code/IHM/MainWindow.xaml.cs @@ -59,10 +59,25 @@ namespace IHM MessageBox.Show("Suppression ok"); } + 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 f83b4ac..1273a0d 100644 --- a/Code/LinqToPgSQL/PersLinqToPgSQL.cs +++ b/Code/LinqToPgSQL/PersLinqToPgSQL.cs @@ -64,8 +64,40 @@ 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) { /*List ListeInscrits = new List(LoadInscrit());*/ @@ -88,7 +120,30 @@ namespace LinqToPgSQL SupprimerEcheancierBdd(i); SupprimerPlanificationBdd(i); */ + using (var command = new NpgsqlCommand(requete, conn)) + { + command.Parameters.AddWithValue("p", i.Id); + await command.ExecuteNonQueryAsync(); + } + } + + public async void SupprimerBanqueBdd(Inscrit i, Banque b) + { + var conn = new NpgsqlConnection(connString); + Console.Out.WriteLine("Ouverture de la connection"); + conn.Open(); + + await using var cmd = new NpgsqlCommand("DELETE FROM InscrBanque WHERE nombanque=(@b) AND idinscrit=(@i)", conn) + { + 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 fe3121c..949073d 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(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 7e86094..d50c340 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(Inscrit i, Banque b) + { + Pers.SupprimerBanqueBdd(i, b); + } + /* public void supprimerInscritBdd(Inscrit i) {