Axapta对话验证 [英] Axapta Dialog Validation

查看:191
本文介绍了Axapta对话验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现几个关于网络的帖子和文章谈论在对话框中验证表单域,但是没有一个示例看起来似乎正常工作。

I've found several posts and articles around the net talking about validating form fields in dialogs, but none of the examples I've found seem to work properly.

有人可以发布一个完整的,简洁的x ++代码示例,生成包含单个文本字段的对话框,执行简单的验证(如果text =abc),如果验证通过,则关闭窗口(返回字段值)或者如果验证失败,则生成Infolog警告,而不关闭对话框。

Can someone post a complete, concise example of x++ code that generates a dialog containing a single text field, performs simple validation (if text = "abc") on it, and either closes the window (returning the field value) if validation passes or generates an Infolog warning without closing the dialog if validation fails.

对于我们刚刚开始使用x ++的人,我认为这是一个很好的起点,

For those of us just beginning in x++, I think it would be a great starting point to have an actual working example to build on.

谢谢!

推荐答案

在AX 2009中的一个例子,说明如何使用RunBase类构建一个简单的对话框。在其中,我创建一个名为DialogExample的类,并从RunBase派生。要显示对话框,您只需要运行该类,但通常情况下,可以通过将MenuItem指向该类。

Here is an example in AX 2009 of how to build a simple dialog using the RunBase class. In it I create a class called DialogExample and derive from RunBase. To show the dialog you simply need to run the class, but typically this would be done by pointing a MenuItem at the class.

public class DialogExample extends RunBase
{
    DialogField dialogName;
    Name name;

    #DEFINE.CurrentVersion(1)
    #LOCALMACRO.CurrentList
        name
    #ENDMACRO
}

Object dialog()
{
    Dialog dialog = super();
    ;

    // Add a field for a name to the dialog. This will populate the field with 
    // any value that happens to be saved in name from previous uses of the
    // dialog.
    dialogName = dialog.addFieldValue(TypeId(Name), name);

    return dialog;
}

boolean getFromDialog()
{
    ;

    // Retrieve the current value from the dialog.
    name = dialogName.value();

    return true;
}

boolean validate(Object _calledFrom = null)
{
    boolean isValid;

    isValid = super(_calledFrom);


    // Perform any validation nessecary.
    if (name != 'abc')
    {
        isValid = checkFailed('Name is not equal to abc') && isValid;
    }

    return isValid;
}

Name parmName()
{
    ;

    return name;
}

public container pack()
{
    return [#CurrentVersion,#CurrentList];
}

public boolean unpack(container _packedClass)
{
    int version = conpeek(_packedClass, 1);

    switch (version)
    {
        case #CurrentVersion:
            [version,#CurrentList] = _packedClass;
            break;
        default :
            return false;
    }

    return true;
}

public static void main(Args args)
{
    DialogExample DialogExample;
    ;

    dialogExample = new dialogExample();

    // Display the dialog. This only returns true if the the user clicks "Ok" 
    // and validation passes.
    if (dialogExample.prompt())
    {
        // Perform any logic that needs to be run.
        info(dialogExample.parmName());
    }
}

通常在这种情况下需要运行的逻辑在类中放入一个运行方法,然后如果点击Ok按钮从main中调用。由于run方法将是一个实例方法,所以无需parm方法来访问对话框中的字段值。

Typically in this scenario logic that needs to be run would be put in a run method on the class and then called into from main if the Ok button is clicked. Since the run method would be an instance method this gets rid of the need for the parm methods to access the value of the field on the dialog.

这篇关于Axapta对话验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆