using Newtonsoft.Json.Linq; using Newtonsoft.Json; using NFine.Code; using NFine.Data.Extensions; using NFine.Domain._03_Entity.SRM; using NFine.Repository; using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data.Common; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; namespace NFine.Application.WMS { public class ICSOutsourcingReceiveApp : RepositoryFactory { public static DataTable Invmes = new DataTable(); /// /// 红字采购入库 删除 /// /// /// /// public string DeleteICSOutsourcingReceiveApplyNeg(string keyValue) { //站点信息 string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string msg = ""; keyValue = keyValue.Substring(1, keyValue.Length - 2); string sql = string.Empty; sql += string.Format(@"DELETE FROM dbo.ICSOutsourcingReceive WHERE RCVCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint); //sql += string.Format(@"DELETE FROM dbo.ICSMOApplyNegDetail WHERE ApplyNegCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint); try { if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0) { } } catch (Exception ex) { throw new Exception(ex.Message); } return msg; } /// /// 红字采购入库 查询 /// /// /// public DataTable GetOutsourcingReceiveApplyNeg(ref Pagination jqgridparam) { DataTable dt = new DataTable(); List parameter = new List(); string sql = @"select a.RCVCode from ICSOutsourcingReceive a group by a.RCVCode"; sql = string.Format(sql); DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } /// /// 红字采购入库 明细查询 /// /// /// public DataTable GetOutsourcingReceiveApplyNegDetail(string ApplyNegCode, ref Pagination jqgridparam) { DataTable dt = new DataTable(); object Figure = GetDecimalDigits(); List parameter = new List(); string wherestr = ""; if (!string.IsNullOrEmpty(ApplyNegCode)) { wherestr += " and a.RCVCode = '" + ApplyNegCode + "' "; } string sql = @"SELECT a.ID,a.RCVCode,a.Sequence,a.InvCode,a.Quantity,a.RCVQuantity,a.Amount,a.Type,a.SourceCode,a.SourceSequence ,a.WHCode,e.WarehouseName as WHName,a.Status,a.CreatePerson,a.CreateDateTime ,a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10 ,a.EATTRIBUTE,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10 from ICSOutsourcingReceive a left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint left join ICSWarehouse e on a.WHCode = e.WarehouseCode and a.WorkPoint=e.WorkPoint where 1 = 1 " + wherestr; sql = string.Format(sql, Figure); DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam); } public object GetDecimalDigits() { string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(','); try { string sql = string.Empty; sql = @"select Figure from ICSConfiguration where Code='Figure001' and Enable='1' and WorkPoint='" + WorkPoint + "'"; object Figure = SqlHelper.ExecuteScalar(sql); return Figure; } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } } public void ClearTemp() { Invmes.Rows.Clear(); } /// /// 新增 /// /// /// public string SaveICSOutsourcingReceiveApplyNeg(string ICSASN) { string msg = ""; string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "OutsourcingReceive/Create"; string result = HttpPost(APIURL, ICSASN); 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 UpdateICSOutsourcingReceiveApplyNeg(string ICSASN) { string msg = ""; string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "OutsourcingReceive/Update"; string result = HttpPost(APIURL, ICSASN); 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 GetCode(string WorkPoint) { WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string OOCode = string.Empty; if (!string.IsNullOrEmpty(WorkPoint)) { OOCode = GetSerialCode(WorkPoint, "ICSOutsourcingReceive", "RCVCode", "OR", 8); } if (!string.IsNullOrWhiteSpace(OOCode)) { string sqlISHave = @"SELECT RCVCode FROM ICSOutsourcingReceive a WHERE a.RCVCode = '{0}'"; sqlISHave = string.Format(sqlISHave, OOCode); DataTable dtIsHave = SqlHelper.GetDataTableBySql(sqlISHave); if (dtIsHave.Rows.Count > 0) { throw new Exception("单号已存在!"); } } return OOCode; } public string GetSerialCode(string workPointCode, string tbName, string colName, string Pre, int numLen) { string sql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}"; sql = string.Format(sql, new object[] { workPointCode, tbName, colName, Pre, numLen }); return SqlHelper.ExecuteScalar(sql).ToString(); } public void UpdateOutsourcingReceiveOrderApplyNegTemp(string json) { var data = json.ToJObject(); string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; var info = Invmes.Select(string.Format("TLZID='{0}'", data["TLZID"])); if (info != null && info.Length > 0) { info[0]["ZJID"] = data["ZJID"]; info[0]["InvName"] = data["InvName"]; } else { DataRow newrow = Invmes.NewRow(); newrow["ZJID"] = data["ZJID"]; Invmes.Rows.Add(newrow); } } public DataTable GetICSOutsourcingReceiveReturnTemporary(string RCVCode) { string sql = @"SELECT a.ID,a.RCVCode,a.Sequence,a.InvCode,a.Quantity,a.RCVQuantity,a.Amount,a.Type,a.SourceCode as OOCode,a.SourceSequence as OOSequence ,a.WHCode,e.WarehouseName as WHName,a.Status,a.CreatePerson,a.CreateDateTime,b.InvName ,a.ExtensionID,a.MUSER,a.MUSERName,a.MTIME,a.WorkPoint,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10 ,a.EATTRIBUTE,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8, a.EATTRIBUTE9,a.EATTRIBUTE10 from ICSOutsourcingReceive a left join ICSInventory b on a.InvCode = b.InvCode and a.WorkPoint = b.WorkPoint left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint left join ICSWarehouse e on a.WHCode = e.WarehouseCode and a.WorkPoint=e.WorkPoint where a.RCVCode ='" + RCVCode + "' "; DataTable table = Repository().FindDataSetBySql(sql).Tables[0]; DataTable dtCloned = table.Clone(); foreach (DataColumn col in dtCloned.Columns) { col.DataType = typeof(string); } foreach (DataRow row in table.Rows) { DataRow newrow = dtCloned.NewRow(); foreach (DataColumn column in dtCloned.Columns) { newrow[column.ColumnName] = row[column.ColumnName].ToString(); } dtCloned.Rows.Add(newrow); } if (Invmes.Rows.Count > 0) { dtCloned.Merge(Invmes, false); } return dtCloned; } /// /// 接口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); } } } }