public EchantillonDonne Read(int id_echantillon, int id_rdv) { EchantillonDonne echantillonDonne = null; if (OpenConnection()) { command = manager.CreateCommand(); EchantillonDAO echantillonManager = new EchantillonDAO(); RendezVousDAO rendezVousManager = new RendezVousDAO(); command.CommandText = "SELECT * " + "FROM echantillon_donne " + "WHERE id_echantillon = @id_echantillon AND " + "id_rdv = @id_rdv"; command.Parameters.AddWithValue("@id_echantillon", id_echantillon); command.Parameters.AddWithValue("@id_rdv", id_rdv); dataReader = command.ExecuteReader(); while (dataReader.Read()) { echantillonDonne = new EchantillonDonne(); echantillonDonne.Echantillon = echantillonManager.Read((int)dataReader["id_echantillon"], true); echantillonDonne.RendezVous = rendezVousManager.Read((int)dataReader["id_rdv"], true); echantillonDonne.Quantite = (int)dataReader["quantite"]; } dataReader.Close(); CloseConnection(); } return(echantillonDonne); }
// pas besoin du delete on garde les produits dans la bd (historique) //public void Delete(Produit produit) //{ // if (OpenConnection()) // { // command = manager.CreateCommand(); // command.CommandText = "DELETE FROM produit " + // "WHERE id_produit= @id" + //// certainement rajouter DELETE echantillon // command.Parameters.AddWithValue("@id", produit.IdProduit); // command.ExecuteNonQuery(); // CloseConnection(); // } //} public List <Produit> ReadAll() { List <Produit> produits = new List <Produit>(); if (OpenConnection()) { EchantillonDAO echantillonManager = new EchantillonDAO(); Produit produit; command = manager.CreateCommand(); command.CommandText = "SELECT * " + "FROM produit"; // Lecture des résultats dataReader = command.ExecuteReader(); while (dataReader.Read()) { produit = new Produit(); produit.Id_produit = (int)dataReader["id_produit"]; produit.Pathologie = (string)dataReader["pathologie"]; produit.Famille = (string)dataReader["famille"]; produit.Nom = (string)dataReader["nom"]; produit.Notice = (string)dataReader["notice"]; produit.Libelle = (string)dataReader["libelle"]; produit.Echantillons = echantillonManager.ReadAllFromProduit(produit); produits.Add(produit); } dataReader.Close(); CloseConnection(); } return(produits); }
public List <EchantillonDonne> ReadAllFromRendezVous(int id_rdv) { List <EchantillonDonne> liste_echantillons_donnes = new List <EchantillonDonne>(); if (OpenConnection()) { EchantillonDonne echantillonDonne = new EchantillonDonne(); EchantillonDAO echantillonManager = new EchantillonDAO(); RendezVousDAO rendezVousManager = new RendezVousDAO(); ProduitDAO produitManager = new ProduitDAO(); command = manager.CreateCommand(); command.CommandText = "SELECT ed.id_echantillon, ed.id_rdv, ed.quantite AS echantillonQuantite, p.id_produit " + "FROM produit p " + "join echantillon e on e.id_produit = p.id_produit " + "join echantillon_donne ed on ed.id_echantillon = e.id_echantillon " + "where id_rdv =@id_rdv "; command.Parameters.AddWithValue("@id_rdv", id_rdv); // Lecture des résultats dataReader = command.ExecuteReader(); Debug.WriteLine("ICI "); while (dataReader.Read()) { echantillonDonne = new EchantillonDonne(); echantillonDonne.Echantillon = echantillonManager.Read((int)dataReader["id_echantillon"], true); echantillonDonne.Produit = produitManager.Read((int)dataReader["id_produit"], true); echantillonDonne.Quantite = (int)dataReader["echantillonQuantite"]; echantillonDonne.RendezVous = rendezVousManager.Read(id_rdv, true); liste_echantillons_donnes.Add(echantillonDonne); } dataReader.Close(); CloseConnection(); } return(liste_echantillons_donnes); }
public Produit Read(int id, bool isReadFromEchantillonDonne) { Produit produit = new Produit(); if (OpenConnection()) { EchantillonDAO echantillonManager = new EchantillonDAO(); command = manager.CreateCommand(); command.CommandText = "SELECT * " + "FROM produit " + "WHERE id_produit = @id"; command.Parameters.AddWithValue("@id", id); // Lecture des résultats dataReader = command.ExecuteReader(); while (dataReader.Read()) { produit.Id_produit = (int)dataReader["id_produit"]; produit.Pathologie = (string)dataReader["pathologie"]; produit.Famille = (string)dataReader["famille"]; produit.Nom = (string)dataReader["nom"]; produit.Notice = (string)dataReader["notice"]; produit.Libelle = (string)dataReader["libelle"]; if (!isReadFromEchantillonDonne) { Debug.WriteLine(" JE NE SUIS PAS LU ET C BIEN"); produit.Echantillons = echantillonManager.ReadAllFromProduit(produit); } } dataReader.Close(); CloseConnection(); } return(produit); }