using ICSSoft.Common;
using ICSSoft.Entity;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using static ICSSoft.Common.HTTPHelper;
namespace ICSSoft.DataProject
{
///
/// 使用中
/// 更新库存表、日志表
///
public class ICSWareHouseLotInfoService
{
private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
///
/// 分批
///
///
///
///
///
///
///
///
///
///
///
public static void WareHouseLotInfoInBatches(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User,
string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary language, string MergeID = "")
{
}
///
/// 添加库存
///
///
///
///
///
///
///
///
///
///
public static void WareHouseLotInfoUp(string Identification, string LocationCode, string LotNo, string Quantity, string User,
string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary language, string LogID, string jointLotNo, string createDate)
{
try
{
#region 正常入库
///添加库存(原条码退回,更新库存;新条码直接入库)
//stirng locationcode = "";
string sql = string.Empty;
string locationcode = "";
if (BusinessCode != TransTypeEnum.SalesReturnBack.GetDescription())
{
if (string.IsNullOrWhiteSpace(LogID))
{
sql = @"IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo164") + @"',16,1);
RETURN
END ";
}
else
{
sql = @"SELECT LocationCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
sql = string.Format(sql, LotNo, WorkPoint);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
if (dt == null || dt.Rows.Count <= 0)
{
throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), LotNo));
}
locationcode = dt.Rows[0]["LocationCode"].ToString();
}
}
sql += @" IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
RETURN
END
IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
BEGIN
IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.Quantity=0)
BEGIN
UPDATE a SET a.Quantity=ISNULL(a.Quantity,0)+'{3}',WarehouseCode=e.WarehouseCode,LocationCode=d.LocationCode
From ICSWareHouseLotInfo a
INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
END
ELSE IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.LocationCode='{4}')
BEGIN
UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{3}'
WHERE LotNo='{0}' AND WorkPoint='{1}'
END
ELSE IF('" + locationcode + @"' != '{4}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo395"), "{4}", locationcode) + @"', 16, 1);
RETURN
END
END
ELSE
BEGIN
IF EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
BEGIN
IF NOT EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}' AND il.LocationCode='{4}')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo180") + @"',16,1);
RETURN
END
END
INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
SELECT NEWID(),a.LotNo ,e.WarehouseCode,d.LocationCode,a.InvCode ,'{3}','{5}','0',f.F_Account ,f.F_RealName ,'{5}' ,a.WorkPoint ,''
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
--INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
END";
sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, LocationCode, createDate);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
}
///添加日志
sql = @"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,LogID)
SELECT NEWID(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
'','',c.WarehouseCode,c.LocationCode,'{6}',
'','0','{4}','{5}','0','',
'','','',f.F_Account ,f.F_RealName ,
SYSDATETIME() ,a.WorkPoint ,'','{7}'
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
";
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, LogID);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
}
#endregion
#region 管控方式是"料品"时
ControlMode mode = ICSControlModeService.GetControlMode();
if (mode.itemCode.Equals("ControlMode02"))
{
//查询是否存在料品管控的条码
string sqlStrNew = @"SELECT a.ID,
con.ContainerCode,
con.ContainerName,
a.LotNo,
a.InvCode,
inv.InvName,
inv.InvStd,
inv.InvUnit,-- {0}
inv.AmountUnit,
ext.ID AS ExtensionID,
ext.ProjectCode,
ext.Version,
ext.BatchCode,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [ USER ],
a.MTIME AS [ MTime ]
FROM
ICSInventoryLot a
LEFT JOIN ICSContainerLot conlot ON a.LotNo = conlot.LotNo AND a.WorkPoint = conlot.WorkPoint
LEFT JOIN ICSContainer con ON conlot.ContainerID = con.ID AND conlot.WorkPoint = con.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode = inv.InvCode AND a.WorkPoint = inv.WorkPoint
INNER JOIN ICSExtension ext ON a.ExtensionID = ext.ID AND a.WorkPoint = ext.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
sqlStrNew = string.Format(sqlStrNew, jointLotNo, WorkPoint);
DataTable table = DBHelper.SQlReturnData(sqlStrNew, cmd);
string json = JsonConvert.SerializeObject(table);
List modelNew = JsonConvert.DeserializeObject>(json);
//当不存在料品管控条码时,生成新条码
if (!(modelNew.Count > 0))
{
//获取旧条码的信息
string jsonStr = ICSControlModeService.QueryLotNo(LotNo, WorkPoint);
List model = JsonConvert.DeserializeObject>(jsonStr);
//在条码表中插入一条新数据,在条码表中插入一条新数据,并在库存表中添加新数据
LotNoMode lotNoMode = model[0];
CreateLotNo(jointLotNo, Quantity, "", "", WorkPoint, Identification, User, lotNoMode.InvCode, BusinessCode, lotNoMode.ProjectCode, lotNoMode.BatchCode,
lotNoMode.Version, lotNoMode.Brand, lotNoMode.cFree1, lotNoMode.cFree2, lotNoMode.cFree3, lotNoMode.cFree4, lotNoMode.cFree5, lotNoMode.cFree6, lotNoMode.cFree7,
lotNoMode.cFree8, lotNoMode.cFree9, lotNoMode.cFree10, cmd, language, LocationCode, LotNo);
}
try
{
//合并前日志
WareHouseLotInfoLog(Identification, jointLotNo, User, WorkPoint, "2",
TransTypeEnum.LOTMergeBefore.GetDescription(), cmd, language);
//更新目标条码库存
WareHouseLotInfoMerge(Identification, jointLotNo, LotNo, Quantity, User, WorkPoint, "2",
TransTypeEnum.LOTMergeAfter.GetDescription(), cmd, language);
//合并后日志
WareHouseLotInfoLog(Identification, jointLotNo, User, WorkPoint, "2",
TransTypeEnum.LOTMergeAfter.GetDescription(), cmd, language);
}
catch (Exception)
{
throw;
}
}
#endregion
#region 委外入库,倒冲
if (BusinessCode.Equals(TransTypeEnum.OutsourcingReceiveDoc.GetDescription()))
{
#region sql
sql = @"-- 1.创建临时表 初始单据数据 maintemp
SELECT
c.OOCode AS TransCode,
a.OODetailID AS DetailID,
a.InvCode,
b.InvName,
b.InvStd,
a.Quantity/c.Quantity*{2} AS Quantity,
a.Amount,
a.Sequence AS TransSequence,
a.IssueQuantity,
c.Sequence,
inv.InvUnit,
0 AS LocationQty,
inv.AmountUnit,
a.ExtensionID,
a.WorkPoint,
ext.ProjectCode,
CASE WHEN ISNULL(inv.BatchEnable, '0')='1' THEN ext.BatchCode ELSE '' END AS BatchCode,
ext.Version,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10
INTO #maintemp
FROM
ICSOOPick a
inner join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
INNER JOIN (
SELECT a.OOCode,a.Sequence,a.WorkPoint
FROM ICSOutsourcingOrder a
INNER JOIN ICSInventoryLotDetail b ON b.TransCode=a.OOCode AND b.TransSequence=a.Sequence AND b.WorkPoint=a.WorkPoint
INNER JOIN ICSInventoryLot c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint
WHERE c.LotNo='{0}' AND c.WorkPoint='{1}'
) temp ON c.OOCode=temp.OOCode AND a.WorkPoint=temp.WorkPoint AND c.Sequence=temp.Sequence
WHERE a.SupplyType='1'
GROUP BY c.OOCode,a.Quantity,c.Quantity,a.InvCode,b.InvName,b.InvStd,a.WhCode,a.ExtensionID,a.WorkPoint,inv.BatchEnable,a.OODetailID,a.Amount,a.Sequence,a.IssueQuantity,inv.InvName,inv.InvCode,inv.InvUnit,inv.AmountUnit,c.Sequence,
ext.ProjectCode,ext.BatchCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10;
select * into #resulttemp from #maintemp
ALTER TABLE #resulttemp ADD LotNo VARCHAR(50)
delete from #resulttemp
-- 2.根据maintemp 中的物料信息 查出库存中对应的条码信息 barcodetemp
select a.lotno,a.invcode,(a.quantity-a.lockQuantity) as quantity ,a.mtime into #barcodetemp from ICSWareHouseLotInfo a LEFT JOIN
(select #maintemp.invcode from #maintemp group by #maintemp.InvCode) b on a.invcode = b.invcode where a.Quantity-a.lockQuantity>0 ORDER BY a.MTIME ASC
-- 3.循环maintemp,根据 行号和子表ID 向最终结果集中写入数据 ;barcodetemp 中的已匹配数据删除或更新
BEGIN
DECLARE @transSequence int;--当前循环的行号
DECLARE @qty int;--条码表数量
DECLARE @needqty int;--本行所需数量
DECLARE @lotno VARCHAR(50);--条码
DECLARE @DetailID VARCHAR(50);--本行所在工单行ID
DECLARE tempCursor CURSOR FOR (select transSequence,DetailID from #maintemp); --创建游标tempCursor,并定义游标所指向的集合
OPEN tempCursor; --打开游标
FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID; --游标读取下一个数据
WHILE @@fetch_status=0
BEGIN
select @needqty=Quantity from #maintemp where transSequence = @transSequence AND DetailID = @DetailID
PRINT @transSequence
WHILE @needqty>0
BEGIN
select top 1 @qty = isnull(quantity,0),@lotno = isnull(lotno,'') from #barcodetemp a
RIGHT JOIN (select invcode from #maintemp where transSequence = @transSequence AND DetailID = @DetailID) b on a.invcode=b.invcode ORDER BY mtime
BEGIN
IF(@needqty-@qty>=0 and ISNULL(@lotno, '')<>'')
BEGIN
insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
ISNULL(Amount, 0), InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@qty,ISNULL(AmountUnit, ''),
ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
delete from #barcodetemp where lotno = @lotno
SET @needqty=@needqty-@qty
END
ELSE IF(@needqty-@qty<0 and ISNULL(@lotno, '')<>'')
BEGIN
insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@needqty,ISNULL(AmountUnit, ''),
ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
update #barcodetemp set quantity = @qty-@needqty where lotno = @lotno
SET @needqty=@needqty-@qty
END
ELSE
BEGIN
insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,0,ISNULL(AmountUnit, ''),
ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
SET @needqty=0
END
END
END
FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID;
END
CLOSE tempCursor
DEALLOCATE tempCursor
END
select TransCode,LotNo,LocationQty AS Quantity,InvCode,DetailID,Sequence,TransSequence from #resulttemp
--select * from #resulttemp
DROP table #maintemp
DROP table #resulttemp
DROP table #barcodetemp";
#endregion
sql = String.Format(sql, LotNo, WorkPoint, Quantity);
DataTable table = DBHelper.SQlReturnData(sql, cmd);
string json = JsonConvert.SerializeObject(table);
List downItemModels = JsonConvert.DeserializeObject>(json);
foreach (DownItemModel model in downItemModels)
{
if (model != null && model.LotNo == null || "" == model.LotNo)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo201"));
}
WareHouseLotInfoDown(Identification, model.TransCode, model.Sequence + "~" + model.TransSequence, model.LotNo, model.Quantity, User, WorkPoint, "13", BusinessCode, cmd, language);
//回写已领数量
sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + model.Quantity + ") WHERE OODetailID='{0}' AND Sequence='{1}' AND WorkPoint='{2}'";
sql = String.Format(sql, model.DetailID, model.TransSequence, WorkPoint);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
}
}
}
#endregion
}
catch (Exception)
{
throw;
}
}
///
/// 添加库存
///
///
///
///
///
///
///
///
///
///
public static void WareHouseLotInfoUpForkLift(string Identification, string LocationCode, string ContainerCode, string User,
string TransType, string BusinessCode, SqlCommand cmd, Dictionary language)
{
try
{
#region 正常入库
///添加库存(原条码退回,更新库存;新条码直接入库)
//stirng locationcode = "";
string sql = string.Empty;
string locationcode = "";
string lotsql = @" select A.LotNo,C.Quantity,B.WorkPoint from ICSContainerLot A
LEFT JOIN ICSContainer B ON B.ID=A.ContainerID AND B.WorkPoint=A.WorkPoint
LEFT JOIN ICSInventoryLot C ON C.LotNo=A.LotNo AND C.WorkPoint=A.WorkPoint
where B.ContainerCode='{0}'";
lotsql = string.Format(lotsql, ContainerCode);
DataTable lotdt = DBHelper.SQlReturnData(lotsql, cmd);
if (lotdt.Rows.Count == 0)
{
throw new Exception("托盘号不存在或者尚未绑定条码!");
}
foreach (DataRow dr in lotdt.Rows)
{
sql = @"
IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
BEGIN
IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.Quantity=0)
BEGIN
UPDATE a SET a.Quantity=ISNULL(a.Quantity,0)+'{3}',WarehouseCode=e.WarehouseCode,LocationCode=d.LocationCode
From ICSWareHouseLotInfo a
INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
END
ELSE IF EXISTS(SELECT a.LotNO FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.LocationCode='{4}')
BEGIN
UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{3}'
WHERE LotNo='{0}' AND WorkPoint='{1}'
END
ELSE IF('" + locationcode + @"' != '{4}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo395"), "{4}", locationcode) + @"', 16, 1);
RETURN
END
END
ELSE
BEGIN
IF EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
BEGIN
IF NOT EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}' AND il.LocationCode='{4}')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo180") + @"',16,1);
RETURN
END
END
INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
SELECT NEWID(),a.LotNo ,e.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0','{2}','{2}',SYSDATETIME() ,a.WorkPoint ,''
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
--INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
END";
sql = string.Format(sql, dr["LotNo"].ToString(), dr["WorkPoint"].ToString(), User, dr["Quantity"].ToString(), LocationCode);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
}
///添加日志
sql = @"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(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
'','',c.WarehouseCode,c.LocationCode,'{6}',
'','0','{4}','{5}','0','',
'','','','{2}','{2}',
SYSDATETIME() ,a.WorkPoint ,''
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
";
sql = string.Format(sql, dr["LotNo"].ToString(), dr["WorkPoint"].ToString(), User, Identification, TransType, BusinessCode, dr["Quantity"].ToString());
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
}
}
#endregion
}
catch (Exception)
{
throw;
}
}
///
/// 添加库存(货柜)
///
///
///
///
///
///
///
///
///
///
public static void WareHouseLotInfoUpForHG(string Identification, string TransCode, string TransLine, string INVCode, string Quantity, string User,
string WorkPoint, string HGCode, string TransType, string BusinessCode, SqlCommand cmd, Dictionary language)
{
try
{
string LocationCode = "";
string WHCode = "";
string LotNo = "";
#region 根据传入的料号和数量自动生成条码
if (BusinessCode == "2")
{
string ExtensionID = "";
string Pre = "DN" + TransCode + TransLine;
string PRODUCTDATE = DateTime.Now.ToString();
string lotsql = @"SELECT TOP 1 ISNULL(ExtensionID,'') AS ExtensionID FROM ICSDeliveryNotice WHERE DNCode='{0}' AND WorkPoint='{1}'";
lotsql = string.Format(lotsql, TransCode, WorkPoint);
DataTable lotdt = DBHelper.SQlReturnData(lotsql, cmd);
if (lotdt.Rows.Count != 0)
{
ExtensionID = lotdt.Rows[0]["ExtensionID"].ToString();
}
lotsql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
lotsql = string.Format(lotsql, WorkPoint, "ICSInventoryLot", "LotNO", Pre, 5);
LotNo = DBHelper.SQlReturnData(lotsql, cmd).Rows[0][0].ToString();
lotsql = string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
Values('{0}','{1}','{2}','{3}','{3}',getdate(),'{4}' )",
LotNo, TransCode, TransLine, User, WorkPoint);
lotsql += string.Format(@"insert into ICSInventoryLot
(ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount)
select
newid(),'{0}',InvCode,'{1}','2999-12-31 00:00:00.000','{2}','{7}','7','{3}','{3}', getdate(),'{4}',0
from ICSDeliveryNotice where DNCode='{5}' and Sequence='{6}' and WorkPoint='{4}'",
LotNo, PRODUCTDATE, Quantity, User, WorkPoint, TransCode, TransLine, ExtensionID);
if (!DBHelper.ExecuteNonQuery(lotsql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo215"));
}
}
else if (BusinessCode == "18")
{
string ExtensionID = "";
string Pre = "KCP" + TransCode + TransLine;
string PRODUCTDATE = DateTime.Now.ToString();
string lotsql = @"SELECT TOP 1 ISNULL(ExtensionID,'') AS ExtensionID FROM ICSManufactureReceive WHERE RCVCode='{0}' AND WorkPoint='{1}'";
lotsql = string.Format(lotsql, TransCode, WorkPoint);
DataTable lotdt = DBHelper.SQlReturnData(lotsql, cmd);
if (lotdt.Rows.Count != 0)
{
ExtensionID = lotdt.Rows[0]["ExtensionID"].ToString();
}
lotsql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
lotsql = string.Format(lotsql, WorkPoint, "ICSInventoryLot", "LotNO", Pre, 5);
LotNo = DBHelper.SQlReturnData(lotsql, cmd).Rows[0][0].ToString();
lotsql = string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
Values('{0}','{1}','{2}','{3}','{3}',getdate(),'{4}' )",
LotNo, TransCode, TransLine, User, WorkPoint);
lotsql += string.Format(@"insert into ICSInventoryLot
(ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount)
select
newid(),'{0}',InvCode,'{1}','2999-12-31 00:00:00.000','{2}','{7}','9','{3}','{3}', getdate(),'{4}',0
from ICSManufactureReceive where RCVCode='{5}' and Sequence='{6}' and WorkPoint='{4}'",
LotNo, PRODUCTDATE, Quantity, User, WorkPoint, TransCode, TransLine, ExtensionID);
if (!DBHelper.ExecuteNonQuery(lotsql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo215"));
}
}
else if (BusinessCode == "16")
{
string ExtensionID = "";
string Pre = "MA" + TransCode + TransLine;
string PRODUCTDATE = DateTime.Now.ToString();
string lotsql = @"SELECT TOP 1 ISNULL(ExtensionID,'') AS ExtensionID FROM ICSMOApplyNegDetail WHERE ApplyNegCode='{0}' AND WorkPoint='{1}'";
lotsql = string.Format(lotsql, TransCode, WorkPoint);
DataTable lotdt = DBHelper.SQlReturnData(lotsql, cmd);
if (lotdt.Rows.Count != 0)
{
ExtensionID = lotdt.Rows[0]["ExtensionID"].ToString();
}
lotsql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
lotsql = string.Format(lotsql, WorkPoint, "ICSInventoryLot", "LotNO", Pre, 5);
LotNo = DBHelper.SQlReturnData(lotsql, cmd).Rows[0][0].ToString();
lotsql = string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
Values('{0}','{1}','{2}','{3}','{3}',getdate(),'{4}' )",
LotNo, TransCode, TransLine, User, WorkPoint);
lotsql += string.Format(@"insert into ICSInventoryLot
(ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount)
select
newid(),'{0}',InvCode,'{1}','2999-12-31 00:00:00.000','{2}','{7}','12','{3}','{3}', getdate(),'{4}',0
from ICSMOApplyNegDetail where ApplyNegCode='{5}' and Sequence='{6}' and WorkPoint='{4}'",
LotNo, PRODUCTDATE, Quantity, User, WorkPoint, TransCode, TransLine, ExtensionID);
if (!DBHelper.ExecuteNonQuery(lotsql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo215"));
}
}
#endregion
#region 正常入库
#region 根据传入的货柜机器号找到对应的入库库位和仓库(一个机器号可能对应多个库位,需要根据料号找到对应区域确认唯一的入库库位)
string chksql = @"select F_Define2 AS BinCode,C.WarehouseCode AS WHCode from Sys_SRM_ItemsDetail A
LEFT JOIN ICSLocation B ON B.LocationCode=A.F_Define2 AND B.WorkPoint=A.F_Define4
LEFT JOIN ICSWarehouse C ON C.ID=B.WHID AND C.WorkPoint=B.WorkPoint
where F_Define1='{0}' AND F_ItemName='HG_Location' AND F_Define4='{1}'";
chksql = string.Format(chksql, HGCode, WorkPoint);
DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
if (chkdt.Rows.Count == 0)
{
throw new Exception("传入货柜机器号:" + HGCode + "没有维护对应的WMS入库库位!");
}
else
{
#region 根据料号和仓库找到对应的区域
string locationsql = @"";
if (BusinessCode == "2")
{
locationsql = @"select B.LocationCode from ICSDeliveryNotice A
INNER JOIN ICSInventoryDetail B ON B.INVCode=A.InvCode AND B.WHCode=A.WHCode
AND B.WorkPoint=A.WorkPoint
WHERE A.DNCode='{0}' AND A.WorkPoint='{1}'";
}
else if (BusinessCode == "18")
{
locationsql = @"select B.LocationCode from ICSManufactureReceive A
INNER JOIN ICSInventoryDetail B ON B.INVCode=A.InvCode AND B.WHCode=A.WHCode AND B.WorkPoint=A.WorkPoint
WHERE A.RCVCode='{0}' AND A.WorkPoint='{1}'";
}
else if (BusinessCode == "16")
{
locationsql = @"select B.LocationCode from ICSMOApplyNeg A
INNER JOIN ICSMOApplyNegDetail C ON C.ApplyNegCode=A.ApplyNegCode AND C.WorkPoint=A.WorkPoint
INNER JOIN ICSInventoryDetail B ON B.INVCode=C.InvCode AND B.WHCode=C.WHCode AND B.WorkPoint=C.WorkPoint
WHERE A.ApplyNegCode='{0}' AND A.WorkPoint='{1}'";
}
locationsql = string.Format(locationsql, TransCode, WorkPoint);
DataTable locationdt = DBHelper.SQlReturnData(locationsql, cmd);
if (locationdt.Rows.Count == 0)
{
throw new Exception("单据:" + TransCode + "对应仓库及物料没有维护对应的区域,无法入库!");
}
else
{
foreach (DataRow dr in chkdt.Rows)
{
if (dr["BinCode"].ToString().Split('-')[1].ToString() == locationdt.Rows[0]["LocationCode"].ToString())
{
LocationCode = dr["BinCode"].ToString();
WHCode = dr["WHCode"].ToString();
}
}
}
#endregion
}
#endregion
if (LocationCode == "")
{
throw new Exception("传入机器号:" + HGCode + "对应的库位所在区域与单据:" + TransCode + "对应仓库及物料的所在区域不符,无法入库!");
}
string sql = string.Empty;
sql = @" INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
SELECT NEWID(),a.LotNo ,'{4}','{5}',a.InvCode ,'{3}',SYSDATETIME(),'0','{2}','{2}',SYSDATETIME() ,a.WorkPoint ,''
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, WHCode, LocationCode);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
}
///添加日志
sql = @"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(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
'','',c.WarehouseCode,c.LocationCode,'{6}',
'','0','{4}','{5}','0','',
'','','','{2}','{2}',
SYSDATETIME() ,a.WorkPoint ,''
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
--INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
";
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
}
#endregion
}
catch (Exception)
{
throw;
}
}
///
/// 减少库存
///
///
///
///
///
///
///
///
///
///
///
public static DataTable WareHouseLotInfoDown(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User,
string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary language, string MergeID = "")
{
String LotEnable = "";
String PrintEnable = "";
string lotstr = "";
int result = 0;
List NewBarCodeList = new List();
DataTable dtLotno = new DataTable();
DataTable lstDt = new DataTable();
try
{
///更新库存
string sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
RETURN
END";
sql = string.Format(sql, LotNo, WorkPoint, Quantity);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
}
//出库后取消占料
sql = @"update b set b.LockQuantity = convert(decimal(18, 6), b.LockQuantity) - convert(decimal(18, 6), c.Quantity)
from dbo.ICSWareHouseLotInfo b
inner join (select sum(Quantity) as Quantity, LotNo from ICSWareHouseLotInfolog where
LotNo='{0}' AND TransCode ='{1}' AND TransSequence='{2}'
and TransType = '15' and WorkPoint = '{3}' group by LotNo) c
on c.LotNo = b.LotNo
DELETE FROM ICSWareHouseLotInfoLog
WHERE LotNo='{0}' AND TransCode='{1}' AND TransSequence='{2}' AND WorkPoint='{3}' AND TransType='15'";
sql = string.Format(sql, LotNo, TransCode, TransSequence, WorkPoint);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
//throw new Exception("占料信息解除失败!");//"库存更新失败!");
}
//检验是否分批
sql = @"SELECT b.LotEnable,b.PrintEnable FROM ICSInventoryLot a
LEFT JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
where a.LotNo='{0}' and a.WorkPoint='{1}'
";
sql = string.Format(sql, LotNo, WorkPoint);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
if (dt.Rows.Count == 0)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
}
else
{
LotEnable = dt.Rows[0]["LotEnable"].ToString();
PrintEnable = dt.Rows[0]["PrintEnable"].ToString();
}
if (LotEnable.Equals("True"))
{
///分批前添加日志
sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
RETURN
END
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(),'{3}','{7}','{8}',a.LotNo ,a.InvCode ,
c.WarehouseCode,c.LocationCode,'','',c.Quantity+{6},
'','0','{4}','31','0','',
'','','',f.F_Account ,f.F_RealName ,
SYSDATETIME() ,a.WorkPoint ,''
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
";
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, TransCode, TransSequence);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
}
#region 获取分批后的条码(lotstr)
sql = @"SELECT TOP 1 LotNO FROM ICSInventoryLot WHERE EATTRIBUTE1='{0}' AND WorkPoint='{1}'
ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC";
sql = string.Format(sql, LotNo, WorkPoint);
dt = DBHelper.SQlReturnData(sql, cmd);
if (dt.Rows.Count == 0)
{
lotstr = LotNo + "-" + 1;
}
else
{
lotstr = LotNo + "-" + (Convert.ToInt32(dt.Rows[0]["LotNO"].ToString().Split('-')[dt.Rows[0]["LotNO"].ToString().Split('-').Length - 1]) + 1).ToString();
}
NewBarCodeList.Add(lotstr);//将分批后新条码添加到新集合
#endregion
#region 将分批后的条码记录插入条码表,库存表及日志表并将原条码库存数量清零
sql = @"INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
Quantity,Amount,ExtensionID,Type,PrintTimes,
LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
WorkPoint,EATTRIBUTE1)
SELECT TOP 1 NEWID(),'{0}',a.InvCode,a.ProductDate,a.ExpirationDate,
'{2}',a.Amount,a.ExtensionID,a.Type,a.PrintTimes,
a.LastPrintUser,a.LastPrintTime,a.MUSER ,a.MUSERName ,GETDATE(),
a.WorkPoint ,'{1}'
From ICSInventoryLot a
where a.LotNo='{1}' and a.WorkPoint='{3}'";
sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
cmd.CommandText = sql;
result = cmd.ExecuteNonQuery();
if (result <= 0)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo195"));//条码分批后条码表存入失败!
}
sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
select NEWID(),'{0}',WarehouseCode,LocationCode,InvCode,'0',InDate,0
,MUSER,MUSERName,GETDATE(),'{3}',''
from ICSWareHouseLotInfo
where LotNO='{1}' AND WorkPoint='{3}'";
sql = string.Format(sql, lotstr, LotNo, Quantity, WorkPoint);
cmd.CommandText = sql;
result = cmd.ExecuteNonQuery();
if (result <= 0)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo196"));//条码分批后库存表存入失败!
}
//插入条码单据表
sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
sql = string.Format(sql, LotNo, WorkPoint, User, lotstr);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
}
sql = @"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,LogID)
SELECT NEWID(),'{3}','{4}','{5}','{10}' ,a.InvCode ,
c.WarehouseCode,c.LocationCode,'','','{6}',
'','0','{7}','{8}','0','',
'','','',f.F_Account ,f.F_RealName ,
SYSDATETIME() ,a.WorkPoint ,'','{9}'
FROM ICSInventoryLot a
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
";
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID, lotstr);
cmd.CommandText = sql;
result = cmd.ExecuteNonQuery();
if (result <= 0)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo197"));//条码分批后库存日志表存入失败!
}
if (PrintEnable.Equals("True"))
{
sql = @"select A.LotNO AS OLDLotNo , C.Quantity AS OLDLotQty, A.eattribute1 as LotNO, B.Quantity AS LotQty ,b.InvCode,d.INVSTD,d.INVNAME,b.MTIME,A.TransCode
from ICSWareHouseLotInfolog A
left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
where A.lotno like'{0}%' and a.workpoint='{1}'
";
sql = string.Format(sql, LotNo, WorkPoint);
dtLotno = DBHelper.SQlReturnData(sql, cmd);
lstDt = dtLotno;
}
///添加日志
sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
RETURN
END
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,MergeID)
SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
c.WarehouseCode,c.LocationCode,'','',c.Quantity,
'','0','{7}','32','0','',
'','','',f.F_Account ,f.F_RealName ,
SYSDATETIME() ,a.WorkPoint ,'','{9}'
FROM ICSInventoryLot a
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
";
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
}
#endregion
}
else
{
NewBarCodeList.Add(LotNo);
///添加日志
sql = @"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,MergeID)
SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
c.WarehouseCode,c.LocationCode,'','','{6}',
'','0','{7}','{8}','0','',
'','','','{2}','{2}',
SYSDATETIME() ,a.WorkPoint ,'','{9}'
FROM ICSInventoryLot a
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
--INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
";
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
}
}
}
catch (Exception)
{
throw;
}
return lstDt;
}
///
/// 减少库存(货柜)
///
///
///
///
///
///
///
///
///
///
///
public static DataTable WareHouseLotInfoDownHG(string Identification, string TransCode, string User,
string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary language, string MergeID = "")
{
String LotEnable = "";
String PrintEnable = "";
string lotstr = "";
int result = 0;
DataTable dtLotno = new DataTable();
DataTable lstDt = new DataTable();
try
{
#region 根据占料获取库存条码
string sql = @"select TransSequence,LotNo,Quantity,InvCode from ICSWareHouseLotInfoLog
where TransCode='{0}' and TransType='15' and WorkPoint='{1}'";
sql = string.Format(sql, TransCode, WorkPoint);
DataTable lotdt = DBHelper.SQlReturnData(sql, cmd);
if (lotdt.Rows.Count == 0)
{
throw new Exception("未查询到单据占料信息,无法出库!");
}
#endregion
foreach (DataRow dr in lotdt.Rows)
{
///更新库存
sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
RETURN
END";
sql = string.Format(sql, dr["LotNo"].ToString(), WorkPoint, Convert.ToDecimal(dr["Quantity"]));
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
}
//出库后取消占料
sql = @"update b set b.LockQuantity = convert(decimal(18, 6), b.LockQuantity) - convert(decimal(18, 6), c.Quantity)
from dbo.ICSWareHouseLotInfo b
inner join (select sum(Quantity) as Quantity, LotNo from ICSWareHouseLotInfolog where
LotNo='{0}' AND TransCode ='{1}' AND TransSequence='{2}'
and TransType = '15' and WorkPoint = '{3}' group by LotNo) c
on c.LotNo = b.LotNo
DELETE FROM ICSWareHouseLotInfoLog
WHERE LotNo='{0}' AND TransCode='{1}' AND TransSequence='{2}' AND WorkPoint='{3}' AND TransType='15'";
sql = string.Format(sql, dr["LotNo"].ToString(), TransCode, dr["TransSequence"].ToString(), WorkPoint);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
//throw new Exception("占料信息解除失败!");//"库存更新失败!");
}
///添加日志
sql = @"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,MergeID)
SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
c.WarehouseCode,c.LocationCode,'','','{6}',
'','0','{7}','{8}','0','',
'','','','{2}','{2}',
SYSDATETIME() ,a.WorkPoint ,'','{9}'
FROM ICSInventoryLot a
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
--INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
";
sql = string.Format(sql, dr["LotNo"].ToString(), WorkPoint, User, Identification, TransCode, dr["TransSequence"].ToString()
, Convert.ToDecimal(dr["Quantity"]), TransType, BusinessCode, MergeID);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
}
}
}
catch (Exception)
{
throw;
}
return lstDt;
}
///
/// 出库单据增加验证,整单全部出库之后删除所有跟单据关联的占料信息,解锁占料数量
///
///
///
///
///
public static void MaterialOccpyCancel(string TransType, string TransCode, string WorkPoint, SqlCommand cmd, Dictionary language)
{
try
{
//验证单据是否整单出库完成,若已完成,则删除所有相关占料信息并解除占料数量
bool DocComplete = false;
string sql = "";
if (TransType == "采购退货-采购退货单")
{
sql = @"select SUM(Quantity) as NeedQTY,SUM(RCVQuantity) AS HasQTY from ICSDeliveryNotice
where DNCode='{0}' and WorkPoint='{1}'";
}
else if (TransType == "生产发料-领料申请单")
{
sql = @"select SUM(Quantity) as NeedQTY,SUM(IssueQuantity) AS HasQTY from ICSMOApply
where ApplyCode='{0}' and WorkPoint='{1}'";
}
else if (TransType == "委外发料-委外领料申请单")
{
sql = @"select SUM(Quantity) as NeedQTY,SUM(IssueQuantity) AS HasQTY from ICSOApply
where ApplyCode='{0}' and WorkPoint='{1}'";
}
else if (TransType == "销售发货-销售发货单")
{
sql = @"select SUM(Quantity) as NeedQTY,SUM(SDNQuantity) AS HasQTY from ICSSDN
where SDNCode='{0}' and WorkPoint='{1}'";
}
else if (TransType == "杂发")
{
sql = @"select SUM(Quantity) as NeedQTY,SUM(OutQuantity) AS HasQTY from ICSOtherOut
where OutCode='{0}' and WorkPoint='{1}'";
}
sql = string.Format(sql, TransCode, WorkPoint);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
if (dt.Rows.Count != 0)
{
if (Convert.ToDecimal(dt.Rows[0]["NeedQTY"]) == Convert.ToDecimal(dt.Rows[0]["HasQTY"]))
{
DocComplete = true;
}
}
if (DocComplete == true)
{
sql = @"select LotNo,Quantity from ICSWareHouseLotInfoLog
where TransCode='{0}' AND WorkPoint='{1}' and TransType=15";
sql = string.Format(sql, TransCode, WorkPoint);
dt = DBHelper.SQlReturnData(sql, cmd);
foreach (DataRow dr in dt.Rows)
{
sql += @" update ICSWareHouseLotInfo set LockQuantity=CONVERT(decimal(18,6),LockQuantity)-{0}
where LotNo='{1}' AND WorkPoint='{2}' ";
sql = string.Format(sql, dr["Quantity"].ToString(), dr["LotNo"].ToString(), WorkPoint);
}
DBHelper.ExecuteNonQuery(sql, cmd);
sql = @"DELETE FROM ICSWareHouseLotInfoLog
WHERE TransType=15 AND TransCode='{0}' AND WorkPoint='{1}'";
sql = string.Format(sql, TransCode, WorkPoint);
DBHelper.ExecuteNonQuery(sql, cmd);
}
}
catch (Exception)
{
throw;
}
}
///
/// 减少库存(无条码领料)
///
///
///
///
///
///
///
///
///
///
///
public static DataTable WareHouseLotInfoDownWithOutLot(string Identification, string TransCode, string User,
string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary language, string MergeID = "")
{
String LotEnable = "";
String PrintEnable = "";
string lotstr = "";
int result = 0;
List NewBarCodeList = new List();
DataTable dtLotno = new DataTable();
DataTable lstDt = new DataTable();
try
{
#region 根据单据获得占料信息
string docsql = @"select TransSequence,LotNo,Quantity,InvCode from ICSWareHouseLotInfoLog
where TransCode='{0}' and TransType='15' and WorkPoint='{1}'";
docsql = string.Format(docsql, TransCode, WorkPoint);
DataTable docdt = DBHelper.SQlReturnData(docsql, cmd);
#endregion
foreach (DataRow dr in docdt.Rows)
{
string INVCode = dr["InvCode"].ToString();
decimal lotQuantity = Convert.ToDecimal(dr["Quantity"]);
string DocLineNO = dr["TransSequence"].ToString();
string LotNO = dr["LotNo"].ToString();
///更新库存
string sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
RETURN
END";
sql = string.Format(sql, LotNO, WorkPoint, lotQuantity);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
}
///添加日志
sql = @"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,MergeID)
SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
c.WarehouseCode,c.LocationCode,'','','{6}',
'','0','{7}','{8}','0','',
'','','','{2}','{2}',
SYSDATETIME() ,a.WorkPoint ,'','{9}'
FROM ICSInventoryLot a
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
sql = string.Format(sql, LotNO, WorkPoint, User, Identification, TransCode, DocLineNO, lotQuantity, TransType, BusinessCode, MergeID);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
}
}
//出库后取消占料
string cancelsql = @"update b set b.LockQuantity = convert(decimal(18, 6), b.LockQuantity) - convert(decimal(18, 6), c.Quantity)
from dbo.ICSWareHouseLotInfo b
inner join (select sum(Quantity) as Quantity, LotNo from ICSWareHouseLotInfolog where TransCode ='{0}'
and TransType = '15' and WorkPoint = '{1}' group by LotNo) c
on c.LotNo = b.LotNo
DELETE FROM ICSWareHouseLotInfoLog
WHERE TransCode='{0}' AND WorkPoint='{1}' AND TransType='15'";
cancelsql = string.Format(cancelsql, TransCode, WorkPoint);
if (!DBHelper.ExecuteNonQuery(cancelsql, cmd))
{
//throw new Exception("占料信息解除失败!");//"库存更新失败!");
}
}
catch (Exception)
{
throw;
}
return lstDt;
}
///
/// 修改库存
///
///
///
///
///
///
///
///
///
///
public static void WareHouseLotInfoUpdate(string Identification, string TransCode, string TransSequence, string LotNo, string Quantity, string User,
string WorkPoint, string TransType, string CheckKind, SqlCommand cmd, Dictionary language)
{
try
{
///添加日志
string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
RETURN
END
IF EXISTS(SELECT LotNo FROM ICSWareHouseLotInfoLog WHERE LotNo='{0}' AND WorkPoint='{1}' AND TransType=15)
BEGIN
RAISERROR('条码:{0}存在占料信息,请取消占料后再修改库存!',16,1);
RETURN
END
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(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
a.WarehouseCode,a.LocationCode,'','',a.Quantity,
'{8}','0','{6}','{7}','0','',
'','','',f.F_Account ,f.F_RealName ,
SYSDATETIME() ,a.WorkPoint ,''
FROM ICSWareHouseLotInfo a
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
";
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, TransTypeEnum.LOTCheckBefore.GetDescription(), CheckKind);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
}
///更新库存
sql = @"UPDATE ICSWareHouseLotInfo SET Quantity='{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'";
sql = string.Format(sql, LotNo, WorkPoint, Quantity);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
}
///添加日志
sql = @"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(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
a.WarehouseCode,a.LocationCode,'','',a.Quantity,
'{8}','0','{6}','{7}','0','',
'','','',f.F_Account ,f.F_RealName ,
SYSDATETIME() ,a.WorkPoint ,''
FROM ICSWareHouseLotInfo a
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
";
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, TransTypeEnum.LOTCheckAfter.GetDescription(), CheckKind);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
}
}
catch (Exception)
{
throw;
}
}
///
/// 调拨
///
///
///
///
///
///
///
///
///
public static DataTable WareHouseLotInfoTransfer(string Identification, string TransCode, string TransSequence, string WarehouseCode, string LocationCode,
string LotNo, string Quantity, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary language, string MergeID)
{
bool? LotEnable = null;
String PrintEnable = "";
string lotstr = "";
int result = 0;
DataTable dtLotno = new DataTable();
DataTable lstDt = new DataTable();
List NewBarCodeList = new List();
try
{
var tranferWorkpoint = string.Empty;
var checksql = $@"SELECT
top 1 a.EATTRIBUTE1
FROM
ICSTransfer a
WHERE
TransferNO = '{TransCode}'
AND Sequence = '{TransSequence}'
AND WorkPoint = '{WorkPoint}'
AND Type = '{TransType}'";
var workPoint = DBHelper.ExecuteScalar(checksql, cmd).ToString();
if (workPoint == null || workPoint == "")
{
tranferWorkpoint = WorkPoint;
}
else
{
tranferWorkpoint = workPoint.ToString();
}
#region 先删除条码的占料信息
string sql = @" update b set b.LockQuantity = convert(decimal(18, 6), b.LockQuantity) - convert(decimal(18, 6), c.Quantity)
from dbo.ICSWareHouseLotInfo b
inner join (select sum(Quantity) as Quantity, LotNo from ICSWareHouseLotInfolog where
LotNo='{0}' AND TransCode ='{1}' AND TransSequence='{2}'
and TransType = '15' and WorkPoint = '{3}' group by LotNo) c
on c.LotNo = b.LotNo
delete from ICSWareHouseLotInfoLog
where LotNo='{0}' and TransCode='{1}' and TransSequence='{2}' and WorkPoint='{3}' and TransType=15";
sql = string.Format(sql, LotNo, TransCode, TransSequence, WorkPoint);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
//throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
}
#endregion
///分批前添加日志
sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
RETURN
END
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(),'{3}','{7}','{8}',a.LotNo ,a.InvCode ,
c.WarehouseCode,c.LocationCode,'','',c.Quantity,
'','0','{4}','31','0','',
'','','',f.F_Account ,f.F_RealName ,
SYSDATETIME() ,'{1}' ,'{9}'
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
";
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode, Quantity, TransCode, TransSequence, tranferWorkpoint);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
}
///更新库存
sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}',--LocationCode = '{3}',
WorkPoint ='{4}' WHERE LotNo='{0}' AND WorkPoint='{1}';
UPDATE ICSInventoryLot SET WorkPoint='{4}' WHERE LotNo='{0}' AND WorkPoint='{1}';
IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
RETURN
END";
sql = string.Format(sql, LotNo, WorkPoint, Quantity, LocationCode, tranferWorkpoint);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
}
#region 获取分批后的条码(lotstr)
sql = @"SELECT TOP 1 LotNO FROM ICSInventoryLot WHERE EATTRIBUTE1='{0}' AND WorkPoint='{1}'
ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC";
sql = string.Format(sql, LotNo, tranferWorkpoint);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
if (dt.Rows.Count == 0)
{
lotstr = LotNo + "-" + 1;
}
else
{
lotstr = LotNo + "-" + (Convert.ToInt32(dt.Rows[0]["LotNO"].ToString().Split('-')[dt.Rows[0]["LotNO"].ToString().Split('-').Length - 1]) + 1).ToString();
}
NewBarCodeList.Add(lotstr);//将分批后新条码添加到新集合
#endregion
#region 将分批后的条码记录插入条码表,库存表及日志表并将原条码库存数量清零
sql = @"INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
Quantity,Amount,ExtensionID,Type,PrintTimes,
LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
WorkPoint,EATTRIBUTE1)
SELECT TOP 1 NEWID(),'{0}',a.InvCode,a.ProductDate,a.ExpirationDate,
'{2}',a.Amount,a.ExtensionID,a.Type,a.PrintTimes,
a.LastPrintUser,a.LastPrintTime,a.MUSER ,a.MUSERName ,GETDATE(),
'{3}' ,'{1}'
From ICSInventoryLot a
where a.LotNo='{1}' and a.WorkPoint='{3}'";
sql = string.Format(sql, lotstr, LotNo, Quantity, tranferWorkpoint);
cmd.CommandText = sql;
result = cmd.ExecuteNonQuery();
if (result <= 0)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo195"));//条码分批后条码表存入失败!
}
#endregion
sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
select NEWID(),'{0}','{4}','{5}',InvCode,'{2}',InDate,0
,MUSER,MUSERName,GETDATE(),'{3}',''
from ICSWareHouseLotInfo
where LotNO='{1}' AND WorkPoint='{3}'";
sql = string.Format(sql, lotstr, LotNo, Quantity, tranferWorkpoint, WarehouseCode, LocationCode);
cmd.CommandText = sql;
result = cmd.ExecuteNonQuery();
if (result <= 0)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo196"));//条码分批后库存表存入失败!
}
//插入条码单据表
sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
SELECT '{0}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,'{1}'
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON b.LotNo='{3}' AND a.WorkPoint=b.WorkPoint
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
WHERE a.LotNo='{3}' AND a.WorkPoint='{1}'";
sql = string.Format(sql, lotstr, tranferWorkpoint, User, LotNo);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
}
sql = @"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,LogID)
SELECT NEWID(),'{3}','{4}','{5}','{10}' ,a.InvCode ,
c.WarehouseCode,c.LocationCode,'{11}','{12}','{6}',
'','0','{7}','{8}','0','',
'','','',f.F_Account ,f.F_RealName ,
SYSDATETIME() ,'{1}' ,'{13}','{9}'
FROM ICSInventoryLot a
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
WHERE a.LotNo='{0}' AND a.WorkPoint='{13}'
";
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID, lotstr, WarehouseCode, LocationCode, tranferWorkpoint);
cmd.CommandText = sql;
result = cmd.ExecuteNonQuery();
if (result <= 0)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo197"));//条码分批后库存日志表存入失败!
}
///添加日志
sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
RETURN
END
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,MergeID)
SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
c.WarehouseCode,c.LocationCode,'','',c.Quantity,
'','0','{7}','32','0','',
'','','',f.F_Account ,f.F_RealName ,
SYSDATETIME() ,'{1}' ,'{10}','{9}'
FROM ICSInventoryLot a
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
WHERE a.LotNo='{0}' AND a.WorkPoint='{10}'
";
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, MergeID, tranferWorkpoint);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
}
if (PrintEnable.Equals("True"))
{
sql = @"select A.LotNO , C.Quantity AS OLDLotQty, B.Quantity AS LotQty ,b.InvCode,d.INVSTD,d.INVNAME,b.MTIME,A.TransCode
from ICSWareHouseLotInfolog A
left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
where (a.BusinessCode ='{2}' or a.BusinessCode='32')
and A.lotno like '{0}%' and a.workpoint='{1}'
and a.TransCode='{3}' and a.TransSequence='{4}'
";
sql = string.Format(sql, LotNo, WorkPoint, BusinessCode, TransCode, TransSequence);
dtLotno = DBHelper.SQlReturnData(sql, cmd);
lstDt = dtLotno;
}
#region 整单验证,如果单据全部完成,整单删除占料信息
bool DocComplete = false;
sql = @"select SUM(Quantity) as NeedQTY,SUM(TransferQuantity) AS HasQTY from ICSTransfer
where TransferNO='{0}' and WorkPoint='{1}'";
sql = string.Format(sql, TransCode, WorkPoint);
DataTable chkdt = DBHelper.SQlReturnData(sql, cmd);
if (dt.Rows.Count != 0)
{
if (Convert.ToDecimal(chkdt.Rows[0]["NeedQTY"]) == Convert.ToDecimal(chkdt.Rows[0]["HasQTY"]))
{
DocComplete = true;
}
}
if (DocComplete == true)
{
sql = @"select LotNo,Quantity from ICSWareHouseLotInfoLog
where TransCode='{0}' AND WorkPoint='{1}' and TransType=15";
sql = string.Format(sql, TransCode, WorkPoint);
dt = DBHelper.SQlReturnData(sql, cmd);
foreach (DataRow dr in dt.Rows)
{
sql += @" update ICSWareHouseLotInfo set LockQuantity=CONVERT(decimal(18,6),LockQuantity)-{0}
where LotNo='{1}' AND WorkPoint='{2}' ";
sql = string.Format(sql, dr["Quantity"].ToString(), dr["LotNo"].ToString(), WorkPoint);
}
DBHelper.ExecuteNonQuery(sql, cmd);
sql = @"DELETE FROM ICSWareHouseLotInfoLog
WHERE TransType=15 AND TransCode='{0}' AND WorkPoint='{1}'";
sql = string.Format(sql, TransCode, WorkPoint);
DBHelper.ExecuteNonQuery(sql, cmd);
}
#endregion
}
catch (Exception)
{
throw;
}
return lstDt;
}
///
/// 移库
///
///
///
///
///
///
///
///
///
public static void WareHouseLotInfoLibrary(string Identification, string TransCode, string TransSequence, string WarehouseCode, string LocationCode,
string LotNo, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary language)
{
try
{
string sql = @"SELECT WarehouseCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
sql = string.Format(sql, LotNo, WorkPoint);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
if (dt == null || dt.Rows.Count <= 0)
{
throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), LotNo));
}
string whcode = dt.Rows[0]["WarehouseCode"].ToString();
///添加日志
sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
RETURN
END
IF('" + whcode + @"' != '{8}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo394"), "{8}", whcode) + @"', 16, 1);
RETURN
END
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(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
c.WarehouseCode,c.LocationCode,'{8}','{9}',c.Quantity,
'','0','{6}','{7}','0','',
'','','',f.F_Account ,f.F_RealName ,
SYSDATETIME() ,a.WorkPoint ,''
FROM ICSInventoryLot a
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
";
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, TransType, BusinessCode, WarehouseCode, LocationCode);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
}
///添加库存
sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity>0)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo038") + @"',16,1);
RETURN
END
IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.WarehouseCode='{2}')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo038") + @"',16,1);
RETURN
END
UPDATE ICSWareHouseLotInfo SET WarehouseCode='{2}',LocationCode='{3}' WHERE LotNo='{0}' AND WorkPoint='{1}'
";
sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存表更新失败!");
}
}
catch (Exception)
{
throw;
}
}
///
/// 两步调入
///
///
///
///
///
///
///
///
///
public static void WareHouseLotInfoTwoStepTransferDocIn(string Identification, string TransCode, string TransSequence, string WarehouseCode,
string LocationCode, string LotNo, string Quantity, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary language)
{
try
{
///添加日志
string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
RETURN
END
INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
ToWarehouseCode,ToLocationCode,Quantity,
Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
MTIME,WorkPoint,EATTRIBUTE1)
SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
'{9}','{10}','{6}',
'','0','{7}','{8}','0','',
'','','',f.F_Account ,f.F_RealName ,
SYSDATETIME() ,a.WorkPoint ,''
FROM ICSInventoryLot a
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
";
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransCode, TransSequence, Quantity, TransType, BusinessCode, WarehouseCode, LocationCode);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
}
///添加库存
sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo171") + @"',16,1);
RETURN
END
UPDATE ICSWareHouseLotInfo SET WarehouseCode='{2}',LocationCode='{3}',Quantity=Quantity+'{4}' WHERE LotNo='{0}' AND WorkPoint='{1}'
";
sql = string.Format(sql, LotNo, WorkPoint, WarehouseCode, LocationCode, Quantity);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存表更新失败!");
}
}
catch (Exception)
{
throw;
}
}
///
/// 拆分、合并日志
///
///
///
///
///
///
///
///
public static DataTable WareHouseLotInfoLog(string Identification, string LotNo, string User, string WorkPoint, string TransType, string BusinessCode, SqlCommand cmd, Dictionary language)
{
String LotEnable = "";
String PrintEnable = "";
DataTable dtLotno = new DataTable();
DataTable lstDt = new DataTable();
try
{
//检验是否分批
string sql = @"SELECT b.LotEnable,b.PrintEnable FROM ICSInventoryLot a
LEFT JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
where a.LotNo='{0}' and a.WorkPoint='{1}'
";
sql = string.Format(sql, LotNo, WorkPoint);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
if (dt.Rows.Count == 0)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
}
else
{
LotEnable = dt.Rows[0]["LotEnable"].ToString();
PrintEnable = dt.Rows[0]["PrintEnable"].ToString();
}
///添加日志
sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
RETURN
END
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(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
'','',c.WarehouseCode,c.LocationCode,c.Quantity,
'','0','{4}','{5}','0','',
'','','',f.F_Account ,f.F_RealName ,
SYSDATETIME() ,a.WorkPoint ,''
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
";
sql = string.Format(sql, LotNo, WorkPoint, User, Identification, TransType, BusinessCode);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
}
if (PrintEnable.Equals("True"))
{
sql = @"select A.LotNO , C.Quantity AS OLDLotQty, B.Quantity AS LotQty ,b.InvCode,d.INVSTD,d.INVNAME,b.MTIME,A.TransCode
from ICSWareHouseLotInfolog A
left join ICSInventoryLot B on A.LotNO=B.LotNO and a.WorkPoint=b.WorkPoint
left join ICSWareHouseLotInfo C ON A.LotNO=C.LotNO and a.WorkPoint=c.WorkPoint
left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
where a.BusinessCode='32'
and A.lotno like '{0}%' and a.workpoint='{1}'
";
sql = string.Format(sql, LotNo, WorkPoint, BusinessCode);
dtLotno = DBHelper.SQlReturnData(sql, cmd);
lstDt = dtLotno;
}
}
catch (Exception)
{
throw;
}
return lstDt;
}
///
/// 合并
///
///
///
///
///
///
///
///
public static void WareHouseLotInfoMerge(string Identification, string LotNo, string CurrentLotNo, string Quantity, string User, string WorkPoint, string TransType,
string BusinessCode, SqlCommand cmd, Dictionary language)
{
try
{
///更新目标条码库存
string sql = @"IF NOT EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
INNER JOIN ICSInventoryLot b ON b.LotNo='{3}' AND a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo170") + @"',16,1);
RETURN
END
IF NOT EXISTS (SELECT a.LotNo FROM ICSInventoryLot a,ICSInventoryLot b WHERE
a.LotNo= '{0}' AND b.LotNo= '{3}'
AND a.WorkPoint= '{1}' AND a.ExtensionID= b.ExtensionID )
BEGIN
RAISERROR ('" + language.GetNameByCode("WMSAPIInfo467") + @"',16,1 );
RETURN
END
IF NOT EXISTS (SELECT a.LotNo FROM ICSWareHouseLotInfo a,ICSWareHouseLotInfo b WHERE
a.LotNo= '{0}' AND b.LotNo= '{3}'
AND a.WorkPoint= '{1}' AND a.WarehouseCode= b.WarehouseCode )
BEGIN
RAISERROR ( '" + language.GetNameByCode("WMSAPIInfo468") + @"', 16, 1 );
RETURN
END
IF NOT EXISTS (SELECT a.LotNo FROM ICSWareHouseLotInfo a,ICSWareHouseLotInfo b WHERE
a.LotNo= '{0}' AND b.LotNo= '{3}'
AND a.WorkPoint= '{1}' AND a.LocationCode= b.LocationCode )
BEGIN
RAISERROR ( '" + language.GetNameByCode("WMSAPIInfo469") + @"', 16, 1 );
RETURN
END
IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo171") + @"',16,1);
RETURN
END
UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)+'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
";
sql = string.Format(sql, LotNo, WorkPoint, Quantity, CurrentLotNo);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo169"));//"目标条码库存更新失败!");
}
///更新原条码库存
sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
RETURN
END";
sql = string.Format(sql, CurrentLotNo, WorkPoint, Quantity);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
}
///添加日志
sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
RETURN
END
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(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
'','',c.WarehouseCode,c.LocationCode,c.Quantity,
'','0','{4}','{5}','0','',
'','','',f.F_Account ,f.F_RealName ,
SYSDATETIME() ,a.WorkPoint ,''
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
";
sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Identification, TransType, BusinessCode);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
}
}
catch (Exception)
{
throw;
}
}
///
/// 拆分
///
///
///
///
///
///
///
///
public static void WareHouseLotInfoSplit(string Identification, string LotNo, string CurrentLotNo, string Quantity, string User, string WorkPoint, string TransType,
string BusinessCode, SqlCommand cmd, Dictionary language)
{
try
{
///更新库存
string sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=ISNULL(Quantity,0)-'{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'
IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Quantity<0)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo167") + @"',16,1);
RETURN
END";
sql = string.Format(sql, LotNo, WorkPoint, Quantity);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
}
#region 添加库存
//插入条码表
sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
RETURN
END
IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a WHERE a.LotNo='{4}' AND a.WorkPoint='{1}')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo172") + @"',16,1);
RETURN
END
INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
SELECT NEWID(),'{4}' ,a.InvCode,a.ProductDate,a.ExpirationDate ,'{3}',a.ExtensionID,'101',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,a.LotNo
FROM ICSInventoryLot a
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, CurrentLotNo);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo173"));//"条码表写入失败!");
}
//插入条码单据表
sql = @"INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint)
SELECT '{3}',b.TransCode,b.TransSequence,f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
sql = string.Format(sql, LotNo, WorkPoint, User, CurrentLotNo);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo174"));//"条码单据表写入失败!");
}
///添加库存
sql = @"IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo164") + @"',16,1);
RETURN
END
IF EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint
WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
BEGIN
IF NOT EXISTS(SELECT il.InvCode FROM ICSInventoryLocation il
INNER JOIN ICSInventoryLot a ON a.InvCode=il.InvCode AND a.WorkPoint=il.WorkPoint
INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint AND il.LocationCode=d.LocationCode
WHERE il.Enable='1' AND a.LotNo='{0}' AND a.WorkPoint='{1}')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo180") + @"',16,1);
RETURN
END
END
INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
SELECT NEWID(),a.LotNo ,d.WarehouseCode,d.LocationCode,a.InvCode ,'{3}',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSWareHouseLotInfo d ON a.EATTRIBUTE1=d.LotNo AND a.WorkPoint=d.WorkPoint
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Quantity);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
}
///添加日志
sql = @"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(),'{3}',b.TransCode,b.TransSequence,a.LotNo ,a.InvCode ,
'','',c.WarehouseCode,c.LocationCode,c.Quantity,
'','0','{4}','{5}','0','',
'','','',f.F_Account ,f.F_RealName ,
SYSDATETIME() ,a.WorkPoint ,''
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSWareHouseLotInfo c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
";
sql = string.Format(sql, CurrentLotNo, WorkPoint, User, Identification, TransType, BusinessCode);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
}
#endregion
}
catch (Exception)
{
throw;
}
}
///
/// 回写ERP ID
///
///
///
///
///
///
///
///
///
public static void WareHouseLotInfoLogUpdate(string TransType, string SourceDetailID, string Identification, string ID, string DetailID, string Code, string Sequence, string col, SqlCommand cmd, Dictionary language, string BusinessCode)
{
string ERPupdate = string.Empty;
try
{
//采购入库
if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.PODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.towarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
";
}
//审核的到货单
else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.towarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
";
}
//采购拒收
else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
";
}
//审核的委外到货单
else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.ODNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
";
}
//委外拒收
else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
";
}
//采购退货
else if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSDeliveryNotice c ON a.TransCode=c.DNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.DNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.DNType='2' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
";
}
//委外发料
else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSOutsourcingOrder y ON a.TransCode=y.OOCode AND a.WorkPoint=y.WorkPoint
INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE x.PickID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
";
}
//委外退料
else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
|| TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
|| TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
{
ERPupdate = @"--根据退料单退料
UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
Left JOIN ICSOIssue m ON (CASE WHEN d.Type='3' THEN c.SourceDetailID ELSE 0 END)=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE ISNULL(m.ApplyDetailID,ISNULL(m.PickID, c.SourceDetailID))='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
--根据原条码退料-备料表
UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSOutsourcingOrder y ON b.TransCode=y.OOCode AND b.WorkPoint=y.WorkPoint
INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE x.PickID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
--根据原条码退料-申请单
UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE z.ApplyDetailID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
--根据原条码退料-材料出库单
UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE ISNULL(m.ApplyDetailID, m.PickID)='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
";
}
//委外入库
else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.OODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
";
}
//委外退货
else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSODeliveryNotice c ON a.TransCode=c.ODNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.ODNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.ODNType='2' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
";
}
//生产发料
else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSMO y ON a.TransCode=y.MOCode AND a.WorkPoint=y.WorkPoint
INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE x.PickID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
";
}
//生产退料
else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
|| TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
|| TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
{
ERPupdate = @"--根据退料单退料
UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
left JOIN ICSMOIssue m ON (CASE WHEN d.Type='3' THEN c.SourceDetailID ELSE 0 END)=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
WHERE ISNULL(m.ApplyDetailID, ISNULL(m.PickID, c.SourceDetailID))='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
--根据原条码退料-备料表
UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO y ON b.TransCode=y.MOCode AND b.WorkPoint=y.WorkPoint
INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
WHERE x.PickID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
--根据原条码退料-申请单
UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
WHERE z.ApplyDetailID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
--根据原条码退料-材料出库单
UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
WHERE ISNULL(m.ApplyDetailID, m.PickID)='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
";
}
//生产入库
else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.MODetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
";
}
//开立的生产入库单
else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND a.BusinessCode ='{7}'
";
}
//销售出库
else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
";
}
//销售退货
else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
";
}
//返工工单
else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE d.PickID='{3}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
";
}
//一步调拨
else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSTransfer c ON a.TransCode=c.TransferNO AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
WHERE c.TransferID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND a.BusinessCode ='{7}'
";
}
//调拨
else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSTransfer c ON a.TransCode=c.TransferNO AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
WHERE c.TransferID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='1' AND a.BusinessCode ='{7}'
";
}
//两步调出
else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSOtherOut c ON a.TransCode=c.OutCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
INNER JOIN ICSTransfer d ON c.TransferDetailID=d.TransferDetailID AND c.WorkPoint=d.WorkPoint
WHERE c.OutID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
";
}
//两步调入
else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
WHERE b.InID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
";
}
//销售退货-原条码
else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.SDNDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
";
}
//其他出库
else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSOtherOut c ON a.TransCode=c.OutCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
WHERE c.OutID='{0}' AND a.Identification='{1}' AND a.ERPUpload='0' AND a.BusinessCode ='{7}'
";
}
//其他入库
else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
WHERE c.InID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
";
}
//拆卸单
else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
{
ERPupdate = @"UPDATE d set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSWareHouseLotInfoLog d ON b.TransCode=d.TransCode AND d.TransSequence='1' AND b.WorkPoint=d.WorkPoint
WHERE c.DABDOCID='{0}' AND a.Identification='{1}' AND d.ERPUpload='0' AND a.BusinessCode ='{7}'
UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
WHERE c.DABDOCID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.DABDOCType='2' AND a.BusinessCode ='{7}'
";
}
//领料申请单
else if (TransType == TransTypeEnum.MOApply.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSMOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
";
}
//委外领料申请单
else if (TransType == TransTypeEnum.OOApply.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.ApplyDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
";
}
//开立材料出库
else if (TransType == TransTypeEnum.MOIssue.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSMOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
WHERE c.IssueID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
";
}
//开立委外材料出库
else if (TransType == TransTypeEnum.OOIssue.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
WHERE c.IssueID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
";
}
//开立红字入库单
else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSPurchaseReceive c ON a.TransCode=c.RCVCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND a.BusinessCode ='{7}'
";
}
//开立委外红字入库单
else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSOutsourcingReceive c ON a.TransCode=c.RCVCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
WHERE c.RCVID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND c.Type='2' AND a.BusinessCode ='{7}'
";
}
//借用
else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSBrrow c ON a.TransCode=c.BrrowCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.BrrowDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.fromwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
";
}
//归还
else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
{
ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE c.ReturnDetailID='{0}' AND a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{7}'
and (ISNULL(a.tohwarehousecode, '') + ISNULL(ext.ProjectCode, '') + CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END + ISNULL(ext.Version, '') + ISNULL(ext.Brand, '') +
ISNULL(ext.cFree1, '') + ISNULL(ext.cFree2, '') + ISNULL(ext.cFree3, '') + ISNULL(ext.cFree4, '') + ISNULL(ext.cFree5, '')+ ISNULL(ext.cFree6, '') + ISNULL(ext.cFree7, '') + ISNULL(ext.cFree8, '') + ISNULL(ext.cFree9, '') + ISNULL(ext.cFree10, ''))='{6}'
";
}
ERPupdate = string.Format(ERPupdate, SourceDetailID, Identification, ID, DetailID, Code, Sequence, col, BusinessCode);
if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
{
throw new Exception(TransType + language.GetNameByCode("WMSAPIInfo175"));//"回写日志失败!");
}
}
catch (Exception ex)
{
log.Debug(ex.ToString());
log.Debug(TransType + Environment.NewLine + ERPupdate);
throw;
}
}
///
/// 倒冲时子件已领数量回写
///
public static void DetailQTYUpdate()
{
}
///
/// 生成条码
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
public static void CreateLotNo(string LotNo, string Quantity, string TransCode, string TransSequence, string WorkPoint, string Identification, string User, string InvCode, string BusinessCode,
string ProjectCode, string BatchCode, string Version, string Brand, string cFree1, string cFree2, string cFree3, string cFree4, string cFree5, string cFree6, string cFree7, string cFree8, string cFree9, string cFree10, SqlCommand cmd, Dictionary language, string LocationCode, string OLDLotNo)
{
try
{
String EffectiveEnable = "";
String Colspan = "";
String IDD = "";
int EffectiveDays = 0;
String Time = "";
int EffectiveDayss = 0;
DateTime dtt;
DateTime now = DateTime.Now;
string sql = string.Empty;
//string sql = @"select EffectiveEnable,EffectiveDays from ICSInventory a
// Left Join ICSMO b ON a.InvCode=b.InvCode and a.WorkPoint = b.WorkPoint
// where b.MoCode='{0}' and b.WorkPoint='{1}'";
//sql = string.Format(sql, TransCode, WorkPoint);
//DataTable dt = DBHelper.SQlReturnData(sql, cmd);
//if (dt.Rows.Count == 0)
//{
// throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
//}
//else
//{
// EffectiveEnable = dt.Rows[0]["EffectiveEnable"].ToString();
//EffectiveDays = Convert.ToInt32(dt.Rows[0]["EffectiveDays"]);
//}
//EffectiveDayss = Convert.ToInt32(EffectiveDays);
//if (!EffectiveEnable.Equals("False"))
//{
int year = now.Year;
int month = now.Month;
int day = now.Day;
int n = DateTime.DaysInMonth(year, month);
int k = day + EffectiveDays;
if (k > n)
{
day = EffectiveDays - (n - day);
month = month + 1;
if (month > 12)
{
month = 1;
year = year + 1;
}
}
else
{
day = day + EffectiveDays;
}
Time = year + "-" + month + "-" + day;
//}
//else
//{
// Time = "2999-12-31 00:00:00.000";
//}
dtt = Convert.ToDateTime(Time);
//检验自由项
Colspan = ProjectCode + "~" + BatchCode + "~" + Version
+ "~" + Brand + "~" + cFree1
+ "~" + cFree2 + "~" + cFree3 + "~" + cFree4
+ "~" + cFree5 + "~" + cFree6 + "~" + cFree7
+ "~" + cFree8 + "~" + cFree9 + "~" + cFree10;
sql = @"select ID,Colspan from ICSExtension a
where Colspan='{0}' and WorkPoint='{1}'";
sql = string.Format(sql, Colspan, WorkPoint);
DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
if (dttt.Rows.Count == 0)
{
IDD = Guid.NewGuid().ToString();
sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
sql = string.Format(sql, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, User, WorkPoint, IDD);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
}
}
else
{
IDD = dttt.Rows[0]["ID"].ToString();
}
//存入条码表
sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
RETURN
END
INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
Quantity,Amount,ExtensionID,Type,PrintTimes,
LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
WorkPoint,EATTRIBUTE1)
SELECT TOP 1 NEWID(),'{0}','{8}',GETDATE(),'{6}',
'{1}','0','{7}','16',null,
null,null,'{2}' ,f.F_RealName ,GETDATE(),
'{4}' ,''
FROM Sys_SRM_User f
where f.F_Account='{2}' and f.F_Location='{4}'
";
sql = string.Format(sql, LotNo, Quantity, User, TransCode, WorkPoint, TransSequence, dtt, IDD, InvCode);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
}
///存入条码关联表
sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{3}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
RETURN
END
INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,
WorkPoint,EATTRIBUTE1)
SELECT '{4}','{0}','{1}',f.F_Account ,f.F_RealName,GETDATE(),
a.WorkPoint,''
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
WHERE a.LotNo='{5}' AND a.WorkPoint='{3}'
";
sql = string.Format(sql, TransCode, TransSequence, User, WorkPoint, LotNo, OLDLotNo);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo367"));
}
//存入库存表
sql = @"INSERT INTO ICSWareHouseLotInfo(ID,LotNO,WarehouseCode,LocationCode,InvCode,Quantity,InDate,LockQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
SELECT NEWID(),a.LotNo ,e.WarehouseCode,d.LocationCode,a.InvCode ,'0',SYSDATETIME(),'0',f.F_Account ,f.F_RealName ,SYSDATETIME() ,a.WorkPoint ,''
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
--INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSLocation d ON d.LocationCode='{4}' AND a.WorkPoint=d.WorkPoint
INNER JOIN ICSWarehouse e ON d.WHID=e.ID AND d.WorkPoint=e.WorkPoint
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'";
sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, LocationCode);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo165"));
}
}
catch (Exception)
{
throw;
}
}
///
/// 料架条码绑定
///
///
///
///
///
///
///
public static void ContainerBind(string LotNo, string ContainerCode, string ContainerType, string LocationCode, string RecomendBinCode, string User, string WorkPoint, SqlCommand cmd, Dictionary language)
{
try
{
///添加日志
if (ContainerType != "窄巷道叉车(木托盘)")
{
string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{3}") + @"',16,1);
RETURN
END
IF NOT EXISTS(SELECT ID FROM ICSInventoryLot WHERE LotNO='{0}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{0}") + @"',16,1);
RETURN
END
IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCode='{1}' AND WorkPoint='{2}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo473"), "{2}", "{1}") + @"',16,1);
RETURN
END
IF NOT EXISTS (SELECT * FROM ICSContainerLot WHERE ContainerID=
(SELECT ID FROM ICSContainer WHERE ContainerCode='{1}' AND WorkPoint='{2}') AND LotNo='{0}')
BEGIN
-- update ICSContainer set EATTRIBUTE1='已绑定' where ContainerCode='{1}' AND WorkPoint='{2}'
INSERT INTO ICSContainerLot
(ID,ContainerID,LotNo,MUSER,MUSERName,WorkPoint,MTIME,EATTRIBUTE1)
SELECT NEWID(),ID,'{0}','{3}'
,(SELECT F_RealName FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}'),'{2}',GETDATE(),'' FROM ICSContainer
WHERE ContainerCode='{1}' AND WorkPoint='{2}'
END
-- ELSE
-- BEGIN
-- update ICSContainer set LocationCode='{4}',EATTRIBUTE1='已绑定' where ContainerCode='{1}' AND WorkPoint='{2}'
-- UPDATE ICSContainerLot SET LotNo='{0}' WHERE ContainerID=
-- (SELECT ID FROM ICSContainer WHERE ContainerCode='{1}' AND WorkPoint='{2}')
-- END
";
sql = string.Format(sql, LotNo, ContainerCode, WorkPoint, User, LocationCode);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception("容器:" + ContainerCode + "与条码:" + LotNo + "绑定失败!");
}
}
else
{
string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{3}") + @"',16,1);
RETURN
END
IF NOT EXISTS (SELECT * FROM ICSContainerLot WHERE ContainerID=
(SELECT ID FROM ICSContainer WHERE ContainerCode='{1}' AND WorkPoint='{2}'))
BEGIN
INSERT INTO ICSContainerLot
(ID,ContainerID,LotNo,MUSER,MUSERName,WorkPoint,MTIME,EATTRIBUTE1)
SELECT NEWID(),ID,'{0}','{3}'
,(SELECT F_RealName FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}'),'{2}',GETDATE(),'{4}' FROM ICSContainer
WHERE ContainerCode='{1}' AND WorkPoint='{2}'
END
ELSE
BEGIN
UPDATE ICSContainerLot SET LotNo='{0}' WHERE ContainerID=
(SELECT ID FROM ICSContainer WHERE ContainerCode='{1}' AND WorkPoint='{2}')
END
";
sql = string.Format(sql, LotNo, ContainerCode, WorkPoint, User, LocationCode);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception("容器:" + ContainerCode + "与条码:" + LotNo + "绑定失败!");
}
if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadForkLift"]))
{
string ForkLiftUrl = System.Configuration.ConfigurationManager.AppSettings["ForkLiftUrl"];
string Year = DateTime.Now.Year.ToString();
string Month = DateTime.Now.Month.ToString().PadLeft(2, '0');
string Day = DateTime.Now.Day.ToString().PadLeft(2, '0');
string Hour = DateTime.Now.Hour.ToString().PadLeft(2, '0');
string Minute = DateTime.Now.Minute.ToString().PadLeft(2, '0');
string Second = DateTime.Now.Second.ToString().PadLeft(2, '0');
string InspectJosn = "{";
InspectJosn += "\"ID\":\"" + Year + Month + Day + Hour + Minute + Second + "\",";
InspectJosn += "\"PalletID\": \"" + ContainerCode + "\",";
InspectJosn += "\"LaneCode\": \"\",";
InspectJosn += "\"TaskType\": \"PTWY\",";
InspectJosn += "\"SourceBin\": \"\",";
InspectJosn += "\"DestBin\": \"" + RecomendBinCode + "\"";
InspectJosn += "}";
RestHelper rest = new RestHelper(ForkLiftUrl, HttpVerb.POST);
rest.PostData = InspectJosn;
string strResult = rest.MakeRequest();
//string resultstr = HTTPHelper.Post(ERPUrl.AGVBineURL, InspectJosn);
ForkLiftResult result = JsonConvert.DeserializeObject(strResult);
if (result.Ret == 1)
{
sql = @"update ICSContainer set LocationCode='{2}',EATTRIBUTE1='已搬运' where ContainerCode='{0}' AND WorkPoint='{1}'";
sql = string.Format(sql, ContainerCode, WorkPoint, LocationCode);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo207"));//料架状态更新失败
}
}
else
{
throw new Exception(result.RetMsg);
}
}
}
//else
//{
// if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
// {
// string Year = DateTime.Now.Year.ToString();
// string Month = DateTime.Now.Month.ToString().PadLeft(2, '0');
// string Day = DateTime.Now.Day.ToString().PadLeft(2, '0');
// string Hour = DateTime.Now.Hour.ToString().PadLeft(2, '0');
// string Minute = DateTime.Now.Minute.ToString().PadLeft(2, '0');
// string Second = DateTime.Now.Second.ToString().PadLeft(2, '0');
// // {
// // "reqCode":"20230420150602",
// // "podCode":"200051",
// // "positionCode":"105670AA130750",
// // "indBind":"1"
// //}
// string InspectJosn = "{";
// InspectJosn += "\"reqCode\":\"" + Year + Month + Day + Hour + Minute + Second + "\",";
// InspectJosn += "\"podCode\": \"" + ContainerCode + "\",";
// InspectJosn += "\"positionCode\": \"" + LocationCode + "\",";
// InspectJosn += "\"indBind\": \"1\",";
// InspectJosn += "\"PodDir\": \"0\"";
// InspectJosn += "}";
// if (InspectJosn != "")
// {
// RestHelper rest = new RestHelper(ERPUrl.AGVBineURL, HttpVerb.POST);
// rest.PostData = InspectJosn;
// string strResult = rest.MakeRequest();
// //string resultstr = HTTPHelper.Post(ERPUrl.AGVBineURL, InspectJosn);
// AGVPodBindOutputModel result = JsonConvert.DeserializeObject(strResult);
// if (result.code == 0)
// {
// sql = @"update ICSContainer set LocationCode='{2}',EATTRIBUTE1='已绑定' where ContainerCode='{0}' AND WorkPoint='{1}'";
// sql = string.Format(sql, ContainerCode, WorkPoint, LocationCode);
// if (!DBHelper.ExecuteNonQuery(sql, cmd))
// {
// throw new Exception(language.GetNameByCode("WMSAPIInfo207"));//料架状态更新失败
// }
// }
// else
// {
// throw new Exception(result.message);
// }
// }
// }
//}
}
catch (Exception)
{
throw;
}
}
///
/// 料架条码解绑
///
///
///
///
///
public static void ContainerUnBind(string ContainerCode, string WorkPoint, SqlCommand cmd, Dictionary language)
{
try
{
string datasql = @"select LocationCode from ICSContainer
where ContainerCode='{0}' and WorkPoint='{1}'";
datasql = string.Format(datasql, ContainerCode, WorkPoint);
DataTable datadt = DBHelper.SQlReturnData(datasql, cmd);
if (datadt.Rows.Count == 0)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo207"));
}
else
{
string LocationCode = datadt.Rows[0]["LocationCode"].ToString();
string sql = @"delete from ICSContainerLot
WHERE ContainerID=
(SELECT ID FROM ICSContainer WHERE ContainerCode='{0}' AND WorkPoint='{1}')";
sql = string.Format(sql, ContainerCode, WorkPoint);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception("料架:" + ContainerCode + "解绑失败!");
}
//else
//{
// if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
// {
// AGVPodBindInputModel Info = new AGVPodBindInputModel();
// Info.reqCode = "5";
// Info.podCode = ContainerCode;
// Info.positionCode = LocationCode;
// Info.indBind = "0";
// string poststr = JsonConvert.SerializeObject(Info);
// string resultstr = HTTPHelper.HttpPost("AGV料架解绑", ERPUrl.AGVBineURL, poststr);
// AGVPodBindOutputModel result = JsonConvert.DeserializeObject(resultstr.ToString());
// if (result.code != 0)
// {
// throw new Exception(result.message);
// }
// else
// {
// sql = @"Update ICSContainer set EATTRIBUTE1='',LocationCode=''
// WHERE ContainerCode='{0}' AND WorkPoint='{1}'";
// sql = string.Format(sql, ContainerCode, WorkPoint);
// if (!DBHelper.ExecuteNonQuery(sql, cmd))
// {
// throw new Exception(language.GetNameByCode("WMSAPIInfo207"));//料架状态更新失败
// }
// }
// }
//}
}
}
catch (Exception)
{
throw;
}
}
///
/// 呼叫AGV开始搬运任务
///
///
///
///
///
///
///
public static void CallAGVStartTask(string ContainerCode, string TransType, string LocationCode, string User, string WorkPoint, SqlCommand cmd, Dictionary language)
{
try
{
string sql = @"select ContainerCode from ICSContainer
where LocationCode='{0}' and WorkPoint='{1}'";
sql = string.Format(sql, ContainerCode, WorkPoint);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
if (dt.Rows.Count == 0)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo209"));//位置编码未绑定料架
}
else
{
ContainerCode = dt.Rows[0]["ContainerCode"].ToString();
}
if (TransType == "开始任务")
{
sql = @"update ICSContainer set EATTRIBUTE1='已搬运' where ContainerCode='{0}' AND WorkPoint='{1}'";
}
else
{
sql = @"update ICSContainer set EATTRIBUTE1='已绑定' where ContainerCode='{0}' AND WorkPoint='{1}'";
}
sql = string.Format(sql, ContainerCode, WorkPoint, LocationCode);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo207"));//料架状态更新失败
}
//if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
//{
// string Year = DateTime.Now.Year.ToString();
// string Month = DateTime.Now.Month.ToString().PadLeft(2, '0');
// string Day = DateTime.Now.Day.ToString().PadLeft(2, '0');
// string Hour = DateTime.Now.Hour.ToString().PadLeft(2, '0');
// string Minute = DateTime.Now.Minute.ToString().PadLeft(2, '0');
// string Second = DateTime.Now.Second.ToString().PadLeft(2, '0');
// AGVStartTaskModel Info = new AGVStartTaskModel();
// List LineList = new List();
// AGVStartTaskLineModel LineInfo = new AGVStartTaskLineModel();
// Info.reqCode = Year + Month + Day + Hour + Minute + Second;
// Info.podCode = ContainerCode;
// Info.taskTyp = "F01";
// LineInfo.positionCode = LocationCode;
// LineInfo.type = "00";
// LineList.Add(LineInfo);
// LineInfo = new AGVStartTaskLineModel();
// LineInfo.positionCode = "1";//目标位置编码待提供
// LineInfo.type = "04";
// LineList.Add(LineInfo);
// Info.positionCodePath = LineList;
// string poststr = JsonConvert.SerializeObject(Info);
// string resultstr = HTTPHelper.HttpPost("AGV开始任务", ERPUrl.AGVTaskStart, poststr);
// AGVStartTaskResultModel result = JsonConvert.DeserializeObject(resultstr.ToString());
// if (result.code == 0)
// {
// }
// else
// {
// throw new Exception(result.message);
// }
//}
}
catch (Exception)
{
throw;
}
}
///
/// 获取AGV搬运的目标位置
///
///
///
///
///
///
public static string GetAGVTaskPosition(string LocationCode, string User, string WorkPoint, SqlCommand cmd, Dictionary language)
{
try
{
string sql = @"select Define1 from Sys_EnumValues
where EnumKey='00011' AND EnumText='{0}' AND WorkPointCode='{1}'";
sql = string.Format(sql, LocationCode, WorkPoint);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
if (dt.Rows.Count == 0)
{
return "";
}
else
{
return dt.Rows[0]["Define1"].ToString();
}
}
catch (Exception)
{
throw;
}
}
///
/// 保存AGV任务ID
///
///
///
///
///
///
public static void ActionSaveAGVTaskCode(string TaskCode, string ContainerCode, string Location, bool IsOverLoad, string User, string WorkPoint, SqlCommand cmd, Dictionary language)
{
try
{
string sql = @"Insert into ICSAGVTaskLog
(ID,TaskCode,ContainerCode,LocationCode,IsOverLoad,UserCode,MTIME,WorkPoint)
select NEWID(),'{0}','{1}','{2}','{3}','{4}',GETDATE(),'{5}'";
if (IsOverLoad == true)
{
sql = string.Format(sql, TaskCode, ContainerCode, Location, "是", User, WorkPoint);
}
else
{
sql = string.Format(sql, TaskCode, ContainerCode, Location, "否", User, WorkPoint);
}
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
if (dt.Rows.Count == 0)
{
throw new Exception("已存在相同的任务ID,请勿重复下任务!");
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// AGV搬运完成回调
///
///
///
///
///
///
public static void ActionAGVTaskEnd(string reqCode, string currentPositionCode, string taskCode, string action, string podCode, SqlCommand cmd, Dictionary language)
{
try
{
#region 根据任务ID查询是否需要超托入库
bool OverLoad = false;
string ContainerCode = "";
string InWHCode = "";
string InLocationCode = "";
string sql = @"select ContainerCode,LocationCode,IsOverLoad from ICSAGVTaskLog
where TaskCode='{0}'";
sql = string.Format(sql, reqCode);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
if (dt.Rows.Count == 0)
{
throw new Exception("未查询到对应的任务ID:" + reqCode + "!");
}
else
{
if (dt.Rows[0]["IsOverLoad"].ToString() == "是")
{
OverLoad = true;
}
ContainerCode = dt.Rows[0]["IsOverLoad"].ToString();
#region 查询料架中条码对应单据的仓库及条码对应物料的区域(绑定时已做卡控,一个料架只能绑定同仓库区域的条码,故只要通过其中一个条码来判断)
sql = @"SELECT C.WHCode,C.LocationCode FROM ICSInventoryLotDetail A
INNER JOIN ICSDeliveryNotice B ON B.DNCode=A.TransCode AND B.Sequence=A.TransSequence AND B.WorkPoint=A.WorkPoint
INNER JOIN ICSInventoryDetail C ON C.INVCode=B.InvCode AND C.WHCode=B.WHCode AND C.WorkPoint=B.WorkPoint
WHERE A.LotNo=(select top 1 LotNo from ICSContainerLot A
INNER JOIN ICSContainer B ON B.ID=A.ContainerID
WHERE B.ContainerCode='{0}')
UNION ALL
SELECT C.WHCode,C.LocationCode FROM ICSInventoryLotDetail A
INNER JOIN ICSMOApplyNegDetail B ON B.ApplyNegCode=A.TransCode AND B.Sequence=A.TransSequence AND B.WorkPoint=A.WorkPoint
INNER JOIN ICSInventoryDetail C ON C.INVCode=B.InvCode AND C.WHCode=B.WHCode AND C.WorkPoint=B.WorkPoint
WHERE A.LotNo=(select top 1 LotNo from ICSContainerLot A
INNER JOIN ICSContainer B ON B.ID=A.ContainerID
WHERE B.ContainerCode='{0}')";
sql = string.Format(sql, ContainerCode);
dt = DBHelper.SQlReturnData(sql, cmd);
if (dt.Rows.Count == 0)
{
throw new Exception("未查询到料架:" + ContainerCode + ",对应的入库区域和仓库!");
}
else
{
InWHCode = dt.Rows[0]["WHCode"].ToString();
InLocationCode = dt.Rows[0]["LocationCode"].ToString();
#region 根据入库仓库和区域获取按库位编码排序后可以入库的下一个库位
if (OverLoad == false)
{
#region 正常入库
#region 获取已被超托入库占用的库位
string LocationIsTaken = "";
sql = @"SELECT A.EATTRIBUTE1 FROM ICSLocation A
INNER JOIN ICSWareHouseLotInfo B ON B.LocationCode=A.LocationCode AND B.WorkPoint=A.WorkPoint AND B.Quantity>0
WHERE ISNULL(A.EATTRIBUTE1,'')!='' AND A.LocationCode like ('{0}'+'-'+'{1}%')";
sql = string.Format(sql, InWHCode, InLocationCode);
dt = DBHelper.SQlReturnData(sql, cmd);
foreach (DataRow dr in dt.Rows)
{
if (LocationIsTaken == "")
{
LocationIsTaken += "'" + dr["EATTRIBUTE1"].ToString().Split(',')[0] + "','" + dr["EATTRIBUTE1"].ToString().Split(',')[1] + "'";
}
else
{
LocationIsTaken += ",'" + dr["EATTRIBUTE1"].ToString().Split(',')[0] + "','" + dr["EATTRIBUTE1"].ToString().Split(',')[1] + "'";
}
}
#endregion
sql = @"select TOP 1 A.LocationCode from ICSLocation A
LEFT JOIN ICSWareHouseLotInfo B ON B.LocationCode=A.LocationCode AND B.WorkPoint=A.WorkPoint AND B.Quantity>0
where B.LocationCode IS NULL AND A.LocationCode like ('{0}'+'-'+'{1}%') AND ISNULL(A.EATTRIBUTE1,'')=''
AND A.LocationCode NOT IN ({2})
ORDER BY A.LocationCode";
sql = string.Format(sql, InWHCode, InLocationCode, LocationIsTaken);
dt = DBHelper.SQlReturnData(sql, cmd);
if (dt.Rows.Count == 0)
{
throw new Exception("仓库:" + InWHCode + ",区域:" + InLocationCode + "无可用库位,无法入库!");
}
else
{
if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadForkLift"]))
{
string ForkLiftUrl = System.Configuration.ConfigurationManager.AppSettings["ForkLiftUrl"];
string Year = DateTime.Now.Year.ToString();
string Month = DateTime.Now.Month.ToString().PadLeft(2, '0');
string Day = DateTime.Now.Day.ToString().PadLeft(2, '0');
string Pre = "CC" + Year + Month + Day;
string serialsql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
serialsql = string.Format(serialsql, "1701", "ICSForkLiftTaskLog", "TaskCode", Pre, 4);
string TaskCode = DBHelper.SQlReturnData(serialsql, cmd).Rows[0][0].ToString();
string SerialNum = DateTime.Now.Hour.ToString().PadLeft(2, '0');
string InspectJosn = "{";
InspectJosn += "\"ID\":\"" + TaskCode + "\",";//任务编号
InspectJosn += "\"PalletID\": \"" + ContainerCode + "\",";//料架号
//InspectJosn += "\"LaneCode\": \"\",";
InspectJosn += "\"TaskType\": \"PTWY\",";//任务类型
InspectJosn += "\"SourceBin\": \"" + currentPositionCode + "\",";//起始点位
InspectJosn += "\"DestBin\": \"" + dt.Rows[0]["LocationCode"].ToString() + "\"";//目标点位
InspectJosn += "}";
RestHelper rest = new RestHelper(ForkLiftUrl, HttpVerb.POST);
rest.PostData = InspectJosn;
string strResult = rest.MakeRequest();
//string resultstr = HTTPHelper.Post(ERPUrl.AGVBineURL, InspectJosn);
ForkLiftResult result = JsonConvert.DeserializeObject(strResult);
if (result.Ret == 1)
{
#region 记录叉车的任务编号及相关信息
#endregion
sql = @"INSERT INTO ICSForkLiftTaskLog
(ID,TaskCode,ContainerCode,TaskType,StartLocation,EndLocation,MTIME,WorkPoint)
select NEWID(),'{0}','{1}','PTWY','{2}','{3}',GETDATE(),'1701'";
sql = string.Format(sql, TaskCode, ContainerCode, currentPositionCode, dt.Rows[0]["LocationCode"].ToString());
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
//throw new Exception("任务编码:" + TaskCode + ",日志记录失败");//料架状态更新失败
}
}
else
{
throw new Exception(result.RetMsg);
}
}
}
#endregion
}
else
{
#region 超托入库
#region 获取已被正常入库占用的库位
string LocationIsTaken = "";
sql = @"SELECT A.LocationCode,A.WorkPoint INTO #tempLocation FROM ICSLocation A
INNER JOIN ICSWareHouseLotInfo B ON B.LocationCode=A.LocationCode AND B.WorkPoint=A.WorkPoint AND B.Quantity>0
WHERE ISNULL(A.EATTRIBUTE1,'') = '' AND A.LocationCode like ('{0}'+'-'+'{1}%')
SELECT * INTO #tempOverLoad FROM ICSLocationOverLoad WHERE LocationCode like ('{0}'+'-'+'{1}%')
select Distinct A.OverLoadLocationCode from #tempOverLoad A
INNER JOIN #tempLocation B ON B.LocationCode=A.LocationCode AND B.WorkPoint=A.WorkPoint
drop table #tempLocation
drop table #tempOverLoad";
sql = string.Format(sql, InWHCode, InLocationCode);
dt = DBHelper.SQlReturnData(sql, cmd);
foreach (DataRow dr in dt.Rows)
{
if (LocationIsTaken == "")
{
LocationIsTaken += "'" + dr["OverLoadLocationCode"].ToString() + "'";
}
else
{
LocationIsTaken += ",'" + dr["OverLoadLocationCode"].ToString() + "'";
}
}
#endregion
sql = @"select TOP 1 A.LocationCode from ICSLocation A
LEFT JOIN ICSWareHouseLotInfo B ON B.LocationCode=A.LocationCode AND B.WorkPoint=A.WorkPoint AND B.Quantity>0
where B.LocationCode IS NULL AND A.LocationCode like ('{0}'+'-'+'{1}%') AND ISNULL(A.EATTRIBUTE1,'')!=''
AND A.LocationCode NOT IN ({2})
ORDER BY A.LocationCode";
sql = string.Format(sql, InWHCode, InLocationCode, LocationIsTaken);
dt = DBHelper.SQlReturnData(sql, cmd);
if (dt.Rows.Count == 0)
{
throw new Exception("仓库:" + InWHCode + ",区域:" + InLocationCode + "无可用库位,无法入库!");
}
else
{
if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadForkLift"]))
{
string ForkLiftUrl = System.Configuration.ConfigurationManager.AppSettings["ForkLiftUrl"];
string Year = DateTime.Now.Year.ToString();
string Month = DateTime.Now.Month.ToString().PadLeft(2, '0');
string Day = DateTime.Now.Day.ToString().PadLeft(2, '0');
string Pre = "CC" + Year + Month + Day;
string serialsql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
serialsql = string.Format(serialsql, "1701", "ICSForkLiftTaskLog", "TaskCode", Pre, 4);
string TaskCode = DBHelper.SQlReturnData(serialsql, cmd).Rows[0][0].ToString();
string SerialNum = DateTime.Now.Hour.ToString().PadLeft(2, '0');
string InspectJosn = "{";
InspectJosn += "\"ID\":\"" + TaskCode + "\",";//任务编号
InspectJosn += "\"PalletID\": \"" + ContainerCode + "\",";//料架号
//InspectJosn += "\"LaneCode\": \"\",";
InspectJosn += "\"TaskType\": \"PTWY\",";//任务类型
InspectJosn += "\"SourceBin\": \"" + currentPositionCode + "\",";//起始点位
InspectJosn += "\"DestBin\": \"" + dt.Rows[0]["LocationCode"].ToString() + "\"";//目标点位
InspectJosn += "}";
RestHelper rest = new RestHelper(ForkLiftUrl, HttpVerb.POST);
rest.PostData = InspectJosn;
string strResult = rest.MakeRequest();
//string resultstr = HTTPHelper.Post(ERPUrl.AGVBineURL, InspectJosn);
ForkLiftResult result = JsonConvert.DeserializeObject(strResult);
if (result.Ret == 1)
{
#region 记录叉车的任务编号及相关信息
sql = @"INSERT INTO ICSForkLiftTaskLog
(ID,TaskCode,ContainerCode,TaskType,StartLocation,EndLocation,MTIME,WorkPoint)
select NEWID(),'{0}','{1}','PTWY','{2}','{3}',GETDATE(),'1701'
Update ICSAGVCallBackLog set Result='成功',Message=''
where ReqCode='{4}'";
sql = string.Format(sql, TaskCode, ContainerCode, currentPositionCode, dt.Rows[0]["LocationCode"].ToString(), reqCode);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
//throw new Exception("任务编码:" + TaskCode + ",日志记录失败");//料架状态更新失败
}
#endregion
}
else
{
throw new Exception(result.RetMsg);
}
}
}
#endregion
}
#endregion
}
#endregion
}
#endregion
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 叉车搬运完成回调
///
///
///
///
public static void ActionForkLiftTaskEnd(string TaskID, string TaskType, string DestBin, SqlCommand cmd, Dictionary language)
{
try
{
if (TaskType == "PTWY上架")
{
#region 入库
#region 获取任务ID相关的料架条码及目标库位信息
string ContainerCode = "";
string StartLocation = "";
string EndLocation = "";
string sql = @"select ContainerCode,StartLocation,EndLocation from ICSForkLiftTaskLog
where TaskCode='{0}'";
sql = string.Format(sql, TaskID);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
if (dt.Rows.Count == 0)
{
throw new Exception("任务ID:" + TaskID + ",未查询到相关任务记录,无法入库!");
}
else
{
ContainerCode = dt.Rows[0]["ContainerCode"].ToString();
StartLocation = dt.Rows[0]["StartLocation"].ToString();
EndLocation = dt.Rows[0]["EndLocation"].ToString();
}
#endregion
#region 根据条码获取入库单据信息
string chksql = @"select COUNT(B.LotNo) AS LotCount from ICSContainer A
INNER JOIN ICSContainerLot B ON B.ContainerID=A.ContainerID AND B.WorkPoint=A.WorkPoint
WHERE ContainerCode='{0}'";
chksql = string.Format(chksql, ContainerCode);
DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
sql = @"select E.DNCode AS TransNO,E.Sequence AS TransLine,C.LotNo,C.Quantity,'采购入库' AS DocType
,A.WorkPoint,C.InvCode from ICSContainer A
INNER JOIN ICSContainerLot B ON B.ContainerID=A.ContainerID AND B.WorkPoint=A.WorkPoint
INNER JOIN ICSInventoryLot C ON C.LotNo=B.LotNo AND C.WorkPoint=B.WorkPoint
INNER JOIN ICSInventoryLotDetail D ON D.LotNo=C.LotNo AND D.WorkPoint=C.WorkPoint
INNER JOIN ICSDeliveryNotice E ON E.DNCode=D.TransCode AND E.Sequence=D.TransSequence AND E.WorkPoint=D.WorkPoint
where A.ContainerCode='{0}'
UNION ALL
select E.ApplyNegCode AS TransNO,E.Sequence AS TransLine,C.LotNo,C.Quantity,'生产退料' AS DocType
,A.WorkPoint,C.InvCode from ICSContainer A
INNER JOIN ICSContainerLot B ON B.ContainerID=A.ContainerID AND B.WorkPoint=A.WorkPoint
INNER JOIN ICSInventoryLot C ON C.LotNo=B.LotNo AND C.WorkPoint=B.WorkPoint
INNER JOIN ICSInventoryLotDetail D ON D.LotNo=C.LotNo AND D.WorkPoint=C.WorkPoint
INNER JOIN ICSMOApplyNegDetail E ON E.ApplyNegCode=D.TransCode AND E.Sequence=D.TransSequence AND E.WorkPoint=D.WorkPoint
where A.ContainerCode='{0}'";
sql = string.Format(sql, ContainerCode);
dt = DBHelper.SQlReturnData(sql, cmd);
if (chkdt.Rows.Count != dt.Rows.Count)
{
throw new Exception("料架:" + ContainerCode + ",绑定条码的数量与实际查到的条码单据关联数据不符,请确认条码信息!");
}
#endregion
else
{
#region WMS入库
string Identification = Guid.NewGuid().ToString();
string BusinessCode = string.Empty;
foreach (DataRow dr in dt.Rows)
{
if (dr["DocType"].ToString() == "采购入库")
{
#region 采购入库
ICSPurchaseService.DeliveryNoticeIn(dr["LotNo"].ToString(), dr["Quantity"].ToString(), dr["WorkPoint"].ToString(), cmd, language);
BusinessCode = TransTypeEnum.DeliveryNotice.GetDescription();
#endregion
}
else
{
#region 生产退料入库
ICSManufactureService.MOIssueDocNegative(TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
, "", dr["LotNo"].ToString(), dr["Quantity"].ToString(), dr["WorkPoint"].ToString(), cmd, language);
BusinessCode = TransTypeEnum.MOIssueDocNegative.GetDescription();
#endregion
}
WareHouseLotInfoUp(Identification, EndLocation, dr["LotNo"].ToString(), dr["Quantity"].ToString(),
"ForkLift", dr["WorkPoint"].ToString(), "2", BusinessCode
, cmd, language, "", dr["InvCode"].ToString() + EndLocation.Split('-')[0].ToString()
, DateTime.Now.ToString());
}
#endregion
}
#region 判断单据是否全部完成入库,并过账SAP
string docsql = @"select DISTINCT E.DNCode AS TransNO,'采购入库' AS DocType,A.WorkPoint from ICSContainer A
INNER JOIN ICSContainerLot B ON B.ContainerID=A.ContainerID AND B.WorkPoint=A.WorkPoint
INNER JOIN ICSInventoryLot C ON C.LotNo=B.LotNo AND C.WorkPoint=B.WorkPoint
INNER JOIN ICSInventoryLotDetail D ON D.LotNo=C.LotNo AND D.WorkPoint=C.WorkPoint
INNER JOIN ICSDeliveryNotice E ON E.DNCode=D.TransCode AND E.Sequence=D.TransSequence AND E.WorkPoint=D.WorkPoint
where A.ContainerCode='{0}'
UNION ALL
select DISTINCT E.ApplyNegCode AS TransNO,'生产退料' AS DocType,A.WorkPoint from ICSContainer A
INNER JOIN ICSContainerLot B ON B.ContainerID=A.ContainerID AND B.WorkPoint=A.WorkPoint
INNER JOIN ICSInventoryLot C ON C.LotNo=B.LotNo AND C.WorkPoint=B.WorkPoint
INNER JOIN ICSInventoryLotDetail D ON D.LotNo=C.LotNo AND D.WorkPoint=C.WorkPoint
INNER JOIN ICSMOApplyNegDetail E ON E.ApplyNegCode=D.TransCode AND E.Sequence=D.TransSequence AND E.WorkPoint=D.WorkPoint
where A.ContainerCode='{0}'";
docsql = string.Format(docsql, ContainerCode);
DataTable docdt = DBHelper.SQlReturnData(sql, cmd);
foreach (DataRow dr in docdt.Rows)
{
if (dr["DocType"].ToString() == "采购入库")
{
#region 检验合格单过账SAP(检验合格单为两层结构 一行对应一个序列号)
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, dr["TransNO"].ToString(), dr["WorkPoint"].ToString());
chkdt = DBHelper.SQlReturnData(chksql, cmd);
if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) != Convert.ToDecimal(chkdt.Rows[0]["RCVQuantity"]))
{
continue;
}
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, dr["TransNO"].ToString(), dr["WorkPoint"].ToString());
DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
if (Sapdt.Rows.Count == 0)
{
throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo205"), dr["TransNO"].ToString()));//单据查询失败
}
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")
{
string logsql = @"insert into ICSWMSCallSAPErrorLog
(ID,DocType,DocNO,WorkPoint,MTIME,WorkType,EATTRIBUTE1)
Select NEWID(),'{0}','{1}','{2}',GETDATE(),'叉车入库','{3}'";
logsql = string.Format(logsql, "采购入库", dr["TransNO"].ToString(), dr["WorkPoint"].ToString()
, result.L_MESSAGE);
DBHelper.ExecuteNonQuery(logsql, cmd);
}
#endregion
}
else
{
#region SAP(三层结构)
string ErrorMessage = "";
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, dr["TransNO"].ToString(), dr["WorkPoint"].ToString());
chkdt = DBHelper.SQlReturnData(chksql, cmd);
if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) == Convert.ToDecimal(chkdt.Rows[0]["IssueQuantity"]))
{
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 = dr["TransNO"].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 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, dr["TransNO"].ToString(), dr["WorkPoint"].ToString());
DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
foreach (DataRow drs in Sapdt.Rows)
{
if (Convert.ToDecimal(drs["Quantity"].ToString()) == Convert.ToDecimal(drs["IssueNegQuantity"].ToString()))
{
SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR();
Item.DANJU = drs["ApplyNegCode"].ToString();
Item.POSNR = drs["SAPSequence"].ToString();
Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(drs["Quantity"].ToString()), 3);
ItemList.Add(Item);
if (drs["BatchCode"].ToString() != "")
{
ItemLine.DANJU = drs["ApplyNegCode"].ToString();
ItemLine.POSNR = drs["SAPSequence"].ToString();
ItemLine.MATNR = drs["InvCode"].ToString();
ItemLine.GERNR = drs["BatchCode"].ToString();
ItemLineList.Add(ItemLine);
}
}
}
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)
{
ErrorMessage += resultItem.L_MESSAGE + "/r/n";
}
string logsql = @"insert into ICSWMSCallSAPErrorLog
(ID,DocType,DocNO,WorkPoint,MTIME,WorkType,EATTRIBUTE1)
Select NEWID(),'{0}','{1}','{2}',GETDATE(),'叉车入库','{3}'";
logsql = string.Format(logsql, "生产退料", dr["TransNO"].ToString(), dr["WorkPoint"].ToString()
, ErrorMessage);
DBHelper.ExecuteNonQuery(logsql, cmd);
}
}
}
#endregion
}
}
#endregion
#endregion
}
else if (TaskType == "PICK出库")
{
#region 出库(仅记录叉车搬运到的出库点位,用于后面的回库)
string sql = @" Update ICSForkLiftTaskLog SET EndLocation='{0}'
where ReqCode='{1}'";
sql = string.Format(sql, DestBin, TaskID);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
//throw new Exception("任务编码:" + TaskCode + ",日志记录失败");//料架状态更新失败
}
#endregion
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 料架单据绑定
///
///
///
///
///
///
///
public static void ContainerTransCodeBind(List tranCodes, string containerCode, string User, SqlCommand cmd, Dictionary language)
{
try
{
string sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' )
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
RETURN
END
IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCode='{0}' )
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo473"), "", "{0}") + @"',16,1);
RETURN
END;
SELECT top 1 Desks FROM ICSMOApply WHERE ApplyCode='{2}'
";
sql = string.Format(sql, containerCode, User, tranCodes.FirstOrDefault());
var table = DBHelper.SQlReturnData(sql, cmd);
if (table.Rows.Count <= 0)
{
throw new Exception("单据对应的工位不存在,操作失败");
}
foreach (string tranCode in tranCodes)
{
string sqlCheck = @"IF NOT EXISTS(select ID from ICSWareHouseLotInfoLog where TransType='15' AND TransCode='{0}')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo478") + @"',16,1);
RETURN
END;
IF NOT EXISTS( SELECT ID FROM ICSMOApply WHERE ApplyCode='{0}' AND Desks='{1}')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo477") + @"',16,1);
RETURN
END;
IF EXISTS(select ID from ICSContainerReceiptsNumber where ContainerCode='{2}' AND TransCode='{0}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo479"), "{0}", "{2}") + @"',16,1);
RETURN
END;
INSERT INTO ICSContainerReceiptsNumber SELECT NEWID(),'{0}','{2}',F_Account,F_RealName,GETDATE(),NULL,NULL,NULL,NULL,NULL FROM Sys_SRM_User WHERE F_Account='{3}' ";
sqlCheck = string.Format(sqlCheck, tranCode, table.Rows[0]["Desks"].ToString(), containerCode, User);
if (!DBHelper.ExecuteNonQuery(sqlCheck, cmd))
{
throw new Exception("单据新增失败");
}
}
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 根据条码获取仓库和区域信息
///
///
///
public static DataTable GetWHCodeArea(string LotNo, SqlCommand cmd)
{
try
{
string check = $@"SELECT C.WHCode,C.LocationCode FROM ICSInventoryLotDetail A
INNER JOIN ICSDeliveryNotice B ON B.DNCode=A.TransCode AND B.Sequence=A.TransSequence AND B.WorkPoint=A.WorkPoint
INNER JOIN ICSInventoryDetail C ON C.INVCode=B.InvCode AND C.WHCode=B.WHCode AND C.WorkPoint=B.WorkPoint
WHERE A.LotNo='{LotNo}'
UNION ALL
SELECT C.WHCode,C.LocationCode FROM ICSInventoryLotDetail A
INNER JOIN ICSMOApplyNegDetail B ON B.ApplyNegCode=A.TransCode AND B.Sequence=A.TransSequence AND B.WorkPoint=A.WorkPoint
INNER JOIN ICSInventoryDetail C ON C.INVCode=B.InvCode AND C.WHCode=B.WHCode AND C.WorkPoint=B.WorkPoint
WHERE A.LotNo='{LotNo}'";
var table = DBHelper.SQlReturnData(check, cmd);
return table;
}
catch (Exception ex)
{
throw ex;
}
}
}
}