题
我在正确进行格式时遇到了一些麻烦。我相信这可能是对我试图进行更改的事件的理解可能是错误的。
任何方向都很棒
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_BEFORERPRINT方法时,即使我逐步浏览子报告并正确设置了值,这些值始终等同于false。发生了什么导致布尔属性重置为false?
只需在每个子报告的Fetch_Data方法中打印任何记录,请更改它。
private void Causes_FetchData(object sender, FetchEventArgs eArgs)
{
if (m_pos < m_corrs.Count)
{
if (!ShouldShowBottBorder)
ShouldShowBottBorder = true;
//...
}
}
解决方案
您不能保证,在相应的FetchData事件之后,预印事件正好增加。例如,fetchdata可能会为多次记录开火,但是由于布局引擎中有些逻辑,它可能需要几个记录,然后ActiveReports知道它将提交哪个页面。因此,在提出相应的印刷事件之前,要为几个事件提出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在线帮助. 。要了解有关将数据传递到子报告的更多信息,请参见 ActiveReports在线帮助中的运行时间数据源的子报告.
Scott Willeke
GrapeCity inc.