关闭

dynamicreports1

223人阅读 评论(0) 收藏 举报
package report;

import static net.sf.dynamicreports.report.builder.DynamicReports.cmp;
import static net.sf.dynamicreports.report.builder.DynamicReports.col;
import static net.sf.dynamicreports.report.builder.DynamicReports.exp;
import static net.sf.dynamicreports.report.builder.DynamicReports.grid;
import static net.sf.dynamicreports.report.builder.DynamicReports.report;
import static net.sf.dynamicreports.report.builder.DynamicReports.sbt;
import static net.sf.dynamicreports.report.builder.DynamicReports.stl;
import static net.sf.dynamicreports.report.builder.DynamicReports.type;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import net.sf.dynamicreports.adhoc.AdhocManager;
import net.sf.dynamicreports.adhoc.configuration.AdhocColumn;
import net.sf.dynamicreports.adhoc.configuration.AdhocConfiguration;
import net.sf.dynamicreports.adhoc.configuration.AdhocReport;
import net.sf.dynamicreports.examples.Templates;
import net.sf.dynamicreports.jasper.builder.JasperReportBuilder;
import net.sf.dynamicreports.report.base.expression.AbstractSimpleExpression;
import net.sf.dynamicreports.report.builder.column.ColumnBuilder;
import net.sf.dynamicreports.report.builder.column.TextColumnBuilder;
import net.sf.dynamicreports.report.builder.grid.ColumnTitleGroupBuilder;
import net.sf.dynamicreports.report.builder.style.StyleBuilder;
import net.sf.dynamicreports.report.builder.subtotal.AggregationSubtotalBuilder;
import net.sf.dynamicreports.report.constant.HorizontalAlignment;
import net.sf.dynamicreports.report.datasource.DRDataSource;
import net.sf.dynamicreports.report.definition.ReportParameters;
import net.sf.dynamicreports.report.exception.DRException;
import net.sf.jasperreports.engine.JRDataSource;

    

    /**

     * @author Ricardo Mariaca (r.mariaca@dynamicreports.org)

     */

    public class Invoicetest {

       private InvoiceData data = new InvoiceData();

       private AggregationSubtotalBuilder<BigDecimal> totalSum;

       private JRDataSource createDataSource1() {
           
           DRDataSource dataSource = new DRDataSource("item", "quantity", "unitprice", "quantity1", "unitprice1", "quantity2", "unitprice2", "quantity3");
 
       //    dataSource.add("Notebook", 1, new BigDecimal(500));
 
        dataSource.add(null,null , null,null , null,null , null);
           return dataSource;
 
        }
       
       private JRDataSource createDataSource() {

              DRDataSource dataSource = new DRDataSource("item", "orderdate", "quantity");

              for (int i = 0; i < 20; i++) {

                 dataSource.add("Book", new Date(), (int) (Math.random() * 10) + 1);

              }

              return dataSource;

           }

       public JasperReportBuilder build() throws DRException {
           JasperReportBuilder report5 = report();
           try {
               TextColumnBuilder<String>[] columns = new TextColumnBuilder[7];
               columns[0] =  col.column("Totle",       "item",      type.stringType()).setWidth(200);
               columns[1] =  col.column("Totle1",       "item1",      type.stringType());
               columns[2] =  col.column("Totle2",       "item2",      type.stringType());
               columns[3] =  col.column("Totle3",       "item3",      type.stringType());
               columns[4] =  col.column("Totle4",       "item4",      type.stringType());
               columns[5] =  col.column("Totle5",       "item5",      type.stringType());
               columns[6] =  col.column("Totle6",       "item6",      type.stringType());
            //   columns[7] =  col.column("Totle7",       "item7",      type.stringType());
               
               StyleBuilder columnStyle = stl.style(Templates.columnStyle)

                 .setBorder(stl.pen1Point());

              StyleBuilder subtotalStyle = stl.style(columnStyle)

                 .bold();

              StyleBuilder shippingStyle = stl.style(Templates.boldStyle)

                 .setHorizontalAlignment(HorizontalAlignment.RIGHT);
              
               report5 =  report()//create new report design
               .setTemplate(Templates.reportTemplate)

          //   .setColumnStyle(columnStyle)

         //    .setSubtotalStyle(subtotalStyle)
                              .columns(//add columns
                                      columns)
                          
                              .setDataSource(createDataSource1());//set datasource
               
                         //     .show();//create and show report
               
                         } catch (Exception e) {
               
                            e.printStackTrace();
               
                         }
           
            String titlev = "test title";

          JasperReportBuilder report = report();

         

          //init styles

          StyleBuilder columnStyle = stl.style(Templates.columnStyle)

             .setBorder(stl.pen1Point());

          StyleBuilder subtotalStyle = stl.style(columnStyle)

             .bold();

          StyleBuilder shippingStyle = stl.style(Templates.boldStyle)

             .setHorizontalAlignment(HorizontalAlignment.RIGHT);

    

          //init columns

          TextColumnBuilder<Integer> rowNumberColumn = col.reportRowNumberColumn()

             .setFixedColumns(2)

             .setHorizontalAlignment(HorizontalAlignment.CENTER);

//          TextColumnBuilder<String> descriptionColumn = col.column("Description", "description", type.stringType())
//
//             .setFixedWidth(250);
         
          TextColumnBuilder<Integer> quantityColumn = col.column("Quantity", "quantity", type.integerType()).setWidth(100)

             .setHorizontalAlignment(HorizontalAlignment.CENTER);

          TextColumnBuilder<BigDecimal> unitPriceColumn = col.column("Unit Price", "unitprice", Templates.currencyType).setWidth(100);

          
          TextColumnBuilder<String> colaa = col.column("Unit Price", "description1", type.stringType());
          TextColumnBuilder<String> colbb = col.column("Unit Price", "description2", type.stringType());

          TextColumnBuilder<String> colaa1 = col.column("Unit Price", "description1", type.stringType());
          TextColumnBuilder<String> colbb1 = col.column("Unit Price", "description2", type.stringType());

          TextColumnBuilder<String> colaa2 = col.column("Unit Price", "description1", type.stringType());
          TextColumnBuilder<String> colbb2 = col.column("Unit Price", "description2", type.stringType());

          
          TextColumnBuilder<String> priceColumn = colaa

                  .setTitle("Price")

                  .setDataType(type.stringType());

               //vat = price * tax
          TextColumnBuilder<String> priceColumn2 = colbb

                  .setTitle("Price1")

                  .setDataType(type.stringType());
              
          TextColumnBuilder<String> priceColumna = colaa1

                  .setTitle("aPrice")

                  .setDataType(type.stringType());

               //vat = price * tax
          TextColumnBuilder<String> priceColumn2a = colbb1

                  .setTitle("aPrice1")

                  .setDataType(type.stringType());
          
          TextColumnBuilder<String> priceColumnb = colaa2

                  .setTitle("bPrice")

                  .setDataType(type.stringType());

               //vat = price * tax
          TextColumnBuilder<String> priceColumn2b = colbb2

                  .setTitle("bPrice1")

                  .setDataType(type.stringType());
     
          //total = price + vat
          ColumnTitleGroupBuilder totalColumn = grid.titleGroup("Total Price 1", priceColumn, priceColumn2);
          ColumnTitleGroupBuilder totalColumn1 = grid.titleGroup("Total Price 2", priceColumna, priceColumn2a);
          ColumnTitleGroupBuilder totalColumn2 = grid.titleGroup("Total Price 3", priceColumnb, priceColumn2b);
          
          
          report

             .setTemplate(Templates.reportTemplate)

             .setColumnStyle(columnStyle)

             .setSubtotalStyle(subtotalStyle)

               .columnGrid(
                      quantityColumn, unitPriceColumn, totalColumn,totalColumn1,totalColumn2)
               .columns(
                       quantityColumn, unitPriceColumn,priceColumn, priceColumn2,priceColumna, priceColumn2a,priceColumnb, priceColumn2b)
              
                        .summary(cmp.subreport(report5))
                       .pageFooter(

                Templates.footerComponent)

             .setDataSource(createInvoice());

          return report;

       }

       private class TotalPaymentExpression extends AbstractSimpleExpression<String> {

          private static final long serialVersionUID = 1L;

    

          @Override

          public String evaluate(ReportParameters reportParameters) {

return null;
          }

       }

    

       public static void main(String[] args) {

           Invoicetest design = new Invoicetest();

          try {

             JasperReportBuilder report = design.build();

             report.show();

          } catch (DRException e) {

             e.printStackTrace();

          }

       }
       private List<Item> createInvoice() {
           List<Item> items = new ArrayList<Item>();
           items.add(createItem("Notebook", 1, new BigDecimal(1000)));
           items.add(createItem("DVD", 5, new BigDecimal(40)));
           items.add(createItem("Book", 2, new BigDecimal(10)));
           items.add(createItem("Phone", 1, new BigDecimal(200)));
           
           return items;
       }
       
       private Item createItem(String description, Integer quantity, BigDecimal unitprice) {
           Item item = new Item();
           item.setDescription(description);
           item.setQuantity(quantity);
           item.setUnitprice(unitprice);
           item.setDescription1("aaa");
           item.setDescription2("bbb");
           return item;
       }
    }

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:79867次
    • 积分:1443
    • 等级:
    • 排名:千里之外
    • 原创:9篇
    • 转载:390篇
    • 译文:0篇
    • 评论:2条
    最新评论