java使用fast报表控件_报表生成器成功案例:C#调用FastReport控件示例

FastReport .Net是适用于Windows Forms,ASP.NET,MVC和.NET Core的全功能报表解决方案。它可以在Microsoft Visual Studio 2005-2019中使用。支持.Net Framework 2.0-4.x,.NET Core 3.0及以上版本。

在FastReport .NET 2021.1的新版本中,我们实现了对.NET 5的支持。添加了新条形码-Deutsce Post Leitcode。将RTF转换为报告对象的算法已得到显着改进。并且还添加了用于转换数字的新功能。欢迎下载体验。(点击下方按钮下载)

立即点击下载FastReport.NET v2021.1最新版

Fastreport.NET在线购买价更低,专享85折起!赶紧加入购物清单吧!

下载FastReport组件必须的dll文件,如下图:

d0a6bd8038bb55383b9590b9f696e4f1.png

创建个WinForm项目

dbbd4ab6677b736376f3e0eeae7295a8.png

引用dll文件

32232fc945872bcac93a563a3a8f6585.png

引用dll文件创建FastReport控件工具

6b84769cd015b41ca934b78ebd49b65f.png

创建打印设置From

464692ec8f862d866a578b6a51467e10.png

C#代码:

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;

}

}

}

创建打印预览From

2899ad98a6492ff35bffc40c25ebba51.png

C#代码:

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;

}

}

}

示例:

f7bb3e3e0c8770270bea8063df6f0e7c.png

打印设置效果:

462e7edce8bd2f8538e314f3ef93970f.png

打印预览效果:

6cb98f4d841866bcc00759f27401709e.png

还想要更多吗?您可以点击阅读【FastReport 报表2020最新资源盘点】,查找需要的教程资源。让人兴奋的是FastReport .NET正在慧都网火热销售中!慧都17周年庆惠享超低折扣,低至3701元起!>>查看价格详

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值