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;
                    Avion   avion      = DAL_Avion.GetAvion(IdAvion);

                    switch (column_nom)
                    {
                    case "Matricule":
                        avion.Matricule = el.Text;
                        break;

                    case "Moteur":
                        avion.Moteur = el.Text;
                        break;

                    case "Kilometre":
                        float kilometre;
                        if (!float.TryParse(el.Text, out kilometre))
                        {
                            kilometre = avion.Kilometre;
                        }
                        avion.Kilometre = kilometre;
                        break;

                    case "Modele":
                        avion.Modele = el.Text;
                        break;

                    case "Type":
                        avion.Type = el.Text;
                        break;

                    case "Passager":
                        int passager;
                        if (!int.TryParse(el.Text, out passager))
                        {
                            passager = avion.Passager;
                        }
                        avion.Kilometre = passager;
                        break;

                    default:
                        break;
                    }
                    DAL_Avion.ModifierAvion(avion.Id, avion.Matricule, avion.Moteur, avion.Kilometre, avion.Modele, avion.Type, avion.Passager);
                }
            }
        }
Ejemplo n.º 2
0
        public static Avion FindByMatricule(string matricule)
        {
            bdd.OpenConnection();
            string       query = "SELECT * FROM avion WHERE matricule = @matricule;";
            MySqlCommand cmd   = new MySqlCommand(query, bdd.GetConnection());

            cmd.Parameters.AddWithValue("@matricule", matricule);
            cmd.ExecuteNonQuery();
            MySqlDataReader reader = cmd.ExecuteReader();

            reader.Read();
            Avion avion = new Avion(reader.GetInt32(0), reader.GetString(1), reader.GetString(2), reader.GetFloat(3), reader.GetString(4), reader.GetString(5), reader.GetInt32(6));

            reader.Close();
            bdd.CloseConnection();
            return(avion);
        }
Ejemplo n.º 3
0
        public static List <string> SelectMatriculeAvions()
        {
            List <string> avions = new List <string>();

            bdd.OpenConnection();
            string       query = "SELECT * FROM avion;";
            MySqlCommand cmd   = new MySqlCommand(query, bdd.GetConnection());

            cmd.ExecuteNonQuery();
            MySqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                Avion avion = new Avion(reader.GetInt32(0), reader.GetString(1), reader.GetString(2), reader.GetFloat(3), reader.GetString(4), reader.GetString(5), reader.GetInt32(6));
                avions.Add(avion.Matricule);
            }
            reader.Close();
            bdd.CloseConnection();
            return(avions);
        }