119 lines
4.9 KiB
C#
119 lines
4.9 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_event : ADBase
|
|
{
|
|
#region Constructeurs
|
|
public A_T_event(string sChaineConnexion)
|
|
: base(sChaineConnexion)
|
|
{ }
|
|
#endregion
|
|
public int Ajouter(DateTime? E_date, DateTime? E_duree, int? ID_typeEvenement,string E_description, int? ID_lieu)
|
|
{
|
|
CreerCommande("AjouterT_event");
|
|
int res = 0;
|
|
Commande.Parameters.Add("ID_event", SqlDbType.Int);
|
|
Direction("ID_event", ParameterDirection.Output);
|
|
if(E_date == null) Commande.Parameters.AddWithValue("@E_date", Convert.DBNull);
|
|
else Commande.Parameters.AddWithValue("@E_date", E_date);
|
|
if(E_duree == null) Commande.Parameters.AddWithValue("@E_duree", Convert.DBNull);
|
|
else Commande.Parameters.AddWithValue("@E_duree", E_duree);
|
|
if(ID_typeEvenement == null) Commande.Parameters.AddWithValue("@ID_typeEvenement", Convert.DBNull);
|
|
else Commande.Parameters.AddWithValue("@ID_typeEvenement", ID_typeEvenement);
|
|
if(E_description == null) Commande.Parameters.AddWithValue("@E_description", Convert.DBNull);
|
|
else Commande.Parameters.AddWithValue("@E_description", E_description);
|
|
if(ID_lieu == null) Commande.Parameters.AddWithValue("@ID_lieu", Convert.DBNull);
|
|
else Commande.Parameters.AddWithValue("@ID_lieu", ID_lieu);
|
|
Commande.Connection.Open();
|
|
Commande.ExecuteNonQuery();
|
|
res = int.Parse(LireParametre("ID_event"));
|
|
Commande.Connection.Close();
|
|
return res;
|
|
}
|
|
public int Modifier(int ID_event, DateTime? E_date, DateTime? E_duree, int? ID_typeEvenement, string E_description, int? ID_lieu)
|
|
{
|
|
CreerCommande("ModifierT_event");
|
|
int res = 0;
|
|
Commande.Parameters.AddWithValue("@ID_event", ID_event);
|
|
if(E_date == null) Commande.Parameters.AddWithValue("@E_date", Convert.DBNull);
|
|
else Commande.Parameters.AddWithValue("@E_date", E_date);
|
|
if(E_duree == null) Commande.Parameters.AddWithValue("@E_duree", Convert.DBNull);
|
|
else Commande.Parameters.AddWithValue("@E_duree", E_duree);
|
|
if(ID_typeEvenement == null) Commande.Parameters.AddWithValue("@ID_typeEvenement", Convert.DBNull);
|
|
else Commande.Parameters.AddWithValue("@ID_typeEvenement", ID_typeEvenement);
|
|
if(E_description == null) Commande.Parameters.AddWithValue("@E_description", Convert.DBNull);
|
|
else Commande.Parameters.AddWithValue("@E_description", E_description);
|
|
if(ID_lieu == null) Commande.Parameters.AddWithValue("@ID_lieu", Convert.DBNull);
|
|
else Commande.Parameters.AddWithValue("@ID_lieu", ID_lieu);
|
|
Commande.Connection.Open();
|
|
Commande.ExecuteNonQuery();
|
|
Commande.Connection.Close();
|
|
return res;
|
|
}
|
|
public List<C_T_event> Lire(string Index)
|
|
{
|
|
CreerCommande("SelectionnerT_event");
|
|
Commande.Parameters.AddWithValue("@Index", Index);
|
|
Commande.Connection.Open();
|
|
SqlDataReader dr = Commande.ExecuteReader();
|
|
List<C_T_event> res = new List<C_T_event>();
|
|
while (dr.Read())
|
|
{
|
|
C_T_event tmp = new C_T_event();
|
|
tmp.ID_event = int.Parse(dr["ID_event"].ToString());
|
|
if(dr["E_date"] != DBNull.Value) tmp.E_date = DateTime.Parse(dr["E_date"].ToString());
|
|
if(dr["E_duree"] != DBNull.Value) tmp.E_duree = DateTime.Parse(dr["E_duree"].ToString());
|
|
if(dr["ID_typeEvenement"] != DBNull.Value) tmp.ID_typeEvenement = int.Parse(dr["ID_typeEvenement"].ToString());
|
|
if(dr["E_description"] != DBNull.Value) tmp.E_description = (dr["E_description"].ToString());
|
|
if(dr["ID_lieu"] != DBNull.Value) tmp.ID_lieu = int.Parse(dr["ID_lieu"].ToString());
|
|
res.Add(tmp);
|
|
}
|
|
dr.Close();
|
|
Commande.Connection.Close();
|
|
return res;
|
|
}
|
|
public C_T_event Lire_ID(int ID_event)
|
|
{
|
|
CreerCommande("SelectionnerT_event_ID");
|
|
Commande.Parameters.AddWithValue("@ID_event", ID_event);
|
|
Commande.Connection.Open();
|
|
SqlDataReader dr = Commande.ExecuteReader();
|
|
C_T_event res = new C_T_event();
|
|
while (dr.Read())
|
|
{
|
|
res.ID_event = int.Parse(dr["ID_event"].ToString());
|
|
if(dr["E_date"] != DBNull.Value) res.E_date = DateTime.Parse(dr["E_date"].ToString());
|
|
if(dr["E_duree"] != DBNull.Value) res.E_duree = DateTime.Parse(dr["E_duree"].ToString());
|
|
if(dr["ID_typeEvenement"] != DBNull.Value) res.ID_typeEvenement = int.Parse(dr["ID_typeEvenement"].ToString());
|
|
if(dr["E_description"] != DBNull.Value) res.E_description = (dr["E_description"].ToString());
|
|
if(dr["ID_lieu"] != DBNull.Value) res.ID_lieu = int.Parse(dr["ID_lieu"].ToString());
|
|
}
|
|
dr.Close();
|
|
Commande.Connection.Close();
|
|
return res;
|
|
}
|
|
public int Supprimer(int ID_event)
|
|
{
|
|
CreerCommande("SupprimerT_event");
|
|
int res = 0;
|
|
Commande.Parameters.AddWithValue("@ID_event", ID_event);
|
|
Commande.Connection.Open();
|
|
res = Commande.ExecuteNonQuery();
|
|
Commande.Connection.Close();
|
|
return res;
|
|
}
|
|
}
|
|
}
|