#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 { /// /// Couche d'accès aux données (Data Access Layer) /// 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, DateTime R_Date) { 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.Parameters.AddWithValue("@R_Date", R_Date); 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 , DateTime R_Date) { 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.Parameters.AddWithValue("@R_Date", R_Date); Commande.Connection.Open(); Commande.ExecuteNonQuery(); Commande.Connection.Close(); return res; } public List Lire(string Index) { CreerCommande("SelectionnerT_repa"); Commande.Parameters.AddWithValue("@Index", Index); Commande.Connection.Open(); SqlDataReader dr = Commande.ExecuteReader(); List res = new List(); while (dr.Read()) { C_T_repa tmp = new C_T_repa(); tmp.ID_repa = int.Parse(dr["ID_repa"].ToString()); tmp.R_Date = DateTime.Parse(dr["R_Date"].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; } /// /// resume de Lire /// /// Date filtre debut compris /// Date fin non compris public List Lire(DateTime start, DateTime end) { CreerCommande("SelectEventBetweenTwoDateTime"); Commande.Parameters.AddWithValue("@dateStart", start); Commande.Parameters.AddWithValue("@dateEnd", end); Commande.Connection.Open(); SqlDataReader dr = Commande.ExecuteReader(); List res = new List(); while (dr.Read()) { C_T_repa tmp = new C_T_repa(); tmp.ID_repa = int.Parse(dr["ID_repa"].ToString()); tmp.R_Date = DateTime.Parse(dr["R_Date"].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 List Lire(DateTime dateV) { CreerCommande("SelectEventBetweenTwoDateTime"); Commande.Parameters.AddWithValue("@dateV", dateV); Commande.Connection.Open(); SqlDataReader dr = Commande.ExecuteReader(); List res = new List(); while (dr.Read()) { C_T_repa tmp = new C_T_repa(); tmp.ID_repa = int.Parse(dr["ID_repa"].ToString()); tmp.R_Date = DateTime.Parse(dr["R_Date"].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.R_Date = DateTime.Parse(dr["R_Date"].ToString()); 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; } } }