限制用户为播放器添加5个以上的属性

时间:2014-02-24 14:16:19

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

我有tableA(字段:playerId,技能)

所以我的问题是:如何使用户无法添加超过5个相同的playerId?

表的覆盖方法和操作方法是什么?

...罐

1 个答案:

答案 0 :(得分:2)

您可以创建一个新的整数字段AttributeNum。您可以根据您的要求覆盖表上的insert()或initValue()。如果要在此表上快速保持基于集合的操作,请在insert()上选择initValue()。

在overriden方法中,您可以使用查询来聚合和计算当前记录的每个属性数。

编辑:

或者,您可以覆盖表格上的validateWrite()方法。

boolean validateWrite()
{
    TableA        tableA;
    boolean       ret = super();    
    #define.MaxAttributes(5) // consider using setup         
    if (ret && !this.RecId)
    {
        select count(RecId) from tableA where tableA.PlayerId == this.PlayerId;    
        if (tableA.RecId >= #MaxAttributes)
        {    
            ret = checkFailed("Error message goes here");
        }    
    }
    return ret;
}

您没有指定每个玩家的属性是否应该是唯一的,但您还应考虑创建适当的索引以强制执行数据完整性。

您可以在此处找到更多信息:

Maintain Fast SQL Operations [AX 2012]

Speeding Up SQL Operations [AX 2012]

Maintaining Data Integrity [AX 2012]

Data Model for New Microsoft Dynamics AX Modules [AX 2012]

Where to Place the Code [AX 2012]