纽威
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.

1118 lines
67 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
1 year 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, SUM(Convert(decimal(18,6),A.RCVQuantity)) AS RCVQuantity,B.BatchCode from ICSDeliveryNotice A
  538. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  539. WHERE DNCode='{0}' AND A.WorkPoint='{1}'
  540. GROUP BY A.DNCode,B.BatchCode";
  541. sql = string.Format(sql, dt.Rows[i]["DNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  542. DataTable Sapdt = Repository().FindDataSetBySql(sql).Tables[0];
  543. if (Sapdt.Rows.Count == 0)
  544. {
  545. throw new Exception("单据查询失败");//单据查询失败
  546. }
  547. string id = dt.Rows[i]["ID"].ToString();
  548. string dnCode = dt.Rows[i]["DNCode"].ToString();
  549. string invCode = dt.Rows[i]["INVCode"].ToString();
  550. string workPoint = dt.Rows[i]["WorkPoint"].ToString();
  551. string whCode = dt.Rows[i]["WHCode"].ToString();
  552. string quantity = dt.Rows[i]["Quantity"].ToString();
  553. string sequence = dt.Rows[i]["Sequence"].ToString();
  554. decimal dnQuantity = dt.Rows[i]["RCVQuantity"].ToDecimal();
  555. sqlString.Append($@"DELETE FROM ICSDeliveryNotice WHERE ID='{id}';");
  556. sqlString.Append($@"INSERT INTO ICSDeleteReceiptsLog VALUES(NEWID(),'{dnCode}','{sequence}','13','{workPoint}','{invCode}',{dnQuantity},null,'{MUSER}','{MUSERNAME}','{MTime}');");
  557. SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU Client = new SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU();
  558. SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU1 Info = new SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU1();
  559. Info.NEWID = Guid.NewGuid().ToString();
  560. Info.PRUEFLOS = Sapdt.Rows[0]["DNCode"].ToString();
  561. Info.L_LME = System.Decimal.Round(Convert.ToDecimal(Sapdt.Rows[0]["RCVQuantity"].ToString()), 3);
  562. Info.SERNP = Sapdt.Rows[0]["BatchCode"].ToString();
  563. Info.Z_GERNR = new SAPCallBackJYHGDVPN.ZWEBS_GERNR[0];
  564. SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKUResponse result = new SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKUResponse();
  565. result = Client.CallZWMS_SK_WS_RUKU(Info);
  566. if (result.Z_NULL == "N")
  567. {
  568. IsSuccess = "N";
  569. ErrorMessage += result.L_MESSAGE;
  570. }
  571. }
  572. if (IsSuccess == "N")
  573. {
  574. throw new Exception(ErrorMessage);
  575. }
  576. #endregion
  577. if (sqlString.IsEmpty())
  578. {
  579. return 0;
  580. }
  581. int count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString());
  582. return count;
  583. }
  584. #endregion
  585. #region 机加工入库
  586. else if (type == "14")
  587. {
  588. string IsSuccess = "";
  589. string ErrorMessage = "";
  590. string sql = $@" select Distinct A.RCVCode,A.WorkPoint from ICSManufactureReceive A
  591. where A.RCVCode in ({codes})";
  592. DataTable dt = Repository().FindDataSetBySql(sql).Tables[0];
  593. for (int i = 0; i < dt.Rows.Count; i++)
  594. {
  595. string chksql = @"select SUM(Quantity) AS Quantity,SUM(RCVQuantity) AS RCVQuantity from ICSManufactureReceive
  596. where RCVCode='{0}' and WorkPoint='{1}'
  597. GROUP BY RCVCode,WorkPoint";
  598. chksql = string.Format(chksql, dt.Rows[i]["RCVCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  599. DataTable chkdt = Repository().FindDataSetBySql(chksql).Tables[0];
  600. SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ();
  601. SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1();
  602. Info.NEWID = Guid.NewGuid().ToString();
  603. Info.DANJU = dt.Rows[i]["RCVCode"].ToString();
  604. Info.STATE = "0";
  605. List<SAPCallBackDocVPN.ZWMS_PZ> ItemList = new List<SAPCallBackDocVPN.ZWMS_PZ>();
  606. List<SAPCallBackDocVPN.ZWEBS_GERNR> ItemLineList = new List<SAPCallBackDocVPN.ZWEBS_GERNR>();
  607. Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1];
  608. sql = @"select A.ID,A.WorkPoint,A.WHCode,A.RCVCode,A.SAPSequence,A.InvCode,A.Sequence,A.Quantity,A.RCVQuantity
  609. ,ISNULL(B.BatchCode,'') AS BatchCode from ICSManufactureReceive A
  610. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  611. WHERE RCVCode='{0}' AND A.WorkPoint='{1}'";
  612. sql = string.Format(sql, dt.Rows[i]["RCVCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  613. DataTable Sapdt = Repository().FindDataSetBySql(sql).Tables[0];
  614. foreach (DataRow dr in Sapdt.Rows)
  615. {
  616. string id = dr["ID"].ToString();
  617. string dnCode = dr["RCVCode"].ToString();
  618. string invCode = dr["INVCode"].ToString();
  619. string workPoint = dr["WorkPoint"].ToString();
  620. string whCode = dr["WHCode"].ToString();
  621. decimal quantity = dr["Quantity"].ToDecimal();
  622. string sequence = dr["SAPSequence"].ToString();
  623. string batchCode = dr["BatchCode"].ToString();
  624. decimal dnQuantity = dr["RCVQuantity"].ToDecimal();
  625. SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
  626. SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR();
  627. Item.DANJU = dr["RCVCode"].ToString();
  628. Item.POSNR = dr["SAPSequence"].ToString();
  629. Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["RCVQuantity"].ToString()), 3);
  630. ItemList.Add(Item);
  631. if (dr["BatchCode"].ToString() != "")
  632. {
  633. ItemLine.DANJU = dr["RCVCode"].ToString();
  634. ItemLine.POSNR = dr["SAPSequence"].ToString();
  635. ItemLine.MATNR = dr["InvCode"].ToString();
  636. ItemLine.GERNR = dr["BatchCode"].ToString();
  637. ItemLineList.Add(ItemLine);
  638. }
  639. if (Convert.ToDecimal(dr["Quantity"].ToString()) != Convert.ToDecimal(dr["RCVQuantity"].ToString()) || Convert.ToDecimal(dr["Quantity"].ToString()) == 0)
  640. {
  641. sqlString.Append($@"DELETE FROM ICSManufactureReceive WHERE ID='{id}';");
  642. sqlString.Append($@"INSERT INTO ICSDeleteReceiptsLog VALUES(NEWID(),'{dnCode}','{sequence}','14','{workPoint}','{invCode}',{dnQuantity},null,'{MUSER}','{MUSERNAME}','{MTime}');");
  643. }
  644. }
  645. if (ItemList.Count > 0)
  646. {
  647. Info.Z_ITEM = ItemList.ToArray();
  648. if (ItemLineList.Count > 0)
  649. {
  650. Info.Z_GERNR = ItemLineList.ToArray();
  651. }
  652. else
  653. {
  654. Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1];
  655. }
  656. SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse();
  657. result = Client.CallZWMS_SK_WS_PZ(Info);
  658. if (result.Z_NULL == "N")
  659. {
  660. foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG)
  661. {
  662. IsSuccess = "N";
  663. ErrorMessage += resultItem.L_MESSAGE + "/r/n";
  664. }
  665. }
  666. }
  667. }
  668. if (IsSuccess == "N")
  669. {
  670. throw new Exception(ErrorMessage);
  671. }
  672. if (sqlString.IsEmpty())
  673. {
  674. return 0;
  675. }
  676. int count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString());
  677. return count;
  678. }
  679. #endregion
  680. #region 成本中心退料
  681. else if (type == "15")
  682. {
  683. #region SAP(三层结构)
  684. string IsSuccess = "";
  685. string ErrorMessage = "";
  686. string sql = $@" select Distinct A.InCode,A.WorkPoint from ICSOtherIn A
  687. where A.InCode in ({codes})";
  688. DataTable dt = Repository().FindDataSetBySql(sql).Tables[0];
  689. for (int i = 0; i < dt.Rows.Count; i++)
  690. {
  691. var applyCode = dt.Rows[i]["InCode"].ToString();
  692. var applyWorkPoint = dt.Rows[i]["WorkPoint"].ToString();
  693. string chksql = @"select SUM(Quantity) AS Quantity,SUM(InQuantity) AS InQuantity from ICSOtherIn
  694. where InCode='{0}' and WorkPoint='{1}'
  695. GROUP BY InCode,WorkPoint";
  696. chksql = string.Format(chksql, applyCode, applyWorkPoint);
  697. DataTable chkdt = Repository().FindDataSetBySql(chksql).Tables[0];
  698. SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ();
  699. SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1();
  700. Info.NEWID = Guid.NewGuid().ToString();
  701. Info.DANJU = dt.Rows[i]["InCode"].ToString();
  702. Info.STATE = "0";
  703. List<SAPCallBackDocVPN.ZWMS_PZ> ItemList = new List<SAPCallBackDocVPN.ZWMS_PZ>();
  704. List<SAPCallBackDocVPN.ZWEBS_GERNR> ItemLineList = new List<SAPCallBackDocVPN.ZWEBS_GERNR>();
  705. Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1];
  706. sql = @"select A.InCode,A.SAPSequence,A.InvCode,A.Sequence,A.Quantity,A.InQuantity
  707. ,ISNULL(B.BatchCode,'') AS BatchCode,A.ID,A.WHCode,A.WorkPoint from ICSOtherIn A
  708. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  709. WHERE InCode='{0}' AND A.WorkPoint='{1}'";
  710. sql = string.Format(sql, dt.Rows[i]["InCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  711. DataTable Sapdt = Repository().FindDataSetBySql(sql).Tables[0];
  712. foreach (DataRow dr in Sapdt.Rows)
  713. {
  714. string id = dr["ID"].ToString();
  715. string dnCode = dr["InCode"].ToString();
  716. string invCode = dr["INVCode"].ToString();
  717. string workPoint = dr["WorkPoint"].ToString();
  718. string whCode = dr["WHCode"].ToString();
  719. decimal quantity = dr["Quantity"].ToDecimal();
  720. string sequence = dr["SAPSequence"].ToString();
  721. string batchCode = dr["BatchCode"].ToString();
  722. decimal dnQuantity = dr["InQuantity"].ToDecimal();
  723. SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
  724. SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR();
  725. Item.DANJU = dnCode;
  726. Item.POSNR = sequence;
  727. Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["InQuantity"].ToString()), 3); ;
  728. ItemList.Add(Item);
  729. if (dr["BatchCode"].ToString() != "")
  730. {
  731. ItemLine.DANJU = dnCode;
  732. ItemLine.POSNR = sequence;
  733. ItemLine.MATNR = invCode;
  734. ItemLine.GERNR = batchCode;
  735. ItemLineList.Add(ItemLine);
  736. }
  737. if (Convert.ToDecimal(dr["InQuantity"].ToString()) != Convert.ToDecimal(dr["Quantity"].ToString()) || Convert.ToDecimal(dr["Quantity"].ToString()) == 0)
  738. {
  739. sqlString.Append($@"DELETE FROM ICSOtherIn WHERE ID='{id}';");
  740. sqlString.Append($@"INSERT INTO ICSDeleteReceiptsLog VALUES(NEWID(),'{dnCode}','{sequence}','15','{workPoint}','{invCode}',{dnQuantity},null,'{MUSER}','{MUSERNAME}','{MTime}');");
  741. }
  742. }
  743. if (ItemList.Count > 0)
  744. {
  745. Info.Z_ITEM = ItemList.ToArray();
  746. if (ItemLineList.Count > 0)
  747. {
  748. Info.Z_GERNR = ItemLineList.ToArray();
  749. }
  750. else
  751. {
  752. Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1];
  753. }
  754. SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse();
  755. result = Client.CallZWMS_SK_WS_PZ(Info);
  756. if (result.Z_NULL == "N")
  757. {
  758. foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG)
  759. {
  760. IsSuccess = "N";
  761. ErrorMessage += resultItem.L_MESSAGE + "/r/n";
  762. }
  763. }
  764. }
  765. }
  766. if (IsSuccess == "N")
  767. {
  768. throw new Exception(ErrorMessage);
  769. }
  770. #endregion
  771. if (sqlString.IsEmpty())
  772. {
  773. return 0;
  774. }
  775. int count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString());
  776. return count;
  777. }
  778. #endregion、
  779. #region 退料单
  780. else if (type == "16")
  781. {
  782. #region SAP(三层结构)
  783. string IsSuccess = "";
  784. string ErrorMessage = "";
  785. string sql = $@" select Distinct A.ApplyNegCode,A.WorkPoint from ICSMOApplyNeg A
  786. where A.ApplyNegCode in ({codes})";
  787. DataTable dt = Repository().FindDataSetBySql(sql).Tables[0];
  788. for (int i = 0; i < dt.Rows.Count; i++)
  789. {
  790. var applyCode = dt.Rows[i]["ApplyNegCode"].ToString();
  791. var applyWorkPoint = dt.Rows[i]["WorkPoint"].ToString();
  792. string chksql = @"select SUM(B.Quantity) AS Quantity,SUM(B.IssueNegQuantity) AS IssueQuantity from ICSMOApplyNeg A
  793. LEFT JOIN ICSMOApplyNegDetail B ON B.ApplyNegCode=A.ApplyNegCode AND B.WorkPoint=A.WorkPoint
  794. where A.ApplyNegCode='{0}' and A.WorkPoint='{1}'
  795. GROUP BY A.ApplyNegCode,A.WorkPoint";
  796. chksql = string.Format(chksql, applyCode, applyWorkPoint);
  797. DataTable chkdt = Repository().FindDataSetBySql(chksql).Tables[0];
  798. if (Convert.ToDecimal(chkdt.Rows[0]["IssueQuantity"].ToString()) == 0)
  799. {
  800. //删除主表
  801. sqlString.Append($@"DELETE FROM ICSMOApplyNeg WHERE ApplyNegCode='{applyCode}' and WorkPoint='{applyWorkPoint}';");
  802. }
  803. SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ();
  804. SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1();
  805. Info.NEWID = Guid.NewGuid().ToString();
  806. Info.DANJU = dt.Rows[i]["ApplyNegCode"].ToString();
  807. Info.STATE = "0";
  808. List<SAPCallBackDocVPN.ZWMS_PZ> ItemList = new List<SAPCallBackDocVPN.ZWMS_PZ>();
  809. List<SAPCallBackDocVPN.ZWEBS_GERNR> ItemLineList = new List<SAPCallBackDocVPN.ZWEBS_GERNR>();
  810. Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1];
  811. sql = @" select A.ApplyNegCode,B.SAPSequence,B.InvCode,B.Sequence,B.Quantity,B.IssueNegQuantity
  812. ,ISNULL(C.BatchCode,'') AS BatchCode,B.WorkPoint,B.ID,B.WHCode from ICSMOApplyNeg A
  813. LEFT JOIN ICSMOApplyNegDetail B ON B.ApplyNegCode=A.ApplyNegCode AND B.WorkPoint=A.WorkPoint
  814. LEFT JOIN ICSExtension C ON C.ID=B.ExtensionID AND C.WorkPoint=B.WorkPoint
  815. WHERE A.ApplyNegCode='{0}' AND A.WorkPoint='{1}'";
  816. sql = string.Format(sql, dt.Rows[i]["ApplyNegCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  817. DataTable Sapdt = Repository().FindDataSetBySql(sql).Tables[0];
  818. foreach (DataRow dr in Sapdt.Rows)
  819. {
  820. string id = dr["ID"].ToString();
  821. string dnCode = dr["ApplyNegCode"].ToString();
  822. string invCode = dr["INVCode"].ToString();
  823. string workPoint = dr["WorkPoint"].ToString();
  824. string whCode = dr["WHCode"].ToString();
  825. decimal quantity = dr["Quantity"].ToDecimal();
  826. string sequence = dr["SAPSequence"].ToString();
  827. string batchCode = dr["BatchCode"].ToString();
  828. decimal dnQuantity = dr["IssueNegQuantity"].ToDecimal() == 0 ? 0 : dr["IssueNegQuantity"].ToDecimal();
  829. SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
  830. SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR();
  831. Item.DANJU = dnCode;
  832. Item.POSNR = sequence;
  833. Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["IssueNegQuantity"].ToString()), 3);
  834. ItemList.Add(Item);
  835. if (dr["BatchCode"].ToString() != "")
  836. {
  837. ItemLine.DANJU = dnCode;
  838. ItemLine.POSNR = sequence;
  839. ItemLine.MATNR = invCode;
  840. ItemLine.GERNR = batchCode;
  841. ItemLineList.Add(ItemLine);
  842. }
  843. if (Convert.ToDecimal(dr["IssueNegQuantity"].ToString()) != Convert.ToDecimal(dr["Quantity"].ToString()) || Convert.ToDecimal(dr["Quantity"].ToString()) == 0)
  844. {
  845. sqlString.Append($@"DELETE FROM ICSMOApplyNegDetail WHERE ID='{id}';");
  846. sqlString.Append($@"INSERT INTO ICSDeleteReceiptsLog VALUES(NEWID(),'{dnCode}','{sequence}','16','{workPoint}','{invCode}',{dnQuantity},null,'{MUSER}','{MUSERNAME}','{MTime}');");
  847. }
  848. }
  849. if (ItemList.Count > 0)
  850. {
  851. Info.Z_ITEM = ItemList.ToArray();
  852. if (ItemLineList.Count > 0)
  853. {
  854. Info.Z_GERNR = ItemLineList.ToArray();
  855. }
  856. else
  857. {
  858. Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1];
  859. }
  860. SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse();
  861. result = Client.CallZWMS_SK_WS_PZ(Info);
  862. if (result.Z_NULL == "N")
  863. {
  864. foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG)
  865. {
  866. IsSuccess = "N";
  867. ErrorMessage += resultItem.L_MESSAGE + "/r/n";
  868. }
  869. }
  870. }
  871. }
  872. if (IsSuccess == "N")
  873. {
  874. throw new Exception(ErrorMessage);
  875. }
  876. #endregion
  877. if (sqlString.IsEmpty())
  878. {
  879. return 0;
  880. }
  881. int count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString());
  882. return count;
  883. }
  884. #endregion
  885. #region 销售退货单
  886. else
  887. {
  888. string IsSuccess = "";
  889. string ErrorMessage = "";
  890. string sql = $@" select Distinct A.SDNCode,A.WorkPoint from ICSSDN A
  891. where A.SDNCode in ({codes})";
  892. DataTable dt = Repository().FindDataSetBySql(sql).Tables[0];
  893. for (int i = 0; i < dt.Rows.Count; i++)
  894. {
  895. string chksql = @"select SUM(Quantity) AS Quantity,SUM(SDNQuantity) AS SDNQuantity from ICSSDN
  896. where SDNCode='{0}' and WorkPoint='{1}'
  897. GROUP BY SDNCode,WorkPoint";
  898. chksql = string.Format(chksql, dt.Rows[i]["SDNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  899. DataTable chkdt = Repository().FindDataSetBySql(chksql).Tables[0];
  900. SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ Client = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ();
  901. SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ1 Info = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ1();
  902. List<SAPCallBackDispatchVPN.ZWMS_DO_HEAD> headlist = new List<SAPCallBackDispatchVPN.ZWMS_DO_HEAD>();
  903. SAPCallBackDispatchVPN.ZWMS_DO_HEAD head = new SAPCallBackDispatchVPN.ZWMS_DO_HEAD();
  904. head.VBELN = dt.Rows[i]["SDNCode"].ToString();
  905. headlist.Add(head);
  906. Info.T_HEAD = headlist.ToArray();
  907. List<SAPCallBackDispatchVPN.ZWMS_DO_ITEM> ItemList = new List<SAPCallBackDispatchVPN.ZWMS_DO_ITEM>();
  908. List<SAPCallBackDispatchVPN.ZWMS_DO_GERNR> ItemLineList = new List<SAPCallBackDispatchVPN.ZWMS_DO_GERNR>();
  909. Info.T_RETURN = new SAPCallBackDispatchVPN.ZWMS_DO_RETURN[1];
  910. sql = @" select A.ID,A.WorkPoint,A.WHCode, A.SDNCode,A.SAPSequence,A.InvCode,A.Sequence,A.Quantity,A.SDNQuantity
  911. ,ISNULL(B.BatchCode,'') AS BatchCode from ICSSDN A
  912. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  913. WHERE SDNCode='{0}' AND A.WorkPoint='{1}'";
  914. sql = string.Format(sql, dt.Rows[i]["SDNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  915. DataTable Sapdt = Repository().FindDataSetBySql(sql).Tables[0];
  916. foreach (DataRow dr in Sapdt.Rows)
  917. {
  918. string id = dr["ID"].ToString();
  919. string dnCode = dr["SDNCode"].ToString();
  920. string invCode = dr["INVCode"].ToString();
  921. string workPoint = dr["WorkPoint"].ToString();
  922. string whCode = dr["WHCode"].ToString();
  923. decimal quantity = dr["Quantity"].ToDecimal();
  924. string sequence = dr["SAPSequence"].ToString();
  925. string batchCode = dr["BatchCode"].ToString();
  926. decimal dnQuantity = dr["SDNQuantity"].ToDecimal();
  927. SAPCallBackDispatchVPN.ZWMS_DO_ITEM Item = new SAPCallBackDispatchVPN.ZWMS_DO_ITEM();
  928. SAPCallBackDispatchVPN.ZWMS_DO_GERNR ItemLine = new SAPCallBackDispatchVPN.ZWMS_DO_GERNR();
  929. Item.VBELN = dr["SDNCode"].ToString();
  930. Item.POSNR = dr["SAPSequence"].ToString();
  931. Item.LFIMG = System.Decimal.Round(Convert.ToDecimal(dr["SDNQuantity"].ToString()), 3);
  932. ItemList.Add(Item);
  933. if (dr["BatchCode"].ToString() != "")
  934. {
  935. ItemLine.VBELN = dr["SDNCode"].ToString();
  936. ItemLine.POSNR = dr["SAPSequence"].ToString();
  937. ItemLine.GERNR = dr["BatchCode"].ToString();
  938. ItemLineList.Add(ItemLine);
  939. }
  940. if (Convert.ToDecimal(dr["Quantity"].ToString()) != Convert.ToDecimal(dr["SDNQuantity"].ToString()) || Convert.ToDecimal(dr["Quantity"].ToString()) == 0)
  941. {
  942. sqlString.Append($@"DELETE FROM ICSSDN WHERE ID='{id}';");
  943. sqlString.Append($@"INSERT INTO ICSDeleteReceiptsLog VALUES(NEWID(),'{dnCode}','{sequence}','17','{workPoint}','{invCode}',{dnQuantity},null,'{MUSER}','{MUSERNAME}','{MTime}');");
  944. }
  945. }
  946. if (ItemList.Count > 0)
  947. {
  948. Info.T_ITEM = ItemList.ToArray();
  949. if (ItemLineList.Count > 0)
  950. {
  951. Info.T_GERNR = ItemLineList.ToArray();
  952. }
  953. else
  954. {
  955. Info.T_GERNR = new SAPCallBackDispatchVPN.ZWMS_DO_GERNR[1];
  956. }
  957. SAPCallBackDispatchVPN.ZWMS_SK_DO_GZResponse result = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZResponse();
  958. result = Client.CallZWMS_SK_DO_GZ(Info);
  959. foreach (SAPCallBackDispatchVPN.ZWMS_DO_RETURN resultItem in result.T_RETURN)
  960. {
  961. if (resultItem.ZFLG == "N")
  962. {
  963. IsSuccess = "N";
  964. ErrorMessage += resultItem.ZMESS + "/r/n";
  965. }
  966. }
  967. }
  968. }
  969. if (IsSuccess == "N")
  970. {
  971. throw new Exception(ErrorMessage);
  972. }
  973. if (sqlString.IsEmpty())
  974. {
  975. return 0;
  976. }
  977. int count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString());
  978. return count;
  979. }
  980. #endregion
  981. }
  982. catch (Exception ex)
  983. {
  984. throw new Exception(ex.Message);
  985. }
  986. }
  987. public string CheckReceipt(string codes, string type)
  988. {
  989. try
  990. {
  991. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  992. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  993. DateTime MTime = DateTime.Now;
  994. string check = $@"IF EXISTS (SELECT ID FROM ICSWareHouseLotInfoLog WHERE TransType='15' AND TransCode IN ({codes}) )
  995. BEGIN
  996. RAISERROR('',16,1);
  997. RETURN
  998. END;";
  999. //Repository().ExecuteBySql(check);
  1000. SqlHelper.CmdExecuteNonQueryLi(check);
  1001. string sql = String.Empty;
  1002. StringBuilder msg=new StringBuilder();
  1003. if (type == "14")
  1004. {
  1005. sql += $@"SELECT a.RCVCode as Code,a.Sequence,SUM(c.Quantity) as Quantity ,a.RCVQuantity as IssueQuantity
  1006. FROM ICSManufactureReceive a
  1007. left JOIN ICSInventoryLotDetail b ON a.RCVCode=b.TransCode AND a.Sequence=b.TransSequence
  1008. left JOIN ICSInventoryLot c ON c.LotNo=b.LotNo
  1009. WHERE a.RCVCode in ({codes})
  1010. AND b.LotNo NOT LIKE '%-%'
  1011. GROUP BY a.RCVCode,a.Sequence,a.RCVQuantity";
  1012. }
  1013. else if (type == "15")
  1014. {
  1015. sql += $@"SELECT a.InCode as Code,a.Sequence,SUM(c.Quantity) as Quantity ,a.InQuantity as IssueQuantity
  1016. FROM ICSOtherIn a
  1017. left JOIN ICSInventoryLotDetail b ON a.InCode=b.TransCode AND a.Sequence=b.TransSequence
  1018. left JOIN ICSInventoryLot c ON c.LotNo=b.LotNo
  1019. WHERE a.InCode in ({codes})
  1020. AND b.LotNo NOT LIKE '%-%'
  1021. GROUP BY a.InCode,a.Sequence,a.InQuantity";
  1022. }
  1023. else if (type == "16")
  1024. {
  1025. sql += $@"SELECT a.ApplyNegCode as Code,a.Sequence,SUM(c.Quantity) as Quantity ,a.IssueNegQuantity as IssueQuantity FROM ICSMOApplyNegDetail a
  1026. left JOIN ICSInventoryLotDetail b ON a.ApplyNegCode=b.TransCode AND a.Sequence=b.TransSequence
  1027. left JOIN ICSInventoryLot c ON c.LotNo=b.LotNo
  1028. WHERE a.ApplyNegCode in ({codes})
  1029. AND b.LotNo NOT LIKE '%-%'
  1030. GROUP BY a.ApplyNegCode,a.Sequence,a.IssueNegQuantity";
  1031. }
  1032. else if (type == "17")
  1033. {
  1034. sql += $@"SELECT a.SDNCode as Code,a.Sequence,SUM(c.Quantity) as Quantity ,a.SDNQuantity as IssueQuantity
  1035. FROM ICSSDN a
  1036. left JOIN ICSInventoryLotDetail b ON a.SDNCode=b.TransCode AND a.Sequence=b.TransSequence
  1037. left JOIN ICSInventoryLot c ON c.LotNo=b.LotNo
  1038. WHERE a.SDNCode in ({codes})
  1039. AND b.LotNo NOT LIKE '%-%'
  1040. GROUP BY a.SDNCode,a.Sequence,a.SDNQuantity";
  1041. }
  1042. if (!sql.IsEmpty())
  1043. {
  1044. var datas = Repository().FindDataSetBySql(sql).Tables[0];
  1045. if (datas.Rows.Count < 1)
  1046. return msg.ToString();
  1047. foreach (DataRow data in datas.Rows)
  1048. {
  1049. string code = data["Code"].ToString();
  1050. string sequence = data["Sequence"].ToString();
  1051. decimal quantity = data["Quantity"].ToDecimal();
  1052. decimal issueQuantity = data["IssueQuantity"].ToDecimal();
  1053. if (quantity != issueQuantity)
  1054. {
  1055. msg.Append($@"单据号:{code},行号:{sequence},已经生成条码,请先删除条码后再取消单据; ");
  1056. }
  1057. }
  1058. }
  1059. return msg.ToString();
  1060. }
  1061. catch (Exception ex)
  1062. {
  1063. throw new Exception(ex.Message);
  1064. }
  1065. }
  1066. }
  1067. }