ProjetThe/ProjetTheAlone/Model - Copie/A_T_listPlat.cs

118 lines
3.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_listPlat : ADBase
{
#region Constructeurs
public A_T_listPlat(string sChaineConnexion)
: base(sChaineConnexion)
{ }
#endregion
public int Ajouter(DateTime LP_DatePlat, int ID_plat)
{
CreerCommande("AjouterT_listPlat");
int res = 0;
Commande.Parameters.Add("ID_listPlat", SqlDbType.Int);
Direction("ID_listPlat", ParameterDirection.Output);
Commande.Parameters.AddWithValue("@LP_DatePlat", LP_DatePlat);
Commande.Parameters.AddWithValue("@ID_plat", ID_plat);
Commande.Connection.Open();
Commande.ExecuteNonQuery();
res = int.Parse(LireParametre("ID_listPlat"));
Commande.Connection.Close();
return res;
}
public int Modifier(int ID_listPlat, DateTime LP_DatePlat, int ID_plat)
{
CreerCommande("ModifierT_listPlat");
int res = 0;
Commande.Parameters.AddWithValue("@ID_listPlat", ID_listPlat);
Commande.Parameters.AddWithValue("@LP_DatePlat", LP_DatePlat);
Commande.Parameters.AddWithValue("@ID_plat", ID_plat);
Commande.Connection.Open();
Commande.ExecuteNonQuery();
Commande.Connection.Close();
return res;
}
public List<C_T_listPlat> Lire(string Index)
{
CreerCommande("SelectionnerT_listPlat");
Commande.Parameters.AddWithValue("@Index", Index);
Commande.Connection.Open();
SqlDataReader dr = Commande.ExecuteReader();
List<C_T_listPlat> res = new List<C_T_listPlat>();
while (dr.Read())
{
C_T_listPlat tmp = new C_T_listPlat();
tmp.ID_listPlat = int.Parse(dr["ID_listPlat"].ToString());
tmp.ID_repa = int.Parse(dr["ID_repa"].ToString());
tmp.ID_plat = int.Parse(dr["ID_plat"].ToString());
res.Add(tmp);
}
dr.Close();
Commande.Connection.Close();
return res;
}
public C_T_listPlat Lire_ID(int ID_listPlat)
{
CreerCommande("SelectionnerT_listPlat_ID");
Commande.Parameters.AddWithValue("@ID_listPlat", ID_listPlat);
Commande.Connection.Open();
SqlDataReader dr = Commande.ExecuteReader();
C_T_listPlat res = new C_T_listPlat();
while (dr.Read())
{
res.ID_listPlat = int.Parse(dr["ID_listPlat"].ToString());
res.ID_repa = int.Parse(dr["ID_repa"].ToString());
res.ID_plat = int.Parse(dr["ID_plat"].ToString());
}
dr.Close();
Commande.Connection.Close();
return res;
}
public List<C_T_plat> Lire(DateTime LP_DateRepas)
{
CreerCommande("SelectRepaByDate");
Commande.Parameters.AddWithValue("@dateV", LP_DateRepas);
Commande.Connection.Open();
SqlDataReader dr = Commande.ExecuteReader();
List<C_T_plat> res = new List<C_T_plat>();
while (dr.Read())
{
C_T_plat tmp = new C_T_plat();
tmp.ID_plat = int.Parse(dr["ID_plat"].ToString());
if (dr["P_nom"] != DBNull.Value) tmp.P_nom = (dr["P_nom"].ToString());
if (dr["P_img"] != DBNull.Value) tmp.P_img = Outil.toNullableByteArray.Convert((byte[])dr["P_img"]);
var x = dr["ID_typePlat"];
if (dr["ID_typePlat"] != DBNull.Value) tmp.ID_typePlat = (C_T_plat.TypePlat_E)(int.Parse(dr["ID_typePlat"].ToString()));
res.Add(tmp);
}
dr.Close();
Commande.Connection.Close();
return res;
}
public int Supprimer(int ID_listPlat)
{
CreerCommande("SupprimerT_listPlat");
int res = 0;
Commande.Parameters.AddWithValue("@ID_listPlat", ID_listPlat);
Commande.Connection.Open();
res = Commande.ExecuteNonQuery();
Commande.Connection.Close();
return res;
}
}
}