Compile Birt development. Tips

Source: Internet
Author: User

Solution URL:

Http://www.birthome.cn

1. Set the color of the table to be separated by rows.
Create a table, select a table, click script, and write count = 0 in the onprepare event;
Select a line and write it in the script oncreate method of the line details:
Count ++;
If (count % 10 = 0 ){
Style. pageBreakAfter = "Always"; // you can specify 10 rows for each page.
}
If (count % 2! = 0 ){
Style. setBackgroundColor ("white ");
} Else {
Style. setBackgroundColor ("#123456 ");
}

2. Write in dataset:
Select *
From CLASSICMODELS. MERs
Where CUSTOMERNUMBER =?

Parameter bound to a self-built parameter: no,
Set in dataset beforeopen:
Var no = "103 ";
ReportContext. setParameterValue ("no", no );
In this way, you can set the report parameter values.

3. Processing of birt Dynamic Parameters
(Click the created Data Set, click the Script page of the Data Set on the right, and write the Script in beforeOpen)
In this example, you can select different query conditions to query and display reports.
Use my report service for demonstration.
The conditions for querying my reports are start time, end time, site, with tickets, no tickets, more than 55, less than 55
Set the report parameters to match these query conditions respectively. Start, end, station, ticketed, unticketed, up55t, below55t
Among them, there are votes, no votes, more than 55, and less than 55 can only choose one situation
I will not write the Page code, which is probably set to 1 if I select one,
Write in the script of the report Dataset:
Var condition = "and 1 = 1 order by Weight desc ";
Var start = reportContext. getParameterValue ("start ");
Var end = reportContext. getParameterValue ("end ");
Var ticket = reportContext. getParameterValue ("ticketed ");
Var unticket = reportContext. getParameterValue ("unticketed ");
Var up55t = reportContext. getParameterValue ("up55t ");
Var below55t = reportContext. getParameterValue ("below55t ");
Var st = reportContext. getParameterValue ("station ");
Var station = "and DetectionStationNo = '" + st + "'";

If (st = "all "){
Station = "and 1 = 1 ";
}


If (ticket = 1 ){
Condition = "and VehClass = 1 order by Weight desc ";
}
If (unticket = 1 ){
Condition = "and VehClass = 0 order by Weight desc ";
}
If (up55t = 1 ){
Condition = "and Weight> 55000 order by OverPercent desc ";
}
If (below55t = 1 ){
Condition = "and not Weight >=55000 order by Weight desc ";
}
Then this. queryText = "..." + condition;


Of course, sometimes we may choose either one or all. For example, if you select all the sites on the page, for a specific value, I specify that if it is all, this condition is not added, 1 = 1
You can try it yourself.

4. row number displayed in the table
Add data in a column of the table detail line, and write row. _ rownum + 1. Select an integer for the data type.


5. Print test in birt
The Code is as follows:

ImportPackage (Packages. java. io );
Out = new PrintWriter (new FileWriter ("c:/test/info.txt", true ));
Out. println ("println" + variable );
Out. close ();

Of course, the creation of a file is not determined here. Create a file first, or you can determine whether the file exists or does not exist.

6. Write Java code in birt:
ImportPackage (Packages. java. io );
Out = new PrintWriter (new FileWriter ("c:/test/info.txt", true ));
Out. println ("println" + variable );
Out. close ();
In this way, you can write all the desired Java code in birt.

7. Notes in the script
Use // or /**/

8. Custom jar:
You can add custom jar to birt.
Right-click Project Properties-> Report Design-> Classpath-> button [Add External JARs]
Add your own jar
Introduce the following in the birt Script:
ImportPackage (Packages. java. io );
Example: I wrote a class com. wanmei. birt. test. Birt. java, as shown below:
Public class Birt {
Public String getThreadName (){
Return Thread. currentThread (). getName () + "-thread ";
}
}
Write in birt script
ImportPackage (Packages. java. io );
ImportPackage (Packages.com. wanmei. birt. test );
Var birt = Birt ();
Var threadName = birt. getThreadName ();

Out = new PrintWriter (new FileWriter ('C:/info.txt ', true ));
Out. println ('threadname: '+ threadName );
Out. close ();
In this way, you can see the printed content in file c:/info.txt.

Related Article

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.