コード例 #1
0
        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;
                    Vol      Vol        = DAL_Vol.GetVol(IdVol);

                    switch (column_nom)
                    {
                    case "Trajet":
                        Vol.StrTrajet = co.Text;
                        Vol.Trajet    = DAL_Trajet.FindByStrTrajet(co.Text).Id;
                        break;

                    case "Avion":
                        Vol.Avion = co.Text;
                        break;

                    case "Départ":
                        DateTime depart;
                        if (!DateTime.TryParse(el.Text, out depart))
                        {
                            depart = Vol.Depart;
                        }
                        Vol.Depart = depart;
                        break;

                    case "Arrivée":
                        DateTime arrivee;
                        if (!DateTime.TryParse(el.Text, out arrivee))
                        {
                            arrivee = Vol.Arrivee;
                        }
                        Vol.Arrivee = arrivee;
                        break;

                    default:
                        break;
                    }
                    DAL_Vol.ModifierVol(Vol.Id, Vol.Trajet, DAL_Avion.FindByMatricule(Vol.Avion).Id, Vol.Depart, Vol.Arrivee);
                }
            }
        }
コード例 #2
0
        public static Vol GetVol(int id)
        {
            bdd.OpenConnection();
            string       query = "SELECT * FROM vol WHERE id = @id;";
            MySqlCommand cmd   = new MySqlCommand(query, bdd.GetConnection());

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

            reader.Read();
            Vol Vol = new Vol(reader.GetInt32(0), reader.GetInt32(1), reader.GetInt32(2), reader.GetDateTime(3), reader.GetDateTime(4));

            reader.Close();
            bdd.CloseConnection();
            return(Vol);
        }
コード例 #3
0
        public static ObservableCollection <Vol> SelectVols()
        {
            ObservableCollection <Vol> Vols = new ObservableCollection <Vol>();

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

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

            while (reader.Read())
            {
                Vol Vol = new Vol(reader.GetInt32(0), reader.GetInt32(1), reader.GetInt32(2), reader.GetDateTime(3), reader.GetDateTime(4));
                Vols.Add(Vol);
            }
            reader.Close();
            bdd.CloseConnection();
            return(Vols);
        }