ProjetThe/ProjetTheAlone/Model/A_T_repa.cs

101 lines
3.3 KiB
C#
Raw Normal View History

2019-01-18 13:08:55 +01:00
#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_repa : ADBase
{
#region Constructeurs
public A_T_repa(string sChaineConnexion)
: base(sChaineConnexion)
{ }
#endregion
public int Ajouter(int? ID_listPlat, int? ID_typeRepa)
{
CreerCommande("AjouterT_repa");
int res = 0;
Commande.Parameters.Add("ID_repa", SqlDbType.Int);
Direction("ID_repa", ParameterDirection.Output);
if(ID_listPlat == null) Commande.Parameters.AddWithValue("@ID_listPlat", Convert.DBNull);
else Commande.Parameters.AddWithValue("@ID_listPlat", ID_listPlat);
if(ID_typeRepa == null) Commande.Parameters.AddWithValue("@ID_typeRepa", Convert.DBNull);
else Commande.Parameters.AddWithValue("@ID_typeRepa", ID_typeRepa);
Commande.Connection.Open();
Commande.ExecuteNonQuery();
res = int.Parse(LireParametre("ID_repa"));
Commande.Connection.Close();
return res;
}
public int Modifier(int ID_repa, int? ID_listPlat, int? ID_typeRepa)
{
CreerCommande("ModifierT_repa");
int res = 0;
Commande.Parameters.AddWithValue("@ID_repa", ID_repa);
if(ID_listPlat == null) Commande.Parameters.AddWithValue("@ID_listPlat", Convert.DBNull);
else Commande.Parameters.AddWithValue("@ID_listPlat", ID_listPlat);
if(ID_typeRepa == null) Commande.Parameters.AddWithValue("@ID_typeRepa", Convert.DBNull);
else Commande.Parameters.AddWithValue("@ID_typeRepa", ID_typeRepa);
Commande.Connection.Open();
Commande.ExecuteNonQuery();
Commande.Connection.Close();
return res;
}
public List<C_T_repa> Lire(string Index)
{
CreerCommande("SelectionnerT_repa");
Commande.Parameters.AddWithValue("@Index", Index);
Commande.Connection.Open();
SqlDataReader dr = Commande.ExecuteReader();
List<C_T_repa> res = new List<C_T_repa>();
while (dr.Read())
{
C_T_repa tmp = new C_T_repa();
tmp.ID_repa = int.Parse(dr["ID_repa"].ToString());
if(dr["ID_listPlat"] != DBNull.Value) tmp.ID_listPlat = int.Parse(dr["ID_listPlat"].ToString());
if(dr["ID_typeRepa"] != DBNull.Value) tmp.ID_typeRepa = int.Parse(dr["ID_typeRepa"].ToString());
res.Add(tmp);
}
dr.Close();
Commande.Connection.Close();
return res;
}
public C_T_repa Lire_ID(int ID_repa)
{
CreerCommande("SelectionnerT_repa_ID");
Commande.Parameters.AddWithValue("@ID_repa", ID_repa);
Commande.Connection.Open();
SqlDataReader dr = Commande.ExecuteReader();
C_T_repa res = new C_T_repa();
while (dr.Read())
{
res.ID_repa = int.Parse(dr["ID_repa"].ToString());
if(dr["ID_listPlat"] != DBNull.Value) res.ID_listPlat = int.Parse(dr["ID_listPlat"].ToString());
if(dr["ID_typeRepa"] != DBNull.Value) res.ID_typeRepa = int.Parse(dr["ID_typeRepa"].ToString());
}
dr.Close();
Commande.Connection.Close();
return res;
}
public int Supprimer(int ID_repa)
{
CreerCommande("SupprimerT_repa");
int res = 0;
Commande.Parameters.AddWithValue("@ID_repa", ID_repa);
Commande.Connection.Open();
res = Commande.ExecuteNonQuery();
Commande.Connection.Close();
return res;
}
}
}