|
|
@ -1,37 +1,38 @@
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Npgsql;
|
|
|
|
using Npgsql;
|
|
|
|
using Model;
|
|
|
|
using Model;
|
|
|
|
using System.IO;
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
namespace LinqToPgSQL
|
|
|
|
|
|
|
|
{
|
|
|
|
namespace LinqToPgSQL
|
|
|
|
public class PersLinqToPgSQL : IPersistanceManager
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class PersLinqToPgSQL : IPersistanceManager
|
|
|
|
private static string Host = "90.114.135.116";
|
|
|
|
{
|
|
|
|
private static string User = "postgres";
|
|
|
|
private static string Host = "90.114.135.116";
|
|
|
|
private static string DBname = "conseco";
|
|
|
|
private static string User = "postgres";
|
|
|
|
private static string Password = "lulu";
|
|
|
|
private static string DBname = "conseco";
|
|
|
|
private static string Port = "5432";
|
|
|
|
private static string Password = "lulu";
|
|
|
|
|
|
|
|
private static string Port = "5432";
|
|
|
|
string connString =
|
|
|
|
|
|
|
|
String.Format(
|
|
|
|
string connString =
|
|
|
|
"Server={0};Username={1};Database={2};Port={3};Password={4};SSLMode=Prefer",
|
|
|
|
String.Format(
|
|
|
|
Host,
|
|
|
|
"Server={0};Username={1};Database={2};Port={3};Password={4};SSLMode=Prefer",
|
|
|
|
User,
|
|
|
|
Host,
|
|
|
|
DBname,
|
|
|
|
User,
|
|
|
|
Port,
|
|
|
|
DBname,
|
|
|
|
Password);
|
|
|
|
Port,
|
|
|
|
|
|
|
|
Password);
|
|
|
|
public PersLinqToPgSQL() { }
|
|
|
|
|
|
|
|
public IEnumerable<Inscrit> LoadInscrit()
|
|
|
|
public PersLinqToPgSQL() { }
|
|
|
|
{
|
|
|
|
public IEnumerable<Inscrit> LoadInscrit()
|
|
|
|
List<Inscrit> ListeInscrits = new List<Inscrit>();
|
|
|
|
{
|
|
|
|
|
|
|
|
List<Inscrit> ListeInscrits = new List<Inscrit>();
|
|
|
|
var conn = new NpgsqlConnection(connString);
|
|
|
|
|
|
|
|
|
|
|
|
var conn = new NpgsqlConnection(connString);
|
|
|
|
Console.Out.WriteLine("Ouverture de la connection"); try
|
|
|
|
Console.Out.WriteLine("Ouverture de la connection"); try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
conn.Open();
|
|
|
|
conn.Open();
|
|
|
@ -41,65 +42,54 @@ namespace LinqToPgSQL
|
|
|
|
conn.Close();
|
|
|
|
conn.Close();
|
|
|
|
Environment.Exit(0);
|
|
|
|
Environment.Exit(0);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var AllInscrit = new NpgsqlCommand("SELECT * FROM Inscrit", conn);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var reader = AllInscrit.ExecuteReader();
|
|
|
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
|
|
|
{
|
|
|
|
NpgsqlDataReader dbReader = new NpgsqlCommand("SELECT * FROM Inscrit", conn).ExecuteReader();
|
|
|
|
Console.WriteLine(
|
|
|
|
|
|
|
|
string.Format(
|
|
|
|
while (dbReader.Read())
|
|
|
|
"({0}, {1}, {2}, {3}, {4}",
|
|
|
|
{
|
|
|
|
reader.GetString(0),
|
|
|
|
|
|
|
|
reader.GetString(1),
|
|
|
|
ListeInscrits.Add(new Inscrit(dbReader.GetString(0), dbReader.GetString(1), dbReader.GetString(2), dbReader.GetString(3), dbReader.GetString(4)));
|
|
|
|
reader.GetString(2),
|
|
|
|
}
|
|
|
|
reader.GetString(3),
|
|
|
|
|
|
|
|
reader.GetString(4)
|
|
|
|
dbReader.Close();
|
|
|
|
/*reader.GetInt32(2).ToString()*/
|
|
|
|
|
|
|
|
)
|
|
|
|
return ListeInscrits;
|
|
|
|
);
|
|
|
|
}
|
|
|
|
foreach (var EltInscrit in reader)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ListeInscrits.Add(new(reader.GetString(0), reader.GetString(1), reader.GetString(3), reader.GetString(2), reader.GetString(4)));
|
|
|
|
/*Revoir la BDD, probleme de clé étrangère de devise*/
|
|
|
|
}
|
|
|
|
public async void SupprimerInscritBdd(Inscrit i)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
/*List<Inscrit> ListeInscrits = new List<Inscrit>(LoadInscrit());*/
|
|
|
|
}
|
|
|
|
|
|
|
|
reader.Close();
|
|
|
|
var conn = new NpgsqlConnection(connString);
|
|
|
|
|
|
|
|
Console.Out.WriteLine("Ouverture de la connection");
|
|
|
|
return ListeInscrits;
|
|
|
|
conn.Open();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string requete = $"DELETE FROM INSCRIT WHERE id=(@p)";
|
|
|
|
/*Revoir la BDD, probleme de clé étrangère de devise*/
|
|
|
|
string requeteFKey = $"DELETE FROM DEVISEINSCRIT WHERE idInscrit=(@p2)";
|
|
|
|
public async void SupprimerInscritBdd(Inscrit i)
|
|
|
|
|
|
|
|
{
|
|
|
|
using (var command1 = new NpgsqlCommand(requeteFKey, conn))
|
|
|
|
/*List<Inscrit> ListeInscrits = new List<Inscrit>(LoadInscrit());*/
|
|
|
|
{
|
|
|
|
|
|
|
|
command1.Parameters.AddWithValue("p2", i.Id);
|
|
|
|
var conn = new NpgsqlConnection(connString);
|
|
|
|
await command1.ExecuteNonQueryAsync();
|
|
|
|
Console.Out.WriteLine("Ouverture de la connection");
|
|
|
|
}
|
|
|
|
conn.Open();
|
|
|
|
|
|
|
|
|
|
|
|
using (var command = new NpgsqlCommand(requete, conn))
|
|
|
|
|
|
|
|
{
|
|
|
|
string requete = $"DELETE FROM INSCRIT WHERE id=(@p)";
|
|
|
|
command.Parameters.AddWithValue("p", i.Id);
|
|
|
|
string requeteFKey = $"DELETE FROM DEVISEINSCRIT WHERE idInscrit=(@p2)";
|
|
|
|
await command.ExecuteNonQueryAsync();
|
|
|
|
|
|
|
|
}
|
|
|
|
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();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|