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

120 lines
5.2 KiB

using NFine.Data.Extensions;
using System;
using System.Data;
using NFine.Code;
using NFine.Repository;
using NFine.Domain._03_Entity.SRM;
using System.Data.SqlClient;
using System.Text;
namespace NFine.Application.WMS
{
public class UpdateBinCodeApp : RepositoryFactory<ICSVendor>
{
public string SetData_PR(String savePath, string Year)
{
//数据获取
try
{
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
SqlConnection conn = SqlHelper.GetDataCenterConn();
DataTable data = FileToExcel.ExcelToTable(savePath);
string sql1 = "";
if (data != null && data.Rows.Count > 0)
{
foreach (DataRow dr in data.Rows)
{
string lotno = dr["物料条码"].ToString().ToUpper();
string binCode = dr["库位"].ToString().ToUpper();
//查询条码是否存在,并且获取条码初始仓库
string sql = $@"SELECT WarehouseCode, LocationCode,LotNo FROM ICSWareHouseLotInfo WHERE LotNo='{lotno}' AND WorkPoint='{WorkPoint}' ";
DataTable dataset = Repository().FindDataSetBySql(sql).Tables[0];
if (dataset.Rows.Count == 0)
{
return "条码" + lotno + "不存在";
}
else
{
//查询修改的库位
string binSql = $@"SELECT WarehouseCode,LocationCode FROM ICSLocation a
LEFT JOIN ICSWarehouse b ON a.WHID=b.ID AND a.WorkPoint=b.WorkPoint
WHERE a.LocationCode='{binCode}' AND a.WorkPoint='{WorkPoint}' ";
DataTable binDt = Repository().FindDataSetBySql(binSql).Tables[0];
if (binDt.Rows.Count == 0)
{
return "库位" + binCode + "不存在";
}
else
{
string newWHCode = binDt.Rows[0]["WarehouseCode"].ToString().ToUpper();
if (newWHCode != dataset.Rows[0]["WarehouseCode"].ToString().ToUpper())
{
return "条码" + lotno + "原仓库" + dataset.Rows[0]["WarehouseCode"].ToString().ToUpper() + "和修改后仓库" + newWHCode + "不一致";
}
else
{
///添加日志
sql1 += @"
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}'
";
///修改库位
sql1 += @" UPDATE ICSWareHouseLotInfo SET WarehouseCode='{8}',LocationCode='{9}' WHERE LotNo='{0}' AND WorkPoint='{1}' ";
sql1 = string.Format(sql1, lotno, WorkPoint, MUSER, Guid.NewGuid().ToString(), "", "", "7", "29", newWHCode, binCode);
}
}
}
}
if (!string.IsNullOrWhiteSpace(sql1))
{
StringBuilder sqlb = new StringBuilder(sql1);
Repository().ExecuteBySql(sqlb);
}
}
else
{
return "无有效的导入数据。";
}
return "true";
}
catch (Exception ex)
{
return ex.Message;
}
}
public string GetNewid()
{
string sql = "select newid() AS ID";
return Repository().FindTableBySql(sql, null).Rows[0]["ID"].ToString();
}
}
}