Inside Dynamics Axapta源代码赏析(四)
生活随笔
收集整理的這篇文章主要介紹了
Inside Dynamics Axapta源代码赏析(四)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
第八章:Developing Applications Using Business Connector
這一章的代碼主要演示如何通過Business Connector與Axapta交互
在Dynamics Axapta的客戶端安裝目錄中找到Microsoft.Dynamics.BusinessConnectorNet.dll這個文件,添加到VS.NET的工程中.
1.HelloWorldBC.cs
class?HelloWorldBC
????{
????????static?void?Main(string[]?args)
????????{
????????????Axapta?ax;
????????????//?Log?on?to?Dynamics?AX
????????????ax?=?new?Axapta();
????????????try
????????????{
????????????????ax.Logon(null,?null,?null,?null);
????????????}
????????????catch?(Exception)
????????????{
????????????????Console.WriteLine("Exception?occurred?during?logon");
????????????}
????????????
????????????Console.WriteLine("Hello?World!");
????????????
????????????//?Log?off?from?Dynamics?AX
????????????ax.Logoff();
????????}
????} 好久沒用VS2005了,今天用了一下,智能提示忒爽了,Axapta編輯器也快點好起來吧......
搞不清楚四個參數都填null是怎么找到AOS的?本來想用Reflector反編譯一下Microsoft.Dynamics.BusinessConnectorNet.dll,結果出來的是亂七八糟的東西,唉,忒不友好了......
2.AccessingDataBC.cs
遍歷所有的料品,并打印料品Id和料品名稱.
?//?Instantiate?a?Dynamics?AX?record?object?for?the?
????????????//?record?we?want?to?work?with
????????????AxaptaRecord?axRecord?=?ax.CreateAxaptaRecord("InventTable");
????????????
????????????//?Execute?a?query?against?the?record?
????????????axRecord.ExecuteStmt("select?*?from?%1");
????????????//?Loop?through?the?returned?records
????????????//?Extract?the?data?from?two?fields?for?each?record
????????????while?(axRecord.Found)
????????????{
????????????????invItemName?=?axRecord.get_Field(invItemNameField);
????????????????invItemId?=?axRecord.get_Field(invItemIdField);
????????????????Console.WriteLine(invItemId?+?"\t"?+?invItemName);
????????????????//?Go?to?the?next?record
????????????????axRecord.Next();
????????????} 3.InvokingBusinessLogicBC.cs
調用Axapta中的靜態方法.
?//?Invoke?the?CallStaticClassMethod?managed?class
????????????????//?Provide?the?X++?class?name?and?method?to?execute
????????????????//?The?return?value?is?placed?into?returnValue
????????????????returnValue?=?ax.CallStaticClassMethod("InventoryManager",
????????????????????????????"updateInventoryQty");
????????????????//?Use?the?return?value?to?take?some?action
????????????????if((Boolean)returnValue)
????????????????????Console.WriteLine("Inventory?quantity?updated?successfully");
????????????????else
????????????????????Console.WriteLine("Inventory?quantity?update?failed");
這一章的代碼主要演示如何通過Business Connector與Axapta交互
在Dynamics Axapta的客戶端安裝目錄中找到Microsoft.Dynamics.BusinessConnectorNet.dll這個文件,添加到VS.NET的工程中.
1.HelloWorldBC.cs
class?HelloWorldBC
????{
????????static?void?Main(string[]?args)
????????{
????????????Axapta?ax;
????????????//?Log?on?to?Dynamics?AX
????????????ax?=?new?Axapta();
????????????try
????????????{
????????????????ax.Logon(null,?null,?null,?null);
????????????}
????????????catch?(Exception)
????????????{
????????????????Console.WriteLine("Exception?occurred?during?logon");
????????????}
????????????
????????????Console.WriteLine("Hello?World!");
????????????
????????????//?Log?off?from?Dynamics?AX
????????????ax.Logoff();
????????}
????} 好久沒用VS2005了,今天用了一下,智能提示忒爽了,Axapta編輯器也快點好起來吧......
搞不清楚四個參數都填null是怎么找到AOS的?本來想用Reflector反編譯一下Microsoft.Dynamics.BusinessConnectorNet.dll,結果出來的是亂七八糟的東西,唉,忒不友好了......
2.AccessingDataBC.cs
遍歷所有的料品,并打印料品Id和料品名稱.
?//?Instantiate?a?Dynamics?AX?record?object?for?the?
????????????//?record?we?want?to?work?with
????????????AxaptaRecord?axRecord?=?ax.CreateAxaptaRecord("InventTable");
????????????
????????????//?Execute?a?query?against?the?record?
????????????axRecord.ExecuteStmt("select?*?from?%1");
????????????//?Loop?through?the?returned?records
????????????//?Extract?the?data?from?two?fields?for?each?record
????????????while?(axRecord.Found)
????????????{
????????????????invItemName?=?axRecord.get_Field(invItemNameField);
????????????????invItemId?=?axRecord.get_Field(invItemIdField);
????????????????Console.WriteLine(invItemId?+?"\t"?+?invItemName);
????????????????//?Go?to?the?next?record
????????????????axRecord.Next();
????????????} 3.InvokingBusinessLogicBC.cs
調用Axapta中的靜態方法.
?//?Invoke?the?CallStaticClassMethod?managed?class
????????????????//?Provide?the?X++?class?name?and?method?to?execute
????????????????//?The?return?value?is?placed?into?returnValue
????????????????returnValue?=?ax.CallStaticClassMethod("InventoryManager",
????????????????????????????"updateInventoryQty");
????????????????//?Use?the?return?value?to?take?some?action
????????????????if((Boolean)returnValue)
????????????????????Console.WriteLine("Inventory?quantity?updated?successfully");
????????????????else
????????????????????Console.WriteLine("Inventory?quantity?update?failed");
其中的類InventoryManager在工程InsideDynamicsAXChapter8中定義.
這些連接和簡單的操作倒還可以,不過Axapta的接口和SDK寫得確實不甘恭維......
轉載于:https://www.cnblogs.com/Farseer1215/archive/2006/09/26/515255.html
總結
以上是生活随笔為你收集整理的Inside Dynamics Axapta源代码赏析(四)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 做了输卵管造影一般多久后可以要孩子?
- 下一篇: Google 代码搜索