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

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