public static List <Achat> readAll() { List <Achat> res = new List <Achat>(); Achat achat = null; MySqlCommand cmd = new MySqlCommand(); cmd.CommandText = "SELECT * FROM locations"; cmd.Connection = Connexion.getInstance(); try { MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Commande idCo = CommandeADO.findById(reader["idCo"].ToString()); bool demandeL = bool.Parse(reader["demandeLivraison"].ToString()); float prixTotal = float.Parse(reader["prixTotal"].ToString()); int effectifMT = Int32.Parse(reader["effectifMaterielTotal"].ToString()); Clients idCl = ClientsADO.findById(reader["idCl"].ToString()); achat = new Achat(idCo, demandeL, prixTotal, effectifMT, idCl); res.Add(achat); } cmd = null; reader.Close(); reader = null; } catch (Exception ex) { Console.WriteLine("Erreur de dataReader : " + ex.Message); } return(res); }
public static List <Contenir> readAll() { List <Contenir> res = new List <Contenir>(); Contenir ctnr = null; MySqlCommand cmd = new MySqlCommand(); cmd.CommandText = "SELECT * FROM materiels"; cmd.Connection = Connexion.getInstance(); try { MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Materiel idM = MaterielADO.findById(reader["idM"].ToString()); Commande idCo = CommandeADO.findById(reader["idCo"].ToString()); string nbMateriel = reader["nbMateriel"].ToString(); ctnr = new Contenir(idM, idCo, nbMateriel); res.Add(ctnr); } cmd = null; reader.Close(); reader = null; } catch (Exception ex) { Console.WriteLine("Erreur de dataReader : " + ex.Message); } return(res); }
public static Location findById(string id) { Location loc = null; MySqlCommand cmd = new MySqlCommand(); cmd.CommandText = "SELECT * FROM locations WHERE idCo = @idCo"; cmd.Parameters.AddWithValue("@idCo", id); //Connexion temporaire ! string chaineDeConnexion = "server=localhost; database=projet dj; username=root; Pooling=true; charset=utf8"; MySqlConnection connexion = null; try { connexion = new MySqlConnection(chaineDeConnexion); connexion.Open(); } catch (Exception ex) { Console.WriteLine("Erreur de connexion : " + ex.Message); } cmd.Connection = connexion; try { MySqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { Commande idCo = CommandeADO.findById(reader["idCo"].ToString()); DateTime dateD = DateTime.Parse(reader["dateDebut"].ToString()); DateTime dateF = DateTime.Parse(reader["dateFin"].ToString()); bool demandeI = bool.Parse(reader["demandeInstallation"].ToString()); float prixTotal = float.Parse(reader["prixTotal"].ToString()); int effectifMT = Int32.Parse(reader["effectifMaterielTotal"].ToString()); Clients idCl = ClientsADO.findById(reader["idCl"].ToString()); loc = new Location(idCo, dateD, dateF, demandeI, prixTotal, effectifMT, idCl); } cmd = null; reader.Close(); reader = null; } catch (Exception ex) { Console.WriteLine("Erreur de dataReader : " + ex.Message); } connexion.Close(); connexion = null; return(loc); }
// **************************************** RECHERCHE ************************************** public static List <Achat> findByRecherche(string recherche) { List <Achat> res = new List <Achat>(); Achat achat = null; MySqlCommand cmd = new MySqlCommand(); cmd.CommandText = "SELECT * FROM achats WHERE idCo LIKE '" + recherche + "%'"; //Connexion temporaire ! string chaineDeConnexion = "server=localhost; database=projet dj; username=root; Pooling=true; charset=utf8"; MySqlConnection connexion = null; try { connexion = new MySqlConnection(chaineDeConnexion); connexion.Open(); } catch (Exception ex) { Console.WriteLine("Erreur de connexion : " + ex.Message); } cmd.Connection = connexion; try { MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Commande idCo = CommandeADO.findById(reader["idCo"].ToString()); DateTime dateA = DateTime.Parse(reader["dateAchat"].ToString()); bool demandeL = bool.Parse(reader["demandeLivraison"].ToString()); float prixTotal = float.Parse(reader["prixTotal"].ToString()); int effectifMT = Int32.Parse(reader["effectifMaterielTotal"].ToString()); Clients idCl = ClientsADO.findById(reader["idCl"].ToString()); achat = new Achat(idCo, dateA, demandeL, prixTotal, effectifMT, idCl); res.Add(achat); } cmd = null; reader.Close(); reader = null; } catch (Exception ex) { Console.WriteLine("Erreur de dataReader : " + ex.Message); } connexion.Close(); connexion = null; return(res); }
public static Contenir findById(string id) { Contenir ctnr = null; MySqlCommand cmd = new MySqlCommand(); cmd.CommandText = "SELECT * FROM contenir WHERE idCo = @idCo"; cmd.Parameters.AddWithValue("@idCo", id); //Connexion temporaire ! string chaineDeConnexion = "server=localhost; database=projet dj; username=root; Pooling=true; charset=utf8"; MySqlConnection connexion = null; try { connexion = new MySqlConnection(chaineDeConnexion); connexion.Open(); } catch (Exception ex) { Console.WriteLine("Erreur de connexion : " + ex.Message); } cmd.Connection = connexion; try { MySqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { Materiel idM = MaterielADO.findById(reader["idM"].ToString()); Commande idCo = CommandeADO.findById(reader["idCo"].ToString()); string nbMateriel = reader["nbMateriel"].ToString(); ctnr = new Contenir(idM, idCo, nbMateriel); } cmd = null; reader.Close(); reader = null; } catch (Exception ex) { Console.WriteLine("Erreur de dataReader : " + ex.Message); } connexion.Close(); connexion = null; return(ctnr); }
// **************************************** RECHERCHE ************************************** public static List <Contenir> findByRecherche(string recherche) { List <Contenir> res = new List <Contenir>(); Contenir ctnr = null; MySqlCommand cmd = new MySqlCommand(); cmd.CommandText = "SELECT * FROM contenir WHERE idCo LIKE '" + recherche + "%'"; //Connexion temporaire ! string chaineDeConnexion = "server=localhost; database=projet dj; username=root; Pooling=true; charset=utf8"; MySqlConnection connexion = null; try { connexion = new MySqlConnection(chaineDeConnexion); connexion.Open(); } catch (Exception ex) { Console.WriteLine("Erreur de connexion : " + ex.Message); } cmd.Connection = connexion; try { MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Materiel idM = MaterielADO.findById(reader["idM"].ToString()); Commande idCo = CommandeADO.findById(reader["idCo"].ToString()); string nbMateriel = reader["nbMateriel"].ToString(); ctnr = new Contenir(idM, idCo, nbMateriel); res.Add(ctnr); } cmd = null; reader.Close(); reader = null; } catch (Exception ex) { Console.WriteLine("Erreur de dataReader : " + ex.Message); } connexion.Close(); connexion = null; return(res); }