Home > .Net Framework > Kelas untuk mengisikan data ke Microsoft Report Viewer

Kelas untuk mengisikan data ke Microsoft Report Viewer


Microsoft Report Viewer adalah sebuah solusi reporting yang tersedia di lingkungan .Net Framework yang disediakan secara cuma – cuma oleh microsoft, berikut ini sebuah kelas sederhana untuk mengisi report tersebut dengan data

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Reporting.WinForms;
using System.Data;
using System.Windows.Forms;
namespace Smart_Academic.lib
{
    public class ReportingEngine
    {

        public static ReportViewer Create(string tableName,DataSet ds, ReportViewer viewer, IDataReader drd)
        {
            
            ds.Tables[tableName].Clear();
            ds.Tables[tableName].Load(drd);
            
            drd.Close();
            //viewer.RefreshReport();
            viewer.SetDisplayMode(DisplayMode.PrintLayout);
            //viewer.RefreshReport();
            //viewer.RefreshReport();
            //Me.ReportViewer1.ZoomMode = ZoomMode.PageWidth
            viewer.ZoomMode = ZoomMode.PageWidth;
            viewer.RefreshReport();

            return viewer;
        }

        public static ReportViewer Create(string[] tableNames, DataSet ds, ReportViewer viewer, IDataReader[] drds)
        {
            int i = 0;
            foreach (string tableName in tableNames)
            {
                ds.Tables[tableName].Clear();
                ds.Tables[tableName].Load(drds[i]);
                //Console.WriteLine(tableName);
                drds[i].Close();            
                
                i++;
            }
            //viewer.RefreshReport();
            viewer.SetDisplayMode(DisplayMode.PrintLayout);
            //viewer.RefreshReport();
            //viewer.RefreshReport();
            viewer.ZoomMode = ZoomMode.PageWidth;
            viewer.RefreshReport();
            return viewer;
        }


        public static ReportViewer Create(string[] tableNames, DataSet ds, ReportViewer viewer, DataTable[] tables)
        {
            int i = 0;
            for(i=0;i<tableNames.Length;i++)
            {
                //ds.Tables[tableName].Clear();
                //ds.Tables[tableName].Load(drds[i]);
                //ds.Tables[i] = tables[i];
                DataTable tb = ds.Tables[tableNames[i]];
                //Console.WriteLine(tableNames[i]);
                //Console.WriteLine("Datasource begin " + tb.Rows.Count);
                //Console.WriteLine("Target Column : " +tb.Columns.Count);
                DataTable source = tables[i];
                DataRow[] rows = source.Select();
                tb.Rows.Clear();
                foreach (DataRow row in rows)
                {
                    //Console.WriteLine("Item Column : " + row.ItemArray.Length);
                    tb.Rows.Add(row.ItemArray);
                }
                //Console.WriteLine("Datasource end " + tb.Rows.Count);
            }
            viewer.SetDisplayMode(DisplayMode.PrintLayout);
            //viewer.RefreshReport();
            //viewer.RefreshReport();
            viewer.ZoomMode = ZoomMode.PageWidth;
            viewer.RefreshReport();
            return viewer;
            
        }
    }
}

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: