1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| /// <summary>
/// Loads ans shows the CR Viewer. Thread-safe
/// </summary>
/// <param name="crReportType">Type of the Report. Ex : typeof(CR_INVOICE)</param>
/// <param name="dtSource">DataTable that contains the data</param>
public void SetDataSource(Type crReportType, DataTable dtSource)
{
if (this.InvokeRequired)
this.Invoke(new SetDataSourceDelegate(SetDataSource), new object[] { crReportType, dtSource });
else
{
ReportClass crReport = ReloadCrPreview(crReportType);
try
{
crReport.SetDataSource(dtSource);
crPreview.CrViewer.RefreshReport();
crReport.Refresh();
}
catch
{
/* A msgbox "Load Report Failed" id shown */
}
}
}
/// <summary>
/// Recharger le composant CR pour effacer le cache.
/// Sinon les pages visualisées restent dans le cache et ne seront pas mises à jour dans l'aperçu
/// </summary>
private ReportClass ReloadCrPreview(Type crReportType)
{
// Ne pas cacher le panel parent pendant le redessinage -> "Load Report Failed" !
crPreview.CrViewer.ReportSource = null;
crPreview.Dispose();
// Create ReportClass
crReport = (ReportClass)Activator.CreateInstance(crReportType);
crPreview = new CrViewerControl();
crPreview.CrViewer.ReportSource = crReport;
//
// crPreview (from Designer.cs)
//
crPreview.Dock = System.Windows.Forms.DockStyle.Fill;
crPreview.Name = "crPreview";
// Add new control
panelCrViewer.Controls.Add(this.crPreview);
Application.DoEvents(); // NE PAS RETIRER -> "Load Report Failed" !
return crReport;
} |
Partager