Fusion de Connexion dans Npgsql
continuous-integration/drone/push Build is failing Details

Link_to_npgsql
Hug0lvt 2 years ago
commit 65caf7d7b2

@ -15,7 +15,7 @@ namespace IHM
/// </summary>
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());
}

@ -7,7 +7,12 @@
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Button x:Name="test2" Content="Button" HorizontalAlignment="Left" Margin="411,167,0,0" VerticalAlignment="Top" Click="test_Click"/>
<TextBlock Name="idpers" Text="null"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBox Name="id" Height="100" Width="200" Text="OUIOUIOUI"/>
<TextBox Name="mdp" Height="100" Width="200" Text="OUIOUIOUI"/>
</StackPanel>
<Button x:Name="test2" Content="Button" HorizontalAlignment="Center" Margin="0,320,0,0" VerticalAlignment="Top" Click="test_Click"/>
</Grid>

@ -22,40 +22,21 @@ namespace IHM
/// </summary>
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 = "";
}
}

@ -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<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)
{
List<Inscrit> ListeInscrits = new List<Inscrit>();
var conn = new NpgsqlConnection(connString);
string resultat="";
var conn = new NpgsqlConnection(connexionBDD);
Console.Out.WriteLine("Ouverture de la connection");
try
{
conn.Open();
}
catch
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.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)
{
/*List<Inscrit> ListeInscrits = new List<Inscrit>(LoadInscrit());*/
var conn = new NpgsqlConnection(connString);
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();
}
}

@ -8,8 +8,7 @@ namespace Model
{
public interface IPersistanceManager
{
IEnumerable<Inscrit> LoadInscrit();
IEnumerable<Banque> LoadBanque();
string LoadInscrit(string id,string mdp);
void SupprimerInscritBdd(Inscrit inscrit);
void SupprimerBanqueBdd(Inscrit inscrit, Banque banque);
void SupprimerToutesBanquesBdd(Inscrit inscrit);

@ -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<Inscrit> ListedesInscrits { get; private set; }
private List<Inscrit> TousLesInscrits { get; set; } = new List<Inscrit>();
public IReadOnlyCollection<Banque> ListeDesBanques { get; private set; }
private List<Banque> TouteLesBanques { get; set; } = new List<Banque>();
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<Inscrit>(TousLesInscrits);
ListeDesBanques = new ReadOnlyCollection<Banque>(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)

@ -6,4 +6,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Npgsql" Version="6.0.7" />
</ItemGroup>
</Project>

Loading…
Cancel
Save