2010-11-30 57 views
0

我在使格式正确发生时遇到了一些麻烦。我相信它是什么,我试图做出改变事件的可能不正确的认识造成的。在另一个事件中重置属性值

任何方向将是巨大的

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。发生什么事情导致布尔属性重置为false?

如果在每个子报表的Fetch_Data方法中打印任何记录,只需更改它。

private void Causes_FetchData(object sender, FetchEventArgs eArgs) 
    { 
     if (m_pos < m_corrs.Count) 
     { 
      if (!ShouldShowBottBorder) 
       ShouldShowBottBorder = true; 
      //... 
     } 
    } 
+0

你似乎没有在任何地方设置`ShouldShowBottBorder`。你能告诉我们该房产的来源吗? – 2010-11-30 04:01:02

回答

2

您不能确保BeforePrint事件在相应的FetchData事件之后精确地引发。例如,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. 
相关问题