2016-06-30 29 views
3

レポートを生成するためにFastReport.Netをインストールしました。FastReport.Netを使用してレポートを作成

私は次の参照が含まれている:

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

はまた、私はFastReport.Netと呼ばれるツールボックスにカスタムタブを作成し、タブにFastReportのコントロール/コンポーネントを追加し、私が持っているコントロールはいます

Pointer and WebReport 

私はドラッグとWebReportコンポーネントをdroppped私.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の上の設計(CTRL +Shiftキー + F10)からSelect DataSource...をクリックしたときには、選択するために、オプションなしでポップアップを開きます。

他の手順はありますか?

編集

私はこれを試してみました:

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登録が成功しませんでした。

実行を続けると、report.Show();で実行を停止します。

答えて

2

1つの方法は、WebReportというFastReportコントロールを使用できることです。このため

あなたがする必要があるのは、次のようにそれは、このためのツールボックスの手順で、新しいカスタムタブを作成している:右ツールボックスのをクリックし、FastReportのと呼ばれる新しいタブを作成する]をクリックします

  • (あなたが与えることができます任意の名前)
  • この後、WebReportコントロールをドラッグアンドドロップしてレポートを作成した後、FastReport
  • のdllを追加します。
  • メニューからデータベースと対話する場合は、「データソース」を追加します。

とthats it!

関連する問題