From 37f6961afe8785496eb7244e1b321ee92a260ef5 Mon Sep 17 00:00:00 2001 From: hulivet1 Date: Mon, 17 Oct 2022 09:30:45 +0200 Subject: [PATCH 1/4] =?UTF-8?q?D=C3=A9tection=20de=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Code/IHM/App.xaml.cs | 2 ++ .../Converters/Func2WindowPartConverter.cs | 28 +++++++++++++++++++ Code/IHM/MainWindow.xaml.cs | 3 +- Code/LinqToPgSQL/PersLinqToPgSQL.cs | 3 +- Code/Model/Stub.cs | 2 ++ 5 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 Code/IHM/Converters/Func2WindowPartConverter.cs diff --git a/Code/IHM/App.xaml.cs b/Code/IHM/App.xaml.cs index d606932..c799256 100644 --- a/Code/IHM/App.xaml.cs +++ b/Code/IHM/App.xaml.cs @@ -16,5 +16,7 @@ namespace IHM public partial class App : Application { public Manager AllInscrits { get; private set; } = new Manager(new LinqToPgSQL.PersLinqToPgSQL()); + //public Manager AllInscrits { get; private set; } = new Manager(new Stub()); + } } diff --git a/Code/IHM/Converters/Func2WindowPartConverter.cs b/Code/IHM/Converters/Func2WindowPartConverter.cs new file mode 100644 index 0000000..d825da7 --- /dev/null +++ b/Code/IHM/Converters/Func2WindowPartConverter.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Controls; +using System.Windows.Data; + +namespace IHM.Converters +{ + public class Func2WindowPartConverter : IValueConverter + { + public object? Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + Func? windowPartCreator = value as Func; + if (windowPartCreator == null) + { + return null; + } + return windowPartCreator(); + } + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Code/IHM/MainWindow.xaml.cs b/Code/IHM/MainWindow.xaml.cs index 7fb459a..568fc61 100644 --- a/Code/IHM/MainWindow.xaml.cs +++ b/Code/IHM/MainWindow.xaml.cs @@ -61,7 +61,8 @@ namespace IHM private void test_Click(object sender, RoutedEventArgs e) { - testSelect(); + //testSelect(); } + } } diff --git a/Code/LinqToPgSQL/PersLinqToPgSQL.cs b/Code/LinqToPgSQL/PersLinqToPgSQL.cs index a7306e1..53d3ecc 100644 --- a/Code/LinqToPgSQL/PersLinqToPgSQL.cs +++ b/Code/LinqToPgSQL/PersLinqToPgSQL.cs @@ -33,7 +33,8 @@ namespace LinqToPgSQL var conn = new NpgsqlConnection(connString); Console.Out.WriteLine("Ouverture de la connection"); - conn.Open(); + conn.Open();//gérer l'exception ! + //pb de pare-feu a l'iut var AllInscrit = new NpgsqlCommand("SELECT * FROM Inscrit", conn); diff --git a/Code/Model/Stub.cs b/Code/Model/Stub.cs index 1a671fb..42b3df6 100644 --- a/Code/Model/Stub.cs +++ b/Code/Model/Stub.cs @@ -12,6 +12,8 @@ namespace Model public List Inscrits = new(); public List Comptes = new(); + + // ajouter load all pour tout les inscrits public List LoadInscrit() From 5b996f98f0b9b7f056af29977de0ff93fb3a6a4c Mon Sep 17 00:00:00 2001 From: nimaye Date: Mon, 17 Oct 2022 09:49:12 +0200 Subject: [PATCH 2/4] gestion de l'exception --- Code/LinqToPgSQL/PersLinqToPgSQL.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Code/LinqToPgSQL/PersLinqToPgSQL.cs b/Code/LinqToPgSQL/PersLinqToPgSQL.cs index 9c5d4c6..ccaad1d 100644 --- a/Code/LinqToPgSQL/PersLinqToPgSQL.cs +++ b/Code/LinqToPgSQL/PersLinqToPgSQL.cs @@ -32,8 +32,17 @@ namespace LinqToPgSQL List ListeInscrits = new List(); var conn = new NpgsqlConnection(connString); - Console.Out.WriteLine("Ouverture de la connection"); - conn.Open(); + Console.Out.WriteLine("Ouverture de la connection"); try + { + conn.Open(); + } + catch + { + conn.Close(); + Environment.Exit(0); + + } + var AllInscrit = new NpgsqlCommand("SELECT * FROM Inscrit", conn); From c8291716ac18be651540a80f2ac633bf1c72a891 Mon Sep 17 00:00:00 2001 From: Hug0lvt Date: Tue, 18 Oct 2022 22:55:49 +0200 Subject: [PATCH 3/4] =?UTF-8?q?Patch=20bug=20du=20premier=20=C3=A9l=C3=A9m?= =?UTF-8?q?ent=20de=20la=20base=20manquant?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Code/LinqToPgSQL/PersLinqToPgSQL.cs | 182 +++++++++++++--------------- 1 file changed, 86 insertions(+), 96 deletions(-) diff --git a/Code/LinqToPgSQL/PersLinqToPgSQL.cs b/Code/LinqToPgSQL/PersLinqToPgSQL.cs index ccaad1d..17ba8e1 100644 --- a/Code/LinqToPgSQL/PersLinqToPgSQL.cs +++ b/Code/LinqToPgSQL/PersLinqToPgSQL.cs @@ -1,37 +1,38 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Npgsql; -using Model; -using System.IO; - -namespace LinqToPgSQL -{ - public class PersLinqToPgSQL : IPersistanceManager - { - private static string Host = "90.114.135.116"; - private static string User = "postgres"; - private static string DBname = "conseco"; - private static string Password = "lulu"; - private static string Port = "5432"; - - string connString = - String.Format( - "Server={0};Username={1};Database={2};Port={3};Password={4};SSLMode=Prefer", - Host, - User, - DBname, - Port, - Password); - - public PersLinqToPgSQL() { } - public IEnumerable LoadInscrit() - { - List ListeInscrits = new List(); - - var conn = new NpgsqlConnection(connString); +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Npgsql; +using Model; +using System.IO; +using System.Diagnostics; + +namespace LinqToPgSQL +{ + public class PersLinqToPgSQL : IPersistanceManager + { + private static string Host = "90.114.135.116"; + private static string User = "postgres"; + private static string DBname = "conseco"; + private static string Password = "lulu"; + private static string Port = "5432"; + + string connString = + String.Format( + "Server={0};Username={1};Database={2};Port={3};Password={4};SSLMode=Prefer", + Host, + User, + DBname, + Port, + Password); + + public PersLinqToPgSQL() { } + public IEnumerable LoadInscrit() + { + List ListeInscrits = new List(); + + var conn = new NpgsqlConnection(connString); Console.Out.WriteLine("Ouverture de la connection"); try { conn.Open(); @@ -41,65 +42,54 @@ namespace LinqToPgSQL conn.Close(); Environment.Exit(0); - } - - - var AllInscrit = new NpgsqlCommand("SELECT * FROM Inscrit", conn); - - var reader = AllInscrit.ExecuteReader(); - while (reader.Read()) - { - Console.WriteLine( - string.Format( - "({0}, {1}, {2}, {3}, {4}", - reader.GetString(0), - reader.GetString(1), - reader.GetString(2), - reader.GetString(3), - reader.GetString(4) - /*reader.GetInt32(2).ToString()*/ - ) - ); - foreach (var EltInscrit in reader) - { - ListeInscrits.Add(new(reader.GetString(0), reader.GetString(1), reader.GetString(3), reader.GetString(2), reader.GetString(4))); - } - - - } - reader.Close(); - - 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 DEVISEINSCRIT WHERE idInscrit=(@p2)"; - - using (var command1 = new NpgsqlCommand(requeteFKey, conn)) - { - command1.Parameters.AddWithValue("p2", i.Id); - await command1.ExecuteNonQueryAsync(); - } - - using (var command = new NpgsqlCommand(requete, conn)) - { - command.Parameters.AddWithValue("p", i.Id); - await command.ExecuteNonQueryAsync(); - } - - - - } - } -} + } + + + + + + + NpgsqlDataReader dbReader = new NpgsqlCommand("SELECT * FROM Inscrit", conn).ExecuteReader(); + + while (dbReader.Read()) + { + + ListeInscrits.Add(new Inscrit(dbReader.GetString(0), dbReader.GetString(1), dbReader.GetString(2), dbReader.GetString(3), dbReader.GetString(4))); + } + + dbReader.Close(); + + 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 DEVISEINSCRIT WHERE idInscrit=(@p2)"; + + using (var command1 = new NpgsqlCommand(requeteFKey, conn)) + { + command1.Parameters.AddWithValue("p2", i.Id); + await command1.ExecuteNonQueryAsync(); + } + + using (var command = new NpgsqlCommand(requete, conn)) + { + command.Parameters.AddWithValue("p", i.Id); + await command.ExecuteNonQueryAsync(); + } + + + + } + } +} From 1c39f4b4022d9b15611e7ac8c69f4a9c18211e66 Mon Sep 17 00:00:00 2001 From: nimaye Date: Wed, 19 Oct 2022 08:28:00 +0200 Subject: [PATCH 4/4] modification de la surchage du constructeur inscrit --- Code/IHM/MainWindow.xaml.cs | 2 +- Code/LinqToPgSQL/PersLinqToPgSQL.cs | 6 ++---- Code/Model/Inscrit.cs | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Code/IHM/MainWindow.xaml.cs b/Code/IHM/MainWindow.xaml.cs index e6e57b6..09786c4 100644 --- a/Code/IHM/MainWindow.xaml.cs +++ b/Code/IHM/MainWindow.xaml.cs @@ -39,7 +39,7 @@ namespace IHM { - MessageBox.Show($"{i.Id} + {i.Nom} + {i.Mdp} + {i.Mail} + {i.Dev}"); + MessageBox.Show($"{i.Id} + {i.Nom} + {i.Prenom} + {i.Mail} + {i.Mdp}"); } diff --git a/Code/LinqToPgSQL/PersLinqToPgSQL.cs b/Code/LinqToPgSQL/PersLinqToPgSQL.cs index 17ba8e1..1eb575d 100644 --- a/Code/LinqToPgSQL/PersLinqToPgSQL.cs +++ b/Code/LinqToPgSQL/PersLinqToPgSQL.cs @@ -44,10 +44,6 @@ namespace LinqToPgSQL } - - - - NpgsqlDataReader dbReader = new NpgsqlCommand("SELECT * FROM Inscrit", conn).ExecuteReader(); @@ -55,7 +51,9 @@ namespace LinqToPgSQL { ListeInscrits.Add(new Inscrit(dbReader.GetString(0), dbReader.GetString(1), dbReader.GetString(2), dbReader.GetString(3), dbReader.GetString(4))); + } + dbReader.Close(); diff --git a/Code/Model/Inscrit.cs b/Code/Model/Inscrit.cs index 4a495fa..c952c38 100644 --- a/Code/Model/Inscrit.cs +++ b/Code/Model/Inscrit.cs @@ -10,7 +10,7 @@ namespace Model public class Inscrit { - public Inscrit(string id, string nom, string mail, string prenom, string mdp) + public Inscrit(string id, string nom, string prenom, string mail, string mdp) { Id = id; Nom = nom;