ActiveReport3.0通用報表瀏覽器

來源:互聯網
上載者:User

通用的報表瀏覽器,就是在報表瀏覽器表單中提供幾個方法,用來載入資料和調用報表瀏覽器顯示報表。如:

  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中內建的沒有修改,漢化過程請自己完成。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.