SapApi.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Data;
  5. using Dongke.IBOSS.PRD.Basics.Library;
  6. using SAP.Middleware.Connector;
  7. /// <summary>
  8. /// SapApi
  9. /// </summary>
  10. public class SapApi
  11. {
  12. //SAP服务器配置参数
  13. public static INIUtility ini = INIUtility.Instance(INIUtility.IniFile.SAP_HEGII);
  14. public static string appServerHost = ini.ReadIniData("SAP_RFC_INFO", "SapAppServerHost");
  15. public static string systemNumber = ini.ReadIniData("SAP_RFC_INFO", "SapSystemNumber");
  16. public static string user = ini.ReadIniData("SAP_RFC_INFO", "SapUser");
  17. public static string password = ini.ReadIniData("SAP_RFC_INFO", "SapPassword");
  18. public static string client = ini.ReadIniData("SAP_RFC_INFO", "SapClient");
  19. /// <summary>
  20. /// 读取库存单价接口(获取库存数量)
  21. /// </summary>
  22. /// <param name="WERKS">工厂代号</param>
  23. /// <param name="MATNR">物料编号</param>
  24. /// <param name="LGORT">库存地点</param>
  25. /// <param name="ZTYPE">消息类型: S 成功,E 错误,W 警告,I 信息,A 中断</param>
  26. /// <param name="ZMSG">消息文本</param>
  27. /// <returns></returns>
  28. public static DataTable ZMMFM037(string WERKS, List<string> matnrs, string LGORT, out string ZTYPE, out string ZMSG)
  29. {
  30. RfcConfigParameters rfcPara = new RfcConfigParameters();
  31. rfcPara.Add(RfcConfigParameters.AppServerHost, appServerHost);
  32. rfcPara.Add(RfcConfigParameters.SystemNumber, systemNumber);
  33. rfcPara.Add(RfcConfigParameters.User, user);
  34. rfcPara.Add(RfcConfigParameters.Password, password);
  35. rfcPara.Add(RfcConfigParameters.Client, client);
  36. rfcPara.Add(RfcConfigParameters.Name, "CON");
  37. rfcPara.Add(RfcConfigParameters.Language, "ZH");
  38. rfcPara.Add(RfcConfigParameters.PoolSize, "5");
  39. rfcPara.Add(RfcConfigParameters.ConnectionIdleTimeout, "60");
  40. RfcDestination rfcDest = RfcDestinationManager.GetDestination(rfcPara);
  41. RfcRepository rfcRep = rfcDest.Repository;
  42. //接口API
  43. IRfcFunction rfcApi = rfcRep.CreateFunction("ZMMFM037");
  44. //输入参数
  45. IRfcTable imTable = rfcApi.GetTable("TAB_IN");
  46. foreach (string MATNR in matnrs)
  47. {
  48. imTable.Append();
  49. imTable.SetValue("WERKS", WERKS);
  50. imTable.SetValue("MATNR", MATNR);
  51. imTable.SetValue("LGORT", LGORT);
  52. }
  53. //调用接口
  54. rfcApi.Invoke(rfcDest);
  55. //获取输出
  56. ZTYPE = rfcApi.GetValue("ZTYPE").ToString();
  57. ZMSG = rfcApi.GetValue("ZMSG").ToString();
  58. IRfcTable table = rfcApi.GetTable("TAB_OUT");
  59. DataTable dt = GetDataTableFromRFCTable(table);
  60. //string[] columns = new string[] { "WERKS", "MATNR", "MEINS", "VBELN", "POSNR", "CHARG", "LGORT", "MENGE", "VERPR", "WAERS" };
  61. //DataTable dt = new DataTable();
  62. //foreach (string clmn in columns)
  63. //{
  64. // dt.Columns.Add(clmn);
  65. //}
  66. //for (int i = 0; i < table.RowCount; i++)
  67. //{
  68. // DataRow dr = dt.NewRow();
  69. // foreach (string clmn in columns)
  70. // {
  71. // dr[clmn] = table.GetString(clmn);
  72. // }
  73. // dt.Rows.Add(dr);
  74. //}
  75. rfcDest = null;
  76. rfcRep = null;
  77. return dt;
  78. }
  79. /// <summary>
  80. /// 读取库存单价接口(获取库存数量)
  81. /// </summary>
  82. /// <param name="WERKS">工厂代号</param>
  83. /// <param name="MATNR">物料编号</param>
  84. /// <param name="LGORT">库存地点</param>
  85. /// <param name="ZMSG">消息文本</param>
  86. /// <returns></returns>
  87. public static DataTable ZMM_WMS016(string WERKS, List<string> matnrs, string LGORT, out string ZMSG)
  88. {
  89. RfcConfigParameters rfcPara = new RfcConfigParameters();
  90. rfcPara.Add(RfcConfigParameters.AppServerHost, appServerHost);
  91. rfcPara.Add(RfcConfigParameters.SystemNumber, systemNumber);
  92. rfcPara.Add(RfcConfigParameters.User, user);
  93. rfcPara.Add(RfcConfigParameters.Password, password);
  94. rfcPara.Add(RfcConfigParameters.Client, client);
  95. rfcPara.Add(RfcConfigParameters.Name, "CON");
  96. rfcPara.Add(RfcConfigParameters.Language, "ZH");
  97. rfcPara.Add(RfcConfigParameters.PoolSize, "5");
  98. rfcPara.Add(RfcConfigParameters.ConnectionIdleTimeout, "60");
  99. RfcDestination rfcDest = RfcDestinationManager.GetDestination(rfcPara);
  100. RfcRepository rfcRep = rfcDest.Repository;
  101. //接口API
  102. IRfcFunction rfcApi = rfcRep.CreateFunction("ZMM_WMS016");
  103. //输入参数
  104. IRfcTable imTable = rfcApi.GetTable("IT_INPUT");
  105. if (matnrs != null && matnrs.Count > 0)
  106. {
  107. foreach (string MATNR in matnrs)
  108. {
  109. imTable.Append();
  110. imTable.SetValue("WERKS", WERKS);
  111. imTable.SetValue("MATNR", MATNR);
  112. imTable.SetValue("LGORT", LGORT);
  113. }
  114. }
  115. else
  116. {
  117. imTable.Append();
  118. imTable.SetValue("WERKS", WERKS);
  119. imTable.SetValue("MATNR", "");
  120. imTable.SetValue("LGORT", LGORT);
  121. }
  122. //调用接口
  123. rfcApi.Invoke(rfcDest);
  124. //获取输出
  125. ZMSG = rfcApi.GetValue("E_MSG").ToString();
  126. IRfcTable table = rfcApi.GetTable("IT_OUTPUT");
  127. DataTable dt = GetDataTableFromRFCTable(table);
  128. rfcDest = null;
  129. rfcRep = null;
  130. return dt;
  131. }
  132. /// <summary>
  133. /// 物料凭证通用接口
  134. /// </summary>
  135. /// <param name="list">数据</param>
  136. /// <param name="ZMSG">消息文本</param>
  137. /// <returns></returns>
  138. public static DataTable ZMMFM_MES_YCDB(List<SendSendOutGoods> list, out string ZMSG)
  139. {
  140. RfcConfigParameters rfcPara = new RfcConfigParameters();
  141. rfcPara.Add(RfcConfigParameters.AppServerHost, appServerHost);
  142. rfcPara.Add(RfcConfigParameters.SystemNumber, systemNumber);
  143. rfcPara.Add(RfcConfigParameters.User, user);
  144. rfcPara.Add(RfcConfigParameters.Password, password);
  145. rfcPara.Add(RfcConfigParameters.Client, client);
  146. rfcPara.Add(RfcConfigParameters.Name, "CON");
  147. rfcPara.Add(RfcConfigParameters.Language, "ZH");
  148. rfcPara.Add(RfcConfigParameters.PoolSize, "5");
  149. rfcPara.Add(RfcConfigParameters.ConnectionIdleTimeout, "60");
  150. RfcDestination rfcDest = RfcDestinationManager.GetDestination(rfcPara);
  151. RfcRepository rfcRep = rfcDest.Repository;
  152. //接口API
  153. IRfcFunction rfcApi = rfcRep.CreateFunction("ZMMFM_MES_YCDB");
  154. //输入参数
  155. IRfcTable imTable = rfcApi.GetTable("GT_INPUT");
  156. if (list != null && list.Count > 0)
  157. {
  158. foreach (SendSendOutGoods ss in list)
  159. {
  160. imTable.Append();
  161. imTable.SetValue("WERKS", ss.WERKS);
  162. imTable.SetValue("MATNR", ss.MATNR);
  163. imTable.SetValue("LGORT", ss.LGORT);
  164. imTable.SetValue("MESNO", ss.MESNO);
  165. imTable.SetValue("MESLINENO", ss.MESLINENO);
  166. imTable.SetValue("ZID", ss.ZID);
  167. imTable.SetValue("BUDAT", ss.BUDAT);
  168. imTable.SetValue("BWART", ss.BWART);
  169. imTable.SetValue("PSMNG", ss.PSMNG);
  170. imTable.SetValue("MEINS", ss.MEINS);
  171. imTable.SetValue("MOVE_MAT", ss.MOVE_MAT);
  172. imTable.SetValue("MOVE_STLOC", ss.MOVE_STLOC);
  173. imTable.SetValue("MOVE_BATCH", ss.MOVE_BATCH);
  174. imTable.SetValue("CHARG", ss.CHARG);
  175. imTable.SetValue("CARID", ss.CARID);
  176. }
  177. }
  178. //调用接口
  179. rfcApi.Invoke(rfcDest);
  180. ZMSG = "";
  181. //获取输出
  182. // ZMSG = rfcApi.GetValue("E_MSG").ToString();
  183. IRfcTable table = rfcApi.GetTable("GT_OUTPUT");
  184. DataTable dt = GetDataTableFromRFCTable(table);
  185. rfcDest = null;
  186. rfcRep = null;
  187. return dt;
  188. }
  189. public class SendSendOutGoods
  190. {
  191. public string MESNO;
  192. public string MESLINENO;
  193. public string ZID;
  194. public string BUDAT;
  195. public string HEADER_TXT;
  196. public string BWART;
  197. public string SOBKZ;
  198. public string MOVE_REAS;
  199. public string WERKS;
  200. public string MATNR;
  201. public int PSMNG;
  202. public string MEINS;
  203. public string LGORT;
  204. public string CHARG;
  205. public string KDAUF;
  206. public int KDPOS;
  207. public string MOVE_MAT;
  208. public string MOVE_STLOC;
  209. public string MOVE_BATCH;
  210. public string VAL_SALES_ORD;
  211. public int VAL_S_ORD_ITEM;
  212. public string CARID;
  213. }
  214. /// <summary>
  215. /// 读取库存单价接口(获取库存数量)
  216. /// </summary>
  217. /// <param name="WERKS">工厂代号</param>
  218. /// <param name="LGORT">库存地点</param>
  219. /// <param name="ZMSG">消息文本</param>
  220. /// <returns></returns>
  221. public static DataTable ZMM_WMS016(string WERKS, DataTable dtInventory, out string ZMSG)
  222. {
  223. RfcConfigParameters rfcPara = new RfcConfigParameters();
  224. rfcPara.Add(RfcConfigParameters.AppServerHost, appServerHost);
  225. rfcPara.Add(RfcConfigParameters.SystemNumber, systemNumber);
  226. rfcPara.Add(RfcConfigParameters.User, user);
  227. rfcPara.Add(RfcConfigParameters.Password, password);
  228. rfcPara.Add(RfcConfigParameters.Client, client);
  229. rfcPara.Add(RfcConfigParameters.Name, "CON");
  230. rfcPara.Add(RfcConfigParameters.Language, "ZH");
  231. rfcPara.Add(RfcConfigParameters.PoolSize, "5");
  232. rfcPara.Add(RfcConfigParameters.ConnectionIdleTimeout, "60");
  233. RfcDestination rfcDest = RfcDestinationManager.GetDestination(rfcPara);
  234. RfcRepository rfcRep = rfcDest.Repository;
  235. //接口API
  236. IRfcFunction rfcApi = rfcRep.CreateFunction("ZMM_WMS016");
  237. //输入参数
  238. IRfcTable imTable = rfcApi.GetTable("IT_INPUT");
  239. foreach (DataRow row in dtInventory.Rows)
  240. {
  241. imTable.Append();
  242. imTable.SetValue("WERKS", WERKS);
  243. imTable.SetValue("MATNR", row["IDNRK"]);
  244. imTable.SetValue("LGORT", row["POSITION"]);
  245. }
  246. //调用接口
  247. rfcApi.Invoke(rfcDest);
  248. //获取输出
  249. ZMSG = rfcApi.GetValue("E_MSG").ToString();
  250. IRfcTable table = rfcApi.GetTable("IT_OUTPUT");
  251. DataTable dt = GetDataTableFromRFCTable(table);
  252. rfcDest = null;
  253. rfcRep = null;
  254. return dt;
  255. }
  256. /// <summary>
  257. /// 查询PO的相关信息(获取订单达成数量)
  258. /// </summary>
  259. /// <param name="IN_EBELN">采购凭证号</param>
  260. /// <param name="ZTYPE">消息类型: S 成功,E 错误,W 警告,I 信息,A 中断</param>
  261. /// <param name="ZMSG">消息文本</param>
  262. /// <returns></returns>
  263. public static DataTable ZMMFM_MES_POCX(string IN_EBELN, out string ZTYPE, out string ZMSG)
  264. {
  265. RfcConfigParameters rfcPara = new RfcConfigParameters();
  266. rfcPara.Add(RfcConfigParameters.AppServerHost, appServerHost);
  267. rfcPara.Add(RfcConfigParameters.SystemNumber, systemNumber);
  268. rfcPara.Add(RfcConfigParameters.User, user);
  269. rfcPara.Add(RfcConfigParameters.Password, password);
  270. rfcPara.Add(RfcConfigParameters.Client, client);
  271. rfcPara.Add(RfcConfigParameters.Name, "CON");
  272. rfcPara.Add(RfcConfigParameters.Language, "ZH");
  273. rfcPara.Add(RfcConfigParameters.PoolSize, "5");
  274. rfcPara.Add(RfcConfigParameters.ConnectionIdleTimeout, "60");
  275. RfcDestination rfcDest = RfcDestinationManager.GetDestination(rfcPara);
  276. RfcRepository rfcRep = rfcDest.Repository;
  277. //接口API
  278. IRfcFunction rfcApi = rfcRep.CreateFunction("ZMMFM_MES_POCX");
  279. //输入参数
  280. rfcApi.SetValue("IN_EKORG", 1000);
  281. rfcApi.SetValue("IN_EBELN", IN_EBELN);
  282. rfcApi.SetValue("IN_AEDAT_FROM", "20220101");
  283. rfcApi.SetValue("IN_AEDAT_TO", "20301231");
  284. //调用接口
  285. rfcApi.Invoke(rfcDest);
  286. //获取输出
  287. ZTYPE = rfcApi.GetValue("ZTYPE").ToString();
  288. ZMSG = rfcApi.GetValue("ZMSG").ToString();
  289. IRfcTable table = rfcApi.GetTable("GT_OUT");
  290. //EBELN 采购凭证编号
  291. //EBELP 采购凭证的项目编号
  292. //MENGE 采购订单数量
  293. //MEINS 订单计量单位
  294. //ZYSSL 已收/ 退数量数量
  295. //ZWSSL 未收/ 退数量
  296. //ELIKZ 交货已完成标识
  297. //LIFNR 供应商编码
  298. //EKGRP 采购组
  299. //MATNR 物料编码
  300. //string[] columns = new string[] { "EBELN", "EBELP", "MENGE", "MEINS", "ZYSSL", "ZWSSL", "ELIKZ", "LIFNR", "EKGRP", "MATNR" };
  301. DataTable dt = GetDataTableFromRFCTable(table);
  302. //foreach (string clmn in columns)
  303. //{
  304. // dt.Columns.Add(clmn);
  305. //}
  306. //for (int i = 0; i < table.RowCount; i++)
  307. //{
  308. // DataRow dr = dt.NewRow();
  309. // foreach (string clmn in columns)
  310. // {
  311. // dr[clmn] = table.ro.GetString(clmn);
  312. // }
  313. // dt.Rows.Add(dr);
  314. //}
  315. rfcDest = null;
  316. rfcRep = null;
  317. return dt;
  318. }
  319. /// <summary>
  320. /// 物料主数据接口(同步最小包装数用)
  321. /// </summary>
  322. /// <param name="MBLNR">物料凭证编号</param>
  323. /// <param name="createTime">创建时间</param>
  324. /// <param name="ZTYPE">消息类型: S 成功,E 错误,W 警告,I 信息,A 中断</param>
  325. /// <param name="ZMSG">消息文本</param>
  326. /// <returns></returns>
  327. public static DataTable ZMMFM054(out string ZTYPE, out string ZMSG)
  328. {
  329. RfcConfigParameters rfcPara = new RfcConfigParameters();
  330. rfcPara.Add(RfcConfigParameters.AppServerHost, appServerHost);
  331. rfcPara.Add(RfcConfigParameters.SystemNumber, systemNumber);
  332. rfcPara.Add(RfcConfigParameters.User, user);
  333. rfcPara.Add(RfcConfigParameters.Password, password);
  334. rfcPara.Add(RfcConfigParameters.Client, client);
  335. rfcPara.Add(RfcConfigParameters.Name, "CON");
  336. rfcPara.Add(RfcConfigParameters.Language, "ZH");
  337. rfcPara.Add(RfcConfigParameters.PoolSize, "5");
  338. rfcPara.Add(RfcConfigParameters.ConnectionIdleTimeout, "60");
  339. RfcDestination rfcDest = RfcDestinationManager.GetDestination(rfcPara);
  340. RfcRepository rfcRep = rfcDest.Repository;
  341. //接口API
  342. IRfcFunction rfcApi = rfcRep.CreateFunction("ZMMFM054");
  343. //输入参数
  344. rfcApi.SetValue("IN_ALL", 'Y');
  345. rfcApi.SetValue("IN_WERKS", 5020);
  346. //调用接口
  347. rfcApi.Invoke(rfcDest);
  348. //获取输出
  349. ZTYPE = rfcApi.GetValue("ZTYPE").ToString();
  350. ZMSG = rfcApi.GetValue("ZMSG").ToString();
  351. IRfcTable table = rfcApi.GetTable("OUT_TABLE");
  352. DataTable dt = GetDataTableFromRFCTable(table);
  353. rfcDest = null;
  354. rfcRep = null;
  355. return dt;
  356. }
  357. /// <summary>
  358. /// 东科与SAP系统之线边仓库存领用接口(库存过账)
  359. /// </summary>
  360. /// <param name="BLDAT">过帐日期</param>
  361. /// <param name="ZDKNO">东科单据号</param>
  362. /// <param name="ZTYPE">消息类型: S 成功,E 错误,W 警告,I 信息,A 中断</param>
  363. /// <param name="ZMSG">消息文本</param>
  364. /// <returns></returns>
  365. public static DataTable ZMMFM045(string BLDAT, string ZDKNO, DataTable dtTable, out string ZTYPE, out string ZMSG)
  366. {
  367. RfcConfigParameters rfcPara = new RfcConfigParameters();
  368. rfcPara.Add(RfcConfigParameters.AppServerHost, appServerHost);
  369. rfcPara.Add(RfcConfigParameters.SystemNumber, systemNumber);
  370. rfcPara.Add(RfcConfigParameters.User, user);
  371. rfcPara.Add(RfcConfigParameters.Password, password);
  372. rfcPara.Add(RfcConfigParameters.Client, client);
  373. rfcPara.Add(RfcConfigParameters.Name, "CON");
  374. rfcPara.Add(RfcConfigParameters.Language, "ZH");
  375. rfcPara.Add(RfcConfigParameters.PoolSize, "5");
  376. rfcPara.Add(RfcConfigParameters.ConnectionIdleTimeout, "60");
  377. RfcDestination rfcDest = RfcDestinationManager.GetDestination(rfcPara);
  378. RfcRepository rfcRep = rfcDest.Repository;
  379. //接口API
  380. IRfcFunction rfcApi = rfcRep.CreateFunction("ZMMFM045");
  381. //BLDAT DATS 8 0 必填 凭证日期 格式: yyyymmdd
  382. //BUDAT DATS 8 0 必填 过帐日期 格式: yyyymmdd
  383. //WERKS CHAR 4 0 必填 工厂 5020
  384. //LGORT_FM CHAR 4 0 必填 发出库位
  385. //LGORT_TO CHAR 4 0 必填 接收库位
  386. //MATNR CHAR 40 0 必填 物料编号
  387. //BWART CHAR 3 0 必填 移动类型(库存管理) 目前只允许填:311
  388. //MEINS UNIT 3 0 必填 基本计量单位
  389. //MENGE QUAN 13 3 必填 数量
  390. //ZDKNO CHAR 40 0 必填 东科单据号
  391. //输入参数
  392. IRfcTable imTable = rfcApi.GetTable("IT_ITEM");
  393. foreach (DataRow dr in dtTable.Rows)
  394. {
  395. imTable.Append();
  396. imTable.SetValue("BLDAT", BLDAT);
  397. imTable.SetValue("BUDAT", BLDAT);
  398. imTable.SetValue("WERKS", "5000");
  399. imTable.SetValue("LGORT_FM", dr["LGORT_FM"]);
  400. imTable.SetValue("LGORT_TO", dr["TOLOGT"]);
  401. imTable.SetValue("MATNR", dr["MATNR"]);
  402. imTable.SetValue("CHARG", dr["CHARG"] + "");
  403. imTable.SetValue("BWART", "311");
  404. imTable.SetValue("MEINS", dr["MEINS"]);
  405. imTable.SetValue("MENGE", dr["MENGE"]);
  406. imTable.SetValue("ZDKNO", ZDKNO);
  407. }
  408. //调用接口
  409. rfcApi.Invoke(rfcDest);
  410. //获取输出
  411. ZTYPE = rfcApi.GetValue("ZTYPE").ToString();
  412. ZMSG = rfcApi.GetValue("ZMSG").ToString();
  413. IRfcTable table = rfcApi.GetTable("ET_RETURN");
  414. DataTable dt = GetDataTableFromRFCTable(table);
  415. //string[] columns = new string[] { "BLDAT", "WERKS", "MBLNR", "MJAHR", "MSGTY", "MSGTX" };
  416. //DataTable dt = new DataTable();
  417. //foreach (string clmn in columns)
  418. //{
  419. // dt.Columns.Add(clmn);
  420. //}
  421. //for (int i = 0; i < table.RowCount; i++)
  422. //{
  423. // DataRow dr = dt.NewRow();
  424. // foreach (string clmn in columns)
  425. // {
  426. // dr[clmn] = table.GetString(clmn);
  427. // }
  428. // dt.Rows.Add(dr);
  429. //}
  430. rfcDest = null;
  431. rfcRep = null;
  432. return dt;
  433. }
  434. /// <summary>
  435. /// 冲销凭证接口(撤销过账)
  436. /// </summary>
  437. /// <param name="MBLNR">物料凭证编号</param>
  438. /// <param name="createTime">创建时间</param>
  439. /// <param name="ZTYPE">消息类型: S 成功,E 错误,W 警告,I 信息,A 中断</param>
  440. /// <param name="ZMSG">消息文本</param>
  441. /// <returns></returns>
  442. public static void ZMMFM038(string MBLNR, DateTime createTime, out string ZTYPE, out string ZMSG)
  443. {
  444. RfcConfigParameters rfcPara = new RfcConfigParameters();
  445. rfcPara.Add(RfcConfigParameters.AppServerHost, appServerHost);
  446. rfcPara.Add(RfcConfigParameters.SystemNumber, systemNumber);
  447. rfcPara.Add(RfcConfigParameters.User, user);
  448. rfcPara.Add(RfcConfigParameters.Password, password);
  449. rfcPara.Add(RfcConfigParameters.Client, client);
  450. rfcPara.Add(RfcConfigParameters.Name, "CON");
  451. rfcPara.Add(RfcConfigParameters.Language, "ZH");
  452. rfcPara.Add(RfcConfigParameters.PoolSize, "5");
  453. rfcPara.Add(RfcConfigParameters.ConnectionIdleTimeout, "60");
  454. RfcDestination rfcDest = RfcDestinationManager.GetDestination(rfcPara);
  455. RfcRepository rfcRep = rfcDest.Repository;
  456. //接口API
  457. IRfcFunction rfcApi = rfcRep.CreateFunction("ZMMFM038");
  458. //输入参数
  459. rfcApi.SetValue("MBLNR", MBLNR);
  460. rfcApi.SetValue("MJAHR", createTime.ToString("yyyy"));
  461. rfcApi.SetValue("BUDAT", createTime.ToString("yyyyMMdd"));
  462. //调用接口
  463. rfcApi.Invoke(rfcDest);
  464. //获取输出
  465. ZTYPE = rfcApi.GetValue("ZTYPE").ToString();
  466. ZMSG = rfcApi.GetValue("ZMSG").ToString();
  467. rfcDest = null;
  468. rfcRep = null;
  469. }
  470. /// <summary>
  471. /// 测试用,用于把线边仓的货,全挪走
  472. /// </summary>
  473. /// <param name="BLDAT">过帐日期</param>
  474. /// <param name="ZDKNO">东科单据号</param>
  475. /// <param name="ZTYPE">消息类型: S 成功,E 错误,W 警告,I 信息,A 中断</param>
  476. /// <param name="ZMSG">消息文本</param>
  477. /// <returns></returns>
  478. public static DataTable ZMMFM045_TEST(string BLDAT, string ZDKNO, DataTable dtTable, out string ZTYPE, out string ZMSG)
  479. {
  480. RfcConfigParameters rfcPara = new RfcConfigParameters();
  481. rfcPara.Add(RfcConfigParameters.AppServerHost, appServerHost);
  482. rfcPara.Add(RfcConfigParameters.SystemNumber, systemNumber);
  483. rfcPara.Add(RfcConfigParameters.User, user);
  484. rfcPara.Add(RfcConfigParameters.Password, password);
  485. rfcPara.Add(RfcConfigParameters.Client, client);
  486. rfcPara.Add(RfcConfigParameters.Name, "CON");
  487. rfcPara.Add(RfcConfigParameters.Language, "ZH");
  488. rfcPara.Add(RfcConfigParameters.PoolSize, "5");
  489. rfcPara.Add(RfcConfigParameters.ConnectionIdleTimeout, "60");
  490. RfcDestination rfcDest = RfcDestinationManager.GetDestination(rfcPara);
  491. RfcRepository rfcRep = rfcDest.Repository;
  492. //接口API
  493. IRfcFunction rfcApi = rfcRep.CreateFunction("ZMMFM045");
  494. //BLDAT DATS 8 0 必填 凭证日期 格式: yyyymmdd
  495. //BUDAT DATS 8 0 必填 过帐日期 格式: yyyymmdd
  496. //WERKS CHAR 4 0 必填 工厂 5020
  497. //LGORT_FM CHAR 4 0 必填 发出库位
  498. //LGORT_TO CHAR 4 0 必填 接收库位
  499. //MATNR CHAR 40 0 必填 物料编号
  500. //BWART CHAR 3 0 必填 移动类型(库存管理) 目前只允许填:311
  501. //MEINS UNIT 3 0 必填 基本计量单位
  502. //MENGE QUAN 13 3 必填 数量
  503. //ZDKNO CHAR 40 0 必填 东科单据号
  504. //输入参数
  505. IRfcTable imTable = rfcApi.GetTable("IT_ITEM");
  506. foreach (DataRow dr in dtTable.Rows)
  507. {
  508. imTable.Append();
  509. imTable.SetValue("BLDAT", BLDAT);
  510. imTable.SetValue("BUDAT", BLDAT);
  511. imTable.SetValue("WERKS", "5020");
  512. imTable.SetValue("LGORT_FM", "2205");
  513. imTable.SetValue("LGORT_TO", "1103");
  514. imTable.SetValue("MATNR", dr["MATNR"]);
  515. imTable.SetValue("CHARG", dr["CHARG"] + "");
  516. imTable.SetValue("BWART", "311");
  517. imTable.SetValue("MEINS", dr["MEINS"]);
  518. imTable.SetValue("MENGE", dr["MENGE"]);
  519. imTable.SetValue("ZDKNO", ZDKNO);
  520. }
  521. //调用接口
  522. rfcApi.Invoke(rfcDest);
  523. //获取输出
  524. ZTYPE = rfcApi.GetValue("ZTYPE").ToString();
  525. ZMSG = rfcApi.GetValue("ZMSG").ToString();
  526. IRfcTable table = rfcApi.GetTable("ET_RETURN");
  527. DataTable dt = GetDataTableFromRFCTable(table);
  528. rfcDest = null;
  529. rfcRep = null;
  530. return dt;
  531. }
  532. /// <summary>
  533. /// IRfcTable转DataTable
  534. /// </summary>
  535. /// <param name="myrfcTable"></param>
  536. /// <returns></returns>
  537. private static DataTable GetDataTableFromRFCTable(IRfcTable myrfcTable)
  538. {
  539. DataTable loTable = new DataTable();
  540. int liElement = 0;
  541. for (liElement = 0; liElement <= myrfcTable.ElementCount - 1; liElement++)
  542. {
  543. RfcElementMetadata metadata = myrfcTable.GetElementMetadata(liElement);
  544. loTable.Columns.Add(metadata.Name);
  545. }
  546. foreach (IRfcStructure Row in myrfcTable)
  547. {
  548. DataRow ldr = loTable.NewRow();
  549. for (liElement = 0; liElement <= myrfcTable.ElementCount - 1; liElement++)
  550. {
  551. RfcElementMetadata metadata = myrfcTable.GetElementMetadata(liElement);
  552. ldr[metadata.Name] = Row.GetString(metadata.Name);
  553. }
  554. loTable.Rows.Add(ldr);
  555. }
  556. return loTable;
  557. }
  558. }