113 lines
4.2 KiB
C#
113 lines
4.2 KiB
C#
#region Ressources extérieures
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Data.SqlTypes;
|
|
using ProjetTheAlone.Classes;
|
|
#endregion
|
|
|
|
namespace ProjetTheAlone.Acces
|
|
{
|
|
/// <summary>
|
|
/// Couche d'accès aux données (Data Access Layer)
|
|
/// </summary>
|
|
public class A_T_beneficiaire : ADBase
|
|
{
|
|
#region Constructeurs
|
|
public A_T_beneficiaire(string sChaineConnexion)
|
|
: base(sChaineConnexion)
|
|
{ }
|
|
#endregion
|
|
public int Ajouter(string B_nom, string B_prenom, DateTime? B_anniversaire, byte?[] B_img)
|
|
{
|
|
CreerCommande("AjouterT_beneficiaire");
|
|
int res = 0;
|
|
Commande.Parameters.Add("ID_beneficiaire", SqlDbType.Int);
|
|
Direction("ID_beneficiaire", ParameterDirection.Output);
|
|
if(B_nom == null) Commande.Parameters.AddWithValue("@B_nom", Convert.DBNull);
|
|
else Commande.Parameters.AddWithValue("@B_nom", B_nom);
|
|
if(B_prenom == null) Commande.Parameters.AddWithValue("@B_prenom", Convert.DBNull);
|
|
else Commande.Parameters.AddWithValue("@B_prenom", B_prenom);
|
|
if(B_anniversaire == null) Commande.Parameters.AddWithValue("@B_anniversaire", Convert.DBNull);
|
|
else Commande.Parameters.AddWithValue("@B_anniversaire", B_anniversaire);
|
|
if(B_img == null) Commande.Parameters.AddWithValue("@B_img", Convert.DBNull);
|
|
else Commande.Parameters.AddWithValue("@B_img", B_img);
|
|
Commande.Connection.Open();
|
|
Commande.ExecuteNonQuery();
|
|
res = int.Parse(LireParametre("ID_beneficiaire"));
|
|
Commande.Connection.Close();
|
|
return res;
|
|
}
|
|
public int Modifier(int ID_beneficiaire, string B_nom, string B_prenom, DateTime? B_anniversaire, byte?[] B_img)
|
|
{
|
|
CreerCommande("ModifierT_beneficiaire");
|
|
int res = 0;
|
|
Commande.Parameters.AddWithValue("@ID_beneficiaire", ID_beneficiaire);
|
|
if(B_nom == null) Commande.Parameters.AddWithValue("@B_nom", Convert.DBNull);
|
|
else Commande.Parameters.AddWithValue("@B_nom", B_nom);
|
|
if(B_prenom == null) Commande.Parameters.AddWithValue("@B_prenom", Convert.DBNull);
|
|
else Commande.Parameters.AddWithValue("@B_prenom", B_prenom);
|
|
if(B_anniversaire == null) Commande.Parameters.AddWithValue("@B_anniversaire", Convert.DBNull);
|
|
else Commande.Parameters.AddWithValue("@B_anniversaire", B_anniversaire);
|
|
if(B_img == null) Commande.Parameters.AddWithValue("@B_img", Convert.DBNull);
|
|
else Commande.Parameters.AddWithValue("@B_img", B_img);
|
|
Commande.Connection.Open();
|
|
Commande.ExecuteNonQuery();
|
|
Commande.Connection.Close();
|
|
return res;
|
|
}
|
|
public List<C_T_beneficiaire> Lire(string Index)
|
|
{
|
|
CreerCommande("SelectionnerT_beneficiaire");
|
|
Commande.Parameters.AddWithValue("@Index", Index);
|
|
Commande.Connection.Open();
|
|
SqlDataReader dr = Commande.ExecuteReader();
|
|
List<C_T_beneficiaire> res = new List<C_T_beneficiaire>();
|
|
while (dr.Read())
|
|
{
|
|
C_T_beneficiaire tmp = new C_T_beneficiaire();
|
|
tmp.ID_beneficiaire = int.Parse(dr["ID_beneficiaire"].ToString());
|
|
tmp.B_nom = dr["B_nom"].ToString();
|
|
tmp.B_prenom = dr["B_prenom"].ToString();
|
|
if(dr["B_anniversaire"] != DBNull.Value) tmp.B_anniversaire = DateTime.Parse(dr["B_anniversaire"].ToString());
|
|
tmp.B_img = dr["B_img"];
|
|
res.Add(tmp);
|
|
}
|
|
dr.Close();
|
|
Commande.Connection.Close();
|
|
return res;
|
|
}
|
|
public C_T_beneficiaire Lire_ID(int ID_beneficiaire)
|
|
{
|
|
CreerCommande("SelectionnerT_beneficiaire_ID");
|
|
Commande.Parameters.AddWithValue("@ID_beneficiaire", ID_beneficiaire);
|
|
Commande.Connection.Open();
|
|
SqlDataReader dr = Commande.ExecuteReader();
|
|
C_T_beneficiaire res = new C_T_beneficiaire();
|
|
while (dr.Read())
|
|
{
|
|
res.ID_beneficiaire = int.Parse(dr["ID_beneficiaire"].ToString());
|
|
res.B_nom = dr["B_nom"].ToString();
|
|
res.B_prenom = dr["B_prenom"].ToString();
|
|
if(dr["B_anniversaire"] != DBNull.Value) res.B_anniversaire = DateTime.Parse(dr["B_anniversaire"].ToString());
|
|
res.B_img = (byte?[])dr["B_img"];
|
|
}
|
|
dr.Close();
|
|
Commande.Connection.Close();
|
|
return res;
|
|
}
|
|
public int Supprimer(int ID_beneficiaire)
|
|
{
|
|
CreerCommande("SupprimerT_beneficiaire");
|
|
int res = 0;
|
|
Commande.Parameters.AddWithValue("@ID_beneficiaire", ID_beneficiaire);
|
|
Commande.Connection.Open();
|
|
res = Commande.ExecuteNonQuery();
|
|
Commande.Connection.Close();
|
|
return res;
|
|
}
|
|
}
|
|
}
|