TransactionTxt浅析

为什么要用TransactionTxt这个东西?
没找到官方的文档,按照我的理解的话,之所以要用这个TransactionTxt是为了弥补数据集的不完备,或者说有些物理表之间根本就不应该存在关联,但是有时候用户又想看到一些信息,好象越说越乱了,呵呵.
举个例子我们知道所有的交易最终过帐产生凭证的记录都会记录在LedgerTrans表中,从表的设计角度来说,LedgerTrans应该只记录凭证号,过帐科目,过帐金额等信息就可以了,没有必要记录客户信息,因为只关乎科目.但是有时候用户想看到是与哪家客户的何种交易产生了这张凭证,而对于销售模块来说,这些信息记录在CustInvoiceJournal和CustInvoiceTrans这两张表中,当然LedgerTrans和CustInvoiceJournal可以通过凭证号和发票日期进行关联,但LedgerTrans是所有类型的交易过帐后的集大成者,税额,项目,采购,生产等所有的过帐记录都会体现在LedgerTrans中,如果查询分别跟这些模块中的表进行关联,不是不可能而是太累了......仅仅想知道一个客户或者供应商的代码用得着这么大动干戈吗?当然用不着.TransactionTxt就是解决这个问题的.
怎么玩?
在数据层Axapta提供了一个存储TransactionTxt的表TransactionTxt,一个枚举类型LedgerTransactionTxt
在表现层Axapta提供了一个Form用于编辑表TransactionTxt中的记录.
另外还提供了一个类TransactionTxt用于动态生成Txt文本.
Basic->Setup->TransactionTxt这个窗体用于编辑TransactionTxt中的记录.
如果在Text这一栏点击快捷菜单中的What's this会给出一个提示,说%1,%2,%3是系统用了的,%4-%6可以供大家自己尽情享用.怎么感觉这么悬乎?%1这样的东西感觉像strFm这函数中的占位符,其实稍微看一下TransActionTxt这个类中的Txt方法,确实是占位符.
return strFmt(txt, transDate,formLetterNum,voucherNum,key1,key2,key3);
看到这一句就明白了,transData,formLetterNum......都是TransActionTxt的属性,只不过前三个是固定类型的,而后三个没有指定是普通的str 20.
如果还觉得不明白,就看一下销售订单是怎么用TransactionTxt的吧.
SalesFormLetter_Invoice中的UpdateNow方法
 transactionTxt = this.initTransactionTxt(creditNote  ? LedgerTransTxt::SalesCreditNoteLedger :
                                                           LedgerTransTxt::SalesInvoiceLedger);
    
this.initLedgerVoucher(transactionTxt);
其中的initTransactionTxt方法如下
protected TransactionTxt initTransactionTxt(LedgerTransTxt  ledgerTransTxt)
{
    TransactionTxt  transactionTxt;
    ;
    transactionTxt 
= new TransactionTxt();
    transactionTxt.setType          (ledgerTransTxt);
    transactionTxt.setLanguage      (custInvoiceJour.languageId);
    transactionTxt.setVoucher       (custInvoiceJour.ledgerVoucher);
    transactionTxt.setFormLetter    (custInvoiceJour.invoiceId);
    transactionTxt.setKey1          (custInvoiceJour.salesId);
    transactionTxt.setKey2          (custInvoiceJour.invoiceAccount);
    transactionTxt.setKey3          (CustTable::groupId(custInvoiceJour.invoiceAccount));

    
return transactionTxt;
}
从上面的代码可以看出%4-%6依次被赋值为销售订单单号,发票客户代码及其所在的客户组,当然可以按照自己的需要自定义这些值,其实由这里也可以看出%1-%3也可以自己随便玩的,而不是帮助里所说的不能易主,如果后三个实在不够用也可以打前三个的主意,如果六个还不够用,那就继承一下TransactionTxt吧,想弄多少都行,呵呵.不过一般好象没那么变态的需求,需要那么多信息......
原文地址:https://www.cnblogs.com/Farseer1215/p/526705.html