public void Create(RendezVous rendezVous) { if (OpenConnection()) { EchantillonDonneDAO echantillonDonneDAO = new EchantillonDonneDAO(); command = manager.CreateCommand(); command.CommandText = "INSERT INTO rendez_vous " + "(id_commercial, id_praticien, date_rdv, motif_rdv, indice_confiance, date_bilan) " + "VALUES (@id_commercial, @id_praticien, @date_rdv, @motif_rdv, @indice_confiance,@date_bilan)"; command.Parameters.AddWithValue("@id_commercial", rendezVous.Employe.Id); command.Parameters.AddWithValue("@id_praticien", rendezVous.Praticien.Id); command.Parameters.AddWithValue("@date_rdv", rendezVous.Date_rdv); command.Parameters.AddWithValue("@motif_rdv", rendezVous.Motif_rdv.ToString()); command.Parameters.AddWithValue("@indice_confiance", rendezVous.Indice_confiance); command.Parameters.AddWithValue("@date_bilan", rendezVous.Date_bilan); if (rendezVous.Liste_echantillons_donnes != null) { foreach (EchantillonDonne echantillonDonne in rendezVous.Liste_echantillons_donnes) { echantillonDonneDAO.Create(echantillonDonne); } } command.ExecuteNonQuery(); CloseConnection(); } }
public int Read_IdEchantillon_FromNomConcentration(string nom, int concentration) { int id = 0; if (OpenConnection()) { ProduitDAO produitManager = new ProduitDAO(); EchantillonDonneDAO enchantillonDonneManager = new EchantillonDonneDAO(); command = manager.CreateCommand(); command.CommandText = "SELECT id_echantillon " + "FROM echantillon " + "JOIN produit on produit.id_produit = echantillon.id_produit " + "WHERE produit.nom = @nom AND echantillon.concentration = @concentration"; command.Parameters.AddWithValue("@nom", nom); command.Parameters.AddWithValue("@concentration", concentration); // Lecture des résultats dataReader = command.ExecuteReader(); while (dataReader.Read()) { id = (int)dataReader["id_echantillon"]; } dataReader.Close(); CloseConnection(); } return(id); }
public RendezVous Read(int id_rdv, bool isReadFromEchantillonDonne) { RendezVous rendezVous = null; if (OpenConnection()) { rendezVous = new RendezVous(); EmployeDAO employeManager = new EmployeDAO(); PraticienDAO praticienManager = new PraticienDAO(); EchantillonDonneDAO echantillonDonneManager = new EchantillonDonneDAO(); command = manager.CreateCommand(); command.CommandText = "SELECT * " + "FROM rendez_vous " + "WHERE id_rdv = @id " + "ORDER BY date_rdv ASC"; command.Parameters.AddWithValue("@id", id_rdv); // Lecture des résultats dataReader = command.ExecuteReader(); while (dataReader.Read()) { rendezVous.Id_rdv = (int)dataReader["id_rdv"]; rendezVous.Date_bilan = (DateTime)dataReader["date_bilan"]; rendezVous.Date_rdv = (DateTime)dataReader["date_rdv"]; rendezVous.Employe = employeManager.Read((int)dataReader["id_commercial"]); rendezVous.Praticien = praticienManager.Read((int)dataReader["id_praticien"]); rendezVous.Indice_confiance = (int)dataReader["indice_confiance"]; // Utilisation d'un Enum.Parse pour transformer un string en Enum // Pour ce faire : (Type Enum)Enum.Parse(typeof(Type Enum), (string)variable); rendezVous.Motif_rdv = (RendezVous.Rdv)Enum.Parse(typeof(RendezVous.Rdv), (string)dataReader["motif_rdv"]); if (!isReadFromEchantillonDonne) { rendezVous.Liste_echantillons_donnes = echantillonDonneManager.ReadAllFromRendezVous(rendezVous.Id_rdv); } } dataReader.Close(); CloseConnection(); } return(rendezVous); }
//public void Create(Echantillon echantillon) //{ // if (OpenConnection()) // { // command = manager.CreateCommand(); // command.CommandText = "INSERT INTO echantillon " + // "(id_produit, quantite, concentration, libelle) " + // "VALUES (@id_produit, @quantite, @concentration, @libelle)"; // command.Parameters.AddWithValue("@id_produit", echantillon.Produit.Id_produit); // command.Parameters.AddWithValue("@quantite", echantillon.Quantite); // command.Parameters.AddWithValue("@concentration", echantillon.Concentration); // command.Parameters.AddWithValue("@libelle", echantillon.Libelle); // command.ExecuteNonQuery(); // CloseConnection(); // } //} public Echantillon Read(int id_echantillon, bool isReadFromEchantillonDonnes) { Echantillon echantillon = new Echantillon(); if (OpenConnection()) { ProduitDAO produitManager = new ProduitDAO(); EchantillonDonneDAO enchantillonDonneManager = new EchantillonDonneDAO(); command = manager.CreateCommand(); command.CommandText = "SELECT * " + "FROM echantillon " + "WHERE id_echantillon = @id_echantillon"; command.Parameters.AddWithValue("@id_echantillon", id_echantillon); // Lecture des résultats dataReader = command.ExecuteReader(); while (dataReader.Read()) { echantillon.Id_echantillon = (int)dataReader["id_echantillon"]; echantillon.Produit = produitManager.Read((int)dataReader["id_produit"], isReadFromEchantillonDonnes); echantillon.Quantite = (int)dataReader["quantite"]; echantillon.Concentration = (int)dataReader["concentration"]; echantillon.Libelle = (string)dataReader["libelle"]; if (!isReadFromEchantillonDonnes) { //Debug.WriteLine(" JE NE SUIS PAS LU ET C BIEN"); echantillon.Liste_echantillons_donnes = enchantillonDonneManager.ReadAllFromEchantillon(echantillon); } } dataReader.Close(); CloseConnection(); } return(echantillon); }
public List <RendezVous> ReadRDVHistoFromCommercialID(int id_commercial) { List <RendezVous> liste_rdv = new List <RendezVous>(); if (OpenConnection()) { RendezVous rdv; EmployeDAO employeManager = new EmployeDAO(); PraticienDAO praticienManager = new PraticienDAO(); EchantillonDonneDAO echantillonDonneManager = new EchantillonDonneDAO(); command = manager.CreateCommand(); command.CommandText = "SELECT * FROM rendez_vous WHERE id_commercial = @id_commercial AND date_rdv < NOW()"; command.Parameters.AddWithValue("@id_commercial", id_commercial); dataReader = command.ExecuteReader(); Debug.WriteLine("==== Je suis appellé une fois pour lire les RDV"); while (dataReader.Read()) { rdv = new RendezVous(); rdv.Id_rdv = (int)dataReader["id_rdv"]; rdv.Employe = employeManager.Read((int)dataReader["id_commercial"]); rdv.Praticien = praticienManager.Read((int)dataReader["id_praticien"]); rdv.Date_rdv = (DateTime)dataReader["date_rdv"]; rdv.Date_bilan = (DateTime)dataReader["date_bilan"]; rdv.Motif_rdv = (RendezVous.Rdv)Enum.Parse(typeof(RendezVous.Rdv), (string)dataReader["motif_rdv"]); rdv.Indice_confiance = (int)dataReader["indice_confiance"]; rdv.Liste_echantillons_donnes = echantillonDonneManager.ReadAllFromRendezVous(rdv.Id_rdv); liste_rdv.Add(rdv); } dataReader.Close(); command.ExecuteNonQuery(); CloseConnection(); } return(liste_rdv); }
//public void Update(Echantillon echantillon) //{ // if (OpenConnection()) // { // command = manager.CreateCommand(); // command.CommandText = "UPDATE echantillon " + // "SET id_echantillon=@id_echantillon, id_produit=@id_produit, quantite=@quantite, concentration=@concentration, libelle=@libelle " + // "WHERE echantillon.id_echantillon = @id_echantillon"; // command.Parameters.AddWithValue("@id_echantillon", echantillon.Id_echantillon); // command.Parameters.AddWithValue("@id_produit", echantillon.Produit.Id_produit); // command.Parameters.AddWithValue("@quantite", echantillon.Quantite); // command.Parameters.AddWithValue("@concentration", echantillon.Concentration); // command.Parameters.AddWithValue("@libelle", echantillon.Libelle); // // Update ligne frais ? // command.ExecuteNonQuery(); // CloseConnection(); // } //} //public void Delete(Echantillon echantillon) //{ // if (OpenConnection()) // { // command = manager.CreateCommand(); // command.CommandText = "DELETE FROM echantillon " + // "WHERE id_echantillon = @id_echantillon"; // command.Parameters.AddWithValue("@id_echantillon", echantillon.Id_echantillon); // // Delete ligne frais // command.ExecuteNonQuery(); // CloseConnection(); // } //} public List <Echantillon> ReadAllFromProduit(Produit produit) { List <Echantillon> liste_echantillons = new List <Echantillon>(); if (OpenConnection()) { EchantillonDonneDAO echantillonDonneManager = new EchantillonDonneDAO(); Echantillon echantillon = new Echantillon(); command = manager.CreateCommand(); command.CommandText = "SELECT * " + "FROM echantillon " + "WHERE id_produit = @id_produit"; command.Parameters.AddWithValue("@id_produit", produit.Id_produit); // Lecture des résultats dataReader = command.ExecuteReader(); while (dataReader.Read()) { echantillon.Produit = produit; echantillon.Id_echantillon = (int)dataReader["id_echantillon"]; echantillon.Quantite = (int)dataReader["quantite"]; echantillon.Libelle = (string)dataReader["libelle"]; echantillon.Concentration = (int)dataReader["concentration"]; echantillon.Liste_echantillons_donnes = echantillonDonneManager.ReadAllFromEchantillon(echantillon); liste_echantillons.Add(echantillon); } dataReader.Close(); CloseConnection(); } return(liste_echantillons); }
public List <RendezVous> ReadAll() { List <RendezVous> liste_rdv = new List <RendezVous>(); if (OpenConnection()) { RendezVous rdv; EmployeDAO employeManager = new EmployeDAO(); PraticienDAO praticienManager = new PraticienDAO(); EchantillonDonneDAO echantillonDonneManager = new EchantillonDonneDAO(); command = manager.CreateCommand(); command.CommandText = "SELECT * FROM rendez_vous"; dataReader = command.ExecuteReader(); while (dataReader.Read()) { rdv = new RendezVous(); rdv.Id_rdv = (int)dataReader["id_rdv"]; rdv.Employe = employeManager.Read((int)dataReader["id_commercial"]); rdv.Praticien = praticienManager.Read((int)dataReader["id_praticien"]); rdv.Date_rdv = (DateTime)dataReader["date_rdv"]; rdv.Motif_rdv = (RendezVous.Rdv)Enum.Parse(typeof(RendezVous.Rdv), (string)dataReader["motif_rdv"]); rdv.Indice_confiance = (int)dataReader["indice_confiance"]; rdv.Date_bilan = (DateTime)dataReader["date_bilan"]; rdv.Liste_echantillons_donnes = echantillonDonneManager.ReadAllFromRendezVous(rdv.Id_rdv); liste_rdv.Add(rdv); } dataReader.Close(); command.ExecuteNonQuery(); CloseConnection(); } return(liste_rdv); }