From 98c88e43bf82c1127045bb4d92f0e45ac6167ec6 Mon Sep 17 00:00:00 2001 From: luevard Date: Fri, 21 Oct 2022 14:01:06 +0200 Subject: [PATCH] modification loadInsrit --- Code/IHM/MainWindow.xaml.cs | 2 +- Code/LinqToPgSQL/PersLinqToPgSQL.cs | 44 +++++++++++------------------ Code/Model/IPersistanceManager.cs | 2 +- Code/Model/Manager.cs | 27 ++++++------------ Code/Model/Model.csproj | 4 +++ 5 files changed, 30 insertions(+), 49 deletions(-) diff --git a/Code/IHM/MainWindow.xaml.cs b/Code/IHM/MainWindow.xaml.cs index 0de7bd9..3597942 100644 --- a/Code/IHM/MainWindow.xaml.cs +++ b/Code/IHM/MainWindow.xaml.cs @@ -32,7 +32,7 @@ namespace IHM public void testSelect() { - MessageBox.Show($"{Manager.SelectedInscrits.Id} + {Manager.SelectedInscrits.Nom} + {Manager.SelectedInscrits.Prenom} + {Manager.SelectedInscrits.Mail} + {Manager.SelectedInscrits.Mdp}"); + MessageBox.Show($"{Manager.SelectedInscrits}"); } public void testSuppression() diff --git a/Code/LinqToPgSQL/PersLinqToPgSQL.cs b/Code/LinqToPgSQL/PersLinqToPgSQL.cs index 1d6b0ba..41ed0a2 100644 --- a/Code/LinqToPgSQL/PersLinqToPgSQL.cs +++ b/Code/LinqToPgSQL/PersLinqToPgSQL.cs @@ -12,43 +12,30 @@ 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 connexionBDD = String.Format("Server={0};Username{1};Database{2};Port{3};Password{4};SSLMode=Prefer",Host,User,DBname,Port,Password); - public Inscrit LoadInscrit() + string connexionBDD = String.Format("Server=90.114.135.116; Username=postgres; Database=conseco; Port=5432; Password=lulu; SSLMode=Prefer"); + public string LoadInscrit(string id, string mdp) { - int t = 0; - Inscrit i=null; var conn = new NpgsqlConnection(connexionBDD); - Console.Out.WriteLine("Ouverture de la connection"); try - { - conn.Open(); - } - catch - { - conn.Close(); - Environment.Exit(0); - } - NpgsqlDataReader dbReader = new NpgsqlCommand("SELECT * FROM Inscrit", conn).ExecuteReader(); - while (dbReader.Read()) + Console.Out.WriteLine("Ouverture de la connection"); + conn.Open(); + using var cmd = new NpgsqlCommand("SELECT id FROM INSCRIT WHERE (nom=(@p) OR mail=(@p)) AND mdp=@p2",conn) { - t++; - i=new Inscrit(dbReader.GetString(0), dbReader.GetString(1), dbReader.GetString(2), dbReader.GetString(3), dbReader.GetString(4)); - } - dbReader.Close(); - return i; + Parameters = + { + new("p", id), + new("p2", mdp) + } + }; + return cmd.ExecuteNonQuery().ToString(); } + /*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(connexionBDD); Console.Out.WriteLine("Ouverture de la connection"); conn.Open(); @@ -65,5 +52,6 @@ namespace LinqToPgSQL await command.ExecuteNonQueryAsync(); } } + } -} +} \ No newline at end of file diff --git a/Code/Model/IPersistanceManager.cs b/Code/Model/IPersistanceManager.cs index 05e222f..f273ff1 100644 --- a/Code/Model/IPersistanceManager.cs +++ b/Code/Model/IPersistanceManager.cs @@ -8,7 +8,7 @@ namespace Model { public interface IPersistanceManager { - Inscrit LoadInscrit(); + string LoadInscrit(string id,string mdp); void SupprimerInscritBdd(Inscrit inscrit); } } diff --git a/Code/Model/Manager.cs b/Code/Model/Manager.cs index 442672e..aaa2a9b 100644 --- a/Code/Model/Manager.cs +++ b/Code/Model/Manager.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; +using Npgsql; using System.Text; using System.Threading.Tasks; @@ -12,37 +13,25 @@ namespace Model { public event PropertyChangedEventHandler? PropertyChanged; public IPersistanceManager Pers { get; private set; } - public Inscrit SelectedInscrits - { - get => selectedInscrits; - set - { - if (selectedInscrits != value) - { - selectedInscrits = value; - OnPropertyChanged(nameof(SelectedInscrits)); - } - } - } - private Inscrit selectedInscrits; + public string SelectedInscrits; + void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); public Manager(IPersistanceManager persistance) { - SelectedInscrits = persistance.LoadInscrit(); Pers = persistance; } - public void supprimerInscritBdd(Inscrit i) + public void SupprimerInscritBdd(Inscrit i) { Pers.SupprimerInscritBdd(i); } - /* public void supprimerInscritBdd(Inscrit i) - { - + public void LoadInscrit(string id, string mdp) + { + SelectedInscrits = Pers.LoadInscrit(id, mdp); + } - }*/ } diff --git a/Code/Model/Model.csproj b/Code/Model/Model.csproj index bafd05b..1fb252d 100644 --- a/Code/Model/Model.csproj +++ b/Code/Model/Model.csproj @@ -6,4 +6,8 @@ enable + + + +