Axosoft Report Builder (Active Reports 3) - 取决于字段值的条件结果

Axosoft Report Builder (Active Reports 3) - Conditional Results Depending on Field Value

虽然我有一个大问题要解决,但我正在尝试使用 Axosoft 的 Report Builder 创建自定义报告。该报告将包含从数据库中提取以显示的特定项目的计算总数和计数。其中一个字段 (Custom_163) 是一个布尔值,其中 true 将使其成为一种类型的项目(增强),而 false 将具有它作为另一个(维护)。我能够计算报告中项目的总数,但我想将其分解为总数的百分比。

问题:一个布尔字段将确定两种类型的项目。区分它们以收集每个数量是我正在努力的地方。

初始化变量:

private bool _oddRow = true;

private string[] _labels = new string[3];

private int _defectsTotal = 0;
private int _enhanceTotal = 0;
private int _maintenTotal = 0;

详细信息部分(为项目创建行):

public void Detail1_Format()
{
    if  (rpt.Fields.Contains("Custom_163") && rpt.Fields["Custom_163"].Value != null)
    {
        if ((bool)rpt.Fields["Custom_163"].Value == true)
        {
            //needs something here to add a count towards this type
            return enhanceTotal;
        }
        else
        {
            //needs something here to add a count towards this type
            return maintenTotal;
        }

        _defectsTotal++;
        _enhanceTotal += enhanceTotal;
        _maintenTotal += maintenTotal;

        // To Color Every Other Row
        if (_oddRow)
        {
            rpt.Sections["Detail1"].BackColor = System.Drawing.Color.FromArgb(224, 224, 224);
        }
        else
        {   
            rpt.Sections["Detail1"].BackColor = System.Drawing.Color.White;
        }
        _oddRow = !_oddRow;     

        // Converting to String Values
        if (rpt.Fields["ItemId"].Value == null) return; 
    }
}

问题具体在于这些行:

if((bool)rpt.Fields["Custom_163"].Value == true)

我已经根据类似情况对此进行了大量更改:

if(rpt.Fields["Custom_163"].Value.ToString() == "True")
if(rpt.Fields["Custom_163"].Value == true)
if(rpt.Fields["Custom_163"].Value = true)
if(rpt.Fields["Custom_163"].Value == 1)
if(rpt.Fields["Custom_163"].Value.ToString() == "1")
if (Convert.ToBoolean(rpt.Fields["Custom_163"].Value) ==  true)
etc...

但它们似乎没有按预期工作。我希望它过滤掉此字段为 true 的项目,以便其余部分将执行。

另一件事是 return 从 if-else 语句中获取值(不起作用,我尝试使用下面的单独方法也不起作用):

public class findTotals
{
    public findTotals()
    {
    }
    public int resultTotals()
    {
        bool item = (bool)rpt.Fields["Custom_163"].Value;

        if ( item == true)
        {
            int enhanceTotal = 1;
            return; 
        }
        else
        {
            int maintenTotal = 1;
            return;
        }
    }
}

(这整个方法需要大量的工作TBH)。

最后,这些行必须在第二个 if-else 之外,或者至少以某种方式 returned 到原始 if 以便打印到报告中:

_enhanceTotal += enhanceTotal;
_maintenTotal += maintenTotal;

_defectsTotal 获取所有项目的总数并且工作正常。不过,这两行应该根据上述条件为每种类型添加一个计数,以便在报告末尾发布增强功能的总量和维护项目的总量。它不起作用,如果不是 casting/conversion 错误或条件迫使数组越界,则这是其他问题。我也玩过所有这些的顺序。

可能的解决方案?

  1. 如何安全地将 bool 值转换(如果需要)为 int,以便该数字可用于加总?

  2. 如何 return if-else 中的值,以便范围与变量匹配?我需要一个方法吗?

提前致谢

您应该能够与 "True" 进行字符串比较。即

if(string.Compare(rpt.Fields["Custom_163"].Value.ToString(), "True") == 0)

我明白问题出在哪里了。

所以基本上...

if (Convert.ToBoolean(rpt.Fields["Custom_163"].Value) ==  true)
{
    enhanceTotal++;
}
else
{
    maintenTotal++;      
}

_defectsTotal++;

(这都在另一个 if 语句和一堆与问题无关的代码中。)这工作正常,实际上 returns 计数,之后另一个障碍是找出标签,以便它可以正确打印到它的占位符中。不需要整个 findTotals 方法。我不需要比上面列出的三个变量更多的变量来使其工作。我不断出错的一个原因是因为我试图使用一个变量作为标签打印到报告中的不同位置,这显然是不允许的。我没有使用一个标签并将其贴在各处,而是制作了多个相同的标签并确保给它们不同的名称等。

因此,在三个不同的报告部分中,X 不是 X,而是 X、Y、Z(所有相同但不同的标识符)并将其粘贴在需要的地方。伙计,现在看来很明显了,再次感谢。