Fusion de Link_toPgsql dans Code
continuous-integration/drone/push Build is passing Details

Code
Hug0lvt 2 years ago
commit 17301c5ee9

@ -14,6 +14,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestsUnitaires", "TestsUnit
{ACFA83F8-98C8-43AE-9328-B3F751098FFA} = {ACFA83F8-98C8-43AE-9328-B3F751098FFA} {ACFA83F8-98C8-43AE-9328-B3F751098FFA} = {ACFA83F8-98C8-43AE-9328-B3F751098FFA}
EndProjectSection EndProjectSection
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LinqToPgSQL", "LinqToPgSQL\LinqToPgSQL.csproj", "{4A9DB718-B874-4565-87B0-57C73B9BE240}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -36,6 +38,10 @@ Global
{B1AE713C-B5DE-4E81-A33F-818AAD0548A7}.Debug|Any CPU.Build.0 = Debug|Any CPU {B1AE713C-B5DE-4E81-A33F-818AAD0548A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B1AE713C-B5DE-4E81-A33F-818AAD0548A7}.Release|Any CPU.ActiveCfg = Release|Any CPU {B1AE713C-B5DE-4E81-A33F-818AAD0548A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B1AE713C-B5DE-4E81-A33F-818AAD0548A7}.Release|Any CPU.Build.0 = Release|Any CPU {B1AE713C-B5DE-4E81-A33F-818AAD0548A7}.Release|Any CPU.Build.0 = Release|Any CPU
{4A9DB718-B874-4565-87B0-57C73B9BE240}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4A9DB718-B874-4565-87B0-57C73B9BE240}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4A9DB718-B874-4565-87B0-57C73B9BE240}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4A9DB718-B874-4565-87B0-57C73B9BE240}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

@ -5,6 +5,8 @@ using System.Data;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using Model;
using LinqToPgSQL;
namespace IHM namespace IHM
{ {
@ -13,5 +15,8 @@ namespace IHM
/// </summary> /// </summary>
public partial class App : Application public partial class App : Application
{ {
public Manager Manager { get; private set; } = new Manager(new LinqToPgSQL.PersLinqToPgSQL());
//public Manager AllInscrits { get; private set; } = new Manager(new Stub());
} }
} }

@ -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<UserControl>? windowPartCreator = value as Func<UserControl>;
if (windowPartCreator == null)
{
return null;
}
return windowPartCreator();
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

@ -7,4 +7,9 @@
<UseWPF>true</UseWPF> <UseWPF>true</UseWPF>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\LinqToPgSQL\LinqToPgSQL.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup>
</Project> </Project>

@ -7,6 +7,13 @@
mc:Ignorable="d" mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800"> Title="MainWindow" Height="450" Width="800">
<Grid> <Grid>
<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> </Grid>
</Window> </Window>

@ -12,6 +12,8 @@ using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Navigation; using System.Windows.Navigation;
using System.Windows.Shapes; using System.Windows.Shapes;
using LinqToPgSQL;
using Model;
namespace IHM namespace IHM
{ {
@ -20,9 +22,34 @@ namespace IHM
/// </summary> /// </summary>
public partial class MainWindow : Window public partial class MainWindow : Window
{ {
public Manager Manager => ((App)Application.Current).Manager;
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
DataContext = Manager.SelectedInscrits;
} }
public void testSelect()
{
MessageBox.Show($"{Manager.SelectedInscrits}");
}
public void testSuppression()
{
MessageBox.Show("Suppression ok");
}
private void test_Click(object sender, RoutedEventArgs e)
{
Manager.LoadInscrit(id.Text,mdp.Text);
if (Manager.SelectedInscrits != null)
{
idpers.Text = Manager.SelectedInscrits;
testSelect();
}
else idpers.Text = "";
}
} }
} }

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Npgsql" Version="6.0.7" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,207 @@
using System;
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;
using System.Diagnostics;
using System.Windows;
using System.Threading;
namespace LinqToPgSQL
{
public class PersLinqToPgSQL : IPersistanceManager
{
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)
{
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
{
dr.Read();
resultat = dr.GetString(0);
dr.Close();
return resultat;
}
catch (Exception ex)
{
MessageBox.Show(ex+"Utilisateur inconnu");
dr.Close();
return "null";//a changer doit retester
}
}
public IEnumerable<Banque> LoadBanque()
{
List<Banque> ListeBanques = new List<Banque>();
var conn = new NpgsqlConnection(connexionBDD);
Console.Out.WriteLine("Ouverture de la connection");
try
{
conn.Open();
}
catch
{
conn.Close();
MessageBox.Show("Problème de connection à la base de donnée. Aprés fermeture, l'application se fermera automatiquement");
Environment.Exit(-1);
}
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;
}
/*Charge le compte d'un inscrit*/
public IEnumerable<Compte> LoadCompte(Inscrit i)
{
List<Compte> ListeCompte = new List<Compte>();
var conn = new NpgsqlConnection(connexionBDD);
Console.Out.WriteLine("Ouverture de la connection");
try
{
conn.Open();
}
catch
{
conn.Close();
MessageBox.Show("Problème de connection à la base de données. Aprés fermeture, l'application se fermera automatiquement.");
Environment.Exit(-1);
}
string requete = "Select * FROM Compte c, InscrBanque ib, Inscrit i WHERE c.idInscrit = ib.idInscrit AND c.idInscritBanque = ib.id AND i.id = (@p1)";
NpgsqlDataReader dbReader = new NpgsqlCommand("Select * FROM Compte c, InscrBanque ib, Inscrit i WHERE c.idInscrit = ib.idInscrit AND c.idInscritBanque = ib.id AND i.id = (@p1) ", conn).ExecuteReader();
using (var command1 = new NpgsqlCommand(requete, conn))
{
command1.Parameters.AddWithValue("p", i.Id);
/*await command1.ExecuteNonQueryAsync();*/
}
while (dbReader.Read())
{
ListeCompte.Add(new Compte(dbReader.GetString(0), dbReader.GetInt64(1)));
}
dbReader.Close();
return ListeCompte;
}
/*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(connexionBDD);
Console.Out.WriteLine("Ouverture de la connection");
try
{
conn.Open();
}
catch
{
conn.Close();
MessageBox.Show("Problème de connection à la base de données. Aprés fermeture, l'application se fermera automatiquement.");
Environment.Exit(-1);
}
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("p", i.Id);
await command1.ExecuteNonQueryAsync();
}
SupprimerToutesBanquesBdd(i);
/* SupprimerCompteBdd(i);
SupprimerEcheancierBdd(i);
SupprimerPlanificationBdd(i);
*/
}
/* Suppression de toutes les banques d'un inscrit*/
public async void SupprimerToutesBanquesBdd(Inscrit i)
{
var conn = new NpgsqlConnection(connexionBDD);
Console.Out.WriteLine("Ouverture de la connection");
try
{
conn.Open();
}
catch
{
conn.Close();
MessageBox.Show("Problème de connection ave la base de données. Aprés fermeture de la fenêtre, l'application se fermera automatiquement");
Environment.Exit(-1);
}
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("p", i.Id);
await command1.ExecuteNonQueryAsync();
}
}
/*Suppression d'une banque d'un inscrit*/
public async void SupprimerBanqueBdd(Inscrit i, Banque b)
{
var conn = new NpgsqlConnection(connexionBDD);
Console.Out.WriteLine("Ouverture de la connection");
try
{
conn.Open();
}
catch
{
conn.Close();
MessageBox.Show("Problème de connection avec la base de données. Aprés fermeture de la fenêtre, l'application se fermera automatiquement");
Environment.Exit(-1);
}
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
}
}
}

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model
{
public interface IPersistanceManager
{
string LoadInscrit(string id,string mdp);
void SupprimerInscritBdd(Inscrit inscrit);
void SupprimerBanqueBdd(Inscrit inscrit, Banque banque);
void SupprimerToutesBanquesBdd(Inscrit inscrit);
}
}

@ -75,6 +75,8 @@ namespace Model
LesBanques = lesbanques; LesBanques = lesbanques;
} }
public void ajouterBanque(Banque banque) public void ajouterBanque(Banque banque)
{ {
LesBanques.Add(banque); LesBanques.Add(banque);
@ -83,6 +85,7 @@ namespace Model
public void SupprimerBanque(Banque banque) public void SupprimerBanque(Banque banque)
{ {
LesBanques.Remove(banque); LesBanques.Remove(banque);
} }
public void ChoisirDevise(Devises devise) public void ChoisirDevise(Devises devise)

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
using Npgsql;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -10,43 +11,45 @@ namespace Model
{ {
public class Manager : INotifyPropertyChanged public class Manager : INotifyPropertyChanged
{ {
public IReadOnlyCollection<Inscrit> ListedesInscrits { get; private set; }
private List<Inscrit> TousLesInscrits { get; set; } = new List<Inscrit>();
public event PropertyChangedEventHandler? PropertyChanged; public event PropertyChangedEventHandler? PropertyChanged;
void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); public IPersistanceManager Pers { get; private set; }
public string SelectedInscrits;
public Inscrit SelectedInscrits public Banque SelectedBanque
{ {
get => selectedInscrits; get => selectedBanque;
set set
{ {
if(selectedInscrits != value) if(selectedBanque != value)
{ {
selectedInscrits = value; selectedBanque = value;
OnPropertyChanged(nameof(SelectedInscrits)); OnPropertyChanged(nameof(selectedBanque));
} }
} }
} }
private Inscrit selectedInscrits; private Banque selectedBanque;
public Manager(IReadOnlyCollection<Inscrit> listedesInscrits, List<Inscrit> tousLesInscrits, Inscrit selectedInscrits) void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
public Manager(IPersistanceManager persistance)
{ {
ListedesInscrits = listedesInscrits; Pers = persistance;
TousLesInscrits = tousLesInscrits;
this.selectedInscrits = selectedInscrits;
} }
/*En attente de la persistance*/ public void SupprimerInscritBdd(Inscrit i)
{
Pers.SupprimerInscritBdd(i);
}
/* public Manager(IPersistanceManager persistance) public void LoadInscrit(string id, string mdp)
{ {
ListedesInscrits = new ReadOnlyCollection<Inscrit>(TousLesInscrits); SelectedInscrits = Pers.LoadInscrit(id, mdp);
persistance = persistance; }
}*/
public void supprimerToutesBanquesBdd(Inscrit inscrit)
{
Pers.SupprimerToutesBanquesBdd(inscrit);
}
} }

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

@ -12,11 +12,18 @@ namespace Model
public List<Inscrit> Inscrits = new(); public List<Inscrit> Inscrits = new();
public List<Compte> Comptes = new(); public List<Compte> Comptes = new();
// ajouter load all pour tout les inscrits // ajouter load all pour tout les inscrits
public List<Inscrit> LoadInscrit() public List<Inscrit> LoadInscrit()
{ {
Inscrits.Add(new("00001", "Evard", "lucasevard@gmail.com","Lucas","test",10,LoadBanques())); Inscrits.Add(new("00001", "Evard", "lucasevard@gmail.com","Lucas","test",10,LoadBanques()));
Inscrits.Add(new("00002", "Livet", "hugolivet@gmail.com", "Hugo", "test", 110,LoadBanques())); Inscrits.Add(new("00002", "Livet", "hugolivet@gmail.com", "Hugo", "test", 280,LoadBanques()));
Inscrits.Add(new("00003", "Smith", "smith@gmail.com", "Luke", "test", 150,LoadBanques()));
Inscrits.Add(new("00004", "Jean", "jean@gmail.com", "sylvain", "test", 410,LoadBanques()));
Inscrits.Add(new("00005", "Franc", "franc@gmail.com", "Julie", "test", 820,LoadBanques()));
Inscrits.Add(new("00006", "March", "march@gmail.com", "bastien", "test", 1120,LoadBanques()));
return Inscrits; return Inscrits;
} }
public List<Banque> LoadBanques() public List<Banque> LoadBanques()
@ -27,10 +34,13 @@ namespace Model
} }
public List<Compte> LoadCompte() public List<Compte> LoadCompte()
{ {
Comptes.Add(new("Livret A", 2)); Comptes.Add(new("Livret A", 1500));
Comptes.Add(new("Compte Cheque", 2000)); Comptes.Add(new("Compte Courant", 2000));
Comptes.Add(new("PEL", 22000));
return Comptes; return Comptes;
} }
} }
} }

@ -0,0 +1,6 @@
[.ShellClassInfo]
IconResource=C:\WINDOWS\System32\SHELL32.dll,294
[ViewState]
Mode=
Vid=
FolderType=Generic
Loading…
Cancel
Save