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.

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