背景颜色行

时间:2017-02-28 13:49:45

标签: axapta dynamics-ax-2012 x++

我在表单的数据源上创建了一个显示方法来检查某个字段的匹配项,如果有2个相同的值,则表单中的特定行应该得到背景颜色。

以下代码的问题是,如果只有1行记录匹配,表单中的所有行都会被赋予背景颜色。

我做错了什么?

public void displayOption(Common _record, FormRowDisplayOption _options)
    {
        SalesLine  salesLineLocal;
        ;

        salesLineLocal = _record;

         while select salesLineLocal
            where salesLineLocal.SerialId == salesLine.SerialId

        if(salesLineLocal.RecId != SalesLine.RecId)
        {
                _options.backColor(Winapi::RGB2int(251,181,251));

        }
    }

1 个答案:

答案 0 :(得分:4)

修改您的方法如下,这样可以正常工作:

public void displayOption(Common _record, FormRowDisplayOption _options)
{
    SalesLine  salesLineCurrent;
    SalesLine  salesLineLocal;
    ;

    salesLineCurrent = _record;

    select firstOnly RecId from salesLineLocal
        where salesLineLocal.SerialId == salesLineCurrent.SerialId
           && salesLineLocal.RecId    != salesLineCurrent.RecId;

    if (salesLineLocal.RecId)
    {
        _options.backColor(Winapi::RGB2int(251,181,251));
    }

    super(_record, _options);
}

但是如果你想改进它,你可以在表级别移动验证逻辑。在SalesLine表创建方法

public boolean hasDupplicate()
{
    SalesLine  salesLine;
    ;

    select firstOnly RecId from salesLine
        where salesLine.SerialId == this.SerialId
           && salesLine.RecId    != this.RecId;

    return salesLine.RecId != 0
}

然后您的displayOption方法看起来像

public void displayOption(Common _record, FormRowDisplayOption _options)
{
    SalesLine  salesLineLocal;
    ;

    salesLineLocal = _record;

    if (salesLineLocal.hasDupplicate())
    {
        _options.backColor(Winapi::RGB2int(251,181,251));
    }

    super(_record, _options);
}