public plane(int idThisPlane, Modele.ORM.type thisType, Modele.ORM.crew thisCrew, Modele.ORM.warehouse thisWarehouse, bool thisStatus) { IdPlane = idThisPlane; Type = thisType; Crew = thisCrew; Warehouse = thisWarehouse; Status = thisStatus; }
//Select statement public static ObservableCollection <Modele.ORM.plane> getPlanes() { ObservableCollection <Modele.ORM.plane> Planes = new ObservableCollection <Modele.ORM.plane>(); string query = "SELECT * FROM plane;"; //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 idplane = dataReader.GetInt32(0); Modele.ORM.type Type = Modele.ORM.type.GetType(dataReader.GetInt32(1)); Modele.ORM.crew Crew; if (dataReader[2] != DBNull.Value) { Crew = Modele.ORM.crew.GetCrew(dataReader.GetInt32(2)); } else { Crew = null; } Modele.ORM.warehouse Warehouse = Modele.ORM.warehouse.GetWarehouse(dataReader.GetInt32(3)); bool status = dataReader.GetBoolean(4); Modele.ORM.plane Plane = new Modele.ORM.plane(idplane, Type, Crew, Warehouse, status); Planes.Add(Plane); } //close Data Reader dataReader.Close(); //close Connection connection.CloseConnection(); //return list to be displayed return(Planes); } else { return(Planes); } }
private void InsertPlaneClick(object sender, RoutedEventArgs e) { Modele.ORM.type Type = PlaneType.SelectedItem as Modele.ORM.type; Modele.ORM.warehouse Warehouse = PlaneWarehouse.SelectedItem as Modele.ORM.warehouse; bool status = (bool)Status.IsChecked; vue.insertPlane(Type.IdType, Warehouse.IdWarehouse, status); gridPlanes.ItemsSource = vue.getPlanes(); this.ModalAddPlane.Visibility = Visibility.Collapsed; }
public static ObservableCollection <Modele.ORM.type> getTypes() { ObservableCollection <Modele.ORM.type> Types = new ObservableCollection <Modele.ORM.type>(); string query = "SELECT * FROM type;"; //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(); Modele.ORM.type Type; //Read the data and store them in the list while (dataReader.Read()) { Type = new Modele.ORM.type( dataReader.GetInt32(0), dataReader.GetString(1), dataReader.GetString(2), dataReader.GetInt32(3), dataReader.GetInt32(4), dataReader.GetInt32(5), dataReader.GetInt32(6), dataReader.GetInt32(7) ); Types.Add(Type); } //close Data Reader dataReader.Close(); //close Connection connection.CloseConnection(); //return list to be displayed return(Types); } else { return(Types); } }
//Select statement public static Modele.ORM.type getType(int idType) { Modele.ORM.type Type = null; string query = "SELECT * FROM type where id=@type;"; //Open connection ConnexionWorkBench connection = new ConnexionWorkBench(); if (connection.OpenConnection() == true) { //Create Command MySqlCommand cmd = new MySqlCommand(query, connection.GetConnection()); //shield sql injection cmd.Parameters.AddWithValue("@type", idType); //Create a data reader and Execute the command MySqlDataReader dataReader = cmd.ExecuteReader(); //Read the data and store them in the list while (dataReader.Read()) { Type = new Modele.ORM.type( dataReader.GetInt32(0), dataReader.GetString(1), dataReader.GetString(2), dataReader.GetInt32(3), dataReader.GetInt32(4), dataReader.GetInt32(5), dataReader.GetInt32(6), dataReader.GetInt32(7) ); } //close Data Reader dataReader.Close(); //close Connection connection.CloseConnection(); //return list to be displayed return(Type); } else { return(Type); } }