diff --git a/WMS-BS/NFine.Application/WMS/BlitemApp.cs b/WMS-BS/NFine.Application/WMS/BlitemApp.cs index bc2418f..0439c2e 100644 --- a/WMS-BS/NFine.Application/WMS/BlitemApp.cs +++ b/WMS-BS/NFine.Application/WMS/BlitemApp.cs @@ -12,6 +12,8 @@ using System.Configuration; using System.Net; using System.IO; using Newtonsoft.Json.Linq; +using System.Data.SqlClient; +using ICS.Data; namespace NFine.Application.WMS { @@ -187,20 +189,140 @@ SELECT Grid as GeValue,Grid +'格' as GeName FROM ICSLocation WITH (NOLOCK) WHE return dt; } + //public string AddICSCheck(string Parameter) + //{ + // string msg = ""; + // string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "Check/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; + //} + + /// + /// 新增盘点单接口 + /// + /// + /// public string AddICSCheck(string Parameter) { string msg = ""; - string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "Check/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") + try { - msg = MessAge; + List model = JsonConvert.DeserializeObject>(Parameter.ToString()); + if (model == null || model.Count<=0) + { + msg = "操作失败"; + return msg; + } + + string sql = string.Empty; + foreach (var item in model) + { + if (string.IsNullOrEmpty(item.User)) + { + throw new Exception("操作人不能为空!");//"操作人不能为空!"); + + } + if (string.IsNullOrEmpty(item.WorkPoint)) + { + throw new Exception("站点不能为空");//"站点不能为空!" + } + + //创建盘点单 + foreach (var itemInfo in item.Detail) + { + string Code = string.Empty; + //获取单号 + sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{0}' AND F_Location='{1}') + BEGIN + RAISERROR('操作人不存在',16,1); + RETURN + END + + DECLARE @MaxNO INT,@date varchar(20)='CHK'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8) + SELECT @MaxNO=SUBSTRING(MAX(CheckCode),LEN(@date)+1,LEN(MAX(CheckCode))-LEN(@date))+1 FROM ICSCheck + WHERE SUBSTRING(CheckCode, 1, LEN(@date))=@date + IF @MaxNO IS NULL + BEGIN + SELECT @date+'00001' AS Code + END + ELSE + BEGIN + SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code + END "; + sql = string.Format(sql, item.User, item.WorkPoint); + Code = SqlHelper.ExecuteScalar(sql).ToString(); + if (string.IsNullOrWhiteSpace(Code)) + { + throw new Exception("盘点单号不能为空");//"盘点单单号不能为空!"); + } + int len = itemInfo.SelectLevel.Length; + sql = @"IF NOT EXISTS(SELECT id FROM ICSWareHouseLotInfo WHERE SUBSTRING(LocationCode,1,{4}) = '{1}') + BEGIN + RAISERROR('维护库位在库存中没有记录!',16,1); + RETURN + END + INSERT INTO ICSCheck (ID,CheckCode,SelectLevel,Status,Quantity,Amount,MUSER,MUSERName,MTIME,WorkPoint) + SELECT NEWID(),'{0}','{1}','2',SUM(a.Quantity),0,b.F_Account,b.F_RealName,GETDATE(),b.F_Location + FROM ICSWareHouseLotInfo a + INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}' + WHERE SUBSTRING(a.LocationCode,1,{4}) = '{1}' + GROUP BY b.F_Account,b.F_RealName,b.F_Location"; + sql = string.Format(sql, Code, itemInfo.SelectLevel, item.User, item.WorkPoint, len); + + if (SqlHelper.ExecuteNonQuery(sql)<=0) + { + throw new Exception("盘点单创建失败");//"盘点单创建失败!"); + } + } + } + } + catch (Exception ex) + { + msg = ex.Message; } return msg; } + /// + /// + /// + public class ICSCheck + { + /// + /// 用户 + /// + public string User { get; set; } + /// + /// 操作时间 + /// + public string MTIME { get; set; } + /// + /// + /// 站点 + /// + public string WorkPoint { get; set; } + /// + /// 详情 + /// + public List Detail { get; set; } + } + /// + /// + /// + public class Detail + { + /// + /// 仓库编码 + /// + public string SelectLevel { get; set; } + } + //接口api解析