2010-11-30 11 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. 
相關問題