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

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