第八章:Developing Applications Using Business Connector
这一章的代码主要演示如何通过Business Connector与Axapta交互
在Dynamics Axapta的客户端安装目录中找到Microsoft.Dynamics.BusinessConnectorNet.dll这个文件,添加到VS.NET的工程中.
1.HelloWorldBC.cs
class
HelloWorldBC
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
static void Main(string[] args)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Axapta ax;
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// Log on to Dynamics AX
ax = new Axapta();
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
try
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
ax.Logon(null, null, null, null);
}
catch (Exception)
![ExpandedSubBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Console.WriteLine("Exception occurred during logon");
}
Console.WriteLine("Hello World!");
// Log off from Dynamics AX
ax.Logoff();
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
}
好久没用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
"
);
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
//
Loop through the returned records
//
Extract the data from two fields for each record
while
(axRecord.Found)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
invItemName = axRecord.get_Field(invItemNameField);
invItemId = axRecord.get_Field(invItemIdField);
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
Console.WriteLine(invItemId + "\t" + invItemName);
![InBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// 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
"
);
![None.gif](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
//
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写得确实不甘恭维......