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.
357 lines
15 KiB
357 lines
15 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 Newtonsoft.Json.Linq;
|
|
using System.Net;
|
|
using System.IO;
|
|
using NFine.Domain._03_Entity.WMS;
|
|
|
|
namespace NFine.Application.WMS
|
|
{
|
|
public class InspectionDeciliterApp : RepositoryFactory<ICSVendor>
|
|
{
|
|
/// <summary>
|
|
/// 获取分批条码
|
|
/// </summary>
|
|
public string GetNewLotNo(string LotNO)
|
|
{
|
|
DataTable dt = new DataTable();
|
|
|
|
List<DbParameter> parameter = new List<DbParameter>();
|
|
//string sql = @"select max(LotNo) as NewLotNo from ICSInventoryLot where EATTRIBUTE1='{0}' ";
|
|
string sql = @"SELECT TOP 1 LotNO as NewLotNo FROM ICSInventoryLot WHERE EATTRIBUTE1='{0}'
|
|
ORDER BY CAST(SUBSTRING(LotNO, (LEN(LotNO)-CHARINDEX('-',REVERSE(LotNO))+1)+1,CHARINDEX('-',REVERSE(LotNO))-1) AS INT) DESC";
|
|
sql = string.Format(sql, LotNO);
|
|
dt= Repository().FindTableBySql(sql.ToString());
|
|
if (dt==null||dt.Rows.Count==0|| dt.Rows[0]["NewLotNo"].ToString()=="")
|
|
{
|
|
return LotNO+"-1";
|
|
}
|
|
else
|
|
{
|
|
string newLotNO = dt.Rows[0]["NewLotNo"].ToString();
|
|
int COUNT = Convert.ToInt32(newLotNO.Substring(newLotNO.LastIndexOf('-') + 1)) + 1;
|
|
return LotNO + "-"+ COUNT.ToString();
|
|
}
|
|
}
|
|
|
|
public string Split(string Parameter)
|
|
{
|
|
|
|
string msg = "";
|
|
try
|
|
{
|
|
|
|
if (Parameter != null && !string.IsNullOrWhiteSpace(Parameter.ToString()) && Parameter.ToString() != "[]")
|
|
{
|
|
List<LOTCreateIModel> model = new List<LOTCreateIModel>();
|
|
model = JsonConvert.DeserializeObject<List<LOTCreateIModel>>(Parameter.ToString());
|
|
msg= LOTSplitCreate(model);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
msg = ex.Message;
|
|
}
|
|
return msg;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 拆分
|
|
/// </summary>
|
|
/// <param name="JsonData"></param>
|
|
/// <returns></returns>
|
|
public static string LOTSplitCreate(List<LOTCreateIModel> JsonData)
|
|
{
|
|
string newlotno = "";
|
|
string msg;
|
|
DataTable printTable = new DataTable();
|
|
if (JsonData.Count <= 0)
|
|
{
|
|
throw new Exception("");//"传送数据为空!"
|
|
}
|
|
try
|
|
{
|
|
string Identification = Guid.NewGuid().ToString();
|
|
foreach (var item in JsonData)
|
|
{
|
|
if (string.IsNullOrEmpty(item.LotNo))
|
|
{
|
|
msg = "条码不能为空";
|
|
throw new Exception("条码不能为空");//"条码不能为空!"
|
|
|
|
}
|
|
else if (item.detail.Count <= 0)
|
|
{
|
|
msg = "明细信息不能为空";
|
|
throw new Exception("明细信息不能为空");//"明细信息不能为空!");
|
|
|
|
}
|
|
//拆分前日志
|
|
WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "4", "71", "");
|
|
|
|
foreach (var info in item.detail)
|
|
{
|
|
newlotno = info.CurrentLotNo;
|
|
//更新条码信息
|
|
WareHouseLotInfoSplit(item.LotNo, info.CurrentLotNo, info.CurrentQuantity, item.User, item.WorkPoint);
|
|
}
|
|
|
|
//拆分后日志
|
|
printTable = WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "4","72",
|
|
newlotno);
|
|
}
|
|
return "";
|
|
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
throw new Exception(ex.Message);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
/// <summary>
|
|
/// 拆分、合并日志
|
|
/// </summary>
|
|
/// <param name="Identification"></param>
|
|
/// <param name="LotNo"></param>
|
|
/// <param name="User"></param>
|
|
/// <param name="WorkPoint"></param>
|
|
/// <param name="TransType"></param>
|
|
/// <param name="BusinessCode"></param>
|
|
/// <param name="cmd"></param>
|
|
public static DataTable WareHouseLotInfoLog(string Identification, string LotNo, string User, string WorkPoint, string TransType, string BusinessCode, string newLotno)
|
|
{
|
|
String LotEnable = "";
|
|
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 = SqlHelper.CmdExecuteDataTable(sql);
|
|
if (dt.Rows.Count == 0)
|
|
{
|
|
throw new Exception("条码不存在,操作失败");
|
|
}
|
|
else
|
|
{
|
|
LotEnable = dt.Rows[0]["LotEnable"].ToString();
|
|
}
|
|
///添加日志
|
|
sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
|
|
BEGIN
|
|
RAISERROR('用户不存在',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 ,
|
|
'','','','',a.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 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 (SqlHelper.ExecuteNonQuery(sql) < 0)
|
|
{
|
|
throw new Exception("日志表更新失败");
|
|
}
|
|
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
return lstDt;
|
|
}
|
|
/// <summary>
|
|
/// 拆分
|
|
/// </summary>
|
|
/// <param name="Identification"></param>
|
|
/// <param name="LotNo"></param>
|
|
/// <param name="User"></param>
|
|
/// <param name="WorkPoint"></param>
|
|
/// <param name="TransType"></param>
|
|
/// <param name="BusinessCode"></param>
|
|
/// <param name="cmd"></param>
|
|
public static void WareHouseLotInfoSplit( string LotNo, string CurrentLotNo, string Quantity, string User, string WorkPoint)
|
|
{
|
|
try
|
|
{
|
|
string sql = string.Empty;
|
|
#region 添加库存
|
|
//插入条码表
|
|
sql = @"
|
|
IF NOt EXISTS(SELECT a.LotNo FROM ICSInventoryLot a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
|
|
BEGIN
|
|
RAISERROR('原条码不存在,操作失败',16,1);
|
|
RETURN
|
|
END
|
|
IF EXISTS(SELECT a.LotNo FROM ICSContainerLot a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
|
|
BEGIN
|
|
INSERT INTO ICSContainerLot([ID], [ContainerID], [LotNo], [MUSER], [MUSERName], [WorkPoint], [MTIME], [EATTRIBUTE1], [EATTRIBUTE2], [EATTRIBUTE3], [EATTRIBUTE4], [EATTRIBUTE5], [EATTRIBUTE6], [EATTRIBUTE7], [EATTRIBUTE8], [EATTRIBUTE9], [EATTRIBUTE10])
|
|
SELECT NEWID(),ContainerID,'{4}' ,MUSER,MUSERName,WorkPoint ,MTIME,EATTRIBUTE1,EATTRIBUTE2, EATTRIBUTE3, EATTRIBUTE4, EATTRIBUTE5, EATTRIBUTE6, EATTRIBUTE7, EATTRIBUTE8, EATTRIBUTE9, EATTRIBUTE10
|
|
FROM ICSContainerLot WHERE LotNo='{4}' AND WorkPoint='{1}'
|
|
END
|
|
INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,Amount,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,EATTRIBUTE7)
|
|
SELECT NEWID(),'{4}' ,a.InvCode,a.ProductDate,a.ExpirationDate ,'{3}',a.Amount/a.Quantity*{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}';
|
|
UPDATE ICSInventoryLot SET Quantity=Quantity-{3} WHERE LotNo='{0}' AND WorkPoint='{1}';
|
|
IF EXISTS(SELECT a.LotNo FROM ICSASNDetail a WHERE a.LotNo='{0}' AND a.WorkPoint='{1}')
|
|
BEGIN
|
|
INSERT INTO [dbo].[ICSASNDetail] ([ID], [ASNCode], [Sequence], [LotNo], [Quantity], [Amount], [DNQuantity], [DNAmount], [MUSER], [MUSERName], [WorkPoint], [MTIME]) SELECT NEWID(),a.ASNCode,a.Sequence,'{4}',{3},a.Amount,{3},a.DNAmount,f.F_Account ,f.F_RealName,a.WorkPoint,GETDATE() FROM
|
|
ICSASNDetail 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}' ;
|
|
UPDATE ICSASNDetail SET Quantity=Quantity-{3} ,DNQuantity=DNQuantity-{3} WHERE LotNo='{0}' AND WorkPoint='{1}'
|
|
|
|
END";
|
|
sql = string.Format(sql, LotNo, WorkPoint, User, Quantity, CurrentLotNo);
|
|
|
|
if (SqlHelper.ExecuteNonQuery(sql) < 0)
|
|
{
|
|
throw new Exception("条码表写入失败!");//"条码表写入失败!");
|
|
}
|
|
//插入条码单据表
|
|
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 (SqlHelper.ExecuteNonQuery(sql) < 0)
|
|
{
|
|
throw new Exception("条码单据表写入失败!");//"条码单据表写入失败!");
|
|
}
|
|
#endregion
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
//接口api解析
|
|
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);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据ID获取条码
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public DataTable GetLotNoByID(string ID)
|
|
{
|
|
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
|
|
string sql = @"select '' as ID,'' as LotNo union all
|
|
SELECT ID,LotNo FROM ICSWareHouseLotInfo WITH (NOLOCK) WHERE ID in ({0}) ";
|
|
sql = string.Format(sql, ID.TrimEnd(','));
|
|
//string role = NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode;
|
|
//if (role != "admin")
|
|
//{
|
|
// sql += " and b.WorkPoint='" + WorkPoint + "'";
|
|
//}
|
|
DataTable dt = SqlHelper.GetDataTableBySql(sql);
|
|
return dt;
|
|
}
|
|
|
|
public class LOTCreateIModel
|
|
{
|
|
/// <summary>
|
|
/// 条码
|
|
/// </summary>
|
|
public string LotNo { get; set; }
|
|
/// <summary>
|
|
/// 操作人
|
|
/// </summary>
|
|
public string User { get; set; }
|
|
/// <summary>
|
|
/// 操作时间
|
|
/// </summary>
|
|
public DateTime MTime { get; set; }
|
|
|
|
/// <summary>
|
|
/// 站点
|
|
/// </summary>
|
|
public string WorkPoint { get; set; }
|
|
|
|
public List<LOTCreateIModelInfo> detail { get; set; }
|
|
}
|
|
public class LOTCreateIModelInfo
|
|
{
|
|
/// 合并条码
|
|
/// </summary>
|
|
public string CurrentLotNo { get; set; }
|
|
/// <summary>
|
|
/// 合并数量
|
|
/// </summary>
|
|
public string CurrentQuantity { get; set; }
|
|
/// <summary>
|
|
/// 站点
|
|
/// </summary>
|
|
public string WorkPoint { get; set; }
|
|
|
|
}
|
|
|
|
}
|
|
}
|