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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 28.10.2006, 16:40   #1  
Blog bot is offline
Blog bot
Участник
 
25,643 / 848 (80) +++++++
Регистрация: 28.10.2006
Dynamics AX Geek: Useful methods for sets / record2set example
Источник: http://AxGeek.spaces.live.com/Blog/c...DB13!138.entry
==============
I find myself working with sets and maps a lot. They are a fast and easy way to buffer information without going back to the database all the time.
The set object has a few nice methods to compare sets.
 
Union
Pass two sets to this method. The method returns a new set that includes all items from either set.
 
Difference
Pass two sets to this method. The return set includes all items from the first set that are not found in the second set.
 
Intersection
Pass two sets to this method. The method return set includes all items found in both sets.
 
The following example illustrates the three methods. record2Set creates a set out of any table record (for simplicity arrays are excluded here). The format is fieldname#value The method is applied to two customer records. Check out the results you are getting: 
  • Union proves not very useful in this example, it has all the fields, and two entries if values are different.
  • Difference is interesting. These are the differences in the two records. Note that the values are from whichever set you supplied first.
  • Intersection. All identical fields. Differences are dropped altogether.
 static void JobSetExamples(Args _args)
{
    custTable   custTable_1;
    custTable   custTable_2;
    Set         setCustTable_1;
    Set         setCustTable_2;
    Set         compare;
 
    set record2set(common _record)
    {
        DictTable       dictTable;
        DictField       dictField;
        FieldId         fieldId;
        Set             recordSet;
        ;
 
        dictTable = new DictTable(_record.tableId);
        recordSet = new Set(Types::String);
 
        for (fieldId = dictTable.fieldNext(0);fieldId;fieldId = dictTable.fieldNext(fieldId))
        {
            dictField = dictTable.fieldObject(fieldId);
            if (!dictField.isSystem() && dictField.arraySize() == 1)
                recordSet.add(strfmt("%1#%2",dictField.name(),_record.(fieldId)));
        }
 
        return recordSet;
    }
    ;
 
    custTable_1            = CustTable::find('4000');
    custTable_2            = CustTable::find('4000');
    custTable_1.AccountNum = "1234";
    custTable_1.Name       = "Test";
    custTable_2.CreditMax  = 333.33;
 
    setCustTable_1 = record2set(custTable_1);
    setCustTable_2 = record2set(custTable_2);
 
    compare = Set::difference(setCustTable_1,setCustTable_2);
    print compare.toString();
 
    compare = Set::difference(setCustTable_2,setCustTable_1);
    print compare.toString();
 
    compare = Set::intersection(setCustTable_1,setCustTable_2);
    print compare.toString();
 
    compare = Set::union(setCustTable_1,setCustTable_2);
    print compare.toString();
 
    pause;
}




==============
Источник: http://AxGeek.spaces.live.com/Blog/c...DB13!138.entry
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
Dynamics AX: Managing Your Supply Chain Using Microsoft Dynamics AX 2009 - Book Review Blog bot DAX Blogs 0 31.03.2009 23:06
axStart: Microsoft Dynamics AX 2009 Hot Topics Web Seminar Series Blog bot DAX Blogs 0 06.08.2008 12:05
Inside Dynamics AX 4.0: Usage Scenarios Blog bot DAX Blogs 0 04.10.2007 05:15
Сергей Герасимов: Что нового в Microsoft Dynamics AX 4.0 Blog bot DAX Blogs 0 16.01.2007 11:00
Dynamics AX: Why Dynamics AX beats SAP Blog bot DAX Blogs 0 10.01.2007 23:15

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

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

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