public AttributionSalle() { InitializeComponent(); lesActiviteSansSalle = new List <Activite>(); lesActivitesSave = new List <Activite>(); act = new Activite(); typeActivite = new Type(); lesActivites = new List <Activite>(); lesActivites = act.InitActivite(); typeActivite.InitListeType(); foreach (Activite a in lesActivites) { if (string.IsNullOrEmpty(a.Salle)) { lesActiviteSansSalle.Add(a); } } lesActiviteSansSalle = lesActiviteSansSalle.OrderBy(o => o.Heuredebut).ToList(); MessageBox.Show("Vous allez attribuer des salles aux activités", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); changerActivite(); }
private void creerPDFlisteactives(bool estprotect) { int i = 0; lesActivites = activitechoisie.InitActivite(); listeType = type.InitType(); recupDates(); try { string nompdf = Properties.Settings.Default["savePDFCommun"].ToString(); // Récupère le chemin Document doc = new Document(); if (estprotect == true) { nompdf += "listeactivitee.pdf"; } else { nompdf += "listeactivitep.pdf"; } PdfWriter listeActPDF = PdfWriter.GetInstance(doc, new FileStream(nompdf, FileMode.Create, FileAccess.Write)); if (estprotect == true) { System.Text.UTF8Encoding enconding = new System.Text.UTF8Encoding(); // Création du norme d'encodage listeActPDF.SetEncryption(null, enconding.GetBytes("123456789"), PdfWriter.AllowScreenReaders, PdfWriter.STRENGTH128BITS); // Encryptage du fichier PDF qui autorise seulement la lecture de celui-ci } doc.Open(); Paragraph paragraph = new Paragraph(); Phrase titre = new Phrase("Listes des activités de Joach Autrement", FontFactory.GetFont(FontFactory.COURIER, 20)); paragraph.Alignment = Element.ALIGN_CENTER; paragraph.SpacingAfter = 15; paragraph.Add(titre); doc.Add(paragraph); lesDates = lesDates.OrderBy(x => x.Date).ToList(); foreach (DatePDF d in lesDates) { d.LesActivites = d.LesActivites.OrderBy(x => x.IdType).ThenBy(x => x.Heuredebut).ToList(); foreach (Type untype in listeType) { Paragraph p = new Paragraph(); Phrase t = new Phrase(d.Date.ToLongDateString().ToUpper() + " " + d.Libelle + "\n" + untype.Libelle, FontFactory.GetFont(FontFactory.COURIER, 20)); p.Add(t); p.Alignment = Element.ALIGN_CENTER; p.SpacingAfter = 15; doc.NewPage(); doc.Add(p); foreach (Activite act in d.LesActivites) { if (act.IdType == untype.Id) { i++; iTextSharp.text.Font gras = new iTextSharp.text.Font(); string typeecriture = "bold"; gras.SetStyle(typeecriture); iTextSharp.text.Font italique = new iTextSharp.text.Font(); typeecriture = "italic"; italique.SetStyle(typeecriture); PdfPTable tableactivite = new PdfPTable(2); //Table regroupant toutes les autres tables pour les infos de cette activité float[] taillecolonnetableactivite = { 30, 70 }; tableactivite.SetWidths(taillecolonnetableactivite); tableactivite.DefaultCell.Border = iTextSharp.text.Rectangle.NO_BORDER; tableactivite.DefaultCell.BorderWidthTop = 2; tableactivite.DefaultCell.BorderWidthBottom = 2; PdfPTable tablecodeheure = new PdfPTable(1); PdfPTable Colonnedroite = new PdfPTable(1); Colonnedroite.DefaultCell.BorderWidthTop = iTextSharp.text.Rectangle.NO_BORDER; Colonnedroite.DefaultCell.BorderWidthRight = iTextSharp.text.Rectangle.NO_BORDER; Colonnedroite.DefaultCell.BorderWidthBottom = iTextSharp.text.Rectangle.NO_BORDER; PdfPTable tablelibelledescription = new PdfPTable(1); PdfPTable tableinfodivers = new PdfPTable(3); PdfPCell infoCode = new PdfPCell(); Phrase infocode = new Phrase(act.Code, gras); infoCode.BorderWidth = PdfPCell.NO_BORDER; infoCode.AddElement(infocode); Phrase infoheures = new Phrase(act.Heuredebut.ToShortTimeString() + " - " + act.Heurefin.ToShortTimeString()); infoCode.AddElement(infoheures); tablecodeheure.AddCell(infoCode); tableactivite.AddCell(tablecodeheure); PdfPCell infolibelledescri = new PdfPCell(); Phrase infolibelle = new Phrase(act.Libelle, gras); infolibelledescri.BorderWidth = PdfPCell.NO_BORDER; infolibelledescri.AddElement(infolibelle); Phrase infoentetelibelledescri = new Phrase(act.EnteteDescription, FontFactory.GetFont(BaseFont.TIMES_ITALIC)); infolibelledescri.AddElement(infoentetelibelledescri); Phrase infodescription = new Phrase(act.Description); infolibelledescri.AddElement(infodescription); tablelibelledescription.AddCell(infolibelledescri); Colonnedroite.AddCell(tablelibelledescription); PdfPCell prerequisclasse = new PdfPCell(new Phrase(act.Restriction)); prerequisclasse.BorderWidth = PdfPCell.NO_BORDER; tableinfodivers.AddCell(prerequisclasse); PdfPCell infoNombreeleve = new PdfPCell(); Paragraph infonombreelevep = new Paragraph(new Phrase(act.Nombreplaces + " élèves")); infoNombreeleve.BorderWidth = PdfPCell.NO_BORDER; infonombreelevep.Alignment = Element.ALIGN_CENTER; infoNombreeleve.AddElement(infonombreelevep); tableinfodivers.AddCell(infoNombreeleve); PdfPCell infoSalle = new PdfPCell(); Paragraph infosallep = new Paragraph(new Phrase(act.Salle)); infoSalle.BorderWidth = PdfPCell.NO_BORDER; infosallep.Alignment = Element.ALIGN_CENTER; infoSalle.AddElement(infosallep); tableinfodivers.AddCell(infoSalle); Colonnedroite.AddCell(tableinfodivers); tableactivite.AddCell(Colonnedroite); doc.Add(tableactivite); } } } } doc.Close(); } catch (System.IO.IOException err)// gestion des erreurs { MessageBox.Show("Erreur pdf: " + err, "Problème connection", MessageBoxButtons.OK, MessageBoxIcon.Error); } }