nouvelle branche connexion
continuous-integration/drone/push Build is passing Details

connexion
Lucas EVARD 2 years ago
parent 1c39f4b402
commit 9c2913d709

@ -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());
}

@ -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.Id} + {Manager.SelectedInscrits.Nom} + {Manager.SelectedInscrits.Prenom} + {Manager.SelectedInscrits.Mail} + {Manager.SelectedInscrits.Mdp}");
}
public void testSuppression()
{
foreach (Inscrit i in ListedesInscrits.ListedesInscrits)
{
if (i.Nom == "YOUVOI")
{
ListedesInscrits.supprimerInscritBdd(i);
}
}
MessageBox.Show("Suppression ok");
}

@ -18,21 +18,12 @@ namespace LinqToPgSQL
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={0};Username{1};Database{2};Port{3};Password{4};SSLMode=Prefer",Host,User,DBname,Port,Password);
public Inscrit LoadInscrit()
{
List<Inscrit> ListeInscrits = new List<Inscrit>();
var conn = new NpgsqlConnection(connString);
int t = 0;
Inscrit i=null;
var conn = new NpgsqlConnection(connexionBDD);
Console.Out.WriteLine("Ouverture de la connection"); try
{
conn.Open();
@ -41,23 +32,15 @@ namespace LinqToPgSQL
{
conn.Close();
Environment.Exit(0);
}
NpgsqlDataReader dbReader = new NpgsqlCommand("SELECT * FROM Inscrit", conn).ExecuteReader();
while (dbReader.Read())
{
ListeInscrits.Add(new Inscrit(dbReader.GetString(0), dbReader.GetString(1), dbReader.GetString(2), dbReader.GetString(3), dbReader.GetString(4)));
t++;
i=new Inscrit(dbReader.GetString(0), dbReader.GetString(1), dbReader.GetString(2), dbReader.GetString(3), dbReader.GetString(4));
}
dbReader.Close();
return ListeInscrits;
return i;
}
@ -66,28 +49,21 @@ namespace LinqToPgSQL
{
/*List<Inscrit> ListeInscrits = new List<Inscrit>(LoadInscrit());*/
var conn = new NpgsqlConnection(connString);
var conn = new NpgsqlConnection(connexionBDD);
Console.Out.WriteLine("Ouverture de la connection");
conn.Open();
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("p2", i.Id);
await command1.ExecuteNonQueryAsync();
}
using (var command = new NpgsqlCommand(requete, conn))
{
command.Parameters.AddWithValue("p", i.Id);
await command.ExecuteNonQueryAsync();
}
}
}
}

@ -8,7 +8,7 @@ namespace Model
{
public interface IPersistanceManager
{
IEnumerable<Inscrit> LoadInscrit();
Inscrit LoadInscrit();
void SupprimerInscritBdd(Inscrit inscrit);
}
}

@ -10,16 +10,8 @@ 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 IPersistanceManager Pers { get; private set; }
public Inscrit SelectedInscrits
{
get => selectedInscrits;
@ -33,22 +25,11 @@ namespace Model
}
}
private Inscrit selectedInscrits;
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 Manager(IPersistanceManager persistance)
{
ListedesInscrits = new ReadOnlyCollection<Inscrit>(TousLesInscrits);
SelectedInscrits = persistance.LoadInscrit();
Pers = persistance;
}

Loading…
Cancel
Save