95 lines
2.6 KiB
C#
95 lines
2.6 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_lieu : ADBase
|
||
|
{
|
||
|
#region Constructeurs
|
||
|
public A_T_lieu(string sChaineConnexion)
|
||
|
: base(sChaineConnexion)
|
||
|
{ }
|
||
|
#endregion
|
||
|
public int Ajouter(string L_nom)
|
||
|
{
|
||
|
CreerCommande("AjouterT_lieu");
|
||
|
int res = 0;
|
||
|
Commande.Parameters.Add("ID_lieu", SqlDbType.Int);
|
||
|
Direction("ID_lieu", ParameterDirection.Output);
|
||
|
if(L_nom == null) Commande.Parameters.AddWithValue("@L_nom", Convert.DBNull);
|
||
|
else Commande.Parameters.AddWithValue("@L_nom", L_nom);
|
||
|
Commande.Connection.Open();
|
||
|
Commande.ExecuteNonQuery();
|
||
|
res = int.Parse(LireParametre("ID_lieu"));
|
||
|
Commande.Connection.Close();
|
||
|
return res;
|
||
|
}
|
||
|
public int Modifier(int ID_lieu, string L_nom)
|
||
|
{
|
||
|
CreerCommande("ModifierT_lieu");
|
||
|
int res = 0;
|
||
|
Commande.Parameters.AddWithValue("@ID_lieu", ID_lieu);
|
||
|
if(L_nom == null) Commande.Parameters.AddWithValue("@L_nom", Convert.DBNull);
|
||
|
else Commande.Parameters.AddWithValue("@L_nom", L_nom);
|
||
|
Commande.Connection.Open();
|
||
|
Commande.ExecuteNonQuery();
|
||
|
Commande.Connection.Close();
|
||
|
return res;
|
||
|
}
|
||
|
public List<C_T_lieu> Lire(string Index)
|
||
|
{
|
||
|
CreerCommande("SelectionnerT_lieu");
|
||
|
Commande.Parameters.AddWithValue("@Index", Index);
|
||
|
Commande.Connection.Open();
|
||
|
SqlDataReader dr = Commande.ExecuteReader();
|
||
|
List<C_T_lieu> res = new List<C_T_lieu>();
|
||
|
while (dr.Read())
|
||
|
{
|
||
|
C_T_lieu tmp = new C_T_lieu();
|
||
|
tmp.ID_lieu = int.Parse(dr["ID_lieu"].ToString());
|
||
|
if(dr["L_nom"] != DBNull.Value) tmp.L_nom = (dr["L_nom"].ToString());
|
||
|
res.Add(tmp);
|
||
|
}
|
||
|
dr.Close();
|
||
|
Commande.Connection.Close();
|
||
|
return res;
|
||
|
}
|
||
|
public C_T_lieu Lire_ID(int ID_lieu)
|
||
|
{
|
||
|
CreerCommande("SelectionnerT_lieu_ID");
|
||
|
Commande.Parameters.AddWithValue("@ID_lieu", ID_lieu);
|
||
|
Commande.Connection.Open();
|
||
|
SqlDataReader dr = Commande.ExecuteReader();
|
||
|
C_T_lieu res = new C_T_lieu();
|
||
|
while (dr.Read())
|
||
|
{
|
||
|
res.ID_lieu = int.Parse(dr["ID_lieu"].ToString());
|
||
|
if(dr["L_nom"] != DBNull.Value) res.L_nom = (dr["L_nom"].ToString());
|
||
|
}
|
||
|
dr.Close();
|
||
|
Commande.Connection.Close();
|
||
|
return res;
|
||
|
}
|
||
|
public int Supprimer(int ID_lieu)
|
||
|
{
|
||
|
CreerCommande("SupprimerT_lieu");
|
||
|
int res = 0;
|
||
|
Commande.Parameters.AddWithValue("@ID_lieu", ID_lieu);
|
||
|
Commande.Connection.Open();
|
||
|
res = Commande.ExecuteNonQuery();
|
||
|
Commande.Connection.Close();
|
||
|
return res;
|
||
|
}
|
||
|
}
|
||
|
}
|