Esempio n. 1
0
        //Méthode qui permet d'insérer un nouveau médicament
        public static void InsererMedicament(Medicament medicament)
        {
            DbCommand dbc = GetConnexion().CreateCommand();

            // construction de la requête SQL insert
            dbc.CommandText = "INSERT INTO medicament VALUES ( "
                              + "'" + medicament.GetId() + "',"
                              + "'" + medicament.GetNomCommercial() + "',"
                              + "'" + medicament.GetFamille().GetId() + "',"
                              + "'" + medicament.GetComposition() + "',"
                              + "'" + medicament.GetEffets() + "',"
                              + "'" + medicament.GetContreIndications() + "'"
                              + " )";
            // Debug : affiche la requête SQL
            MessageBox.Show(dbc.CommandText);
            // Exécution de la requête
            dbc.ExecuteNonQuery();
        }
        private void listMedicaments_SelectedIndexChanged(object sender, EventArgs e)
        {
            // récupération de l'indice du médicament sélectionné
            int indexMed = this.listMedicaments.SelectedIndex;
            // récupération du médicament dans la classe manager
            Medicament med = Manager.GetMedicament(indexMed);

            // mise à jour des champs de texte
            this.txtId.Text                = med.GetId();
            this.txtNomCommercial.Text     = med.GetNomCommercial();
            this.txtEffets.Text            = med.GetEffets();
            this.txtComposition.Text       = med.GetComposition();
            this.txtContreIndications.Text = med.GetContreIndications();
            // récupération de la famille du médicament grâce au Manager
            Famille famille = Manager.ChargerFamilleDuMedicament(med);

            // mise à jour du champ de texte txtFamille avec le libellé de la famille
            this.txtFamille.Text = famille.GetLibelle();
        }