Partage
  • Partager sur Facebook
  • Partager sur Twitter

Facture ITEXTCSHARP

    17 février 2023 à 9:58:01

    Bonjour

    je suis entrais de crée une facture en utilisons la méthode ITEXTCSHARP ,

    -1 avent d'imprimer j'afficher d'abord mon datagrid.

    -2 après savoir afficher mon datagrid, je sélection une cellule la grille, la ligne entière est sélectionnée et la méthode PrintDocument_PrintEleve est appelée pour imprimer la ligne sélectionnée. Si aucune cellule n'est sélectionnée, une boîte de message est affichée pour avertir l'utilisateur, Dans la méthode PrintDocument_PrintEleve, la ligne sélectionnée est récupérée à partir du DataGridView et les données de chaque cellule sont imprimées dans un document PDF en utilisant la bibliothèque iTextSharp.

    je code ne m'envoi pas de message d'erreur, même si je sélection une ligne de la cellule je ne récuper pas de donnée dans la grille

            private void Btn_ImprimerR_Click(object sender, EventArgs e)
            {
                if(DTG_AReinscription.SelectedCells.Count > 0)
                {
                    // Récupérer la cellule sélectionnée
                    DataGridViewCell cell = DTG_AReinscription.SelectedCells[0];
    
                    // Récupérer la ligne de la cellule sélectionnée
                    DataGridViewRow row = cell.OwningRow;
    
                    // Sélectionner la ligne
                    row.Selected = true;
    
                    // Imprimer la ligne sélectionnée
                    PrintDialog printDialog = new PrintDialog();
                    PrintDocument printDocument = new PrintDocument();
                    printDialog.Document = printDocument;
                    printDocument.PrintPage += new PrintPageEventHandler(PrintDocument_PrintEleve);
    
                    DialogResult result = printDialog.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        printDocument.Print();
                    }
                }else
                {
                    MessageBox.Show("Vous devez sélectionner une ligne pour imprimer.", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
     private void PrintDocument_PrintEleve(object sender, System.Drawing.Printing.PrintPageEventArgs e)
            {
                if (DTG_AReinscription.SelectedRows.Count > 0)
                {
                    DataGridViewRow row = DTG_AReinscription.SelectedRows[0];
    
                    // Parcourir les colonnes de la ligne sélectionnée et imprimer les données
                    for (int i = 0; i < row.Cells.Count; i++)
                    {
                        string cellValue = row.Cells[i].FormattedValue.ToString();
    
                        // Créer un document PDF
                        Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
    
                        // Créer un flux de sortie pour enregistrer le PDF
                        PdfWriter.GetInstance(pdfDoc, new FileStream("Facture.pdf", FileMode.Create));
                        pdfDoc.Open();
    
                        // Créer une table pour l'en-tête
                        PdfPTable headerTable = new PdfPTable(1);
                        headerTable.DefaultCell.BorderWidth = 0;
                        headerTable.DefaultCell.BorderColor = BaseColor.WHITE;
    
                        // Ajouter le nom de l'école à l'en-tête
                        Bitmap bmp = new Bitmap("C:\\Users\\Parfait André\\OneDrive\\Documents\\Visual Studio 2022\\Templates\\ProjectTemplates\\C#\\GESTION_KELASI\\GESTION_KELASI\\bin\\Debug\\logo-design.jpg");
                        bmp.MakeTransparent(Color.White);
    
                        iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance(bmp, ImageFormat.Jpeg);
                        logo.ScalePercent(7f);
                        logo.SetAbsolutePosition(35, 750);
                        pdfDoc.Add(logo);
    
    
                        // Ajouter le nom de l'école à l'en-tête
                        PdfPCell cell = new PdfPCell(new Phrase("ECOLE PRIVEE \nLE HAVRE DE LA PEDAGOGIE HP-r@", FontFactory.GetFont("Arial", 15, iTextSharp.text.Font.BOLD)));
                        cell.HorizontalAlignment = Element.ALIGN_CENTER;
                        cell.Border = PdfPCell.NO_BORDER;
                        headerTable.AddCell(cell);
                        //////////////////////////////
                        /////////////////////////////
                        cell = new PdfPCell(new Phrase("-----------------------------------------------------------------------", FontFactory.GetFont("Arial", 5, iTextSharp.text.Font.BOLD)));
                        cell.HorizontalAlignment = Element.ALIGN_CENTER;
                        cell.Border = PdfPCell.NO_BORDER;
                        headerTable.AddCell(cell);
                        //////////////////////////////////
                        /////////////////////////////////
    
                        cell = new PdfPCell(new Phrase("02 rue Ekouamo, \nQuarier Moukondo-Ngamblo", FontFactory.GetFont("Arial", 10, iTextSharp.text.Font.BOLD)));
                        cell.HorizontalAlignment = Element.ALIGN_CENTER;
                        cell.Border = PdfPCell.NO_BORDER;
                        headerTable.AddCell(cell);
    
                        cell = new PdfPCell(new Phrase("En face du camp COMUS-Brazzaville", FontFactory.GetFont("Arial", 10, iTextSharp.text.Font.BOLD)));
                        cell.HorizontalAlignment = Element.ALIGN_CENTER;
                        cell.Border = PdfPCell.NO_BORDER;
                        headerTable.AddCell(cell);
    
                        cell = new PdfPCell(new Phrase("B.P : 0125 Tél : 05555655 / 25625555", FontFactory.GetFont("Arial", 10, iTextSharp.text.Font.BOLD)));
                        cell.HorizontalAlignment = Element.ALIGN_CENTER;
                        cell.Border = PdfPCell.NO_BORDER;
                        headerTable.AddCell(cell);
    
                        /* LineSeparator line = new LineSeparator();
                         line.LineColor = new BaseColor(System.Drawing.Color.Black);
                         line.LineWidth = 1;
                         pdfDoc.Add(line);*/
    
                        //////////////////////////////
                        /////////////////////////////
                        cell = new PdfPCell(new Phrase("-----------------------------------------------", FontFactory.GetFont("Arial", 5, iTextSharp.text.Font.BOLD)));
                        cell.HorizontalAlignment = Element.ALIGN_CENTER;
                        cell.Border = PdfPCell.NO_BORDER;
                        headerTable.AddCell(cell);
                        //////////////////////////////////
                        /////////////////////////////////
    
                        Paragraph heureParagraphe = new Paragraph("Heure actuelle : " + DateTime.Now.ToString("HH:mm:ss") + "                                                             Classe : " + DTG_AReinscription.Rows[0].Cells["Column14"].Value.ToString(), FontFactory.GetFont("Arial", 12));
                        headerTable.AddCell(heureParagraphe);
    
    
                        cell = new PdfPCell(new Phrase(" "));
                        cell.Colspan = 4;
                        cell.FixedHeight = 10;
                        cell.Border = PdfPCell.NO_BORDER;
                        headerTable.AddCell(cell);
    
                        // Définir la taille de ligne par défaut pour la table
    
                        // Définir la taille de ligne par défaut pour la table
    
                        cell = new PdfPCell(new Phrase("Client : " + "                                                                Reçu : N° " + DTG_AReinscription.Rows[0].Cells["Column10"].Value.ToString(), FontFactory.GetFont("Arial", 12, iTextSharp.text.Font.BOLD)));
                        cell.HorizontalAlignment = Element.ALIGN_CENTER;
                        cell.Border = PdfPCell.TOP_BORDER;
                        cell.BorderWidthTop = 2f; // ajouter une bordure en haut de la cellule
                        cell.Colspan = 4;
                        cell.Phrase.Leading = 25f; // ajouter un espace de 25 points entre les lignes
                        cell.FixedHeight = 30f; // ajouter un espace de 30 points entre les lignes
                        headerTable.AddCell(cell);
    
    
                        cell = new PdfPCell(new Phrase("Reçu de la Réinscription", FontFactory.GetFont("Arial", 14, iTextSharp.text.Font.BOLD)));
                        cell.HorizontalAlignment = Element.ALIGN_CENTER;
                        cell.Border = PdfPCell.NO_BORDER;
                        //cell.BorderWidthTop = 2f; // ajouter une bordure en haut de la cellule
                        cell.Colspan = 4;
                        cell.Phrase.Leading = 25f; // ajouter un espace de 25 points entre les lignes
                        cell.FixedHeight = 30f; // ajouter un espace de 30 points entre les lignes
                        headerTable.AddCell(cell);
    
                        string nom = DTG_AReinscription.Rows[0].Cells["Column2"].Value.ToString();
                        string prenom = DTG_AReinscription.Rows[0].Cells["Column3"].Value.ToString();
    
                        string nomComplet = nom + " " + prenom;
    
                        cell = new PdfPCell(new Phrase("Matricul : " + DTG_AReinscription.Rows[0].Cells["Column9"].Value.ToString() + "            : " + nomComplet, FontFactory.GetFont("Arial", 12)));
                        cell.HorizontalAlignment = Element.ALIGN_LEFT;
                        cell.Border = PdfPCell.NO_BORDER;
                        cell.Colspan = 4;
                        cell.Phrase.Leading = 25f; // ajouter un espace de 25 points entre les lignes
                        cell.FixedHeight = 30f; // ajouter un espace de 30 points entre les lignes
                        headerTable.AddCell(cell);
    
                        cell = new PdfPCell(new Phrase("Classe : " + DTG_AReinscription.Rows[0].Cells["Column13"].Value.ToString(), FontFactory.GetFont("Arial", 12)));
                        cell.HorizontalAlignment = Element.ALIGN_LEFT;
                        cell.Border = PdfPCell.NO_BORDER;
                        cell.Colspan = 4;
                        cell.Phrase.Leading = 25f; // ajouter un espace de 25 points entre les lignes
                        cell.FixedHeight = 30f; // ajouter un espace de 30 points entre les lignes
                        headerTable.AddCell(cell);
    
                        cell = new PdfPCell(new Phrase("Montant payé : " + "#" + DTG_AReinscription.Rows[0].Cells["Column17"].Value.ToString() + "#", FontFactory.GetFont("Arial", 12, iTextSharp.text.Font.BOLD)));
                        cell.HorizontalAlignment = Element.ALIGN_LEFT;
                        cell.Border = PdfPCell.NO_BORDER;
                        cell.Colspan = 4;
                        cell.Phrase.Leading = 25f; // ajouter un espace de 25 points entre les lignes
                        cell.FixedHeight = 30f; // ajouter un espace de 30 points entre les lignes
                        headerTable.AddCell(cell);
    
                        cell = new PdfPCell(new Phrase("Mode règlement  : Espèce ", FontFactory.GetFont("Arial", 12)));
                        cell.HorizontalAlignment = Element.ALIGN_LEFT;
                        cell.Border = PdfPCell.NO_BORDER;
                        cell.Colspan = 4;
                        cell.Phrase.Leading = 25f; // ajouter un espace de 25 points entre les lignes
                        cell.FixedHeight = 30f; // ajouter un espace de 30 points entre les lignes
                        headerTable.AddCell(cell);
    
                        cell = new PdfPCell(new Phrase("NB : Arrêté le present à la somme : " + "#" + DTG_AReinscription.Rows[0].Cells["Column17"].Value.ToString() + "#" + "   Francs CFA", FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD)));
                        cell.HorizontalAlignment = Element.ALIGN_LEFT;
                        cell.Border = PdfPCell.NO_BORDER;
                        cell.Colspan = 4;
                        cell.Phrase.Leading = 25f; // ajouter un espace de 25 points entre les lignes
                        cell.FixedHeight = 30f; // ajouter un espace de 30 points entre les lignes
                        headerTable.AddCell(cell);
    
                        cell = new PdfPCell(new Phrase("Fait à Brazzaville, le " + DTG_AReinscription.Rows[0].Cells["Column11"].Value.ToString(), FontFactory.GetFont("Arial", 12)));
                        cell.HorizontalAlignment = Element.ALIGN_LEFT;
                        cell.Border = PdfPCell.NO_BORDER;
                        cell.Colspan = 2;
                        cell.Phrase.Leading = 5f * cell.Phrase.Font.Size;
                        headerTable.AddCell(cell);
    
                        cell = new PdfPCell(new Phrase("Signature de la caissière", FontFactory.GetFont("Arial", 12)));
                        cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                        cell.Border = PdfPCell.NO_BORDER;
                        cell.Colspan = 2;
                        cell.Phrase.Leading = 5f * cell.Phrase.Font.Size;
                        headerTable.AddCell(cell);
                        /////////////////////////////////
                        ///
    
                        cell = new PdfPCell(new Phrase(" "));
                        cell.Colspan = 4;
                        cell.FixedHeight = 10;
                        cell.Border = PdfPCell.NO_BORDER;
                        headerTable.AddCell(cell);
    
                        cell = new PdfPCell(new Phrase("Caisse", FontFactory.GetFont("Arial", 12, iTextSharp.text.Font.BOLD)));
                        cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                        cell.Border = PdfPCell.NO_BORDER;
                        cell.Colspan = 2;
                        headerTable.AddCell(cell);
    
                        pdfDoc.Add(headerTable);
                        pdfDoc.Close();
                    }
                }
                else
                {
                    MessageBox.Show("Afficher les données avant d'imprimer les information");
                }
            }  

    merci cordialement. 


    • Partager sur Facebook
    • Partager sur Twitter
      17 février 2023 à 17:45:29

      Copie d'écran du message d'erreur, SVP.
      • Partager sur Facebook
      • Partager sur Twitter
      Je recherche un CDI/CDD/mission freelance comme Architecte Logiciel/ Expert Technique sur technologies Microsoft.
        17 février 2023 à 19:48:02

        il n'y a pas de message d'erreur.
        • Partager sur Facebook
        • Partager sur Twitter
          20 février 2023 à 10:51:07

          Désolé, j'avais mal lu. :-°
          • Partager sur Facebook
          • Partager sur Twitter
          Je recherche un CDI/CDD/mission freelance comme Architecte Logiciel/ Expert Technique sur technologies Microsoft.

          Facture ITEXTCSHARP

          × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
          × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
          • Editeur
          • Markdown