private void buttonEnregistrerDiplôme_Click(object sender, EventArgs e) { Diplome_Personne diplome_personne = new Diplome_Personne(); diplome_personne.diplome = Convert.ToInt32(this.comboBoxIntituléDiplôme.SelectedValue); diplome_personne.DateObtention = this.dateTimePicker1.Value; diplome_personne.diplome = Convert.ToInt32(this.comboBoxNiveauDiplôme.SelectedValue); if (this.comboBoxNiveauDiplôme.SelectedValue == "Autre") { Niveau niveau = new Niveau(); niveau.Libelle = this.textBoxNiveauAjout.Text; NiveauDB.Insert(niveau); } if (this.comboBoxIntituléDiplôme.SelectedValue == "Autre") { Diplome NewDiplome = new Diplome(); NewDiplome.Libelle = this.textBoxIntituléAjout.Text; NewDiplome.niveau = NiveauDB.LastID(); DiplomeDB.Insert(NewDiplome); } Diplome_PersonneDB.Insert(diplome_personne); Close(); }
/// <summary> /// Récupère une Diplome à partir d'un identifiant de client /// </summary> /// <param name="Identifiant">Identifant de Diplome</param> /// <returns>Un Diplome </returns> public static Diplome Get(Int32 identifiant) { //Connection SqlConnection connection = DataBase.connection; //Commande String requete = @"SELECT Identifiant, Libelle, IdentifiantNiveau FROM Diplome WHERE Identifiant = @Identifiant"; SqlCommand commande = new SqlCommand(requete, connection); //Paramètres commande.Parameters.AddWithValue("Identifiant", identifiant); //Execution connection.Open(); SqlDataReader dataReader = commande.ExecuteReader(); dataReader.Read(); //1 - Création du Diplome Diplome diplome = new Diplome(); diplome.Identifiant = dataReader.GetInt32(0); diplome.Libelle = dataReader.GetString(1); diplome.niveau = dataReader.GetInt32(2); dataReader.Close(); connection.Close(); return diplome; }
public static void Insert(Diplome Diplome) { //Connection SqlConnection connection = DataBase.connection; //Commande String requete = @"INSERT INTO Diplome (Libelle, IdentifiantNiveau) VALUES (@Libelle, @IdentifiantNiveau);SELECT SCOPE_IDENTITY() "; connection.Open(); SqlCommand commande = new SqlCommand(requete, connection); //Paramètres commande.Parameters.AddWithValue("Libelle", Diplome.Libelle); commande.Parameters.AddWithValue("IdentifiantNiveau", Diplome.niveau); //Execution commande.ExecuteNonQuery(); connection.Close(); }
public static void Update(Diplome Diplome) { //Connection SqlConnection connection = DataBase.connection; //Commande String requete = @"UPDATE Diplome SET Libelle = @Libelle, IdentifiantNiveau = @IdentifiantNiveau WHERE Identifiant = @Identifiant"; connection.Open(); SqlCommand commande = new SqlCommand(requete, connection); //Paramètres commande.Parameters.AddWithValue("Libelle", Diplome.Libelle); commande.Parameters.AddWithValue("niveau", Diplome.niveau); commande.Parameters.AddWithValue("IdentifiantNiveau", Diplome.niveau); //Execution commande.ExecuteNonQuery(); connection.Close(); }
/// <summary> /// Récupère une liste de Diplome à partir de la base de données /// </summary> /// <returns>Une liste de client</returns> public static List<Diplome> List() { //Récupération de la chaine de connexion //Connection SqlConnection connection = DataBase.connection; //Commande String requete = "SELECT Identifiant, Libelle, IdentifiantNiveau FROM Diplome"; connection.Open(); SqlCommand commande = new SqlCommand(requete, connection); //execution SqlDataReader dataReader = commande.ExecuteReader(); List<Diplome> list = new List<Diplome>(); while (dataReader.Read()) { //1 - Créer un Diplome à partir des donner de la ligne du dataReader Diplome diplome = new Diplome(); diplome.Identifiant = dataReader.GetInt32(0); diplome.Libelle = dataReader.GetString(1); diplome.niveau = dataReader.GetInt32(2); //2 - Ajouter ce Diplome à la list de client list.Add(diplome); } dataReader.Close(); connection.Close(); return list; }