如何在报表最后一页打东西及系统的一个类似小方法

来源:互联网 发布:mac什么浏览器好用 编辑:程序博客网 时间:2024/04/29 20:27
 

在做报表是发现系统会使用一种firstlast EDT的数据来判断是否打印footer,现在和大家分享一下:

在路径:AR->设置->表格->表格设置 下得到如下配置面板:

 

可以看到group:金额 下有一个字段:合计,这里选择的是尾页。这个字段的数据来源于表:CustFormletterParameters. TotalsFirstLastPage。我们这里设置的是尾页,即FISTLAST::LAST.

系统中有一个报表中用到了这个设置(得谢谢micky的帮助!,报表名为:CustCollectionJour

它会设置两个标志:BOOLEAN printFooter,showFooter. Init 方法时将printFooter设置为true

然后重新了fetch,其中代表性的代码如下:

boolean fetch()

{

         ……

    queryRun = new QueryRun(this.query());

    while (queryRun.next())

    {

        showFooter              = true;

        custCollectionLetterJour = queryRun.get(tablenum(CustCollectionLetterJour));

                   ……

        if (!this.send(_custTable))

        {

            break;

        }

        printFooter         = this.totalsPage(FirstLast::First, showFooter);

         ……

        this.send(custCollectionLetterJour);

                   ……

        method send run several times here

                   ……

        if (element.page() != 1)

        {

            printFooter             = this.totalsPage(FirstLast::Last, showFooter);

        }

        else

        {

            printFooter             = showFooter;

        }

        ……

        element.newPage(true);

        element.page(1);

    }

    return true;

}

其中调用到了方法:

boolean  totalsPage(FirstLast   firstLast, boolean     printNow)

{

    return totalsFirstLastPage == firstLast ? printNow : false;

}

在该方法中totalsFirstLastPage是从表CustFormletterParameters. TotalsFirstLastPage的值。

FooterexcuteSection被重新为:

void  executeSection()

{

    if (printFooter)

    {

        super();

        printFooter = false;

    }

}

整个逻辑类似这样:

首先printFootershowFootertrue,每拿到一条JournalHeader,先会执行

printFooter         = this.totalsPage(FirstLast::First, showFooter);

返回始终是false,所以在下一次设置printFooter前始终不会执行footerexcuteSectionsuper,也即不会打印footer

当与此Header相关的所有记录、信息都打印完了,这时候执行到了

if (element.page() != 1)

        {

            printFooter             = this.totalsPage(FirstLast::Last, showFooter);

        }

        else

        {

            printFooter             = showFooter;

        }

即在执行到这里之前,即使记录多换页了,footer是不被打印的。这里判断是不是已经不在第一页了,如果不是第一页,执行

printFooter             = this.totalsPage(FirstLast::Last, showFooter);

会将printfooter设置为true,所以footer要被打印了。如果是第一页,执行

printFooter             = showFooter;

由于showFooter的值在初始后就没有被改动过,所以也返回true,结果就是不管怎么,到这里footer都是要被打印的。

在此之后

element.newPage(true);

        element.page(1);

即新开一页,重复上面所提的的逻辑。

 

之所以要去看这个东西,是因为Micky当时的建议是这样可以设置是否在最后一页打东西。从这个结果看,如果while (queryRun.next())并非执行一次,那么这条路是行不通的。就我目前的了解,在执行完之前是没办法在代码中得到总页数的。

如果有需要只在最后一页执行一些代码,完全可以在

while (queryRun.next())

{….}

之后放入你的处理逻辑。While执行完了当然报表的主体内容也就打印完了。

以上是我个人的理解,希望大家多指正!谢谢!

 

原创粉丝点击