gpt4 book ai didi

c# - 使用 FastReport.Net 创建报告

转载 作者:行者123 更新时间:2023-11-30 16:48:28 26 4
gpt4 key购买 nike

我已经安装了FastReport.Net用于生成报告。

我包含了以下引用资料:

FastReport.dll , FastReport.Web.dll , FastReport.Bars.dll , FastReport.Editor.dll , FastReport.Service.dll

我还在工具箱中创建了一个名为 FastReport.Net 的自定义选项卡,并将 FastReport 控件/组件添加到该选项卡,我拥有的控件是:

Pointer and WebReport

我已将 WebReport 组件拖放到我的 .aspx 页面上,这使我的 web.config 如下所示:

<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="FastReport.Web, Version=2016.3.13.0, Culture=neutral, PublicKeyToken=DB7E5CE63278458C" />
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="FastReport, Version=2016.3.13.0, Culture=neutral, PublicKeyToken=DB7E5CE63278458C" />
</assemblies>
</compilation>
</system.web>
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=WIN-SERVER;Initial Catalog=RndDatabase;User ID=development;Password=development" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add name="FastReportHandler" path="FastReport.Export.axd" verb="*" type="FastReport.Web.Handlers.WebExport" />
</handlers>
</system.webServer>
</configuration>

我的问题是如何从数据库中获取数据并使用 FastReport 打印报告。

我在我的项目中创建了一个 dataset.xsd,但是当我从 FastReport 上的设计中单击 Select DataSource... 时(ctrl+Shift +F10) 它会打开一个没有可供选择的选项的弹出窗口。

还有其他的程序吗?

编辑

我试过这个:

using System;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.SqlClient;
using System.Web.UI.WebControls;

using FastReport;
using FastReport.Web.Handlers;
using FastReport.Wizards;
using FastReport.Utils;
using FastReport.TypeConverters;
using FastReport.Code;
using FastReport.MSChart;
using FastReport.Data;
using FastReport.Design.StandardDesigner;


namespace fastreports4
{
public partial class fastrepo : System.Web.UI.Page
{
string sql = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();

protected void Page_Load(object sender, EventArgs e)
{

}

public DataSet BindData()
{
DataSet _dataSet = new DataSet();
SqlConnection con = new SqlConnection(sql);
SqlCommand cmd = new SqlCommand("select * from cities", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(_dataSet);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
return _dataSet;
}


protected void Button1_Click(object sender, EventArgs e)
{
DataSet _dataSet = new DataSet();
_dataSet = BindData();
Report report = new Report();
// register the "Cities" table
report.RegisterData(_dataSet.Tables[0], "Cities");
// enable it to use in a report
report.GetDataSource("Cities").Enabled = true;
// create A4 page with all margins set to 1cm
ReportPage page1 = new ReportPage();
page1.Name = "Page1";
report.Pages.Add(page1);
// create ReportTitle band
page1.ReportTitle = new ReportTitleBand();
page1.ReportTitle.Name = "FastReport";
// set its height to 1.5cm
page1.ReportTitle.Height = Units.Centimeters * 1.5f;
// create group header
GroupHeaderBand group1 = new GroupHeaderBand();
group1.Name = "Cities Data";
group1.Height = Units.Centimeters * 1;
// set group condition
group1.Condition = "[Cities.CityName]";//[Cities.CityName].Substring(0, 1)
// add group to the page.Bands collection
page1.Bands.Add(group1);
// create group footer
group1.GroupFooter = new GroupFooterBand();
group1.GroupFooter.Name = "GroupFooter1";
group1.GroupFooter.Height = Units.Centimeters * 1;
// create DataBand
DataBand data1 = new DataBand();
data1.Name = "Data1";
data1.Height = Units.Centimeters * 0.5f;
// set data source
data1.DataSource = report.GetDataSource("Cities");
// connect databand to a group
group1.Data = data1;
// create "Text" objects
// report title
TextObject text1 = new TextObject();
text1.Name = "Text1";
// set bounds
text1.Bounds = new System.Drawing.RectangleF(0, 0,
Units.Centimeters * 19, Units.Centimeters * 1);
// set text
text1.Text = "CitiesData";
// set appearance
text1.HorzAlign = HorzAlign.Center;
text1.Font = new System.Drawing.Font("Tahoma", 14, FontStyle.Bold);
// add it to ReportTitle
page1.ReportTitle.Objects.Add(text1);
// group
TextObject text2 = new TextObject();
text2.Name = "Text2";
text2.Bounds = new RectangleF(0, 0,
Units.Centimeters * 2, Units.Centimeters * 1);
text2.Text = "[Cities.CityName]";//[Cities.CityName].Substring(0, 1)
text2.Font = new Font("Tahoma", 10, FontStyle.Bold);
// add it to GroupHeader
group1.Objects.Add(text2);
report.Show();
}
}
}

这里我想在点击一个按钮时生成一个报告,当点击一个按钮生成报告时,它在 report.Show(); 行给我一个错误说:

DragDrop registration did not succeed.

当我继续执行时,它会在 report.Show(); 处停止执行。

最佳答案

一种方法是您可以使用名为 WebReport 的 FastReport 控件。

为此,您需要做的就是在工具箱中创建一个新的自定义选项卡,步骤如下:

  • 右键单击工具箱并单击创建名为 FastReport 的新选项卡(您可以提供任何名称)
  • 添加FastReport的dll
  • 在此之后拖放 Webreport 控件并创建报告。
  • 如果您想通过菜单添加 DataSource 与数据库交互。

就是这样!

关于c# - 使用 FastReport.Net 创建报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38122027/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com