bird

 

ActiveReport3.0报表浏览器汉化完整完整代码(C#版) (转)

很久没有来看看了,也有半年多没有写东西了,最近组织上要求用一个新的报表工具看看,以满足现有的报表需求,我就开始研究ActiveReport 报表工具。和以往一样,我仔细研究了一下ActiveReport3.0中的自带的例子,做了几个报表,发现还不错,我就尝试着做了几个曾经觉的很复杂的 报表--课程表,效果还不错。于是就做了一通用的报表浏览器,就是在报表浏览器窗体中提供几个方法,用来加载数据和调用报表浏览器显示报表。如:

  public static void PreviewReport(DataDynamics.ActiveReports.ActiveReport3 report)
  {
   report.Run();
   FrmActiveReportViewer form = new FrmActiveReportViewer();
   form.reportDocument = report.Document;
   form.Show();
  }

还有

  public static void PreviewReport(DataDynamics.ActiveReports.ActiveReport3 report, DataSet dataSet, string tableName)
  {
   report.DataSource = dataSet;
   report.DataMember = tableName;
   report.Run();
   FrmActiveReportViewer form = new FrmActiveReportViewer();
   form.reportDocument = report.Document;
   form.Show();
  }

浏览窗体完成之后才发现,浏览窗口都是英文的,到客户面前一定不过关,如何汉化呢,在网上找到了几行代码, 

Public Sub Creport(AReport As ActiveReport)
'
汉化ActiveReport
'
以下适用2.0
With AReport
  .ToolBar.Tools.Item(0).Tooltip = "
各页目录"
  .ToolBar.Tools.Item(2).Caption = "
打印..."
  .ToolBar.Tools.Item(2).Tooltip = "
打印报表"
  .ToolBar.Tools.Item(4).Tooltip = "
拷贝"
  .ToolBar.Tools.Item(6).Tooltip = "
查找"
  .ToolBar.Tools.Item(8).Tooltip = "
单页显示"
  .ToolBar.Tools.Item(9).Tooltip = "
多页显示"
  .ToolBar.Tools.Item(11).Tooltip = "
缩小"
  .ToolBar.Tools.Item(12).Tooltip = "
放大"
  .ToolBar.Tools.Item(15).Tooltip = "
上一页"
  .ToolBar.Tools.Item(16).Tooltip = "
下一页"
  .ToolBar.Tools.Item(19).Tooltip = "
后退"
  .ToolBar.Tools.Item(19).Caption = "
后退"
  .ToolBar.Tools.Item(20).Tooltip = "
前进"
  .ToolBar.Tools.Item(20).Caption = "
前进"
 End With
End Sub
在报表流览器中toolbar对象中,有tools对象的集合,他们的Caption和ToolTip属性都是可写的,用下面的代码就可以解决了。
   this.reportViewer.Toolbar.Tools[0].ToolTip = "各页目录";
   this.reportViewer.Toolbar.Tools[2].Caption = "打印...";
   this.reportViewer.Toolbar.Tools[2].ToolTip = "打印报表";
   this.reportViewer.Toolbar.Tools[4].ToolTip = "拷贝";
   this.reportViewer.Toolbar.Tools[6].ToolTip = "查找";
   this.reportViewer.Toolbar.Tools[8].ToolTip = "单页显示";
   this.reportViewer.Toolbar.Tools[9].ToolTip = "多页显示";
   this.reportViewer.Toolbar.Tools[10].ToolTip = "连续滚动显示";
   this.reportViewer.Toolbar.Tools[11].ToolTip = "缩放";
   this.reportViewer.Toolbar.Tools[12].ToolTip = "缩小";
   this.reportViewer.Toolbar.Tools[13].ToolTip = "放大";
   this.reportViewer.Toolbar.Tools[14].ToolTip = "缩放";
   this.reportViewer.Toolbar.Tools[16].ToolTip = "上一页";
   this.reportViewer.Toolbar.Tools[17].ToolTip = "下一页";
   this.reportViewer.Toolbar.Tools[18].ToolTip = "当前页码";
   this.reportViewer.Toolbar.Tools[20].ToolTip = "后退";
   this.reportViewer.Toolbar.Tools[20].Caption = "后退";
   this.reportViewer.Toolbar.Tools[21].ToolTip = "前进";
   this.reportViewer.Toolbar.Tools[21].Caption = "前进";
   this.reportViewer.Toolbar.Tools[23].Caption = "注释";
还有一个问题报表有一个导出的功能,
查看一下DataDynamics.ActiveReports.Toolbar命名空间,其中有AccessibleToolbarButton、Button、CheckButton等类,他们都是控件类,既然提供了这些控件,就一定可以使用,再用对象浏览器查看一下
public class ToolsCollection : System.Collections.CollectionBase
    DataDynamics.ActiveReports.Toolbar 的成员
public System.Int32 Add ( DataDynamics.ActiveReports.Toolbar.Tool value )
    DataDynamics.ActiveReports.Toolbar.ToolsCollection 的成员
报表浏览器中提供了添加控件的方法,如:this.reportViewer.Toolbar.Tools.Add(toolButton);
这样添加一个工具栏按钮就没有问题了。
DataDynamics.ActiveReports.Toolbar.Button toolButton = new DataDynamics.ActiveReports.Toolbar.Button();
   toolButton.Caption = "报表导出";
   toolButton.ToolTip = "报表导出";
   toolButton.Tag = "Export";
   toolButton.Id = 30;
   toolButton.ImageIndex = 11;
   this.reportViewer.Toolbar.Tools.Add(toolButton);
   this.reportViewer.ToolClick+=new DataDynamics.ActiveReports.Toolbar.ToolClickEventHandler(reportViewer_ToolClick);
这样主要的代码就完成了。下面是完整的代码:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Lingzhan.HSM.LaunchCourse.Report
{
 /// <summary>
 /// FrmActiveReportViewer 的摘要说明。
 /// </summary>
 public class FrmActiveReportViewer : System.Windows.Forms.Form
 {
  private DataDynamics.ActiveReports.Viewer.Viewer reportViewer;
  public DataDynamics.ActiveReports.Document.Document reportDocument;
  private System.Windows.Forms.ImageList imageList1;
  private System.ComponentModel.IContainer components;

  public FrmActiveReportViewer()
  {
   //
   // Windows 窗体设计器支持所必需的
   //
   InitializeComponent();

   //
   // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
   //
  }

  /// <summary>
  /// 清理所有正在使用的资源。
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if(components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows 窗体设计器生成的代码
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {
   this.components = new System.ComponentModel.Container();
   System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FrmActiveReportViewer));
   this.reportViewer = new DataDynamics.ActiveReports.Viewer.Viewer();
   this.imageList1 = new System.Windows.Forms.ImageList(this.components);
   this.SuspendLayout();
   //
   // reportViewer
   //
   this.reportViewer.BackColor = System.Drawing.SystemColors.Control;
   this.reportViewer.Dock = System.Windows.Forms.DockStyle.Fill;
   this.reportViewer.Document = new DataDynamics.ActiveReports.Document.Document("ARNet Document");
   this.reportViewer.Location = new System.Drawing.Point(0, 0);
   this.reportViewer.Name = "reportViewer";
   this.reportViewer.ReportViewer.BackColor = System.Drawing.SystemColors.Control;
   this.reportViewer.ReportViewer.CurrentPage = 0;
   this.reportViewer.ReportViewer.MultiplePageCols = 2;
   this.reportViewer.ReportViewer.MultiplePageRows = 3;
   this.reportViewer.ReportViewer.ViewType = DataDynamics.ActiveReports.Viewer.ViewType.Normal;
   this.reportViewer.Size = new System.Drawing.Size(792, 573);
   this.reportViewer.TabIndex = 0;
   this.reportViewer.TableOfContents.Text = "Table Of Contents";
   this.reportViewer.TableOfContents.Width = 200;
   this.reportViewer.TabTitleLength = 35;
   this.reportViewer.Toolbar.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
   //
   // imageList1
   //
   this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
   this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
   this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
   //
   // FrmActiveReportViewer
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
   this.ClientSize = new System.Drawing.Size(792, 573);
   this.Controls.Add(this.reportViewer);
   this.Name = "FrmActiveReportViewer";
   this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
   this.Text = "报表浏览";
   this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
   this.Load += new System.EventHandler(this.FrmActiveReportViewer_Load);
   this.ResumeLayout(false);

  }
  #endregion 
  
  private void FrmActiveReportViewer_Load(object sender, System.EventArgs e)
  {
   this.reportViewer.Toolbar.Tools[0].ToolTip = "各页目录";
   this.reportViewer.Toolbar.Tools[2].Caption = "打印...";
   this.reportViewer.Toolbar.Tools[2].ToolTip = "打印报表";
   this.reportViewer.Toolbar.Tools[4].ToolTip = "拷贝";
   this.reportViewer.Toolbar.Tools[6].ToolTip = "查找";
   this.reportViewer.Toolbar.Tools[8].ToolTip = "单页显示";
   this.reportViewer.Toolbar.Tools[9].ToolTip = "多页显示";
   this.reportViewer.Toolbar.Tools[10].ToolTip = "连续滚动显示";
   this.reportViewer.Toolbar.Tools[11].ToolTip = "缩放";
   this.reportViewer.Toolbar.Tools[12].ToolTip = "缩小";
   this.reportViewer.Toolbar.Tools[13].ToolTip = "放大";
   this.reportViewer.Toolbar.Tools[14].ToolTip = "缩放";
   this.reportViewer.Toolbar.Tools[16].ToolTip = "上一页";
   this.reportViewer.Toolbar.Tools[17].ToolTip = "下一页";
   this.reportViewer.Toolbar.Tools[18].ToolTip = "当前页码";
   this.reportViewer.Toolbar.Tools[20].ToolTip = "后退";
   this.reportViewer.Toolbar.Tools[20].Caption = "后退";
   this.reportViewer.Toolbar.Tools[21].ToolTip = "前进";
   this.reportViewer.Toolbar.Tools[21].Caption = "前进";
   this.reportViewer.Toolbar.Tools[23].Caption = "注释";
   DataDynamics.ActiveReports.Toolbar.Button toolButton = new DataDynamics.ActiveReports.Toolbar.Button();
   toolButton.Caption = "报表导出";
   toolButton.ToolTip = "报表导出";
   toolButton.Tag = "Export";
   toolButton.Id = 30;
   toolButton.ImageIndex = 11;

   this.reportViewer.Toolbar.Tools.Add(toolButton);
   this.reportViewer.ToolClick+=new DataDynamics.ActiveReports.Toolbar.ToolClickEventHandler(reportViewer_ToolClick);
   reportViewer.Document = reportDocument;
  }

  public static void PreviewReport(DataDynamics.ActiveReports.ActiveReport3 report)
  {
   report.Run();
   FrmActiveReportViewer form = new FrmActiveReportViewer();
   form.reportDocument = report.Document;
   form.Show();
  }

  public static void PreviewReport(DataDynamics.ActiveReports.ActiveReport3 report, DataSet dataSet, string tableName)
  {
   report.DataSource = dataSet;
   report.DataMember = tableName;
   report.Run();
   FrmActiveReportViewer form = new FrmActiveReportViewer();
   form.reportDocument = report.Document;
   form.Show();
  }

  private void ExportDocument()
  {
   FrmExportReport form = new FrmExportReport(reportDocument);
   form.ShowDialog(this);
  }

  private void reportViewer_ToolClick(object sender, DataDynamics.ActiveReports.Toolbar.ToolClickEventArgs e)
  {
   DataDynamics.ActiveReports.Toolbar.Button button = (DataDynamics.ActiveReports.Toolbar.Button)e.Tool;
   if(button.Id == 30)
   {
    this.ExportDocument();
   }
  }
 }
}
 效果如图:

导出对话框我用的是ActiveReport3.0中自带的没有修改,汉化过程请自己完成。

这样报表浏览器的主要功能就完成了,但是导出功能并不完善,请各位网友一起完善。以达最佳效果。

posted on 2008-02-23 09:55  鸟人  阅读(2311)  评论(2编辑  收藏  举报

导航