国家  china

FlexReport的链接到外部程序集的对象

概述

本文给大家讲解一个不常用到的知识点,但是又不容忽略的点,相信大家在使用的FlexReport.Designer的时候选择数据源的时候都会发现链接到外部程序集中的对象,这是一种什么数据源呢,想必大家都翘首以盼了,那我们就开始揭秘吧。

image

外部程序集简单的说就是dll文件,再简单的说就是外部对象就是我们常说的Entity的对象,但是又有点不同它有自己实现的API,实现接口有两个IC1FlexReportRecordset、IC1FlexReportExternalRecordset,这样实现后,FlexReport.Designer就可以读到这个外部程序集的对象。

现在我们主要教大家实现这两个接口

IC1FlexReportRecordset:

   1:    public class MyRecordset : IC1FlexReportRecordset
   2:      {
   3:          private int _recNo;
   4:          private int _recCount;
   6:          public MyRecordset()
   7:          {
   8:              _recCount = 60;
   9:          }
  11:          public int RecCount
  12:          {
  13:              get { return _recCount; }
  14:              set { _recCount = value; }
  15:          }
  17:          #region IC1FlexReportRecordset implementation
  18:          public string[] GetFieldNames()
  19:          {
  20:              return new string[] { "ID", "Caption" };
  21:          }
  22:   
  23:          public Type[] GetFieldTypes()
  24:          {
  25:              return new Type[] { typeof(int), typeof(string) };
  26:          }
  28:          public object GetFieldValue(int fieldIndex)
  29:          {
  30:              switch (fieldIndex)
  31:              {
  32:                  case 0:
  33:                      return _recNo + 1;
  34:                  case 1:
  35:                      return string.Format("Caption {0}", _recNo + 1);
  36:                  default:
  37:                      return null;
  38:              }
  39:          }
  41:          public bool BOF()
  42:          {
  43:              return _recNo < 0;
  44:          }
  46:          public bool EOF()
  47:          {
  48:              return _recNo >= _recCount;
  49:          }
  51:          public void MoveFirst()
  52:          {
  53:              _recNo = 0;
  54:          }
  56:          public void MoveLast()
  57:          {
  58:              _recNo = _recCount - 1;
  59:          }
  61:          public void MovePrevious()
  62:          {
  63:              --_recNo;
  64:          }
  66:          public void MoveNext()
  67:          {
  68:              ++_recNo;
  69:          }
  71:          public int GetBookmark()
  72:          {
  73:              return _recNo;
  74:          }
  76:          public void SetBookmark(int bkmk)
  77:          {
  78:              _recNo = bkmk;
  79:          }
  81:          public int Count
  82:          {
  83:              get { return RecCount; }
  84:          }
  85:          #endregion
  86:      }

IC1FlexReportExternalRecordset:

   1:   public class MyExtRecordset : IC1FlexReportExternalRecordset
   2:      {
   3:          private MyRecordset _recordset;
   4:   
   5:          public MyExtRecordset()
   6:          {
   7:              _recordset = new MyRecordset();
   8:          }
   9:   
  10:          public int RecCount
  11:          {
  12:              get { return _recordset.RecCount; }
  13:              set { _recordset.RecCount = value; }
  14:          }
  15:   
  16:          #region IC1ReportExternalRecordset Members
  17:          public void EditParams()
  18:          {
  19:              using (MyExtRecordsetForm f = new MyExtRecordsetForm())
  20:                  f.Edit(this);
  21:          }
  22:   
  23:          public IC1FlexReportRecordset GetRecordset()
  24:          {
  25:              return _recordset;
  26:          }
  27:   
  28:          public string Caption
  29:          {
  30:              get { return "External Recordset Sample"; }
  31:          }
  32:   
  33:          public string Params
  34:          {
  35:              get
  36:              {
  37:                  return _recordset.RecCount.ToString();
  38:              }
  39:              set
  40:              {
  41:                  int count;
  42:                  if (int.TryParse(value, out count))
  43:                      _recordset.RecCount = count;
  44:              }
  45:          }
  46:          #endregion
  47:      }

这样我们编译后就会生成一个dll文件。我们看看效果

image

image

image

这样我们就完成了外部数据源的定义。

如果你有疑问,可以到GCDN获得技术支持:

http://gcdn.gcpowertools.com.cn/showforum-68.html

GCDNhttp://gcdn.gcpowertools.com.cn/

官方网站http://www.gcpowertools.com.cn/

转载声明:
欢迎将本站文章进行转载、演绎或用于商业目的,转载时请注明以下信息
文章转自:葡萄城控件产品博客,http://blog.gcpowertools.com.cn
原文地址:http://blog.gcpowertools.com.cn/post/FlexReport_External.aspx

不允许评论