Advertisement
Guest User

Problème C# & MySQL

a guest
Feb 2nd, 2019
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.98 KB | None | 0 0
  1.     public partial class Fm_Saisie_Absence : Form
  2.     {
  3.         string server = "xxxx";
  4.         string database = "gestion_absences";
  5.         string user = "xxxx";
  6.         string pwd = "xxxx";
  7.  
  8.         string pseudo_prof;
  9.  
  10.         public Fm_Saisie_Absence(string pseudo)
  11.         {
  12.             pseudo_prof = pseudo;
  13.             InitializeComponent();
  14.             RecupPromotions(server, database, user, pwd);
  15.  
  16.            
  17.         }
  18.  
  19.  
  20.         private void bt_valider_Click(object sender, EventArgs e)
  21.         {
  22.  
  23.         }
  24.  
  25.         private void Visualiser_Absence_Click(object sender, EventArgs e)
  26.         {
  27.             Form Visualiser_Absence = new Visualiser_Absences(pseudo_prof);
  28.             Visualiser_Absence.Show();
  29.             this.Hide();
  30.         }
  31.  
  32.         private void palmares_absences_Click(object sender, EventArgs e)
  33.         {
  34.             Form Palmarès_Absence = new Palmarès_Absence(pseudo_prof);
  35.             Palmarès_Absence.Show();
  36.             this.Hide();
  37.         }
  38.  
  39.         private void RecupPromotions(string server, string database, string user,string pwd)
  40.         {
  41.             string connectionString;
  42.             connectionString = "SERVER=" + server + ";" + "DATABASE=" +
  43.             database + ";" + "UID=" + user + ";" + "PASSWORD=" + pwd + ";";
  44.             MySqlConnection Cnx = new MySqlConnection(connectionString);
  45.  
  46.             //Execution de la requête
  47.             string requete = "SELECT designation FROM promotions";
  48.             MySqlCommand Cmd = new MySqlCommand(requete, Cnx);
  49.             Cnx.Open();
  50.  
  51.             MySqlDataReader rdr = Cmd.ExecuteReader();
  52.  
  53.             while (rdr.Read())
  54.             {
  55.                 CB_Promotion.Items.Add(rdr["designation"]);
  56.             };
  57.  
  58.             Cnx.Close();
  59.         }
  60.  
  61.         private void CB_Promotion_SelectedIndexChanged(object sender, EventArgs e)
  62.         {
  63.             CLB_Eleves.Items.Clear();
  64.             string id_promotion = (CB_Promotion.SelectedIndex + 1).ToString();
  65.  
  66.             string connectionString;
  67.             connectionString = "SERVER=" + server + ";" + "DATABASE=" +
  68.             database + ";" + "UID=" + user + ";" + "PASSWORD=" + pwd + ";";
  69.             MySqlConnection Cnx = new MySqlConnection(connectionString);
  70.  
  71.             //Execution de la requête
  72.             string requete = "SELECT nom_etudiant, prenom_etudiant FROM etudiants WHERE id_promotion='" + id_promotion +"';" ;
  73.             MySqlCommand Cmd = new MySqlCommand(requete, Cnx);
  74.             Cnx.Open();
  75.  
  76.             MySqlDataReader rdr = Cmd.ExecuteReader();
  77.  
  78.             while (rdr.Read())
  79.             {
  80.                 CLB_Eleves.Items.Add(rdr["nom_etudiant"].ToString() + " " + rdr["prenom_etudiant"].ToString());
  81.             };
  82.             Cnx.Close();
  83.  
  84.             RecupMatieres(server, database, user, pwd, pseudo_prof, id_promotion);
  85.  
  86.         }
  87.  
  88.         private void RecupMatieres(string server, string database, string user, string pwd, string pseudo, string id_promotion)
  89.         {
  90.             string connectionString;
  91.             connectionString = "SERVER=" + server + ";" + "DATABASE=" +
  92.             database + ";" + "UID=" + user + ";" + "PASSWORD=" + pwd + ";";
  93.             MySqlConnection Cnx = new MySqlConnection(connectionString);
  94.  
  95.             //Execution de la requête
  96.             string requete = "SELECT designation FROM matieres, enseignants, lien_matiere_enseignant WHERE enseignants.pseudo='" + pseudo +
  97.                 "' AND lien_matiere_enseignant.id_enseignant = enseignants.id_enseignant " +
  98.                 "AND lien_matiere_enseignant.id_matiere = matieres.id_matiere" +
  99.                 "AND lien_matiere_promotion.id_promotion='" + id_promotion + "';";
  100.             MySqlCommand Cmd = new MySqlCommand(requete, Cnx);
  101.             Cnx.Open();
  102.  
  103.             MySqlDataReader rdr = Cmd.ExecuteReader();
  104.  
  105.             while (rdr.Read())
  106.             {
  107.                 CB_Matieres.Items.Add(rdr["designation"]);
  108.             };
  109.  
  110.             Cnx.Close();
  111.         }
  112.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement