在另一个事件中重置属性值

发布于 2024-10-05 06:29:44 字数 2287 浏览 3 评论 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,即使我单步执行子报告并正确设置值。发生了什么导致 bool 属性重置为 false?

如果每个子报表的 Fetch_Data 方法中有需要打印的记录,只需更改它即可。

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

I am having some trouble with getting the formatting to occur correctly. I believe it stems from what is probably incorrect understanding of the events that I am attempting to make the changes in.

any direction would be great

    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;
        }
    }

the issue is that every time I step through the eh_BeforePrint method, the values always equate to false even though I step through the sub reports and the values are properly set. What is happening to cause the bool property to reset to false?

Just changing it if there are any records to print in the Fetch_Data method of each sub report.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笨笨の傻瓜 2024-10-12 06:29:44

您不能确保 BeforePrint 事件恰好在相应的 FetchData 事件之后引发。例如,FetchData 可能会针对多条记录多次触发,但由于布局引擎中的一些保持在一起的逻辑,ActiveReports 可能需要多条记录才能知道它将提交一个部分到哪个页面。因此,在引发相应的 BeforePrint 事件之前,为多个事件引发 FetchData 是很常见的。

如果我正确理解你的代码,那么还有一个更大的问题。您似乎正在计算子报告中的值(m_causes 和 m_actions 似乎是实际的子报告)。如果是这种情况,您将无法可靠地计算子报表中的值并将其传递到父报表。相反,您需要在父报告中计算这些值。但是,通常您可以添加一些共享函数来计算值并从父报表中调用它,然后将该值传递到子报表中。

如果您对此有具体疑问,请在此处发表评论并提供更多信息。

在一个不相关的说明中,如果您更改初始化子报表的方式,您可以获得相当显着的性能提升。始终在 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 中事件的更多信息,请参阅 报表事件ActiveReports 在线帮助中的概念主题
要了解有关将数据传递到子报表的详细信息,请参阅具有运行时数据源的子报表ActiveReports 在线帮助

Scott Willeke
GrapeCity inc.

You cannot be assured that the BeforePrint event raises exactly after the corresponding FetchData event. For example, FetchData may fire many times for several records, but due to some keep together logic in the layout engine, it may take several records before ActiveReports knows which page it will commit a section to. Therefore, it is pretty common for FetchData to be raised for several events before the corresponding BeforePrint events are raised.

If I understand your code properly there is a bigger problem though. It appears you are calculating values in your subreports (m_causes and m_actions appear to be actual subreports). If that is the case you cannot reliably calculate values in your subreports and pass them out to the parent report. Instead, you'll need to calculate those values in your parent report. However, usually you can add some shared function to calculate the value and call it from the parent report, and then pass that value into the subreports.

Comment here with some more information if you have specific questions about doing that.

On an unrelated note, you can get a pretty significant performance boost if you change the way you're initializing your subreports. Always initialize your subreports in the ReportStart event and then set their data in the format event of the section containing the Subreport control. This way you initialize each subreport once instead of initializing each subureport for every record. For example:

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);
}

You would setup those "Fields" values in FetchData similar to how your initializing the subreports now. Something like the following:

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;
    }
}

To learn more about the events in ActiveReports see the Report Events concepts topic in the ActiveReports Online Help.
To learn more about passing data into Subreports see Subreports with Run-Time Data Sources in the ActiveReports Online Help.

Scott Willeke
GrapeCity inc.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文