Veuillez m'aider pour la correction de mon programme. L'exportation ne marche pas. Je veux également un programme qui permettra d'imprimer la table.
Merci beaucoup d'avance


Code Source:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using iText.Layout.Properties;

namespace SP_MARKET
{
public partial class Rapport : Form
{
private Fonctions Con;

public Rapport()
{
InitializeComponent();
Con = new Fonctions();
}

private void ExportToPDF()
{
// Demander à l'utilisateur où sauvegarder le fichier
using (SaveFileDialog saveFileDialog = new SaveFileDialog
{
Filter = "PDF Files|*.pdf",
Title = "Save a PDF File",
FileName = "Factures.pdf"
})
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
// Récupérer les données de la base de données
DataTable factures = GetFactures();

// Vérifier si des données ont été récupérées
if (factures.Rows.Count == 0)
{
MessageBox.Show("Aucune facture trouvée.");
return;
}

// Créer le document PDF
using (PdfWriter writer = new PdfWriter(saveFileDialog.FileName))
using (PdfDocument pdf = new PdfDocument(writer))
{
Document document = new Document(pdf);

// Titre du document
document.Add(new Paragraph("Rapport des Factures")
.SetTextAlignment(TextAlignment.CENTER)
.SetFontSize(20));

// Créer une table pour les données
Table table = new Table(7); // Ajustez le nombre de colonnes selon vos données
table.AddHeaderCell("Code Facture");
table.AddHeaderCell("Date de l'Opération");
table.AddHeaderCell("Montant Total");
table.AddHeaderCell("Montant Payé");
table.AddHeaderCell("Reste");
table.AddHeaderCell("Mode de Paiement");
table.AddHeaderCell("Vendeur");

// Ajouter les lignes de données
foreach (DataRow row in factures.Rows)
{
table.AddCell(row["FactCode"].ToString());
table.AddCell(Convert.ToDateTime(row["FactDate"]).ToString("dd/MM/yyyy"));
table.AddCell(row["FactMontantTotal"].ToString());
table.AddCell(row["FactMontantPaye"].ToString());
table.AddCell(row["FactReste"].ToString());
table.AddCell(row["FactModePaiement"].ToString());
table.AddCell(row["FactVendeur"].ToString());
}

document.Add(table);
document.Close();
}

MessageBox.Show("PDF généré avec succès !");
}
catch (Exception ex)
{
MessageBox.Show("Erreur lors de la génération du PDF : " + ex.Message + "\n" + ex.StackTrace);
}
}
}
}

private DataTable GetFactures()
{
DataTable dataTable = new DataTable();
string connectionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename="C:\\Users\\USER\\source\\repos\\SP MARKET\\SP MARKET\\SuperMarcheBD.mdf";Integrated Security=True;Connect Timeout=30";

using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
string query = "SELECT FactCode, FactDate, FactMontantTotal, FactMontantPaye, FactReste, FactModePaiement, FactVendeur FROM FactureTbl";
using (SqlCommand command = new SqlCommand(query, connection))
{
using (SqlDataAdapter adapter = new SqlDataAdapter(command))
{
adapter.Fill(dataTable);
}
}
}

return dataTable;
}

private void ExportPdfButton_Click(object sender, EventArgs e)
{
ExportToPDF();
}
}
}