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

  • 相关阅读:
    SQL Server 2008 允许远程链接 解决方法
    对上传图片进行剪切的jquery插件
    解决在IE6 下,css中的position:fixed 不起作用的办法
    对网站搞评比投票活动的总结
    关于设置sql server 2008服务器属性时出现的无法加载xplog70.dll文件的问题
    Android LayoutInflater的使用
    在Android中查看和管理sqlite数据库
    android开发的WARNING: Could not initialize OpenglES emulation, using software renderer问题的解决
    Android 常用错误及解决方法
    解决MyEclipse启动速度慢,提高MyEclipse启动速度
  • 原文地址:https://www.cnblogs.com/perock/p/2352388.html
Copyright © 2011-2022 走看看