- using System;
- using System.Data;
- using FastReport;
- using Szcx.GeneralDB;
- using System.Collections.Generic;
- namespace CxFastReport
- {
- //基类
- public abstract class BasePlugin :IfrxUserDataSet, IfrxUserDataSetEvents, IfrxDataSet, IfrxPlugin
- {
- private int itemIndex;
- /// <summary>
- /// 报表行索引,包括报表头,尾和数据行
- /// </summary>
- public int ItemIndex
- {
- get { return itemIndex; }
- set { itemIndex = value; }
- }
- private int columnCount;
- /// <summary>
- /// 列数
- /// </summary>
- public int ColumnCount
- {
- get { return columnCount; }
- set { columnCount = value; }
- }
- int rowCount = 0;
- /// <summary>
- /// 数据项总行数
- /// </summary>
- public int RowCount
- {
- get { return rowCount; }
- set { rowCount = value; }
- }
- #region IfrxUserDataSet 成员
- string fields;
- /// <summary>
- /// 报表列集合,格式:('column1'/n'column1'/n........)
- /// </summary>
- public string Fields
- {
- get { return fields; }
- set { fields = value; }
- }
- string name;
- public string Name
- {
- get { return name; }
- set { name = value; }
- }
- #endregion
- #region IfrxUserDataSetEvents 成员
- public void OnFirst() { ItemIndex = 0; }
- public void OnNext() { ItemIndex++; }
- public void OnPrior() { ItemIndex--; }
- public void OnCheckEOF( out bool IsEOF)
- {
- IsEOF = (ItemIndex >= rowCount);
- }
- /// <summary>
- /// 报表时获取数据
- /// </summary>
- /// <param name="VarName">列名</param>
- /// <param name="Value">值</param>
- public abstract void OnGetValue( object columanName, out object Value);
- #endregion
- #region IfrxDataSet 成员
- public int CurrentRecordNo { get { return ItemIndex; } }
- public void GoFirst() { ItemIndex = 0; }
- public void GoNext() { ItemIndex++; }
- public void GoPrior() { ItemIndex--; }
- public int FieldsCount { get { return ColumnCount; } }
- public int RecordsCount { get { return this .rowCount; } }
- public int RangeEndCount
- {
- get
- {
- // TODO: Add ReportDataTable.RangeEndCount getter implementation
- return 0;
- }
- set
- {
- // TODO: Add ReportDataTable.RangeEndCount setter implementation
- }
- }
- public FastReport.frxRangeBegin RangeBegin
- {
- get
- {
- // TODO: Add ReportDataTable.RangeBegin getter implementation
- return new FastReport.frxRangeBegin();
- }
- set
- {
- // TODO: Add ReportDataTable.RangeBegin setter implementation
- }
- }
- public abstract object ValueOfField( string FieldName);
- string userName = "" ;
- public string UserName
- {
- get { return userName; }
- set { userName = value; }
- }
- public FastReport.frxRangeEnd RangeEnd
- {
- get
- {
- // TODO: Add ReportDataTable.RangeEnd getter implementation
- return new FastReport.frxRangeEnd();
- }
- set
- {
- // TODO: Add ReportDataTable.RangeEnd setter implementation
- }
- }
- #endregion
- #region IfrxPlugin 成员
- public FastReport.frxPluginType PluginType
- {
- get
- {
- return FastReport.frxPluginType.ptDataSet;
- }
- }
- #endregion
- }
- }
- using System;
- using System.Data;
- using FastReport;
- using Szcx.GeneralDB;
- using System.Collections.Generic;
- using Szcx.Misc;
- namespace CxFastReport
- {
- //实现Table数据的转换
- public class ReportDataTable : BasePlugin
- {
- private DataTable dataTable;
- /// <summary>
- /// 构造方法,构建列
- /// </summary>
- /// <param name="table">数据表</param>
- /// <param name="dataSourceName">生成的数据源名称</param>
- public ReportDataTable(DataTable table, string dataSourceName)
- {
- dataTable = table;
- FeildMap.Clear();
- //初始化
- this .Name = dataSourceName;
- this .UserName = dataSourceName;
- this .RowCount = table.Rows.Count;
- this .Fields = null ;
- this .ColumnCount = table.Columns.Count;
- //构建列
- foreach (DataColumn col in dataTable.Columns)
- {
- FeildMap.Add(field.FLD_DESC, field);
- this .Fields += field.FLD_DESC + "/n" ;
- }
- }
- /// <summary>
- /// 实现报表时获取数据
- /// </summary>
- /// <param name="columnName">列名</param>
- /// <param name="Value">获取的值</param>
- public override void OnGetValue( object columnName, out object Value)
- {
- //报表时获取值
- object value = dataTable.Rows[ this .ItemIndex][columnName.ToString()];
- //将Decimal数据类型装换为Int32,FastReport不能识别Decimal数据类型
- if (Value is Decimal)
- {
- Value = Decimal.ToInt32((Decimal)Value);
- }
- }
- public override object ValueOfField( string FieldName)
- {
- throw new Exception( "The method or operation is not implemented." );
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Text;
- using FastReport;
- using System.Data;
- namespace CxFastReport
- {
- //数据绑定类
- public class ReportBinding
- {
- private List<BasePlugin> reportBasePlugins = new List<BasePlugin>();
- public void BindToReport(List<BasePlugin> plugins, TfrxReportClass report)
- {
- reportBasePlugins.Clear();
- foreach (BasePlugin plugin in plugins)
- {
- this .reportBasePlugins.Add(plugin);
- report.BindObject(plugin);
- report.SelectDataset(true , plugin);
- }
- }
- /// <summary>
- /// 卸载数据源
- /// </summary>
- public void UnbindFromReport(TfrxReportClass report)
- {
- foreach (BasePlugin local_table in this .reportBasePlugins)
- {
- report.SelectDataset(false , local_table);
- }
- reportBasePlugins.Clear();
- }
- }
- }
- //继承FastReporet的新类
- using System;
- using System.Collections.Generic;
- using System.Text;
- using FastReport;
- using System.Data;
- using System.Windows.Forms;
- using System.Collections;
- namespace CxFastReport
- {
- public class FrxFastReport : TfrxReportClass
- {
- Form form;
- bool secondLang;
- public bool SecondLang
- {
- get { return secondLang; }
- set { secondLang = value; }
- }
- /// <summary>
- /// 绑定数据源对象的类
- /// </summary>
- private ReportBinding reportBinding = null ;
- /// <summary>
- /// 数据源插件对象:分别是由:ReportDataTable,ReportList实现的
- /// </summary>
- List<BasePlugin> plugins = new List<BasePlugin>();
- private IList list = null ;
- public FrxFastReport(Form form, bool secondLang)
- {
- this .secondLang = secondLang;
- this .reportBinding = new ReportBinding();
- this .form = form;
- }
- Dictionary<string , object > listDataSource = new Dictionary< string , object >();
- /// <summary>
- /// 数据源和名称,键值对,object为数据源,string数据源名称,
- /// 如:ListDataSource.Add(new Dictionary<tableName,dataTable>);
- /// </summary>
- public Dictionary< string , object > ListDataSource
- {
- get { return listDataSource; }
- set { listDataSource = value; }
- }
- /// <summary>
- /// 绑定数据到报表
- /// </summary>
- public void BindToReport()
- {
- IEnumerator ienumeratorKey = ListDataSource.Keys.GetEnumerator();
- while (ienumeratorKey.MoveNext())
- {
- string key = ienumeratorKey.Current.ToString();
- object reportDataSource = this .ListDataSource[key];
- if (reportDataSource is DataTable)
- {
- this .plugins.Add( new ReportDataTable((DataTable)reportDataSource, key));
- continue ;
- }
- if (reportDataSource is DataView)
- {
- DataTable tempTable = ((DataView)reportDataSource).Table;
- this .plugins.Add( new ReportDataTable(tempTable, key));
- continue ;
- }
- if (reportDataSource is IList)
- {
- this .list = (IList)reportDataSource;
- this .plugins.Add( new ReportList( this .list, key));
- continue ;
- }
- }
- this .reportBinding.BindToReport( this .plugins, this );
- }
- /// <summary>
- /// 卸载数据源
- /// </summary>
- public void UnbindFromReport()
- {
- this .reportBinding.UnbindFromReport( this );
- }
- }
- }
- //掉用方法
- //设置FastReport数据源
- Dictionary<string , DataTable> listDataSource = new Dictionary< string , DataTable>();
- /// <summary>
- /// 数据源和名称,键值对,object为数据源,string数据源名称,
- /// 如:ListDataSource.Add(new Dictionary<tableName,dataTable>);
- /// </summary>
- public Dictionary< string , DataTable> ListDataSource
- {
- get { return listDataSource; }
- set { listDataSource = value; }
- }
- /// <summary>
- /// 绑定数据到报表
- /// </summary>
- public void BindToReport()
- {
- IEnumerator ienumeratorKey = ListDataSource.Keys.GetEnumerator();
- while (ienumeratorKey.MoveNext())
- {
- string key = ienumeratorKey.Current.ToString(); DataTable reportDataSource = this .ListDataSource[key];
- this .plugins.Add( new ReportDataTable((DataTable)reportDataSource, key));
- this .reportBinding.BindToReport( this .plugins, this );
- }
关于C# WinForm FastReport Studio的使用方法
最新推荐文章于 2024-03-20 16:02:29 发布