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.
 
 
 
 
 

156 lines
6.0 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 DeciliterApp : 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 = "";
string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "AMLOTSplit/Create";
string result = HttpPost(APIURL, Parameter);
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;
}
//接口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 string Combine(string LotNo, string ID)
{
string msg = "";
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
string sql = @" select distinct LotNo,Quantity from ICSWareHouseLotInfo WHERE ID IN (" + ID.TrimEnd(',') + ")";
DataTable dt = Repository().FindTableBySql(sql.ToString());
List<LotNoCombineHead> asn = new List<LotNoCombineHead>();
LotNoCombineHead ass = new LotNoCombineHead();
for (int i = 0; i < dt.Rows.Count; i++)
{
if (LotNo == dt.Rows[i]["LotNo"].ToString())
{
continue;
}
LotNoCombineBody DetailList = new LotNoCombineBody();
DetailList.CurrentLotNo= dt.Rows[i]["LotNo"].ToString();
DetailList.CurrentQuantity= dt.Rows[i]["Quantity"].ToString();
ass.detail.Add(DetailList);
}
ass.LotNo = LotNo;
ass.User = MUSER;
ass.WorkPoint = WorkPoint;
ass.MTIME= System.DateTime.Now.ToString("s");
asn.Add(ass);
string input = JsonConvert.SerializeObject(asn);
string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "LOTMerge/Create";
string result = HttpPost(APIURL, input);
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;
}
}
}