diff --git a/Code/IHM/App.xaml.cs b/Code/IHM/App.xaml.cs
index c799256..87723ac 100644
--- a/Code/IHM/App.xaml.cs
+++ b/Code/IHM/App.xaml.cs
@@ -15,7 +15,7 @@ namespace IHM
///
public partial class App : Application
{
- public Manager AllInscrits { get; private set; } = new Manager(new LinqToPgSQL.PersLinqToPgSQL());
+ public Manager Manager { get; private set; } = new Manager(new LinqToPgSQL.PersLinqToPgSQL());
//public Manager AllInscrits { get; private set; } = new Manager(new Stub());
}
diff --git a/Code/IHM/MainWindow.xaml b/Code/IHM/MainWindow.xaml
index 4a745ad..ecdd3d5 100644
--- a/Code/IHM/MainWindow.xaml
+++ b/Code/IHM/MainWindow.xaml
@@ -7,7 +7,12 @@
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
-
+
+
+
+
+
+
diff --git a/Code/IHM/MainWindow.xaml.cs b/Code/IHM/MainWindow.xaml.cs
index 1bcdaec..d13c1f7 100644
--- a/Code/IHM/MainWindow.xaml.cs
+++ b/Code/IHM/MainWindow.xaml.cs
@@ -22,40 +22,21 @@ namespace IHM
///
public partial class MainWindow : Window
{
- public Manager ListedesInscrits => ((App)Application.Current).AllInscrits;
+ public Manager Manager => ((App)Application.Current).Manager;
public MainWindow()
{
InitializeComponent();
-
- ListedesInscrits.LoadInscrit();
- DataContext = ListedesInscrits;
-
+ DataContext = Manager.SelectedInscrits;
}
public void testSelect()
{
- foreach (Inscrit i in ListedesInscrits.ListedesInscrits)
- {
-
-
- MessageBox.Show($"{i.Id} + {i.Nom} + {i.Prenom} + {i.Mail} + {i.Mdp}");
-
-
- }
-
+ MessageBox.Show($"{Manager.SelectedInscrits}");
}
public void testSuppression()
{
- foreach (Inscrit i in ListedesInscrits.ListedesInscrits)
- {
- if (i.Nom == "YOUVOI")
- {
- ListedesInscrits.supprimerInscritBdd(i);
- }
-
- }
MessageBox.Show("Suppression ok");
}
@@ -75,9 +56,13 @@ namespace IHM
private void test_Click(object sender, RoutedEventArgs e)
{
- // testSelect();
- // testSuppression();
- testSupressionBanqueBdd();
+ Manager.LoadInscrit(id.Text,mdp.Text);
+ if (Manager.SelectedInscrits != null)
+ {
+ idpers.Text = Manager.SelectedInscrits;
+ testSelect();
+ }
+ else idpers.Text = "";
}
}
diff --git a/Code/LinqToPgSQL/PersLinqToPgSQL.cs b/Code/LinqToPgSQL/PersLinqToPgSQL.cs
index 77239b3..330c4b1 100644
--- a/Code/LinqToPgSQL/PersLinqToPgSQL.cs
+++ b/Code/LinqToPgSQL/PersLinqToPgSQL.cs
@@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using System.Data;
+using System.Configuration;
using Npgsql;
using Model;
using System.IO;
@@ -14,49 +16,31 @@ 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()
+ 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)
{
- List ListeInscrits = new List();
-
- var conn = new NpgsqlConnection(connString);
- Console.Out.WriteLine("Ouverture de la connection");
+ string resultat="";
+ var conn = new NpgsqlConnection(connexionBDD);
+ Console.Out.WriteLine("Ouverture de la connection");
+ conn.Open();
+ NpgsqlParameter p1 = new NpgsqlParameter { ParameterName = "p", Value = id };
+ NpgsqlParameter p2 = new NpgsqlParameter { ParameterName = "p2", Value = mdp };
+ NpgsqlCommand cmd = new NpgsqlCommand($"SELECT id FROM INSCRIT WHERE (nom=(@p) OR mail=(@p)) AND mdp=@p2", conn);
+ cmd.Parameters.Add(p1);
+ cmd.Parameters.Add(p2);
+ NpgsqlDataReader dr = cmd.ExecuteReader();
try
{
- conn.Open();
- }
- catch
- {
- conn.Close();
-
- MessageBox.Show("Problème de connection à la base de données. L'application se fermera après fermeture de la fenêtre");
- Environment.Exit(0);
-
+ dr.Read();
+ resultat = dr.GetString(0);
+ dr.Close();
+ return resultat;
}
-
-
- NpgsqlDataReader dbReader = new NpgsqlCommand("SELECT * FROM Inscrit", conn).ExecuteReader();
-
- while (dbReader.Read())
+ catch (Exception ex)
{
-
- ListeInscrits.Add(new Inscrit(dbReader.GetString(0), dbReader.GetString(1), dbReader.GetString(2), dbReader.GetString(3), dbReader.GetString(4)));
-
+ MessageBox.Show(ex+"Utilisateur inconnu");
+ dr.Close();
+ return "null";//a changer doit retester
}
@@ -140,8 +124,9 @@ namespace LinqToPgSQL
/*Suppression d'un inscrit dans la base de données*/
public async void SupprimerInscritBdd(Inscrit i)
{
-
- var conn = new NpgsqlConnection(connString);
+ /*List ListeInscrits = new List(LoadInscrit());*/
+
+ var conn = new NpgsqlConnection(connexionBDD);
Console.Out.WriteLine("Ouverture de la connection");
try
{
@@ -156,8 +141,8 @@ namespace LinqToPgSQL
string requete = $"DELETE FROM INSCRIT WHERE id=(@p)";
-
- using (var command1 = new NpgsqlCommand(requete, conn))
+ string requeteFKey = $"DELETE FROM DEVISEINSCRIT WHERE idInscrit=(@p2)";
+ using (var command1 = new NpgsqlCommand(requeteFKey, conn))
{
command1.Parameters.AddWithValue("p", i.Id);
await command1.ExecuteNonQueryAsync();
@@ -189,8 +174,8 @@ namespace LinqToPgSQL
string requete = $"DELETE * FROM BANQUE b, INSCRBANQUE ib WHERE b.nom=ib.nomBanque AND ib.idInscrit=(@id)";
using (var command1 = new NpgsqlCommand(requete, conn))
{
- command1.Parameters.AddWithValue("id", i.Id.ToString());
- await command1.ExecuteNonQueryAsync();
+ command.Parameters.AddWithValue("p", i.Id);
+ await command.ExecuteNonQueryAsync();
}
}
diff --git a/Code/Model/IPersistanceManager.cs b/Code/Model/IPersistanceManager.cs
index 8ac0500..d313124 100644
--- a/Code/Model/IPersistanceManager.cs
+++ b/Code/Model/IPersistanceManager.cs
@@ -8,8 +8,7 @@ namespace Model
{
public interface IPersistanceManager
{
- IEnumerable LoadInscrit();
- IEnumerable LoadBanque();
+ string LoadInscrit(string id,string mdp);
void SupprimerInscritBdd(Inscrit inscrit);
void SupprimerBanqueBdd(Inscrit inscrit, Banque banque);
void SupprimerToutesBanquesBdd(Inscrit inscrit);
diff --git a/Code/Model/Manager.cs b/Code/Model/Manager.cs
index e24f18f..af552e5 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;
@@ -10,31 +11,9 @@ namespace Model
{
public class Manager : INotifyPropertyChanged
{
- public Manager() { }
-
public event PropertyChangedEventHandler? PropertyChanged;
-
- 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; }
-
-
- public Inscrit SelectedInscrits
- {
- get => selectedInscrits;
- set
- {
- if (selectedInscrits != value)
- {
- selectedInscrits = value;
- OnPropertyChanged(nameof(SelectedInscrits));
- }
- }
- }
- private Inscrit selectedInscrits;
+ public string SelectedInscrits;
public Banque SelectedBanque
{
@@ -52,39 +31,19 @@ namespace Model
void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
-
- public void LoadInscrit()
- {
- TousLesInscrits.Clear();
- TousLesInscrits.AddRange(Pers.LoadInscrit());
- if (TousLesInscrits.Count > 0)
- SelectedInscrits = TousLesInscrits.First();
-
- }
-
- 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;
}
- public void supprimerInscritBdd(Inscrit inscrit)
+ public void SupprimerInscritBdd(Inscrit i)
{
Pers.SupprimerInscritBdd(inscrit);
}
- public void supprimerBanqueBdd(Inscrit inscrit, Banque banque)
+ public void LoadInscrit(string id, string mdp)
{
- Pers.SupprimerBanqueBdd(inscrit, banque);
+ SelectedInscrits = Pers.LoadInscrit(id, mdp);
}
public void supprimerToutesBanquesBdd(Inscrit inscrit)
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
+
+
+
+
diff --git a/Code/TestsUnitaires/TestUnitCompte.cs b/Code/TestsUnitaires/TestUnitCompte.cs
index 739b9f7..2a152c8 100644
--- a/Code/TestsUnitaires/TestUnitCompte.cs
+++ b/Code/TestsUnitaires/TestUnitCompte.cs
@@ -1,35 +1,35 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Model;
-
-namespace TestsUnitaires
-{
- public class TestUnitCompte
- {
- [Fact]
- public void TestConstructeurCompte()
- {
- Compte c1 = new("Livret A", 234);
- Compte c2 = new("&e23R_te7", 1245.34);
- Assert.Equal("Livret A", c1.Nom);
- Assert.Equal("&e23R_te7", c2.Nom);
- Assert.Equal(234, c1.Solde);
- Assert.Equal(1245.34, c2.Solde);
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Model;
+
+namespace TestsUnitaires
+{
+ public class TestUnitCompte
+ {
+ [Fact]
+ public void TestConstructeurCompte()
+ {
+ Compte c1 = new("Livret A", 234);
+ Compte c2 = new("&e23R_te7", 1245.34);
+ Assert.Equal("Livret A", c1.Nom);
+ Assert.Equal("&e23R_te7", c2.Nom);
+ Assert.Equal(234, c1.Solde);
+ Assert.Equal(1245.34, c2.Solde);
}
- [Fact]
- public void testSupprimerBanque()
- {
- Banque bq = new Banque("Crédit Agricole", "https://creditagricole.fr", "https://yt3.ggpht.com/a/AGF-l7_mEfX2eQaGm8GefLOg5ZMRciNw-pESE3gUWg=s900-c-k-c0xffffffff-no-rj-mo");
- Inscrit i1 = new Inscrit("A1001", "Smith", "smith@gmail.com", "luke", "test", 500);
- Assert.NotNull(i1.LesBanques);
- i1.ajouterBanque(bq);
- Assert.Contains(bq, i1.LesBanques);
- i1.SupprimerBanque(bq);
+ [Fact]
+ public void testSupprimerBanque()
+ {
+ Banque bq = new Banque("Crédit Agricole", "https://creditagricole.fr", "https://yt3.ggpht.com/a/AGF-l7_mEfX2eQaGm8GefLOg5ZMRciNw-pESE3gUWg=s900-c-k-c0xffffffff-no-rj-mo");
+ Inscrit i1 = new Inscrit("A1001", "Smith", "smith@gmail.com", "luke", "test", 500);
+ Assert.NotNull(i1.LesBanques);
+ i1.ajouterBanque(bq);
+ Assert.Contains(bq, i1.LesBanques);
+ i1.SupprimerBanque(bq);
Assert.DoesNotContain(bq, i1.LesBanques);
- }
- }
-}
+ }
+ }
+}