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; namespace NFine.Application.WMS { public class BlitemApp : RepositoryFactory { public DataTable GetGridJson(string queryJson, ref Pagination jqgridparam) { DataTable dt = new DataTable(); var queryParam = queryJson.ToJObject(); List parameter = new List(); #region [SQL] string sql = @"select DISTINCT a.ID, a.CheckCode, a.MTIME, a.InvCode, b.InvName, b.InvStd , b.InvDesc, d.ContainerID, a.Quantity, a.ActualQuantity, a.MuserName, a.WHCode from ICSCheck a with (nolock) LEFT JOIN ICSCheckDetail c with (nolock) ON a.CheckCode=c.CheckCode AND a.WorkPoint=c.WorkPoint LEFT JOIN ICSContainerLot d with (nolock) ON c.LotNo=d.LotNo AND c.WorkPoint =d.WorkPoint left join ICSInventory b with (nolock) on a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint"; sql += " WHERE 1=1"; sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName()); #endregion if (!string.IsNullOrWhiteSpace(queryJson)) { if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString())) { sql += " and a.CheckCode like '%" + queryParam["POCode"].ToString() + "%' "; } } if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin") { sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'"; } if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor") { sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'"; } return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } public DataTable GetSubGridJson(string CheckCode, string Sequence, ref Pagination jqgridparam) { DataTable dt = new DataTable(); //var queryParam = queryJson.ToJObject(); List parameter = new List(); string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(','); string sql = @" SELECT distinct a.ID, b.InvCode, b.InvName , b.InvStd , a.LotNo, a.Quantity, a.ActualQuantity, d.WarehouseCode, d.LocationCode FROM ICSCheckDetail a left join ICSInventoryLot c on a.LotNo=c.LotNO left join ICSInventory b on c.InvCode=b.InvCode left join ICSWareHouseLotInfo d on c.LotNO=d.LotNO WHERE a.CheckCode='" + CheckCode + "' and a.WorkPoint in ('" + WorkPoint + "')"; return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } public string DeleteICSCheckDetail(string ID) { //站点信息 string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; string sql = string.Empty; try { sql = string.Format(@"DELETE FROM ICSCheckDetail WHERE ID ='{0}' and WorkPoint ='{1}'", ID, WorkPoint); SqlHelper.ExecuteNonQuery(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 获取仓库 /// /// public DataTable GetWHCode() { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string sql = @" select '' as WarehouseCode,'' as WarehouseName union all SELECT WarehouseCode,WarehouseName FROM ICSWarehouse WITH (NOLOCK) WHERE WorkPoint = '{0}' "; sql = string.Format(sql, WorkPoint); //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 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; } //接口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); } } public string DeleteICSCheck(string keyValue) { //站点信息 string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; try { sql += string.Format(@"DELETE FROM dbo.ICSCheck WHERE CheckCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint); sql += string.Format(@"DELETE FROM dbo.ICSCheckDetail WHERE CheckCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint); SqlHelper.ExecuteNonQuery(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } } }