AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 04.05.2009, 14:05   #1  
Blog bot is offline
Blog bot
Участник
 
25,617 / 848 (80) +++++++
Регистрация: 28.10.2006
PatrickChua: Change the combobox options in RunbaseBatch class
Источник: http://patrickchuaax.spaces.live.com...68AA!115.entry
==============

 
Quote
Change the combobox options in RunbaseBatch class
RunbaseBatch class supplies some features, including batch processing, pack/unpack and progress bar etc. On the other hand, we get this request frequently, usually to modify the properties of dialog control in runtime. For example, we add a combobox control on the dialog, but the options of combobox can't be predefined. Well, the combobox can be very conveniently filled with field lists if you are using a form, while the combobox's selection lists in RunbaseBatch is determined by Enum values ( dialog.addField(TypeId(someEnum)). How can we accomplish this?
First option, change the eunm's values dynamically? Oh, terrible, this means that Axapta needs to add, edit and save AOT node, then synchronize in run time.
Second option, use Form instead of RunbaseBatch class, if you want this Form to be savable and batchable, you need to manually to add some codes on it.
Well, it is no point to do that if there is any other work around. 
There is a third option, and I believe this should do the trick.
Let's start with a simple RunBaseBatch class and a simple scenario, dynamically adding printers' name to the combobox.
Define a BaseEnum called TestRunBaseDialog (ensure that the style property is set to combo box), and create an element for it which is called TestComboboxElement. Then we can set the TestComboboxElement's label as "Select a printer".
Now we can create the RunbaseBatch class from scratch.

 
Declare the class
class TestAddComboOptionsInRunbase extends runbasebatch
{
    int                 printerName;
    DialogField dialogPrinter;
    FormComboboxControl controlCombobox;

    #define.CurrentVersion(1)
    #localmacro.CurrentList
        printerName
    #endmacro
}

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

 
Unpack the value
public boolean unpack(container packedClass)
{
    boolean         _ret;
    Integer         _version    = runbase::getVersion(packedClass);

    switch (_version)
    {
        case #CurrentVersion:
            [_version, #CurrentList] = packedClass;
            break;
        default:
            _ret = false;
    }
    return _ret;
}

 
Design the dialog, we need to activate the dialogSelectCtrl method. And please notice that, there should be some other dialog control to be added before dialogPrinter. The reason is that after the Dialog form has been built, the selected control can not be the dialogPrinter, otherwise, we can't implement the dialogSelectCtrl method when we look up the options in dialogPrinter combobox. So we add a Text before adding combobox.
protected Object dialog(DialogRunbase _dialog, boolean _forceOnClient)
{
    DialogRunBase dialog;
    ;

    controlCombobox = new FormComboboxControl();
    dialog = super(_dialog, _forceOnClient);
    dialog.caption("Dialog for printer option");
    dialog.addText("Choose Printer");
    dialogPrinter = dialog.addField(typeId(TestRunBaseDialog));
  
    dialog.allowUpdateOnSelectCtrl(true);
    return dialog;
}

 
Okey, we can define how to change the selection list in the combobox now.
public void dialogSelectCtrl()
{
    controlCombobox = dialogPrinter.fieldControl();
    controlCombobox.clear();
    controlCombobox.add("Printer One");
    controlCombobox.add("Printer Two");
    controlCombobox.add("Printer three");
    //… more printers here
}

 
Process your business logic in run()
void run()
{
    ;

    switch (printerName)
    {
        case 0:
        info ("You are choosing printer one.");
        break;
        case 1:
        info ("You are choosing printer two.");
        break;
        case 2:
        info ("You are choosing printer three.");
        break;
    }

    //Put your logic here
}


Finally, put the codes to Main()
static void main(Args _args)
{
    TestAddComboOptionsInRunbase testRunBase = new TestAddComboOptionsInRunbase ();
    ;

    if (testRunBase.prompt())
    {
        testRunBase.run();
    }
}

 
The reason why we use dialogSelectCtrl() is that the dialog control in RunbaseBatch class is not built before the prompt method, the dialogPrinter is still the object of FormBuildControl. Only FormComboboxControl object can add and change the selection list. After Axapta implement the runbaseBatch.prompt(), dialogPrinter has become the object of FormComboboxControl. So in the dialogSelectCtrl(), we can modify the selection list of dialogPrinter combobox.
==============
Источник: http://patrickchuaax.spaces.live.com...68AA!115.entry
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
axaptapedia: RunBaseBatch Blog bot DAX Blogs 0 04.04.2009 22:05
axaptapedia: RunBaseBatch Blog bot DAX Blogs 0 31.03.2009 06:06
PatrickChua: Change the combobox options in RunbaseBatch class Blog bot DAX Blogs 0 28.10.2006 18:14
Fred Shen: Change the combobox options in RunbaseBatch class Blog bot DAX Blogs 0 28.10.2006 16:40
Говорят вышел SP2 для Axapta 3. Кто нибуть что знает на эту тему? soin DAX: Прочие вопросы 10 13.10.2003 10:43

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 21:35.