Report generator success story: C# call FastReport control example

FastReport .Net is a full-featured report solution for Windows Forms, ASP.NET, MVC and .NET Core. It can be used in Microsoft Visual Studio 2005-2019. Support .Net Framework 2.0-4.x, .NET Core 3.0 and above.

In the new version of FastReport .NET 2021.1, we have implemented support for .NET 5. Added a new barcode-Deutsce Post Leitcode. The algorithm for converting RTF into report objects has been significantly improved. And also added new functions for converting numbers. Welcome to download and experience.

[Huidu.com] Download the latest version of FastReport.NET v2021.1

Fastreport.NET online purchase price is lower, exclusive 15% off! Hurry up and add to the shopping list!

Download the necessary dll file of FastReport component, as shown below:
Report generator success story: C# call FastReport control example

Create a WinForm project
Report generator success story: C# call FastReport control example

Reference dll file

Report generator success story: C# call FastReport control example

Create FastReport control tool by referencing dll file
Report generator success story: C# call FastReport control example

Create print settings From

Report generator success story: C# call FastReport control example
C# code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FastReport;
using System.Data.SqlClient;

namespace PrintTest001
{
public partial class FrmPrintDesigner : Form
{
public FrmPrintDesigner()
{
InitializeComponent();
}

    private void FrmPrintDesigner_Load(object sender, EventArgs e)
    {
        Report dReport = new Report();   //实例化一个Report报表
        String reportFile = "Report/Report01.frx";
        dReport.Load(reportFile);  //载入报表文件
        this.designerControl1.Report = dReport; //这里不一样的是把Report赋给控件的属性            
        DataSet ds1 = new DataSet();
        ds1 = getDataHz();
        dReport.RegisterData(ds1, "单据汇总");

        DataSet ds2 = new DataSet();
        ds2 = getDataMx();
        dReport.RegisterData(ds2, "单据明细");

        dReport.Prepare();   //准备
        dReport.Design();  //显示
    } 

    private DataSet getDataHz()
    {
        String connStr = ReturnDataSet.connectionString;
        SqlConnection conn = new SqlConnection(connStr);
        conn.Open();
        String sqlStr = ReturnDataSet.HzSql;
        SqlCommand comm = new SqlCommand();
        comm.CommandText = sqlStr;
        comm.CommandType = CommandType.Text;
        comm.Connection = conn;
        DataSet ds = new DataSet();
        SqlDataAdapter adapter = new SqlDataAdapter(comm);
        adapter.Fill(ds, "单据汇总");
        conn.Close();
        return ds;
    }
    private DataSet getDataMx()
    {
        String connStr = ReturnDataSet.connectionString;
        SqlConnection conn = new SqlConnection(connStr);
        conn.Open();
        String sqlStr = ReturnDataSet.MxSql;
        SqlCommand comm = new SqlCommand();
        comm.CommandText = sqlStr;
        comm.CommandType = CommandType.Text;
        comm.Connection = conn;
        DataSet ds = new DataSet();
        SqlDataAdapter adapter = new SqlDataAdapter(comm);
        adapter.Fill(ds, "单据明细");
        conn.Close();
        return ds;
    }
}

}
Create print preview From
Report generator success story: C# call FastReport control example

C# code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FastReport;
using System.Data.SqlClient;

namespace PrintTest001
{
public partial class FrmPrintPreview : Form
{
public FrmPrintPreview()
{
InitializeComponent();
}

    private void FrmPrintPreview_Load(object sender, EventArgs e)
    {
        Report dReport = new Report();   //实例化一个Report报表
        String reportFile = "Report/Report01.frx";
        dReport.Load(reportFile);  //载入报表文件
        dReport.Preview = previewControl1; //设置报表的Preview控件(这里的previewControl1就是我们之前拖进去的那个)    
        DataSet ds1 = new DataSet();
        ds1 = getDataHz();
        dReport.RegisterData(ds1, "单据汇总");

        DataSet ds2 = new DataSet();
        ds2 = getDataMx();
        dReport.RegisterData(ds2, "单据明细");

        dReport.Prepare();   //准备
        dReport.ShowPrepared();  //显示

    }

    private DataSet getDataHz()
    {
        String connStr = ReturnDataSet.connectionString;
        SqlConnection conn = new SqlConnection(connStr);
        conn.Open();
        String sqlStr = ReturnDataSet.HzSql;
        SqlCommand comm = new SqlCommand();
        comm.CommandText = sqlStr;
        comm.CommandType = CommandType.Text;
        comm.Connection = conn;
        DataSet ds = new DataSet();
        SqlDataAdapter adapter = new SqlDataAdapter(comm);
        adapter.Fill(ds, "单据汇总");
        conn.Close();
        return ds;
    }
    private DataSet getDataMx()
    {
        String connStr = ReturnDataSet.connectionString;
        SqlConnection conn = new SqlConnection(connStr);
        conn.Open();
        String sqlStr = ReturnDataSet.MxSql;
        SqlCommand comm = new SqlCommand();
        comm.CommandText = sqlStr;
        comm.CommandType = CommandType.Text;
        comm.Connection = conn;
        DataSet ds = new DataSet();
        SqlDataAdapter adapter = new SqlDataAdapter(comm);
        adapter.Fill(ds, "单据明细");
        conn.Close();
        return ds;
    }
}

}
Example:

Report generator success story: C# call FastReport control example
Print setting effect:

Report generator success story: C# call FastReport control example

Print preview effect:

Report generator success story: C# call FastReport control example
Want more? You can click to read [FastReport 2020 latest resource inventory] to find the tutorial resources you need. What is exciting is that FastReport .NET is now on sale on Huidu.com! Huidu’s 17th Anniversary Celebrates an ultra-low discount, starting from 3701 yuan!

Guess you like

Origin blog.51cto.com/14874181/2576963