纽威
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.

361 lines
15 KiB

  1. using NFine.Data.Extensions;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using NFine.Code;
  9. using NFine.Repository;
  10. using System.Data.Common;
  11. using NFine.Domain._03_Entity.SRM;
  12. using ICS.Application.Entity;
  13. using Newtonsoft.Json;
  14. using System.Configuration;
  15. using System.Data.SqlClient;
  16. using ICS.Data;
  17. using Newtonsoft.Json.Linq;
  18. using NFine.Domain._03_Entity.WMS;
  19. using System.Net;
  20. using System.IO;
  21. namespace NFine.Application.WMS
  22. {
  23. public class ProductionRAFMRApp : RepositoryFactory<ICSVendor>
  24. {
  25. public static DataTable PRInvmes = new DataTable();
  26. /// <summary>
  27. /// 退料
  28. /// </summary>
  29. /// <param name="jqgridparam"></param>
  30. /// <returns></returns>
  31. public DataTable GetICSMOApplyNeg(ref Pagination jqgridparam)
  32. {
  33. DataTable dt = new DataTable();
  34. List<DbParameter> parameter = new List<DbParameter>();
  35. string sql = @" select a.ID,a.ApplyNegCode,a.WHCode,b.WarehouseName,a.Status,a.Type,a.Memo,a.CreatePerson,a.CreateDateTime,a.MUSER,a.MUSERName
  36. from ICSMOApplyNeg a
  37. left join ICSWarehouse b on a.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  38. where a.Type='2'";
  39. sql = string.Format(sql);
  40. DataTable dttest = Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  41. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  42. }
  43. public DataTable GetICSMOApplyNegDetail(string ApplyNegCode, ref Pagination jqgridparam)
  44. {
  45. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  46. DataTable dt = new DataTable();
  47. //var queryParam = queryJson.ToJObject();
  48. List<DbParameter> parameter = new List<DbParameter>();
  49. string sql = @"select ID,ApplyNegCode,Sequence,SourceDetailID,InvCode,Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,MUSERName,MTIME from ICSMOApplyNegDetail
  50. WHERE ApplyNegCode='" + ApplyNegCode + "' ";
  51. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  52. }
  53. public string DeleteICSMOApplyNeg(string keyValue)
  54. {
  55. //站点信息
  56. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  57. string msg = "";
  58. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  59. string sql = string.Empty;
  60. sql += string.Format(@"DELETE FROM dbo.ICSMOApplyNeg WHERE ApplyNegCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  61. sql += string.Format(@"DELETE FROM dbo.ICSMOApplyNegDetail WHERE ApplyNegCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  62. try
  63. {
  64. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  65. {
  66. }
  67. }
  68. catch (Exception ex)
  69. {
  70. throw new Exception(ex.Message);
  71. }
  72. return msg;
  73. }
  74. public DataTable GetICSReturnTemporary(string rfqno)
  75. {
  76. string sql = @"SELECT
  77. a.ApplyNegCode,
  78. a.InvCode,
  79. a.Quantity,
  80. a.Amount,
  81. a.SourceDetailID as ZJID,
  82. b.InvName,
  83. b.InvStd,
  84. b.InvUnit,
  85. a.IssueNegQuantity ,
  86. a.ExtensionID
  87. FROM
  88. ICSMOApplyNegDetail a
  89. LEFT JOIN ICSInventory b ON a.InvCode = b.InvCode and a.WorkPoint=b.WorkPoint where a.ApplyNegCode='" + rfqno + "'";
  90. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  91. DataTable dtCloned = table.Clone();
  92. foreach (DataColumn col in dtCloned.Columns)
  93. {
  94. col.DataType = typeof(string);
  95. }
  96. foreach (DataRow row in table.Rows)
  97. {
  98. DataRow newrow = dtCloned.NewRow();
  99. foreach (DataColumn column in dtCloned.Columns)
  100. {
  101. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  102. }
  103. dtCloned.Rows.Add(newrow);
  104. }
  105. if (PRInvmes.Rows.Count > 0)
  106. {
  107. dtCloned.Merge(PRInvmes, false);
  108. }
  109. return dtCloned;
  110. }
  111. public DataTable GetINV(string invcode, ref Pagination jqgridparam)
  112. {
  113. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  114. List<DbParameter> parameter = new List<DbParameter>();
  115. DataTable table = new DataTable();
  116. string wherestr = "";
  117. if (!string.IsNullOrEmpty(invcode))
  118. {
  119. wherestr += " and a.InvCode like '%" + invcode + "'%";
  120. }
  121. string sql = "SELECT DISTINCT a.ID as ZJID,a.ApplyCode,a.Sequence as MuHang,a.InvCode,a.Quantity,a.Amount,b.InvName,b.InvStd,b.InvUnit,a.IssueQuantity,a.ExtensionID FROM ICSMOApply a left JOIN ICSInventory b ON a.InvCode = b.InvCode and a.WorkPoint=b.WorkPoint where a.IssueQuantity>0 and a.WorkPoint = '" + WorkPoint + "'" + wherestr;
  122. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  123. }
  124. public void AddMOApplyNegTemp(string json)
  125. {
  126. var data = json.ToJObject();
  127. if (PRInvmes.Columns.Count <= 0)
  128. {
  129. PRInvmes.Columns.Add("ZJID", typeof(string));
  130. PRInvmes.Columns.Add("InvCode", typeof(string));
  131. PRInvmes.Columns.Add("INVNAME", typeof(string));
  132. PRInvmes.Columns.Add("InvStd", typeof(string));
  133. PRInvmes.Columns.Add("InvUnit", typeof(string));
  134. PRInvmes.Columns.Add("Quantity", typeof(string));
  135. PRInvmes.Columns.Add("IssueNegQuantity", typeof(string));
  136. PRInvmes.Columns.Add("ExtensionID", typeof(string));
  137. PRInvmes.Columns.Add("Amount", typeof(string));
  138. PRInvmes.Columns.Add("ID", typeof(string));
  139. }
  140. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  141. DataRow newrow = PRInvmes.NewRow();
  142. newrow["ZJID"] = data["ZJID"];
  143. newrow["InvName"] = data["InvName"];
  144. newrow["InvCode"] = data["InvCode"];
  145. newrow["InvStd"] = data["InvStd"];
  146. newrow["InvUnit"] = data["InvUnit"];
  147. newrow["Amount"] = data["Amount"];
  148. newrow["IssueNegQuantity"] = data["IssueNegQuantity"];
  149. newrow["ExtensionID"] = data["ExtensionID"];
  150. newrow["Quantity"] = "";
  151. newrow["ID"] = data["ID"];
  152. PRInvmes.Rows.Add(newrow);
  153. }
  154. public string SaveICSMOApplyNeg(string ICSASN)
  155. {
  156. string msg = "";
  157. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "MOIssueDocNegativeApply/Create";
  158. string result = HttpPost(APIURL, ICSASN);
  159. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  160. string MessAge = Obj["Message"].ToString();
  161. string Success = Obj["Success"].ToString();
  162. if (Success.ToUpper() == "FALSE")
  163. {
  164. msg = MessAge;
  165. }
  166. return msg;
  167. }
  168. public void ClearTemp()
  169. {
  170. PRInvmes.Rows.Clear();
  171. }
  172. public DataTable GetICSMOApplyNegDetailTemp(string ApplyNegCode)
  173. {
  174. string sql = @"SELECT
  175. a.ID,
  176. a.ID as TLZID,
  177. a.ApplyNegCode,
  178. a.InvCode,
  179. a.Quantity,
  180. a.Amount,
  181. a.SourceDetailID as ZJID,
  182. b.InvName,
  183. b.InvStd,
  184. b.InvUnit,
  185. a.IssueNegQuantity,
  186. a.ExtensionID
  187. FROM
  188. ICSMOApplyNegDetail a
  189. LEFT JOIN ICSInventory b ON a.InvCode = b.InvCode and a.WorkPoint=b.WorkPoint where a.ApplyNegCode='" + ApplyNegCode + "'";
  190. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  191. if (PRInvmes == null || PRInvmes.Columns.Count <= 0)
  192. PRInvmes = table.Clone();
  193. DataTable dtCloned = table.Clone();
  194. foreach (DataColumn col in dtCloned.Columns)
  195. {
  196. col.DataType = typeof(string);
  197. }
  198. foreach (DataRow row in table.Rows)
  199. {
  200. DataRow newrow = dtCloned.NewRow();
  201. foreach (DataColumn column in dtCloned.Columns)
  202. {
  203. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  204. }
  205. dtCloned.Rows.Add(newrow);
  206. }
  207. if (PRInvmes.Rows.Count > 0)
  208. {
  209. //dtCloned.Merge(Invmes, false);
  210. foreach (DataRow data in PRInvmes.Rows)
  211. {
  212. var info = dtCloned.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  213. if (info != null && info.Length > 0)
  214. {
  215. info[0]["ZJID"] = data["ZJID"];
  216. info[0]["InvName"] = data["InvName"];
  217. info[0]["InvCode"] = data["InvCode"];
  218. info[0]["InvStd"] = data["InvStd"];
  219. info[0]["InvUnit"] = data["InvUnit"];
  220. info[0]["Amount"] = data["Amount"];
  221. info[0]["IssueNegQuantity"] = data["IssueNegQuantity"];
  222. info[0]["ExtensionID"] = data["ExtensionID"];
  223. info[0]["Quantity"] = 0;
  224. }
  225. else
  226. {
  227. DataRow newrow = dtCloned.NewRow();
  228. newrow["ZJID"] = data["ZJID"];
  229. newrow["InvName"] = data["InvName"];
  230. newrow["InvCode"] = data["InvCode"];
  231. newrow["InvStd"] = data["InvStd"];
  232. newrow["InvUnit"] = data["InvUnit"];
  233. newrow["Amount"] = data["Amount"];
  234. newrow["Quantity"] = 0;
  235. newrow["ID"] = data["ID"];
  236. newrow["TLZID"] = data["TLZID"];
  237. newrow["IssueNegQuantity"] = data["IssueNegQuantity"];
  238. newrow["ExtensionID"] = data["ExtensionID"];
  239. dtCloned.Rows.Add(newrow);
  240. }
  241. }
  242. }
  243. return dtCloned;
  244. }
  245. public void UpdateMOApplyNegTemp(string json)
  246. {
  247. var data = json.ToJObject();
  248. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  249. var info = PRInvmes.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  250. if (info != null && info.Length > 0)
  251. {
  252. info[0]["ZJID"] = data["ZJID"];
  253. info[0]["InvName"] = data["InvName"];
  254. info[0]["InvCode"] = data["InvCode"];
  255. info[0]["InvStd"] = data["InvStd"];
  256. info[0]["InvUnit"] = data["InvUnit"];
  257. info[0]["Amount"] = data["Amount"];
  258. info[0]["IssueNegQuantity"] = data["IssueNegQuantity"];
  259. info[0]["ExtensionID"] = data["ExtensionID"];
  260. info[0]["Quantity"] = 0;
  261. }
  262. else
  263. {
  264. DataRow newrow = PRInvmes.NewRow();
  265. newrow["ZJID"] = data["ZJID"];
  266. newrow["InvName"] = data["InvName"];
  267. newrow["InvCode"] = data["InvCode"];
  268. newrow["InvStd"] = data["InvStd"];
  269. newrow["InvUnit"] = data["InvUnit"];
  270. newrow["Amount"] = data["Amount"];
  271. newrow["IssueNegQuantity"] = data["IssueNegQuantity"];
  272. newrow["ExtensionID"] = data["ExtensionID"];
  273. newrow["Quantity"] = 0;
  274. newrow["ID"] = data["ID"];
  275. newrow["TLZID"] = data["TLZID"];
  276. PRInvmes.Rows.Add(newrow);
  277. }
  278. }
  279. public string AuditICSMOApplyNeg(string ICSASN)
  280. {
  281. string msg = "";
  282. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "MOIssueDocNegativeApply/Approve";
  283. string result = HttpPost(APIURL, ICSASN);
  284. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  285. string MessAge = Obj["Message"].ToString();
  286. string Success = Obj["Success"].ToString();
  287. if (Success.ToUpper() == "FALSE")
  288. {
  289. msg = MessAge;
  290. }
  291. return msg;
  292. }
  293. public string UpdateICSMOApplyNeg(string ICSASN)
  294. {
  295. string msg = "";
  296. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "MOIssueDocNegativeApply/Update";
  297. string result = HttpPost(APIURL, ICSASN);
  298. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  299. string MessAge = Obj["Message"].ToString();
  300. string Success = Obj["Success"].ToString();
  301. if (Success.ToUpper() == "FALSE")
  302. {
  303. msg = MessAge;
  304. }
  305. return msg;
  306. }
  307. //接口api解析
  308. public static string HttpPost(string url, string body)
  309. {
  310. try
  311. {
  312. Encoding encoding = Encoding.UTF8;
  313. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  314. request.Method = "POST";
  315. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  316. request.ContentType = "application/json; charset=utf-8";
  317. byte[] buffer = encoding.GetBytes(body);
  318. request.ContentLength = buffer.Length;
  319. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  320. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  321. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  322. {
  323. return reader.ReadToEnd();
  324. }
  325. }
  326. catch (WebException ex)
  327. {
  328. throw new Exception(ex.Message);
  329. }
  330. }
  331. }
  332. }