public static void updateFligt(Modele.ORM.flight Filght) { string query = "UPDATE flight SET Available_Places = @places WHERE id=@id"; //Open connection ConnexionWorkBench connection = new ConnexionWorkBench(); if (connection.OpenConnection() == true) { //Create Command MySqlCommand cmd = new MySqlCommand(query, connection.GetConnection()); cmd.Parameters.AddWithValue("@id", Filght.Id); cmd.Parameters.AddWithValue("@places", Filght.AvailablePlaces); //Create a data reader and Execute the command cmd.ExecuteNonQuery(); //close Connection connection.CloseConnection(); } }
//Select statement public static ObservableCollection <Modele.ORM.flight> getFlights() { ObservableCollection <Modele.ORM.flight> Flights = new ObservableCollection <Modele.ORM.flight>(); string query = "SELECT * FROM flight;"; //Open connection ConnexionWorkBench connection = new ConnexionWorkBench(); if (connection.OpenConnection() == true) { //Create Command MySqlCommand cmd = new MySqlCommand(query, connection.GetConnection()); //Create a data reader and Execute the command MySqlDataReader dataReader = cmd.ExecuteReader(); //Read the data and store them in the list while (dataReader.Read()) { int idvol = dataReader.GetInt32(0); Modele.ORM.plane Plane = Modele.ORM.plane.getPlane(dataReader.GetInt32(1)); int freePlaces = dataReader.GetInt32(2); DateTime hoursDeparture = dataReader.GetDateTime(3); DateTime hoursArrival = dataReader.GetDateTime(3); Modele.ORM.flight Flight = new Modele.ORM.flight(idvol, Plane, freePlaces, hoursDeparture, hoursArrival); Flights.Add(Flight); } //close Data Reader dataReader.Close(); //close Connection connection.CloseConnection(); //return list to be displayed return(Flights); } else { return(Flights); } }
public static void updateFligt(Modele.ORM.flight Filght) { Modele.DAL.Request.FlightRequest.updateFligt(Filght); }