轉帖|實施案例|編輯:楊鵬連|2020-12-28 09:38:09.160|閱讀 1754 次
概述:本文介紹了報表生成器C#調用FastReport控件成功示例研究。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
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文件,如下圖:
引用dll文件
引用dll文件創建FastReport控件工具
創建打印設置From
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
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;
}
}
}
示例:
打印設置效果:
還想要更多嗎?您可以點擊閱讀【FastReport 報表2020最新資源盤點】,查找需要的教程資源。讓人興奮的是FastReport .NET正在慧都網火熱銷售中!慧都17周年慶惠享超低折扣,低至3701元起!>>查看價格詳情
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自: