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

497 lines
20 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 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 ProductionIssueApp : RepositoryFactory<ICSVendor>
  24. {
  25. public static DataTable Invmes = new DataTable();
  26. // public static DataTable Supplier = new DataTable();
  27. /// <summary>
  28. /// 退料
  29. /// </summary>
  30. /// <param name="jqgridparam"></param>
  31. /// <returns></returns>
  32. public DataTable GetICSMOApplyNeg(ref Pagination jqgridparam)
  33. {
  34. DataTable dt = new DataTable();
  35. List<DbParameter> parameter = new List<DbParameter>();
  36. 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
  37. from ICSMOApplyNeg a
  38. left join ICSMOApplyNegDetail c ON a.ApplyNegCode=c.ApplyNegCode
  39. left join ICSWarehouse b on c.WHCode=b.WarehouseCode and a.WorkPoint=b.WorkPoint
  40. where a.Type='1' ";
  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. //子表查询
  46. public DataTable GetICSMOApplyNegDetail(string ApplyNegCode, ref Pagination jqgridparam)
  47. {
  48. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  49. DataTable dt = new DataTable();
  50. //var queryParam = queryJson.ToJObject();
  51. List<DbParameter> parameter = new List<DbParameter>();
  52. string sql = @"select a.ID,a.ApplyNegCode,a.Sequence,a.SourceDetailID,a.InvCode,a.Quantity,a.Amount,a.IssueNegQuantity,a.ExtensionID,a.MUSER
  53. ,a.MUSERName,a.MTIME
  54. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  55. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  56. from ICSMOApplyNegDetail a
  57. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  58. WHERE a.ApplyNegCode='" + ApplyNegCode + "' ";
  59. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  60. }
  61. public DataTable GetINV(string invcode, ref Pagination jqgridparam)
  62. {
  63. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  64. List<DbParameter> parameter = new List<DbParameter>();
  65. DataTable table = new DataTable();
  66. string wherestr = "";
  67. if (!string.IsNullOrEmpty(invcode))
  68. {
  69. wherestr += " and a.InvCode like '%" + invcode + "%'";
  70. }
  71. string sql = @"SELECT DISTINCT a.PickID as ZJID,c.MOCode,c.Sequence as MuHang,a.InvCode,a.Quantity,a.Amount,b.InvName,b.InvStd,b.InvUnit
  72. ,a.IssueQuantity,a.ExtensionID
  73. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  74. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  75. FROM ICSMOPick a
  76. left JOIN ICSInventory b ON a.InvCode = b.InvCode and a.WorkPoint=b.WorkPoint
  77. left join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  78. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  79. where a.IssueQuantity>0 and a.WorkPoint = '" + WorkPoint + "'" + wherestr;
  80. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  81. }
  82. public DataTable GetICSMOPickLog(string invcode, ref Pagination jqgridparam)
  83. {
  84. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  85. List<DbParameter> parameter = new List<DbParameter>();
  86. DataTable table = new DataTable();
  87. //string wherestr = "";
  88. //if (!string.IsNullOrEmpty(invcode))
  89. //{
  90. // wherestr += " and a.InvCode like '%" + invcode + "'%";
  91. //}
  92. string sql = @" select distinct a.WHCode,b.MOCode,b.Sequence,a.Sequence as ZJHH,c.BatchCode,a.Quantity,a.Amount,a.ID,a.InvCode
  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 ICSMOPick a
  96. left join ICSMO b on b.ID=a.MODetailID and b.WorkPoint=a.WorkPoint
  97. left join ICSExtension f on a.ExtensionID=f.ID
  98. where a.InvCode='{0}' and a.WorkPoint='{1}'
  99. ";
  100. sql = string.Format(sql, invcode, WorkPoint);
  101. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  102. }
  103. /// <summary>
  104. /// 获取仓库列表
  105. /// </summary>
  106. /// <returns></returns>
  107. public DataTable GetWHCode()
  108. {
  109. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  110. string sql = @"
  111. select '' as WarehouseCode,'' as WarehouseName
  112. union all
  113. select WarehouseCode,WarehouseName from ICSWarehouse where Enable='1' and WorkPoint='{0}'
  114. ";
  115. //string role = NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode;
  116. //if (role != "admin")
  117. //{
  118. // sql += " and b.WorkPoint=" + WorkPoint.TrimEnd(',') + "";
  119. //}
  120. sql = string.Format(sql, WorkPoint);
  121. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  122. return dt;
  123. }
  124. public DataTable GetICSReturnTemporary(string rfqno)
  125. {
  126. string sql = @"SELECT
  127. a.ApplyNegCode,
  128. a.InvCode,
  129. a.Quantity,
  130. a.Amount,
  131. a.SourceDetailID as ZJID,
  132. b.InvName,
  133. b.InvStd,
  134. b.InvUnit
  135. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  136. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  137. FROM
  138. ICSMOApplyNegDetail a
  139. LEFT JOIN ICSInventory b ON a.InvCode = b.InvCode
  140. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  141. where a.ApplyNegCode='" + rfqno + "'";
  142. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  143. DataTable dtCloned = table.Clone();
  144. foreach (DataColumn col in dtCloned.Columns)
  145. {
  146. col.DataType = typeof(string);
  147. }
  148. foreach (DataRow row in table.Rows)
  149. {
  150. DataRow newrow = dtCloned.NewRow();
  151. foreach (DataColumn column in dtCloned.Columns)
  152. {
  153. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  154. }
  155. dtCloned.Rows.Add(newrow);
  156. }
  157. if (Invmes.Rows.Count > 0)
  158. {
  159. dtCloned.Merge(Invmes, false);
  160. }
  161. return dtCloned;
  162. }
  163. public string GetNewid()
  164. {
  165. string sql = "select newid() AS ID";
  166. return Repository().FindTableBySql(sql, null).Rows[0]["ID"].ToString();
  167. }
  168. public void AddMOApplyNegTemp(string json)
  169. {
  170. var data = json.ToJObject();
  171. if (Invmes.Columns.Count <= 0)
  172. {
  173. Invmes.Columns.Add("ZJID", typeof(string));
  174. Invmes.Columns.Add("InvCode", typeof(string));
  175. Invmes.Columns.Add("INVNAME", typeof(string));
  176. Invmes.Columns.Add("InvStd", typeof(string));
  177. Invmes.Columns.Add("InvUnit", typeof(string));
  178. Invmes.Columns.Add("Quantity", typeof(string));
  179. Invmes.Columns.Add("IssueQuantity", typeof(string));
  180. Invmes.Columns.Add("ExtensionID", typeof(string));
  181. Invmes.Columns.Add("Amount", typeof(string));
  182. Invmes.Columns.Add("ID", typeof(string));
  183. }
  184. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  185. DataRow newrow = Invmes.NewRow();
  186. newrow["ZJID"] = data["ZJID"];
  187. newrow["InvName"] = data["InvName"];
  188. newrow["InvCode"] = data["InvCode"];
  189. newrow["InvStd"] = data["InvStd"];
  190. newrow["InvUnit"] = data["InvUnit"];
  191. newrow["Amount"] = data["Amount"];
  192. newrow["IssueQuantity"] = data["IssueQuantity"];
  193. newrow["ExtensionID"] = data["ExtensionID"];
  194. newrow["Quantity"] = "";
  195. newrow["ID"] = data["ID"];
  196. Invmes.Rows.Add(newrow);
  197. }
  198. public string DeleteMopick(string json)
  199. {
  200. try
  201. {
  202. string wheresql = "(";
  203. string[] id = json.Split(',');
  204. for (int i = 0; i < id.Length; i++)
  205. {
  206. wheresql += "'" + id[i].Replace(']', ' ').Replace('[', ' ').Replace('"', ' ').Trim() + "',";
  207. }
  208. wheresql = wheresql.Trim(',') + ")";
  209. string sql = "delete from ICSMOApplyNeg where id in" + wheresql;
  210. int count = DbHelper.ExecuteNonQuery(CommandType.Text, sql);
  211. DataRow[] row = Invmes.Select("ID in " + wheresql + "");
  212. foreach (DataRow a in row)
  213. {
  214. Invmes.Rows.Remove(a);
  215. }
  216. return "删除成功!";
  217. }
  218. catch (Exception ex)
  219. {
  220. return ex.Message + " 删除失败!";
  221. }
  222. }
  223. public void ClearTemp()
  224. {
  225. Invmes.Rows.Clear();
  226. }
  227. public string SaveICSMOApplyNeg(string ICSASN)
  228. {
  229. string msg = "";
  230. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "MOIssueDocNegativeApply/Create";
  231. string result = HttpPost(APIURL, ICSASN);
  232. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  233. string MessAge = Obj["Message"].ToString();
  234. string Success = Obj["Success"].ToString();
  235. if (Success.ToUpper() == "FALSE")
  236. {
  237. msg = MessAge;
  238. }
  239. return msg;
  240. }
  241. public string UpdateICSMOApplyNeg(string ICSASN)
  242. {
  243. string msg = "";
  244. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "MOIssueDocNegativeApply/Update";
  245. string result = HttpPost(APIURL, ICSASN);
  246. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  247. string MessAge = Obj["Message"].ToString();
  248. string Success = Obj["Success"].ToString();
  249. if (Success.ToUpper() == "FALSE")
  250. {
  251. msg = MessAge;
  252. }
  253. return msg;
  254. }
  255. //接口api解析
  256. public static string HttpPost(string url, string body)
  257. {
  258. try
  259. {
  260. Encoding encoding = Encoding.UTF8;
  261. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  262. request.Method = "POST";
  263. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  264. request.ContentType = "application/json; charset=utf-8";
  265. byte[] buffer = encoding.GetBytes(body);
  266. request.ContentLength = buffer.Length;
  267. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  268. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  269. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  270. {
  271. return reader.ReadToEnd();
  272. }
  273. }
  274. catch (WebException ex)
  275. {
  276. throw new Exception(ex.Message);
  277. }
  278. }
  279. /// <summary>
  280. /// 获取料品属性修改文本框值
  281. /// </summary>
  282. /// <param name="POCode"></param>
  283. /// <param name="PORow"></param>
  284. /// <returns></returns>
  285. public DataTable GetInputValue(string ID)
  286. {
  287. try
  288. {
  289. DataTable dt = new DataTable();
  290. //var queryParam = queryJson.ToJObject();
  291. List<DbParameter> parameter = new List<DbParameter>();
  292. string sql = @"select InvCode,InvName,InvDesc,InvStd,InvUnit,AmountUnit, ClassCode,ClassName,InvRate,InvVersion,InvBrand,InvIQC,
  293. InvFQC,EffectiveEnable,EffectiveDays,BatchEnable,LotEnable,PrintEnable,WHUser
  294. from ICSInventory
  295. WHERE 1=1 AND ID='{0}' ";
  296. sql = string.Format(sql, ID);
  297. return Repository().FindTableBySql(sql.ToString());
  298. }
  299. catch (Exception ex)
  300. {
  301. throw new Exception(ex.Message.ToString());
  302. }
  303. }
  304. public DataTable GetICSMOApplyNegDetailTemp(string ApplyNegCode)
  305. {
  306. string sql = @"SELECT
  307. a.ID,
  308. a.ID as TLZID,
  309. a.ApplyNegCode,
  310. a.InvCode,
  311. a.Quantity,
  312. a.Amount,
  313. a.SourceDetailID as ZJID,
  314. b.InvName,
  315. b.InvStd,
  316. b.InvUnit,
  317. a.IssueNegQuantity,
  318. a.ExtensionID
  319. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  320. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  321. FROM
  322. ICSMOApplyNegDetail a
  323. LEFT JOIN ICSInventory b ON a.InvCode = b.InvCode
  324. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  325. where a.ApplyNegCode='" + ApplyNegCode + "'";
  326. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  327. if(Invmes==null || Invmes.Columns.Count<=0)
  328. Invmes = table.Clone();
  329. DataTable dtCloned = table.Clone();
  330. foreach (DataColumn col in dtCloned.Columns)
  331. {
  332. col.DataType = typeof(string);
  333. }
  334. foreach (DataRow row in table.Rows)
  335. {
  336. DataRow newrow = dtCloned.NewRow();
  337. foreach (DataColumn column in dtCloned.Columns)
  338. {
  339. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  340. }
  341. dtCloned.Rows.Add(newrow);
  342. }
  343. if (Invmes.Rows.Count > 0)
  344. {
  345. //dtCloned.Merge(Invmes, false);
  346. foreach (DataRow data in Invmes.Rows)
  347. {
  348. var info = dtCloned.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  349. if (info != null && info.Length > 0)
  350. {
  351. info[0]["ZJID"] = data["ZJID"];
  352. info[0]["InvName"] = data["InvName"];
  353. info[0]["InvCode"] = data["InvCode"];
  354. info[0]["InvStd"] = data["InvStd"];
  355. info[0]["InvUnit"] = data["InvUnit"];
  356. info[0]["Amount"] = data["Amount"];
  357. info[0]["IssueNegQuantity"] = data["IssueNegQuantity"];
  358. info[0]["ExtensionID"] = data["ExtensionID"];
  359. info[0]["Quantity"] = 0;
  360. }
  361. else
  362. {
  363. DataRow newrow = dtCloned.NewRow();
  364. newrow["ZJID"] = data["ZJID"];
  365. newrow["InvName"] = data["InvName"];
  366. newrow["InvCode"] = data["InvCode"];
  367. newrow["InvStd"] = data["InvStd"];
  368. newrow["InvUnit"] = data["InvUnit"];
  369. newrow["Amount"] = data["Amount"];
  370. newrow["Quantity"] = 0;
  371. newrow["ID"] = data["ID"];
  372. newrow["TLZID"] = data["TLZID"];
  373. newrow["IssueNegQuantity"] = data["IssueNegQuantity"];
  374. newrow["ExtensionID"] = data["ExtensionID"];
  375. dtCloned.Rows.Add(newrow);
  376. }
  377. }
  378. }
  379. return dtCloned;
  380. }
  381. public void UpdateMOApplyNegTemp(string json)
  382. {
  383. var data = json.ToJObject();
  384. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  385. var info = Invmes.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  386. if (info != null && info.Length > 0)
  387. {
  388. info[0]["ZJID"] = data["ZJID"];
  389. info[0]["InvName"] = data["InvName"];
  390. info[0]["InvCode"] = data["InvCode"];
  391. info[0]["InvStd"] = data["InvStd"];
  392. info[0]["InvUnit"] = data["InvUnit"];
  393. info[0]["Amount"] = data["Amount"];
  394. info[0]["IssueNegQuantity"] = data["IssueNegQuantity"];
  395. info[0]["ExtensionID"] = data["ExtensionID"];
  396. info[0]["Quantity"] = 0;
  397. }
  398. else
  399. {
  400. DataRow newrow = Invmes.NewRow();
  401. newrow["ZJID"] = data["ZJID"];
  402. newrow["InvName"] = data["InvName"];
  403. newrow["InvCode"] = data["InvCode"];
  404. newrow["InvStd"] = data["InvStd"];
  405. newrow["InvUnit"] = data["InvUnit"];
  406. newrow["Amount"] = data["Amount"];
  407. newrow["IssueNegQuantity"] = data["IssueNegQuantity"];
  408. newrow["ExtensionID"] = data["ExtensionID"];
  409. newrow["Quantity"] = 0;
  410. newrow["ID"] = data["ID"];
  411. newrow["TLZID"] = data["TLZID"];
  412. Invmes.Rows.Add(newrow);
  413. }
  414. }
  415. public string AuditICSMOApplyNeg(string ICSASN)
  416. {
  417. string msg = "";
  418. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "MOIssueDocNegativeApply/Approve";
  419. string result = HttpPost(APIURL, ICSASN);
  420. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  421. string MessAge = Obj["Message"].ToString();
  422. string Success = Obj["Success"].ToString();
  423. if (Success.ToUpper() == "FALSE")
  424. {
  425. msg = MessAge;
  426. }
  427. return msg;
  428. }
  429. public string DeleteICSMOApplyNeg(string keyValue)
  430. {
  431. //站点信息
  432. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  433. string msg = "";
  434. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  435. string sql = string.Empty;
  436. sql += string.Format(@"DELETE FROM dbo.ICSMOApplyNeg WHERE ApplyNegCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  437. sql += string.Format(@"DELETE FROM dbo.ICSMOApplyNegDetail WHERE ApplyNegCode IN ({0}) and WorkPoint ='{1}'", keyValue.TrimEnd(','), WorkPoint);
  438. try
  439. {
  440. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  441. {
  442. }
  443. }
  444. catch (Exception ex)
  445. {
  446. throw new Exception(ex.Message);
  447. }
  448. return msg;
  449. }
  450. }
  451. }