예제 #1
0
 private void BaddE1_Click(object sender, EventArgs e)
 {
     if ( CBctorE1.SelectedItem != null
           && TBvehiculeE1.Text != null)
         {
             Vehicule = new Vehicule();
             Vehicule.Nom = TBvehiculeE1.Text;
             Vehicule.ID_Constructeur = (Int32)CBctorE1.SelectedValue;
             VehiculeDB.Insert(Vehicule);
             Vehicule.Identifiant = VehiculeDB.LastID();
             SuivantE1('a');
         }
 }
예제 #2
0
        public static Vehicule Get(Int32 Identifiant)
        {
            Vehicule vehicule = new Vehicule();

            //Connection
            SqlConnection connection = DataBase.Connection();

            //Requete
            String requete = select+" WHERE Identifiant = @Identifiant;";

            //Commande
            SqlCommand commande = new SqlCommand(requete, connection);

            //Parametres
            commande.Parameters.AddWithValue("Identifiant", Identifiant);

            //Execution
            try
            {
                connection.Open();

                SqlDataReader dataReader = commande.ExecuteReader();
                dataReader.Read();
                vehicule.Identifiant = dataReader.GetInt32(0);
                vehicule.Nom= dataReader.GetString(1);
                vehicule.ID_Constructeur = dataReader.GetInt32(2);

                dataReader.Close();

                return vehicule;
            }
            catch (Exception)
            {
                return null;
            }
            finally
            {
                connection.Close();
            }
        }
예제 #3
0
        public static Boolean Insert(Vehicule vehicule)
        {
            //Connection
            SqlConnection connection = DataBase.Connection();

            //Requete
            String requete = @"INSERT INTO Vehicule (" + champs + ") VALUES (@Nom,@ID_Constructeur);";

            //Commande
            SqlCommand commande = new SqlCommand(requete, connection);

            //Parametres
            commande.Parameters.AddWithValue("Nom", vehicule.Nom);
            commande.Parameters.AddWithValue("ID_Constructeur", vehicule.ID_Constructeur);
            //Execution
            try
            {
                connection.Open();
                commande.ExecuteNonQuery();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                connection.Close();
            }
        }
예제 #4
0
        public static Boolean Update(Vehicule vehicule)
        {
            //Connection
            SqlConnection connection = DataBase.Connection();

            //Requete
            String requete = @"UPDATE Vehicule
                               SET Nom=@Nom,ID_Constructeur=@ID_Constructeur
                               WHERE Identifiant=@Identifiant ;";

            //Commande
            SqlCommand commande = new SqlCommand(requete, connection);

            //Parametres
            commande.Parameters.AddWithValue("Identifiant",vehicule.Identifiant);
            commande.Parameters.AddWithValue("Nom",vehicule.Nom );
            commande.Parameters.AddWithValue("ID_Constructeur", vehicule.ID_Constructeur);

            //Execution
            try
            {
                connection.Open();
                commande.ExecuteNonQuery();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
            finally
            {
                connection.Close();
            }
        }
예제 #5
0
        public static List<Vehicule> List()
        {
            List<Vehicule> listeVehicule = new List<Vehicule>();

            //Connection
            SqlConnection connection = DataBase.Connection();

            //Requete
            String requete = select+";";

            //Commande
            SqlCommand commande = new SqlCommand(requete, connection);

            //Parametres

            //Execution
            try
            {
                connection.Open();

                SqlDataReader dataReader = commande.ExecuteReader();

                while (dataReader.Read())
                {
                   Vehicule vehicule = new Vehicule();
                   vehicule.Identifiant = dataReader.GetInt32(0);
                   vehicule.Nom= dataReader.GetString(1);
                   vehicule.ID_Constructeur= dataReader.GetInt32(2);
                   listeVehicule.Add(vehicule);
                }

                dataReader.Close();

            }
            catch (Exception)
            {
                listeVehicule = null;
            }
            finally
            {
                connection.Close();
            }
            return listeVehicule;
        }
예제 #6
0
 private void BupdateE1_Click(object sender, EventArgs e)
 {
     if (LBvehiculeE1.SelectedItem != null)
         {
             Vehicule = VehiculeDB.Get((Int32)LBvehiculeE1.SelectedValue);
             SuivantE1('u');
         }
 }