/// <summary> /// Modifie l'évènement /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonUpdate_Click(object sender, EventArgs e) { if (condition()) { if (verifiLicence()) { Clubs club = new Clubs(); club.setNom(comboBox2.Text); Adherents adherent = new Adherents(); adherent.setId(Int32.Parse(textID.Text)); adherent.setClub(club); adherent.setSexe(comboBox1.Text); adherent.setNom(textNom.Text); adherent.setPrenom(textPrenom.Text); adherent.setLicence(textLicence.Text); adherent.setNaissance(dateTimePicker1.Value); adherent.setAdresse(textAdresse.Text); adherent.setCPT(Int32.Parse(textCodePostal.Text)); adherent.setVille(textVille.Text); adherent.setCotisation(Int32.Parse(textCotisation.Text)); try { ModeleBDD bd = new ModeleBDD(); bd.UPDATEAdherent(adherent); comboBox1.Text = ""; comboBox2.Text = ""; textID.Text = ""; textNom.Text = ""; textPrenom.Text = ""; textLicence.Text = ""; //dateTimePicker1.Value = DateTime.Now; textAdresse.Text = ""; textCodePostal.Text = ""; textVille.Text = ""; textCotisation.Text = ""; label10.Text = adherent.getNom() + " a été modifié "; dataGridView1.ClearSelection(); FillDataGridView(); }catch (Exception e2) { MessageBox.Show("Message d'erreur : " + e2.Message + " \nType de l'exception " + e2.GetType() + " \nPile d'appel" + e2.StackTrace); } } else { MessageBox.Show("La licence doit être unique"); } } else { MessageBox.Show("Veuillez remplir tout les champs"); } }
/// <summary> /// Ajoute un évènements /// </summary> /// <param name="sender"></param> /// <param name="e">l'évènement à ajouter</param> private void buttonInsertion_Click(object sender, EventArgs e) { if (condition()) { if (verifiLicence()) { Clubs club = new Clubs(); club.setNom(comboBox2.Text); Adherents adherent = new Adherents(); adherent.setClub(club); adherent.setSexe(comboBox1.Text); adherent.setNom(textNom.Text); adherent.setPrenom(textPrenom.Text); adherent.setLicence(textLicence.Text); adherent.setNaissance(dateTimePicker1.Value); adherent.setAdresse(textAdresse.Text); adherent.setCPT(Int32.Parse(textCodePostal.Text)); adherent.setVille(textVille.Text); adherent.setCotisation(Int32.Parse(textCotisation.Text)); ModeleBDD bd = new ModeleBDD(); bd.setAdherent(adherent); comboBox1.Text = ""; comboBox2.Text = ""; textNom.Text = ""; textPrenom.Text = ""; textLicence.Text = ""; //dateTimePicker1.Value = DateTime.Now; textAdresse.Text = ""; textCodePostal.Text = ""; textVille.Text = ""; textCotisation.Text = ""; label10.Text = adherent.getNom() + " a été ajouter avec succès "; dataGridView1.ClearSelection(); FillDataGridView(); } else { MessageBox.Show("La Licence doit être unique"); } } else { MessageBox.Show("Veuillez rmplir tout les champs"); } }
//les sont modifié //adherent /// <summary> /// Methode qui selection tous adhernts sur la base de données /// </summary> /// <returns>Return un Listes des adherents</returns> public List <Adherents> getAdherents() { List <Adherents> lesAdherents = new List <Adherents>(); using (MySqlConnection connection = new MySqlConnection(connectionString)) { connection.Open(); string query = "SELECT a.id AS IdAdherent, a.Licence, a.Sexe, a.Nom, a.Prenom, a.Naissance, a.Adresse, a.CodePostal, a.Ville, a.Cotisation, c.id AS IdClub, c.Nom AS NomClub FROM adherents AS a INNER JOIN clubs AS c ON a.id_clubs=c.id"; //Crée Commande MySqlCommand command = new MySqlCommand(query, connection); //On crée un datareader et on execute la commande using (MySqlDataReader dataReader = command.ExecuteReader()) { //On li la base de données et on ajoute dans la liste les ahderents de la base de données while (dataReader.Read()) { Clubs club = new Clubs(); club.setId((int)dataReader["IdClub"]); club.setNom((string)dataReader["NomClub"]); Adherents lAdherent = new Adherents(); lAdherent.setId((int)dataReader["IdAdherent"]); lAdherent.setClub(club); lAdherent.setLicence((string)dataReader["Licence"]); lAdherent.setSexe((string)dataReader["Sexe"]); lAdherent.setNom((string)dataReader["Nom"]); lAdherent.setPrenom((string)dataReader["Prenom"]); lAdherent.setNaissance((DateTime)dataReader["Naissance"]); lAdherent.setAdresse((string)dataReader["Adresse"]); lAdherent.setCPT((int)dataReader["CodePostal"]); lAdherent.setVille((string)dataReader["Ville"]); lAdherent.setCotisation((int)dataReader["Cotisation"]); lesAdherents.Add(lAdherent); } //string MySQLFormatDate = dateValue.ToString("yyyy-MM-dd HH:mm:ss") } connection.Close(); return(lesAdherents); } }