爱思开
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.

381 lines
16 KiB

2 years ago
  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 a.ID,a.ApplyNegCode,a.Sequence,a.SourceDetailID,a.InvCode,a.Quantity,a.Amount,a.IssueNegQuantity,a.ExtensionID
  50. ,a.MUSER,a.MUSERName,a.MTIME
  51. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  52. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  53. from ICSMOApplyNegDetail a
  54. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  55. WHERE a.ApplyNegCode='" + ApplyNegCode + "' ";
  56. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  57. }
  58. public string DeleteICSMOApplyNeg(string keyValue)
  59. {
  60. //站点信息
  61. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  62. string msg = "";
  63. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  64. string sql = string.Empty;
  65. sql += string.Format(@"DELETE FROM dbo.ICSMOApplyNeg WHERE ApplyNegCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  66. sql += string.Format(@"DELETE FROM dbo.ICSMOApplyNegDetail WHERE ApplyNegCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  67. try
  68. {
  69. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  70. {
  71. }
  72. }
  73. catch (Exception ex)
  74. {
  75. throw new Exception(ex.Message);
  76. }
  77. return msg;
  78. }
  79. public DataTable GetICSReturnTemporary(string rfqno)
  80. {
  81. string sql = @"SELECT
  82. a.ApplyNegCode,
  83. a.InvCode,
  84. a.Quantity,
  85. a.Amount,
  86. a.SourceDetailID as ZJID,
  87. b.InvName,
  88. b.InvStd,
  89. b.InvUnit,
  90. a.IssueNegQuantity ,
  91. a.ExtensionID
  92. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  93. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  94. FROM
  95. ICSMOApplyNegDetail a
  96. LEFT JOIN ICSInventory b ON a.InvCode = b.InvCode and a.WorkPoint=b.WorkPoint
  97. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  98. where a.ApplyNegCode='" + rfqno + "'";
  99. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  100. DataTable dtCloned = table.Clone();
  101. foreach (DataColumn col in dtCloned.Columns)
  102. {
  103. col.DataType = typeof(string);
  104. }
  105. foreach (DataRow row in table.Rows)
  106. {
  107. DataRow newrow = dtCloned.NewRow();
  108. foreach (DataColumn column in dtCloned.Columns)
  109. {
  110. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  111. }
  112. dtCloned.Rows.Add(newrow);
  113. }
  114. if (PRInvmes.Rows.Count > 0)
  115. {
  116. dtCloned.Merge(PRInvmes, false);
  117. }
  118. return dtCloned;
  119. }
  120. public DataTable GetINV(string invcode, ref Pagination jqgridparam)
  121. {
  122. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  123. List<DbParameter> parameter = new List<DbParameter>();
  124. DataTable table = new DataTable();
  125. string wherestr = "";
  126. if (!string.IsNullOrEmpty(invcode))
  127. {
  128. wherestr += " and a.InvCode like '%" + invcode + "%'";
  129. }
  130. string sql = @"SELECT DISTINCT a.ApplyDetailID as ZJID,a.ApplyCode,a.Sequence as MuHang,a.InvCode,a.Quantity,a.Amount,b.InvName,b.InvStd,b.InvUnit
  131. ,a.IssueQuantity,a.ExtensionID
  132. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  133. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  134. FROM ICSMOApply a
  135. left JOIN ICSInventory b ON a.InvCode = b.InvCode and a.WorkPoint=b.WorkPoint
  136. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  137. where a.IssueQuantity>0 and a.WorkPoint = '" + WorkPoint + "'" + wherestr;
  138. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  139. }
  140. public void AddMOApplyNegTemp(string json)
  141. {
  142. var data = json.ToJObject();
  143. if (PRInvmes.Columns.Count <= 0)
  144. {
  145. PRInvmes.Columns.Add("ZJID", typeof(string));
  146. PRInvmes.Columns.Add("InvCode", typeof(string));
  147. PRInvmes.Columns.Add("INVNAME", typeof(string));
  148. PRInvmes.Columns.Add("InvStd", typeof(string));
  149. PRInvmes.Columns.Add("InvUnit", typeof(string));
  150. PRInvmes.Columns.Add("Quantity", typeof(string));
  151. PRInvmes.Columns.Add("IssueNegQuantity", typeof(string));
  152. PRInvmes.Columns.Add("ExtensionID", typeof(string));
  153. PRInvmes.Columns.Add("Amount", typeof(string));
  154. PRInvmes.Columns.Add("ID", typeof(string));
  155. }
  156. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  157. DataRow newrow = PRInvmes.NewRow();
  158. newrow["ZJID"] = data["ZJID"];
  159. newrow["InvName"] = data["InvName"];
  160. newrow["InvCode"] = data["InvCode"];
  161. newrow["InvStd"] = data["InvStd"];
  162. newrow["InvUnit"] = data["InvUnit"];
  163. newrow["Amount"] = data["Amount"];
  164. newrow["IssueNegQuantity"] = data["IssueNegQuantity"];
  165. newrow["ExtensionID"] = data["ExtensionID"];
  166. newrow["Quantity"] = "";
  167. newrow["ID"] = data["ID"];
  168. PRInvmes.Rows.Add(newrow);
  169. }
  170. public string SaveICSMOApplyNeg(string ICSASN)
  171. {
  172. string msg = "";
  173. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "MOIssueDocNegativeApply/Create";
  174. string result = HttpPost(APIURL, ICSASN);
  175. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  176. string MessAge = Obj["Message"].ToString();
  177. string Success = Obj["Success"].ToString();
  178. if (Success.ToUpper() == "FALSE")
  179. {
  180. msg = MessAge;
  181. }
  182. return msg;
  183. }
  184. public void ClearTemp()
  185. {
  186. PRInvmes.Rows.Clear();
  187. }
  188. public DataTable GetICSMOApplyNegDetailTemp(string ApplyNegCode)
  189. {
  190. string sql = @"SELECT
  191. a.ID,
  192. a.ID as TLZID,
  193. a.ApplyNegCode,
  194. a.InvCode,
  195. a.Quantity,
  196. a.Amount,
  197. a.SourceDetailID as ZJID,
  198. b.InvName,
  199. b.InvStd,
  200. b.InvUnit,
  201. a.IssueNegQuantity,
  202. a.ExtensionID
  203. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  204. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  205. FROM
  206. ICSMOApplyNegDetail a
  207. LEFT JOIN ICSInventory b ON a.InvCode = b.InvCode and a.WorkPoint=b.WorkPoint
  208. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  209. where a.ApplyNegCode='" + ApplyNegCode + "'";
  210. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  211. if (PRInvmes == null || PRInvmes.Columns.Count <= 0)
  212. PRInvmes = table.Clone();
  213. DataTable dtCloned = table.Clone();
  214. foreach (DataColumn col in dtCloned.Columns)
  215. {
  216. col.DataType = typeof(string);
  217. }
  218. foreach (DataRow row in table.Rows)
  219. {
  220. DataRow newrow = dtCloned.NewRow();
  221. foreach (DataColumn column in dtCloned.Columns)
  222. {
  223. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  224. }
  225. dtCloned.Rows.Add(newrow);
  226. }
  227. if (PRInvmes.Rows.Count > 0)
  228. {
  229. //dtCloned.Merge(Invmes, false);
  230. foreach (DataRow data in PRInvmes.Rows)
  231. {
  232. var info = dtCloned.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  233. if (info != null && info.Length > 0)
  234. {
  235. info[0]["ZJID"] = data["ZJID"];
  236. info[0]["InvName"] = data["InvName"];
  237. info[0]["InvCode"] = data["InvCode"];
  238. info[0]["InvStd"] = data["InvStd"];
  239. info[0]["InvUnit"] = data["InvUnit"];
  240. info[0]["Amount"] = data["Amount"];
  241. info[0]["IssueNegQuantity"] = data["IssueNegQuantity"];
  242. info[0]["ExtensionID"] = data["ExtensionID"];
  243. info[0]["Quantity"] = 0;
  244. }
  245. else
  246. {
  247. DataRow newrow = dtCloned.NewRow();
  248. newrow["ZJID"] = data["ZJID"];
  249. newrow["InvName"] = data["InvName"];
  250. newrow["InvCode"] = data["InvCode"];
  251. newrow["InvStd"] = data["InvStd"];
  252. newrow["InvUnit"] = data["InvUnit"];
  253. newrow["Amount"] = data["Amount"];
  254. newrow["Quantity"] = 0;
  255. newrow["ID"] = data["ID"];
  256. newrow["TLZID"] = data["TLZID"];
  257. newrow["IssueNegQuantity"] = data["IssueNegQuantity"];
  258. newrow["ExtensionID"] = data["ExtensionID"];
  259. dtCloned.Rows.Add(newrow);
  260. }
  261. }
  262. }
  263. return dtCloned;
  264. }
  265. public void UpdateMOApplyNegTemp(string json)
  266. {
  267. var data = json.ToJObject();
  268. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  269. var info = PRInvmes.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  270. if (info != null && info.Length > 0)
  271. {
  272. info[0]["ZJID"] = data["ZJID"];
  273. info[0]["InvName"] = data["InvName"];
  274. info[0]["InvCode"] = data["InvCode"];
  275. info[0]["InvStd"] = data["InvStd"];
  276. info[0]["InvUnit"] = data["InvUnit"];
  277. info[0]["Amount"] = data["Amount"];
  278. info[0]["IssueNegQuantity"] = data["IssueNegQuantity"];
  279. info[0]["ExtensionID"] = data["ExtensionID"];
  280. info[0]["Quantity"] = 0;
  281. }
  282. else
  283. {
  284. DataRow newrow = PRInvmes.NewRow();
  285. newrow["ZJID"] = data["ZJID"];
  286. newrow["InvName"] = data["InvName"];
  287. newrow["InvCode"] = data["InvCode"];
  288. newrow["InvStd"] = data["InvStd"];
  289. newrow["InvUnit"] = data["InvUnit"];
  290. newrow["Amount"] = data["Amount"];
  291. newrow["IssueNegQuantity"] = data["IssueNegQuantity"];
  292. newrow["ExtensionID"] = data["ExtensionID"];
  293. newrow["Quantity"] = 0;
  294. newrow["ID"] = data["ID"];
  295. newrow["TLZID"] = data["TLZID"];
  296. PRInvmes.Rows.Add(newrow);
  297. }
  298. }
  299. public string AuditICSMOApplyNeg(string ICSASN)
  300. {
  301. string msg = "";
  302. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "MOIssueDocNegativeApply/Approve";
  303. string result = HttpPost(APIURL, ICSASN);
  304. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  305. string MessAge = Obj["Message"].ToString();
  306. string Success = Obj["Success"].ToString();
  307. if (Success.ToUpper() == "FALSE")
  308. {
  309. msg = MessAge;
  310. }
  311. return msg;
  312. }
  313. public string UpdateICSMOApplyNeg(string ICSASN)
  314. {
  315. string msg = "";
  316. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "MOIssueDocNegativeApply/Update";
  317. string result = HttpPost(APIURL, ICSASN);
  318. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  319. string MessAge = Obj["Message"].ToString();
  320. string Success = Obj["Success"].ToString();
  321. if (Success.ToUpper() == "FALSE")
  322. {
  323. msg = MessAge;
  324. }
  325. return msg;
  326. }
  327. //接口api解析
  328. public static string HttpPost(string url, string body)
  329. {
  330. try
  331. {
  332. Encoding encoding = Encoding.UTF8;
  333. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  334. request.Method = "POST";
  335. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  336. request.ContentType = "application/json; charset=utf-8";
  337. byte[] buffer = encoding.GetBytes(body);
  338. request.ContentLength = buffer.Length;
  339. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  340. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  341. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  342. {
  343. return reader.ReadToEnd();
  344. }
  345. }
  346. catch (WebException ex)
  347. {
  348. throw new Exception(ex.Message);
  349. }
  350. }
  351. }
  352. }