private void buttonUpdate_Click(object sender, EventArgs e) { if (condition()) { TypeClub letype = new TypeClub(); letype.setLibelle(comboBox1.Text); Clubs club = new Clubs(); club.setId(Int32.Parse(textID.Text)); club.setLienSite(textLienSite.Text); club.setNom(textNom.Text); club.setMail(textEmail.Text); club.setType(letype); club.setAdresse(textAdresse.Text); club.setCPT(Int32.Parse(textCPT.Text)); club.setVille(textVille.Text); club.setTel(Int32.Parse(textTel.Text)); ModeleBDD bd = new ModeleBDD(); bd.UPDATEClub(club); labelInfo.Text = club.getNom() + " a été modifié "; dataGridView1.ClearSelection(); FillDataGridView(); } else { MessageBox.Show("Veuillez remplir tout les champs"); } }
//Statistique Cotisation public string AVGCotisation(Clubs leClub) { string moyenne = ""; using (MySqlConnection connection = new MySqlConnection(connectionString)) { connection.Open(); MySqlCommand command = connection.CreateCommand(); command.CommandText = "SELECT AVG(adherents.Cotisation) as Moyenne FROM adherents INNER JOIN clubs ON adherents.id_clubs = clubs.id WHERE clubs.Nom =@Nom"; command.Parameters.AddWithValue("@Nom", leClub.getNom()); using (MySqlDataReader dataReader = command.ExecuteReader()) { Clubs LeClub = new Clubs(); while (dataReader.Read()) { LeClub.setCPT((int)dataReader["Moyenne"]); } } connection.Close(); moyenne = leClub.getCPT().ToString(); return(moyenne); } }
private void buttonInsert_Click(object sender, EventArgs e) { if (condition()) { TypeClub letype = new TypeClub(); letype.setLibelle(comboBox1.Text); Clubs club = new Clubs(); club.setLienSite(textLienSite.Text); club.setNom(textNom.Text); club.setMail(textEmail.Text); club.setType(letype); club.setAdresse(textAdresse.Text); club.setCPT(Int32.Parse(textCPT.Text)); club.setVille(textVille.Text); club.setTel(Int32.Parse(textTel.Text)); try { ModeleBDD bd = new ModeleBDD(); bd.setClub(club); textNom.Text = ""; textLienSite.Text = ""; comboBox1.Text = ""; textEmail.Text = ""; textAdresse.Text = ""; textCPT.Text = ""; textVille.Text = ""; textTel.Text = ""; labelInfo.Text = club.getNom() + " a été ajouter avec succès "; dataGridView1.ClearSelection(); FillDataGridView(); }catch (Exception e1) { MessageBox.Show("Message d'erreur : " + e1.Message + " \nType de l'exception " + e1.GetType() + " \nPile d'appel" + e1.StackTrace); } } else { MessageBox.Show("Veuillez remplir tout les champs"); } }
//La methode est modifié //club /// <summary> /// Methode qui selection tous clubs sur la base de données /// </summary> /// <returns>Return un Listes des clubs</returns> public List <Clubs> getClubs() { List <Clubs> lesClubs = new List <Clubs>(); using (MySqlConnection connection = new MySqlConnection(connectionString)) { connection.Open(); string query = "SELECT c.id AS IdClub, c.Nom, c.LienSIte, c.Adresse, c.Ville, c.CodePostal, c.Telephone, c.Email, c.id_type, t.id AS IdType, t.Libelle From clubs AS c INNER JOIN type AS t ON c.id_type = t.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 ajiute dans la liste les ahderents de la base de données while (dataReader.Read()) { TypeClub Type = new TypeClub(); Type.setId((int)dataReader["IdType"]); Type.setLibelle((string)dataReader["Libelle"]); Clubs lClub = new Clubs(); lClub.setId((int)dataReader["IdClub"]); lClub.setLienSite((string)dataReader["LienSite"]); lClub.setMail((string)dataReader["Email"]); lClub.setNom((string)dataReader["Nom"]); lClub.setType(Type); lClub.setTel((int)dataReader["Telephone"]); lClub.setAdresse((string)dataReader["Adresse"]); lClub.setCPT((int)dataReader["CodePostal"]); lClub.setVille((string)dataReader["Ville"]); lesClubs.Add(lClub); } } connection.Close(); return(lesClubs); } }