找回密码
 立即注册

QQ登录

只需一步,快速开始

ZenosZeng 讲师达人认证 悬赏达人认证
超级版主   /  发表于:2012-9-3 19:25  /   查看:5216  /  回复:0
C1Report提供了非常灵活的方式来创建和保持多个报表到一个报表定义文件(.XML)中。然而,默认情况下每次预览时只能查看一个报表的内容。本文将介绍如果一次预览多个报表的内容。

主要实现方法是同时加载多个报表,进行内容合并,然后,被加载的每一页报表内容保存到一个图片数组中。这些图片最好将作为一个RenderImage对象添加到C1PrintDocument中,一旦这些图片加载完成,C1PrintDocument也就在预览控件中显示完成。

实现代码如下:
  1. private void Form1_Load(object sender, EventArgs e)
  2. {
  3.       // load the reports
  4.       c1Report1.Load("Report1.xml", "ReportName");
  5.       c1Report2.Load("Report2.xml", "ReportName");
  6.       this.c1Report1.Render();
  7.       this.c1Report2.Render();

  8.       // the margins are set to zero to compensate for the margins already present in the reports
  9.       c1PrintDocument1.PageLayout.PageSettings.LeftMargin = "0.0in";
  10.       c1PrintDocument1.PageLayout.PageSettings.TopMargin = "0.0in";
  11.       int i;
  12.       int count=c1Report1.GetPageCount() + c1Report2.GetPageCount();
  13.       Pages = new System.Drawing.Imaging.Metafile[count];

  14.       // get pageimages of report1
  15.       foreach (System.Drawing.Imaging.Metafile Page in this.c1Report1.GetPageImages())
  16.       {
  17.            Pages.SetValue(Page, index);
  18.            index++;
  19.       }

  20.       // get pageimages of report2
  21.       foreach (System.Drawing.Imaging.Metafile Page in this.c1Report2.GetPageImages())
  22.       {
  23.            Pages.SetValue(Page, index);
  24.            index++;
  25.       }

  26.       // add images from array to PrintDocument as RenderImages
  27.       for (i = 0; i <= (Pages.Length - 1); i++)
  28.       {
  29.            RenderImage PageImage = new RenderImage(Pages[ i ]);
  30.            this.c1PrintDocument1.Body.Children.Add(PageImage);
  31.            this.c1PrintDocument1.Reflow();
  32.       }

  33.       // Preview the C1PrintDocument

  34.       // for winform Application
  35.       c1PrintPreviewControl1.Document = c1PrintDocument1;
  36.       // for WPF Application
  37.       c1DocumentViewer1.Document = c1PrintDocument1.FixedDocumentSequence;
  38. }
复制代码


需要注意的是,如果报表数据量较大时,这种方法可能会因为存在显示延时。

源码下载:VS2010 + C1 2012V2

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

0 个回复

您需要登录后才可以回帖 登录 | 立即注册
返回顶部