水晶报表 - 默认参数 [英] Crystal Reports - Default Parameters

查看:166
本文介绍了水晶报表 - 默认参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Crystal报表中,您可以为报表参数定义默认值。



例如,我可能有一个日期范围并设置默认开始12/01 / 2008,默认结束时间为12/31/2008。



是否可以在运行时修改这些默认值?例如:



1 - 默认为当月的第一天和最后几天?



到一个专有公司财政日历的第一天和最后几天? (即在数据库中查找)



3 - First&今年的最后几天?



你得到点。这可能吗?我甚至会开放一个解决方案,涉及到运行一个外部应用程序到达报告和修改它们,如果任何人都知道如何这样做。



编辑: / p>

为了回答Philippe Grondier提出的问题,大多数报告都是从应用程序中运行的。我希望比运行时操纵水晶对象简单一些;我现在有我的手,现在解决该API的其他部分。

解决方案

您打算从水晶报表界面运行您的水晶报表作为嵌入在另一个程序中的加载项(例如,您可以使用Crystal Reports ActiveX Designer运行时支持 - craxdrt.dll - 在VB代码中)?在最后一种情况下,可以在启动报表之前操作报表的每个对象。然后可以根据需要更新参数等对象。



作为这种运行时更新的简单示例,我的报表打印例程将会检查报表中是否存在名为printedBy的字段。如果找到此字段,其值将被解析为请求报告的用户的域名,并将被打印出来。



在更高级别,您甚至可以重塑报表SQL字符串以添加可以从代码继承的特定过滤器。通过这样做,你可能甚至不需要参数:让你的代码添加过滤值'on the fly'



编辑:一些代码示例:



(m_rapport是一个CRAXDRT.report对象,ActiveSession是我当前的会话对象)

  m_rapport.ParameterFields.Count> 0 then 
For i = 1到m_rapport.ParameterFields.Count
如果m_rapport.ParameterFields(i).Name ={?PUB_DateDebutPeriode}然后
m_rapport.ParameterFields(i).AddCurrentValue CDate (DateValue(sessionActive.dateDebutPeriode))
如果
结束如果m_rapport.ParameterFields(i).Name ={?PUB_DateFinPeriode}然后
m_rapport.ParameterFields(i).AddCurrentValue CDate (sessionActive.dateFinPeriode))
如果
结束如果m_rapport.ParameterFields(i).Name ={?PUB_id_Personne}然后
m_rapport.ParameterFields(i).AddCurrentValue StringFromGUID(clientActif.id_Personne )
End If
Next i
Endif

另一个函数用于在运行时更改报表的数据源,以便报表可以在不同的服务器/位置上执行。


In Crystal reports, you can define default values for the report parameters.

For example, I might have a date range and set a default start of 12/01/2008 and a default end of 12/31/2008.

Is it possible to modify these defaults at runtime? For example:

1 - Default to the first and last days of the current month?

2 - Default to the first and last days of a proprietary company fiscal calendar? (i.e., look it up in a database)

3 - First & Last days of the current year?

You get the point. Is this possible? I'd even be open to a solution that involved running an external application to reach into the reports and modify them, if anyone knows how to do that.

Edit:

To answer the question posed by Philippe Grondier, most of these reports are run from inside an application. I was hoping for something simpler than manipulating the crystal object at runtime; I have my hands full right now with figuring out other parts of that API. I might take a look in the future, though.

解决方案

Are you planning to run your crystal report from the crystal reports interface or as an add-in embedded in another program (you can for example use the Crystal Reports ActiveX Designer Runtime Support - craxdrt.dll - in VB code) ? In this last case, it is possible to manipulate every object of the report before launching it. Objects such as parameters can then be updated according to your needs.

As a simple example of such runtime update, my report printing routine will allways check if there is a field named "printedBy" in the report. In case this field is found, its value will be settled to the the domain name of the user that requests the report and will be printed out.

At an higher level, you can even reshape the report SQL string to add specific filters that can be inherited from your code. By doing so you might not even need parameters anymore: let your code add the filtering values 'on the fly'

EDIT: some code examples:

(m_rapport is a CRAXDRT.report object, ActiveSession is my current session object)

If m_rapport.ParameterFields.Count > 0 Then
    For i = 1 To m_rapport.ParameterFields.Count
        If m_rapport.ParameterFields(i).Name = "{?PUB_DateDebutPeriode}" Then
            m_rapport.ParameterFields(i).AddCurrentValue CDate(DateValue(sessionActive.dateDebutPeriode))
        End If
        If m_rapport.ParameterFields(i).Name = "{?PUB_DateFinPeriode}" Then
            m_rapport.ParameterFields(i).AddCurrentValue CDate(DateValue(sessionActive.dateFinPeriode))
        End If
        If m_rapport.ParameterFields(i).Name = "{?PUB_id_Personne}" Then
            m_rapport.ParameterFields(i).AddCurrentValue StringFromGUID(clientActif.id_Personne)
        End If
    Next i
Endif

I also have another function to change report's datasource at runtime, so that reports can be executed on different servers/locations.

这篇关于水晶报表 - 默认参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆