Farseer

导航

读取Info内容

后记:
最近发现其实AX里的类Info已经提供了相应的静态方法infoCon2Str来实现这个功能,所以可以直接调用这个方法去实现本文所说的功能,本文不看也罢。
AX用Infolog去管理用户操作中的出错或者提示信息,最后用SysInfologBrowser这个窗体去展现,但如果通过.NET Business Connector之类的去调用AX的系统类就不可能用这种方法了,因为不可能将窗体通过.NET Business Connector去展现,如果想知道调用的系统类到底发生了什么事情,可以把Infolog的内容转换成字符串返回给调用者。
窗体SysInfologBrowser的数据是通过类info的viewBuild来构造的,所以可以把这个方法简化一下,返回一个字符串,在Global中添加一个静态方法:

static str viewBuildExpress(InfologData _data)
{
    SysInfologMessageStruct logLine;

    
int                  i = 1, j;
    Exception            exception;

    
int                  parentId;

    TmpInfolog           tmpLookup;
    str                  returnValue;

    
int                  oldParentId;
    
int                  seq = 0;

    str                  splitStr 
= '';
    TmpInfoLog           tmpInfoLog;
    SysInfologEnumerator 
enum = SysInfologEnumerator::newData(_data);


TmpInfolog selectInfolog(SysInfologPrefix _prefix, 
int _parentid)
{
    TmpInfolog tmpinfolog2;
    tmpinfolog2.setTmpData(tmpInfoLog);

    select tmpinfolog2
        
where tmpinfolog2.Parent == _parentid   &&
              tmpinfolog2.Prefix 
== _prefix;

    
if (tmpinfolog2)
        
return tmpinfolog2;
    
return null;
}


    
if (conlen(_data)==0)
        
return '';

    
enum.reset();
    
enum.moveNext();
    logLine  
= SysInfologMessageStruct::construct(enum.currentMessage());
    tmpInfoLog.recordLevelSecurity(
true);
    
enum.reset();
    i 
= 1;
    
while (enum.moveNext())
    
{
        logLine  
= SysInfologMessageStruct::construct(enum.currentMessage());
        exception 
= enum.currentException();

        parentId 
= 1;   //header has id = 1

        
for (j=1; j<=logLine.prefixDepth(); j++)
        
{
            tmpLookup.setTmpData(tmpInfoLog);
            tmpLookup 
= selectInfolog(logLine.preFixTextElement(j), parentid);

            
if (tmpLookup)
            
{
                parentId 
= tmpLookup.Seq;
            }

            
else
            
{
                tmpInfoLog.Name         
= logLine.preFixTextElement(j);
                tmpInfoLog.Parent       
= parentId;
                tmpInfolog.Prefix       
= tmpInfolog.Name;
                tmpInfolog.ConIdx       
= j;
                seq
++;
                tmpInfoLog.Seq          
= seq;
                tmpInfoLog.insert();
                parentId                
= tmpInfoLog.Seq;
            }

        }

        
if (parentId != oldParentId)
        
{
            oldParentId 
= parentId;
        }


        tmpInfoLog.Parent   
= parentId;
        seq
++;
        tmpInfoLog.Seq      
= seq;
        tmpInfoLog.Name     
= logLine.message();
        tmpInfoLog.doInsert();
    }


    
while select * from tmpInfoLog
    order by seq
    
{
        splitStr 
= '';
        
for(i=1;i<=tmpInfolog.ConIdx;i++)
        
{

            splitStr 
+= '\t';
        }

        returnValue 
+= splitStr + tmpInfolog.Name;
        returnValue 
+='\n';
    }

    
return returnValue;



}
调用示例:
static void viewBuildExpressTest(Args _args)
{
    InfologData             data;
    
int                     beforeLine,endLine;
    InventJournalTable      inventJournalTable 
= InventJournalTable::find('000079_061');
    InventJournalCheckPost  journalCheckPost   
= InventJournalCheckPost::newPostJournal(inventJournalTable);
    SalesFormLetter         salesFormLetter 
= SalesFormLetter::construct(DocumentStatus::PackingSlip);
    SalesTable              salesTable;
    ;

    select 
* from salesTable
    
where salesTable.SalesId == '00415_036';
    
try
    
{
        beforeLine 
= infolog.line()+1;
        journalCheckPost.run();
        salesFormLetter.update(salesTable);
        endLine     
= infolog.line()+1;
        box::info(Global::viewBuildExpress(infolog.copy(beforeLine,endLine)));

    }

    
catch
    
{
        endLine     
= infolog.line()+1;
        box::info(Global::viewBuildExpress(infolog.copy(beforeLine,endLine)));
    }


}

posted on 2008-04-27 11:43  佛西亚  阅读(1009)  评论(1编辑  收藏  举报