关于C# WinForm FastReport Studio的使用方法

  1. using  System;  
  2. using  System.Data;  
  3. using  FastReport;  
  4. using  Szcx.GeneralDB;  
  5. using  System.Collections.Generic;  
  6.   
  7. namespace  CxFastReport  
  8. {  
  9.     //基类   
  10.     public   abstract   class  BasePlugin :IfrxUserDataSet, IfrxUserDataSetEvents, IfrxDataSet, IfrxPlugin  
  11.     {  
  12.         private   int  itemIndex;  
  13.         /// <summary>   
  14.         /// 报表行索引,包括报表头,尾和数据行   
  15.         /// </summary>   
  16.         public   int  ItemIndex  
  17.         {  
  18.             get  {  return  itemIndex; }  
  19.             set  { itemIndex = value; }  
  20.         }  
  21.   
  22.         private   int  columnCount;  
  23.         /// <summary>   
  24.         /// 列数   
  25.         /// </summary>   
  26.         public   int  ColumnCount  
  27.         {  
  28.             get  {  return  columnCount; }  
  29.             set  { columnCount = value; }  
  30.         }  
  31.   
  32.         int  rowCount = 0;  
  33.         /// <summary>   
  34.         /// 数据项总行数   
  35.         /// </summary>   
  36.         public   int  RowCount  
  37.         {  
  38.             get  {  return  rowCount; }  
  39.             set  { rowCount = value; }  
  40.         }  
  41.           
  42.         #region IfrxUserDataSet 成员   
  43.   
  44.         string  fields;  
  45.         /// <summary>   
  46.         /// 报表列集合,格式:('column1'/n'column1'/n........)   
  47.         /// </summary>   
  48.         public   string  Fields  
  49.         {  
  50.             get  {  return  fields; }  
  51.             set  { fields = value; }  
  52.         }  
  53.   
  54.         string  name;  
  55.         public   string  Name  
  56.         {  
  57.             get  {  return  name; }  
  58.             set  { name = value; }  
  59.         }  
  60.    
  61.         #endregion   
  62.   
  63.         #region IfrxUserDataSetEvents 成员  
  64.   
  65.         public   void  OnFirst() { ItemIndex = 0; }  
  66.         public   void  OnNext() { ItemIndex++; }  
  67.         public   void  OnPrior() { ItemIndex--; }  
  68.   
  69.         public   void  OnCheckEOF( out   bool  IsEOF)  
  70.         {  
  71.             IsEOF = (ItemIndex >= rowCount);  
  72.         }  
  73.   
  74.         /// <summary>   
  75.         /// 报表时获取数据   
  76.         /// </summary>   
  77.         /// <param name="VarName">列名</param>   
  78.         /// <param name="Value">值</param>   
  79.         public   abstract   void  OnGetValue( object  columanName,  out   object  Value);  
  80.  
  81.        #endregion   
  82.   
  83.         #region IfrxDataSet 成员  
  84.   
  85.         public   int  CurrentRecordNo {  get  {  return  ItemIndex; } }  
  86.         public   void  GoFirst() { ItemIndex = 0; }  
  87.         public   void  GoNext() { ItemIndex++; }  
  88.         public   void  GoPrior() { ItemIndex--; }  
  89.   
  90.         public   int  FieldsCount {  get  {  return  ColumnCount; } }  
  91.         public   int  RecordsCount {  get  {  return   this .rowCount; } }  
  92.   
  93.   
  94.         public   int  RangeEndCount  
  95.         {  
  96.             get   
  97.             {  
  98.                 // TODO:  Add ReportDataTable.RangeEndCount getter implementation   
  99.                 return  0;  
  100.             }  
  101.             set   
  102.             {  
  103.                 // TODO:  Add ReportDataTable.RangeEndCount setter implementation   
  104.             }  
  105.         }  
  106.   
  107.         public  FastReport.frxRangeBegin RangeBegin  
  108.         {  
  109.             get   
  110.             {  
  111.                 // TODO:  Add ReportDataTable.RangeBegin getter implementation   
  112.                 return   new  FastReport.frxRangeBegin();  
  113.             }  
  114.             set   
  115.             {  
  116.                 // TODO:  Add ReportDataTable.RangeBegin setter implementation   
  117.             }  
  118.         }   
  119.   
  120.         public   abstract   object  ValueOfField( string  FieldName);  
  121.   
  122.         string  userName =  "" ;  
  123.   
  124.         public   string  UserName  
  125.         {  
  126.             get  {  return  userName; }  
  127.             set  { userName = value; }  
  128.         }  
  129.   
  130.         public  FastReport.frxRangeEnd RangeEnd  
  131.         {  
  132.             get   
  133.             {  
  134.                 // TODO:  Add ReportDataTable.RangeEnd getter implementation   
  135.                 return   new  FastReport.frxRangeEnd();  
  136.             }  
  137.             set   
  138.             {  
  139.                 // TODO:  Add ReportDataTable.RangeEnd setter implementation   
  140.             }  
  141.         }  
  142.  
  143.         #endregion   
  144.   
  145.         #region IfrxPlugin 成员  
  146.   
  147.         public  FastReport.frxPluginType PluginType  
  148.         {  
  149.             get   
  150.             {  
  151.                 return  FastReport.frxPluginType.ptDataSet;  
  152.             }  
  153.         }  
  154.  
  155.         #endregion   
  156.     }  
  157. }  
  158.   
  159.   
  160.   
  161.   
  162.   
  163.   
  164. using  System;  
  165. using  System.Data;  
  166. using  FastReport;  
  167. using  Szcx.GeneralDB;  
  168. using  System.Collections.Generic;  
  169. using  Szcx.Misc;  
  170.   
  171. namespace  CxFastReport  
  172. {  
  173.     //实现Table数据的转换   
  174.     public   class  ReportDataTable : BasePlugin  
  175.     {  
  176.         private  DataTable dataTable;  
  177.   
  178.         /// <summary>   
  179.         /// 构造方法,构建列   
  180.         /// </summary>   
  181.         /// <param name="table">数据表</param>   
  182.         /// <param name="dataSourceName">生成的数据源名称</param>   
  183.         public  ReportDataTable(DataTable table, string  dataSourceName)  
  184.         {  
  185.             dataTable = table;  
  186.             FeildMap.Clear();  
  187.             //初始化   
  188.             this .Name = dataSourceName;  
  189.             this .UserName = dataSourceName;  
  190.             this .RowCount = table.Rows.Count;  
  191.             this .Fields =  null ;  
  192.             this .ColumnCount = table.Columns.Count;  
  193.             //构建列   
  194.             foreach  (DataColumn col  in  dataTable.Columns)  
  195.             {  
  196.                  FeildMap.Add(field.FLD_DESC, field);  
  197.                  this .Fields += field.FLD_DESC +  "/n" ;  
  198.    
  199.             }  
  200.         }  
  201.   
  202.         /// <summary>   
  203.         /// 实现报表时获取数据   
  204.         /// </summary>   
  205.         /// <param name="columnName">列名</param>   
  206.         /// <param name="Value">获取的值</param>   
  207.         public   override   void  OnGetValue( object  columnName,  out   object  Value)  
  208.         {  
  209.            //报表时获取值   
  210.            object  value = dataTable.Rows[ this .ItemIndex][columnName.ToString()];  
  211.             //将Decimal数据类型装换为Int32,FastReport不能识别Decimal数据类型   
  212.             if  (Value  is  Decimal)  
  213.             {  
  214.                 Value = Decimal.ToInt32((Decimal)Value);  
  215.             }  
  216.         }  
  217.   
  218.         public   override   object  ValueOfField( string  FieldName)  
  219.         {  
  220.             throw   new  Exception( "The method or operation is not implemented." );  
  221.         }  
  222.     }  
  223. }  
  224.   
  225.   
  226.   
  227. using  System;  
  228. using  System.Collections.Generic;  
  229. using  System.Text;  
  230. using  FastReport;  
  231. using  System.Data;  
  232.   
  233. namespace  CxFastReport  
  234. {  
  235.     //数据绑定类   
  236.     public   class  ReportBinding  
  237.     {  
  238.         private  List<BasePlugin> reportBasePlugins =  new  List<BasePlugin>();  
  239.   
  240.         public   void  BindToReport(List<BasePlugin> plugins, TfrxReportClass report)  
  241.         {  
  242.             reportBasePlugins.Clear();  
  243.             foreach  (BasePlugin plugin  in  plugins)  
  244.             {  
  245.                 this .reportBasePlugins.Add(plugin);  
  246.                 report.BindObject(plugin);  
  247.                 report.SelectDataset(true , plugin);  
  248.             }  
  249.         }  
  250.   
  251.         /// <summary>   
  252.         /// 卸载数据源   
  253.         /// </summary>   
  254.         public   void  UnbindFromReport(TfrxReportClass report)  
  255.         {  
  256.             foreach  (BasePlugin local_table  in   this .reportBasePlugins)  
  257.             {  
  258.                 report.SelectDataset(false , local_table);  
  259.             }  
  260.             reportBasePlugins.Clear();  
  261.         }  
  262.     }  
  263. }  
  264.   
  265.   
  266. //继承FastReporet的新类   
  267. using  System;  
  268. using  System.Collections.Generic;  
  269. using  System.Text;  
  270. using  FastReport;  
  271. using  System.Data;  
  272. using  System.Windows.Forms;  
  273. using  System.Collections;  
  274.   
  275. namespace  CxFastReport  
  276. {  
  277.     public   class  FrxFastReport : TfrxReportClass  
  278.     {  
  279.         Form form;  
  280.         bool  secondLang;  
  281.         public   bool  SecondLang  
  282.         {  
  283.             get  {  return  secondLang; }  
  284.             set  { secondLang = value; }  
  285.         }  
  286.   
  287.         /// <summary>   
  288.         /// 绑定数据源对象的类   
  289.         /// </summary>   
  290.         private  ReportBinding reportBinding =  null ;  
  291.   
  292.         /// <summary>   
  293.         /// 数据源插件对象:分别是由:ReportDataTable,ReportList实现的   
  294.         /// </summary>   
  295.         List<BasePlugin> plugins = new  List<BasePlugin>();  
  296.   
  297.         private  IList list =  null ;  
  298.   
  299.         public  FrxFastReport(Form form,  bool  secondLang)  
  300.         {  
  301.             this .secondLang = secondLang;  
  302.             this .reportBinding =  new  ReportBinding();  
  303.             this .form = form;  
  304.         }  
  305.   
  306.         Dictionary<stringobject > listDataSource =  new  Dictionary< stringobject >();  
  307.   
  308.         /// <summary>   
  309.         /// 数据源和名称,键值对,object为数据源,string数据源名称,   
  310.         /// 如:ListDataSource.Add(new Dictionary<tableName,dataTable>);   
  311.         /// </summary>   
  312.         public  Dictionary< stringobject > ListDataSource  
  313.         {  
  314.             get  {  return  listDataSource; }  
  315.             set  { listDataSource = value; }  
  316.         }  
  317.   
  318.         /// <summary>   
  319.         /// 绑定数据到报表   
  320.         /// </summary>   
  321.         public   void  BindToReport()  
  322.         {  
  323.             IEnumerator ienumeratorKey = ListDataSource.Keys.GetEnumerator();  
  324.             while  (ienumeratorKey.MoveNext())  
  325.             {  
  326.                 string  key = ienumeratorKey.Current.ToString();  
  327.                 object  reportDataSource =  this .ListDataSource[key];  
  328.                 if  (reportDataSource  is  DataTable)  
  329.                 {  
  330.                     this .plugins.Add( new  ReportDataTable((DataTable)reportDataSource, key));  
  331.                     continue ;  
  332.                 }  
  333.                 if  (reportDataSource  is  DataView)  
  334.                 {  
  335.                     DataTable tempTable = ((DataView)reportDataSource).Table;  
  336.                     this .plugins.Add( new  ReportDataTable(tempTable, key));  
  337.                     continue ;  
  338.                 }  
  339.                 if  (reportDataSource  is  IList)  
  340.                 {  
  341.                     this .list = (IList)reportDataSource;  
  342.                     this .plugins.Add( new  ReportList( this .list, key));  
  343.                     continue ;  
  344.                 }  
  345.             }  
  346.             this .reportBinding.BindToReport( this .plugins,  this );  
  347.         }  
  348.           
  349.         /// <summary>   
  350.         /// 卸载数据源   
  351.         /// </summary>   
  352.         public   void  UnbindFromReport()  
  353.         {  
  354.             this .reportBinding.UnbindFromReport( this );  
  355.         }  
  356.     }  
  357. }  
  358.   
  359.   
  360. //掉用方法   
  361. //设置FastReport数据源   
  362.  Dictionary<string , DataTable> listDataSource =  new  Dictionary< string , DataTable>();  
  363.    /// <summary>   
  364.         /// 数据源和名称,键值对,object为数据源,string数据源名称,   
  365.         /// 如:ListDataSource.Add(new Dictionary<tableName,dataTable>);   
  366.         /// </summary>   
  367.         public  Dictionary< string , DataTable> ListDataSource  
  368.         {  
  369.             get  {  return  listDataSource; }  
  370.             set  { listDataSource = value; }  
  371.         }  
  372.   
  373.   
  374.   
  375.         /// <summary>   
  376.         /// 绑定数据到报表   
  377.         /// </summary>   
  378.         public   void  BindToReport()  
  379.         {  
  380.             IEnumerator ienumeratorKey = ListDataSource.Keys.GetEnumerator();  
  381.             while  (ienumeratorKey.MoveNext())  
  382.             {  
  383.                 string  key = ienumeratorKey.Current.ToString();                DataTable reportDataSource =  this .ListDataSource[key];  
  384.                  this .plugins.Add( new  ReportDataTable((DataTable)reportDataSource, key));  
  385.                  this .reportBinding.BindToReport( this .plugins,  this );  
  386.         } 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值