public static Trajet GetTrajet(int id) { bdd.OpenConnection(); string query = "SELECT * FROM trajet WHERE id = @id;"; MySqlCommand cmd = new MySqlCommand(query, bdd.GetConnection()); cmd.Parameters.AddWithValue("@id", id); cmd.ExecuteNonQuery(); MySqlDataReader reader = cmd.ExecuteReader(); reader.Read(); Trajet trajet = new Trajet(reader.GetInt32(0), reader.GetInt32(1), reader.GetInt32(2), reader.GetString(3), reader.GetFloat(4), reader.GetString(5)); reader.Close(); bdd.CloseConnection(); return(trajet); }
public static List <string> SelectStrTrajets() { List <string> trajets = new List <string>(); bdd.OpenConnection(); string query = "SELECT * FROM trajet;"; MySqlCommand cmd = new MySqlCommand(query, bdd.GetConnection()); cmd.ExecuteNonQuery(); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Trajet trajet = new Trajet(reader.GetInt32(0), reader.GetInt32(1), reader.GetInt32(2), reader.GetString(3), reader.GetFloat(4), reader.GetString(5)); trajets.Add(trajet.Depart + " - " + trajet.Arrivee); } reader.Close(); bdd.CloseConnection(); return(trajets); }
public static ObservableCollection <Trajet> SelectTrajets() { ObservableCollection <Trajet> trajets = new ObservableCollection <Trajet>(); bdd.OpenConnection(); string query = "SELECT * FROM trajet;"; MySqlCommand cmd = new MySqlCommand(query, bdd.GetConnection()); cmd.ExecuteNonQuery(); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Trajet trajet = new Trajet(reader.GetInt32(0), reader.GetInt32(1), reader.GetInt32(2), reader.GetString(3), reader.GetFloat(4), reader.GetString(5)); trajets.Add(trajet); } reader.Close(); bdd.CloseConnection(); return(trajets); }
private void Edit(object sender, DataGridCellEditEndingEventArgs e) { if (e.EditAction == DataGridEditAction.Commit) { DataGridColumn column = e.Column; if (column != null) { string column_nom = (string)column.Header; TextBox el = e.EditingElement as TextBox; ComboBox co = e.EditingElement as ComboBox; Trajet trajet = DAL_Trajet.GetTrajet(IdTrajet); switch (column_nom) { case "Durée": trajet.Duree = el.Text; break; case "Référence": trajet.Reference = el.Text; break; case "Distance": trajet.Distance = float.Parse(el.Text); break; case "Départ": trajet.Depart = (string)co.SelectionBoxItem; break; case "Arrivée": trajet.Arrivee = (string)co.SelectionBoxItem; break; default: break; } DAL_Trajet.ModifierTrajet(trajet.Id, trajet.Duree, trajet.Reference, trajet.Distance, DAL_Aeroport.FindByName(trajet.Depart).Id, DAL_Aeroport.FindByName(trajet.Arrivee).Id); } } }