我在使格式化正确发生方面遇到了一些麻烦。我认为这源于对我试图改变的事件的错误理解。
任何方向都会很棒
private void so_FetchData(object sender, FetchEventArgs eArgs)
{
if (m_so != null && m_so.Rows.Count > (m_soRowCount + 1))
{
DataRow soDr = m_so.Rows[m_soRowCount++];
if (soDr != null)
{
var compResID = (int) soDr["CompResID"];
var result = (ComplianceLevel) soDr["Result"];
var sectNum = (int) soDr["JobSectType"];
var sectName = soDr["S" + sectNum + "Name"] as string;
var sectTxt = soDr["S" + sectNum + "Text"] as string;
Fields["CompLev"].Value = (result == ComplianceLevel.OtherThanSerious) ? "Other Than Serious" : result.ToString();
m_sectInfo = new SectInfo(sectName, sectTxt);
m_causes = new Causes(compResID);
m_actions = new Actions(compResID);
subReport1.Report = m_sectInfo;
subReport2.Report = m_causes;
subReport3.Report = m_actions;
eArgs.EOF = false;
}
}
else
{
eArgs.EOF = true;
}
}
private void eh_BeforePrint(object sender, EventArgs e)
{
//decide where the bottom border should be draw to
if (m_actions != null && m_actions.ShouldShowBottBorder)
{
subReport3.Border.BottomStyle = BorderLineStyle.ThickSolid;
subReport2.Border.BottomStyle = BorderLineStyle.Solid;
}
else if (m_causes != null && m_causes.ShouldShowBottBorder)
{
subReport2.Border.BottomStyle = BorderLineStyle.ThickSolid;
}
else
{
subReport1.Border.BottomStyle = BorderLineStyle.ThickSolid;
}
}
问题在于,每次单步执行eh_BeforePrint方法时,即使我单步执行子报表并且值已正确设置,值也始终等于false。是什么导致bool属性重置为false?
如果要在每个子报告的Fetch_Data方法中打印任何记录,只需更改它。
private void Causes_FetchData(object sender, FetchEventArgs eArgs)
{
if (m_pos < m_corrs.Count)
{
if (!ShouldShowBottBorder)
ShouldShowBottBorder = true;
//...
}
}
答案 0 :(得分:2)
在相应的FetchData事件之后,您无法确定BeforePrint事件是否完全引发。例如,对于多个记录,FetchData可能会多次触发,但由于某些逻辑在布局引擎中保持在一起,因此在ActiveReports知道它将提交一个部分的页面之前,它可能需要几个记录。因此,在引发相应的BeforePrint事件之前,为几个事件引发FetchData是很常见的。
如果我正确理解你的代码,那么问题就更大了。您似乎正在计算子报表中的值(m_causes和m_actions似乎是实际的子报表)。如果是这种情况,则无法可靠地计算子报表中的值并将其传递给父报表。相反,您需要在父报告中计算这些值。但是,通常可以添加一些共享函数来计算值并从父报表中调用它,然后将该值传递到子报表中。
如果您对此有具体问题,请在此处查看更多信息。
如果您更改了初始化子报表的方式,那么在不相关的注释中,您可以获得非常显着的性能提升。始终在ReportStart事件中初始化子报表,然后在包含子报表控件的部分的格式事件中设置其数据。这样,您可以初始化每个子报表一次,而不是为每个记录初始化每个子库。例如:
private void so_ReportStart()
{
subreport1.Report = new SectInfo();
subreport2.Report = new Causes();
subreport3.Report = new Actions();
}
private void Detail_Format()
{ // assuming Detail is the section containing your subreports:
((SectInfo)subreport1.Report).SetParameters(Fields["sectName"].Value, Fields["sectTxt"].Value);
((Causes)subreport2.Report).SetParameters(Fields["compResID"].Value);
((Actions)subreport3.Report).SetParameters(Fields["compResID"].Value);
}
您可以在FetchData中设置这些“字段”值,类似于现在初始化子报表的方式。如下所示:
private void so_FetchData(object sender, FetchEventArgs eArgs)
{
if (m_so != null && m_so.Rows.Count > (m_soRowCount + 1))
{
DataRow soDr = m_so.Rows[m_soRowCount++];
if (soDr != null)
{
var compResID = (int) soDr["CompResID"];
var result = (ComplianceLevel) soDr["Result"];
var sectNum = (int) soDr["JobSectType"];
var sectName = soDr["S" + sectNum + "Name"] as string;
var sectTxt = soDr["S" + sectNum + "Text"] as string;
Fields["CompLev"].Value = (result == ComplianceLevel.OtherThanSerious) ? "Other Than Serious" : result.ToString();
/** BEGIN NEW CODE **/
Fields["sectName"].Value = sectName;
Fields["sectTxt"].Value = sectTxt;
Fields["compResID"].Value = compResId;
/** END NEW CODE **/
/** OLD CODE:
m_sectInfo = new SectInfo(sectName, sectTxt);
m_causes = new Causes(compResID);
m_actions = new Actions(compResID);
subReport1.Report = m_sectInfo;
subReport2.Report = m_causes;
subReport3.Report = m_actions;
**/
eArgs.EOF = false;
}
}
else
{
eArgs.EOF = true;
}
}
要了解有关ActiveReports中事件的更多信息,请参阅the Report Events concepts topic in the ActiveReports Online Help。 要了解有关将数据传递到子报告的详细信息,请参阅Subreports with Run-Time Data Sources in the ActiveReports Online Help。
Scott Willeke
GrapeCity inc.