private void PrintDocumentEditionAelier_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { try { int x = 10, y = 10; Atelier ate = new Atelier(); ate = (Atelier)listAtelier.SelectedItem; int ateId = ate.GetId(); String ateNom = ate.GetNom(); String ateDescription = ate.GetDescription(); String ateHoraire = ate.GetHoraire(); DateTime ateJour = ate.GetJour(); int ateNbrPlace = ate.GetNbrPlace(); String atePublicConcerne = ate.GetPublicConcerne(); Font drawFont = new Font("Arial", 16); SolidBrush drawBrush = new SolidBrush(Color.Black); e.Graphics.DrawString("Voici l'atelier n°" + ateId + " : " + ateNom + " pour les " + atePublicConcerne, drawFont, drawBrush, x, y); e.Graphics.DrawString("Description :" + ateDescription + " Nombre de place total : " + ateNbrPlace, drawFont, drawBrush, x, y + 30); e.Graphics.DrawString("Jour :" + ateJour + " Horaire : " + ateHoraire, drawFont, drawBrush, x, y + 60); e.Graphics.DrawString("Voici les enfants inscrits :", drawFont, drawBrush, x, y + 100); e.Graphics.DrawImage(bmp, x, y + 190); } catch { } }
private void listAtelier_SelectedIndexChanged(object sender, EventArgs e) { try { Atelier ate = new Atelier(); ate = (Atelier)listAtelier.SelectedItem; int ateId = ate.GetId(); Console.WriteLine(ateId); MySqlConnection conn = null; conn = DBMySQLUtils.GetDBConnection("172.29.102.22", "ram", "root", "root"); String recupEnfant = null; recupEnfant = "CALL `recup_Enfant_Atelier2`(@pateId);"; MySqlCommand afficherEnfant = null; afficherEnfant = conn.CreateCommand(); afficherEnfant.CommandText = recupEnfant; afficherEnfant.Parameters.AddWithValue("@pateId", ateId); conn.Open(); DataTable dt = new DataTable(); MySqlDataAdapter adapter = null; adapter = new MySqlDataAdapter(afficherEnfant); adapter.Fill(dt); dataGridViewListeEnfant.DataSource = null; dataGridViewListeEnfant.Rows.Clear(); dataGridViewListeEnfant.Refresh(); foreach (DataRow row in dt.Rows) { populate(row[0].ToString(), row[1].ToString(), row[2].ToString(), row[3].ToString(), row[4].ToString(), row[5].ToString(), row[6].ToString(), row[7].ToString()); } // Terminez la connexion. conn.Close(); // Disposez un objet, libérez des ressources. conn.Dispose(); } catch (Exception e5) { Console.WriteLine("Error: " + e5); Console.WriteLine(e5.StackTrace); } Console.Read(); }
private void btnAjoutEnfantAtelier_Click(object sender, EventArgs e) { Console.WriteLine(listEnfant.SelectedItem); Console.WriteLine(listAtelier.SelectedItem); Atelier ate = new Atelier(); ate = (Atelier)listAtelier.SelectedItem; Console.WriteLine(ate); int ateId = ate.GetId(); Console.WriteLine(ateId); Enfant enf = new Enfant(); enf = (Enfant)listEnfant.SelectedItem; int enfId = enf.GetId(); Console.WriteLine(enfId); MySqlConnection conn = DBMySQLUtils.GetDBConnection("172.29.102.22", 3306, "ram", "root", "root"); string sql = "CALL `creer_Lien`(@pEnfId , @pAteId);"; // Créez un objet Command. MySqlCommand cmd = new MySqlCommand(sql, conn); cmd.Parameters.AddWithValue("@pEnfId", enfId); cmd.Parameters.AddWithValue("@pAteId", ateId); conn.Open(); try { if (cmd.ExecuteNonQuery() > 0) { MessageBox.Show("Enfant mis à jour"); } conn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); conn.Close(); } }
private void EditionAtelier_Load(object sender, EventArgs e) { { List <Atelier> lstAtelier = new List <Atelier>(); MySqlConnection conn = DBMySQLUtils.GetDBConnection("172.29.102.22", 3306, "ram", "root", "root"); string sql = "CALL `recup_Atelier`();"; // Créez un objet Command. MySqlCommand cmd = new MySqlCommand(sql, conn); string sql2 = "CALL `recup_Enfant`();"; // Créez un objet Command. MySqlCommand cmd2 = new MySqlCommand(sql2, conn); conn.Open(); using (MySqlDataReader objReader = cmd.ExecuteReader()) { if (objReader.HasRows) { while (objReader.Read()) { //I would also check for DB.Null here before reading the value. int ateId = objReader.GetInt32(objReader.GetOrdinal("ateId")); String ateNom = objReader.GetString(objReader.GetOrdinal("ateNom")); String ateDescription = objReader.GetString(objReader.GetOrdinal("ateDescription")); String ateHoraire = objReader.GetString(objReader.GetOrdinal("ateHoraire")); DateTime ateJour = objReader.GetDateTime(objReader.GetOrdinal("ateJour")); int ateNbrPlace = objReader.GetInt32(objReader.GetOrdinal("ateNbrPlace")); String atePublicConcerne = objReader.GetString(objReader.GetOrdinal("atePublicConcerne")); Atelier atelier = new Atelier(ateId, ateNom, ateDescription, ateHoraire, ateJour, ateNbrPlace, atePublicConcerne); listAtelier.Items.Add(atelier); } } } conn.Close(); } }