zoukankan      html  css  js  c++  java
  • 多栏报表 多列报表

    Multi Column Report

    [edit]Data Structure

    This is tutorial how to create multiple columns on a report. The report designer has no support for multi column rendering; Like in Word where you can set a "Number of Columns" property on a paragraph. As Workaround create a temporary table with exactly the same fields as needed on the report. For example if you want to display SalesId, CustAccount, ItemId and Qty from the SalesLine, the temporary table for two columns has 8 columns.

    image

    The getFreeSlot() Method is needed in the report to determine if there is a free column slot or if it is necessary to create a new line on the table.

    public static TmpSalesTable2Col getFreeSlot(TmpSalesTable2Col tmp,int column)
    {  ;   if(column==1)
        {
            select firstonly tmp where tmp.SalesId_1 == "";
            return tmp;
        }
        else if(column==2)
        {
            select firstonly tmp where tmp.SalesId_2 == "";
            return tmp;
        }
        else
        {
            throw error("Column number must be between 0 and 1");
        }
    }

    [edit]Report

    Create a new report and declare a variable from type of the temporary table.

    public class ReportRun extends ObjectRun
    {
        TmpSalesTable2Col   tmpSalesTable;
    }

    Create a new method to populate the temporary table. In this example the SalesLine is fetched. If it was created in 2007 it belongs to column number 1 and if it was created in 2008 it belongs to column number 2. I assume here that there are only rows for 2007 or 2008. Otherwise it would be good to filter the select by year. The find() method is used to find a free slot; That means a record exists but with a free slot for the needed column.

    private void populateTmpTable()
    {
        SalesLine           salesLine;
        TmpSalesTable2Col   temp;
        int col;  ;   while select salesLine
        order by SalesId
        {
            // 2007 is first column
            if(year(salesLine.createdDate)==2007)
            {
                temp = TmpSalesTable2Col::getFreeSlot(tmpSalesTable,1);
                // existing record with free slot in first column
                if(temp)
                {
                    temp.SalesId_1 = salesLine.SalesId;
                    temp.ItemId_1 = salesLine.ItemId;
                    temp.CustAccount_1 = salesLine.CustAccount;
                    temp.Qty_1 = salesLine.QtyOrdered;
                    temp.update();
                }
                else
                {
                    tmpSalesTable.clear();
                    tmpSalesTable.SalesId_1 = salesLine.SalesId;
                    tmpSalesTable.ItemId_1 = salesLine.ItemId;
                    tmpSalesTable.CustAccount_1 = salesLine.CustAccount;
                    tmpSalesTable.Qty_1 = salesLine.QtyOrdered;
                    tmpSalesTable.insert();
                }
            }
            // 2008 is second column
            if(year(salesLine.createdDate)==2008)
            {
                temp = TmpSalesTable2Col::getFreeSlot(tmpSalesTable,2);
                // existing record with free slot in second column
                if(temp)
                {
                    temp.SalesId_2 = salesLine.SalesId;
                    temp.ItemId_2 = salesLine.ItemId;
                    temp.CustAccount_2 = salesLine.CustAccount;
                    temp.Qty_2 = salesLine.QtyOrdered;
                    temp.update();
                }
                else
                {
                    tmpSalesTable.clear();
                    tmpSalesTable.SalesId_2 = salesLine.SalesId;
                    tmpSalesTable.ItemId_2 = salesLine.ItemId;
                    tmpSalesTable.CustAccount_2 = salesLine.CustAccount;
                    tmpSalesTable.Qty_2 = salesLine.QtyOrdered;
                    tmpSalesTable.insert();
                }
            }
        }
    }

    Override the fetch() method on the report. Call the populateTmpTable and then send line after line to the report design.

    public boolean fetch()
    {  ;
        element.populateTmpTable();   while select tmpSalesTable
        {
            element.send(tmpSalesTable);
        }   return true;
    }

    Create a new section group for TmpSalesTable2Col and a Body. Put the fields from the table in the body or use a FiledGroup. If necessary add a Sum section, header etc. The report should look like this

    image

  • 相关阅读:
    创建型设计模式之-单例
    设计模式(1、创造型2、结构型、3行为型)
    手写IOC容器和两种注入(构造方法注入和属性注入)
    从依赖倒置原则到IOC控制反转
    自定义HttpHandler可以做什么
    一个用户在浏览器上输入网址怎么走到我们写的.net程序中的,请求到管道处理
    代理Nginx
    .Net Expression表达式目录树(自己动态创建表达式目录树)
    canvas绘制圆环进度条
    城市二级联动
  • 原文地址:https://www.cnblogs.com/perock/p/2352388.html
Copyright © 2011-2022 走看看