纽威
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1113 lines
66 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. using NFine.Repository;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Data;
  8. using NFine.Code;
  9. using System.Data.Common;
  10. using NFine.Domain._03_Entity.SRM;
  11. using System.Configuration;
  12. using System.Net;
  13. using Newtonsoft.Json.Linq;
  14. using Newtonsoft.Json;
  15. using System.IO;
  16. using NFine.Domain._03_Entity.WMS;
  17. using NFine.Data.Extensions;
  18. namespace NFine.Application.WMS
  19. {
  20. public class WMSDeleteReceipts : RepositoryFactory<ICSVendor>
  21. {
  22. public int DeleteReceipt(string codes, string type)
  23. {
  24. try
  25. {
  26. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  27. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  28. DateTime MTime = DateTime.Now;
  29. StringBuilder sqlString = new StringBuilder();
  30. #region 工单领料 售后领料
  31. if (type == "2" || type == "12")
  32. {
  33. #region SAP(三层结构)
  34. string IsSuccess = "";
  35. string ErrorMessage = "";
  36. string sql1 = $@"select DISTINCT A.ApplyCode from ICSMOApply A
  37. WHERE A.ApplyCode in({codes})";
  38. DataTable Sapdt1 = Repository().FindDataSetBySql(sql1).Tables[0];
  39. if (Sapdt1.Rows.Count == 0)
  40. {
  41. throw new Exception("单据查询失败");//单据查询失败
  42. }
  43. for (int i = 0; i < Sapdt1.Rows.Count; i++)
  44. {
  45. var code = Sapdt1.Rows[i]["ApplyCode"].ToString();
  46. SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ();
  47. SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1();
  48. Info.NEWID = Guid.NewGuid().ToString();
  49. Info.DANJU = Sapdt1.Rows[i]["ApplyCode"].ToString();
  50. Info.STATE = "0";
  51. string sql = $@"select A.ID,A.ApplyCode,A.InvCode,A.Sequence,A.SAPSequence,A.Quantity,A.IssueQuantity
  52. ,ISNULL(B.BatchCode,'') AS BatchCode,A.WorkPoint,A.WHCode from ICSMOApply A
  53. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  54. WHERE A.ApplyCode ='{code}'";
  55. DataTable Sapdt = Repository().FindDataSetBySql(sql).Tables[0];
  56. if (Sapdt.Rows.Count == 0)
  57. {
  58. throw new Exception("单据查询失败");//单据查询失败
  59. }
  60. List<SAPCallBackDocVPN.ZWMS_PZ> ItemList = new List<SAPCallBackDocVPN.ZWMS_PZ>();
  61. List<SAPCallBackDocVPN.ZWEBS_GERNR> ItemLineList = new List<SAPCallBackDocVPN.ZWEBS_GERNR>();
  62. Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1];
  63. foreach (DataRow dr in Sapdt.Rows)
  64. {
  65. string id = dr["ID"].ToString();
  66. string dnCode = dr["ApplyCode"].ToString();
  67. string invCode = dr["INVCode"].ToString();
  68. string workPoint = dr["WorkPoint"].ToString();
  69. string whCode = dr["WHCode"].ToString();
  70. decimal quantity = dr["Quantity"].ToDecimal();
  71. string sequence = dr["SAPSequence"].ToString();
  72. string batchCode = dr["BatchCode"].ToString();
  73. decimal dnQuantity = dr["IssueQuantity"].ToDecimal();
  74. SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
  75. SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR();
  76. Item.DANJU = dr["ApplyCode"].ToString();
  77. Item.POSNR = dr["SAPSequence"].ToString();
  78. Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["IssueQuantity"].ToString()), 3);
  79. ItemList.Add(Item);
  80. if (dr["BatchCode"].ToString() != "")
  81. {
  82. ItemLine.DANJU = dr["ApplyCode"].ToString();
  83. ItemLine.POSNR = dr["SAPSequence"].ToString();
  84. ItemLine.MATNR = dr["InvCode"].ToString();
  85. ItemLine.GERNR = dr["BatchCode"].ToString();
  86. ItemLineList.Add(ItemLine);
  87. }
  88. if (Convert.ToDecimal(dr["IssueQuantity"].ToString()) != Convert.ToDecimal(dr["Quantity"].ToString())|| Convert.ToDecimal(dr["Quantity"].ToString())==0)
  89. {
  90. sqlString.Append($@"DELETE FROM ICSMOApply WHERE ID='{id}';");
  91. sqlString.Append($@"INSERT INTO ICSDeleteReceiptsLog VALUES(NEWID(),'{dnCode}','{sequence}','2','{workPoint}','{invCode}',{dnQuantity},null,'{MUSER}','{MUSERNAME}','{MTime}');");
  92. }
  93. }
  94. if (ItemList.Count > 0)
  95. {
  96. Info.Z_ITEM = ItemList.ToArray();
  97. if (ItemLineList.Count > 0)
  98. {
  99. Info.Z_GERNR = ItemLineList.ToArray();
  100. }
  101. else
  102. {
  103. Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1];
  104. }
  105. SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse();
  106. result = Client.CallZWMS_SK_WS_PZ(Info);
  107. if (result.Z_NULL == "N")
  108. {
  109. foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG)
  110. {
  111. IsSuccess = "N";
  112. ErrorMessage += resultItem.L_MESSAGE + "/r/n";
  113. }
  114. }
  115. }
  116. }
  117. if (IsSuccess == "N")
  118. {
  119. throw new Exception(ErrorMessage);
  120. }
  121. #endregion
  122. if (sqlString.IsEmpty())
  123. {
  124. return 0;
  125. }
  126. int count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString());
  127. return count;
  128. }
  129. #endregion
  130. #region 委外领料
  131. else if (type == "5")
  132. {
  133. #region SAP(三层结构)
  134. string IsSuccess = "";
  135. string ErrorMessage = "";
  136. string sql1 = $@"select DISTINCT A.ApplyCode from ICSOApply A
  137. WHERE A.ApplyCode in({codes})";
  138. DataTable Sapdt1 = Repository().FindDataSetBySql(sql1).Tables[0];
  139. if (Sapdt1.Rows.Count == 0)
  140. {
  141. throw new Exception("单据查询失败");//单据查询失败
  142. }
  143. for (int i = 0; i < Sapdt1.Rows.Count; i++)
  144. {
  145. var code = Sapdt1.Rows[i]["ApplyCode"].ToString();
  146. string sql = $@" select Distinct A.ApplyCode,A.WorkPoint from ICSOApply A
  147. where A.ApplyCode='{code}'";
  148. DataTable dt = Repository().FindDataSetBySql(sql).Tables[0];
  149. for (int j = 0; j < dt.Rows.Count; j++)
  150. {
  151. string chksql = @"select SUM(Quantity) AS Quantity,SUM(IssueQuantity) AS IssueQuantity from ICSOApply
  152. where ApplyCode='{0}' and WorkPoint='{1}'
  153. GROUP BY ApplyCode,WorkPoint";
  154. chksql = string.Format(chksql, dt.Rows[j]["ApplyCode"].ToString(), dt.Rows[j]["WorkPoint"].ToString());
  155. DataTable chkdt = Repository().FindDataSetBySql(chksql).Tables[0];
  156. SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ();
  157. SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1();
  158. Info.NEWID = Guid.NewGuid().ToString();
  159. Info.DANJU = dt.Rows[j]["ApplyCode"].ToString();
  160. Info.STATE = "0";
  161. List<SAPCallBackDocVPN.ZWMS_PZ> ItemList = new List<SAPCallBackDocVPN.ZWMS_PZ>();
  162. List<SAPCallBackDocVPN.ZWEBS_GERNR> ItemLineList = new List<SAPCallBackDocVPN.ZWEBS_GERNR>();
  163. Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1];
  164. sql = @" select A.ApplyCode,A.SAPSequence,A.InvCode,A.Sequence,A.Quantity,A.IssueQuantity
  165. ,ISNULL(B.BatchCode,'') AS BatchCode,A.ID,A.WorkPoint,A.WHCode from ICSOApply A
  166. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  167. WHERE ApplyCode='{0}' AND A.WorkPoint='{1}'";
  168. sql = string.Format(sql, dt.Rows[j]["ApplyCode"].ToString(), dt.Rows[j]["WorkPoint"].ToString());
  169. DataTable Sapdt = Repository().FindDataSetBySql(sql).Tables[0];
  170. foreach (DataRow dr in Sapdt.Rows)
  171. {
  172. string id = dr["ID"].ToString();
  173. string dnCode = dr["ApplyCode"].ToString();
  174. string invCode = dr["INVCode"].ToString();
  175. string workPoint = dr["WorkPoint"].ToString();
  176. string whCode = dr["WHCode"].ToString();
  177. decimal quantity = dr["Quantity"].ToDecimal();
  178. string sequence = dr["SAPSequence"].ToString();
  179. string batchCode = dr["BatchCode"].ToString();
  180. decimal dnQuantity = dr["IssueQuantity"].ToDecimal();
  181. SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
  182. SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR();
  183. Item.DANJU = dr["ApplyCode"].ToString();
  184. Item.POSNR = dr["SAPSequence"].ToString();
  185. Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["IssueQuantity"].ToString()), 3);
  186. ItemList.Add(Item);
  187. ItemLine.DANJU = dr["ApplyCode"].ToString();
  188. ItemLine.POSNR = dr["SAPSequence"].ToString();
  189. ItemLine.MATNR = dr["InvCode"].ToString();
  190. ItemLine.GERNR = dr["BatchCode"].ToString();
  191. ItemLineList.Add(ItemLine);
  192. if (Convert.ToDecimal(dr["IssueQuantity"].ToString()) != Convert.ToDecimal(dr["Quantity"].ToString())||Convert.ToDecimal(dr["Quantity"].ToString()) == 0)
  193. {
  194. sqlString.Append($@"DELETE FROM ICSOApply WHERE ID='{id}';");
  195. sqlString.Append($@"INSERT INTO ICSDeleteReceiptsLog VALUES(NEWID(),'{dnCode}','{sequence}','5','{workPoint}','{invCode}',{dnQuantity},null,'{MUSER}','{MUSERNAME}','{MTime}');");
  196. }
  197. }
  198. if (ItemList.Count > 0)
  199. {
  200. Info.Z_ITEM = ItemList.ToArray();
  201. if (ItemLineList.Count > 0)
  202. {
  203. Info.Z_GERNR = ItemLineList.ToArray();
  204. }
  205. else
  206. {
  207. Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1];
  208. }
  209. SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse();
  210. result = Client.CallZWMS_SK_WS_PZ(Info);
  211. if (result.Z_NULL == "N")
  212. {
  213. foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG)
  214. {
  215. IsSuccess = "N";
  216. ErrorMessage += resultItem.L_MESSAGE + "/r/n";
  217. }
  218. }
  219. }
  220. }
  221. }
  222. if (IsSuccess == "N")
  223. {
  224. throw new Exception(ErrorMessage);
  225. }
  226. #endregion
  227. if (sqlString.IsEmpty())
  228. {
  229. return 0;
  230. }
  231. int count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString());
  232. return count;
  233. }
  234. #endregion
  235. #region 销售发货
  236. else if (type == "7")
  237. {
  238. string IsSuccess = "";
  239. string ErrorMessage = "";
  240. string sql = $@" select Distinct A.SDNCode,A.WorkPoint from ICSSDN A
  241. where A.SDNCode in ({codes})";
  242. DataTable dt = Repository().FindDataSetBySql(sql).Tables[0];
  243. for (int i = 0; i < dt.Rows.Count; i++)
  244. {
  245. string chksql = @"select SUM(Quantity) AS Quantity,SUM(SDNQuantity) AS SDNQuantity from ICSSDN
  246. where SDNCode='{0}' and WorkPoint='{1}'
  247. GROUP BY SDNCode,WorkPoint";
  248. chksql = string.Format(chksql, dt.Rows[i]["SDNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  249. DataTable chkdt = Repository().FindDataSetBySql(chksql).Tables[0];
  250. SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ Client = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ();
  251. SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ1 Info = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ1();
  252. List<SAPCallBackDispatchVPN.ZWMS_DO_HEAD> headlist = new List<SAPCallBackDispatchVPN.ZWMS_DO_HEAD>();
  253. SAPCallBackDispatchVPN.ZWMS_DO_HEAD head = new SAPCallBackDispatchVPN.ZWMS_DO_HEAD();
  254. head.VBELN = dt.Rows[i]["SDNCode"].ToString();
  255. headlist.Add(head);
  256. Info.T_HEAD = headlist.ToArray();
  257. List<SAPCallBackDispatchVPN.ZWMS_DO_ITEM> ItemList = new List<SAPCallBackDispatchVPN.ZWMS_DO_ITEM>();
  258. List<SAPCallBackDispatchVPN.ZWMS_DO_GERNR> ItemLineList = new List<SAPCallBackDispatchVPN.ZWMS_DO_GERNR>();
  259. Info.T_RETURN = new SAPCallBackDispatchVPN.ZWMS_DO_RETURN[1];
  260. sql = @" select A.ID,A.WorkPoint,A.WHCode, A.SDNCode,A.InvCode,A.SAPSequence,A.Sequence,A.Quantity,A.SDNQuantity
  261. ,ISNULL(B.BatchCode,'') AS BatchCode from ICSSDN A
  262. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  263. WHERE SDNCode='{0}' AND A.WorkPoint='{1}'";
  264. sql = string.Format(sql, dt.Rows[i]["SDNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  265. DataTable Sapdt = Repository().FindDataSetBySql(sql).Tables[0];
  266. foreach (DataRow dr in Sapdt.Rows)
  267. {
  268. string id = dr["ID"].ToString();
  269. string dnCode = dr["SDNCode"].ToString();
  270. string invCode = dr["INVCode"].ToString();
  271. string workPoint = dr["WorkPoint"].ToString();
  272. string whCode = dr["WHCode"].ToString();
  273. decimal quantity = dr["Quantity"].ToDecimal();
  274. string sequence = dr["SAPSequence"].ToString();
  275. string batchCode = dr["BatchCode"].ToString();
  276. decimal dnQuantity = dr["SDNQuantity"].ToDecimal();
  277. SAPCallBackDispatchVPN.ZWMS_DO_GERNR ItemLine = new SAPCallBackDispatchVPN.ZWMS_DO_GERNR();
  278. SAPCallBackDispatchVPN.ZWMS_DO_ITEM Item = new SAPCallBackDispatchVPN.ZWMS_DO_ITEM();
  279. Item.VBELN = dr["SDNCode"].ToString();
  280. Item.POSNR = dr["SAPSequence"].ToString();
  281. Item.LFIMG = System.Decimal.Round(Convert.ToDecimal(dr["SDNQuantity"].ToString()), 3);
  282. ItemList.Add(Item);
  283. if (dr["BatchCode"].ToString() != "")
  284. {
  285. ItemLine.VBELN = dr["SDNCode"].ToString();
  286. ItemLine.POSNR = dr["SAPSequence"].ToString();
  287. ItemLine.GERNR = dr["BatchCode"].ToString();
  288. ItemLineList.Add(ItemLine);
  289. }
  290. if (Convert.ToDecimal(dr["Quantity"].ToString()) != Convert.ToDecimal(dr["SDNQuantity"].ToString()) || Convert.ToDecimal(dr["Quantity"].ToString()) == 0)
  291. {
  292. sqlString.Append($@"DELETE FROM ICSSDN WHERE ID='{id}';");
  293. sqlString.Append($@"INSERT INTO ICSDeleteReceiptsLog VALUES(NEWID(),'{dnCode}','{sequence}','7','{workPoint}','{invCode}',{dnQuantity},null,'{MUSER}','{MUSERNAME}','{MTime}');");
  294. }
  295. }
  296. if (ItemList.Count > 0)
  297. {
  298. Info.T_ITEM = ItemList.ToArray();
  299. if (ItemLineList.Count > 0)
  300. {
  301. Info.T_GERNR = ItemLineList.ToArray();
  302. }
  303. SAPCallBackDispatchVPN.ZWMS_SK_DO_GZResponse result = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZResponse();
  304. result = Client.CallZWMS_SK_DO_GZ(Info);
  305. foreach (SAPCallBackDispatchVPN.ZWMS_DO_RETURN resultItem in result.T_RETURN)
  306. {
  307. if (resultItem.ZFLG == "N")
  308. {
  309. IsSuccess = "N";
  310. ErrorMessage += resultItem.ZMESS + "/r/n";
  311. }
  312. }
  313. }
  314. }
  315. if (IsSuccess == "N")
  316. {
  317. throw new Exception(ErrorMessage);
  318. }
  319. if (sqlString.IsEmpty())
  320. {
  321. return 0;
  322. }
  323. int count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString());
  324. return count;
  325. }
  326. #endregion
  327. #region 其他出库
  328. else if (type == "8")
  329. {
  330. string IsSuccess = "";
  331. string ErrorMessage = "";
  332. string sql = $@" select Distinct A.OutCode,A.WorkPoint from ICSOtherOut A
  333. where A.OutCode in ({codes})";
  334. DataTable dt = Repository().FindDataSetBySql(sql).Tables[0];
  335. for (int i = 0; i < dt.Rows.Count; i++)
  336. {
  337. string chksql = @"select SUM(Quantity) AS Quantity,SUM(OutQuantity) AS OutQuantity from ICSOtherOut
  338. where OutCode='{0}' and WorkPoint='{1}'
  339. GROUP BY OutCode,WorkPoint";
  340. chksql = string.Format(chksql, dt.Rows[i]["OutCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  341. DataTable chkdt = Repository().FindDataSetBySql(chksql).Tables[0];
  342. if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) != Convert.ToDecimal(chkdt.Rows[0]["OutQuantity"]))
  343. {
  344. SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ();
  345. SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1();
  346. Info.NEWID = Guid.NewGuid().ToString();
  347. Info.DANJU = dt.Rows[i]["OutCode"].ToString();
  348. Info.STATE = "0";
  349. List<SAPCallBackDocVPN.ZWMS_PZ> ItemList = new List<SAPCallBackDocVPN.ZWMS_PZ>();
  350. List<SAPCallBackDocVPN.ZWEBS_GERNR> ItemLineList = new List<SAPCallBackDocVPN.ZWEBS_GERNR>();
  351. Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1];
  352. sql = @"select A.ID, A.OutCode,A.SAPSequence,A.InvCode,A.Sequence,A.Quantity,A.OutQuantity
  353. ,ISNULL(B.BatchCode,'') AS BatchCode,A.WorkPoint,A.WHCode from ICSOtherOut A
  354. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  355. WHERE OutCode='{0}' AND A.WorkPoint='{1}'";
  356. sql = string.Format(sql, dt.Rows[i]["OutCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  357. DataTable Sapdt = Repository().FindDataSetBySql(sql).Tables[0];
  358. foreach (DataRow dr in Sapdt.Rows)
  359. {
  360. string id = dr["ID"].ToString();
  361. string dnCode = dr["OutCode"].ToString();
  362. string invCode = dr["INVCode"].ToString();
  363. string workPoint = dr["WorkPoint"].ToString();
  364. string whCode = dr["WHCode"].ToString();
  365. decimal quantity = dr["Quantity"].ToDecimal();
  366. string sequence = dr["SAPSequence"].ToString();
  367. string batchCode = dr["BatchCode"].ToString();
  368. decimal dnQuantity = dr["OutQuantity"].ToDecimal();
  369. SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
  370. SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR();
  371. Item.DANJU = dr["OutCode"].ToString();
  372. Item.POSNR = dr["SAPSequence"].ToString();
  373. Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["OutQuantity"].ToString()), 3);
  374. ItemList.Add(Item);
  375. if (dr["BatchCode"].ToString() != "")
  376. {
  377. ItemLine.DANJU = dr["OutCode"].ToString();
  378. ItemLine.POSNR = dr["SAPSequence"].ToString();
  379. ItemLine.MATNR = dr["InvCode"].ToString();
  380. ItemLine.GERNR = dr["BatchCode"].ToString();
  381. ItemLineList.Add(ItemLine);
  382. }
  383. if (Convert.ToDecimal(dr["Quantity"].ToString()) != Convert.ToDecimal(dr["OutQuantity"].ToString()) || Convert.ToDecimal(dr["Quantity"].ToString()) == 0)
  384. {
  385. sqlString.Append($@"DELETE FROM ICSOtherOut WHERE ID='{id}';");
  386. sqlString.Append($@"INSERT INTO ICSDeleteReceiptsLog VALUES(NEWID(),'{dnCode}','{sequence}','8','{workPoint}','{invCode}',{dnQuantity},null,'{MUSER}','{MUSERNAME}','{MTime}');");
  387. }
  388. }
  389. if (ItemList.Count > 0)
  390. {
  391. Info.Z_ITEM = ItemList.ToArray();
  392. if (ItemLineList.Count > 0)
  393. {
  394. Info.Z_GERNR = ItemLineList.ToArray();
  395. }
  396. else
  397. {
  398. Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1];
  399. }
  400. SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse();
  401. result = Client.CallZWMS_SK_WS_PZ(Info);
  402. if (result.Z_NULL == "N")
  403. {
  404. foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG)
  405. {
  406. IsSuccess = "N";
  407. ErrorMessage += resultItem.L_MESSAGE + "/r/n";
  408. }
  409. }
  410. }
  411. }
  412. }
  413. if (IsSuccess == "N")
  414. {
  415. throw new Exception(ErrorMessage);
  416. }
  417. if (sqlString.IsEmpty())
  418. {
  419. return 0;
  420. }
  421. int count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString());
  422. return count;
  423. }
  424. #endregion
  425. #region 物料调拨
  426. else if (type == "10")
  427. {
  428. string IsSuccess = "";
  429. string ErrorMessage = "";
  430. string sql = $@" select Distinct A.TransferNO,A.WorkPoint from ICSTransfer A
  431. where A.TransferNO in ({codes})";
  432. DataTable dt = Repository().FindDataSetBySql(sql).Tables[0];
  433. for (int i = 0; i < dt.Rows.Count; i++)
  434. {
  435. string chksql = @"select SUM(Quantity) AS Quantity,SUM(TransferQuantity) AS TransferQuantity from ICSTransfer
  436. where TransferNO='{0}' and WorkPoint='{1}'
  437. GROUP BY TransferNO,WorkPoint";
  438. chksql = string.Format(chksql, dt.Rows[i]["TransferNO"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  439. DataTable chkdt = Repository().FindDataSetBySql(chksql).Tables[0];
  440. SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ();
  441. SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1();
  442. Info.NEWID = Guid.NewGuid().ToString();
  443. Info.DANJU = dt.Rows[i]["TransferNO"].ToString();
  444. Info.STATE = "0";
  445. List<SAPCallBackDocVPN.ZWMS_PZ> ItemList = new List<SAPCallBackDocVPN.ZWMS_PZ>();
  446. List<SAPCallBackDocVPN.ZWEBS_GERNR> ItemLineList = new List<SAPCallBackDocVPN.ZWEBS_GERNR>();
  447. Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1];
  448. sql = @" select A.ID,A.WorkPoint,A.FromWarehouseCode, A.TransferNO,A.SAPSequence,A.InvCode,A.Sequence,A.Quantity,A.TransferQuantity
  449. ,ISNULL(B.BatchCode,'') AS BatchCode from ICSTransfer A
  450. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  451. WHERE TransferNO='{0}' AND A.WorkPoint='{1}'";
  452. sql = string.Format(sql, dt.Rows[i]["TransferNO"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  453. DataTable Sapdt = Repository().FindDataSetBySql(sql).Tables[0];
  454. foreach (DataRow dr in Sapdt.Rows)
  455. {
  456. string id = dr["ID"].ToString();
  457. string dnCode = dr["TransferNO"].ToString();
  458. string invCode = dr["INVCode"].ToString();
  459. string workPoint = dr["WorkPoint"].ToString();
  460. string whCode = dr["FromWarehouseCode"].ToString();
  461. decimal quantity = dr["Quantity"].ToDecimal();
  462. string sequence = dr["SAPSequence"].ToString();
  463. string batchCode = dr["BatchCode"].ToString();
  464. decimal dnQuantity = dr["TransferQuantity"].ToDecimal();
  465. SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
  466. SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR();
  467. Item.DANJU = dr["TransferNO"].ToString();
  468. Item.POSNR = dr["SAPSequence"].ToString();
  469. Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["TransferQuantity"].ToString()), 3);
  470. ItemList.Add(Item);
  471. if (dr["BatchCode"].ToString() != "")
  472. {
  473. ItemLine.DANJU = dr["TransferNO"].ToString();
  474. ItemLine.POSNR = dr["SAPSequence"].ToString();
  475. ItemLine.MATNR = dr["InvCode"].ToString();
  476. ItemLine.GERNR = dr["BatchCode"].ToString();
  477. ItemLineList.Add(ItemLine);
  478. }
  479. if (Convert.ToDecimal(dr["Quantity"].ToString()) != Convert.ToDecimal(dr["TransferQuantity"].ToString()) || Convert.ToDecimal(dr["Quantity"].ToString()) == 0)
  480. {
  481. sqlString.Append($@"DELETE FROM ICSTransfer WHERE ID='{id}';");
  482. sqlString.Append($@"INSERT INTO ICSDeleteReceiptsLog VALUES(NEWID(),'{dnCode}','{sequence}','10','{workPoint}','{invCode}',{dnQuantity},null,'{MUSER}','{MUSERNAME}','{MTime}');");
  483. }
  484. }
  485. if (ItemList.Count > 0)
  486. {
  487. Info.Z_ITEM = ItemList.ToArray();
  488. if (ItemLineList.Count > 0)
  489. {
  490. Info.Z_GERNR = ItemLineList.ToArray();
  491. }
  492. else
  493. {
  494. Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1];
  495. }
  496. SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse();
  497. result = Client.CallZWMS_SK_WS_PZ(Info);
  498. if (result.Z_NULL == "N")
  499. {
  500. foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG)
  501. {
  502. IsSuccess = "N";
  503. ErrorMessage += resultItem.L_MESSAGE + "/r/n";
  504. }
  505. }
  506. }
  507. }
  508. if (IsSuccess == "N")
  509. {
  510. throw new Exception(ErrorMessage);
  511. }
  512. if (sqlString.IsEmpty())
  513. {
  514. return 0;
  515. }
  516. int count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString());
  517. return count;
  518. }
  519. #endregion
  520. #region 检验合格单
  521. else if (type == "13")
  522. {
  523. #region SAP(检验合格单为两层结构 一行对应一个序列号)
  524. string IsSuccess = "";
  525. string ErrorMessage = "";
  526. string sql = $@" select A.DNCode,A.WorkPoint,Quantity,A.Sequence,A.WHCode,A.ID,A.INVCode,A.RCVQuantity
  527. from ICSDeliveryNotice A
  528. where A.DNCode in ({codes})";
  529. DataTable dt = Repository().FindDataSetBySql(sql).Tables[0];
  530. for (int i = 0; i < dt.Rows.Count; i++)
  531. {
  532. string chksql = @"select SUM(Quantity) AS Quantity,SUM(RCVQuantity) AS RCVQuantity from ICSDeliveryNotice
  533. where DNCode='{0}' and WorkPoint='{1}'
  534. GROUP BY DNCode,WorkPoint";
  535. chksql = string.Format(chksql, dt.Rows[i]["DNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  536. DataTable chkdt = Repository().FindDataSetBySql(chksql).Tables[0];
  537. sql = @"select A.DNCode,
  538. CASE WHEN SUM(Convert(decimal(18,6),A.SAPSequence)) IS NULL THEN SUM(A.RCVQuantity)
  539. ELSE SUM(Convert(decimal(18,6),A.SAPSequence)) END AS RCVQuantity,B.BatchCode from ICSDeliveryNotice A
  540. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  541. WHERE DNCode='{0}' AND A.WorkPoint='{1}'
  542. GROUP BY A.DNCode,B.BatchCode";
  543. sql = string.Format(sql, dt.Rows[i]["DNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  544. DataTable Sapdt = Repository().FindDataSetBySql(sql).Tables[0];
  545. if (Sapdt.Rows.Count == 0)
  546. {
  547. throw new Exception("单据查询失败");//单据查询失败
  548. }
  549. string id = dt.Rows[i]["ID"].ToString();
  550. string dnCode = dt.Rows[i]["DNCode"].ToString();
  551. string invCode = dt.Rows[i]["INVCode"].ToString();
  552. string workPoint = dt.Rows[i]["WorkPoint"].ToString();
  553. string whCode = dt.Rows[i]["WHCode"].ToString();
  554. string quantity = dt.Rows[i]["Quantity"].ToString();
  555. string sequence = dt.Rows[i]["Sequence"].ToString();
  556. decimal dnQuantity = dt.Rows[i]["RCVQuantity"].ToDecimal();
  557. sqlString.Append($@"DELETE FROM ICSDeliveryNotice WHERE ID='{id}';");
  558. sqlString.Append($@"INSERT INTO ICSDeleteReceiptsLog VALUES(NEWID(),'{dnCode}','{sequence}','13','{workPoint}','{invCode}',{dnQuantity},null,'{MUSER}','{MUSERNAME}','{MTime}');");
  559. SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU Client = new SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU();
  560. SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU1 Info = new SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU1();
  561. Info.NEWID = Guid.NewGuid().ToString();
  562. Info.PRUEFLOS = Sapdt.Rows[0]["DNCode"].ToString();
  563. Info.L_LME = System.Decimal.Round(Convert.ToDecimal(Sapdt.Rows[0]["RCVQuantity"].ToString()), 3);
  564. Info.SERNP = Sapdt.Rows[0]["BatchCode"].ToString();
  565. Info.Z_GERNR = new SAPCallBackJYHGDVPN.ZWEBS_GERNR[0];
  566. SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKUResponse result = new SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKUResponse();
  567. result = Client.CallZWMS_SK_WS_RUKU(Info);
  568. if (result.Z_NULL == "N")
  569. {
  570. IsSuccess = "N";
  571. ErrorMessage += result.L_MESSAGE;
  572. }
  573. }
  574. if (IsSuccess == "N")
  575. {
  576. throw new Exception(ErrorMessage);
  577. }
  578. #endregion
  579. if (sqlString.IsEmpty())
  580. {
  581. return 0;
  582. }
  583. int count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString());
  584. return count;
  585. }
  586. #endregion
  587. #region 机加工入库
  588. else if (type == "14")
  589. {
  590. string IsSuccess = "";
  591. string ErrorMessage = "";
  592. string sql = $@" select Distinct A.RCVCode,A.WorkPoint from ICSManufactureReceive A
  593. where A.RCVCode in ({codes})";
  594. DataTable dt = Repository().FindDataSetBySql(sql).Tables[0];
  595. for (int i = 0; i < dt.Rows.Count; i++)
  596. {
  597. string chksql = @"select SUM(Quantity) AS Quantity,SUM(RCVQuantity) AS RCVQuantity from ICSManufactureReceive
  598. where RCVCode='{0}' and WorkPoint='{1}'
  599. GROUP BY RCVCode,WorkPoint";
  600. chksql = string.Format(chksql, dt.Rows[i]["RCVCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  601. DataTable chkdt = Repository().FindDataSetBySql(chksql).Tables[0];
  602. SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ();
  603. SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1();
  604. Info.NEWID = Guid.NewGuid().ToString();
  605. Info.DANJU = dt.Rows[i]["RCVCode"].ToString();
  606. Info.STATE = "0";
  607. List<SAPCallBackDocVPN.ZWMS_PZ> ItemList = new List<SAPCallBackDocVPN.ZWMS_PZ>();
  608. List<SAPCallBackDocVPN.ZWEBS_GERNR> ItemLineList = new List<SAPCallBackDocVPN.ZWEBS_GERNR>();
  609. Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1];
  610. sql = @"select A.ID,A.WorkPoint,A.WHCode,A.RCVCode,A.SAPSequence,A.InvCode,A.Sequence,A.Quantity,A.RCVQuantity
  611. ,ISNULL(B.BatchCode,'') AS BatchCode from ICSManufactureReceive A
  612. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  613. WHERE RCVCode='{0}' AND A.WorkPoint='{1}'";
  614. sql = string.Format(sql, dt.Rows[i]["RCVCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  615. DataTable Sapdt = Repository().FindDataSetBySql(sql).Tables[0];
  616. foreach (DataRow dr in Sapdt.Rows)
  617. {
  618. string id = dr["ID"].ToString();
  619. string dnCode = dr["RCVCode"].ToString();
  620. string invCode = dr["INVCode"].ToString();
  621. string workPoint = dr["WorkPoint"].ToString();
  622. string whCode = dr["WHCode"].ToString();
  623. decimal quantity = dr["Quantity"].ToDecimal();
  624. string sequence = dr["SAPSequence"].ToString();
  625. string batchCode = dr["BatchCode"].ToString();
  626. decimal dnQuantity = dr["RCVQuantity"].ToDecimal();
  627. SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
  628. SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR();
  629. Item.DANJU = dr["RCVCode"].ToString();
  630. Item.POSNR = dr["SAPSequence"].ToString();
  631. Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["RCVQuantity"].ToString()), 3);
  632. ItemList.Add(Item);
  633. if (dr["BatchCode"].ToString() != "")
  634. {
  635. ItemLine.DANJU = dr["RCVCode"].ToString();
  636. ItemLine.POSNR = dr["SAPSequence"].ToString();
  637. ItemLine.MATNR = dr["InvCode"].ToString();
  638. ItemLine.GERNR = dr["BatchCode"].ToString();
  639. ItemLineList.Add(ItemLine);
  640. }
  641. if (Convert.ToDecimal(dr["Quantity"].ToString()) != Convert.ToDecimal(dr["RCVQuantity"].ToString()) || Convert.ToDecimal(dr["Quantity"].ToString()) == 0)
  642. {
  643. sqlString.Append($@"DELETE FROM ICSManufactureReceive WHERE ID='{id}';");
  644. sqlString.Append($@"INSERT INTO ICSDeleteReceiptsLog VALUES(NEWID(),'{dnCode}','{sequence}','14','{workPoint}','{invCode}',{dnQuantity},null,'{MUSER}','{MUSERNAME}','{MTime}');");
  645. }
  646. }
  647. if (ItemList.Count > 0)
  648. {
  649. Info.Z_ITEM = ItemList.ToArray();
  650. if (ItemLineList.Count > 0)
  651. {
  652. Info.Z_GERNR = ItemLineList.ToArray();
  653. }
  654. else
  655. {
  656. Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1];
  657. }
  658. SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse();
  659. result = Client.CallZWMS_SK_WS_PZ(Info);
  660. if (result.Z_NULL == "N")
  661. {
  662. foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG)
  663. {
  664. IsSuccess = "N";
  665. ErrorMessage += resultItem.L_MESSAGE + "/r/n";
  666. }
  667. }
  668. }
  669. }
  670. if (IsSuccess == "N")
  671. {
  672. throw new Exception(ErrorMessage);
  673. }
  674. if (sqlString.IsEmpty())
  675. {
  676. return 0;
  677. }
  678. int count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString());
  679. return count;
  680. }
  681. #endregion
  682. #region 成本中心退料
  683. else if (type == "15")
  684. {
  685. #region SAP(三层结构)
  686. string IsSuccess = "";
  687. string ErrorMessage = "";
  688. string sql = $@" select Distinct A.InCode,A.WorkPoint from ICSOtherIn A
  689. where A.InCode in ({codes})";
  690. DataTable dt = Repository().FindDataSetBySql(sql).Tables[0];
  691. for (int i = 0; i < dt.Rows.Count; i++)
  692. {
  693. var applyCode = dt.Rows[i]["InCode"].ToString();
  694. var applyWorkPoint = dt.Rows[i]["WorkPoint"].ToString();
  695. string chksql = @"select SUM(Quantity) AS Quantity,SUM(InQuantity) AS InQuantity from ICSOtherIn
  696. where InCode='{0}' and WorkPoint='{1}'
  697. GROUP BY InCode,WorkPoint";
  698. chksql = string.Format(chksql, applyCode, applyWorkPoint);
  699. DataTable chkdt = Repository().FindDataSetBySql(chksql).Tables[0];
  700. SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ();
  701. SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1();
  702. Info.NEWID = Guid.NewGuid().ToString();
  703. Info.DANJU = dt.Rows[i]["InCode"].ToString();
  704. Info.STATE = "0";
  705. List<SAPCallBackDocVPN.ZWMS_PZ> ItemList = new List<SAPCallBackDocVPN.ZWMS_PZ>();
  706. List<SAPCallBackDocVPN.ZWEBS_GERNR> ItemLineList = new List<SAPCallBackDocVPN.ZWEBS_GERNR>();
  707. Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1];
  708. sql = @"select A.InCode,A.SAPSequence,A.InvCode,A.Sequence,A.Quantity,A.InQuantity
  709. ,ISNULL(B.BatchCode,'') AS BatchCode,A.ID,A.WHCode,A.WorkPoint from ICSOtherIn A
  710. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  711. WHERE InCode='{0}' AND A.WorkPoint='{1}'";
  712. sql = string.Format(sql, dt.Rows[i]["InCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  713. DataTable Sapdt = Repository().FindDataSetBySql(sql).Tables[0];
  714. foreach (DataRow dr in Sapdt.Rows)
  715. {
  716. string id = dr["ID"].ToString();
  717. string dnCode = dr["InCode"].ToString();
  718. string invCode = dr["INVCode"].ToString();
  719. string workPoint = dr["WorkPoint"].ToString();
  720. string whCode = dr["WHCode"].ToString();
  721. decimal quantity = dr["Quantity"].ToDecimal();
  722. string sequence = dr["SAPSequence"].ToString();
  723. string batchCode = dr["BatchCode"].ToString();
  724. decimal dnQuantity = dr["InQuantity"].ToDecimal();
  725. SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
  726. SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR();
  727. Item.DANJU = dnCode;
  728. Item.POSNR = sequence;
  729. Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["InQuantity"].ToString()), 3); ;
  730. ItemList.Add(Item);
  731. if (dr["BatchCode"].ToString() != "")
  732. {
  733. ItemLine.DANJU = dnCode;
  734. ItemLine.POSNR = sequence;
  735. ItemLine.MATNR = invCode;
  736. ItemLine.GERNR = batchCode;
  737. ItemLineList.Add(ItemLine);
  738. }
  739. if (Convert.ToDecimal(dr["InQuantity"].ToString()) != Convert.ToDecimal(dr["Quantity"].ToString()) || Convert.ToDecimal(dr["Quantity"].ToString()) == 0)
  740. {
  741. sqlString.Append($@"DELETE FROM ICSOtherIn WHERE ID='{id}';");
  742. sqlString.Append($@"INSERT INTO ICSDeleteReceiptsLog VALUES(NEWID(),'{dnCode}','{sequence}','15','{workPoint}','{invCode}',{dnQuantity},null,'{MUSER}','{MUSERNAME}','{MTime}');");
  743. }
  744. }
  745. if (ItemList.Count > 0)
  746. {
  747. Info.Z_ITEM = ItemList.ToArray();
  748. if (ItemLineList.Count > 0)
  749. {
  750. Info.Z_GERNR = ItemLineList.ToArray();
  751. }
  752. else
  753. {
  754. Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1];
  755. }
  756. SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse();
  757. result = Client.CallZWMS_SK_WS_PZ(Info);
  758. if (result.Z_NULL == "N")
  759. {
  760. foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG)
  761. {
  762. IsSuccess = "N";
  763. ErrorMessage += resultItem.L_MESSAGE + "/r/n";
  764. }
  765. }
  766. }
  767. }
  768. if (IsSuccess == "N")
  769. {
  770. throw new Exception(ErrorMessage);
  771. }
  772. #endregion
  773. if (sqlString.IsEmpty())
  774. {
  775. return 0;
  776. }
  777. int count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString());
  778. return count;
  779. }
  780. #endregion、
  781. #region 退料单
  782. else if (type == "16")
  783. {
  784. #region SAP(三层结构)
  785. string IsSuccess = "";
  786. string ErrorMessage = "";
  787. string sql = $@" select Distinct A.ApplyNegCode,A.WorkPoint from ICSMOApplyNeg A
  788. where A.ApplyNegCode in ({codes})";
  789. DataTable dt = Repository().FindDataSetBySql(sql).Tables[0];
  790. for (int i = 0; i < dt.Rows.Count; i++)
  791. {
  792. var applyCode = dt.Rows[i]["ApplyNegCode"].ToString();
  793. var applyWorkPoint = dt.Rows[i]["WorkPoint"].ToString();
  794. string chksql = @"select SUM(B.Quantity) AS Quantity,SUM(B.IssueNegQuantity) AS IssueQuantity from ICSMOApplyNeg A
  795. LEFT JOIN ICSMOApplyNegDetail B ON B.ApplyNegCode=A.ApplyNegCode AND B.WorkPoint=A.WorkPoint
  796. where A.ApplyNegCode='{0}' and A.WorkPoint='{1}'
  797. GROUP BY A.ApplyNegCode,A.WorkPoint";
  798. chksql = string.Format(chksql, applyCode, applyWorkPoint);
  799. DataTable chkdt = Repository().FindDataSetBySql(chksql).Tables[0];
  800. if (Convert.ToDecimal(chkdt.Rows[0]["IssueQuantity"].ToString()) == 0)
  801. {
  802. //删除主表
  803. sqlString.Append($@"DELETE FROM ICSMOApplyNeg WHERE ApplyNegCode='{applyCode}' and WorkPoint='{applyWorkPoint}';");
  804. }
  805. SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ();
  806. SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1();
  807. Info.NEWID = Guid.NewGuid().ToString();
  808. Info.DANJU = dt.Rows[i]["ApplyNegCode"].ToString();
  809. Info.STATE = "0";
  810. List<SAPCallBackDocVPN.ZWMS_PZ> ItemList = new List<SAPCallBackDocVPN.ZWMS_PZ>();
  811. List<SAPCallBackDocVPN.ZWEBS_GERNR> ItemLineList = new List<SAPCallBackDocVPN.ZWEBS_GERNR>();
  812. Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1];
  813. sql = @" select A.ApplyNegCode,B.SAPSequence,B.InvCode,B.Sequence,B.Quantity,B.IssueNegQuantity
  814. ,ISNULL(C.BatchCode,'') AS BatchCode,B.WorkPoint,B.ID,B.WHCode from ICSMOApplyNeg A
  815. LEFT JOIN ICSMOApplyNegDetail B ON B.ApplyNegCode=A.ApplyNegCode AND B.WorkPoint=A.WorkPoint
  816. LEFT JOIN ICSExtension C ON C.ID=B.ExtensionID AND C.WorkPoint=B.WorkPoint
  817. WHERE A.ApplyNegCode='{0}' AND A.WorkPoint='{1}'";
  818. sql = string.Format(sql, dt.Rows[i]["ApplyNegCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  819. DataTable Sapdt = Repository().FindDataSetBySql(sql).Tables[0];
  820. foreach (DataRow dr in Sapdt.Rows)
  821. {
  822. string id = dr["ID"].ToString();
  823. string dnCode = dr["ApplyNegCode"].ToString();
  824. string invCode = dr["INVCode"].ToString();
  825. string workPoint = dr["WorkPoint"].ToString();
  826. string whCode = dr["WHCode"].ToString();
  827. decimal quantity = dr["Quantity"].ToDecimal();
  828. string sequence = dr["SAPSequence"].ToString();
  829. string batchCode = dr["BatchCode"].ToString();
  830. decimal dnQuantity = dr["IssueNegQuantity"].ToDecimal() == 0 ? 0 : dr["IssueNegQuantity"].ToDecimal();
  831. SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
  832. SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR();
  833. Item.DANJU = dnCode;
  834. Item.POSNR = sequence;
  835. Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["IssueNegQuantity"].ToString()), 3);
  836. ItemList.Add(Item);
  837. if (dr["BatchCode"].ToString() != "")
  838. {
  839. ItemLine.DANJU = dnCode;
  840. ItemLine.POSNR = sequence;
  841. ItemLine.MATNR = invCode;
  842. ItemLine.GERNR = batchCode;
  843. ItemLineList.Add(ItemLine);
  844. }
  845. if (Convert.ToDecimal(dr["IssueNegQuantity"].ToString()) != Convert.ToDecimal(dr["Quantity"].ToString()) || Convert.ToDecimal(dr["Quantity"].ToString()) == 0)
  846. {
  847. sqlString.Append($@"DELETE FROM ICSMOApplyNegDetail WHERE ID='{id}';");
  848. sqlString.Append($@"INSERT INTO ICSDeleteReceiptsLog VALUES(NEWID(),'{dnCode}','{sequence}','16','{workPoint}','{invCode}',{dnQuantity},null,'{MUSER}','{MUSERNAME}','{MTime}');");
  849. }
  850. }
  851. if (ItemList.Count > 0)
  852. {
  853. Info.Z_ITEM = ItemList.ToArray();
  854. if (ItemLineList.Count > 0)
  855. {
  856. Info.Z_GERNR = ItemLineList.ToArray();
  857. }
  858. else
  859. {
  860. Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1];
  861. }
  862. SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse();
  863. result = Client.CallZWMS_SK_WS_PZ(Info);
  864. if (result.Z_NULL == "N")
  865. {
  866. foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG)
  867. {
  868. IsSuccess = "N";
  869. ErrorMessage += resultItem.L_MESSAGE + "/r/n";
  870. }
  871. }
  872. }
  873. }
  874. if (IsSuccess == "N")
  875. {
  876. throw new Exception(ErrorMessage);
  877. }
  878. #endregion
  879. if (sqlString.IsEmpty())
  880. {
  881. return 0;
  882. }
  883. int count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString());
  884. return count;
  885. }
  886. #endregion
  887. #region 销售退货单
  888. else
  889. {
  890. string IsSuccess = "";
  891. string ErrorMessage = "";
  892. string sql = $@" select Distinct A.SDNCode,A.WorkPoint from ICSSDN A
  893. where A.SDNCode in ({codes})";
  894. DataTable dt = Repository().FindDataSetBySql(sql).Tables[0];
  895. for (int i = 0; i < dt.Rows.Count; i++)
  896. {
  897. string chksql = @"select SUM(Quantity) AS Quantity,SUM(SDNQuantity) AS SDNQuantity from ICSSDN
  898. where SDNCode='{0}' and WorkPoint='{1}'
  899. GROUP BY SDNCode,WorkPoint";
  900. chksql = string.Format(chksql, dt.Rows[i]["SDNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  901. DataTable chkdt = Repository().FindDataSetBySql(chksql).Tables[0];
  902. SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ Client = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ();
  903. SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ1 Info = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ1();
  904. List<SAPCallBackDispatchVPN.ZWMS_DO_HEAD> headlist = new List<SAPCallBackDispatchVPN.ZWMS_DO_HEAD>();
  905. SAPCallBackDispatchVPN.ZWMS_DO_HEAD head = new SAPCallBackDispatchVPN.ZWMS_DO_HEAD();
  906. head.VBELN = dt.Rows[i]["SDNCode"].ToString();
  907. headlist.Add(head);
  908. Info.T_HEAD = headlist.ToArray();
  909. List<SAPCallBackDispatchVPN.ZWMS_DO_ITEM> ItemList = new List<SAPCallBackDispatchVPN.ZWMS_DO_ITEM>();
  910. List<SAPCallBackDispatchVPN.ZWMS_DO_GERNR> ItemLineList = new List<SAPCallBackDispatchVPN.ZWMS_DO_GERNR>();
  911. Info.T_RETURN = new SAPCallBackDispatchVPN.ZWMS_DO_RETURN[1];
  912. sql = @" select A.ID,A.WorkPoint,A.WHCode, A.SDNCode,A.SAPSequence,A.InvCode,A.Sequence,A.Quantity,A.SDNQuantity
  913. ,ISNULL(B.BatchCode,'') AS BatchCode from ICSSDN A
  914. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  915. WHERE SDNCode='{0}' AND A.WorkPoint='{1}'";
  916. sql = string.Format(sql, dt.Rows[i]["SDNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  917. DataTable Sapdt = Repository().FindDataSetBySql(sql).Tables[0];
  918. foreach (DataRow dr in Sapdt.Rows)
  919. {
  920. string id = dr["ID"].ToString();
  921. string dnCode = dr["SDNCode"].ToString();
  922. string invCode = dr["INVCode"].ToString();
  923. string workPoint = dr["WorkPoint"].ToString();
  924. string whCode = dr["WHCode"].ToString();
  925. decimal quantity = dr["Quantity"].ToDecimal();
  926. string sequence = dr["SAPSequence"].ToString();
  927. string batchCode = dr["BatchCode"].ToString();
  928. decimal dnQuantity = dr["SDNQuantity"].ToDecimal();
  929. SAPCallBackDispatchVPN.ZWMS_DO_ITEM Item = new SAPCallBackDispatchVPN.ZWMS_DO_ITEM();
  930. SAPCallBackDispatchVPN.ZWMS_DO_GERNR ItemLine = new SAPCallBackDispatchVPN.ZWMS_DO_GERNR();
  931. Item.VBELN = dr["SDNCode"].ToString();
  932. Item.POSNR = dr["SAPSequence"].ToString();
  933. Item.LFIMG = System.Decimal.Round(Convert.ToDecimal(dr["SDNQuantity"].ToString()), 3);
  934. ItemList.Add(Item);
  935. if (dr["BatchCode"].ToString() != "")
  936. {
  937. ItemLine.VBELN = dr["SDNCode"].ToString();
  938. ItemLine.POSNR = dr["SAPSequence"].ToString();
  939. ItemLine.GERNR = dr["BatchCode"].ToString();
  940. ItemLineList.Add(ItemLine);
  941. }
  942. if (Convert.ToDecimal(dr["Quantity"].ToString()) != Convert.ToDecimal(dr["SDNQuantity"].ToString()) || Convert.ToDecimal(dr["Quantity"].ToString()) == 0)
  943. {
  944. sqlString.Append($@"DELETE FROM ICSSDN WHERE ID='{id}';");
  945. sqlString.Append($@"INSERT INTO ICSDeleteReceiptsLog VALUES(NEWID(),'{dnCode}','{sequence}','17','{workPoint}','{invCode}',{dnQuantity},null,'{MUSER}','{MUSERNAME}','{MTime}');");
  946. }
  947. }
  948. if (ItemList.Count > 0)
  949. {
  950. Info.T_ITEM = ItemList.ToArray();
  951. if (ItemLineList.Count > 0)
  952. {
  953. Info.T_GERNR = ItemLineList.ToArray();
  954. }
  955. else
  956. {
  957. Info.T_GERNR = new SAPCallBackDispatchVPN.ZWMS_DO_GERNR[1];
  958. }
  959. SAPCallBackDispatchVPN.ZWMS_SK_DO_GZResponse result = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZResponse();
  960. result = Client.CallZWMS_SK_DO_GZ(Info);
  961. foreach (SAPCallBackDispatchVPN.ZWMS_DO_RETURN resultItem in result.T_RETURN)
  962. {
  963. if (resultItem.ZFLG == "N")
  964. {
  965. IsSuccess = "N";
  966. ErrorMessage += resultItem.ZMESS + "/r/n";
  967. }
  968. }
  969. }
  970. }
  971. if (IsSuccess == "N")
  972. {
  973. throw new Exception(ErrorMessage);
  974. }
  975. if (sqlString.IsEmpty())
  976. {
  977. return 0;
  978. }
  979. int count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString());
  980. return count;
  981. }
  982. #endregion
  983. }
  984. catch (Exception ex)
  985. {
  986. throw new Exception(ex.Message);
  987. }
  988. }
  989. public string CheckReceipt(string codes, string type)
  990. {
  991. try
  992. {
  993. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  994. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  995. DateTime MTime = DateTime.Now;
  996. string sql = string.Empty;
  997. StringBuilder msg=new StringBuilder();
  998. if (type == "14")
  999. {
  1000. sql = $@"SELECT a.RCVCode as Code,a.Sequence,SUM(c.Quantity) as Quantity ,a.RCVQuantity as IssueQuantity
  1001. FROM ICSManufactureReceive a
  1002. left JOIN ICSInventoryLotDetail b ON a.RCVCode=b.TransCode AND a.Sequence=b.TransSequence
  1003. left JOIN ICSInventoryLot c ON c.LotNo=b.LotNo
  1004. WHERE a.RCVCode in ({codes})
  1005. AND b.LotNo NOT LIKE '%-%'
  1006. GROUP BY a.RCVCode,a.Sequence,a.RCVQuantity";
  1007. }
  1008. else if (type == "15")
  1009. {
  1010. sql = $@"SELECT a.InCode as Code,a.Sequence,SUM(c.Quantity) as Quantity ,a.InQuantity as IssueQuantity
  1011. FROM ICSOtherIn a
  1012. left JOIN ICSInventoryLotDetail b ON a.InCode=b.TransCode AND a.Sequence=b.TransSequence
  1013. left JOIN ICSInventoryLot c ON c.LotNo=b.LotNo
  1014. WHERE a.InCode in ({codes})
  1015. AND b.LotNo NOT LIKE '%-%'
  1016. GROUP BY a.InCode,a.Sequence,a.InQuantity";
  1017. }
  1018. else if (type == "16")
  1019. {
  1020. sql = $@"SELECT a.ApplyNegCode as Code,a.Sequence,SUM(c.Quantity) as Quantity ,a.IssueNegQuantity as IssueQuantity FROM ICSMOApplyNegDetail a
  1021. left JOIN ICSInventoryLotDetail b ON a.ApplyNegCode=b.TransCode AND a.Sequence=b.TransSequence
  1022. left JOIN ICSInventoryLot c ON c.LotNo=b.LotNo
  1023. WHERE a.ApplyNegCode in ({codes})
  1024. AND b.LotNo NOT LIKE '%-%'
  1025. GROUP BY a.ApplyNegCode,a.Sequence,a.IssueNegQuantity";
  1026. }
  1027. else if (type == "17")
  1028. {
  1029. sql = $@"SELECT a.SDNCode as Code,a.Sequence,SUM(c.Quantity) as Quantity ,a.SDNQuantity as IssueQuantity
  1030. FROM ICSSDN a
  1031. left JOIN ICSInventoryLotDetail b ON a.SDNCode=b.TransCode AND a.Sequence=b.TransSequence
  1032. left JOIN ICSInventoryLot c ON c.LotNo=b.LotNo
  1033. WHERE a.SDNCode in ({codes})
  1034. AND b.LotNo NOT LIKE '%-%'
  1035. GROUP BY a.SDNCode,a.Sequence,a.SDNQuantity";
  1036. }
  1037. if (!sql.IsEmpty())
  1038. {
  1039. var datas = Repository().FindDataSetBySql(sql).Tables[0];
  1040. if (datas.Rows.Count < 1)
  1041. return msg.ToString();
  1042. foreach (DataRow data in datas.Rows)
  1043. {
  1044. string code = data["Code"].ToString();
  1045. string sequence = data["Sequence"].ToString();
  1046. decimal quantity = data["Quantity"].ToDecimal();
  1047. decimal issueQuantity = data["IssueQuantity"].ToDecimal();
  1048. if (quantity != issueQuantity)
  1049. {
  1050. msg.Append($@"单据号:{code},行号:{sequence},已经生成条码,请先删除条码后再取消单据; ");
  1051. }
  1052. }
  1053. }
  1054. return msg.ToString();
  1055. }
  1056. catch (Exception ex)
  1057. {
  1058. throw new Exception(ex.Message);
  1059. }
  1060. }
  1061. }
  1062. }