.NET 中使用 Business Connector --------Dynamics AX
Axapta ax; AxaptaRecord custtable; AxaptaObject query; AxaptaObject queryrun; AxaptaObject querybuilddatasource; AxaptaObject querybuildrange; //--------------------------------- // 登录 ax = new Axapta(); ax.Logon("", "", "", ""); //--------------------------------- //--------------------------------- // 创建query对象和数据源 query = ax.CreateAxaptaObject("Query"); querybuilddatasource = query.Call("AddDataSource", 77) as AxaptaObject; // CustTable的 tableId = 77 querybuildrange = querybuilddatasource.Call("AddRange", 1) as AxaptaObject; // AccountNum的 fieldId = 1 querybuildrange.Call("value", "4000"); //查找 AccountNum=4000 //--------------------------------- //--------------------------------- // 执行query queryrun = ax.CreateAxaptaObject("QueryRun", query) as AxaptaObject; queryrun.Call("prompt"); queryrun.Call("next"); //--------------------------------- //--------------------------------- // 获取结果 custtable = queryrun.Call("getNo", 1) as AxaptaRecord; MessageBox.Show((string)custtable.get_Field("Name")); //--------------------------------- //--------------------------------- //注销 ax.Logoff(); //---------------------------------
需要添加引用 Microsoft.Dynamics.BusinessConnectorNet 简单的:
Axapta ax; AxaptaRecord custtable; AxaptaObject connTest; //--------------------------------- // 登录 ax = new Axapta(); ax.Logon("", "", "", ""); //--------------------------------- //--------------------------------- // 创建一个ax类对象的实例 connTest = ax.CreateAxaptaObject("ConnTest"); // 执行方法 getCust custtable = connTest.Call("getCust", "4000") as AxaptaRecord; MessageBox.Show((string)custtable.get_Field("Name")); //--------------------------------- //--------------------------------- // 注销 ax.Logoff(); //---------------------------------
ax中代码:
class ConnTest { } public CustTable getCust(str _custAccount) { Query q; QueryRun qr; QueryBuildDataSource qbds; QueryBuildRange qrange; TableId _tableId; CustTable _custtable; ; _tableId = tablename2id("CustTable"); q = new Query(); qbds = q.addDataSource(_tableId); qrange = qbds.addRange(fieldname2id(_tableId, "AccountNum")); qrange.value(_custAccount); qr = new QueryRun(q); qr.interactive(false); qr.prompt(); if (qr.next()) _custtable = qr.getNo(1); return _custtable; }