using NFine.Repository; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data; using NFine.Code; using System.Data.Common; using NFine.Domain._03_Entity.SRM; using System.Configuration; using System.Net; using Newtonsoft.Json.Linq; using Newtonsoft.Json; using System.IO; using NFine.Domain._03_Entity.WMS; using NFine.Data.Extensions; namespace NFine.Application.WMS { public class WMSDeleteReceipts : RepositoryFactory { public int DeleteReceipt(string codes, string type) { try { string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; DateTime MTime = DateTime.Now; StringBuilder sqlString = new StringBuilder(); #region 工单领料 售后领料 if (type == "2" || type == "12") { #region SAP(三层结构) string IsSuccess = ""; string ErrorMessage = ""; string sql1 = $@"select DISTINCT A.ApplyCode from ICSMOApply A WHERE A.ApplyCode in({codes})"; DataTable Sapdt1 = Repository().FindDataSetBySql(sql1).Tables[0]; if (Sapdt1.Rows.Count == 0) { throw new Exception("单据查询失败");//单据查询失败 } for (int i = 0; i < Sapdt1.Rows.Count; i++) { var code = Sapdt1.Rows[i]["ApplyCode"].ToString(); SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ(); SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1(); Info.NEWID = Guid.NewGuid().ToString(); Info.DANJU = Sapdt1.Rows[i]["ApplyCode"].ToString(); Info.STATE = "0"; string sql = $@"select A.ID,A.ApplyCode,A.InvCode,A.Sequence,A.SAPSequence,A.Quantity,A.IssueQuantity ,ISNULL(B.BatchCode,'') AS BatchCode,A.WorkPoint,A.WHCode from ICSMOApply A LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint WHERE A.ApplyCode ='{code}'"; DataTable Sapdt = Repository().FindDataSetBySql(sql).Tables[0]; if (Sapdt.Rows.Count == 0) { throw new Exception("单据查询失败");//单据查询失败 } List ItemList = new List(); List ItemLineList = new List(); Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1]; foreach (DataRow dr in Sapdt.Rows) { string id = dr["ID"].ToString(); string dnCode = dr["ApplyCode"].ToString(); string invCode = dr["INVCode"].ToString(); string workPoint = dr["WorkPoint"].ToString(); string whCode = dr["WHCode"].ToString(); decimal quantity = dr["Quantity"].ToDecimal(); string sequence = dr["SAPSequence"].ToString(); string batchCode = dr["BatchCode"].ToString(); decimal dnQuantity = dr["IssueQuantity"].ToDecimal(); SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ(); SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR(); Item.DANJU = dr["ApplyCode"].ToString(); Item.POSNR = dr["SAPSequence"].ToString(); Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["IssueQuantity"].ToString()), 3); ItemList.Add(Item); if (dr["BatchCode"].ToString() != "") { ItemLine.DANJU = dr["ApplyCode"].ToString(); ItemLine.POSNR = dr["SAPSequence"].ToString(); ItemLine.MATNR = dr["InvCode"].ToString(); ItemLine.GERNR = dr["BatchCode"].ToString(); ItemLineList.Add(ItemLine); } if (Convert.ToDecimal(dr["IssueQuantity"].ToString()) != Convert.ToDecimal(dr["Quantity"].ToString())|| Convert.ToDecimal(dr["Quantity"].ToString())==0) { sqlString.Append($@"DELETE FROM ICSMOApply WHERE ID='{id}';"); sqlString.Append($@"INSERT INTO ICSDeleteReceiptsLog VALUES(NEWID(),'{dnCode}','{sequence}','2','{workPoint}','{invCode}',{dnQuantity},null,'{MUSER}','{MUSERNAME}','{MTime}');"); } } if (ItemList.Count > 0) { Info.Z_ITEM = ItemList.ToArray(); if (ItemLineList.Count > 0) { Info.Z_GERNR = ItemLineList.ToArray(); } else { Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1]; } SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse(); result = Client.CallZWMS_SK_WS_PZ(Info); if (result.Z_NULL == "N") { foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG) { IsSuccess = "N"; ErrorMessage += resultItem.L_MESSAGE + "/r/n"; } } } } if (IsSuccess == "N") { throw new Exception(ErrorMessage); } #endregion if (sqlString.IsEmpty()) { return 0; } int count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString()); return count; } #endregion #region 委外领料 else if (type == "5") { #region SAP(三层结构) string IsSuccess = ""; string ErrorMessage = ""; string sql1 = $@"select DISTINCT A.ApplyCode from ICSOApply A WHERE A.ApplyCode in({codes})"; DataTable Sapdt1 = Repository().FindDataSetBySql(sql1).Tables[0]; if (Sapdt1.Rows.Count == 0) { throw new Exception("单据查询失败");//单据查询失败 } for (int i = 0; i < Sapdt1.Rows.Count; i++) { var code = Sapdt1.Rows[i]["ApplyCode"].ToString(); string sql = $@" select Distinct A.ApplyCode,A.WorkPoint from ICSOApply A where A.ApplyCode='{code}'"; DataTable dt = Repository().FindDataSetBySql(sql).Tables[0]; for (int j = 0; j < dt.Rows.Count; j++) { string chksql = @"select SUM(Quantity) AS Quantity,SUM(IssueQuantity) AS IssueQuantity from ICSOApply where ApplyCode='{0}' and WorkPoint='{1}' GROUP BY ApplyCode,WorkPoint"; chksql = string.Format(chksql, dt.Rows[j]["ApplyCode"].ToString(), dt.Rows[j]["WorkPoint"].ToString()); DataTable chkdt = Repository().FindDataSetBySql(chksql).Tables[0]; SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ(); SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1(); Info.NEWID = Guid.NewGuid().ToString(); Info.DANJU = dt.Rows[j]["ApplyCode"].ToString(); Info.STATE = "0"; List ItemList = new List(); List ItemLineList = new List(); Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1]; sql = @" select A.ApplyCode,A.SAPSequence,A.InvCode,A.Sequence,A.Quantity,A.IssueQuantity ,ISNULL(B.BatchCode,'') AS BatchCode,A.ID,A.WorkPoint,A.WHCode from ICSOApply A LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint WHERE ApplyCode='{0}' AND A.WorkPoint='{1}'"; sql = string.Format(sql, dt.Rows[j]["ApplyCode"].ToString(), dt.Rows[j]["WorkPoint"].ToString()); DataTable Sapdt = Repository().FindDataSetBySql(sql).Tables[0]; foreach (DataRow dr in Sapdt.Rows) { string id = dr["ID"].ToString(); string dnCode = dr["ApplyCode"].ToString(); string invCode = dr["INVCode"].ToString(); string workPoint = dr["WorkPoint"].ToString(); string whCode = dr["WHCode"].ToString(); decimal quantity = dr["Quantity"].ToDecimal(); string sequence = dr["SAPSequence"].ToString(); string batchCode = dr["BatchCode"].ToString(); decimal dnQuantity = dr["IssueQuantity"].ToDecimal(); SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ(); SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR(); Item.DANJU = dr["ApplyCode"].ToString(); Item.POSNR = dr["SAPSequence"].ToString(); Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["IssueQuantity"].ToString()), 3); ItemList.Add(Item); ItemLine.DANJU = dr["ApplyCode"].ToString(); ItemLine.POSNR = dr["SAPSequence"].ToString(); ItemLine.MATNR = dr["InvCode"].ToString(); ItemLine.GERNR = dr["BatchCode"].ToString(); ItemLineList.Add(ItemLine); if (Convert.ToDecimal(dr["IssueQuantity"].ToString()) != Convert.ToDecimal(dr["Quantity"].ToString())||Convert.ToDecimal(dr["Quantity"].ToString()) == 0) { sqlString.Append($@"DELETE FROM ICSOApply WHERE ID='{id}';"); sqlString.Append($@"INSERT INTO ICSDeleteReceiptsLog VALUES(NEWID(),'{dnCode}','{sequence}','5','{workPoint}','{invCode}',{dnQuantity},null,'{MUSER}','{MUSERNAME}','{MTime}');"); } } if (ItemList.Count > 0) { Info.Z_ITEM = ItemList.ToArray(); if (ItemLineList.Count > 0) { Info.Z_GERNR = ItemLineList.ToArray(); } else { Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1]; } SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse(); result = Client.CallZWMS_SK_WS_PZ(Info); if (result.Z_NULL == "N") { foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG) { IsSuccess = "N"; ErrorMessage += resultItem.L_MESSAGE + "/r/n"; } } } } } if (IsSuccess == "N") { throw new Exception(ErrorMessage); } #endregion if (sqlString.IsEmpty()) { return 0; } int count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString()); return count; } #endregion #region 销售发货 else if (type == "7") { string IsSuccess = ""; string ErrorMessage = ""; string sql = $@" select Distinct A.SDNCode,A.WorkPoint from ICSSDN A where A.SDNCode in ({codes})"; DataTable dt = Repository().FindDataSetBySql(sql).Tables[0]; for (int i = 0; i < dt.Rows.Count; i++) { string chksql = @"select SUM(Quantity) AS Quantity,SUM(SDNQuantity) AS SDNQuantity from ICSSDN where SDNCode='{0}' and WorkPoint='{1}' GROUP BY SDNCode,WorkPoint"; chksql = string.Format(chksql, dt.Rows[i]["SDNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString()); DataTable chkdt = Repository().FindDataSetBySql(chksql).Tables[0]; SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ Client = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ(); SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ1 Info = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ1(); List headlist = new List(); SAPCallBackDispatchVPN.ZWMS_DO_HEAD head = new SAPCallBackDispatchVPN.ZWMS_DO_HEAD(); head.VBELN = dt.Rows[i]["SDNCode"].ToString(); headlist.Add(head); Info.T_HEAD = headlist.ToArray(); List ItemList = new List(); List ItemLineList = new List(); Info.T_RETURN = new SAPCallBackDispatchVPN.ZWMS_DO_RETURN[1]; sql = @" select A.ID,A.WorkPoint,A.WHCode, A.SDNCode,A.InvCode,A.SAPSequence,A.Sequence,A.Quantity,A.SDNQuantity ,ISNULL(B.BatchCode,'') AS BatchCode from ICSSDN A LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint WHERE SDNCode='{0}' AND A.WorkPoint='{1}'"; sql = string.Format(sql, dt.Rows[i]["SDNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString()); DataTable Sapdt = Repository().FindDataSetBySql(sql).Tables[0]; foreach (DataRow dr in Sapdt.Rows) { string id = dr["ID"].ToString(); string dnCode = dr["SDNCode"].ToString(); string invCode = dr["INVCode"].ToString(); string workPoint = dr["WorkPoint"].ToString(); string whCode = dr["WHCode"].ToString(); decimal quantity = dr["Quantity"].ToDecimal(); string sequence = dr["SAPSequence"].ToString(); string batchCode = dr["BatchCode"].ToString(); decimal dnQuantity = dr["SDNQuantity"].ToDecimal(); SAPCallBackDispatchVPN.ZWMS_DO_GERNR ItemLine = new SAPCallBackDispatchVPN.ZWMS_DO_GERNR(); SAPCallBackDispatchVPN.ZWMS_DO_ITEM Item = new SAPCallBackDispatchVPN.ZWMS_DO_ITEM(); Item.VBELN = dr["SDNCode"].ToString(); Item.POSNR = dr["SAPSequence"].ToString(); Item.LFIMG = System.Decimal.Round(Convert.ToDecimal(dr["SDNQuantity"].ToString()), 3); ItemList.Add(Item); if (dr["BatchCode"].ToString() != "") { ItemLine.VBELN = dr["SDNCode"].ToString(); ItemLine.POSNR = dr["SAPSequence"].ToString(); ItemLine.GERNR = dr["BatchCode"].ToString(); ItemLineList.Add(ItemLine); } if (Convert.ToDecimal(dr["Quantity"].ToString()) != Convert.ToDecimal(dr["SDNQuantity"].ToString()) || Convert.ToDecimal(dr["Quantity"].ToString()) == 0) { sqlString.Append($@"DELETE FROM ICSSDN WHERE ID='{id}';"); sqlString.Append($@"INSERT INTO ICSDeleteReceiptsLog VALUES(NEWID(),'{dnCode}','{sequence}','7','{workPoint}','{invCode}',{dnQuantity},null,'{MUSER}','{MUSERNAME}','{MTime}');"); } } if (ItemList.Count > 0) { Info.T_ITEM = ItemList.ToArray(); if (ItemLineList.Count > 0) { Info.T_GERNR = ItemLineList.ToArray(); } SAPCallBackDispatchVPN.ZWMS_SK_DO_GZResponse result = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZResponse(); result = Client.CallZWMS_SK_DO_GZ(Info); foreach (SAPCallBackDispatchVPN.ZWMS_DO_RETURN resultItem in result.T_RETURN) { if (resultItem.ZFLG == "N") { IsSuccess = "N"; ErrorMessage += resultItem.ZMESS + "/r/n"; } } } } if (IsSuccess == "N") { throw new Exception(ErrorMessage); } if (sqlString.IsEmpty()) { return 0; } int count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString()); return count; } #endregion #region 其他出库 else if (type == "8") { string IsSuccess = ""; string ErrorMessage = ""; string sql = $@" select Distinct A.OutCode,A.WorkPoint from ICSOtherOut A where A.OutCode in ({codes})"; DataTable dt = Repository().FindDataSetBySql(sql).Tables[0]; for (int i = 0; i < dt.Rows.Count; i++) { string chksql = @"select SUM(Quantity) AS Quantity,SUM(OutQuantity) AS OutQuantity from ICSOtherOut where OutCode='{0}' and WorkPoint='{1}' GROUP BY OutCode,WorkPoint"; chksql = string.Format(chksql, dt.Rows[i]["OutCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString()); DataTable chkdt = Repository().FindDataSetBySql(chksql).Tables[0]; if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) != Convert.ToDecimal(chkdt.Rows[0]["OutQuantity"])) { SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ(); SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1(); Info.NEWID = Guid.NewGuid().ToString(); Info.DANJU = dt.Rows[i]["OutCode"].ToString(); Info.STATE = "0"; List ItemList = new List(); List ItemLineList = new List(); Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1]; sql = @"select A.ID, A.OutCode,A.SAPSequence,A.InvCode,A.Sequence,A.Quantity,A.OutQuantity ,ISNULL(B.BatchCode,'') AS BatchCode,A.WorkPoint,A.WHCode from ICSOtherOut A LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint WHERE OutCode='{0}' AND A.WorkPoint='{1}'"; sql = string.Format(sql, dt.Rows[i]["OutCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString()); DataTable Sapdt = Repository().FindDataSetBySql(sql).Tables[0]; foreach (DataRow dr in Sapdt.Rows) { string id = dr["ID"].ToString(); string dnCode = dr["OutCode"].ToString(); string invCode = dr["INVCode"].ToString(); string workPoint = dr["WorkPoint"].ToString(); string whCode = dr["WHCode"].ToString(); decimal quantity = dr["Quantity"].ToDecimal(); string sequence = dr["SAPSequence"].ToString(); string batchCode = dr["BatchCode"].ToString(); decimal dnQuantity = dr["OutQuantity"].ToDecimal(); SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ(); SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR(); Item.DANJU = dr["OutCode"].ToString(); Item.POSNR = dr["SAPSequence"].ToString(); Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["OutQuantity"].ToString()), 3); ItemList.Add(Item); if (dr["BatchCode"].ToString() != "") { ItemLine.DANJU = dr["OutCode"].ToString(); ItemLine.POSNR = dr["SAPSequence"].ToString(); ItemLine.MATNR = dr["InvCode"].ToString(); ItemLine.GERNR = dr["BatchCode"].ToString(); ItemLineList.Add(ItemLine); } if (Convert.ToDecimal(dr["Quantity"].ToString()) != Convert.ToDecimal(dr["OutQuantity"].ToString()) || Convert.ToDecimal(dr["Quantity"].ToString()) == 0) { sqlString.Append($@"DELETE FROM ICSOtherOut WHERE ID='{id}';"); sqlString.Append($@"INSERT INTO ICSDeleteReceiptsLog VALUES(NEWID(),'{dnCode}','{sequence}','8','{workPoint}','{invCode}',{dnQuantity},null,'{MUSER}','{MUSERNAME}','{MTime}');"); } } if (ItemList.Count > 0) { Info.Z_ITEM = ItemList.ToArray(); if (ItemLineList.Count > 0) { Info.Z_GERNR = ItemLineList.ToArray(); } else { Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1]; } SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse(); result = Client.CallZWMS_SK_WS_PZ(Info); if (result.Z_NULL == "N") { foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG) { IsSuccess = "N"; ErrorMessage += resultItem.L_MESSAGE + "/r/n"; } } } } } if (IsSuccess == "N") { throw new Exception(ErrorMessage); } if (sqlString.IsEmpty()) { return 0; } int count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString()); return count; } #endregion #region 物料调拨 else if (type == "10") { string IsSuccess = ""; string ErrorMessage = ""; string sql = $@" select Distinct A.TransferNO,A.WorkPoint from ICSTransfer A where A.TransferNO in ({codes})"; DataTable dt = Repository().FindDataSetBySql(sql).Tables[0]; for (int i = 0; i < dt.Rows.Count; i++) { string chksql = @"select SUM(Quantity) AS Quantity,SUM(TransferQuantity) AS TransferQuantity from ICSTransfer where TransferNO='{0}' and WorkPoint='{1}' GROUP BY TransferNO,WorkPoint"; chksql = string.Format(chksql, dt.Rows[i]["TransferNO"].ToString(), dt.Rows[i]["WorkPoint"].ToString()); DataTable chkdt = Repository().FindDataSetBySql(chksql).Tables[0]; SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ(); SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1(); Info.NEWID = Guid.NewGuid().ToString(); Info.DANJU = dt.Rows[i]["TransferNO"].ToString(); Info.STATE = "0"; List ItemList = new List(); List ItemLineList = new List(); Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1]; sql = @" select A.ID,A.WorkPoint,A.FromWarehouseCode, A.TransferNO,A.SAPSequence,A.InvCode,A.Sequence,A.Quantity,A.TransferQuantity ,ISNULL(B.BatchCode,'') AS BatchCode from ICSTransfer A LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint WHERE TransferNO='{0}' AND A.WorkPoint='{1}'"; sql = string.Format(sql, dt.Rows[i]["TransferNO"].ToString(), dt.Rows[i]["WorkPoint"].ToString()); DataTable Sapdt = Repository().FindDataSetBySql(sql).Tables[0]; foreach (DataRow dr in Sapdt.Rows) { string id = dr["ID"].ToString(); string dnCode = dr["TransferNO"].ToString(); string invCode = dr["INVCode"].ToString(); string workPoint = dr["WorkPoint"].ToString(); string whCode = dr["FromWarehouseCode"].ToString(); decimal quantity = dr["Quantity"].ToDecimal(); string sequence = dr["SAPSequence"].ToString(); string batchCode = dr["BatchCode"].ToString(); decimal dnQuantity = dr["TransferQuantity"].ToDecimal(); SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ(); SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR(); Item.DANJU = dr["TransferNO"].ToString(); Item.POSNR = dr["SAPSequence"].ToString(); Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["TransferQuantity"].ToString()), 3); ItemList.Add(Item); if (dr["BatchCode"].ToString() != "") { ItemLine.DANJU = dr["TransferNO"].ToString(); ItemLine.POSNR = dr["SAPSequence"].ToString(); ItemLine.MATNR = dr["InvCode"].ToString(); ItemLine.GERNR = dr["BatchCode"].ToString(); ItemLineList.Add(ItemLine); } if (Convert.ToDecimal(dr["Quantity"].ToString()) != Convert.ToDecimal(dr["TransferQuantity"].ToString()) || Convert.ToDecimal(dr["Quantity"].ToString()) == 0) { sqlString.Append($@"DELETE FROM ICSTransfer WHERE ID='{id}';"); sqlString.Append($@"INSERT INTO ICSDeleteReceiptsLog VALUES(NEWID(),'{dnCode}','{sequence}','10','{workPoint}','{invCode}',{dnQuantity},null,'{MUSER}','{MUSERNAME}','{MTime}');"); } } if (ItemList.Count > 0) { Info.Z_ITEM = ItemList.ToArray(); if (ItemLineList.Count > 0) { Info.Z_GERNR = ItemLineList.ToArray(); } else { Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1]; } SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse(); result = Client.CallZWMS_SK_WS_PZ(Info); if (result.Z_NULL == "N") { foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG) { IsSuccess = "N"; ErrorMessage += resultItem.L_MESSAGE + "/r/n"; } } } } if (IsSuccess == "N") { throw new Exception(ErrorMessage); } if (sqlString.IsEmpty()) { return 0; } int count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString()); return count; } #endregion #region 检验合格单 else if (type == "13") { #region SAP(检验合格单为两层结构 一行对应一个序列号) string IsSuccess = ""; string ErrorMessage = ""; string sql = $@" select A.DNCode,A.WorkPoint,Quantity,A.Sequence,A.WHCode,A.ID,A.INVCode,A.RCVQuantity from ICSDeliveryNotice A where A.DNCode in ({codes})"; DataTable dt = Repository().FindDataSetBySql(sql).Tables[0]; for (int i = 0; i < dt.Rows.Count; i++) { string chksql = @"select SUM(Quantity) AS Quantity,SUM(RCVQuantity) AS RCVQuantity from ICSDeliveryNotice where DNCode='{0}' and WorkPoint='{1}' GROUP BY DNCode,WorkPoint"; chksql = string.Format(chksql, dt.Rows[i]["DNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString()); DataTable chkdt = Repository().FindDataSetBySql(chksql).Tables[0]; sql = @"select A.DNCode, CASE WHEN SUM(Convert(decimal(18,6),A.SAPSequence)) IS NULL THEN SUM(A.RCVQuantity) ELSE SUM(Convert(decimal(18,6),A.SAPSequence)) END AS RCVQuantity,B.BatchCode from ICSDeliveryNotice A LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint WHERE DNCode='{0}' AND A.WorkPoint='{1}' GROUP BY A.DNCode,B.BatchCode"; sql = string.Format(sql, dt.Rows[i]["DNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString()); DataTable Sapdt = Repository().FindDataSetBySql(sql).Tables[0]; if (Sapdt.Rows.Count == 0) { throw new Exception("单据查询失败");//单据查询失败 } string id = dt.Rows[i]["ID"].ToString(); string dnCode = dt.Rows[i]["DNCode"].ToString(); string invCode = dt.Rows[i]["INVCode"].ToString(); string workPoint = dt.Rows[i]["WorkPoint"].ToString(); string whCode = dt.Rows[i]["WHCode"].ToString(); string quantity = dt.Rows[i]["Quantity"].ToString(); string sequence = dt.Rows[i]["Sequence"].ToString(); decimal dnQuantity = dt.Rows[i]["RCVQuantity"].ToDecimal(); sqlString.Append($@"DELETE FROM ICSDeliveryNotice WHERE ID='{id}';"); sqlString.Append($@"INSERT INTO ICSDeleteReceiptsLog VALUES(NEWID(),'{dnCode}','{sequence}','13','{workPoint}','{invCode}',{dnQuantity},null,'{MUSER}','{MUSERNAME}','{MTime}');"); SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU Client = new SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU(); SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU1 Info = new SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU1(); Info.NEWID = Guid.NewGuid().ToString(); Info.PRUEFLOS = Sapdt.Rows[0]["DNCode"].ToString(); Info.L_LME = System.Decimal.Round(Convert.ToDecimal(Sapdt.Rows[0]["RCVQuantity"].ToString()), 3); Info.SERNP = Sapdt.Rows[0]["BatchCode"].ToString(); Info.Z_GERNR = new SAPCallBackJYHGDVPN.ZWEBS_GERNR[0]; SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKUResponse result = new SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKUResponse(); result = Client.CallZWMS_SK_WS_RUKU(Info); if (result.Z_NULL == "N") { IsSuccess = "N"; ErrorMessage += result.L_MESSAGE; } } if (IsSuccess == "N") { throw new Exception(ErrorMessage); } #endregion if (sqlString.IsEmpty()) { return 0; } int count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString()); return count; } #endregion #region 机加工入库 else if (type == "14") { string IsSuccess = ""; string ErrorMessage = ""; string sql = $@" select Distinct A.RCVCode,A.WorkPoint from ICSManufactureReceive A where A.RCVCode in ({codes})"; DataTable dt = Repository().FindDataSetBySql(sql).Tables[0]; for (int i = 0; i < dt.Rows.Count; i++) { string chksql = @"select SUM(Quantity) AS Quantity,SUM(RCVQuantity) AS RCVQuantity from ICSManufactureReceive where RCVCode='{0}' and WorkPoint='{1}' GROUP BY RCVCode,WorkPoint"; chksql = string.Format(chksql, dt.Rows[i]["RCVCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString()); DataTable chkdt = Repository().FindDataSetBySql(chksql).Tables[0]; SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ(); SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1(); Info.NEWID = Guid.NewGuid().ToString(); Info.DANJU = dt.Rows[i]["RCVCode"].ToString(); Info.STATE = "0"; List ItemList = new List(); List ItemLineList = new List(); Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1]; sql = @"select A.ID,A.WorkPoint,A.WHCode,A.RCVCode,A.SAPSequence,A.InvCode,A.Sequence,A.Quantity,A.RCVQuantity ,ISNULL(B.BatchCode,'') AS BatchCode from ICSManufactureReceive A LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint WHERE RCVCode='{0}' AND A.WorkPoint='{1}'"; sql = string.Format(sql, dt.Rows[i]["RCVCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString()); DataTable Sapdt = Repository().FindDataSetBySql(sql).Tables[0]; foreach (DataRow dr in Sapdt.Rows) { string id = dr["ID"].ToString(); string dnCode = dr["RCVCode"].ToString(); string invCode = dr["INVCode"].ToString(); string workPoint = dr["WorkPoint"].ToString(); string whCode = dr["WHCode"].ToString(); decimal quantity = dr["Quantity"].ToDecimal(); string sequence = dr["SAPSequence"].ToString(); string batchCode = dr["BatchCode"].ToString(); decimal dnQuantity = dr["RCVQuantity"].ToDecimal(); SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ(); SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR(); Item.DANJU = dr["RCVCode"].ToString(); Item.POSNR = dr["SAPSequence"].ToString(); Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["RCVQuantity"].ToString()), 3); ItemList.Add(Item); if (dr["BatchCode"].ToString() != "") { ItemLine.DANJU = dr["RCVCode"].ToString(); ItemLine.POSNR = dr["SAPSequence"].ToString(); ItemLine.MATNR = dr["InvCode"].ToString(); ItemLine.GERNR = dr["BatchCode"].ToString(); ItemLineList.Add(ItemLine); } if (Convert.ToDecimal(dr["Quantity"].ToString()) != Convert.ToDecimal(dr["RCVQuantity"].ToString()) || Convert.ToDecimal(dr["Quantity"].ToString()) == 0) { sqlString.Append($@"DELETE FROM ICSManufactureReceive WHERE ID='{id}';"); sqlString.Append($@"INSERT INTO ICSDeleteReceiptsLog VALUES(NEWID(),'{dnCode}','{sequence}','14','{workPoint}','{invCode}',{dnQuantity},null,'{MUSER}','{MUSERNAME}','{MTime}');"); } } if (ItemList.Count > 0) { Info.Z_ITEM = ItemList.ToArray(); if (ItemLineList.Count > 0) { Info.Z_GERNR = ItemLineList.ToArray(); } else { Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1]; } SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse(); result = Client.CallZWMS_SK_WS_PZ(Info); if (result.Z_NULL == "N") { foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG) { IsSuccess = "N"; ErrorMessage += resultItem.L_MESSAGE + "/r/n"; } } } } if (IsSuccess == "N") { throw new Exception(ErrorMessage); } if (sqlString.IsEmpty()) { return 0; } int count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString()); return count; } #endregion #region 成本中心退料 else if (type == "15") { #region SAP(三层结构) string IsSuccess = ""; string ErrorMessage = ""; string sql = $@" select Distinct A.InCode,A.WorkPoint from ICSOtherIn A where A.InCode in ({codes})"; DataTable dt = Repository().FindDataSetBySql(sql).Tables[0]; for (int i = 0; i < dt.Rows.Count; i++) { var applyCode = dt.Rows[i]["InCode"].ToString(); var applyWorkPoint = dt.Rows[i]["WorkPoint"].ToString(); string chksql = @"select SUM(Quantity) AS Quantity,SUM(InQuantity) AS InQuantity from ICSOtherIn where InCode='{0}' and WorkPoint='{1}' GROUP BY InCode,WorkPoint"; chksql = string.Format(chksql, applyCode, applyWorkPoint); DataTable chkdt = Repository().FindDataSetBySql(chksql).Tables[0]; SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ(); SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1(); Info.NEWID = Guid.NewGuid().ToString(); Info.DANJU = dt.Rows[i]["InCode"].ToString(); Info.STATE = "0"; List ItemList = new List(); List ItemLineList = new List(); Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1]; sql = @"select A.InCode,A.SAPSequence,A.InvCode,A.Sequence,A.Quantity,A.InQuantity ,ISNULL(B.BatchCode,'') AS BatchCode,A.ID,A.WHCode,A.WorkPoint from ICSOtherIn A LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint WHERE InCode='{0}' AND A.WorkPoint='{1}'"; sql = string.Format(sql, dt.Rows[i]["InCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString()); DataTable Sapdt = Repository().FindDataSetBySql(sql).Tables[0]; foreach (DataRow dr in Sapdt.Rows) { string id = dr["ID"].ToString(); string dnCode = dr["InCode"].ToString(); string invCode = dr["INVCode"].ToString(); string workPoint = dr["WorkPoint"].ToString(); string whCode = dr["WHCode"].ToString(); decimal quantity = dr["Quantity"].ToDecimal(); string sequence = dr["SAPSequence"].ToString(); string batchCode = dr["BatchCode"].ToString(); decimal dnQuantity = dr["InQuantity"].ToDecimal(); SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ(); SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR(); Item.DANJU = dnCode; Item.POSNR = sequence; Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["InQuantity"].ToString()), 3); ; ItemList.Add(Item); if (dr["BatchCode"].ToString() != "") { ItemLine.DANJU = dnCode; ItemLine.POSNR = sequence; ItemLine.MATNR = invCode; ItemLine.GERNR = batchCode; ItemLineList.Add(ItemLine); } if (Convert.ToDecimal(dr["InQuantity"].ToString()) != Convert.ToDecimal(dr["Quantity"].ToString()) || Convert.ToDecimal(dr["Quantity"].ToString()) == 0) { sqlString.Append($@"DELETE FROM ICSOtherIn WHERE ID='{id}';"); sqlString.Append($@"INSERT INTO ICSDeleteReceiptsLog VALUES(NEWID(),'{dnCode}','{sequence}','15','{workPoint}','{invCode}',{dnQuantity},null,'{MUSER}','{MUSERNAME}','{MTime}');"); } } if (ItemList.Count > 0) { Info.Z_ITEM = ItemList.ToArray(); if (ItemLineList.Count > 0) { Info.Z_GERNR = ItemLineList.ToArray(); } else { Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1]; } SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse(); result = Client.CallZWMS_SK_WS_PZ(Info); if (result.Z_NULL == "N") { foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG) { IsSuccess = "N"; ErrorMessage += resultItem.L_MESSAGE + "/r/n"; } } } } if (IsSuccess == "N") { throw new Exception(ErrorMessage); } #endregion if (sqlString.IsEmpty()) { return 0; } int count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString()); return count; } #endregion、 #region 退料单 else if (type == "16") { #region SAP(三层结构) string IsSuccess = ""; string ErrorMessage = ""; string sql = $@" select Distinct A.ApplyNegCode,A.WorkPoint from ICSMOApplyNeg A where A.ApplyNegCode in ({codes})"; DataTable dt = Repository().FindDataSetBySql(sql).Tables[0]; for (int i = 0; i < dt.Rows.Count; i++) { var applyCode = dt.Rows[i]["ApplyNegCode"].ToString(); var applyWorkPoint = dt.Rows[i]["WorkPoint"].ToString(); string chksql = @"select SUM(B.Quantity) AS Quantity,SUM(B.IssueNegQuantity) AS IssueQuantity from ICSMOApplyNeg A LEFT JOIN ICSMOApplyNegDetail B ON B.ApplyNegCode=A.ApplyNegCode AND B.WorkPoint=A.WorkPoint where A.ApplyNegCode='{0}' and A.WorkPoint='{1}' GROUP BY A.ApplyNegCode,A.WorkPoint"; chksql = string.Format(chksql, applyCode, applyWorkPoint); DataTable chkdt = Repository().FindDataSetBySql(chksql).Tables[0]; if (Convert.ToDecimal(chkdt.Rows[0]["IssueQuantity"].ToString()) == 0) { //删除主表 sqlString.Append($@"DELETE FROM ICSMOApplyNeg WHERE ApplyNegCode='{applyCode}' and WorkPoint='{applyWorkPoint}';"); } SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ(); SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1(); Info.NEWID = Guid.NewGuid().ToString(); Info.DANJU = dt.Rows[i]["ApplyNegCode"].ToString(); Info.STATE = "0"; List ItemList = new List(); List ItemLineList = new List(); Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1]; sql = @" select A.ApplyNegCode,B.SAPSequence,B.InvCode,B.Sequence,B.Quantity,B.IssueNegQuantity ,ISNULL(C.BatchCode,'') AS BatchCode,B.WorkPoint,B.ID,B.WHCode from ICSMOApplyNeg A LEFT JOIN ICSMOApplyNegDetail B ON B.ApplyNegCode=A.ApplyNegCode AND B.WorkPoint=A.WorkPoint LEFT JOIN ICSExtension C ON C.ID=B.ExtensionID AND C.WorkPoint=B.WorkPoint WHERE A.ApplyNegCode='{0}' AND A.WorkPoint='{1}'"; sql = string.Format(sql, dt.Rows[i]["ApplyNegCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString()); DataTable Sapdt = Repository().FindDataSetBySql(sql).Tables[0]; foreach (DataRow dr in Sapdt.Rows) { string id = dr["ID"].ToString(); string dnCode = dr["ApplyNegCode"].ToString(); string invCode = dr["INVCode"].ToString(); string workPoint = dr["WorkPoint"].ToString(); string whCode = dr["WHCode"].ToString(); decimal quantity = dr["Quantity"].ToDecimal(); string sequence = dr["SAPSequence"].ToString(); string batchCode = dr["BatchCode"].ToString(); decimal dnQuantity = dr["IssueNegQuantity"].ToDecimal() == 0 ? 0 : dr["IssueNegQuantity"].ToDecimal(); SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ(); SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR(); Item.DANJU = dnCode; Item.POSNR = sequence; Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["IssueNegQuantity"].ToString()), 3); ItemList.Add(Item); if (dr["BatchCode"].ToString() != "") { ItemLine.DANJU = dnCode; ItemLine.POSNR = sequence; ItemLine.MATNR = invCode; ItemLine.GERNR = batchCode; ItemLineList.Add(ItemLine); } if (Convert.ToDecimal(dr["IssueNegQuantity"].ToString()) != Convert.ToDecimal(dr["Quantity"].ToString()) || Convert.ToDecimal(dr["Quantity"].ToString()) == 0) { sqlString.Append($@"DELETE FROM ICSMOApplyNegDetail WHERE ID='{id}';"); sqlString.Append($@"INSERT INTO ICSDeleteReceiptsLog VALUES(NEWID(),'{dnCode}','{sequence}','16','{workPoint}','{invCode}',{dnQuantity},null,'{MUSER}','{MUSERNAME}','{MTime}');"); } } if (ItemList.Count > 0) { Info.Z_ITEM = ItemList.ToArray(); if (ItemLineList.Count > 0) { Info.Z_GERNR = ItemLineList.ToArray(); } else { Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1]; } SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse(); result = Client.CallZWMS_SK_WS_PZ(Info); if (result.Z_NULL == "N") { foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG) { IsSuccess = "N"; ErrorMessage += resultItem.L_MESSAGE + "/r/n"; } } } } if (IsSuccess == "N") { throw new Exception(ErrorMessage); } #endregion if (sqlString.IsEmpty()) { return 0; } int count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString()); return count; } #endregion #region 销售退货单 else { string IsSuccess = ""; string ErrorMessage = ""; string sql = $@" select Distinct A.SDNCode,A.WorkPoint from ICSSDN A where A.SDNCode in ({codes})"; DataTable dt = Repository().FindDataSetBySql(sql).Tables[0]; for (int i = 0; i < dt.Rows.Count; i++) { string chksql = @"select SUM(Quantity) AS Quantity,SUM(SDNQuantity) AS SDNQuantity from ICSSDN where SDNCode='{0}' and WorkPoint='{1}' GROUP BY SDNCode,WorkPoint"; chksql = string.Format(chksql, dt.Rows[i]["SDNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString()); DataTable chkdt = Repository().FindDataSetBySql(chksql).Tables[0]; SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ Client = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ(); SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ1 Info = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ1(); List headlist = new List(); SAPCallBackDispatchVPN.ZWMS_DO_HEAD head = new SAPCallBackDispatchVPN.ZWMS_DO_HEAD(); head.VBELN = dt.Rows[i]["SDNCode"].ToString(); headlist.Add(head); Info.T_HEAD = headlist.ToArray(); List ItemList = new List(); List ItemLineList = new List(); Info.T_RETURN = new SAPCallBackDispatchVPN.ZWMS_DO_RETURN[1]; sql = @" select A.ID,A.WorkPoint,A.WHCode, A.SDNCode,A.SAPSequence,A.InvCode,A.Sequence,A.Quantity,A.SDNQuantity ,ISNULL(B.BatchCode,'') AS BatchCode from ICSSDN A LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint WHERE SDNCode='{0}' AND A.WorkPoint='{1}'"; sql = string.Format(sql, dt.Rows[i]["SDNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString()); DataTable Sapdt = Repository().FindDataSetBySql(sql).Tables[0]; foreach (DataRow dr in Sapdt.Rows) { string id = dr["ID"].ToString(); string dnCode = dr["SDNCode"].ToString(); string invCode = dr["INVCode"].ToString(); string workPoint = dr["WorkPoint"].ToString(); string whCode = dr["WHCode"].ToString(); decimal quantity = dr["Quantity"].ToDecimal(); string sequence = dr["SAPSequence"].ToString(); string batchCode = dr["BatchCode"].ToString(); decimal dnQuantity = dr["SDNQuantity"].ToDecimal(); SAPCallBackDispatchVPN.ZWMS_DO_ITEM Item = new SAPCallBackDispatchVPN.ZWMS_DO_ITEM(); SAPCallBackDispatchVPN.ZWMS_DO_GERNR ItemLine = new SAPCallBackDispatchVPN.ZWMS_DO_GERNR(); Item.VBELN = dr["SDNCode"].ToString(); Item.POSNR = dr["SAPSequence"].ToString(); Item.LFIMG = System.Decimal.Round(Convert.ToDecimal(dr["SDNQuantity"].ToString()), 3); ItemList.Add(Item); if (dr["BatchCode"].ToString() != "") { ItemLine.VBELN = dr["SDNCode"].ToString(); ItemLine.POSNR = dr["SAPSequence"].ToString(); ItemLine.GERNR = dr["BatchCode"].ToString(); ItemLineList.Add(ItemLine); } if (Convert.ToDecimal(dr["Quantity"].ToString()) != Convert.ToDecimal(dr["SDNQuantity"].ToString()) || Convert.ToDecimal(dr["Quantity"].ToString()) == 0) { sqlString.Append($@"DELETE FROM ICSSDN WHERE ID='{id}';"); sqlString.Append($@"INSERT INTO ICSDeleteReceiptsLog VALUES(NEWID(),'{dnCode}','{sequence}','17','{workPoint}','{invCode}',{dnQuantity},null,'{MUSER}','{MUSERNAME}','{MTime}');"); } } if (ItemList.Count > 0) { Info.T_ITEM = ItemList.ToArray(); if (ItemLineList.Count > 0) { Info.T_GERNR = ItemLineList.ToArray(); } else { Info.T_GERNR = new SAPCallBackDispatchVPN.ZWMS_DO_GERNR[1]; } SAPCallBackDispatchVPN.ZWMS_SK_DO_GZResponse result = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZResponse(); result = Client.CallZWMS_SK_DO_GZ(Info); foreach (SAPCallBackDispatchVPN.ZWMS_DO_RETURN resultItem in result.T_RETURN) { if (resultItem.ZFLG == "N") { IsSuccess = "N"; ErrorMessage += resultItem.ZMESS + "/r/n"; } } } } if (IsSuccess == "N") { throw new Exception(ErrorMessage); } if (sqlString.IsEmpty()) { return 0; } int count = SqlHelper.CmdExecuteNonQueryLi(sqlString.ToString()); return count; } #endregion } catch (Exception ex) { throw new Exception(ex.Message); } } public string CheckReceipt(string codes, string type) { try { string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; DateTime MTime = DateTime.Now; string sql = string.Empty; StringBuilder msg=new StringBuilder(); if (type == "14") { sql = $@"SELECT a.RCVCode as Code,a.Sequence,SUM(c.Quantity) as Quantity ,a.RCVQuantity as IssueQuantity FROM ICSManufactureReceive a left JOIN ICSInventoryLotDetail b ON a.RCVCode=b.TransCode AND a.Sequence=b.TransSequence left JOIN ICSInventoryLot c ON c.LotNo=b.LotNo WHERE a.RCVCode in ({codes}) AND b.LotNo NOT LIKE '%-%' GROUP BY a.RCVCode,a.Sequence,a.RCVQuantity"; } else if (type == "15") { sql = $@"SELECT a.InCode as Code,a.Sequence,SUM(c.Quantity) as Quantity ,a.InQuantity as IssueQuantity FROM ICSOtherIn a left JOIN ICSInventoryLotDetail b ON a.InCode=b.TransCode AND a.Sequence=b.TransSequence left JOIN ICSInventoryLot c ON c.LotNo=b.LotNo WHERE a.InCode in ({codes}) AND b.LotNo NOT LIKE '%-%' GROUP BY a.InCode,a.Sequence,a.InQuantity"; } else if (type == "16") { sql = $@"SELECT a.ApplyNegCode as Code,a.Sequence,SUM(c.Quantity) as Quantity ,a.IssueNegQuantity as IssueQuantity FROM ICSMOApplyNegDetail a left JOIN ICSInventoryLotDetail b ON a.ApplyNegCode=b.TransCode AND a.Sequence=b.TransSequence left JOIN ICSInventoryLot c ON c.LotNo=b.LotNo WHERE a.ApplyNegCode in ({codes}) AND b.LotNo NOT LIKE '%-%' GROUP BY a.ApplyNegCode,a.Sequence,a.IssueNegQuantity"; } else if (type == "17") { sql = $@"SELECT a.SDNCode as Code,a.Sequence,SUM(c.Quantity) as Quantity ,a.SDNQuantity as IssueQuantity FROM ICSSDN a left JOIN ICSInventoryLotDetail b ON a.SDNCode=b.TransCode AND a.Sequence=b.TransSequence left JOIN ICSInventoryLot c ON c.LotNo=b.LotNo WHERE a.SDNCode in ({codes}) AND b.LotNo NOT LIKE '%-%' GROUP BY a.SDNCode,a.Sequence,a.SDNQuantity"; } if (!sql.IsEmpty()) { var datas = Repository().FindDataSetBySql(sql).Tables[0]; if (datas.Rows.Count < 1) return msg.ToString(); foreach (DataRow data in datas.Rows) { string code = data["Code"].ToString(); string sequence = data["Sequence"].ToString(); decimal quantity = data["Quantity"].ToDecimal(); decimal issueQuantity = data["IssueQuantity"].ToDecimal(); if (quantity != issueQuantity) { msg.Append($@"单据号:{code},行号:{sequence},已经生成条码,请先删除条码后再取消单据; "); } } } return msg.ToString(); } catch (Exception ex) { throw new Exception(ex.Message); } } } }