纽威
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

627 lines
34 KiB

using NFine.Data.Extensions;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NFine.Code;
using NFine.Repository;
using System.Data.Common;
using NFine.Domain._03_Entity.SRM;
using ICS.Application.Entity;
using Newtonsoft.Json;
using System.Configuration;
using System.Data.SqlClient;
using ICS.Data;
using System.Net;
using System.IO;
using Newtonsoft.Json.Linq;
using NFine.Domain._03_Entity.WMS;
namespace NFine.Application.WMS
{
public class ICSToSAPApp : RepositoryFactory<ICSVendor>
{
//销售出库过账SAP
public string DisPatchToSAP(string DisPatchCodeList, string WorkPoint)
{
string msg = "";
try
{
string DocNOList = "";
foreach (string DocNO in DisPatchCodeList.TrimEnd(',').Split(','))
{
DocNOList += "'" + DocNO + "',";
}
#region SAP(三层结构)
string IsSuccess = "";
SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ Client = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ();
SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ1 Info = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZ1();
List<SAPCallBackDispatchVPN.ZWMS_DO_HEAD> headlist = new List<SAPCallBackDispatchVPN.ZWMS_DO_HEAD>();
SAPCallBackDispatchVPN.ZWMS_DO_HEAD head = new SAPCallBackDispatchVPN.ZWMS_DO_HEAD();
string sql = @"select DISTINCT SDNCode from ICSSDN where SDNCode IN ({0}) AND WorkPoint='{1}'";
sql = string.Format(sql, DocNOList.TrimEnd(','), WorkPoint);
DataTable Sapdt = SqlHelper.GetDataTableBySql(sql);
foreach (DataRow dr in Sapdt.Rows)
{
head.VBELN = dr["SDNCode"].ToString();
headlist.Add(head);
}
Info.T_HEAD = headlist.ToArray();
List<SAPCallBackDispatchVPN.ZWMS_DO_ITEM> ItemList = new List<SAPCallBackDispatchVPN.ZWMS_DO_ITEM>();
List<SAPCallBackDispatchVPN.ZWMS_DO_GERNR> ItemLineList = new List<SAPCallBackDispatchVPN.ZWMS_DO_GERNR>();
Info.T_RETURN = new SAPCallBackDispatchVPN.ZWMS_DO_RETURN[1];
sql = @" select A.SDNCode,A.InvCode,A.SAPSequence,A.Sequence,A.Quantity,A.SDNQuantity
,ISNULL(B.BatchCode,'') AS BatchCode from ICSSDN A
LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
WHERE SDNCode IN ({0}) AND A.WorkPoint='{1}'";
sql = string.Format(sql, DocNOList.TrimEnd(','), WorkPoint);
Sapdt = SqlHelper.GetDataTableBySql(sql);
foreach (DataRow dr in Sapdt.Rows)
{
if (Convert.ToDecimal(dr["Quantity"].ToString()) == Convert.ToDecimal(dr["SDNQuantity"].ToString()))
{
SAPCallBackDispatchVPN.ZWMS_DO_GERNR ItemLine = new SAPCallBackDispatchVPN.ZWMS_DO_GERNR();
SAPCallBackDispatchVPN.ZWMS_DO_ITEM Item = new SAPCallBackDispatchVPN.ZWMS_DO_ITEM();
Item.VBELN = dr["SDNCode"].ToString();
Item.POSNR = dr["SAPSequence"].ToString();
Item.LFIMG = System.Decimal.Round(Convert.ToDecimal(dr["Quantity"].ToString()), 3);
ItemList.Add(Item);
if (dr["BatchCode"].ToString() != "")
{
ItemLine.VBELN = dr["SDNCode"].ToString();
ItemLine.POSNR = dr["SAPSequence"].ToString();
ItemLine.GERNR = dr["BatchCode"].ToString();
ItemLineList.Add(ItemLine);
}
else
{
string lotsql = @"select A.LOTNO,ISNULL(C.BatchCode,'') AS BatchCode from ICSWareHouseLotInfoLog A
INNER JOIN ICSInventoryLot B ON B.LotNo=A.LotNo AND B.WorkPoint=A.WorkPoint
INNER JOIN ICSExtension C ON C.ID=B.ExtensionID AND C.WorkPoint=B.WorkPoint
where BusinessCode='19' AND TransCode='{0}' and TransSequence='{1}'
and A.WorkPoint='{2}'";
lotsql = string.Format(lotsql, dr["SDNCode"].ToString(), dr["Sequence"].ToString(), WorkPoint);
DataTable lotdt = SqlHelper.GetDataTableBySql(lotsql);
foreach (DataRow lotdr in lotdt.Rows)
{
if (lotdr["BatchCode"].ToString() != "")
{
ItemLine = new SAPCallBackDispatchVPN.ZWMS_DO_GERNR();
ItemLine.VBELN = dr["SDNCode"].ToString();
ItemLine.POSNR = dr["SAPSequence"].ToString();
ItemLine.GERNR = lotdr["BatchCode"].ToString();
ItemLineList.Add(ItemLine);
}
}
}
}
}
if (ItemList.Count > 0)
{
Info.T_ITEM = ItemList.ToArray();
if (ItemLineList.Count > 0)
{
Info.T_GERNR = ItemLineList.ToArray();
}
SAPCallBackDispatchVPN.ZWMS_SK_DO_GZResponse result = new SAPCallBackDispatchVPN.ZWMS_SK_DO_GZResponse();
result = Client.CallZWMS_SK_DO_GZ(Info);
foreach (SAPCallBackDispatchVPN.ZWMS_DO_RETURN resultItem in result.T_RETURN)
{
if (resultItem.ZFLG == "N")
{
IsSuccess = "N";
msg += resultItem.ZMESS + "/r/n";
}
}
if (msg == "")
{
string updatesql = @"Update ICSSDN set EATTRIBUTE1='已过账' where SDNCode in ({0}) AND WorkPoint='{1}'";
updatesql = string.Format(updatesql, DocNOList.TrimEnd(','), WorkPoint);
if (SqlHelper.CmdExecuteNonQueryLi(updatesql) > 0)
{
msg = "";
}
else
{
msg = "待过账状态回写失败!";
}
}
}
#endregion
return msg;
}
catch (Exception ex)
{
msg = ex.Message;
return msg;
}
}
public string ICSTransferToSAP(string TransferCode, string ToLocationCode, string WorkPoint)
{
string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
string ToWareHouseCode = "";
string msg = "";
try
{
#region 验证传入库位是否属于调入仓库
string stacksql = @"select ToWarehouseCode from ICSTransfer
where TransferNO='{0}' and WorkPoint='{1}'
select B.WarehouseCode from ICSLocation A
LEFT JOIN ICSWarehouse B ON B.ID=A.WHID AND B.WorkPoint=A.WorkPoint
WHERE A.LocationCode='{2}' AND A.WorkPoint='{1}'";
stacksql = string.Format(stacksql, TransferCode, WorkPoint, ToLocationCode);
DataTable docdt = Repository().FindDataSetBySql(stacksql).Tables[0];
DataTable stackdt = Repository().FindDataSetBySql(stacksql).Tables[1];
if (stackdt.Rows.Count == 0)
{
throw new Exception("输入目标库位:" + ToLocationCode + "不存在!");
}
foreach (DataRow dr in docdt.Rows)
{
if (dr["ToWarehouseCode"].ToString() != stackdt.Rows[0]["WarehouseCode"].ToString())
{
throw new Exception("目标库位:" + ToLocationCode + "不属于调入仓库:" + dr["ToWarehouseCode"].ToString() + ",无法调拨!");
}
}
ToWareHouseCode = stackdt.Rows[0]["WarehouseCode"].ToString();
#endregion
string dataString = $@"select a.Memo,a.FromWarehouseCode,a.Quantity,a.TransferQuantity,a.InvCode,a.TransferNO,a.SAPSequence,a.Sequence FROM ICSTransfer a
WHERE a.TransferNO = ('" + TransferCode + @"') AND a.WorkPoint = '" + WorkPoint + @"'
AND ISNULL(a.Quantity, 0)>ISNULL(a.TransferQuantity, 0)
AND a.Memo is not null AND a.Memo!='' ";
var datasetModel = Repository().FindDataSetBySql(dataString);
DataTable table1 = null;
DataTable table = null;
StringBuilder updateString = new StringBuilder();
StringBuilder checklot = new StringBuilder();
string sqlString = String.Empty;
List<LotMessage> lotMessages = new List<LotMessage>();
if (datasetModel.Tables[0].Rows.Count != 0)
{
DataTable tableModel = datasetModel.Tables[0];
if (tableModel.Rows.Count > 0)
{
//循环验证条码信息是否与单据信息相符
for (int i = 0; i < tableModel.Rows.Count; i++)
{
LotMessage lotMessage = new LotMessage();
string transCode = tableModel.Rows[i]["TransferNO"].ToString();
string lotNo = tableModel.Rows[i]["Memo"].ToString();
string whCode = tableModel.Rows[i]["FromWarehouseCode"].ToString();
string sequence = tableModel.Rows[i]["Sequence"].ToString();
lotMessage.LotNo = lotNo;
lotMessage.Quantity = Convert.ToDecimal(tableModel.Rows[i]["Quantity"].ToString());
lotMessages.Add(lotMessage);
//验证信息
checklot.Append($@"IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo='{lotNo}' AND a.WorkPoint='{WorkPoint}')
BEGIN
RAISERROR('条码{lotNo},不存在',16,1);
RETURN
END;
IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{tableModel.Rows[i]["Memo"]}' AND a.WorkPoint='{WorkPoint}' AND a.WarehouseCode='{whCode}')
BEGIN
RAISERROR('{lotNo}{transCode}{tableModel.Rows[i]["SAPSequence"]}',16,1);
RETURN
END;
IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{lotNo}' AND a.WorkPoint='{WorkPoint}' AND a.WarehouseCode='{whCode}' AND a.Quantity>=A.LockQuantity+'{tableModel.Rows[i]["Quantity"]}')
BEGIN
RAISERROR('{lotNo}',16,1);
RETURN
END;
IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo='{lotNo}' AND a.WorkPoint='{WorkPoint}' AND InvCode='{tableModel.Rows[i]["InvCode"]}')
BEGIN
RAISERROR('{lotNo}{transCode}{tableModel.Rows[i]["SAPSequence"]}',16,1);
RETURN
END;"
);
updateString.Append($@" INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
MTIME,WorkPoint,EATTRIBUTE1)
SELECT NEWID(),NEWID(),'{transCode}','{sequence}',a.LotNo ,a.InvCode ,
a.WarehouseCode,a.LocationCode,'','','{tableModel.Rows[i]["Quantity"]}',
'','1','15','47','0','',
'','','','{MUSER}' ,'{MUSERNAME}' ,
GETDATE() ,'{WorkPoint}' ,''
FROM ICSWareHouseLotInfo a
WHERE a.LotNo='{tableModel.Rows[i]["Memo"]}' AND a.WorkPoint='{WorkPoint}'
update ICSWareHouseLotInfo set LockQuantity=LockQuantity+'{tableModel.Rows[i]["Quantity"]}' where LotNo='{lotNo}' AND WorkPoint='{WorkPoint}';");
}
SqlHelper.CmdExecuteNonQueryLi(checklot.ToString());
sqlString = $@"SELECT
a.TransferNO AS Code,a.Sequence,a.InvCode,b.InvName,b.InvStd,b.InvUnit,
(SUM(ISNULL(a.Quantity, 0))-SUM(ISNULL(a.TransferQuantity, 0))) AS iQuantity,--应发数量
a.FromWarehouseCode As WarehouseCode,
a.Memo AS LotNO,
ISNULL(c.Quantity, 0) AS QTY,--条码库存
ISNULL(c.Quantity, 0) AS QTYLeft,
a.Quantity as SendQTY, --占料数量
c.LocationCode,
CONVERT(varchar(100),c.MTIME, 23) MTIME,
SUM(c.Quantity-c.LockQuantity) AS QTYTotal,
a.ExtensionID
from ICSTransfer a
Left JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
LEFT JOIN ICSWareHouseLotInfo c ON c.LotNo=a.Memo AND a.FromWarehouseCode=c.WarehouseCode
WHERE a.TransferNO = '{TransferCode}' AND a.Memo is NOT NULL and a.Memo!=''
GROUP BY a.TransferNO,a.Sequence,a.InvCode,b.InvName,b.InvStd,b.InvUnit,
a.Quantity,a.FromWarehouseCode ,a.Memo,c.LocationCode,c.MTIME,c.Quantity,a.ExtensionID,c.LockQuantity; ";
}
}
string sql = $@"SELECT row_number() over ( order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
c.Code,
c.Sequence,
c.InvCode,
c.InvName,
c.InvStd,
c.InvUnit,
c.iQuantity AS iQuantity,
c.WHCode AS WarehouseCode,
d.LotNO,
ISNULL(d.Quantity, 0) AS QTY,
ISNULL(d.Quantity, 0) AS QTYLeft,
CONVERT(decimal(18,6),0) AS SendQTY,
d.LocationCode AS LocationCode,
CONVERT(varchar(100),d.MTIME, 23) MTIME,
f.QTYTotal QTYTotal,c.ExtensionID
FROM
(select
a.TransferNO as Code,
a.Sequence,
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
(SUM(ISNULL(a.Quantity, 0))-SUM(ISNULL(a.TransferQuantity, 0))) AS iQuantity,
a.FromWarehouseCode as WhCode,
a.ExtensionID
FROM
ICSTransfer a
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE a.TransferNO = '{TransferCode}' AND a.WorkPoint = '{WorkPoint}' AND ISNULL(a.Quantity, 0)>ISNULL(a.TransferQuantity, 0)
and (a.Memo is null or a.Memo='' )
GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID,a.Sequence) c
left join (select d.WarehouseCode,d.Quantity-d.LockQuantity as Quantity,d.INVCode, m.LotNo, d.MTIME,d.LocationCode,m.ExtensionID
from ICSWareHouseLotInfo d ,ICSInventoryLot m
where d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
and d.WorkPoint='{WorkPoint}' AND d.Quantity-d.LockQuantity>0 AND d.Quantity>0
--AND SUBSTRING( SUBSTRING(d.LocationCode, CHARINDEX('-',d.LocationCode)+1, LEN(d.LocationCode)),0,CHARINDEX('-', SUBSTRING(d.LocationCode, CHARINDEX('-',d.LocationCode)+1, LEN(d.LocationCode)))) Not IN(SELECT F_Define2 FROM Sys_SRM_ItemsDetail
--WHERE F_Define3='HGAreaConfig' AND F_Define1=d.WarehouseCode AND F_Define4=d.WorkPoint)
) d
on c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode and d.ExtensionID=c.ExtensionID
LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity-LockQuantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{WorkPoint}' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
order by c.Code,Convert(int,c.Sequence),d.MTIME,d.LotNO ";
var dataset = Repository().FindDataSetBySql(sql);
if (dataset.Tables[0].Rows.Count != 0)
{
table = dataset.Tables[0];
decimal qtyCount = 0;
bool remove = false;
List<int> removeList = new List<int>();
for (int i = 0; i < table.Rows.Count; i++)
{
if (lotMessages != null && lotMessages.Count > 0)
{
//排除指定条码的锁定库存数量
List<LotMessage> models = lotMessages.Where(e => e.LotNo == table.Rows[i]["LotNO"].ToString()).ToList();
if (models != null && models.Count > 0)
{
decimal quantity = models.Select(e => e.Quantity).ToList().Sum();
table.Rows[i]["QTYLeft"] = table.Rows[i]["QTYLeft"].ToString().ToDecimal() - quantity;
}
}
if (i != 0
&& (!table.Rows[i]["InvCode"].ToString().Equals(table.Rows[i - 1]["InvCode"].ToString())
|| !table.Rows[i]["Sequence"].ToString().Equals(table.Rows[i - 1]["Sequence"].ToString())
|| !table.Rows[i]["Code"].ToString().Equals(table.Rows[i - 1]["Code"].ToString())
|| !table.Rows[i]["ExtensionID"].ToString().Equals(table.Rows[i - 1]["ExtensionID"].ToString()))
)
{
qtyCount = 0;
remove = false;
}
if (table.Rows[i]["QTYLeft"].ToString().ToDecimal() == 0)
{
removeList.Add(i);
continue;
}
if (remove)
{
removeList.Add(i);
}
else
{
var lotQty = table.Rows[i]["QTYLeft"].ToString().ToDecimal();
var orderQty = table.Rows[i]["iQuantity"].ToString().ToDecimal();
qtyCount += lotQty;
foreach (DataRow dr in table.Rows)
{
if (dr["LotNO"].ToString() == table.Rows[i]["LotNO"].ToString())
{
if (qtyCount > orderQty)
{
dr["QTYLeft"] = Convert.ToDecimal(qtyCount) - Convert.ToDecimal(orderQty);
}
else
{
dr["QTYLeft"] = 0;
}
}
}
if (qtyCount >= orderQty)
{
table.Rows[i]["SendQTY"] = Convert.ToDecimal(lotQty) - (Convert.ToDecimal(qtyCount) - Convert.ToDecimal(orderQty));
remove = true;
}
else
{
table.Rows[i]["SendQTY"] = lotQty;
}
}
}
if (removeList.Count > 0)
{
removeList.Reverse();
foreach (var item in removeList)
{
table.Rows.RemoveAt(item);
}
}
try
{
#region 如果条码数量超出实际需要领料数量,直接报错
string chksql = "";
#region 物料调拨
chksql = @" select InvCode,FromWarehouseCode AS WHCode,(SUM(ISNULL(Quantity, 0))-SUM(ISNULL(TransferQuantity, 0))) as Quantity from ICSTransfer
where TransferNO = '{0}' and WorkPoint='{1}' and (Memo is NULL or Memo='')
GROUP BY InvCode,FromWarehouseCode";
#endregion
chksql = string.Format(chksql, TransferCode, WorkPoint);
var chkdata = Repository().FindDataSetBySql(chksql);
DataTable chktable = chkdata.Tables[0];
foreach (DataRow chkdr in chktable.Rows)
{
decimal ZLQty = 0;
for (int i = 0; i < table.Rows.Count; i++)
{
if (table.Rows[i]["WarehouseCode"].ToString() == chkdr["WHCode"].ToString()
&& table.Rows[i]["InvCode"].ToString() == chkdr["InvCode"].ToString())
{
ZLQty += Convert.ToDecimal(table.Rows[i]["SendQTY"].ToString());
}
}
if (Convert.ToDecimal(chkdr["Quantity"]) < ZLQty)
{
throw new Exception("物料:" + chkdr["InvCode"].ToString() + "实际拣料数量大于单据需求数量,请尝试重新拣料。");
}
if (Convert.ToDecimal(chkdr["Quantity"]) > ZLQty)
{
throw new Exception("物料:" + chkdr["InvCode"].ToString() + "实际拣料数量小于单据需求数量,货柜单据必须整单拣料,请先核对库存。");
}
}
#endregion
#region 验证单据是否已经占料,如已占料则跳过占料步骤
string zlchksql = @"select TransCode from ICSWareHouseLotInfoLog
where TransCode='{0}' and WorkPoint='{1}' and TransType=15";
zlchksql = string.Format(zlchksql, TransferCode, WorkPoint);
var zlchkdata = Repository().FindDataSetBySql(zlchksql);
DataTable zlchktable = zlchkdata.Tables[0];
#endregion
if (table.Rows.Count != 0 && zlchktable.Rows.Count==0)
{
#region 拣料时增加条码出入库记录,修改库存锁定数量,以作占料处理
int Count = 1;
string BusinessCode = "10";
string TransType = "调拨申请单";
string Identification = Guid.NewGuid().ToString();
var pikTbLogTime = DateTime.Now;
string pikTbLogsql = string.Empty;
List<string> DocNoList = new List<string>();
foreach (DataRow PickLog in table.Rows)
{
pikTbLogsql += @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{9}' AND a.WorkPoint='{8}' AND a.Quantity>=A.LockQuantity+'{3}')
BEGIN
RAISERROR('条码{9}的库存可分配数量小于单据数量', 16, 1);
RETURN
END;
IF NOT EXISTS(SELECT TransCode FROM ICSWareHouseLotInfoLog WHERE TransCode='{1}' AND TransSequence='{2}' AND LotNo='{9}' AND WorkPoint='{8}' AND TransType='15')
BEGIN
INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
MTIME,WorkPoint,EATTRIBUTE1)
SELECT NEWID(),'{0}','{1}','{2}',a.LotNo ,a.InvCode ,
a.WarehouseCode,a.LocationCode,'','','{3}',
'','1','15','{4}','0','',
'','','','{5}' ,'{6}' ,
'{7}' ,'{8}' ,''
FROM ICSWareHouseLotInfo a
WHERE a.LotNo='{9}' AND a.WorkPoint='{8}'
update ICSWareHouseLotInfo set LockQuantity=LockQuantity+'{3}' where LotNo='{9}' AND WorkPoint='{8}'
END
UPDATE ICSTransfer SET MUSER='{6}' WHERE TransferNO='{1}' and Sequence='{2}' ; ";
pikTbLogsql = string.Format(pikTbLogsql, Identification, PickLog["Code"].ToString(), PickLog["Sequence"].ToString(), PickLog["SendQTY"].ToString()
, BusinessCode, MUSER, MUSERNAME, pikTbLogTime, WorkPoint, PickLog["LotNO"].ToString());
}
SqlHelper.CmdExecuteNonQueryLi(pikTbLogsql + updateString.ToString());
#endregion
}
//查询有条码的拣料信息
if (!String.IsNullOrEmpty(sqlString))
{
var dataSet1 = Repository().FindDataSetBySql(sqlString);
if (dataSet1.Tables[0].Rows.Count != 0)
{
table1 = dataSet1.Tables[0];
}
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
else
{
if (!String.IsNullOrEmpty(updateString.ToString()))
{
SqlHelper.CmdExecuteNonQueryLi(updateString.ToString());
}
//查询有条码的拣料信息
if (!String.IsNullOrEmpty(sqlString))
{
var dataSet1 = Repository().FindDataSetBySql(sqlString);
if (dataSet1.Tables[0].Rows.Count != 0)
{
table1 = dataSet1.Tables[0];
}
}
}
if (table1 != null && table != null)
{
table.Merge(table1);
}
else if (table == null && table1 != null)
{
table = table1;
}
else if (table1 == null && table == null)
{
msg = "过账失败,无法获取到拣料数据!";
}
string DocNo = "";
string DocLine = "";
List<TransferDoc> ListInfo = new List<TransferDoc>();
TransferDoc Info = new TransferDoc();
List<TransferDetailDoc> DetailList = new List<TransferDetailDoc>();
TransferDetailDoc Detail = new TransferDetailDoc();
foreach (DataRow dr in table.Rows)
{
if (DocNo == "")
{
Info = new TransferDoc();
DocNo = dr["Code"].ToString();
DocLine = dr["Sequence"].ToString();
Info.TransCode = dr["Code"].ToString();
Info.TransSequence = dr["Sequence"].ToString();
Info.WorkPoint = WorkPoint;
Info.User = MUSER;
Info.TransType = "1";
DetailList = new List<TransferDetailDoc>();
Detail = new TransferDetailDoc();
Detail.LocationCode = ToLocationCode;
Detail.WarehouseCode = ToWareHouseCode;
Detail.LotNo = dr["LotNO"].ToString();
Detail.CurrentQuantity = dr["SendQTY"].ToString();
DetailList.Add(Detail);
}
else
{
if (DocNo == dr["Code"].ToString() && DocLine == dr["Sequence"].ToString())
{
Detail = new TransferDetailDoc();
Detail.LocationCode = ToLocationCode;
Detail.WarehouseCode = ToWareHouseCode;
Detail.LotNo = dr["LotNO"].ToString();
Detail.CurrentQuantity = dr["SendQTY"].ToString();
DetailList.Add(Detail);
}
else
{
Info.Detail = DetailList;
ListInfo.Add(Info);
Info = new TransferDoc();
DocNo = dr["Code"].ToString();
DocLine = dr["Sequence"].ToString();
Info.TransCode = dr["Code"].ToString();
Info.TransSequence = dr["Sequence"].ToString();
Info.WorkPoint = WorkPoint;
Info.User = MUSER;
Info.TransType = "1";
DetailList = new List<TransferDetailDoc>();
Detail = new TransferDetailDoc();
Detail.LocationCode = ToLocationCode;
Detail.WarehouseCode = ToWareHouseCode;
Detail.LotNo = dr["LotNO"].ToString();
Detail.CurrentQuantity = dr["SendQTY"].ToString();
DetailList.Add(Detail);
}
}
}
Info.Detail = DetailList;
ListInfo.Add(Info);
string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "AutoTransferIn/Update";
string transferjson = JsonConvert.SerializeObject(ListInfo);
string result = HttpPost(APIURL, transferjson);
JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
string MessAge = Obj["Message"].ToString();
string Success = Obj["Success"].ToString();
if (Success.ToUpper() == "FALSE")
{
msg = MessAge;
}
return msg;
}
catch (Exception ex)
{
msg = ex.Message;
return msg;
}
}
public static string HttpPost(string url, string body)
{
try
{
Encoding encoding = Encoding.UTF8;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
request.ContentType = "application/json; charset=utf-8";
byte[] buffer = encoding.GetBytes(body);
request.ContentLength = buffer.Length;
request.GetRequestStream().Write(buffer, 0, buffer.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
{
return reader.ReadToEnd();
}
}
catch (WebException ex)
{
throw new Exception(ex.Message);
}
}
public class LotMessage
{
public string LotNo { get; set; }
public decimal Quantity { get; set; }
}
}
}