Mise en place de la persistance + modification du manager + liaison de la badd pgsql avec l'application
continuous-integration/drone/push Build is passing Details

connexion
Nicolas MAYE 2 years ago
parent c48b6e2438
commit 47e8c4dcf9

@ -14,7 +14,7 @@ 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}") = "LinqToSql", "LinqToSql\LinqToSql.csproj", "{1F51162A-1232-42E1-A2C3-B19D96905696}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LinqToPgSQL", "LinqToPgSQL\LinqToPgSQL.csproj", "{4A9DB718-B874-4565-87B0-57C73B9BE240}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -38,10 +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
{1F51162A-1232-42E1-A2C3-B19D96905696}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {4A9DB718-B874-4565-87B0-57C73B9BE240}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1F51162A-1232-42E1-A2C3-B19D96905696}.Debug|Any CPU.Build.0 = Debug|Any CPU {4A9DB718-B874-4565-87B0-57C73B9BE240}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1F51162A-1232-42E1-A2C3-B19D96905696}.Release|Any CPU.ActiveCfg = Release|Any CPU {4A9DB718-B874-4565-87B0-57C73B9BE240}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F51162A-1232-42E1-A2C3-B19D96905696}.Release|Any CPU.Build.0 = 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,6 @@ namespace IHM
/// </summary> /// </summary>
public partial class App : Application public partial class App : Application
{ {
public Manager AllInscrits { get; private set; } = new Manager(new LinqToPgSQL.PersLinqToPgSQL());
} }
} }

@ -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,8 @@
mc:Ignorable="d" mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800"> Title="MainWindow" Height="450" Width="800">
<Grid> <Grid>
<Button x:Name="test2" Content="Button" HorizontalAlignment="Left" Margin="411,167,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,37 @@ namespace IHM
/// </summary> /// </summary>
public partial class MainWindow : Window public partial class MainWindow : Window
{ {
public Manager ListedesInscrits => ((App)Application.Current).AllInscrits;
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
ListedesInscrits.LoadInscrit();
DataContext = ListedesInscrits;
}
public void test()
{
foreach (Inscrit i in ListedesInscrits.ListedesInscrits)
{
if(i.Nom == "YOUVOI")
{
MessageBox.Show($"{i.Id} + {i.Nom} + {i.Mdp} + {i.Mail} + {i.Dev}");
}
}
}
private void test_Click(object sender, RoutedEventArgs e)
{
test();
} }
} }
} }

@ -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,69 @@
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<Inscrit> LoadInscrit()
{
List<Inscrit> ListeInscrits = new List<Inscrit>();
var conn = new NpgsqlConnection(connString);
Console.Out.WriteLine("Ouverture de la connection");
conn.Open();
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.GetString(5)*/
/*reader.GetInt32(2).ToString()*/
)
);
foreach (var EltInscrit in reader)
{
ListeInscrits.Add(new(reader.GetString(0), reader.GetString(1), reader.GetString(2), reader.GetString(3), reader.GetString(4)));
}
}
reader.Close();
return ListeInscrits;
}
}
}

@ -1,14 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.0.1" />
</ItemGroup>
</Project>

@ -1,46 +0,0 @@
using System;
using Microsoft.Data.SqlClient;
using System.Text;
namespace sqltest
{
class Program
{
static void Main(string[] args)
{
try
{
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = "<your_server>.database.windows.net";
builder.UserID = "<your_username>";
builder.Password = "<your_password>";
builder.InitialCatalog = "<your_database>";
using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
{
Console.WriteLine("\nQuery data example:");
Console.WriteLine("=========================================\n");
String sql = "SELECT name, collation_name FROM sys.databases";
using (SqlCommand command = new SqlCommand(sql, connection))
{
connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine("{0} {1}", reader.GetString(0), reader.GetString(1));
}
}
}
}
}
catch (SqlException e)
{
Console.WriteLine(e.ToString());
}
Console.ReadLine();
}
}
}

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model
{
public interface IPersistanceManager
{
IEnumerable<Inscrit> LoadInscrit();
}
}

@ -9,6 +9,19 @@ namespace Model
{ {
public class Inscrit public class Inscrit
{ {
public Inscrit(string id, string nom, string mail, string prenom, string mdp)
{
Id = id;
Nom = nom;
Mail = mail;
Prenom = prenom;
Mdp = mdp;
}
public Inscrit(string id, string nom, string mail, string prenom, string mdp, double soldeTotal) public Inscrit(string id, string nom, string mail, string prenom, string mdp, double soldeTotal)
{ {
Id = id; Id = id;

@ -10,11 +10,14 @@ namespace Model
{ {
public class Manager : INotifyPropertyChanged public class Manager : INotifyPropertyChanged
{ {
public Manager() { }
public event PropertyChangedEventHandler? PropertyChanged;
public IReadOnlyCollection<Inscrit> ListedesInscrits { get; private set; } public IReadOnlyCollection<Inscrit> ListedesInscrits { get; private set; }
private List<Inscrit> TousLesInscrits { get; set; } = new List<Inscrit>(); private List<Inscrit> TousLesInscrits { get; set; } = new List<Inscrit>();
public event PropertyChangedEventHandler? PropertyChanged; public IPersistanceManager Pers { get; private set; }
void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
public Inscrit SelectedInscrits public Inscrit SelectedInscrits
@ -22,7 +25,7 @@ namespace Model
get => selectedInscrits; get => selectedInscrits;
set set
{ {
if(selectedInscrits != value) if (selectedInscrits != value)
{ {
selectedInscrits = value; selectedInscrits = value;
OnPropertyChanged(nameof(SelectedInscrits)); OnPropertyChanged(nameof(SelectedInscrits));
@ -31,22 +34,23 @@ namespace Model
} }
private Inscrit selectedInscrits; private Inscrit selectedInscrits;
public Manager(IReadOnlyCollection<Inscrit> listedesInscrits, List<Inscrit> tousLesInscrits, Inscrit selectedInscrits) void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
public void LoadInscrit()
{ {
ListedesInscrits = listedesInscrits; TousLesInscrits.Clear();
TousLesInscrits = tousLesInscrits; TousLesInscrits.AddRange(Pers.LoadInscrit());
this.selectedInscrits = selectedInscrits; if (TousLesInscrits.Count > 0)
SelectedInscrits = TousLesInscrits.First();
} }
/*En attente de la persistance*/ public Manager(IPersistanceManager persistance)
/* public Manager(IPersistanceManager persistance)
{ {
ListedesInscrits = new ReadOnlyCollection<Inscrit>(TousLesInscrits); ListedesInscrits = new ReadOnlyCollection<Inscrit>(TousLesInscrits);
persistance = persistance; Pers = persistance;
}*/ }
} }

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