Fastreport Quick Print (. net)

Source: Internet
Author: User

The first thing I did with the Fastreport plugin was to print a very complex Excel table with hundreds of fields that needed to bind the data, a minimum of 4 data sources, and a horizontal, vertical merged cell.

Instead of directly connecting to the database, I register the DataSet object myself using Registerdata, and all table tables are code-generated, populated into the dataset, and then registered in the control.

The first attempt to use this plugin to do a simple function is the following example, but spent the whole day, but also take a leave of 4 people did not get out, the night with someone else's template directly modified, and then test, passed.

Before the test, has always been prompted not to connect to the data source, because I directly use Notepad to add data source to the template, usually others use the data source is their own writing code, call design way to get, and can only be WinForm program, WebForm program not, Because you want to start the COM component.

Here is a particularly simple way I summarize, using Registerdata to register the DataSet object myself.

1. Select "File"-"new" to create a new Fastreport template, select the 1.

2, select "View"-"Data", shown below, Export dictionary, save.

3. Edit the exported. frd file, save it after editing, and then import it.

As follows:

(1) Tabledatasource is the data source node.

(2) name is the name of the table of the DataSet object.

(3) column is the columns of the table, and when the template binds the data, the column's Name property is used.

<?xml version= "1.0" encoding= "Utf-8"?>

<Dictionary>

<tabledatasource name= "Table1" referencename= "Data.table1" datatype= "System.Int32" enabled= "true" >

<column name= "name" datatype= "System.String" propname= "Column"/>

<column name= "Password" datatype= "System.String" propname= "Column"/>

</TableDataSource>

</Dictionary>

4, edit the template, and add a Table control.

The first line directly double-clicks the input text, the second line directly the right data source to the cell;

Sets the border, font.

5. Add an Event backend method

For example, with Table1 selected, double-click after event Manualbuild to add the following code:

Build Events for control Table1

private void Table1_manualbuild (object sender, EventArgs e)

{

Datasourcebase data1 = Report.getdatasource ("Table1"); Get a data source with table name Table1 in the dataset

Data1. Init (); Initialization

Table1.printrow (0); Control Table1 Print Line No. 0

Table1.printcolumns (); Call Printcolumn or printcolumns for each line you print

while (data1. hasmorerows)//print repeated loops of the line

{

Table1.printrow (1);

Table1.printcolumns ();

Data1. Next (); Read Next line

}

}

Description

(1) The table control starts at line No. 0.

(2) The repeating row of the bound data counts as one row.

(3) Before the output line, to call the Init () method first, when there are two data sources, such as Data1 and Data2,data1 is Data2 's parent data source, you need to data1 as parameters, such as data2. Init (DATA1);

(4) to call Printcolumn or printcolumns for each line printed

6, adding C # code

Create a new test page test.aspx, drag and drop a Fastreport control onto the page (only after fastreport.net has been followed and Fastreport.dll,fastreport.bars.dll,fastreport.web.dll is referenced) To

The following pages are added:

<body>

<form id= "Form1" runat= "Server" >

<cc1:webreport id= "Webreport" runat= "Server" onstartreport= "Webreport_startreport"/>

</form>

</body>

Background method:

protected void Webreport_startreport (object sender, EventArgs e)

{

DataSet ds = new DataSet ();

DataTable table1 = new DataTable ();

Table1. TableName = "Table1"; Be sure to set the table name

Ds. Tables.add (table1);

To add a column in a table

Table1. Columns.Add ("name", typeof (String));

Table1. Columns.Add ("Password", typeof (String));

Arbitrarily add some data

for (int i = 0, MaxI = ten; i < MaxI; i++)

{

DataRow row = table1. NewRow ();

row["name"] = "I am" + i.tostring ();

row["password"] = i.ToString ();

Table1. Rows.Add (row);

}

Report Freport = (sender as Webreport). report;

String spath = Getreportspath ("Test.frx");

Freport.load (spath);

Registering a DataSet object in a Fastreport control

Freport.registerdata (DS);

}

<summary>

Get the path to the Fastreport template

</summary>

<param name= "Sreportname" > Template name </param>

<returns> return to template path </returns>

public string Getreportspath (string sreportname)

{

return FastReport.Utils.Config.ApplicationFolder + "reports\\" + sreportname;

}

7, Test effect

1 corresponding to save, can be various formats;

2 Correspondence printing;

3 corresponds to paging.

Fastreport Quick Print (. net)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.