忍者ブログ

Lutetiums

無料帳票印刷ライブラリ (C# Windows Form アプリケーション)ーその3-

Windows Form に配置・データソース設定


単純な .Net Form アプリケーションにレポートのプレビュー画面を配置。
プログラム側からデータソースを設定するサンプルです。

 
using System;
using System.Data;
using System.Windows.Forms;

using Npgsql;

namespace RDLReport
{
    public partial class Form1 : Form
    {
        private fyiReporting.RdlViewer.ViewerToolstrip reportToolStrip;
        private fyiReporting.RdlViewer.RdlViewer rdlViewer1;
        public Form1()
        {
            InitializeComponent();
            this.SuspendLayout();
// // rdlViewer(印刷プレビュー) // this.rdlViewer1 = new fyiReporting.RdlViewer.RdlViewer(); this.rdlViewer1.Cursor = System.Windows.Forms.Cursors.Default; this.rdlViewer1.Dock = System.Windows.Forms.DockStyle.Fill; this.rdlViewer1.dSubReportGetContent = null; this.rdlViewer1.Folder = null; this.rdlViewer1.HighlightAll = false; this.rdlViewer1.HighlightAllColor = System.Drawing.Color.Fuchsia; this.rdlViewer1.HighlightCaseSensitive = false; this.rdlViewer1.HighlightItemColor = System.Drawing.Color.Aqua; this.rdlViewer1.HighlightPageItem = null; this.rdlViewer1.HighlightText = null; this.rdlViewer1.Location = new System.Drawing.Point(0, 0); this.rdlViewer1.Name = "rdlViewer1"; this.rdlViewer1.PageCurrent = 1; this.rdlViewer1.Parameters = ""; this.rdlViewer1.ReportName = null; this.rdlViewer1.ScrollMode = fyiReporting.RdlViewer.ScrollModeEnum.Continuous; this.rdlViewer1.SelectTool = false; this.rdlViewer1.ShowFindPanel = false; this.rdlViewer1.ShowParameterPanel = false; this.rdlViewer1.ShowWaitDialog = true; this.rdlViewer1.Size = new System.Drawing.Size(580, 472); this.rdlViewer1.SourceFile = null; this.rdlViewer1.SourceRdl = null; this.rdlViewer1.TabIndex = 0; this.rdlViewer1.UseTrueMargins = true; this.rdlViewer1.Zoom = 0.4202973F; this.rdlViewer1.ZoomMode = fyiReporting.RdlViewer.ZoomEnum.FitPage; this.Controls.Add(this.rdlViewer1);
///
/// 印刷ボタン等
/// reportToolStrip = new fyiReporting.RdlViewer.ViewerToolstrip(rdlViewer1); this.Controls.Add(reportToolStrip);
this.ResumeLayout(false);
///
/// レポートにデータ流し込み
/// LoadData(); } private void LoadData() { // 流し込み用データ取得 (レポート側はDataTable で受け取るのでその準備) string constring = @"Server = 127.0.0.1; Port = 5432; User Id = postgres; Password = *****; Database = dvdrental;"; using (NpgsqlConnection conn = new NpgsqlConnection(constring)) { string sql = "Select * from staff where first_name='Mike';"; NpgsqlDataAdapter dataAdapter = new NpgsqlDataAdapter(sql, conn); DataSet dataSet = new DataSet(); dataAdapter.Fill(dataSet); DataTable dt = dataSet.Tables[0]; try { // RDLファイル読み込み rdlViewer1.SourceFile = new Uri(@"C:\test.rdl"); //データ流し込み rdlViewer1.Report.DataSets["Data"].SetData(dataSet.Tables[0]); // パラメータにデータセット rdlViewer1.Parameters += string.Format("param1={0}", "スタッフ情報"); rdlViewer1.Rebuild(); } catch (Exception ex) { System.Diagnostics.Debug.Print(ex.Message); } } } } }
実行するとツールバー付きの印刷プレビュー画面が表示できる。




その1:概要・参照設定その2:RDLデザイン

拍手[0回]

PR

コメント

P R

カレンダー

11 2018/12 01
S M T W T F S
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