FastReport 自定义数据集

时间:2022-05-17 20:47:34

1、可以自定义一个新的数据源

  参考:

internal class VirtualDataSource : DataSourceBase
{
   private int FVirtualRowsCount;

   public int VirtualRowsCount
   {
     get { return FVirtualRowsCount; }
     set { FVirtualRowsCount = value; }
   }

   #region Protected Methods
   /// <inheritdoc/>
   protected override object GetValue(Column column)
   {
     return null;
   }
   #endregion

   #region Public Methods
   public override void InitSchema()
   {
    // do nothing
   }

   public override void LoadData(ArrayList rows)
   {
     rows.Clear();
     for (int i = 0; i < FVirtualRowsCount; i++)
     {
       rows.Add(0);
     }
   }
   #endregion
}

2、可以继承 TableDataSource    修改 LoadData 方法。

 

3、想要可视化设计,必须继承 DataConnectionBase 实现相应的方法。

public override string[] GetTableNames()

public override string QuoteIdentifier(string value, DbConnection connection)

public override Type GetConnectionType()

public override DbDataAdapter GetAdapter(string selectCommand, DbConnection connection,
  CommandParameterCollection parameters)

/// <inheritdoc/>
  public override ConnectionEditorBase GetEditor()
  {
    return new MsSqlConnectionEditor();
  }

  /// <inheritdoc/>
  public override Type GetParameterType()
  {
    return typeof(SqlDbType);
  }

  /// <inheritdoc/>
  public override int GetDefaultParameterType()
  {
    return (int)SqlDbType.VarChar;
  }

  /// <inheritdoc/>
  public override string GetConnectionId()
  {
    SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(ConnectionString);
    string info = builder.InitialCatalog;
    if (String.IsNullOrEmpty(info))
      info = builder.AttachDBFilename;
    return "MS SQL: " + info;
  }
}