From 48991a1b0132f3385a5d1f607b4d68caef3f0eef Mon Sep 17 00:00:00 2001 From: lilili Date: Wed, 9 Aug 2023 09:57:22 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=8B=A3=E6=96=99=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=88=86=E9=85=8D=E6=9D=A1?= =?UTF-8?q?=E7=A0=81=E6=8B=A3=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NFine.Application/WMS/PickMaterialApp.cs | 1088 ++++++++++++----- 1 file changed, 797 insertions(+), 291 deletions(-) diff --git a/WMS-BS/NFine.Application/WMS/PickMaterialApp.cs b/WMS-BS/NFine.Application/WMS/PickMaterialApp.cs index 612eb02..37e9c03 100644 --- a/WMS-BS/NFine.Application/WMS/PickMaterialApp.cs +++ b/WMS-BS/NFine.Application/WMS/PickMaterialApp.cs @@ -1661,14 +1661,513 @@ left join (select distinct TransCode,TransType,WorkPoint from dbo.ICSWareHouseLo string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; ID = string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(','); + string sqls = ""; #region sql #endregion - string sqls = ""; - if (Type == "1") + //调拨单拣料增加逻辑,如果memo字段有条码信息,那么拣料的条码为备注条码,否则走正常逻辑 + if (Type == "10") { - #region 工单备料sql - sqls = @" SELECT + string dataString = $@"select a.Memo,a.FromWarehouseCode,a.Quantity,a.TransferQuantity,a.InvCode,a.TransferNO,a.SAPSequence,a.Sequence FROM ICSTransfer a + WHERE a.TransferNO in ({ID}) AND a.WorkPoint = '{WorkPoint}' + AND ISNULL(a.Quantity, 0)>ISNULL(a.TransferQuantity, 0) + AND a.Memo is not null AND a.Memo!='' "; + + var datasetModel = Repository().FindDataSetBySql(dataString); + DataTable table1 = null; + DataTable table = null; + StringBuilder updateString = new StringBuilder(); + string sqlString = String.Empty; + if (datasetModel.Tables[0].Rows.Count != 0) + { + DataTable tableModel = datasetModel.Tables[0]; + + + + if (tableModel.Rows.Count > 0) + { + //循环验证条码信息是否与单据信息相符 + for (int i = 0; i < tableModel.Rows.Count; i++) + { + string transCode = tableModel.Rows[i]["TransferNO"].ToString(); + string lotNo = tableModel.Rows[i]["Memo"].ToString(); + string whCode = tableModel.Rows[i]["FromWarehouseCode"].ToString(); + string sequence = tableModel.Rows[i]["Sequence"].ToString(); + //验证信息 + updateString.Append($@"IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo='{lotNo}' AND a.WorkPoint='{WorkPoint}') + BEGIN + RAISERROR('条码{lotNo},不存在',16,1); + RETURN + END; + IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{tableModel.Rows[i]["Memo"]}' AND a.WorkPoint='{WorkPoint}' AND a.WarehouseCode='{whCode}') + BEGIN + RAISERROR('条码{lotNo}和单据{transCode}行{tableModel.Rows[i]["SAPSequence"]}仓库不一致',16,1); + RETURN + END; + IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{lotNo}' AND a.WorkPoint='{WorkPoint}' AND a.WarehouseCode='{whCode}' AND a.Quantity>A.LockQuantity+'{tableModel.Rows[i]["Quantity"]}') + BEGIN + RAISERROR('条码{lotNo}的库存可分配数量小于单据数量',16,1); + RETURN + END; + IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo='2023052500001' AND a.WorkPoint='1701' AND InvCode='20064648') + BEGIN + RAISERROR('条码{lotNo}和单据{transCode}行号{tableModel.Rows[i]["SAPSequence"]}对应的物料不一致',16,1); + RETURN + END;" + ); + + updateString.Append($@" INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode, + FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity, + Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID, + ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName, + MTIME,WorkPoint,EATTRIBUTE1) + SELECT NEWID(),NEWID(),'{transCode}','{sequence}',a.LotNo ,a.InvCode , + a.WarehouseCode,a.LocationCode,'','','{tableModel.Rows[i]["Quantity"]}', + '','1','15','47','0','', + '','','','{MUSER}' ,'{MUSERNAME}' , + GETDATE() ,'{WorkPoint}' ,'' + FROM ICSWareHouseLotInfo a + WHERE a.LotNo='{tableModel.Rows[i]["Memo"]}' AND a.WorkPoint='{WorkPoint}' + + update ICSWareHouseLotInfo set LockQuantity=LockQuantity+'{tableModel.Rows[i]["Quantity"]}' where LotNo='{lotNo}' AND WorkPoint='{WorkPoint}';"); + + } + sqlString = $@"SELECT + a.TransferNO AS Code,a.Sequence,a.InvCode,b.InvName,b.InvStd,b.InvUnit, + (SUM(ISNULL(a.Quantity, 0))-SUM(ISNULL(a.TransferQuantity, 0))) AS iQuantity,--应发数量 + a.FromWarehouseCode As WarehouseCode, + a.Memo AS LotNO, + ISNULL(c.Quantity, 0) AS QTY,--条码库存 + ISNULL(c.Quantity, 0) AS QTYLeft, + a.Quantity as SendQTY, --占料数量 + c.LocationCode, + CONVERT(varchar(100),c.MTIME, 23) MTIME, + SUM(c.Quantity-c.LockQuantity) AS QTYTotal, + a.ExtensionID + from ICSTransfer a + Left JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint + LEFT JOIN ICSWareHouseLotInfo c ON c.LotNo=a.Memo AND a.FromWarehouseCode=c.WarehouseCode + WHERE a.TransferNO in({ID}) AND a.Memo is NOT NULL and a.Memo!='' + GROUP BY a.TransferNO,a.Sequence,a.InvCode,b.InvName,b.InvStd,b.InvUnit, + a.Quantity,a.FromWarehouseCode ,a.Memo,c.LocationCode,c.MTIME,c.Quantity,a.ExtensionID,c.LockQuantity; "; + + } + //if (!String.IsNullOrEmpty(sqlString)) + //{ + // var dataSet1 = Repository().FindDataSetBySql(updateString.ToString()+ sqlString); + // if (dataSet1.Tables[0].Rows.Count != 0) + // { + // table1 = dataSet1.Tables[0]; + // } + //} + } + + + + string sql = $@"SELECT row_number() over ( order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo, + c.Code, + c.Sequence, + c.InvCode, + c.InvName, + c.InvStd, + c.InvUnit, + c.iQuantity AS iQuantity, + c.WHCode AS WarehouseCode, + d.LotNO, + ISNULL(d.Quantity, 0) AS QTY, + ISNULL(d.Quantity, 0) AS QTYLeft, + CONVERT(decimal(18,6),0) AS SendQTY, + d.LocationCode AS LocationCode, + CONVERT(varchar(100),d.MTIME, 23) MTIME, + f.QTYTotal QTYTotal,c.ExtensionID + FROM + (select + a.TransferNO as Code, + a.Sequence, + a.InvCode, + b.InvName, + b.InvStd, + b.InvUnit, + (SUM(ISNULL(a.Quantity, 0))-SUM(ISNULL(a.TransferQuantity, 0))) AS iQuantity, + a.FromWarehouseCode as WhCode, + a.ExtensionID + FROM + ICSTransfer a + LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint + WHERE a.TransferNO in ({ID}) AND a.WorkPoint = '{WorkPoint}' AND ISNULL(a.Quantity, 0)>ISNULL(a.TransferQuantity, 0) + and (a.Memo is null or a.Memo='' ) + GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID,a.Sequence) c + left join (select d.WarehouseCode,d.Quantity-d.LockQuantity as Quantity,d.INVCode, m.LotNo, d.MTIME,d.LocationCode,m.ExtensionID + from ICSWareHouseLotInfo d ,ICSInventoryLot m + where d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint + and d.WorkPoint='{WorkPoint}' AND d.Quantity-d.LockQuantity>0 AND d.Quantity>0 + --AND SUBSTRING( SUBSTRING(d.LocationCode, CHARINDEX('-',d.LocationCode)+1, LEN(d.LocationCode)),0,CHARINDEX('-', SUBSTRING(d.LocationCode, CHARINDEX('-',d.LocationCode)+1, LEN(d.LocationCode)))) Not IN(SELECT F_Define2 FROM Sys_SRM_ItemsDetail + --WHERE F_Define3='HGAreaConfig' AND F_Define1=d.WarehouseCode AND F_Define4=d.WorkPoint) + ) d + on c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode and d.ExtensionID=c.ExtensionID + LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity-LockQuantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{WorkPoint}' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode + order by c.Code,Convert(int,c.Sequence),d.MTIME,d.LotNO "; + + var dataset = Repository().FindDataSetBySql(sql); + if (dataset.Tables[0].Rows.Count != 0) + { + table = dataset.Tables[0]; + decimal qtyCount = 0; + bool remove = false; + List removeList = new List(); + for (int i = 0; i < table.Rows.Count; i++) + { + if (i != 0 + && (!table.Rows[i]["InvCode"].ToString().Equals(table.Rows[i - 1]["InvCode"].ToString()) + || !table.Rows[i]["Sequence"].ToString().Equals(table.Rows[i - 1]["Sequence"].ToString()) + || !table.Rows[i]["Code"].ToString().Equals(table.Rows[i - 1]["Code"].ToString()) + || !table.Rows[i]["ExtensionID"].ToString().Equals(table.Rows[i - 1]["ExtensionID"].ToString())) + ) + { + qtyCount = 0; + remove = false; + } + if (table.Rows[i]["QTYLeft"].ToString().ToDecimal() == 0) + { + removeList.Add(i); + continue; + } + if (remove) + { + removeList.Add(i); + } + else + { + var lotQty = table.Rows[i]["QTYLeft"].ToString().ToDecimal(); + var orderQty = table.Rows[i]["iQuantity"].ToString().ToDecimal(); + qtyCount += lotQty; + foreach (DataRow dr in table.Rows) + { + if (dr["LotNO"].ToString() == table.Rows[i]["LotNO"].ToString()) + { + if (qtyCount > orderQty) + { + dr["QTYLeft"] = Convert.ToDecimal(qtyCount) - Convert.ToDecimal(orderQty); + } + else + { + dr["QTYLeft"] = 0; + } + } + } + if (qtyCount >= orderQty) + { + table.Rows[i]["SendQTY"] = Convert.ToDecimal(lotQty) - (Convert.ToDecimal(qtyCount) - Convert.ToDecimal(orderQty)); + remove = true; + } + else + { + table.Rows[i]["SendQTY"] = lotQty; + } + } + } + if (removeList.Count > 0) + { + removeList.Reverse(); + foreach (var item in removeList) + { + table.Rows.RemoveAt(item); + } + } + try + { + #region 占料前增加验证,如果条码数量超出实际需要领料数量,直接报错 + string chksql = ""; + if (Type == "2" || Type == "12") + { + chksql = @" select InvCode,WHCode,SUM(Quantity) as Quantity from ICSMOApply + where ApplyCode in ({0}) and WorkPoint='{1}' + GROUP BY InvCode,WHCode"; + } + if (Type == "5") + { + #region 委外领料SQL + chksql = @" select InvCode,WHCode,SUM(Quantity) as Quantity from ICSOApply + where ApplyCode in ({0}) and WorkPoint='{1}' + GROUP BY InvCode,WHCode"; + #endregion + } + if (Type == "7") + { + #region 销售发货SQL + chksql = @" select InvCode,WHCode,SUM(Quantity) as Quantity from ICSSDN + where SDNCode in ({0}) and WorkPoint='{1}' + GROUP BY InvCode,WHCode"; + #endregion + } + if (Type == "8") + { + #region 其它出库SQL + chksql = @" select InvCode,WHCode,SUM(Quantity) as Quantity from ICSOtherOut + where OutCode in ({0}) and WorkPoint='{1}' + GROUP BY InvCode,WHCode"; + #endregion + } + if (Type == "10") + { + #region 物料调拨 + chksql = @" select InvCode,FromWarehouseCode AS WHCode,SUM(Quantity) as Quantity from ICSTransfer + where TransferNO in ({0}) and WorkPoint='{1}' and (Memo is NULL or Memo='') + GROUP BY InvCode,FromWarehouseCode"; + #endregion + } + chksql = string.Format(chksql, ID, WorkPoint); + var chkdata = Repository().FindDataSetBySql(chksql); + DataTable chktable = chkdata.Tables[0]; + foreach (DataRow chkdr in chktable.Rows) + { + decimal ZLQty = 0; + for (int i = 0; i < table.Rows.Count; i++) + { + if (table.Rows[i]["WarehouseCode"].ToString() == chkdr["WHCode"].ToString() + && table.Rows[i]["InvCode"].ToString() == chkdr["InvCode"].ToString()) + { + ZLQty += Convert.ToDecimal(table.Rows[i]["SendQTY"].ToString()); + } + } + if (Convert.ToDecimal(chkdr["Quantity"]) < ZLQty) + { + throw new Exception("物料:" + chkdr["InvCode"].ToString() + "实际拣料数量大于单据需求数量,请尝试重新拣料。"); + } + if (Convert.ToDecimal(chkdr["Quantity"]) > ZLQty && (Type == "2" || Type == "5" || Type == "12")) + { + chksql = @" select B.F_Define2 from ICSInventoryDetail A + INNER JOIN Sys_SRM_ItemsDetail B ON B.F_Define1=A.WHCode AND B.F_Define2=A.LocationCode AND B.F_Define4=A.WorkPoint + where INVCode='{0}' and WHCode='{1}' and WorkPoint='{2}'"; + chksql = string.Format(chksql, chkdr["InvCode"].ToString(), chkdr["WHCode"].ToString(), WorkPoint); + var chkds = Repository().FindDataSetBySql(chksql); + DataTable chkdt = chkds.Tables[0]; + if (chkdt.Rows.Count != 0) + { + throw new Exception("物料:" + chkdr["InvCode"].ToString() + "实际拣料数量小于单据需求数量,货柜单据必须整单拣料,请先核对库存。"); + } + } + } + #endregion + if (table.Rows.Count != 0) + { + #region 拣料时增加条码出入库记录,修改库存锁定数量,以作占料处理 + int Count = 1; + string BusinessCode = string.Empty; + string TransType = ""; + if (Type == "2") { BusinessCode = "13"; TransType = "生产发料-领料申请单"; } + if (Type == "12") { BusinessCode = "14"; TransType = "生产发料-领料申请单"; } + if (Type == "5") { BusinessCode = "6"; TransType = "委外发料-委外领料申请单"; } + if (Type == "7") { BusinessCode = "19"; TransType = "销售发货-销售发货单"; } + if (Type == "8") { BusinessCode = "24"; TransType = "杂发"; } + if (Type == "10") { BusinessCode = "47"; TransType = "调拨申请单"; } + string Identification = Guid.NewGuid().ToString(); + var pikTbLogTime = DateTime.Now; + string pikTbLogsql = string.Empty; + List DocNoList = new List(); + if (Type == "2" || Type == "12" || Type == "5") + { + #region 货柜 + string InspectJosn = ""; + string InspectJosnHead = ""; + string InspectJosnBody = ""; + InspectJosn += "{"; + InspectJosn += "\"IMP_ORDINI\":["; + InspectJosn += "货柜主表区域预留"; + InspectJosn += "],"; + InspectJosn += "\"IMP_ORDINI_RIGHE\":["; + InspectJosn += "货柜子表区域预留"; + InspectJosn += "]"; + InspectJosn += "}"; + for (int i = 0; i < table.Rows.Count; i++) + { + string hgsql = @"select A.InvCode,A.LocationCode,B.F_Define3,C.LocationCode AS Area + from ICSWareHouseLotInfo A + INNER JOIN Sys_SRM_ItemsDetail B ON B.F_Define2=A.LocationCode AND F_Define4=A.WorkPoint AND F_ItemName='HG_Location' + INNER JOIN ICSInventoryDetail C ON C.INVCode=A.InvCode AND C.WHCode=A.WarehouseCode AND C.WorkPoint=A.WorkPoint + where A.LotNo='{0}' AND A.WorkPoint='{1}'"; + hgsql = string.Format(hgsql, table.Rows[i]["LotNO"].ToString(), WorkPoint); + var hgds = Repository().FindDataSetBySql(hgsql); + if (hgds.Tables.Count == 0) + return null; + DataTable hgtable = hgds.Tables[0]; + if (hgtable.Rows.Count > 0) + { + if (!DocNoList.Contains(table.Rows[i]["Code"].ToString())) + { + DocNoList.Add(table.Rows[i]["Code"].ToString()); + } + InspectJosnBody += "{"; + InspectJosnBody += "\"RIG_ORDINE\":\"" + table.Rows[i]["Code"].ToString() + "\","; + InspectJosnBody += "\"RIG_ARTICOLO\": \"" + hgtable.Rows[0]["InvCode"].ToString() + "\","; + InspectJosnBody += "\"RIG_SUB1\": \"\","; + InspectJosnBody += "\"RIG_SUB2\": \"\","; + InspectJosnBody += "\"RIG_ELERUOLI_GEST\": \"" + hgtable.Rows[0]["Area"].ToString() + "\","; + InspectJosnBody += "\"RIG_ELEBAIE\": \"" + hgtable.Rows[0]["F_Define3"].ToString() + "\","; + InspectJosnBody += "\"RIG_QTAR\": " + table.Rows[i]["SendQTY"].ToString() + ","; + if (i == 0) + { + InspectJosnBody += "\"RIG_HOSTINF\": \"" + table.Rows[i]["Sequence"].ToString() + "\""; + } + else + { + if (table.Rows[i]["Code"].ToString() == table.Rows[i - 1]["Code"].ToString() && + table.Rows[i]["Sequence"].ToString() == table.Rows[i - 1]["Sequence"].ToString()) + { + InspectJosnBody += "\"RIG_HOSTINF\": \"" + table.Rows[i]["Sequence"].ToString() + Count.ToString() + "\""; + Count++; + } + else + { + InspectJosnBody += "\"RIG_HOSTINF\": \"" + table.Rows[i]["Sequence"].ToString() + "\""; + Count = 1; + } + } + InspectJosnBody += "},"; + } + } + InspectJosnBody = InspectJosnBody.TrimEnd(','); + foreach (string DocNo in DocNoList) + { + InspectJosnHead += "{"; + InspectJosnHead += "\"ORD_ORDINE\":\"" + DocNo.TrimStart('\'').TrimEnd('\'') + "\","; + InspectJosnHead += "\"ORD_DES\":\"" + TransType + "\","; + InspectJosnHead += "\"ORD_TIPOOP\":\"P\","; + InspectJosnHead += "\"ORD_CLIENTE\":\"" + WorkPoint + "\""; + InspectJosnHead += "},"; + } + InspectJosnHead = InspectJosnHead.TrimEnd(','); + if (InspectJosnBody != "") + { + InspectJosn = InspectJosn.Replace("货柜主表区域预留", InspectJosnHead); + InspectJosn = InspectJosn.Replace("货柜子表区域预留", InspectJosnBody); + if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"])) + { + string callresult = ""; + #region 货柜接口调用前日志 + object logID = Guid.NewGuid(); + string logsql = @"insert into ICSWMS_HGLog + values + ('{0}',GETDATE(),'{1}','{2}','{3}','{4}','{5}')"; + logsql = string.Format(logsql, logID, InspectJosn, "", WorkPoint, MUSER, MUSERNAME); + SqlHelper.CmdExecuteNonQueryLi(logsql); + #endregion + callresult = HTTPHelper.RestFulGet(InspectJosn, postUrlStr); + #region 货柜接口调用后日志 + logsql = @"update ICSWMS_HGLog set ReturnResult='{0}' + where ID='{1}'"; + logsql = string.Format(logsql, callresult, logID); + SqlHelper.CmdExecuteNonQueryLi(logsql); + #endregion + } + } + #endregion + } + foreach (DataRow PickLog in table.Rows) + { + pikTbLogsql += @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{9}' AND a.WorkPoint='{8}' AND a.Quantity>A.LockQuantity+'{3}') + BEGIN + + RAISERROR('条码{9}的库存可分配数量小于单据数量', 16, 1); + RETURN + END; + IF NOT EXISTS(SELECT TransCode FROM ICSWareHouseLotInfoLog WHERE TransCode='{1}' AND TransSequence='{2}' AND LotNo='{9}' AND WorkPoint='{8}' AND TransType='15') + BEGIN + INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode, + FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity, + Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID, + ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName, + MTIME,WorkPoint,EATTRIBUTE1) + SELECT NEWID(),'{0}','{1}','{2}',a.LotNo ,a.InvCode , + a.WarehouseCode,a.LocationCode,'','','{3}', + '','1','15','{4}','0','', + '','','','{5}' ,'{6}' , + '{7}' ,'{8}' ,'' + FROM ICSWareHouseLotInfo a + WHERE a.LotNo='{9}' AND a.WorkPoint='{8}' + + update ICSWareHouseLotInfo set LockQuantity=LockQuantity+'{3}' where LotNo='{9}' AND WorkPoint='{8}' + END + UPDATE ICSMOApply SET MUSER='{6}' WHERE ApplyCode='{1}' and Sequence='{2}' ; "; + pikTbLogsql = string.Format(pikTbLogsql, Identification, PickLog["Code"].ToString(), PickLog["Sequence"].ToString(), PickLog["SendQTY"].ToString() + , BusinessCode, MUSER, MUSERNAME, pikTbLogTime, WorkPoint, PickLog["LotNO"].ToString()); + } + SqlHelper.CmdExecuteNonQueryLi(pikTbLogsql + updateString.ToString()); + #endregion + } + //查询有条码的拣料信息 + if (!String.IsNullOrEmpty(sqlString)) + { + var dataSet1 = Repository().FindDataSetBySql(sqlString); + if (dataSet1.Tables[0].Rows.Count != 0) + { + table1 = dataSet1.Tables[0]; + } + } + //if (table1 != null) + //{ + // table.Merge(table1); + //} + //var result = ConvertCellToString(table); + //if (Invmes.Rows.Count > 0) + //{ + // result.Merge(Invmes, false); + //} + //return result; + } + catch (Exception ex) + { + throw new Exception(ex.Message); + } + } + else + { + + if (!String.IsNullOrEmpty(updateString.ToString())) + { + SqlHelper.CmdExecuteNonQueryLi(updateString.ToString()); + } + //查询有条码的拣料信息 + if (!String.IsNullOrEmpty(sqlString)) + { + var dataSet1 = Repository().FindDataSetBySql(sqlString); + if (dataSet1.Tables[0].Rows.Count != 0) + { + table1 = dataSet1.Tables[0]; + } + + } + + } + + + if (table1 != null && table != null) + { + table.Merge(table1); + } + else if (table == null && table1 != null) + { + table = table1; + } + else if (table1 == null && table ==null) + { + return null; + } + var result = ConvertCellToString(table); + if (Invmes.Rows.Count > 0) + { + result.Merge(Invmes, false); + } + return result; + + + } + else + { + if (Type == "1") + { + #region 工单备料sql + sqls = @" SELECT c.MOCode as Code, c.Sequence+'~'+a.Sequence as Sequence, a.InvCode, @@ -1684,22 +2183,22 @@ c.Sequence+'~'+a.Sequence as Sequence, LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}' GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,c.Sequence+'~'+a.Sequence"; - #endregion - } - if (Type == "2" || Type == "12") - { - sqls = @"select + #endregion + } + if (Type == "2" || Type == "12") + { + sqls = @"select a.ApplyCode as Code,a.Sequence, a.InvCode, b.InvName, b.InvStd, b.InvUnit, (SUM(ISNULL(a.Quantity, 0))-SUM(ISNULL(a.IssueQuantity, 0))) AS iQuantity, a.WhCode,a.ExtensionID FROM ICSMOApply a LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0) GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence"; - } - if (Type == "3") - { - #region 工单材料出库SQL - sqls = @" select + } + if (Type == "3") + { + #region 工单材料出库SQL + sqls = @" select a.IssueCode as Code, a.Sequence, a.InvCode, @@ -1714,12 +2213,12 @@ a.Sequence, LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}' GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence"; - #endregion - } - if (Type == "4") - { - #region 委外备料SQL - sqls = @" select + #endregion + } + if (Type == "4") + { + #region 委外备料SQL + sqls = @" select c.OOCode as Code, c.Sequence+'~'+a.Sequence as Sequence, a.InvCode, @@ -1735,12 +2234,12 @@ c.Sequence+'~'+a.Sequence as Sequence, LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}' GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode, a.ExtensionID,c.Sequence+'~'+a.Sequence"; - #endregion - } - if (Type == "5") - { - #region 委外领料SQL - sqls = @"select + #endregion + } + if (Type == "5") + { + #region 委外领料SQL + sqls = @"select a.ApplyCode as Code, a.Sequence, a.InvCode, @@ -1754,12 +2253,12 @@ a.Sequence, LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.IssueQuantity, 0) GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence"; - #endregion - } - if (Type == "6") - { - #region 委外材料出库SQL - sqls = @" select + #endregion + } + if (Type == "6") + { + #region 委外材料出库SQL + sqls = @" select a.IssueCode as Code, a.Sequence, a.InvCode, @@ -1774,12 +2273,12 @@ a.Sequence, LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}' GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence"; - #endregion - } - if (Type == "7") - { - #region 销售发货SQL - sqls = @" select + #endregion + } + if (Type == "7") + { + #region 销售发货SQL + sqls = @" select a.SDNCode as Code, a.Sequence, a.InvCode, @@ -1794,12 +2293,12 @@ a.Sequence, LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.SDNQuantity, 0) GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence"; - #endregion - } - if (Type == "8") - { - #region 其它出库SQL - sqls = @" select + #endregion + } + if (Type == "8") + { + #region 其它出库SQL + sqls = @" select a.OutCode as Code, a.Sequence, a.InvCode, @@ -1814,12 +2313,12 @@ a.Sequence, LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.OutQuantity, 0) GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence"; - #endregion - } - if (Type == "9") - { - #region 借用SQL - sqls = @"select + #endregion + } + if (Type == "9") + { + #region 借用SQL + sqls = @"select a.BrrowCode as Code, a.Sequence, a.InvCode, @@ -1834,14 +2333,14 @@ a.Sequence, LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}' GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,a.Sequence"; - #endregion - } - if (Type == "10") - { - #region 物料调拨 - sqls = @"select + #endregion + } + if (Type == "10") + { + #region 物料调拨 + sqls = @"select a.TransferNO as Code, -a.Sequence, + a.Sequence, a.InvCode, b.InvName, b.InvStd, @@ -1853,13 +2352,14 @@ a.Sequence, ICSTransfer a LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}' AND ISNULL(a.Quantity, 0)>ISNULL(a.TransferQuantity, 0) + and a.Memo is null GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID,a.Sequence"; - #endregion - } - if (Type == "11") - { - #region 两步调出 - sqls = @"select + #endregion + } + if (Type == "11") + { + #region 两步调出 + sqls = @"select a.OutCode as Code, a.Sequence, a.InvCode, @@ -1874,13 +2374,13 @@ a.Sequence, LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}' GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID,a.Sequence"; - #endregion - } - sqls = string.Format(sqls, ID, WorkPoint); + #endregion + } + sqls = string.Format(sqls, ID, WorkPoint); - string sql = $@"SELECT row_number() over ( order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo, + string sql = $@"SELECT row_number() over ( order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo, c.Code, -c.Sequence, + c.Sequence, c.InvCode, c.InvName, c.InvStd, @@ -1907,264 +2407,264 @@ c.Sequence, LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity-LockQuantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{WorkPoint}' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode order by c.Code,Convert(int,c.Sequence),d.MTIME,d.LotNO "; - var dataset = Repository().FindDataSetBySql(sql); - if (dataset.Tables[0].Rows.Count == 0) - return null; - DataTable table = dataset.Tables[0]; - decimal qtyCount = 0; - bool remove = false; - List removeList = new List(); - for (int i = 0; i < table.Rows.Count; i++) - { - if (i != 0 - && (!table.Rows[i]["InvCode"].ToString().Equals(table.Rows[i - 1]["InvCode"].ToString()) - || !table.Rows[i]["Sequence"].ToString().Equals(table.Rows[i - 1]["Sequence"].ToString()) - || !table.Rows[i]["Code"].ToString().Equals(table.Rows[i - 1]["Code"].ToString()) - || !table.Rows[i]["ExtensionID"].ToString().Equals(table.Rows[i - 1]["ExtensionID"].ToString())) - ) - { - qtyCount = 0; - remove = false; - } - if (table.Rows[i]["QTYLeft"].ToString().ToDecimal() == 0) - { - removeList.Add(i); - continue; - } - if (remove) - { - removeList.Add(i); - } - else - { - var lotQty = table.Rows[i]["QTYLeft"].ToString().ToDecimal(); - var orderQty = table.Rows[i]["iQuantity"].ToString().ToDecimal(); - qtyCount += lotQty; - foreach (DataRow dr in table.Rows) + var dataset = Repository().FindDataSetBySql(sql); + if (dataset.Tables[0].Rows.Count == 0) + return null; + DataTable table = dataset.Tables[0]; + decimal qtyCount = 0; + bool remove = false; + List removeList = new List(); + for (int i = 0; i < table.Rows.Count; i++) + { + if (i != 0 + && (!table.Rows[i]["InvCode"].ToString().Equals(table.Rows[i - 1]["InvCode"].ToString()) + || !table.Rows[i]["Sequence"].ToString().Equals(table.Rows[i - 1]["Sequence"].ToString()) + || !table.Rows[i]["Code"].ToString().Equals(table.Rows[i - 1]["Code"].ToString()) + || !table.Rows[i]["ExtensionID"].ToString().Equals(table.Rows[i - 1]["ExtensionID"].ToString())) + ) { - if (dr["LotNO"].ToString() == table.Rows[i]["LotNO"].ToString()) - { - if (qtyCount > orderQty) - { - dr["QTYLeft"] = Convert.ToDecimal(qtyCount) - Convert.ToDecimal(orderQty); - } - else - { - dr["QTYLeft"] = 0; - } - } + qtyCount = 0; + remove = false; } - if (qtyCount >= orderQty) + if (table.Rows[i]["QTYLeft"].ToString().ToDecimal() == 0) { - table.Rows[i]["SendQTY"] = Convert.ToDecimal(lotQty) - (Convert.ToDecimal(qtyCount) - Convert.ToDecimal(orderQty)); - remove = true; + removeList.Add(i); + continue; + } + if (remove) + { + removeList.Add(i); } else { - table.Rows[i]["SendQTY"] = lotQty; + var lotQty = table.Rows[i]["QTYLeft"].ToString().ToDecimal(); + var orderQty = table.Rows[i]["iQuantity"].ToString().ToDecimal(); + qtyCount += lotQty; + foreach (DataRow dr in table.Rows) + { + if (dr["LotNO"].ToString() == table.Rows[i]["LotNO"].ToString()) + { + if (qtyCount > orderQty) + { + dr["QTYLeft"] = Convert.ToDecimal(qtyCount) - Convert.ToDecimal(orderQty); + } + else + { + dr["QTYLeft"] = 0; + } + } + } + if (qtyCount >= orderQty) + { + table.Rows[i]["SendQTY"] = Convert.ToDecimal(lotQty) - (Convert.ToDecimal(qtyCount) - Convert.ToDecimal(orderQty)); + remove = true; + } + else + { + table.Rows[i]["SendQTY"] = lotQty; + } } } - } - if (removeList.Count > 0) - { - removeList.Reverse(); - foreach (var item in removeList) + if (removeList.Count > 0) { - table.Rows.RemoveAt(item); + removeList.Reverse(); + foreach (var item in removeList) + { + table.Rows.RemoveAt(item); + } } - } - try - { - #region 占料前增加验证,如果条码数量超出实际需要领料数量,直接报错 - string chksql = ""; - if (Type == "2" || Type == "12") + try { - chksql = @" select InvCode,WHCode,SUM(Quantity) as Quantity from ICSMOApply + #region 占料前增加验证,如果条码数量超出实际需要领料数量,直接报错 + string chksql = ""; + if (Type == "2" || Type == "12") + { + chksql = @" select InvCode,WHCode,SUM(Quantity) as Quantity from ICSMOApply where ApplyCode in ({0}) and WorkPoint='{1}' GROUP BY InvCode,WHCode"; - } - if (Type == "5") - { - #region 委外领料SQL - chksql = @" select InvCode,WHCode,SUM(Quantity) as Quantity from ICSOApply + } + if (Type == "5") + { + #region 委外领料SQL + chksql = @" select InvCode,WHCode,SUM(Quantity) as Quantity from ICSOApply where ApplyCode in ({0}) and WorkPoint='{1}' GROUP BY InvCode,WHCode"; - #endregion - } - if (Type == "7") - { - #region 销售发货SQL - chksql = @" select InvCode,WHCode,SUM(Quantity) as Quantity from ICSSDN + #endregion + } + if (Type == "7") + { + #region 销售发货SQL + chksql = @" select InvCode,WHCode,SUM(Quantity) as Quantity from ICSSDN where SDNCode in ({0}) and WorkPoint='{1}' GROUP BY InvCode,WHCode"; - #endregion - } - if (Type == "8") - { - #region 其它出库SQL - chksql = @" select InvCode,WHCode,SUM(Quantity) as Quantity from ICSOtherOut + #endregion + } + if (Type == "8") + { + #region 其它出库SQL + chksql = @" select InvCode,WHCode,SUM(Quantity) as Quantity from ICSOtherOut where OutCode in ({0}) and WorkPoint='{1}' GROUP BY InvCode,WHCode"; - #endregion - } - if (Type == "10") - { - #region 物料调拨 - chksql = @" select InvCode,FromWarehouseCode AS WHCode,SUM(Quantity) as Quantity from ICSTransfer + #endregion + } + if (Type == "10") + { + #region 物料调拨 + chksql = @" select InvCode,FromWarehouseCode AS WHCode,SUM(Quantity) as Quantity from ICSTransfer where TransferNO in ({0}) and WorkPoint='{1}' GROUP BY InvCode,FromWarehouseCode"; - #endregion - } - chksql = string.Format(chksql, ID, WorkPoint); - var chkdata = Repository().FindDataSetBySql(chksql); - DataTable chktable = chkdata.Tables[0]; - foreach (DataRow chkdr in chktable.Rows) - { - decimal ZLQty = 0; - for (int i = 0; i < table.Rows.Count; i++) + #endregion + } + chksql = string.Format(chksql, ID, WorkPoint); + var chkdata = Repository().FindDataSetBySql(chksql); + DataTable chktable = chkdata.Tables[0]; + foreach (DataRow chkdr in chktable.Rows) { - if (table.Rows[i]["WarehouseCode"].ToString() == chkdr["WHCode"].ToString() - && table.Rows[i]["InvCode"].ToString() == chkdr["InvCode"].ToString()) + decimal ZLQty = 0; + for (int i = 0; i < table.Rows.Count; i++) { - ZLQty += Convert.ToDecimal(table.Rows[i]["SendQTY"].ToString()); + if (table.Rows[i]["WarehouseCode"].ToString() == chkdr["WHCode"].ToString() + && table.Rows[i]["InvCode"].ToString() == chkdr["InvCode"].ToString()) + { + ZLQty += Convert.ToDecimal(table.Rows[i]["SendQTY"].ToString()); + } } - } - if (Convert.ToDecimal(chkdr["Quantity"]) < ZLQty) - { - throw new Exception("物料:" + chkdr["InvCode"].ToString() + "实际拣料数量大于单据需求数量,请尝试重新拣料。"); - } - if (Convert.ToDecimal(chkdr["Quantity"]) > ZLQty && (Type == "2" || Type == "5" || Type == "12")) - { - chksql = @" select B.F_Define2 from ICSInventoryDetail A + if (Convert.ToDecimal(chkdr["Quantity"]) < ZLQty) + { + throw new Exception("物料:" + chkdr["InvCode"].ToString() + "实际拣料数量大于单据需求数量,请尝试重新拣料。"); + } + if (Convert.ToDecimal(chkdr["Quantity"]) > ZLQty && (Type == "2" || Type == "5" || Type == "12")) + { + chksql = @" select B.F_Define2 from ICSInventoryDetail A INNER JOIN Sys_SRM_ItemsDetail B ON B.F_Define1=A.WHCode AND B.F_Define2=A.LocationCode AND B.F_Define4=A.WorkPoint where INVCode='{0}' and WHCode='{1}' and WorkPoint='{2}'"; - chksql = string.Format(chksql, chkdr["InvCode"].ToString(), chkdr["WHCode"].ToString(), WorkPoint); - var chkds = Repository().FindDataSetBySql(chksql); - DataTable chkdt = chkds.Tables[0]; - if (chkdt.Rows.Count != 0) - { - throw new Exception("物料:" + chkdr["InvCode"].ToString() + "实际拣料数量小于单据需求数量,货柜单据必须整单拣料,请先核对库存。"); + chksql = string.Format(chksql, chkdr["InvCode"].ToString(), chkdr["WHCode"].ToString(), WorkPoint); + var chkds = Repository().FindDataSetBySql(chksql); + DataTable chkdt = chkds.Tables[0]; + if (chkdt.Rows.Count != 0) + { + throw new Exception("物料:" + chkdr["InvCode"].ToString() + "实际拣料数量小于单据需求数量,货柜单据必须整单拣料,请先核对库存。"); + } } } - } - #endregion - if (table.Rows.Count != 0) - { - #region 拣料时增加条码出入库记录,修改库存锁定数量,以作占料处理 - int Count = 1; - string BusinessCode = string.Empty; - string TransType = ""; - if (Type == "2") { BusinessCode = "13"; TransType = "生产发料-领料申请单"; } - if (Type == "12") { BusinessCode = "14"; TransType = "生产发料-领料申请单"; } - if (Type == "5") { BusinessCode = "6"; TransType = "委外发料-委外领料申请单"; } - if (Type == "7") { BusinessCode = "19"; TransType = "销售发货-销售发货单"; } - if (Type == "8") { BusinessCode = "24"; TransType = "杂发"; } - if (Type == "10") { BusinessCode = "47"; TransType = "调拨申请单"; } - string Identification = Guid.NewGuid().ToString(); - var pikTbLogTime = DateTime.Now; - string pikTbLogsql = string.Empty; - List DocNoList = new List(); - if (Type == "2" || Type == "12" || Type == "5") + #endregion + if (table.Rows.Count != 0) { - #region 货柜 - string InspectJosn = ""; - string InspectJosnHead = ""; - string InspectJosnBody = ""; - InspectJosn += "{"; - InspectJosn += "\"IMP_ORDINI\":["; - InspectJosn += "货柜主表区域预留"; - InspectJosn += "],"; - InspectJosn += "\"IMP_ORDINI_RIGHE\":["; - InspectJosn += "货柜子表区域预留"; - InspectJosn += "]"; - InspectJosn += "}"; - for (int i = 0; i < table.Rows.Count; i++) + #region 拣料时增加条码出入库记录,修改库存锁定数量,以作占料处理 + int Count = 1; + string BusinessCode = string.Empty; + string TransType = ""; + if (Type == "2") { BusinessCode = "13"; TransType = "生产发料-领料申请单"; } + if (Type == "12") { BusinessCode = "14"; TransType = "生产发料-领料申请单"; } + if (Type == "5") { BusinessCode = "6"; TransType = "委外发料-委外领料申请单"; } + if (Type == "7") { BusinessCode = "19"; TransType = "销售发货-销售发货单"; } + if (Type == "8") { BusinessCode = "24"; TransType = "杂发"; } + if (Type == "10") { BusinessCode = "47"; TransType = "调拨申请单"; } + string Identification = Guid.NewGuid().ToString(); + var pikTbLogTime = DateTime.Now; + string pikTbLogsql = string.Empty; + List DocNoList = new List(); + if (Type == "2" || Type == "12" || Type == "5") { - string hgsql = @"select A.InvCode,A.LocationCode,B.F_Define3,C.LocationCode AS Area + #region 货柜 + string InspectJosn = ""; + string InspectJosnHead = ""; + string InspectJosnBody = ""; + InspectJosn += "{"; + InspectJosn += "\"IMP_ORDINI\":["; + InspectJosn += "货柜主表区域预留"; + InspectJosn += "],"; + InspectJosn += "\"IMP_ORDINI_RIGHE\":["; + InspectJosn += "货柜子表区域预留"; + InspectJosn += "]"; + InspectJosn += "}"; + for (int i = 0; i < table.Rows.Count; i++) + { + string hgsql = @"select A.InvCode,A.LocationCode,B.F_Define3,C.LocationCode AS Area from ICSWareHouseLotInfo A INNER JOIN Sys_SRM_ItemsDetail B ON B.F_Define2=A.LocationCode AND F_Define4=A.WorkPoint AND F_ItemName='HG_Location' INNER JOIN ICSInventoryDetail C ON C.INVCode=A.InvCode AND C.WHCode=A.WarehouseCode AND C.WorkPoint=A.WorkPoint where A.LotNo='{0}' AND A.WorkPoint='{1}'"; - hgsql = string.Format(hgsql, table.Rows[i]["LotNO"].ToString(), WorkPoint); - var hgds = Repository().FindDataSetBySql(hgsql); - if (hgds.Tables.Count == 0) - return null; - DataTable hgtable = hgds.Tables[0]; - if (hgtable.Rows.Count > 0) - { - if (!DocNoList.Contains(table.Rows[i]["Code"].ToString())) - { - DocNoList.Add(table.Rows[i]["Code"].ToString()); - } - InspectJosnBody += "{"; - InspectJosnBody += "\"RIG_ORDINE\":\"" + table.Rows[i]["Code"].ToString() + "\","; - InspectJosnBody += "\"RIG_ARTICOLO\": \"" + hgtable.Rows[0]["InvCode"].ToString() + "\","; - InspectJosnBody += "\"RIG_SUB1\": \"\","; - InspectJosnBody += "\"RIG_SUB2\": \"\","; - InspectJosnBody += "\"RIG_ELERUOLI_GEST\": \"" + hgtable.Rows[0]["Area"].ToString() + "\","; - InspectJosnBody += "\"RIG_ELEBAIE\": \"" + hgtable.Rows[0]["F_Define3"].ToString() + "\","; - InspectJosnBody += "\"RIG_QTAR\": " + table.Rows[i]["SendQTY"].ToString() + ","; - if (i == 0) + hgsql = string.Format(hgsql, table.Rows[i]["LotNO"].ToString(), WorkPoint); + var hgds = Repository().FindDataSetBySql(hgsql); + if (hgds.Tables.Count == 0) + return null; + DataTable hgtable = hgds.Tables[0]; + if (hgtable.Rows.Count > 0) { - InspectJosnBody += "\"RIG_HOSTINF\": \"" + table.Rows[i]["Sequence"].ToString() + "\""; - } - else - { - if (table.Rows[i]["Code"].ToString() == table.Rows[i - 1]["Code"].ToString() && - table.Rows[i]["Sequence"].ToString() == table.Rows[i - 1]["Sequence"].ToString()) + if (!DocNoList.Contains(table.Rows[i]["Code"].ToString())) { - InspectJosnBody += "\"RIG_HOSTINF\": \"" + table.Rows[i]["Sequence"].ToString() + Count.ToString() + "\""; - Count++; + DocNoList.Add(table.Rows[i]["Code"].ToString()); } - else + InspectJosnBody += "{"; + InspectJosnBody += "\"RIG_ORDINE\":\"" + table.Rows[i]["Code"].ToString() + "\","; + InspectJosnBody += "\"RIG_ARTICOLO\": \"" + hgtable.Rows[0]["InvCode"].ToString() + "\","; + InspectJosnBody += "\"RIG_SUB1\": \"\","; + InspectJosnBody += "\"RIG_SUB2\": \"\","; + InspectJosnBody += "\"RIG_ELERUOLI_GEST\": \"" + hgtable.Rows[0]["Area"].ToString() + "\","; + InspectJosnBody += "\"RIG_ELEBAIE\": \"" + hgtable.Rows[0]["F_Define3"].ToString() + "\","; + InspectJosnBody += "\"RIG_QTAR\": " + table.Rows[i]["SendQTY"].ToString() + ","; + if (i == 0) { InspectJosnBody += "\"RIG_HOSTINF\": \"" + table.Rows[i]["Sequence"].ToString() + "\""; - Count = 1; } + else + { + if (table.Rows[i]["Code"].ToString() == table.Rows[i - 1]["Code"].ToString() && + table.Rows[i]["Sequence"].ToString() == table.Rows[i - 1]["Sequence"].ToString()) + { + InspectJosnBody += "\"RIG_HOSTINF\": \"" + table.Rows[i]["Sequence"].ToString() + Count.ToString() + "\""; + Count++; + } + else + { + InspectJosnBody += "\"RIG_HOSTINF\": \"" + table.Rows[i]["Sequence"].ToString() + "\""; + Count = 1; + } + } + InspectJosnBody += "},"; } - InspectJosnBody += "},"; } - } - InspectJosnBody = InspectJosnBody.TrimEnd(','); - foreach (string DocNo in DocNoList) - { - InspectJosnHead += "{"; - InspectJosnHead += "\"ORD_ORDINE\":\"" + DocNo.TrimStart('\'').TrimEnd('\'') + "\","; - InspectJosnHead += "\"ORD_DES\":\"" + TransType + "\","; - InspectJosnHead += "\"ORD_TIPOOP\":\"P\","; - InspectJosnHead += "\"ORD_CLIENTE\":\"" + WorkPoint + "\""; - InspectJosnHead += "},"; - } - InspectJosnHead = InspectJosnHead.TrimEnd(','); - if (InspectJosnBody != "") - { - InspectJosn = InspectJosn.Replace("货柜主表区域预留", InspectJosnHead); - InspectJosn = InspectJosn.Replace("货柜子表区域预留", InspectJosnBody); - if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"])) + InspectJosnBody = InspectJosnBody.TrimEnd(','); + foreach (string DocNo in DocNoList) { - string callresult = ""; - #region 货柜接口调用前日志 - object logID = Guid.NewGuid(); - string logsql = @"insert into ICSWMS_HGLog + InspectJosnHead += "{"; + InspectJosnHead += "\"ORD_ORDINE\":\"" + DocNo.TrimStart('\'').TrimEnd('\'') + "\","; + InspectJosnHead += "\"ORD_DES\":\"" + TransType + "\","; + InspectJosnHead += "\"ORD_TIPOOP\":\"P\","; + InspectJosnHead += "\"ORD_CLIENTE\":\"" + WorkPoint + "\""; + InspectJosnHead += "},"; + } + InspectJosnHead = InspectJosnHead.TrimEnd(','); + if (InspectJosnBody != "") + { + InspectJosn = InspectJosn.Replace("货柜主表区域预留", InspectJosnHead); + InspectJosn = InspectJosn.Replace("货柜子表区域预留", InspectJosnBody); + if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"])) + { + string callresult = ""; + #region 货柜接口调用前日志 + object logID = Guid.NewGuid(); + string logsql = @"insert into ICSWMS_HGLog values ('{0}',GETDATE(),'{1}','{2}','{3}','{4}','{5}')"; - logsql = string.Format(logsql, logID, InspectJosn, "", WorkPoint, MUSER, MUSERNAME); - SqlHelper.CmdExecuteNonQueryLi(logsql); - #endregion - callresult = HTTPHelper.RestFulGet(InspectJosn, postUrlStr); - #region 货柜接口调用后日志 - logsql = @"update ICSWMS_HGLog set ReturnResult='{0}' + logsql = string.Format(logsql, logID, InspectJosn, "", WorkPoint, MUSER, MUSERNAME); + SqlHelper.CmdExecuteNonQueryLi(logsql); + #endregion + callresult = HTTPHelper.RestFulGet(InspectJosn, postUrlStr); + #region 货柜接口调用后日志 + logsql = @"update ICSWMS_HGLog set ReturnResult='{0}' where ID='{1}'"; - logsql = string.Format(logsql, callresult, logID); - SqlHelper.CmdExecuteNonQueryLi(logsql); - #endregion + logsql = string.Format(logsql, callresult, logID); + SqlHelper.CmdExecuteNonQueryLi(logsql); + #endregion + } } + #endregion } - #endregion - } - foreach (DataRow PickLog in table.Rows) - { - pikTbLogsql += @" IF NOT EXISTS(SELECT TransCode FROM ICSWareHouseLotInfoLog WHERE TransCode='{1}' AND TransSequence='{2}' AND LotNo='{9}' AND WorkPoint='{8}' AND TransType='15') + foreach (DataRow PickLog in table.Rows) + { + pikTbLogsql += @" IF NOT EXISTS(SELECT TransCode FROM ICSWareHouseLotInfoLog WHERE TransCode='{1}' AND TransSequence='{2}' AND LotNo='{9}' AND WorkPoint='{8}' AND TransType='15') BEGIN INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode, FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity, @@ -2182,24 +2682,30 @@ c.Sequence, update ICSWareHouseLotInfo set LockQuantity=LockQuantity+'{3}' where LotNo='{9}' AND WorkPoint='{8}' END UPDATE ICSMOApply SET MUSER='{6}' WHERE ApplyCode='{1}' and Sequence='{2}' ; "; - pikTbLogsql = string.Format(pikTbLogsql, Identification, PickLog["Code"].ToString(), PickLog["Sequence"].ToString(), PickLog["SendQTY"].ToString() - , BusinessCode, MUSER, MUSERNAME, pikTbLogTime, WorkPoint, PickLog["LotNO"].ToString()); + pikTbLogsql = string.Format(pikTbLogsql, Identification, PickLog["Code"].ToString(), PickLog["Sequence"].ToString(), PickLog["SendQTY"].ToString() + , BusinessCode, MUSER, MUSERNAME, pikTbLogTime, WorkPoint, PickLog["LotNO"].ToString()); + } + SqlHelper.CmdExecuteNonQueryLi(pikTbLogsql); + #endregion } - SqlHelper.CmdExecuteNonQueryLi(pikTbLogsql); - #endregion - } - var result = ConvertCellToString(table); - if (Invmes.Rows.Count > 0) + var result = ConvertCellToString(table); + if (Invmes.Rows.Count > 0) + { + result.Merge(Invmes, false); + } + return result; + } + catch (Exception ex) { - result.Merge(Invmes, false); + throw new Exception(ex.Message); } - return result; - } - catch (Exception ex) - { - throw new Exception(ex.Message); + + } + + + } ///