/// <summary> /// retourne une liste de tout les adherents sans club dans la table /// </summary> /// <returns></returns> public List <adhérent> ReadadherentSansClub() { List <adhérent> liste = new List <adhérent>(); adhérent adhérents; using ( connexion ) { connexion.Open(); string requete = "SELECT * FROM adherent where adherent.id_club is Null"; MySqlCommand cmd = new MySqlCommand(requete, connexion); using (MySqlDataReader datareader = cmd.ExecuteReader()) { while (datareader.Read()) { adhérents = new adhérent((string)datareader["Nom_adherent"], (string)datareader["Prenom_adherent"], (string)datareader["Ville_adherent"], (string)datareader["numero_licence"], (string)datareader["Code_Postal_adherent"], Convert.ToDouble(datareader["cotisation_adherent"]), (DateTime)datareader["Date_naissance_adherent"], (string)datareader["Adresse_adherent"]); adhérents.id = (int)datareader["id_adherent"]; liste.Add(adhérents); } } } return(liste); }
private void metroGridAdherent_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { index = metroGridAdherent.CurrentRow.Index; adherentModif = adherent.GetAdhérentliste(index); ModifierAdherent modif = new ModifierAdherent(adherent, adherentModif); modif.ShowDialog(); }
/// <summary> /// delete un adherent de la table en fonction de l'id /// </summary> /// <param name="adhérents"></param> public void supprimerAdherent(adhérent adhérents) { using (connexion ) { connexion.Open(); string requete = "DELETE FROM adherent WHERE id_adherent = @id"; MySqlCommand cmd = new MySqlCommand(requete, connexion); cmd.Parameters.AddWithValue("@id", adhérents.id); cmd.ExecuteNonQuery(); } }
/// <summary> /// update dans la table de la clé étrangère id_club d'un adherent en NULL /// </summary> /// <param name="adhérents"></param> public void EnleverAdherentAclub(adhérent adhérents) { using (connexion ) { connexion.Open(); string requete = "UPDATE adherent SET id_club = Null WHERE adherent.id_adherent = @id;"; MySqlCommand cmd = new MySqlCommand(requete, connexion); cmd.Parameters.AddWithValue("@id", adhérents.id); cmd.ExecuteNonQuery(); } }
private void metroButtonAjout_Click(object sender, EventArgs e) { adherent = listAdherents.GetAdhérentliste(indexAdherent); club = listClubs.GetClubliste(indexClub); adherent.club = club; connect.AjoutAdherentAclub(adherent); listBoxAdherents.Items.Clear(); listAdherents.listM = connect.ReadadherentSansClub(); foreach (var item in listAdherents.listM) { listBoxAdherents.Items.Add(item.nom + " " + item.prenom); } }
/// <summary> /// update dans la table d'un adherent en fonction de l'id des modifications des données /// </summary> /// <param name="adhérents"></param> public void ModifAdherent(adhérent adhérents) { using ( connexion ) { connexion.Open(); string requete = "UPDATE `adherent` SET `Nom_adherent` = @nom, `Prenom_adherent` = @prenom, `Date_naissance_adherent` = @date, `Adresse_adherent` = @adresse, `Code_Postal_adherent` = @codepostal, `Ville_adherent` = @ville, `cotisation_adherent` = @cotisation WHERE `adherent`.`id_adherent` = @id"; MySqlCommand cmd = new MySqlCommand(requete, connexion); cmd.Parameters.AddWithValue("@nom", adhérents.nom); cmd.Parameters.AddWithValue("@prenom", adhérents.prenom); cmd.Parameters.AddWithValue("@date", adhérents.date); cmd.Parameters.AddWithValue("@adresse", adhérents.Adresse); cmd.Parameters.AddWithValue("@codepostal", adhérents.codepostal); cmd.Parameters.AddWithValue("@ville", adhérents.ville); cmd.Parameters.AddWithValue("@cotisation", adhérents.cotisation); cmd.Parameters.AddWithValue("@id", adhérents.id); cmd.ExecuteNonQuery(); } }
/// <summary> /// insert dans la table d'un adherent avec les données saisies /// </summary> /// <param name="adhérents"></param> public void ajouterAdherent(adhérent adhérents) { using ( connexion ) { connexion.Open(); string requete = "INSERT INTO `adherent` (`id_adherent`, `numero_licence`, `Nom_adherent`, `Prenom_adherent`, `Date_naissance_adherent`, `Adresse_adherent`, `Code_Postal_adherent`, `Ville_adherent`, `cotisation_adherent`, `id_club`) VALUES (NULL, @numero, @nom, @prenom, @date, @adresse, @codepostal, @ville, @cotisation, NULL);"; MySqlCommand cmd = new MySqlCommand(requete, connexion); cmd.Parameters.AddWithValue("@nom", adhérents.nom); cmd.Parameters.AddWithValue("@prenom", adhérents.prenom); cmd.Parameters.AddWithValue("@date", adhérents.date); cmd.Parameters.AddWithValue("@adresse", adhérents.Adresse); cmd.Parameters.AddWithValue("@codepostal", adhérents.codepostal); cmd.Parameters.AddWithValue("@ville", adhérents.ville); cmd.Parameters.AddWithValue("@numero", adhérents.numero); cmd.Parameters.AddWithValue("@cotisation", adhérents.cotisation); cmd.ExecuteNonQuery(); } }
/// <summary> /// La méthode Readadherent retourne une liste de tout les adhernents dans la table. /// </summary> /// <param ></param> /// <returns></returns> public List <adhérent> Readadherent() { List <adhérent> liste = new List <adhérent>(); adhérent adhérents; Club club; using (connexion) { connexion.Open(); string requete = "SELECT id_adherent, Nom_adherent,numero_licence, Prenom_adherent, Date_naissance_adherent , Adresse_adherent, Code_Postal_adherent,Ville_adherent,cotisation_adherent,club.id_club,Titre_club,url_club,Adresse_club,Code_Postal_club,Ville_club,mail_club,id_type_club,telephone_club FROM adherent INNER join club on adherent.id_club = club.id_club"; MySqlCommand cmd = new MySqlCommand(requete, connexion); using (MySqlDataReader datareader = cmd.ExecuteReader()) { while (datareader.Read()) { adhérents = new adhérent((string)datareader["Nom_adherent"], (string)datareader["Prenom_adherent"], (string)datareader["Ville_adherent"], (string)datareader["numero_licence"], (string)datareader["Code_Postal_adherent"], Convert.ToDouble(datareader["cotisation_adherent"]), (DateTime)datareader["Date_naissance_adherent"], (string)datareader["Adresse_adherent"]); club = new Club( (string)datareader["Titre_club"], (string)datareader["url_club"], (string)datareader["Ville_club"], (string)datareader["telephone_club"], (string)datareader["Code_Postal_club"], (string)datareader["mail_club"], (int)datareader["id_type_club"], (string)datareader["Adresse_club"]); club.id = (int)datareader["id_club"]; adhérents.id = (int)datareader["id_adherent"]; adhérents.club = club; liste.Add(adhérents); } } } return(liste); }
private void metroButtonSupprimer_Click(object sender, EventArgs e) { adhérentselectionner = adherent.GetAdhérentliste(index); adherent.GetAdhérentliste(index); connect.supprimerAdherent(adhérentselectionner); // adherent.suppression(index); listBoxSupprimer.Items.Clear(); adherent.listM = connect.ReadadherentSansClub(); adherent.listM.AddRange(connect.Readadherent()); foreach (var item in adherent.listM) { listBoxSupprimer.Items.Add(item.nom + " " + item.prenom); } }
private void metroButtonDesinscrire_Click(object sender, EventArgs e) { adhérentselectionner = adherent.GetAdhérentliste(index); adherent.GetAdhérentliste(index); connect.EnleverAdherentAclub(adhérentselectionner); // adherent.suppression(index); listBoxadherent.Items.Clear(); adherent.listM = connect.ReadadherentAvecClub(); foreach (var item in adherent.listM) { listBoxadherent.Items.Add(item.nom + " " + item.prenom); } }
private void metroButtonAjouter_Click(object sender, EventArgs e) { try { //string nom = textBoxN.Text; string nom = textBoxN.Text; string prenom = textBoxP.Text; string ville = textBoxVille.Text; double cotisation = Convert.ToDouble(maskedTextBoxCotisation.Text); string numero = Convert.ToString(rand.Next()); string codepostal = maskedTextBoxCodePostal.Text; string adresse = textBoxAdresse.Text; DateTime date = monthCalendar1.SelectionStart; adhérent adherent = new adhérent(nom, prenom, ville, numero, codepostal, cotisation, date, adresse); // listAd.AjouterAdherent(adherent); adherent.date = date; DAOadherent connect = new DAOadherent(); connect.ajouterAdherent(adherent); MetroFramework.MetroMessageBox.Show(this, "l'adhérent a été ajouté à la base de données avec succès !", "Félicitation", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MetroFramework.MetroMessageBox.Show(this, "problème lors de la saisie !", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error); } textBoxN.Text = string.Empty; textBoxP.Text = string.Empty; maskedTextBoxCodePostal.Text = string.Empty; maskedTextBoxCotisation.Text = string.Empty; textBoxVille.Text = string.Empty; textBoxAdresse.Text = string.Empty; }
public void AjouterAdherent(adhérent adherent) { listM.Add(adherent); }
public ModifierAdherent(AdherentManagement listAdherent, adhérent adherentModif) { InitializeComponent(); this.listAd = listAdherent; this.adherentModif = adherentModif; }