C# 在另一个事件中重置属性值
我在正确设置格式方面遇到了一些问题。我相信这源于我对我试图改变的事件的错误理解 任何方向都很好C# 在另一个事件中重置属性值,c#,activereports,C#,Activereports,我在正确设置格式方面遇到了一些问题。我相信这源于我对我试图改变的事件的错误理解 任何方向都很好 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_soR
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;
//...
}
}
private void导致\u FetchData(对象发送方、FetchEventArgs eArgs)
{
如果(m_位置
您无法保证BeforePrint事件在相应的FetchData事件之后发生。例如,FetchData可能会多次触发多条记录,但由于布局引擎中的某些“保持在一起”逻辑,它可能需要多条记录,ActiveReports才能知道它将向哪个页面提交节。因此,在引发相应的BeforePrint事件之前引发多个事件的FetchData是很常见的
如果我正确理解了你的代码,那么还有一个更大的问题。您似乎正在计算子报告中的值(m_原因和m_操作似乎是实际的子报告)。如果是这种情况,则无法可靠地计算子报表中的值并将其传递给父报表。相反,您需要在父报表中计算这些值。但是,通常可以添加一些共享函数来计算值,并从父报表调用该值,然后将该值传递到子报表中
如果您对此有任何具体问题,请在此评论并提供更多信息
另一方面,如果您更改初始化子报表的方式,您可以获得相当显著的性能提升。始终在ReportStart事件中初始化子报表,然后在包含子报表控件的节的format事件中设置其数据。这样,您可以初始化每个子报表一次,而不是为每个记录初始化每个子报表。例如:
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中事件的更多信息,请参阅。
要了解有关将数据传递到子报表的更多信息,请参阅
您似乎没有在任何地方设置
showldbotorder
。你能告诉我们那处房产的来源吗?
Scott Willeke
GrapeCity inc.