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.

8497 lines
367 KiB

3 weeks ago
  1. using Dapper;
  2. using Dapper.Contrib.Extensions;
  3. using ICSSoft.SendMail;
  4. using Newtonsoft.Json;
  5. using Newtonsoft.Json.Linq;
  6. using NFine.Application.DHAY;
  7. using NFine.Application.Entity;
  8. using NFine.Application.Models;
  9. using NFine.Application.SystemManage;
  10. using NFine.Application.WMS;
  11. using NFine.Code;
  12. using NFine.Data.Extensions;
  13. using NFine.Domain._03_Entity.SRM;
  14. using NFine.Repository;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Configuration;
  18. using System.Data;
  19. using System.Data.Common;
  20. using System.Data.SqlClient;
  21. using System.Linq;
  22. using System.Text;
  23. using System.Threading.Tasks;
  24. namespace NFine.Application.DHAY
  25. {
  26. public class IQCQualityApp : RepositoryFactory<ICSVendor>
  27. {
  28. DataActionApp actionapp = new DataActionApp();
  29. public DataTable GetGridJsonChengPing(string queryJson, ref Pagination pagination)
  30. {
  31. DataTable dt = new DataTable();
  32. var queryParam = queryJson.ToJObject();
  33. List<DbParameter> parameter = new List<DbParameter>();
  34. //object Figure = GetDecimalDigits();
  35. #region [SQL]
  36. string sql = @"
  37. select
  38. case when a.Enable=1 then '是'
  39. else '否' end as EnableText
  40. ,a.*
  41. from ICSInspectionRulesGroup a with(nolock)
  42. where 1=1
  43. --and a.WorkPoint='UFDATA_106_2019'
  44. {0}
  45. <1>
  46. <2>
  47. <3>
  48. ";
  49. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  50. //sql = string.Format(sql, Figure);
  51. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  52. #endregion
  53. if (!string.IsNullOrWhiteSpace(queryJson))
  54. {
  55. if (!string.IsNullOrWhiteSpace(queryParam["RulesCode"].ToString()))
  56. {
  57. sql = sql.Replace("<1>", " and a.RulesCode like '%" + queryParam["RulesCode"].ToString() + "%' ");
  58. }
  59. else
  60. {
  61. sql = sql.Replace("<1>", " ");
  62. }
  63. if (!string.IsNullOrWhiteSpace(queryParam["RulesName"].ToString()))
  64. {
  65. sql = sql.Replace("<2>", " and a.RulesName like '%" + queryParam["RulesName"].ToString() + "%' ");
  66. }
  67. else
  68. {
  69. sql = sql.Replace("<2>", " ");
  70. }
  71. if (!string.IsNullOrWhiteSpace(queryParam["Enable"].ToString()))
  72. {
  73. sql = sql.Replace("<3>", " and a.Enable =" + queryParam["Enable"].ToString() + " ");
  74. }
  75. else
  76. {
  77. sql = sql.Replace("<3>", " ");
  78. }
  79. }
  80. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  81. {
  82. sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  83. // sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  84. }
  85. else
  86. {
  87. sql = sql.Replace("{0}", "");
  88. }
  89. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  90. //{
  91. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  92. //}
  93. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref pagination);
  94. }
  95. public DataTable GetGridJsonGroup(string queryJson, ref Pagination pagination)
  96. {
  97. DataTable dt = new DataTable();
  98. var queryParam = queryJson.ToJObject();
  99. List<DbParameter> parameter = new List<DbParameter>();
  100. //object Figure = GetDecimalDigits();
  101. #region [SQL]
  102. string sql = @"
  103. select
  104. case when a.Enable=1 then '是'
  105. else '否' end as EnableText
  106. ,a.*
  107. from ICSInspectionGroup a with(nolock)
  108. where 1=1
  109. {0}
  110. <1>
  111. <2>
  112. <3>
  113. ";
  114. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  115. //sql = string.Format(sql, Figure);
  116. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  117. #endregion
  118. if (!string.IsNullOrWhiteSpace(queryJson))
  119. {
  120. if (!string.IsNullOrWhiteSpace(queryParam["GroupCode"].ToString()))
  121. {
  122. sql = sql.Replace("<1>", " and a.GroupCode like '%" + queryParam["GroupCode"].ToString() + "%' ");
  123. }
  124. else
  125. {
  126. sql = sql.Replace("<1>", " ");
  127. }
  128. if (!string.IsNullOrWhiteSpace(queryParam["GroupName"].ToString()))
  129. {
  130. sql = sql.Replace("<2>", " and a.GroupName like '%" + queryParam["GroupName"].ToString() + "%' ");
  131. }
  132. else
  133. {
  134. sql = sql.Replace("<2>", " ");
  135. }
  136. if (!string.IsNullOrWhiteSpace(queryParam["Enable"].ToString()))
  137. {
  138. sql = sql.Replace("<3>", " and a.Enable =" + queryParam["Enable"].ToString() + " ");
  139. }
  140. else
  141. {
  142. sql = sql.Replace("<3>", " ");
  143. }
  144. }
  145. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  146. {
  147. sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  148. // sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  149. }
  150. else
  151. {
  152. sql = sql.Replace("{0}", "");
  153. }
  154. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  155. //{
  156. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  157. //}
  158. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref pagination);
  159. }
  160. public DataTable GetCheckItemDetailList(string id, ref Pagination pagination)
  161. {
  162. DataTable dt = new DataTable();
  163. // var queryParam = queryJson.ToJObject();
  164. List<DbParameter> parameter = new List<DbParameter>();
  165. //object Figure = GetDecimalDigits();
  166. #region [SQL]
  167. string sql = @"select
  168. a.*
  169. from ICSInspectionList a with(nolock)
  170. where 1=1
  171. {0}
  172. <1>
  173. order by a.ListCode asc
  174. ";
  175. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  176. sql = sql.Replace("<1>", "and a.GroupID='" + id + "'");
  177. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  178. #endregion
  179. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  180. {
  181. sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  182. // sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  183. }
  184. else
  185. {
  186. sql = sql.Replace("{0}", "");
  187. }
  188. return Repository().FindDataSetBySql(sql.ToString(), parameter.ToArray()).Tables[0];
  189. }
  190. public DataTable GetCheckItemGroupPageList(string queryJson, ref Pagination pagination)
  191. {
  192. DataTable dt = new DataTable();
  193. var queryParam = queryJson.ToJObject();
  194. List<DbParameter> parameter = new List<DbParameter>();
  195. //object Figure = GetDecimalDigits();
  196. #region [SQL]
  197. string sql = @"
  198. select
  199. case when a.Enable=1 then '是'
  200. else '否' end as EnableText
  201. ,a.*
  202. from ICSInspectionGroup a with(nolock)
  203. where 1=1
  204. {0}
  205. <1>
  206. <2>
  207. --<3>
  208. ";
  209. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  210. //sql = string.Format(sql, Figure);
  211. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  212. #endregion
  213. if (!string.IsNullOrWhiteSpace(queryJson))
  214. {
  215. if (!string.IsNullOrWhiteSpace(queryParam["GroupCode"].ToString()))
  216. {
  217. sql = sql.Replace("<1>", " and a.GroupCode like '%" + queryParam["GroupCode"].ToString() + "%' ");
  218. }
  219. else
  220. {
  221. sql = sql.Replace("<1>", " ");
  222. }
  223. if (!string.IsNullOrWhiteSpace(queryParam["GroupName"].ToString()))
  224. {
  225. sql = sql.Replace("<2>", " and a.GroupName like '%" + queryParam["GroupName"].ToString() + "%' ");
  226. }
  227. else
  228. {
  229. sql = sql.Replace("<2>", " ");
  230. }
  231. //if (!string.IsNullOrWhiteSpace(queryParam["Enable"].ToString()))
  232. //{
  233. // sql = sql.Replace("<3>", " and a.Enable =" + queryParam["Enable"].ToString() + " ");
  234. //}
  235. //else
  236. //{
  237. // sql = sql.Replace("<3>", " ");
  238. //}
  239. }
  240. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  241. {
  242. sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  243. // sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  244. }
  245. else
  246. {
  247. sql = sql.Replace("{0}", "");
  248. }
  249. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  250. //{
  251. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  252. //}
  253. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref pagination);
  254. }
  255. public DataTable GetBadCodeGroupPageList(string queryJson, ref Pagination pagination)
  256. {
  257. DataTable dt = new DataTable();
  258. var queryParam = queryJson.ToJObject();
  259. List<DbParameter> parameter = new List<DbParameter>();
  260. //object Figure = GetDecimalDigits();
  261. #region [SQL]
  262. string sql = @"
  263. select
  264. a.*
  265. from ICSBadCodeGroup a with(nolock)
  266. where 1=1
  267. {0}
  268. <1>
  269. <2>
  270. ";
  271. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  272. //sql = string.Format(sql, Figure);
  273. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  274. #endregion
  275. if (!string.IsNullOrWhiteSpace(queryJson))
  276. {
  277. if (!string.IsNullOrWhiteSpace(queryParam["BCGCode"].ToString()))
  278. {
  279. sql = sql.Replace("<1>", " and a.BCGCode like '%" + queryParam["BCGCode"].ToString() + "%' ");
  280. }
  281. else
  282. {
  283. sql = sql.Replace("<1>", " ");
  284. }
  285. if (!string.IsNullOrWhiteSpace(queryParam["BCGDesc"].ToString()))
  286. {
  287. sql = sql.Replace("<2>", " and a.BCGDesc like '%" + queryParam["BCGDesc"].ToString() + "%' ");
  288. }
  289. else
  290. {
  291. sql = sql.Replace("<2>", " ");
  292. }
  293. }
  294. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  295. {
  296. sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  297. // sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  298. }
  299. else
  300. {
  301. sql = sql.Replace("{0}", "");
  302. }
  303. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  304. //{
  305. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  306. //}
  307. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref pagination);
  308. }
  309. public DataTable GetBadCodeGroupDetailList(string id, ref Pagination pagination)
  310. {
  311. DataTable dt = new DataTable();
  312. // var queryParam = queryJson.ToJObject();
  313. List<DbParameter> parameter = new List<DbParameter>();
  314. //object Figure = GetDecimalDigits();
  315. #region [SQL]
  316. string sql = @"select
  317. a.*
  318. from ICSBadCode a with(nolock)
  319. where 1=1
  320. {0}
  321. <1>
  322. order by a.BadCode asc
  323. ";
  324. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  325. sql = sql.Replace("<1>", "and a.BCGroupID='" + id + "'");
  326. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  327. #endregion
  328. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  329. {
  330. sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  331. // sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  332. }
  333. else
  334. {
  335. sql = sql.Replace("{0}", "");
  336. }
  337. return Repository().FindDataSetBySql(sql.ToString(), parameter.ToArray()).Tables[0];
  338. }
  339. public DataTable GetAllCheckGroupList(string code)
  340. {
  341. var workpont = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  342. string sql = $@"select b.* from ICSInspectionGroup a with(nolock)
  343. LEFT JOIN ICSInspectionList b with(nolock) ON a.Id = b.groupid AND a.Workpoint = b.workpoint and b.enable='1'
  344. where a.GroupCode='{code}' and a.workpoint='{workpont}' and a.Enable='1'";
  345. var returnValue = SqlHelper.ExecuteTable(sql);
  346. return returnValue;
  347. }
  348. public DataTable GetEditCheckGroupList(string code, string INVCode)
  349. {
  350. var workpont = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  351. string sql = $@"select b.* from ICSInventoryInspectionGroup a with(nolock)
  352. LEFT JOIN ICSInventoryInspectionList b with(nolock) ON a.Id = b.InvGroupID AND a.Workpoint = b.workpoint and b.enable='1'
  353. where a.GroupCode='{code}' and A.InvCode='{INVCode}' and a.workpoint='{workpont}' and a.Enable='1'
  354. order by
  355. case when b.EATTRIBUTE6 = 'Size' then 1
  356. when b.EATTRIBUTE6 = 'Carton' then 2
  357. else 3 end,
  358. b.SetValueMin asc";
  359. var returnValue = SqlHelper.ExecuteTable(sql);
  360. if (returnValue.Rows.Count == 0)
  361. {
  362. sql = $@"select b.* from ICSInspectionGroup a with(nolock)
  363. LEFT JOIN ICSInspectionList b with(nolock) ON a.Id = b.groupid AND a.Workpoint = b.workpoint and b.enable='1'
  364. where a.GroupCode='{code}' and a.workpoint='{workpont}' and a.Enable='1'
  365. order by
  366. case when b.EATTRIBUTE6 = 'Size' then 1
  367. when b.EATTRIBUTE6 = 'Carton' then 2
  368. else 3 end,
  369. b.SetValueMin asc";
  370. returnValue = SqlHelper.ExecuteTable(sql);
  371. }
  372. return returnValue;
  373. }
  374. public string DeleteAql(string keyValue)
  375. {
  376. string returnValue = string.Empty;
  377. try
  378. {
  379. List<DbParameter> parameter = new List<DbParameter>();
  380. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  381. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  382. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  383. var idList = JsonConvert.DeserializeObject<List<string>>(keyValue);
  384. string sql = @" select
  385. a.*
  386. from ICSInspectionRulesGroup a with(nolock)
  387. where a.ID in ('" + string.Join("','", idList) + "') and a.workpoint=@WorkPoint ";
  388. var para = new { WorkPoint = WorkPoint };
  389. var entityList = MsSqlData.Query<ICSInspectionRulesGroupEntity>(sql, para).ToList();
  390. foreach (var item in entityList)
  391. {
  392. //var count = MsSqlData.ExecuteScalar(" select count(1) from IcsCheckingFixtureTransfer with(nolock) where CheckFixtureNo='" + item.CheckFixtureNo + "'").ToInt();
  393. //if (count > 0)
  394. //{
  395. // throw new Exception("当前检具已经存在履历,不能删除");
  396. //}
  397. }
  398. string chksql = @" select ListCode from ICSInspectionList
  399. where EATTRIBUTE5 in
  400. (select RulesCode from ICSInspectionRulesGroup
  401. where ID in ('{0}'))
  402. AND WorkPoint='{1}'";
  403. chksql = string.Format(chksql, string.Join("', '", idList), WorkPoint);
  404. DataTable chkdt = Repository().FindDataSetBySql(chksql.ToString(), parameter.ToArray()).Tables[0];
  405. if (chkdt.Rows.Count > 0)
  406. {
  407. throw new Exception("所选AQL已绑定检验项目,无法删除!");
  408. }
  409. var result = MsSqlData.Delete<ICSInspectionRulesGroupEntity>(entityList);
  410. if (!result)
  411. {
  412. returnValue = "删除失败";
  413. }
  414. string sql2 = @"delete from ICSInspectionRulesList where RulesID in ('" + string.Join("','", idList) + "') and a.workpoint=@WorkPoint ";
  415. List<SqlParameter> paras = new List<SqlParameter>();
  416. paras.Add(new SqlParameter("@WorkPoint", SqlDbType.NVarChar) { Value = WorkPoint });
  417. var line = Repository().ExecuteBySql(new StringBuilder(sql2), paras.ToArray());
  418. }
  419. catch (Exception ex)
  420. {
  421. returnValue = ex.Message;
  422. }
  423. return returnValue;
  424. }
  425. public string DeleteCheckGroup(string keyValue)
  426. {
  427. string returnValue = string.Empty;
  428. try
  429. {
  430. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  431. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  432. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  433. var idList = JsonConvert.DeserializeObject<List<string>>(keyValue);
  434. string sql = @"select
  435. a.*
  436. from ICSInspectionGroup a with(nolock)
  437. where a.ID in ('" + string.Join("','", idList) + "') and a.workpoint=@WorkPoint ";
  438. var para = new { WorkPoint = WorkPoint };
  439. var entityList = MsSqlData.Query<ICSInspectionGroupEntity>(sql, para).ToList();
  440. foreach (var item in entityList)
  441. {
  442. //var count = MsSqlData.ExecuteScalar(" select count(1) from IcsCheckingFixtureTransfer with(nolock) where CheckFixtureNo='" + item.CheckFixtureNo + "'").ToInt();
  443. //if (count > 0)
  444. //{
  445. // throw new Exception("当前检具已经存在履历,不能删除");
  446. //}
  447. }
  448. var result = MsSqlData.Delete<ICSInspectionGroupEntity>(entityList);
  449. if (!result)
  450. {
  451. returnValue = "删除失败";
  452. }
  453. string sql2 = @"delete from ICSInspectionList where GroupID in ('" + string.Join("','", idList) + "') and a.workpoint=@WorkPoint ";
  454. List<SqlParameter> paras = new List<SqlParameter>();
  455. paras.Add(new SqlParameter("@WorkPoint", SqlDbType.NVarChar) { Value = WorkPoint });
  456. var line = Repository().ExecuteBySql(new StringBuilder(sql2), paras.ToArray());
  457. }
  458. catch (Exception ex)
  459. {
  460. returnValue = ex.Message;
  461. }
  462. return returnValue;
  463. }
  464. public DataTable GetItem2RuleList(string queryJson, ref Pagination pagination)
  465. {
  466. DataTable dt = new DataTable();
  467. var queryParam = queryJson.ToJObject();
  468. List<DbParameter> parameter = new List<DbParameter>();
  469. //object Figure = GetDecimalDigits();
  470. #region [SQL]
  471. string sql = @"
  472. select
  473. a.*
  474. from
  475. (
  476. select
  477. a.ID
  478. ,b.InvCode
  479. ,b.InvName
  480. ,b.InvStd
  481. ,c.RulesCode
  482. ,c.RulesName
  483. ,c.RulesDesc
  484. ,a.MUSER
  485. ,a.MUSERName
  486. ,a.MTIME
  487. ,a.EATTRIBUTE1 as CheckAttr --
  488. ,( select t.label from V_QuerySysEnumItem t where t.value=a.EATTRIBUTE1 and t.F_EnCode='CheckAttr'
  489. ) as CheckAttrText
  490. from ICSInventoryInspectionRulesGroup a with(nolock)
  491. join ICSInventory b with(nolock) on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  492. join ICSInspectionRulesGroup c with(nolock) on a.RulesCode=c.RulesCode and a.WorkPoint=c.WorkPoint
  493. where 1=1
  494. {0}
  495. ) a
  496. where 1=1
  497. <1>
  498. <2>
  499. <3>
  500. <4>
  501. ";
  502. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  503. //sql = string.Format(sql, Figure);
  504. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  505. #endregion
  506. if (!string.IsNullOrWhiteSpace(queryJson))
  507. {
  508. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  509. {
  510. sql = sql.Replace("<1>", " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ");
  511. }
  512. else
  513. {
  514. sql = sql.Replace("<1>", " ");
  515. }
  516. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  517. {
  518. sql = sql.Replace("<2>", " and a.InvName like '%" + queryParam["InvName"].ToString() + "%' ");
  519. }
  520. else
  521. {
  522. sql = sql.Replace("<2>", " ");
  523. }
  524. if (!string.IsNullOrWhiteSpace(queryParam["RulesCode"].ToString()))
  525. {
  526. sql = sql.Replace("<3>", " and a.RulesCode like '%" + queryParam["RulesCode"].ToString() + "%' ");
  527. }
  528. else
  529. {
  530. sql = sql.Replace("<3>", " ");
  531. }
  532. if (!string.IsNullOrWhiteSpace(queryParam["RulesName"].ToString()))
  533. {
  534. sql = sql.Replace("<4>", " and a.RulesName like '%" + queryParam["RulesName"].ToString() + "%' ");
  535. }
  536. else
  537. {
  538. sql = sql.Replace("<4>", " ");
  539. }
  540. }
  541. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  542. {
  543. sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  544. // sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  545. }
  546. else
  547. {
  548. sql = sql.Replace("{0}", "");
  549. }
  550. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  551. //{
  552. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  553. //}
  554. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref pagination);
  555. }
  556. public string SaveItem2AqlSingle(string keyValue)
  557. {
  558. string returnValue = string.Empty;
  559. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  560. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  561. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  562. try
  563. {
  564. var dtNow = DateTime.Now;
  565. var para = new { WorkPoint = WorkPoint };
  566. var model = JsonConvert.DeserializeObject<ICSInventoryInspectionRulesGroup>(keyValue);
  567. if (model == null)
  568. {
  569. throw new Exception("传入参数错误");
  570. }
  571. //修改
  572. var entity = MsSqlData.Get<ICSInventoryInspectionRulesGroup>(model.ID);
  573. if (entity == null)
  574. {
  575. throw new Exception("当前数据不存在");
  576. }
  577. entity.RulesCode = model.RulesCode;
  578. var sql1 = @"select top 1 * from ICSInspectionRulesGroup a with(nolock) where a.RulesCode = '" + entity.RulesCode + "' and a.WorkPoint=@WorkPoint ";
  579. var aql = MsSqlData.Query<ICSInspectionRulesGroupEntity>(sql1, para).FirstOrDefault();
  580. if (aql == null)
  581. {
  582. throw new Exception("当前Aql不存在");
  583. }
  584. entity.RulesName = aql.RulesName;
  585. entity.RulesDesc = aql.RulesDesc;
  586. entity.Type = aql.Type;
  587. entity.Enable = model.Enable;
  588. entity.MUSER = MUSER;
  589. entity.MUSERName = MUSERNAME;
  590. entity.MTIME = dtNow;
  591. var result = MsSqlData.Update<ICSInventoryInspectionRulesGroup>(entity);
  592. if (!result)
  593. {
  594. returnValue = "修改失败";
  595. }
  596. }
  597. catch (Exception ex)
  598. {
  599. returnValue = ex.Message;
  600. }
  601. return returnValue;
  602. }
  603. public int UpLoadFinalJudgeFile(string iD, string fileName)
  604. {
  605. var returnValue = 1;
  606. var dtNow = DateTime.Now;
  607. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  608. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  609. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  610. var para = new { WorkPoint = WorkPoint };
  611. SqlConnection conn = SqlHelper.GetDataCenterConn();
  612. try
  613. {
  614. var entity = MsSqlData.Get<IcsMatCheckResult>(iD);
  615. if (entity == null)
  616. {
  617. throw new Exception("当前数据不存在");
  618. }
  619. entity.SpecialFile = fileName;
  620. entity.MUSER = MUSER;
  621. entity.MUSERName = MUSERNAME;
  622. entity.MTIME = dtNow;
  623. var result = MsSqlData.Update<IcsMatCheckResult>(entity);
  624. if (!result)
  625. {
  626. returnValue = 0;
  627. }
  628. }
  629. catch (Exception ex)
  630. {
  631. returnValue = 0;
  632. }
  633. return returnValue;
  634. }
  635. public ICSInventoryInspectionRulesGroup GetItem2Aql(string keyValue)
  636. {
  637. var returnValue = new ICSInventoryInspectionRulesGroup();
  638. try
  639. {
  640. returnValue = MsSqlData.Get<ICSInventoryInspectionRulesGroup>(keyValue);
  641. }
  642. catch (Exception ex)
  643. {
  644. returnValue = null;
  645. }
  646. return returnValue;
  647. }
  648. public string SetData_PR(string savePath)
  649. {
  650. string returnValue = string.Empty;
  651. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  652. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  653. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  654. SqlConnection conn = SqlHelper.GetDataCenterConn();
  655. DataTable data = FileToExcel.ExcelToTable(savePath);
  656. DateTime time = DateTime.Now;
  657. //DataSet dsSave = new DataSet();
  658. //dsSave.Tables.Add(data.Copy());
  659. //dsSave.Tables[0].TableName = "IcsCheckingFixture";
  660. var para = new { WorkPoint = WorkPoint };
  661. string sql0 = @"
  662. select *
  663. from V_QuerySysEnumItem a
  664. where a.F_EnCode='CheckAttr'
  665. ";
  666. var enumList = MsSqlData.Query<SysEnumValueDto>(sql0, para).ToList();
  667. //var chicun = enumList.Where(x => x.Ext1 == "尺寸").Select(x => x.value);
  668. List<ICSInventoryInspectionRulesGroup> list = new List<ICSInventoryInspectionRulesGroup>();
  669. for (int i = 0; i < data.Rows.Count; i++)
  670. {
  671. var item = data.Rows[i];
  672. if (item["物料代码"].ToStringExt() == "")
  673. {
  674. throw new Exception("第" + (i + 1) + "行," + "物料代码为空");
  675. }
  676. if (item["Aql代码"].ToStringExt() == "")
  677. {
  678. throw new Exception("第" + (i + 1) + "行," + "Aql代码为空");
  679. }
  680. if (item["检验属性"].ToStringExt() == "")
  681. {
  682. throw new Exception("第" + (i + 1) + "行," + "检验属性为空");
  683. }
  684. //if (item["类型"].ToStringExt() == "")
  685. //{
  686. // throw new Exception("第" + (i + 1) + "行," + "类型为空");
  687. //}
  688. ICSInventoryInspectionRulesGroup entity = new ICSInventoryInspectionRulesGroup();
  689. entity.ID = Guid.NewGuid().ToString();
  690. entity.InvCode = item["物料代码"].ToStringExt();
  691. entity.RulesCode = item["Aql代码"].ToStringExt();
  692. entity.EATTRIBUTE1 = enumList.Where(x => x.label == item["检验属性"].ToStringExt()).FirstOrDefault()?.value;
  693. var count = MsSqlData.ExecuteScalar
  694. (
  695. " select count(1) from ICSInventoryInspectionRulesGroup a with(nolock) where InvCode='" + entity.InvCode + "' and a.EATTRIBUTE1='" + entity.EATTRIBUTE1 + "' "
  696. ).ToInt();
  697. if (count > 0)
  698. {
  699. throw new Exception("当前物料Aql关系已经存在");
  700. }
  701. var itemCode = MsSqlData.Query<ICSInventoryDto>(
  702. @"select top 1 * from ICSInventory a with(nolock)
  703. where a.InvCode = '" + entity.InvCode + "'")
  704. .FirstOrDefault();
  705. if (itemCode == null)
  706. {
  707. throw new Exception("当前物料不存在");
  708. }
  709. var aql = MsSqlData.Query<ICSInspectionRulesGroupEntity>(
  710. @"select top 1 * from ICSInspectionRulesGroup a with(nolock)
  711. where a.RulesCode = '" + entity.RulesCode + "'")
  712. .FirstOrDefault();
  713. if (aql == null)
  714. {
  715. throw new Exception("当前Aql不存在");
  716. }
  717. entity.RulesName = aql.RulesName;
  718. entity.RulesDesc = aql.RulesDesc;
  719. entity.Type = aql.Type;
  720. entity.Enable = true;
  721. entity.Editable = true;
  722. entity.MUSER = MUSER;
  723. entity.MUSERName = MUSERNAME;
  724. entity.MTIME = time;
  725. entity.WorkPoint = WorkPoint;
  726. list.Add(entity);
  727. }
  728. if (list.Count == 0)
  729. {
  730. throw new Exception("没有导入数据");
  731. }
  732. var result = MsSqlData.Insert<ICSInventoryInspectionRulesGroup>(list);
  733. if (!result)
  734. {
  735. throw new Exception("导入失败");
  736. }
  737. returnValue = "true";
  738. return returnValue;
  739. }
  740. public string UploadFileInspectionRules(string savePath)
  741. {
  742. try
  743. {
  744. List<DbParameter> parameter = new List<DbParameter>();
  745. string returnValue = string.Empty;
  746. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  747. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  748. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  749. SqlConnection conn = SqlHelper.GetDataCenterConn();
  750. DataTable data = FileToExcel.ExcelToTable(savePath);
  751. DateTime time = DateTime.Now;
  752. var para = new { WorkPoint = WorkPoint };
  753. List<string> TypeList = new List<string>();
  754. string sql0 = @"
  755. SELECT a.Name FROM dbo.ICSType a
  756. WHERE TableCode='ICSInspectionList' and ColumnCode='EATTRIBUTE6' and Workpoint='11'
  757. ";
  758. DataTable typedt = Repository().FindDataSetBySql(sql0.ToString(), parameter.ToArray()).Tables[0];
  759. foreach (DataRow dr in typedt.Rows)
  760. {
  761. TypeList.Add(dr["Name"].ToString());
  762. }
  763. List<TempInspectGuid> GuidInfoList = new List<TempInspectGuid>();
  764. string sql = "";
  765. string setValueMax = "";
  766. string setValueMin = "";
  767. for (int i = 0; i < data.Rows.Count; i++)
  768. {
  769. var item = data.Rows[i];
  770. if (item["检验项目组代码"].ToStringExt() == "")
  771. {
  772. return "第" + (i + 1) + "行," + "检验项目组代码为空";
  773. }
  774. if (item["检验项目组名称"].ToStringExt() == "")
  775. {
  776. return "第" + (i + 1) + "行," + "检验项目组名称为空";
  777. }
  778. if (item["检验类型"].ToString() == "")
  779. {
  780. return "第" + (i + 1) + "行," + "检验类型为空";
  781. }
  782. if (item["检验项目代码"].ToStringExt() == "")
  783. {
  784. return "第" + (i + 1) + "行," + "检验项目代码为空";
  785. }
  786. if (item["检验项目名称"].ToStringExt() == "")
  787. {
  788. return "第" + (i + 1) + "行," + "检验项目名称为空";
  789. }
  790. if (item["检验类型"].ToString() == "定量")
  791. {
  792. if (item["标准下限"].ToString() == "" || item["标准上限"].ToString() == "")
  793. {
  794. return "第" + (i + 1) + "行," + "检验类型为定量时,标准上下限不能为空";
  795. }
  796. if (Convert.ToDecimal(item["标准下限"]) >= Convert.ToDecimal(item["标准上限"]))
  797. {
  798. return "第" + (i + 1) + "行," + "标准下限必须小于标准上限";
  799. }
  800. if (item["单位"].ToStringExt() == "")
  801. {
  802. return "第" + (i + 1) + "行," + "检验类型为定量时,单位不能为空";
  803. }
  804. if (item["检验仪器"].ToStringExt() == "")
  805. {
  806. return "第" + (i + 1) + "行," + "检验类型为定量时,检验仪器不能为空";
  807. }
  808. setValueMax = item["标准上限"].ToString();
  809. setValueMin = item["标准下限"].ToString();
  810. }
  811. else
  812. {
  813. if (item["标准下限"].ToString() != "")
  814. {
  815. setValueMin = item["标准下限"].ToString();
  816. }
  817. else
  818. {
  819. setValueMin = "";
  820. }
  821. if (item["标准上限"].ToString() != "")
  822. {
  823. setValueMax = item["标准上限"].ToString();
  824. }
  825. else
  826. {
  827. setValueMax = "";
  828. }
  829. }
  830. if (item["检验实际值是否必填"].ToString() != "是" && item["检验实际值是否必填"].ToString() != "否")
  831. {
  832. return "第" + (i + 1) + "行," + "检验实际值是否必填只能填写是或者否";
  833. }
  834. if (item["AQL代码"].ToString() == "")
  835. {
  836. return "第" + (i + 1) + "行," + "AQL代码为空";
  837. }
  838. if (!TypeList.Contains(item["检验类型"].ToString()))
  839. {
  840. return "第" + (i + 1) + "行," + "所填写检验类型不存在";
  841. }
  842. string NeedActualValue = "";
  843. if (item["检验实际值是否必填"].ToString() == "是")
  844. {
  845. NeedActualValue = "True";
  846. }
  847. else
  848. {
  849. NeedActualValue = "False";
  850. }
  851. string guid = "";
  852. string chksql = "";
  853. DataTable chkdt = new DataTable();
  854. if (GuidInfoList.Count != 0)
  855. {
  856. foreach (TempInspectGuid GuidInfo in GuidInfoList)
  857. {
  858. if (GuidInfo.GroupCode == item["检验项目组代码"].ToStringExt())
  859. {
  860. guid = GuidInfo.GUID;
  861. }
  862. }
  863. if (guid == "")
  864. {
  865. TempInspectGuid GuidInfo = new TempInspectGuid();
  866. chksql = @" select ID from ICSInspectionGroup
  867. where GroupCode='{0}' and WorkPoint='{1}'";
  868. chksql = string.Format(chksql, item["检验项目组代码"].ToStringExt(), WorkPoint);
  869. chkdt = Repository().FindDataSetBySql(chksql.ToString(), parameter.ToArray()).Tables[0];
  870. if (chkdt.Rows.Count != 0)
  871. {
  872. guid = chkdt.Rows[0]["ID"].ToString();
  873. }
  874. else
  875. {
  876. guid = Guid.NewGuid().ToString();
  877. }
  878. GuidInfo.GroupCode = item["检验项目组代码"].ToStringExt();
  879. GuidInfo.GUID = guid;
  880. GuidInfoList.Add(GuidInfo);
  881. }
  882. }
  883. else
  884. {
  885. TempInspectGuid GuidInfo = new TempInspectGuid();
  886. chksql = @" select ID from ICSInspectionGroup
  887. where GroupCode='{0}' and WorkPoint='{1}'";
  888. chksql = string.Format(chksql, item["检验项目组代码"].ToStringExt(), WorkPoint);
  889. chkdt = Repository().FindDataSetBySql(chksql.ToString(), parameter.ToArray()).Tables[0];
  890. if (chkdt.Rows.Count != 0)
  891. {
  892. guid = chkdt.Rows[0]["ID"].ToString();
  893. }
  894. else
  895. {
  896. guid = Guid.NewGuid().ToString();
  897. }
  898. GuidInfo.GroupCode = item["检验项目组代码"].ToStringExt();
  899. GuidInfo.GUID = guid;
  900. GuidInfoList.Add(GuidInfo);
  901. }
  902. chksql = @" SELECT ListCode FROM ICSInspectionList
  903. WHERE ListCode='{0}' AND GroupID='{3}' AND WorkPoint='{1}'
  904. select RulesCode from ICSInspectionRulesGroup
  905. where RulesCode='{2}' and WorkPoint='{1}'";
  906. chksql = string.Format(chksql, item["检验项目代码"].ToStringExt(), WorkPoint, item["AQL代码"].ToStringExt(), guid);
  907. chkdt = Repository().FindDataSetBySql(chksql.ToString(), parameter.ToArray()).Tables[0];
  908. if (chkdt.Rows.Count != 0)
  909. {
  910. return "第" + (i + 1) + "行," + "所填写检验项目代码已存在";
  911. }
  912. chkdt = Repository().FindDataSetBySql(chksql.ToString(), parameter.ToArray()).Tables[1];
  913. if (chkdt.Rows.Count == 0)
  914. {
  915. return "第" + (i + 1) + "行," + "所填写AQL代码不存在";
  916. }
  917. sql += @" IF NOT EXISTS(select GroupCode from ICSInspectionGroup where GroupCode='{0}' and WorkPoint='{4}')
  918. BEGIN
  919. INSERT INTO ICSInspectionGroup
  920. (ID,GroupCode,GroupName,Enable,MUSER,MUSERName,MTIME,WorkPoint)
  921. VALUES
  922. ('{5}','{0}','{1}',1,'{2}','{3}',GETDATE(),'{4}')
  923. INSERT INTO ICSInspectionList
  924. (ID,GroupID,ListCode,ListName,Unit,SetValueMax,SetValueMin,Enable,MUSER,MUSERName,MTIME,WorkPoint
  925. ,EATTRIBUTE1,EATTRIBUTE4,EATTRIBUTE5,EATTRIBUTE6,EATTRIBUTE7)
  926. VALUES
  927. (NEWID(),'{5}','{6}','{7}','{8}',{9},{10},1,'{2}','{3}',GETDATE(),'{4}'
  928. ,'{11}','{12}','{13}',(SELECT Code FROM ICSType
  929. WHERE ColumnCode='EATTRIBUTE6' AND TableCode='ICSInspectionList' AND Name='{14}' AND WorkPoint='{4}')
  930. ,'{15}')
  931. END
  932. ELSE
  933. BEGIN
  934. INSERT INTO ICSInspectionList
  935. (ID,GroupID,ListCode,ListName,Unit,SetValueMax,SetValueMin,Enable,MUSER,MUSERName,MTIME,WorkPoint
  936. ,EATTRIBUTE1,EATTRIBUTE4,EATTRIBUTE5,EATTRIBUTE6,EATTRIBUTE7)
  937. VALUES
  938. (NEWID(),'{5}','{6}','{7}','{8}',{9},{10},1,'{2}','{3}',GETDATE(),'{4}'
  939. ,'{11}','{12}','{13}',(SELECT Code FROM ICSType
  940. WHERE ColumnCode='EATTRIBUTE6' AND TableCode='ICSInspectionList' AND Name='{14}' AND WorkPoint='{4}')
  941. ,'{15}')
  942. END";
  943. if (setValueMax != "")
  944. {
  945. sql = string.Format(sql, item["检验项目组代码"].ToStringExt(), item["检验项目组名称"].ToStringExt(), MUSER, MUSERNAME, WorkPoint
  946. , guid, item["检验项目代码"].ToStringExt(), item["检验项目名称"].ToStringExt(), item["单位"].ToStringExt()
  947. , setValueMax, setValueMin, item["检验标准"].ToStringExt(), NeedActualValue
  948. , item["AQL代码"].ToStringExt(), item["检验类型"].ToStringExt(), item["检验仪器"].ToStringExt());
  949. }
  950. else
  951. {
  952. sql = string.Format(sql, item["检验项目组代码"].ToStringExt(), item["检验项目组名称"].ToStringExt(), MUSER, MUSERNAME, WorkPoint
  953. , guid, item["检验项目代码"].ToStringExt(), item["检验项目名称"].ToStringExt(), item["单位"].ToStringExt()
  954. , "NULL", "NULL", item["检验标准"].ToStringExt(), NeedActualValue
  955. , item["AQL代码"].ToStringExt(), item["检验类型"].ToStringExt(), item["检验仪器"].ToStringExt());
  956. }
  957. }
  958. if (SqlHelper.CmdExecuteNonQuery(sql) == 0)
  959. {
  960. return "导入失败";
  961. }
  962. returnValue = "true";
  963. return returnValue;
  964. }
  965. catch (Exception ex)
  966. {
  967. throw new Exception(ex.Message);
  968. }
  969. }
  970. /// <summary>
  971. /// 东辉AQL导入列表
  972. /// </summary>
  973. /// <param name="savePath"></param>
  974. /// <returns></returns>
  975. public string UploadFileInspectionAQL(string savePath)
  976. {
  977. try
  978. {
  979. List<DbParameter> parameter = new List<DbParameter>();
  980. string returnValue = string.Empty;
  981. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  982. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  983. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  984. SqlConnection conn = SqlHelper.GetDataCenterConn();
  985. DataTable data = FileToExcel.ExcelToTable(savePath);
  986. DateTime time = DateTime.Now;
  987. var para = new { WorkPoint = WorkPoint };
  988. List<TempInspectGuid> GuidInfoList = new List<TempInspectGuid>();
  989. string sql = "";
  990. decimal setValueMin = 0;
  991. decimal setValueMax = 0;
  992. decimal setAllowNGQty = 0;
  993. string AQLType = "";
  994. // 【新增】缓存:AQL编码 -> 主表ID(确保相同AQL只插入一次主表)
  995. Dictionary<string, string> aqlMainIdCache = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
  996. // 【保留】连续性校验缓存
  997. string lastAqlCode = string.Empty;
  998. decimal lastSetValueMax = 0;
  999. for (int i = 0; i < data.Rows.Count; i++)
  1000. {
  1001. var item = data.Rows[i];
  1002. string chksql = "";
  1003. DataTable chkdt = new DataTable();
  1004. string currentAqlCode = item["AQL代码"].ToString().Trim();
  1005. string mainTableId = string.Empty; // 主表(ICSInspectionRulesGroup)的ID
  1006. // AQL代码校验(原有逻辑)
  1007. if (string.IsNullOrEmpty(currentAqlCode))
  1008. {
  1009. return "第" + (i + 1) + "行," + "AQL代码为空";
  1010. }
  1011. else
  1012. {
  1013. chksql = @" select RulesCode from ICSInspectionRulesGroup
  1014. where RulesCode='{0}' and WorkPoint='{1}'";
  1015. chksql = string.Format(chksql, currentAqlCode, WorkPoint);
  1016. chkdt = Repository().FindDataSetBySql(chksql.ToString(), parameter.ToArray()).Tables[0];
  1017. if (chkdt.Rows.Count != 0)
  1018. {
  1019. return "第" + (i + 1) + "行," + "AQL代码已存在";
  1020. }
  1021. }
  1022. // AQL名称校验(原有逻辑)
  1023. if (item["AQL名称"].ToStringExt() == "")
  1024. {
  1025. return "第" + (i + 1) + "行," + "AQL名称为空";
  1026. }
  1027. // 取样数量校验(原有逻辑)
  1028. if (item["取样数量"].ToString() == "")
  1029. {
  1030. return "第" + (i + 1) + "行," + "取样数量为空";
  1031. }
  1032. else
  1033. {
  1034. if (Convert.ToDecimal(item["取样数量"].ToString()) <= 0)
  1035. {
  1036. return "第" + (i + 1) + "行," + "取样数量必须大于0";
  1037. }
  1038. }
  1039. // 允许不良数处理(原有逻辑)
  1040. if (item["允许不良数"].ToStringExt() == "")
  1041. {
  1042. setAllowNGQty = 0;
  1043. }
  1044. else
  1045. {
  1046. setAllowNGQty = Convert.ToDecimal(item["允许不良数"].ToString());
  1047. }
  1048. // 取样类别校验(原有逻辑)
  1049. if (item["取样类别"].ToStringExt() == "")
  1050. {
  1051. return "第" + (i + 1) + "行," + "取样类别为空";
  1052. }
  1053. else
  1054. {
  1055. chksql = @" SELECT a.Code,a.Name FROM dbo.ICSType a
  1056. WHERE a.Name='{0}' AND TableCode='ICSInspectionRulesList' and ColumnCode='EATTRIBUTE2' and Workpoint='{1}'";
  1057. chksql = string.Format(chksql, item["取样类别"].ToString(), WorkPoint);
  1058. chkdt = Repository().FindDataSetBySql(chksql.ToString(), parameter.ToArray()).Tables[0];
  1059. if (chkdt.Rows.Count == 0)
  1060. {
  1061. return "第" + (i + 1) + "行," + "取样类别:" + item["取样类别"].ToString() + "不存在";
  1062. }
  1063. else
  1064. {
  1065. AQLType = chkdt.Rows[0]["Code"].ToString();
  1066. }
  1067. }
  1068. // 批量下限处理(修改:必填校验)
  1069. if (item["批量下限"].ToString() != "")
  1070. {
  1071. setValueMin = Convert.ToDecimal(item["批量下限"]);
  1072. }
  1073. else
  1074. {
  1075. return "第" + (i + 1) + "行," + "批量下限不能为空";
  1076. }
  1077. // 批量上限处理(修改:必填校验)
  1078. if (item["批量上限"].ToString() != "")
  1079. {
  1080. setValueMax = Convert.ToDecimal(item["批量上限"]);
  1081. }
  1082. else
  1083. {
  1084. return "第" + (i + 1) + "行," + "批量上限不能为空";
  1085. }
  1086. // 批量上下限大小校验(原有逻辑)
  1087. if (setValueMax <= setValueMin)
  1088. {
  1089. return "第" + (i + 1) + "行," + "批量上限不能小于批量下限";
  1090. }
  1091. // 同AQL编码的上下限连续性校验(原有逻辑)
  1092. if (i > 0)
  1093. {
  1094. if (currentAqlCode.Equals(lastAqlCode, StringComparison.OrdinalIgnoreCase))
  1095. {
  1096. if (setValueMin != lastSetValueMax + 1)
  1097. {
  1098. return $"第{i + 1}行,AQL编码【{currentAqlCode}】连续性错误:上一行批量上限为{lastSetValueMax},当前行批量下限应为{lastSetValueMax + 1},实际为{setValueMin}";
  1099. }
  1100. }
  1101. }
  1102. // 【核心修改】判断是否需要插入主表
  1103. if (!aqlMainIdCache.ContainsKey(currentAqlCode))
  1104. {
  1105. // 1. 新AQL编码:生成主表ID,插入主表
  1106. mainTableId = Guid.NewGuid().ToString();
  1107. sql += $@"
  1108. INSERT INTO ICSInspectionRulesGroup
  1109. (ID, RulesCode, RulesName, Type, Enable, MUSER, MUSERName, MTIME, WorkPoint)
  1110. VALUES
  1111. ('{mainTableId}', '{currentAqlCode}', '{item["AQL名称"].ToStringExt()}', '1', 1, '{MUSER}', '{MUSERNAME}', GETDATE(), '{WorkPoint}');
  1112. ";
  1113. // 缓存AQL编码与主表ID的映射
  1114. aqlMainIdCache.Add(currentAqlCode, mainTableId);
  1115. }
  1116. else
  1117. {
  1118. // 2. 已有AQL编码:直接使用缓存的主表ID(不插入主表)
  1119. mainTableId = aqlMainIdCache[currentAqlCode];
  1120. }
  1121. // 【固定插入子表】无论AQL是否重复,都插入子表,关联主表ID
  1122. sql += $@"
  1123. INSERT INTO ICSInspectionRulesList
  1124. (ID, RulesID, SetValueMin, SetValueMax, SampleQuantity, Enable, MUSER, MUSERName, MTIME, WorkPoint, EATTRIBUTE1, EATTRIBUTE2)
  1125. VALUES
  1126. (NEWID(), '{mainTableId}', {setValueMin}, {setValueMax}, '{Convert.ToDecimal(item["取样数量"].ToString())}', '1', '{MUSER}', '{MUSERNAME}', GETDATE(), '{WorkPoint}', {setAllowNGQty}, '{AQLType}');
  1127. ";
  1128. // 更新连续性校验缓存
  1129. lastAqlCode = currentAqlCode;
  1130. lastSetValueMax = setValueMax;
  1131. }
  1132. // 执行SQL(注意:SqlHelper.CmdExecuteNonQuery需支持批量执行多行SQL)
  1133. if (SqlHelper.CmdExecuteNonQuery(sql) == 0)
  1134. {
  1135. return "导入失败";
  1136. }
  1137. returnValue = "true";
  1138. return returnValue;
  1139. }
  1140. catch (Exception ex)
  1141. {
  1142. throw new Exception(ex.Message);
  1143. }
  1144. }
  1145. public class TempInspectGuid
  1146. {
  1147. public string GroupCode { get; set; }
  1148. public string GUID { get; set; }
  1149. }
  1150. public DataTable GetMaterialCheckLog(string keyValue)
  1151. {
  1152. List<DbParameter> parameter = new List<DbParameter>();
  1153. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1154. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1155. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1156. var para = new { WorkPoint = WorkPoint };
  1157. string sql = @"SELECT DISTINCT
  1158. a.InvCode,
  1159. d.InvName,
  1160. d.InvStd,
  1161. REPLACE(d.ClassName, '', '') WLFL,
  1162. a.AsnCode,
  1163. a.InvBatcgNo,
  1164. a.InvBatcgQty,
  1165. a.VenCode,
  1166. c.VenName,
  1167. CASE WHEN e.EATTRIBUTE1='是' THEN '是' ELSE '否' END AS SFJL,
  1168. a.FirstCheckTime CHUJIANSHIJIAN,
  1169. a.Result,
  1170. a.IQCGroupHeaderResult ZZJG,
  1171. a.IQCGroupHeaderRemark ZZBZ,
  1172. a.IQCGroupHeaderUser,
  1173. a.IQCGroupHeaderTime,
  1174. BLXX.BRGDesc,
  1175. BLXX1.BadReasonDesc,
  1176. BLFL.BadDesc,
  1177. a.SQEEngineerResult SQEJG,
  1178. a.SQEEngineerRemark SQEBZ,
  1179. a.SQEEngineerUser,
  1180. a.SQEEngineerTime,
  1181. a.IQCHeaderResult ZGJG,
  1182. a.IQCHeaderRemark ZGBZ,
  1183. a.IQCHeaderUser,
  1184. a.IQCHeaderTime,
  1185. a.EATTRIBUTE1 SQEFA,
  1186. A.FinalResult ZZPD,
  1187. a.FinalUser,
  1188. a.FinalTime,
  1189. CASE WHEN a.Result='OK' OR (a.Result='NG' AND a.IsCheckComplete='是') THEN '是'
  1190. ELSE '否' END AS SFJA,
  1191. b.CheckAttr,
  1192. b.CheckAttrText,
  1193. b.CheckItemCode,
  1194. b.CheckItemName,
  1195. b.CheckWay,
  1196. b.CheckAqlName,
  1197. CONVERT(decimal(18, 2), b.SetValueMax) AS SetValueMax,
  1198. CONVERT(decimal(18, 2), b.SetValueMin) AS SetValueMin,
  1199. b.Unit,
  1200. CONVERT(decimal(18, 2), b.S1) AS S1,
  1201. CONVERT(decimal(18, 2), b.S2) AS S2,
  1202. CONVERT(decimal(18, 2), b.S3) AS S3,
  1203. CONVERT(decimal(18, 2), b.S4) AS S4,
  1204. CONVERT(decimal(18, 2), b.S5) AS S5,
  1205. CONVERT(decimal(18, 2), b.S6) AS S6,
  1206. CONVERT(decimal(18, 2), b.S7) AS S7,
  1207. CONVERT(decimal(18, 2), b.S8) AS S8,
  1208. CONVERT(decimal(18, 2), b.S9) AS S9,
  1209. CONVERT(decimal(18, 2), b.S10) AS S10,
  1210. B.AqlQty,B.GoodQty,B.NgQty,B.Result JYXJG,B.Remark JYXBZ,B.MUSER,B.MUSERName,B.MTIME
  1211. FROM IcsMatCheckResult a
  1212. left JOIN IcsMatCheckResultDetail b on a.CheckNo=b.CheckNo AND a.WorkPoint=b.WorkPoint
  1213. LEFT JOIN ICSVendor c on a.VenCode=c.VenCode AND a.WorkPoint=c.WorkPoint
  1214. LEFT JOIN ICSInventory d on a.InvCode=d.InvCode AND a.WorkPoint=d.WorkPoint
  1215. LEFT JOIN (
  1216. SELECT DISTINCT a.ASNCode,b.InvCode,a.EATTRIBUTE1,c.BatchCode,a.WorkPoint,bb.TransCode FROM ICSASNDetail a
  1217. LEFT JOIN ICSInventoryLot b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
  1218. LEFT JOIN ICSInventoryLotDetail bb on a.LotNo=bb.LotNo and a.WorkPoint=bb.WorkPoint
  1219. LEFT JOIN ICSExtension c on b.ExtensionID=c.ID and c.WorkPoint=b.WorkPoint
  1220. )e ON a.AsnCode=e.ASNCode and a.InvCode=e.InvCode and a.InvBatcgNo=e.BatchCode and a.WorkPoint=e.WorkPoint
  1221. LEFT JOIN (
  1222. SELECT DISTINCT a.OASNCode,b.InvCode,a.EATTRIBUTE1,c.BatchCode,a.WorkPoint,bb.TransCode FROM ICSOASNDetail a
  1223. LEFT JOIN ICSInventoryLot b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint
  1224. LEFT JOIN ICSInventoryLotDetail bb on a.LotNo=bb.LotNo and a.WorkPoint=bb.WorkPoint
  1225. LEFT JOIN ICSExtension c on b.ExtensionID=c.ID and c.WorkPoint=b.WorkPoint
  1226. )f ON a.AsnCode=f.OASNCode and a.InvCode=f.InvCode and a.InvBatcgNo=e.BatchCode and a.WorkPoint=e.WorkPoint
  1227. LEFT JOIN ICSBadReasonGroup BLXX ON BLXX.BRGCode=A.BCGCode
  1228. LEFT JOIN ICSBadReason BLXX1 ON BLXX1.BadReasonCode=A.BadReasonCode
  1229. LEFT JOIN ICSBadCode BLFL ON BLFL.BadCode=A.BRGCode
  1230. WHERE 1=1
  1231. and a.InvCode='{0}' AND a.CheckNo IN
  1232. (select TOP 10 CheckNo from IcsMatCheckResult
  1233. where InvCode='{0}' order by MTIME desc)
  1234. order by b.MTIME desc
  1235. ";
  1236. sql = string.Format(sql, keyValue, WorkPoint);
  1237. return Repository().FindDataSetBySql(sql.ToString(), parameter.ToArray()).Tables[0];
  1238. }
  1239. public DataTable GetBadReasonGroupPageList(string queryJson, ref Pagination pagination)
  1240. {
  1241. DataTable dt = new DataTable();
  1242. var queryParam = queryJson.ToJObject();
  1243. List<DbParameter> parameter = new List<DbParameter>();
  1244. //object Figure = GetDecimalDigits();
  1245. #region [SQL]
  1246. string sql = @"
  1247. select
  1248. a.*
  1249. from ICSBadReasonGroup a with(nolock)
  1250. where 1=1
  1251. {0}
  1252. <1>
  1253. <2>
  1254. ";
  1255. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  1256. //sql = string.Format(sql, Figure);
  1257. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  1258. #endregion
  1259. if (!string.IsNullOrWhiteSpace(queryJson))
  1260. {
  1261. if (!string.IsNullOrWhiteSpace(queryParam["BRGCode"].ToString()))
  1262. {
  1263. sql = sql.Replace("<1>", " and a.BRGCode like '%" + queryParam["BRGCode"].ToString() + "%' ");
  1264. }
  1265. else
  1266. {
  1267. sql = sql.Replace("<1>", " ");
  1268. }
  1269. if (!string.IsNullOrWhiteSpace(queryParam["BRGDesc"].ToString()))
  1270. {
  1271. sql = sql.Replace("<2>", " and a.BRGDesc like '%" + queryParam["BRGDesc"].ToString() + "%' ");
  1272. }
  1273. else
  1274. {
  1275. sql = sql.Replace("<2>", " ");
  1276. }
  1277. }
  1278. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  1279. {
  1280. sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  1281. // sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  1282. }
  1283. else
  1284. {
  1285. sql = sql.Replace("{0}", "");
  1286. }
  1287. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  1288. //{
  1289. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  1290. //}
  1291. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref pagination);
  1292. }
  1293. public DataTable ExportAllCheckItemGroup(string groupCode, string GroupName)
  1294. {
  1295. DataTable dt = new DataTable();
  1296. // var queryParam = queryJson.ToJObject();
  1297. List<DbParameter> parameter = new List<DbParameter>();
  1298. //object Figure = GetDecimalDigits();
  1299. #region [SQL]
  1300. string sql = @"
  1301. select
  1302. case when a.Enable=1 then '是'
  1303. else '否' end as EnableText
  1304. ,a.*
  1305. from ICSInspectionGroup a with(nolock)
  1306. where 1=1
  1307. {0}
  1308. <1>
  1309. <2>
  1310. --<3>
  1311. ";
  1312. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  1313. //sql = string.Format(sql, Figure);
  1314. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  1315. #endregion
  1316. if (!string.IsNullOrWhiteSpace(groupCode))
  1317. {
  1318. sql = sql.Replace("<1>", " and a.GroupCode like '%" + groupCode + "%' ");
  1319. }
  1320. else
  1321. {
  1322. sql = sql.Replace("<1>", " ");
  1323. }
  1324. if (!string.IsNullOrWhiteSpace(GroupName))
  1325. {
  1326. sql = sql.Replace("<2>", " and a.GroupName like '%" + GroupName + "%' ");
  1327. }
  1328. else
  1329. {
  1330. sql = sql.Replace("<2>", " ");
  1331. }
  1332. //if (!string.IsNullOrWhiteSpace(queryParam["Enable"].ToString()))
  1333. //{
  1334. // sql = sql.Replace("<3>", " and a.Enable =" + queryParam["Enable"].ToString() + " ");
  1335. //}
  1336. //else
  1337. //{
  1338. // sql = sql.Replace("<3>", " ");
  1339. //}
  1340. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  1341. {
  1342. sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  1343. // sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  1344. }
  1345. else
  1346. {
  1347. sql = sql.Replace("{0}", "");
  1348. }
  1349. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  1350. //{
  1351. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  1352. //}
  1353. return Repository().FindDataSetBySql(sql.ToString(), parameter.ToArray()).Tables[0];
  1354. }
  1355. public string ImportCheckItem(string savePath)
  1356. {
  1357. string returnValue = string.Empty;
  1358. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1359. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1360. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1361. SqlConnection conn = SqlHelper.GetDataCenterConn();
  1362. DataTable data = FileToExcel.ExcelToTable(savePath);
  1363. DateTime time = DateTime.Now;
  1364. //DataSet dsSave = new DataSet();
  1365. //dsSave.Tables.Add(data.Copy());
  1366. DateTime dtNow = DateTime.Now;
  1367. //dsSave.Tables[0].TableName = "IcsCheckingFixture";
  1368. ICSInspectionGroupEntity entity = new ICSInspectionGroupEntity();
  1369. List<ICSInspectionListEntity> list = new List<ICSInspectionListEntity>();
  1370. for (int i = 0; i < data.Rows.Count; i++)
  1371. {
  1372. var item = data.Rows[i];
  1373. if (i == 0)
  1374. {
  1375. if (item["检验类型编码"].ToStringExt() == "")
  1376. {
  1377. throw new Exception("第1行," + "检验类型编码为空");
  1378. }
  1379. if (item["检验类型名称"].ToStringExt() == "")
  1380. {
  1381. throw new Exception("第1行," + "检验类型名称为空");
  1382. }
  1383. entity.ID = Guid.NewGuid().ToString();
  1384. entity.MUSER = MUSER;
  1385. entity.MUSERName = MUSERNAME;
  1386. entity.MTIME = dtNow;
  1387. entity.WorkPoint = WorkPoint;
  1388. entity.GroupCode = item["检验类型编码"].ToStringExt();
  1389. entity.GroupName = item["检验类型名称"].ToStringExt();
  1390. entity.Enable = true;
  1391. }
  1392. if (item["检验项目代码"].ToStringExt() == "")
  1393. {
  1394. throw new Exception("第" + (i + 1) + "行," + "检验项目代码为空");
  1395. }
  1396. if (item["检验项目名称"].ToStringExt() == "")
  1397. {
  1398. throw new Exception("第" + (i + 1) + "行," + "检验项目名称为空");
  1399. }
  1400. if (item["最大值"].ToDecimal() <= 0)
  1401. {
  1402. throw new Exception("第" + (i + 1) + "行," + "最大值必须大于0");
  1403. }
  1404. if (item["最小值"].ToDecimal() <= 0)
  1405. {
  1406. throw new Exception("第" + (i + 1) + "行," + "最小值必须大于0");
  1407. }
  1408. //if (item["单位"].ToStringExt() == "")
  1409. //{
  1410. // throw new Exception("第" + (i + 1) + "行," + "检验项目名称为空");
  1411. //}
  1412. ICSInspectionListEntity detail = new ICSInspectionListEntity();
  1413. detail.ID = Guid.NewGuid().ToString();
  1414. detail.GroupID = entity.ID;
  1415. detail.ListCode = item["检验项目代码"].ToStringExt();
  1416. detail.ListName = item["检验项目名称"].ToStringExt();
  1417. detail.Unit = item["单位"].ToStringExt();
  1418. detail.SetValueMax = item["最大值"].ToDecimal();
  1419. detail.SetValueMin = item["最小值"].ToDecimal();
  1420. detail.Enable = true;
  1421. detail.MUSER = MUSER;
  1422. detail.MUSERName = MUSERNAME;
  1423. detail.MTIME = dtNow;
  1424. detail.WorkPoint = WorkPoint;
  1425. if (detail.SetValueMax <= 0 || detail.SetValueMin <= 0)
  1426. {
  1427. throw new Exception("第" + (i + 1) + "行," + "值必须大于0");
  1428. }
  1429. if (detail.SetValueMax <= detail.SetValueMin)
  1430. {
  1431. throw new Exception("第" + (i + 1) + "行," + "最大值必须大于最小值");
  1432. }
  1433. list.Add(detail);
  1434. }
  1435. if (list.Count == 0)
  1436. {
  1437. throw new Exception("没有导入数据");
  1438. }
  1439. if (list != null && list.Count > 0)
  1440. {
  1441. if (list.Select(x => x.ListCode).Distinct().Count() != list.Count)
  1442. {
  1443. throw new Exception("检验项目代码重复");
  1444. }
  1445. }
  1446. var result = MsSqlData.Insert<ICSInspectionGroupEntity>(entity);
  1447. if (!result)
  1448. {
  1449. throw new Exception("导入失败");
  1450. }
  1451. result = MsSqlData.Insert<ICSInspectionListEntity>(list);
  1452. if (!result)
  1453. {
  1454. throw new Exception("导入失败");
  1455. }
  1456. returnValue = "true";
  1457. return returnValue;
  1458. }
  1459. public ICSInventoryInspectionListDto GetItem2CheckItem(string keyValue)
  1460. {
  1461. var returnValue = new ICSInventoryInspectionListDto();
  1462. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1463. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1464. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1465. var sql = @"select
  1466. a.*
  1467. from
  1468. (
  1469. select
  1470. a.ID
  1471. ,c.InvCode
  1472. ,c.InvName
  1473. ,a.ListCode
  1474. ,a.ListName
  1475. ,b.EATTRIBUTE1 as CheckAttr --
  1476. ,( select t.label from V_QuerySysEnumItem t where t.value=b.EATTRIBUTE1 and t.F_EnCode='CheckAttr'
  1477. ) as CheckAttrText
  1478. ,a.SetValueMax
  1479. ,a.SetValueMin
  1480. ,a.Unit
  1481. ,a.Enable
  1482. ,a.MUSER
  1483. ,a.MUSERName
  1484. ,a.MTIME
  1485. ,a.EATTRIBUTE1
  1486. ,a.EATTRIBUTE2
  1487. ,a.EATTRIBUTE3
  1488. ,a.EATTRIBUTE5
  1489. ,a.EATTRIBUTE6
  1490. ,a.EATTRIBUTE4
  1491. ,d.Name as Type,case when a.EATTRIBUTE4='true' then '是' else '否' end CEATTRIBUTE4
  1492. , case when a.Enable='1' then '是' else '否' end CEnable
  1493. from ICSInventoryInspectionList a with(nolock)
  1494. left join ICSInventoryInspectionGroup b with(nolock) on a.InvGroupID=b.ID
  1495. left join ICSInventory c with(nolock) on b.InvCode=c.InvCode
  1496. LEFT JOIN ICSType d ON a.WorkPoint=d.WorkPoint AND d.TableCode='ICSInventoryInspectionList' AND d.ColumnCode='EATTRIBUTE6' AND a.EATTRIBUTE6=d.Code AND d.Enable='1'
  1497. where 1=1
  1498. and a.WorkPoint=@WorkPoint
  1499. ) a
  1500. where 1=1
  1501. and a.ID=@Id";
  1502. var para = new
  1503. {
  1504. ID = keyValue,
  1505. WorkPoint = WorkPoint,
  1506. };
  1507. returnValue = MsSqlData.Query<ICSInventoryInspectionListDto>(sql, para).FirstOrDefault();
  1508. return returnValue;
  1509. }
  1510. public string SaveItem2CheckItemSingle(string keyValue)
  1511. {
  1512. string returnValue = string.Empty;
  1513. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1514. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1515. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1516. try
  1517. {
  1518. var dtNow = DateTime.Now;
  1519. var model = JsonConvert.DeserializeObject<ICSInventoryInspectionListDto>(keyValue);
  1520. if (model == null)
  1521. {
  1522. throw new Exception("传入参数错误");
  1523. }
  1524. //修改
  1525. var entity = MsSqlData.Get<ICSInventoryInspectionListEntity>(model.ID);
  1526. if (entity == null)
  1527. {
  1528. throw new Exception("当前数据不存在");
  1529. }
  1530. entity.ListName = model.ListName;
  1531. entity.Unit = model.Unit;
  1532. entity.SetValueMax = model.SetValueMax;
  1533. entity.SetValueMin = model.SetValueMin;
  1534. entity.Enable = model.Enable;
  1535. entity.EATTRIBUTE1 = model.EATTRIBUTE1;
  1536. entity.EATTRIBUTE2 = model.EATTRIBUTE2;
  1537. entity.EATTRIBUTE3 = model.EATTRIBUTE3;
  1538. entity.EATTRIBUTE4 = model.EATTRIBUTE4;
  1539. entity.EATTRIBUTE5 = model.EATTRIBUTE5;
  1540. entity.EATTRIBUTE6 = model.EATTRIBUTE6;
  1541. entity.MUSER = MUSER;
  1542. entity.MUSERName = MUSERNAME;
  1543. entity.MTIME = dtNow;
  1544. var result = MsSqlData.Update<ICSInventoryInspectionListEntity>(entity);
  1545. if (!result)
  1546. {
  1547. returnValue = "修改失败";
  1548. }
  1549. }
  1550. catch (Exception ex)
  1551. {
  1552. returnValue = ex.Message;
  1553. }
  1554. return returnValue;
  1555. }
  1556. public DataTable ExportAllMaterialInStorageCheck(string invCode, string invName, string isCheck, string StartDate, string EndDate,
  1557. string checkStartDate, string CheckEndDate)
  1558. {
  1559. DataTable dt = new DataTable();
  1560. //var queryParam = queryJson.ToJObject();
  1561. List<DbParameter> parameter = new List<DbParameter>();
  1562. //object Figure = GetDecimalDigits();
  1563. #region [SQL]
  1564. string sql = @"
  1565. select a.InvCode as
  1566. ,a.InvName as
  1567. ,a.DNCode as
  1568. ,a.InvBatcgNo as
  1569. ,a.DNQuantity as
  1570. ,a.DHDate as
  1571. ,a.VenCode as
  1572. ,a.VenName as
  1573. ,a.ASNCode as
  1574. ,a.IsUrgentItem as
  1575. ,a.IsCheck as
  1576. ,a.Result as
  1577. ,a.CheckDate as
  1578. ,a.WHCode as
  1579. from
  1580. (
  1581. select
  1582. distinct
  1583. max(b.ID) DetailId --
  1584. ,Max(c.ID) LotNoId --ID
  1585. ,c.InvCode
  1586. ,inv.InvName
  1587. ,c1.BatchCode as InvBatcgNo --
  1588. ,sum(b.DNQuantity) DNQuantity --
  1589. ,max(a.VenCode) VenCode --
  1590. ,max(e.VenName ) VenName --
  1591. ,a.ASNCode
  1592. ,max(b.EATTRIBUTE1) as IsUrgentItem --
  1593. ,max(inv.InvUnit) InvUnit
  1594. ,sum(c.Quantity) Quantity
  1595. ,max(c2.FileName) OutReport
  1596. ,max(c2.FilePath) FilePath
  1597. ,max(g.id) CheckID
  1598. ,case when max(g.CheckNo) is null then '否'else '是' end as IsCheck
  1599. ,max(g.Result) Result
  1600. ,max(g.FirstCheckTime) CheckDate
  1601. ,max(g.WHCode) WHCode
  1602. ,max(l.CreateDateTime) DHDate
  1603. ,max(l.DNCode) DNCode
  1604. ,'1' as DocType
  1605. from ICSASN a with(nolock)
  1606. left join ICSASNDetail b with(nolock) on a.ASNCode=b.ASNCode and a.WorkPoint=b.WorkPoint
  1607. left join ICSInventoryLot c with(nolock) on b.LotNo=c.LotNo and b.WorkPoint=b.WorkPoint
  1608. left join ICSInventoryLotDetail cc with(nolock) on b.lotno=cc.lotno and cc.WorkPoint=c.WorkPoint
  1609. left join ICSExtension c1 with(nolock) on c.ExtensionID=c1.ID
  1610. left join (
  1611. select *
  1612. from
  1613. (
  1614. select t.*
  1615. ,row_number() over(partition by t.ASNCode,t.BatchCode,t.invcode order by t.CerateTime desc) RowSeq
  1616. from ICSASNShippingReport t with(nolock)
  1617. ) t where t.RowSeq=1
  1618. ) c2 on a.ASNCode=c2.ASNCode and c1.BatchCode=c2.BatchCode and c.invcode=c2.invcode
  1619. left join ICSInventory inv with(nolock) on c.InvCode=inv.InvCode and c.WorkPoint=inv.WorkPoint
  1620. left join ICSVendor e with(nolock) on a.VenCode=e.VenCode and a.WorkPoint=e.WorkPoint
  1621. left join IcsMatCheckResult g with(nolock) on c.InvCode=g.InvCode and c1.BatchCode=g.InvBatcgNo and a.ASNCode=g.AsnCode
  1622. left join (SELECT ASNCode,InvCode,ExtensionID,max(CreateDateTime) CreateDateTime,max( t.DNCode) DNCode,PODetailID
  1623. from ICSDeliveryNotice t with(nolock) GROUP BY ASNCode,InvCode,ExtensionID,PODetailID ) l
  1624. on a.ASNCode=l.ASNCode and c.InvCode=l.InvCode and l.PODetailID=cc.TransCode+'~'+cc.TransSequence
  1625. where 1=1
  1626. {0}
  1627. and inv.InvIQC=1
  1628. and b.lotno not in
  1629. ( select a.LotNo from ICSASNDetail a
  1630. inner join ICSWareHouseLotInfo b on a.lotno=b.lotno
  1631. left join ICSInspection c on c.LotNo=a.LotNo
  1632. where c.lotno is null
  1633. )
  1634. group by c.InvCode,inv.InvName ,c1.BatchCode,a.ASNCode
  1635. union all
  1636. select
  1637. distinct
  1638. max(b.ID) DetailId --
  1639. ,Max(c.ID) LotNoId --ID
  1640. ,c.InvCode
  1641. ,d.InvName
  1642. ,c1.BatchCode as InvBatcgNo --
  1643. ,sum(b.ODNQuantity) DNQuantity --
  1644. ,max(a.VenCode) VenCode --
  1645. ,max(e.VenName ) VenName --
  1646. ,a.OASNCode as ASNCode
  1647. ,max(b.EATTRIBUTE1) as IsUrgentItem --
  1648. ,max(d.InvUnit) InvUnit
  1649. ,sum(c.Quantity) Quantity
  1650. ,'' as OutReport
  1651. ,'' as FilePath
  1652. ,max(g.id) CheckID
  1653. ,case when max(g.CheckNo) is null then '否'else '是' end as IsCheck
  1654. ,max(g.Result) Result
  1655. ,max(g.FirstCheckTime) CheckDate
  1656. ,max(g.WHCode) WHCode
  1657. ,max(l.CreateDateTime) DHDate
  1658. ,max(l.DNCode) DNCode
  1659. ,'2' as DocType
  1660. from ICSOASN a with(nolock)
  1661. left join ICSOASNDetail b with(nolock) on a.OASNCode=b.OASNCode
  1662. left join ICSInventoryLot c with(nolock) on b.LotNo=c.LotNo
  1663. left join ICSInspection wl with(nolock) on b.LotNo=wl.LotNo and b.WorkPoint=wl.WorkPoint
  1664. left join ICSExtension c1 with(nolock) on c.ExtensionID=c1.ID
  1665. left join ICSInventory d with(nolock) on c.InvCode=d.InvCode
  1666. left join ICSVendor e with(nolock) on a.VenCode=e.VenCode
  1667. left join IcsMatCheckResult g with(nolock) on c.InvCode=g.InvCode and c1.BatchCode=g.InvBatcgNo and a.OASNCode=g.AsnCode
  1668. left join (SELECT OASNCode,InvCode,ExtensionID,max(CreateDateTime) CreateDateTime,max( t.ODNCode) DNCode
  1669. from ICSODeliveryNotice t with(nolock) GROUP BY OASNCode,InvCode,ExtensionID )l on a.OASNCode=l.OASNCode and c.InvCode=l.InvCode and l.ExtensionID=c.ExtensionID
  1670. where 1=1
  1671. and d.InvIQC=1
  1672. and b.lotno not in
  1673. (select a.LotNo from ICSOASNDetail a
  1674. inner join ICSWareHouseLotInfo b on a.lotno=b.lotno
  1675. left join ICSInspection c on c.LotNo=a.LotNo
  1676. where c.lotno is null
  1677. )
  1678. {0}
  1679. group by c.InvCode,d.InvName ,c1.BatchCode,a.OASNCode
  1680. ) a
  1681. where 1=1 AND a.DNQuantity>0
  1682. <1>
  1683. <2>
  1684. <3>
  1685. <4>
  1686. --<5>
  1687. --<6>
  1688. --<7>
  1689. --<8>
  1690. <9>
  1691. <10>
  1692. <11>
  1693. ";
  1694. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  1695. //sql = string.Format(sql, Figure);
  1696. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  1697. #endregion
  1698. if (!string.IsNullOrWhiteSpace(invCode))
  1699. {
  1700. sql = sql.Replace("<1>", " and a.InvCode like '%" + invCode + "%' ");
  1701. }
  1702. else
  1703. {
  1704. sql = sql.Replace("<1>", " ");
  1705. }
  1706. if (!string.IsNullOrWhiteSpace(invName))
  1707. {
  1708. sql = sql.Replace("<2>", " and a.InvName like '%" + invName + "%' ");
  1709. }
  1710. else
  1711. {
  1712. sql = sql.Replace("<2>", " ");
  1713. }
  1714. if (!string.IsNullOrWhiteSpace(StartDate))
  1715. {
  1716. sql = sql.Replace("<3>", " and a.DHDate>='" + StartDate + " 00:00:00' ");
  1717. }
  1718. else
  1719. {
  1720. sql = sql.Replace("<3>", " ");
  1721. }
  1722. if (!string.IsNullOrWhiteSpace(EndDate))
  1723. {
  1724. sql = sql.Replace("<4>", " and a.DHDate<='" + EndDate + " 23:59:59' ");
  1725. }
  1726. else
  1727. {
  1728. sql = sql.Replace("<4>", " ");
  1729. }
  1730. //if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString()))
  1731. //{
  1732. // sql = sql.Replace("<5>", " and a.ASNCode like '%" + queryParam["ASNCode"].ToString() + "%' ");
  1733. //}
  1734. //else
  1735. //{
  1736. // sql = sql.Replace("<5>", " ");
  1737. //}
  1738. //if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString()))
  1739. //{
  1740. // sql = sql.Replace("<6>", " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' ");
  1741. //}
  1742. //else
  1743. //{
  1744. // sql = sql.Replace("<6>", " ");
  1745. //}
  1746. //if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString()))
  1747. //{
  1748. // sql = sql.Replace("<7>", " and a.VenName like '%" + queryParam["VenName"].ToString() + "%' ");
  1749. //}
  1750. //else
  1751. //{
  1752. // sql = sql.Replace("<7>", " ");
  1753. //}
  1754. //if (!string.IsNullOrWhiteSpace(queryParam["InvBatcgNo"].ToString()))
  1755. //{
  1756. // sql = sql.Replace("<8>", " and a.InvBatcgNo like '%" + queryParam["InvBatcgNo"].ToString() + "%' ");
  1757. //}
  1758. //else
  1759. //{
  1760. // sql = sql.Replace("<8>", " ");
  1761. //}
  1762. if (!string.IsNullOrWhiteSpace(isCheck))
  1763. {
  1764. sql = sql.Replace("<9>", " and a.IsCheck='" + isCheck + "' ");
  1765. }
  1766. else
  1767. {
  1768. sql = sql.Replace("<9>", " ");
  1769. }
  1770. if (!string.IsNullOrWhiteSpace(checkStartDate))
  1771. {
  1772. sql = sql.Replace("<10>", " and a.CheckDate>='" + checkStartDate + " 00:00:00' ");
  1773. }
  1774. else
  1775. {
  1776. sql = sql.Replace("<10>", " ");
  1777. }
  1778. if (!string.IsNullOrWhiteSpace(CheckEndDate))
  1779. {
  1780. sql = sql.Replace("<11>", " and a.CheckDate<='" + CheckEndDate + " 23:59:59' ");
  1781. }
  1782. else
  1783. {
  1784. sql = sql.Replace("<11>", " ");
  1785. }
  1786. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  1787. //{
  1788. sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  1789. // // sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  1790. //}
  1791. //else
  1792. //{
  1793. // sql = sql.Replace("{0}", "");
  1794. //}
  1795. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  1796. //{
  1797. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  1798. //}
  1799. return Repository().FindDataSetBySql(sql.ToString(), parameter.ToArray()).Tables[0];
  1800. }
  1801. public string DeleteMatCheck(string keyValue)
  1802. {
  1803. string returnValue = string.Empty;
  1804. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1805. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1806. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1807. try
  1808. {
  1809. var model = JsonConvert.DeserializeObject<IcsMatCheckResultDto>(keyValue);
  1810. if (model == null)
  1811. {
  1812. throw new Exception("数据获取失败");
  1813. }
  1814. var para = new
  1815. {
  1816. WorkPoint = WorkPoint,
  1817. InvCode = model.InvCode,
  1818. AsnCode = model.AsnCode,
  1819. InvBatcgNo = model.InvBatcgNo,
  1820. };
  1821. string sql = @" select * from [IcsMatCheckResult] a with(nolock)
  1822. where InvCode=@InvCode
  1823. and AsnCode=@AsnCode
  1824. and InvBatcgNo=@InvBatcgNo and a.WorkPoint=@WorkPoint ";
  1825. var entityList = MsSqlData.Query<IcsMatCheckResult>(sql, para).ToList();
  1826. if (entityList == null || entityList.Count == 0)
  1827. {
  1828. throw new Exception("当前选择数据不能查到对应检验记录");
  1829. }
  1830. foreach (var item in entityList)
  1831. {
  1832. //var count = MsSqlData.ExecuteScalar(" select count(1) from IcsCheckingFixtureTransfer with(nolock) where CheckFixtureNo='" + item.CheckFixtureNo + "'").ToInt();
  1833. //if (count > 0)
  1834. //{
  1835. // throw new Exception("当前检具已经存在履历,不能删除");
  1836. //}
  1837. Pagination pagination = null;
  1838. var invLotNos = GetMaterialInStorageCheckDetailList(item.AsnCode, item.InvBatcgNo, item.InvCode, ref pagination);
  1839. //删除检验主表记录
  1840. if (invLotNos != null && invLotNos.Rows.Count > 0)
  1841. {
  1842. var lotNos = invLotNos.Select("1=1").Select(x => x["LotNo"].ToString());
  1843. DeleteInspection(lotNos, para);
  1844. }
  1845. var result = MsSqlData.Delete<IcsMatCheckResult>(entityList);
  1846. if (!result)
  1847. {
  1848. throw new Exception("删除失败");
  1849. }
  1850. var sql2 = @" delete from IcsMatCheckResultDetail where CheckNo='" + item.CheckNo + "' and WorkPoint=@WorkPoint ";
  1851. var count = MsSqlData.Execute(sql2, para);
  1852. //if (count == 0)
  1853. //{
  1854. // throw new Exception("删除失败");
  1855. //}
  1856. }
  1857. }
  1858. catch (Exception ex)
  1859. {
  1860. returnValue = ex.Message;
  1861. }
  1862. return returnValue;
  1863. }
  1864. public string IQC1Back(string keyValue)
  1865. {
  1866. string returnValue = string.Empty;
  1867. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  1868. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  1869. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  1870. try
  1871. {
  1872. var dtNow = DateTime.Now;
  1873. var model = JsonConvert.DeserializeObject<IcsMatCheckResultDto>(keyValue);
  1874. if (model == null)
  1875. {
  1876. throw new Exception("传入参数错误");
  1877. }
  1878. var entity = MsSqlData.Get<IcsMatCheckResult>(model.ID);
  1879. if (entity == null)
  1880. {
  1881. throw new Exception("当前数据不存在");
  1882. }
  1883. var para = new
  1884. {
  1885. WorkPoint = WorkPoint,
  1886. };
  1887. Pagination pagination = null;
  1888. var invLotNos = GetMaterialInStorageCheckDetailList(entity.AsnCode, entity.InvBatcgNo, entity.InvCode, ref pagination);
  1889. var result = true;
  1890. //return "";
  1891. switch (model.BackType)
  1892. {
  1893. case "IQC1Back":
  1894. if (!entity.SQEEngineerResult.IsNullOrEmpty())
  1895. {
  1896. throw new Exception("当前数据已经被SQE判定");
  1897. }
  1898. if (entity.IQCGroupHeaderResult.IsNullOrEmpty())
  1899. {
  1900. throw new Exception("当前数据还没有被判定");
  1901. }
  1902. //删除检验主表记录
  1903. if (invLotNos != null && invLotNos.Rows.Count > 0)
  1904. {
  1905. var lotNos = invLotNos.Select("1=1").Select(x => x["LotNo"].ToString());
  1906. DeleteInspection(lotNos, para);
  1907. }
  1908. //删除当前检验角色检验记录
  1909. entity.IQCGroupHeaderResult = null;
  1910. entity.IQCGroupHeaderRemark = null;
  1911. entity.IQCGroupHeaderUser = null;
  1912. entity.IQCGroupHeaderTime = null;
  1913. break;
  1914. case "SQEBack":
  1915. if (!entity.IQCHeaderResult.IsNullOrEmpty())
  1916. {
  1917. throw new Exception("当前数据已经被IQC主管判定");
  1918. }
  1919. if (!entity.FinalResult.IsNullOrEmpty())
  1920. {
  1921. throw new Exception("当前数据已经被追最终判定");
  1922. }
  1923. if (entity.SQEEngineerResult.IsNullOrEmpty())
  1924. {
  1925. throw new Exception("当前数据还没有被判定");
  1926. }
  1927. //删除检验主表记录
  1928. if (invLotNos != null && invLotNos.Rows.Count > 0)
  1929. {
  1930. var lotNos = invLotNos.Select("1=1").Select(x => x["LotNo"].ToString());
  1931. DeleteInspection(lotNos, para);
  1932. }
  1933. //删除当前检验角色检验记录
  1934. entity.SQEEngineerResult = null;
  1935. entity.SQEEngineerRemark = null;
  1936. entity.SQEEngineerUser = null;
  1937. entity.SQEEngineerTime = null;
  1938. entity.EATTRIBUTE1 = null;
  1939. break;
  1940. case "IQC2Back":
  1941. if (!entity.FinalResult.IsNullOrEmpty())
  1942. {
  1943. throw new Exception("当前数据已经被追最终判定");
  1944. }
  1945. if (entity.IQCHeaderResult.IsNullOrEmpty())
  1946. {
  1947. throw new Exception("当前数据还没有被判定");
  1948. }
  1949. //删除检验主表记录
  1950. if (invLotNos != null && invLotNos.Rows.Count > 0)
  1951. {
  1952. var lotNos = invLotNos.Select("1=1").Select(x => x["LotNo"].ToString());
  1953. DeleteInspection(lotNos, para);
  1954. }
  1955. //删除当前检验角色检验记录
  1956. entity.IQCHeaderResult = null;
  1957. entity.IQCHeaderRemark = null;
  1958. entity.IQCHeaderUser = null;
  1959. entity.IQCHeaderTime = null;
  1960. break;
  1961. case "FinalJudgeBack":
  1962. if (entity.FinalResult.IsNullOrEmpty())
  1963. {
  1964. throw new Exception("当前数据还没有被最终判定");
  1965. }
  1966. //删除检验主表记录
  1967. if (invLotNos != null && invLotNos.Rows.Count > 0)
  1968. {
  1969. var lotNos = invLotNos.Select("1=1").Select(x => x["LotNo"].ToString());
  1970. DeleteInspection(lotNos, para);
  1971. }
  1972. //删除当前检验角色检验记录
  1973. entity.FinalUser = null;
  1974. entity.FinalResult = null;
  1975. entity.FinalTime = null;
  1976. entity.GoodQty = 0;
  1977. entity.NgQty = 0;
  1978. break;
  1979. default:
  1980. break;
  1981. }
  1982. entity.MUSER = MUSER;
  1983. entity.MUSERName = MUSERNAME;
  1984. entity.MTIME = dtNow;
  1985. entity.IsCheckComplete = null;
  1986. result = MsSqlData.Update<IcsMatCheckResult>(entity);
  1987. if (!result)
  1988. {
  1989. returnValue = "修改失败";
  1990. }
  1991. }
  1992. catch (Exception ex)
  1993. {
  1994. returnValue = ex.Message;
  1995. }
  1996. return returnValue;
  1997. }
  1998. private void DeleteInspection(IEnumerable<string> lotNos, object para)
  1999. {
  2000. var isInstorageSql = @"select count(1) from ICSWareHouseLotInfo a with(nolock) where a.LotNo in ('" + string.Join("','", lotNos) + "') and WorkPoint=@WorkPoint";
  2001. var count = MsSqlData.ExecuteScalar(isInstorageSql, para).ToInt();
  2002. if (count > 0)
  2003. {
  2004. throw new Exception("当前检验单号对应条码已经入库");
  2005. }
  2006. var sql = @"delete from ICSInspection where LotNo in ('" + string.Join("','", lotNos) + "') and WorkPoint=@WorkPoint";
  2007. var sql2 = @"delete FROM ICSDeliveryNotice WHERE EATTRIBUTE1 in ('" + string.Join("','", lotNos) + "') and WorkPoint=@WorkPoint";
  2008. var aa = MsSqlData.Execute(sql, para);
  2009. aa = MsSqlData.Execute(sql2, para);
  2010. }
  2011. public DataTable ExportMaterialInStorageFinalList(string invCode, string invName, string isCheckComplete, string startDate, string endDate, string aSNCode
  2012. , string venCode, string venName, string invBatcgNo, string juegeProgess, string bcgCode)
  2013. {
  2014. DataTable dt = new DataTable();
  2015. List<DbParameter> parameter = new List<DbParameter>();
  2016. //object Figure = GetDecimalDigits();
  2017. #region [SQL]
  2018. string sql = @"
  2019. select
  2020. a.ASNCode
  2021. ,InvCode
  2022. ,InvName
  2023. ,InvBatcgNo
  2024. ,InvBatcgQty
  2025. ,VenCode
  2026. ,VenName
  2027. ,a.IQCGroupHeaderResult IQC组长判定
  2028. ,a.IQCHeaderResult IQC主管判定
  2029. ,a.SQEEngineerResult SQE工程师判定
  2030. ,a.FinalResult
  2031. ,a.EATTRIBUTE1 SQE处理方案
  2032. ,a.DHDate
  2033. ,a.IQCGroupHeaderUser IQC组长判定人员
  2034. ,a.IQCGroupHeaderTime IQC组长判定时间
  2035. ,a.IQCHeaderUser IQC主管判定人员
  2036. ,a.IQCHeaderTime IQC主管判定时间
  2037. ,a.SQEEngineerUser SQE工程师判定人员
  2038. ,a.SQEEngineerTime SQE工程师判定时间
  2039. ,a.FinalUser
  2040. ,a.FinalTime
  2041. ,a.BcgDesc
  2042. ,a.HasReturnItem 退
  2043. ,a.Urgent
  2044. ,a.FirstCheckUser
  2045. ,a.FirstCheckTime
  2046. from
  2047. (
  2048. select
  2049. distinct
  2050. a.ID
  2051. ,a.CheckNo
  2052. ,a.AsnCode ASNCode
  2053. ,a.InvCode
  2054. ,b.InvName
  2055. ,a.InvBatcgNo
  2056. ,a.InvBatcgQty
  2057. ,a.VenCode
  2058. ,c.VenName
  2059. ,c2.FileName OutReport --
  2060. ,c2.FilePath
  2061. ,a.IQCGroupHeaderResult
  2062. ,a.IQCHeaderResult
  2063. ,a.SQEEngineerResult
  2064. ,a.FinalResult
  2065. ,a.IsCheckComplete
  2066. ,a.EATTRIBUTE1
  2067. ,a.EATTRIBUTE3 CheckDate
  2068. ,case when l.CreateDateTime is not null then l.CreateDateTime
  2069. when l2.CreateDateTime is not null then l2.CreateDateTime
  2070. else null end as DHDate
  2071. ,a.IQCGroupHeaderUser
  2072. ,a.IQCGroupHeaderTime
  2073. ,a.IQCHeaderUser
  2074. ,a.IQCHeaderTime
  2075. ,a.SQEEngineerUser
  2076. ,a.SQEEngineerTime
  2077. ,a.FinalUser
  2078. ,a.FinalTime
  2079. ,a.BRGCode
  2080. ,bcg.BcgDesc
  2081. ,a.HasReturnItem
  2082. ,a.Urgent
  2083. ,a.FirstCheckUser
  2084. ,a.FirstCheckTime
  2085. ,a.WgNgFile
  2086. from IcsMatCheckResult a with(nolock)
  2087. left join ICSBadCodeGroup bcg with(nolock) on a.BRGCode=bcg.bcgcode and a.WorkPoint=bcg.WorkPoint
  2088. left join ICSInventory b with(nolock) on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  2089. left join ICSVendor c with(nolock) on a.VenCode=c.VenCode and a.WorkPoint=c.WorkPoint
  2090. left join (
  2091. select *
  2092. from
  2093. (
  2094. select t.*
  2095. ,row_number() over(partition by t.ASNCode,t.BatchCode,t.invcode order by t.CerateTime desc) RowSeq
  2096. from ICSASNShippingReport t with(nolock)
  2097. ) t where t.RowSeq=1
  2098. ) c2 on a.ASNCode=c2.ASNCode and a.InvBatcgNo=c2.BatchCode and a.invcode=c2.invcode
  2099. left join ICSDeliveryNotice l with(nolock) on a.ASNCode=l.ASNCode
  2100. left join ICSODeliveryNotice l2 with(nolock) on a.ASNCode=l2.OASNCode
  2101. where 1=1
  2102. {0}
  2103. and a.Result='NG'
  2104. ) a
  2105. where 1=1
  2106. --and a.AsnCode=''
  2107. --order by a.CheckNo
  2108. <1>
  2109. <2>
  2110. <3>
  2111. <4>
  2112. <5>
  2113. <6>
  2114. <7>
  2115. <8>
  2116. <9>
  2117. <10>
  2118. <11>
  2119. ";
  2120. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  2121. //sql = string.Format(sql, Figure);
  2122. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  2123. #endregion
  2124. if (!string.IsNullOrWhiteSpace(invCode))
  2125. {
  2126. sql = sql.Replace("<1>", " and a.InvCode like '%" + invCode + "%' ");
  2127. }
  2128. else
  2129. {
  2130. sql = sql.Replace("<1>", " ");
  2131. }
  2132. if (!string.IsNullOrWhiteSpace(invName))
  2133. {
  2134. sql = sql.Replace("<2>", " and a.InvName like '%" + invName + "%' ");
  2135. }
  2136. else
  2137. {
  2138. sql = sql.Replace("<2>", " ");
  2139. }
  2140. if (!string.IsNullOrWhiteSpace(startDate))
  2141. {
  2142. sql = sql.Replace("<3>", " and a.DHDate>='" + startDate + " 00:00:00' ");
  2143. }
  2144. else
  2145. {
  2146. sql = sql.Replace("<3>", " ");
  2147. }
  2148. if (!string.IsNullOrWhiteSpace(endDate))
  2149. {
  2150. sql = sql.Replace("<4>", " and a.DHDate<='" + endDate + " 23:59:59' ");
  2151. }
  2152. else
  2153. {
  2154. sql = sql.Replace("<4>", " ");
  2155. }
  2156. if (!string.IsNullOrWhiteSpace(aSNCode))
  2157. {
  2158. sql = sql.Replace("<5>", " and a.ASNCode like '%" + aSNCode + "%' ");
  2159. }
  2160. else
  2161. {
  2162. sql = sql.Replace("<5>", " ");
  2163. }
  2164. if (!string.IsNullOrWhiteSpace(venCode))
  2165. {
  2166. sql = sql.Replace("<6>", " and a.VenCode like '%" + venCode + "%' ");
  2167. }
  2168. else
  2169. {
  2170. sql = sql.Replace("<6>", " ");
  2171. }
  2172. if (!string.IsNullOrWhiteSpace(venName))
  2173. {
  2174. sql = sql.Replace("<7>", " and a.VenName like '%" + venName + "%' ");
  2175. }
  2176. else
  2177. {
  2178. sql = sql.Replace("<7>", " ");
  2179. }
  2180. if (!string.IsNullOrWhiteSpace(invBatcgNo))
  2181. {
  2182. sql = sql.Replace("<8>", " and a.InvBatcgNo like '%" + invBatcgNo + "%' ");
  2183. }
  2184. else
  2185. {
  2186. sql = sql.Replace("<8>", " ");
  2187. }
  2188. if (!string.IsNullOrWhiteSpace(isCheckComplete))
  2189. {
  2190. if (isCheckComplete == "是")
  2191. sql = sql.Replace("<9>", " and a.IsCheckComplete='" + isCheckComplete + "' ");
  2192. else
  2193. sql = sql.Replace("<9>", " and a.IsCheckComplete is null ");
  2194. }
  2195. else
  2196. {
  2197. sql = sql.Replace("<9>", " ");
  2198. }
  2199. if (!string.IsNullOrWhiteSpace(juegeProgess))
  2200. {
  2201. var aa = juegeProgess;
  2202. if (aa == "1")
  2203. {
  2204. sql = sql.Replace("<10>", " and a.IQCGroupHeaderResult is null ");
  2205. }
  2206. if (aa == "2")
  2207. {
  2208. sql = sql.Replace("<10>", " and a.IQCGroupHeaderResult is not null ");
  2209. }
  2210. if (aa == "3")
  2211. {
  2212. sql = sql.Replace("<10>", " and a.SQEEngineerResult is null ");
  2213. }
  2214. if (aa == "4")
  2215. {
  2216. sql = sql.Replace("<10>", " and a.SQEEngineerResult is not null ");
  2217. }
  2218. if (aa == "5")
  2219. {
  2220. sql = sql.Replace("<10>", " and a.IQCHeaderResult is null ");
  2221. }
  2222. if (aa == "6")
  2223. {
  2224. sql = sql.Replace("<10>", " and a.IQCHeaderResult is not null ");
  2225. }
  2226. if (aa == "7")
  2227. {
  2228. sql = sql.Replace("<10>", " and a.FinalResult is null ");
  2229. }
  2230. }
  2231. else
  2232. {
  2233. sql = sql.Replace("<10>", " ");
  2234. }
  2235. if (!string.IsNullOrWhiteSpace(bcgCode))
  2236. {
  2237. sql = sql.Replace("<11>", " and a.BcgDesc like '%" + bcgCode + "%' ");
  2238. }
  2239. else
  2240. {
  2241. sql = sql.Replace("<11>", " ");
  2242. }
  2243. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  2244. //{
  2245. sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  2246. // // sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  2247. //}
  2248. //else
  2249. //{
  2250. // sql = sql.Replace("{0}", "");
  2251. //}
  2252. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  2253. //{
  2254. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  2255. //}
  2256. return Repository().FindDataSetBySql(sql.ToString(), parameter.ToArray()).Tables[0];
  2257. }
  2258. public string UpdateMaterialReUrgent(string keyValue, string time)
  2259. {
  2260. string returnValue = string.Empty;
  2261. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  2262. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  2263. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2264. try
  2265. {
  2266. var dtNow = DateTime.Now;
  2267. var models = keyValue.Substring(1, keyValue.Length - 2).Split(',').ToList();
  2268. if (models == null)
  2269. {
  2270. throw new Exception("传入参数错误");
  2271. }
  2272. var sql = @"select * from IcsMatCheckResult a with(nolock) where a.id in ('" + string.Join("','", models) + "') and a.WorkPoint=@WorkPoint";
  2273. var para = new
  2274. {
  2275. WorkPoint = WorkPoint,
  2276. };
  2277. //查询已存在条码记录
  2278. var getList = MsSqlData.Query<IcsMatCheckResult>(sql, para).ToList();
  2279. foreach (var item in getList)
  2280. {
  2281. item.Urgent = "是";
  2282. item.MUSER = MUSER;
  2283. item.MUSERName = MUSERNAME;
  2284. item.MTIME = dtNow;
  2285. item.EATTRIBUTE6 = time;
  2286. var result = MsSqlData.Update<IcsMatCheckResult>(item);
  2287. if (!result)
  2288. {
  2289. returnValue = "修改失败";
  2290. }
  2291. }
  2292. }
  2293. catch (Exception ex)
  2294. {
  2295. returnValue = ex.Message;
  2296. }
  2297. return returnValue;
  2298. }
  2299. public string UpdateMaterialHasReturnItem(string keyValue)
  2300. {
  2301. string returnValue = string.Empty;
  2302. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  2303. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  2304. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2305. try
  2306. {
  2307. var dtNow = DateTime.Now;
  2308. var model = JsonConvert.DeserializeObject<IcsMatCheckResultDto>(keyValue);
  2309. if (model == null)
  2310. {
  2311. throw new Exception("传入参数错误");
  2312. }
  2313. var sql = @"select * from IcsMatCheckResult a with(nolock) where a.id in ('" + model.ID + "') and a.WorkPoint=@WorkPoint";
  2314. var para = new
  2315. {
  2316. WorkPoint = WorkPoint,
  2317. };
  2318. //查询已存在条码记录
  2319. var getList = MsSqlData.Query<IcsMatCheckResult>(sql, para).ToList();
  2320. //return "";
  2321. foreach (var item in getList)
  2322. {
  2323. if (item.NgQty > 0)
  2324. {
  2325. item.HasReturnItem = "是";
  2326. item.HasReturnTime = dtNow;
  2327. item.WHRemark = model.WHRemark;
  2328. }
  2329. else
  2330. {
  2331. continue;
  2332. }
  2333. item.MUSER = MUSER;
  2334. item.MUSERName = MUSERNAME;
  2335. item.MTIME = dtNow;
  2336. var result = MsSqlData.Update<IcsMatCheckResult>(item);
  2337. if (!result)
  2338. {
  2339. returnValue = "修改失败";
  2340. }
  2341. }
  2342. }
  2343. catch (Exception ex)
  2344. {
  2345. returnValue = ex.Message;
  2346. }
  2347. return returnValue;
  2348. }
  2349. public string ImportItem2CheckGroup(string savePath)
  2350. {
  2351. string returnValue = string.Empty;
  2352. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2353. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  2354. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  2355. SqlConnection conn = SqlHelper.GetDataCenterConn();
  2356. DataTable data = FileToExcel.ExcelToTable(savePath);
  2357. DateTime time = DateTime.Now;
  2358. //DataSet dsSave = new DataSet();
  2359. //dsSave.Tables.Add(data.Copy());
  2360. DateTime dtNow = DateTime.Now;
  2361. //dsSave.Tables[0].TableName = "IcsCheckingFixture";
  2362. //ICSInspectionGroupEntity entity = new ICSInspectionGroupEntity();
  2363. List<ICSInventoryInspectionListDto> dtolist = new List<ICSInventoryInspectionListDto>();
  2364. List<ICSInventoryInspectionGroupEntity> list = new List<ICSInventoryInspectionGroupEntity>();
  2365. List<ICSInventoryInspectionListEntity> detailList = new List<ICSInventoryInspectionListEntity>();
  2366. var para = new { WorkPoint = WorkPoint };
  2367. string sql0 = @"
  2368. select *
  2369. from V_QuerySysEnumItem a
  2370. where a.F_EnCode='CheckAttr'
  2371. ";
  2372. var enumList = MsSqlData.Query<SysEnumValueDto>(sql0, para).ToList();
  2373. for (int i = 0; i < data.Rows.Count; i++)
  2374. {
  2375. var item = data.Rows[i];
  2376. if (item["物料代码"].ToStringExt() == "")
  2377. {
  2378. throw new Exception("第" + (i + 1) + "行," + "物料代码为空");
  2379. }
  2380. if (item["物料名称"].ToStringExt() == "")
  2381. {
  2382. throw new Exception("第" + (i + 1) + "行," + "物料名称为空");
  2383. }
  2384. if (item["检验项目编码"].ToStringExt() == "")
  2385. {
  2386. throw new Exception("第" + (i + 1) + "行," + "检验项目编码为空");
  2387. }
  2388. if (item["检验项目名称"].ToStringExt() == "")
  2389. {
  2390. throw new Exception("第" + (i + 1) + "行," + "检验项目名称为空");
  2391. }
  2392. if (item["检验属性"].ToStringExt() == "")
  2393. {
  2394. throw new Exception("第" + (i + 1) + "行," + "检验属性为空");
  2395. }
  2396. if (item["启用(是否)"].ToStringExt() == "")
  2397. {
  2398. throw new Exception("第" + (i + 1) + "行," + "启用(是否)为空");
  2399. }
  2400. var dto = new ICSInventoryInspectionListDto();
  2401. dto.InvCode = item["物料代码"].ToStringExt();
  2402. dto.InvName = item["物料名称"].ToStringExt();
  2403. dto.ListCode = item["检验项目编码"].ToStringExt();
  2404. dto.ListName = item["检验项目名称"].ToStringExt();
  2405. dto.EATTRIBUTE1 = item["检验方法"].ToStringExt();
  2406. dto.CheckAttr = item["检验属性"].ToStringExt();
  2407. var enumValue = enumList.Where(x => x.label == dto.CheckAttr).FirstOrDefault();
  2408. if (enumValue == null)
  2409. {
  2410. throw new Exception("第" + (i + 1) + "行," + "检验属性不能识别");
  2411. }
  2412. dto.CheckAttr = enumValue.value;
  2413. dto.SetValueMax = item["设计最大值"].ToDecimal();
  2414. dto.SetValueMin = item["设计最小值"].ToDecimal();
  2415. dto.Unit = item["单位"].ToStringExt();
  2416. dto.Enable = item["启用(是否)"].ToStringExt() == "是" ? true : false;
  2417. dtolist.Add(dto);
  2418. if (enumValue.Ext1 == "尺寸")
  2419. {
  2420. //尺寸
  2421. if (!dto.SetValueMax.HasValue || !dto.SetValueMin.HasValue || dto.Unit.IsEmpty())
  2422. {
  2423. throw new Exception("第" + (i + 1) + "行," + " 当属性为尺寸时,最大值,最小值,单位必填");
  2424. }
  2425. if (dto.SetValueMax.Value <= dto.SetValueMin.Value)
  2426. {
  2427. throw new Exception("第" + (i + 1) + "行," + " 最大值必须大于最小值");
  2428. }
  2429. }
  2430. string dtPre = DateTime.Now.ToString("yyyyMMdd");
  2431. string sql = @"EXEC Addins_GetSerialCode '" + WorkPoint + "','ICSInventoryInspectionGroup','GroupCode','" + "IGC" + dtPre + "',3";
  2432. var serialNo = MsSqlData.ExecuteScalar(sql).ToStringExt();
  2433. ICSInventoryInspectionGroupEntity entity = new ICSInventoryInspectionGroupEntity();
  2434. entity.ID = Guid.NewGuid().ToString();
  2435. entity.InvCode = dto.InvCode;
  2436. entity.GroupCode = serialNo;
  2437. entity.GroupName = serialNo;
  2438. entity.EATTRIBUTE1 = dto.CheckAttr;
  2439. entity.Enable = true;
  2440. entity.MUSER = MUSER;
  2441. entity.MUSERName = MUSERNAME;
  2442. entity.MTIME = dtNow;
  2443. entity.WorkPoint = WorkPoint;
  2444. var detail = new ICSInventoryInspectionListEntity();
  2445. detail = ConvertExt.Mapping<ICSInventoryInspectionListDto, ICSInventoryInspectionListEntity>(dto);
  2446. detail.InvGroupID = entity.ID;
  2447. detail.ID = Guid.NewGuid().ToString();
  2448. detail.MUSER = MUSER;
  2449. detail.MUSERName = MUSERNAME;
  2450. detail.MTIME = dtNow;
  2451. detail.WorkPoint = WorkPoint;
  2452. var sql4Count = @" select
  2453. count(1)
  2454. from
  2455. (
  2456. select
  2457. a.ID
  2458. , c.InvCode
  2459. , c.InvName
  2460. , a.ListCode
  2461. , a.ListName
  2462. , b.EATTRIBUTE1 as CheckAttr --
  2463. from ICSInventoryInspectionList a with(nolock)
  2464. left join ICSInventoryInspectionGroup b with(nolock) on a.InvGroupID = b.ID
  2465. left join ICSInventory c with(nolock) on b.InvCode = c.InvCode
  2466. ) a
  2467. where 1 = 1
  2468. and a.InvCode = @InvCode and a.ListCode=@ListCode ";
  2469. var para2 = new { InvCode = dto.InvCode, ListCode = dto.ListCode, CheckAttr = dto.CheckAttr };
  2470. var count = MsSqlData.ExecuteScalar(sql4Count, para2).ToInt();
  2471. if (count > 0)
  2472. {
  2473. throw new Exception("第" + (i + 1) + "行," + "当前物料检验项目关系已经存在");
  2474. }
  2475. var itemCode = MsSqlData.Query<ICSInventoryDto>(
  2476. @"select top 1 * from ICSInventory a with(nolock)
  2477. where a.InvCode = '" + entity.InvCode + "'")
  2478. .FirstOrDefault();
  2479. if (itemCode == null)
  2480. {
  2481. throw new Exception("第" + (i + 1) + "行," + "当前物料不存在");
  2482. }
  2483. list.Add(entity);
  2484. detailList.Add(detail);
  2485. }
  2486. if (list.Count == 0 || detailList.Count == 0)
  2487. {
  2488. throw new Exception("没有导入数据");
  2489. }
  2490. //if (list != null && list.Count > 0)
  2491. //{
  2492. // if (list.Select(x => x.InvCode).Distinct().Count() != list.Count)
  2493. // {
  2494. // throw new Exception("一个物料只能绑定一个检验类型");
  2495. // }
  2496. //}
  2497. var groupList = dtolist.GroupBy(x => new { x.ListCode, x.InvCode });
  2498. if (groupList.Count() != dtolist.Count)
  2499. {
  2500. var codeError = groupList.Where(x => x.Count() > 1).FirstOrDefault();
  2501. // var conGroupList= groupList.Count()
  2502. throw new Exception("当前物料检验项目代码重复,对应物料和检验项目代码: " + codeError.Key.ListCode + "|" + codeError.Key.InvCode);
  2503. }
  2504. var result = MsSqlData.Insert<ICSInventoryInspectionGroupEntity>(list);
  2505. if (!result)
  2506. {
  2507. throw new Exception("导入失败");
  2508. }
  2509. result = MsSqlData.Insert<ICSInventoryInspectionListEntity>(detailList);
  2510. if (!result)
  2511. {
  2512. throw new Exception("导入失败");
  2513. }
  2514. returnValue = "true";
  2515. return returnValue;
  2516. }
  2517. public List<SelectItemDto> GetSelectBadReasonList(string keyValue)
  2518. {
  2519. var returnValue = new List<SelectItemDto>();
  2520. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  2521. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  2522. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2523. var sql = @"select
  2524. a.*
  2525. from ICSBadReason a with(nolock)
  2526. where 1=1
  2527. and a.WorkPoint=@WorkPoint
  2528. and a.BRGroupID=(
  2529. select
  2530. a.ID
  2531. from ICSBadReasonGroup a with(nolock)
  2532. where 1=1
  2533. and a.BRGCode=@BRGroupID
  2534. )
  2535. order by a.BadReasonCode asc ";
  2536. var para = new
  2537. {
  2538. WorkPoint = WorkPoint,
  2539. BRGroupID = keyValue
  2540. };
  2541. var query = MsSqlData.Query<ICSBadReasonEntity>(sql, para);
  2542. int index = 0;
  2543. returnValue = query.Select(x =>
  2544. {
  2545. ++index;
  2546. SelectItemDto item = new SelectItemDto();
  2547. item.key = index;
  2548. item.value = x.BadReasonCode;
  2549. item.label = x.BadReasonDesc;
  2550. return item;
  2551. }).ToList();
  2552. return returnValue;
  2553. }
  2554. public List<SelectItemDto> GetSelectBadReasonGroupList()
  2555. {
  2556. var returnValue = new List<SelectItemDto>();
  2557. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  2558. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  2559. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2560. var sql = @"select
  2561. a.*
  2562. from ICSBadReasonGroup a with(nolock)
  2563. where 1=1
  2564. and a.WorkPoint=@WorkPoint
  2565. order by a.Mtime asc ";
  2566. var para = new
  2567. {
  2568. WorkPoint = WorkPoint,
  2569. };
  2570. var query = MsSqlData.Query<ICSBadReasonGroupEntity>(sql, para);
  2571. int index = 0;
  2572. returnValue = query.Select(x =>
  2573. {
  2574. ++index;
  2575. SelectItemDto item = new SelectItemDto();
  2576. item.key = index;
  2577. item.value = x.BRGCode;
  2578. item.label = x.BRGDesc;
  2579. return item;
  2580. }).ToList();
  2581. return returnValue;
  2582. }
  2583. public List<SelectItemDto> GetSelectBadCodeGroupList()
  2584. {
  2585. var returnValue = new List<SelectItemDto>();
  2586. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  2587. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  2588. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2589. var sql = @"select
  2590. a.*
  2591. from ICSBadCodeGroup a with(nolock)
  2592. where 1=1
  2593. and a.WorkPoint=@WorkPoint
  2594. order by a.Mtime asc ";
  2595. var para = new
  2596. {
  2597. WorkPoint = WorkPoint,
  2598. };
  2599. var query = MsSqlData.Query<ICSBadCodeGroupEntity>(sql, para);
  2600. int index = 0;
  2601. returnValue = query.Select(x =>
  2602. {
  2603. ++index;
  2604. SelectItemDto item = new SelectItemDto();
  2605. item.key = index;
  2606. item.value = x.BCGCode;
  2607. item.label = x.BCGDesc;
  2608. return item;
  2609. }).ToList();
  2610. return returnValue;
  2611. }
  2612. public IcsMatCheckResultDto GetMaterialReJudgeMain(string keyValue)
  2613. {
  2614. var returnValue = new IcsMatCheckResultDto();
  2615. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  2616. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  2617. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2618. try
  2619. {
  2620. var para1 = new
  2621. {
  2622. WorkPoint = WorkPoint,
  2623. Id = keyValue
  2624. };
  2625. var sqlMain = @"select top 1
  2626. a.*
  2627. ,b.InvName
  2628. ,e.VenName
  2629. ,case when l.CreateDateTime is not null then l.CreateDateTime
  2630. when l2.CreateDateTime is not null then l2.CreateDateTime
  2631. else null end as DHDate
  2632. from IcsMatCheckResult a with(nolock)
  2633. left join ICSInventory b with(nolock) on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  2634. left join ICSVendor e with(nolock) on a.VenCode=e.VenCode and a.WorkPoint=e.WorkPoint
  2635. left join ICSDeliveryNotice l with(nolock) on a.ASNCode=l.ASNCode
  2636. left join ICSODeliveryNotice l2 with(nolock) on a.ASNCode=l2.OASNCode
  2637. where 1 = 1
  2638. and a.WorkPoint= @WorkPoint
  2639. --and a.CheckNo='CR202410300001'
  2640. and a.ID=@Id";
  2641. returnValue = MsSqlData.Query<IcsMatCheckResultDto>(sqlMain, para1).FirstOrDefault();
  2642. if (returnValue == null)
  2643. {
  2644. throw new Exception("当前检验单数据查询失败");
  2645. }
  2646. var para = new
  2647. {
  2648. WorkPoint = WorkPoint,
  2649. CheckNo = returnValue.CheckNo
  2650. };
  2651. var sql1 = @"select
  2652. a.*
  2653. from IcsMatCheckResultDetail a with(nolock)
  2654. where 1 = 1
  2655. and a.WorkPoint = @WorkPoint
  2656. and a.CheckNo=@CheckNo
  2657. order by a.CheckAttr ,a.CheckItemCode";
  2658. var detailList = MsSqlData.Query<IcsMatCheckResultDetailDto>(sql1, para);
  2659. // var para = new { WorkPoint = WorkPoint };
  2660. string sql0 = @"
  2661. select *
  2662. from V_QuerySysEnumItem a
  2663. where a.F_EnCode='CheckAttr'
  2664. ";
  2665. var enumList = MsSqlData.Query<SysEnumValueDto>(sql0, para).ToList();
  2666. var chicun = enumList.Where(x => x.Ext1 == "尺寸").Select(x => x.value);
  2667. returnValue.CCList = detailList.Where(x => chicun.Contains(x.CheckAttr)).ToList();
  2668. chicun = enumList.Where(x => x.Ext1 == "外观").Select(x => x.value);
  2669. returnValue.WGList = detailList.Where(x => chicun.Contains(x.CheckAttr)).ToList();
  2670. chicun = enumList.Where(x => x.Ext1 == "性能").Select(x => x.value);
  2671. returnValue.XNList = detailList.Where(x => chicun.Contains(x.CheckAttr)).ToList();
  2672. }
  2673. catch (Exception ex)
  2674. {
  2675. returnValue = new IcsMatCheckResultDto();
  2676. returnValue.CCList = new List<IcsMatCheckResultDetailDto>();
  2677. returnValue.WGList = new List<IcsMatCheckResultDetailDto>();
  2678. returnValue.XNList = new List<IcsMatCheckResultDetailDto>();
  2679. }
  2680. return returnValue;
  2681. }
  2682. public DataTable GetMaterialInStorageFinalPageList(string queryJson, ref Pagination pagination)
  2683. {
  2684. DataTable dt = new DataTable();
  2685. var queryParam = queryJson.ToJObject();
  2686. List<DbParameter> parameter = new List<DbParameter>();
  2687. //object Figure = GetDecimalDigits();
  2688. #region [SQL]
  2689. string sql = @"
  2690. select
  2691. a.*
  2692. from
  2693. (
  2694. select
  2695. distinct
  2696. a.ID
  2697. ,a.CheckNo
  2698. ,a.AsnCode ASNCode
  2699. ,a.InvCode
  2700. ,b.InvName
  2701. ,a.InvBatcgNo
  2702. ,a.InvBatcgQty
  2703. ,a.VenCode
  2704. ,c.VenName
  2705. ,c2.FileName OutReport --
  2706. ,c2.FilePath
  2707. ,a.IQCGroupHeaderResult
  2708. ,a.IQCHeaderResult
  2709. ,a.SQEEngineerResult
  2710. ,a.FinalResult
  2711. ,a.IsCheckComplete
  2712. ,a.EATTRIBUTE1
  2713. ,a.EATTRIBUTE3 CheckDate
  2714. ,a.EATTRIBUTE6
  2715. ,case when l.CreateDateTime is not null then l.CreateDateTime
  2716. when l2.CreateDateTime is not null then l2.CreateDateTime
  2717. else null end as DHDate
  2718. ,a.IQCGroupHeaderUser
  2719. ,a.IQCGroupHeaderTime
  2720. ,a.IQCHeaderUser
  2721. ,a.IQCHeaderTime
  2722. ,a.SQEEngineerUser
  2723. ,a.SQEEngineerTime
  2724. ,a.FinalUser
  2725. ,a.FinalTime
  2726. ,a.BRGCode
  2727. ,bcg.BcgDesc
  2728. ,a.HasReturnItem
  2729. ,a.Urgent
  2730. ,a.FirstCheckUser
  2731. ,a.FirstCheckTime
  2732. ,a.WgNgFile
  2733. ,a.SQEFile
  2734. ,a.GoodQty
  2735. ,a.NgQty
  2736. ,a.HasReturnTime
  2737. ,a.WHRemark
  2738. from IcsMatCheckResult a with(nolock)
  2739. left join ICSBadCodeGroup bcg with(nolock) on a.BRGCode=bcg.bcgcode and a.WorkPoint=bcg.WorkPoint
  2740. left join ICSInventory b with(nolock) on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  2741. left join ICSVendor c with(nolock) on a.VenCode=c.VenCode and a.WorkPoint=c.WorkPoint
  2742. left join (
  2743. select *
  2744. from
  2745. (
  2746. select t.*
  2747. ,row_number() over(partition by t.ASNCode,t.BatchCode,t.invcode order by t.CerateTime desc) RowSeq
  2748. from ICSASNShippingReport t with(nolock)
  2749. ) t where t.RowSeq=1
  2750. ) c2 on a.ASNCode=c2.ASNCode and a.InvBatcgNo=c2.BatchCode and a.invcode=c2.invcode
  2751. left join ICSDeliveryNotice l with(nolock) on a.ASNCode=l.ASNCode
  2752. left join ICSODeliveryNotice l2 with(nolock) on a.ASNCode=l2.OASNCode
  2753. where 1=1
  2754. {0}
  2755. and a.Result='NG'
  2756. ) a
  2757. where 1=1
  2758. --and a.AsnCode=''
  2759. --order by a.CheckNo
  2760. <1>
  2761. <2>
  2762. <3>
  2763. <4>
  2764. <5>
  2765. <6>
  2766. <7>
  2767. <8>
  2768. <9>
  2769. <10>
  2770. <11>
  2771. ";
  2772. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  2773. //sql = string.Format(sql, Figure);
  2774. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  2775. #endregion
  2776. if (!string.IsNullOrWhiteSpace(queryJson))
  2777. {
  2778. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  2779. {
  2780. sql = sql.Replace("<1>", " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ");
  2781. }
  2782. else
  2783. {
  2784. sql = sql.Replace("<1>", " ");
  2785. }
  2786. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  2787. {
  2788. sql = sql.Replace("<2>", " and a.InvName like '%" + queryParam["InvName"].ToString() + "%' ");
  2789. }
  2790. else
  2791. {
  2792. sql = sql.Replace("<2>", " ");
  2793. }
  2794. if (!string.IsNullOrWhiteSpace(queryParam["StartDate"].ToString()))
  2795. {
  2796. sql = sql.Replace("<3>", " and a.DHDate>='" + queryParam["StartDate"].ToString() + " 00:00:00' ");
  2797. }
  2798. else
  2799. {
  2800. sql = sql.Replace("<3>", " ");
  2801. }
  2802. if (!string.IsNullOrWhiteSpace(queryParam["EndDate"].ToString()))
  2803. {
  2804. sql = sql.Replace("<4>", " and a.DHDate<='" + queryParam["EndDate"].ToString() + " 23:59:59' ");
  2805. }
  2806. else
  2807. {
  2808. sql = sql.Replace("<4>", " ");
  2809. }
  2810. if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString()))
  2811. {
  2812. sql = sql.Replace("<5>", " and a.ASNCode like '%" + queryParam["ASNCode"].ToString() + "%' ");
  2813. }
  2814. else
  2815. {
  2816. sql = sql.Replace("<5>", " ");
  2817. }
  2818. if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString()))
  2819. {
  2820. sql = sql.Replace("<6>", " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' ");
  2821. }
  2822. else
  2823. {
  2824. sql = sql.Replace("<6>", " ");
  2825. }
  2826. if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString()))
  2827. {
  2828. sql = sql.Replace("<7>", " and a.VenName like '%" + queryParam["VenName"].ToString() + "%' ");
  2829. }
  2830. else
  2831. {
  2832. sql = sql.Replace("<7>", " ");
  2833. }
  2834. if (!string.IsNullOrWhiteSpace(queryParam["InvBatcgNo"].ToString()))
  2835. {
  2836. sql = sql.Replace("<8>", " and a.InvBatcgNo like '%" + queryParam["InvBatcgNo"].ToString() + "%' ");
  2837. }
  2838. else
  2839. {
  2840. sql = sql.Replace("<8>", " ");
  2841. }
  2842. if (!string.IsNullOrWhiteSpace(queryParam["IsCheckComplete"].ToString()))
  2843. {
  2844. if (queryParam["IsCheckComplete"].ToString() == "是")
  2845. sql = sql.Replace("<9>", " and a.IsCheckComplete='" + queryParam["IsCheckComplete"].ToString() + "' ");
  2846. else
  2847. sql = sql.Replace("<9>", " and a.IsCheckComplete is null ");
  2848. }
  2849. else
  2850. {
  2851. sql = sql.Replace("<9>", " ");
  2852. }
  2853. if (!string.IsNullOrWhiteSpace(queryParam["JuegeProgess"].ToString()))
  2854. {
  2855. var aa = queryParam["JuegeProgess"].ToString();
  2856. if (aa == "1")
  2857. {
  2858. sql = sql.Replace("<10>", " and a.IQCGroupHeaderResult is null ");
  2859. }
  2860. if (aa == "2")
  2861. {
  2862. sql = sql.Replace("<10>", " and a.IQCGroupHeaderResult is not null ");
  2863. }
  2864. if (aa == "3")
  2865. {
  2866. sql = sql.Replace("<10>", " and a.SQEEngineerResult is null ");
  2867. }
  2868. if (aa == "4")
  2869. {
  2870. sql = sql.Replace("<10>", " and a.SQEEngineerResult is not null ");
  2871. }
  2872. if (aa == "5")
  2873. {
  2874. sql = sql.Replace("<10>", " and a.IQCHeaderResult is null ");
  2875. }
  2876. if (aa == "6")
  2877. {
  2878. sql = sql.Replace("<10>", " and a.IQCHeaderResult is not null ");
  2879. }
  2880. if (aa == "7")
  2881. {
  2882. sql = sql.Replace("<10>", " and a.FinalResult is null ");
  2883. }
  2884. }
  2885. else
  2886. {
  2887. sql = sql.Replace("<10>", " ");
  2888. }
  2889. if (!string.IsNullOrWhiteSpace(queryParam["BcgCode"].ToString()))
  2890. {
  2891. sql = sql.Replace("<11>", " and a.BcgDesc like '%" + queryParam["BcgCode"].ToString() + "%' ");
  2892. }
  2893. else
  2894. {
  2895. sql = sql.Replace("<11>", " ");
  2896. }
  2897. }
  2898. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  2899. //{
  2900. sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  2901. // // sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  2902. //}
  2903. //else
  2904. //{
  2905. // sql = sql.Replace("{0}", "");
  2906. //}
  2907. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  2908. //{
  2909. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  2910. //}
  2911. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref pagination);
  2912. }
  2913. public string SaveMaterialCheckResult(string keyValue)
  2914. {
  2915. string returnValue = string.Empty;
  2916. var otherApp = new DHICSRCVIQCsApp();
  2917. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  2918. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  2919. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  2920. try
  2921. {
  2922. var dtNow = DateTime.Now;
  2923. var model = JsonConvert.DeserializeObject<IcsMatCheckResultDto>(keyValue);
  2924. if (model == null)
  2925. {
  2926. throw new Exception("传入参数错误");
  2927. }
  2928. var getCountSql = @"select Count(1) from IcsMatCheckResult a with(nolock) where a.AsnCode=@AsnCode
  2929. and a.InvCode=@InvCode
  2930. and a.InvBatcgNo=@InvBatcgNo
  2931. and a.WorkPoint=@WorkPoint
  2932. ";
  2933. var para = new
  2934. {
  2935. WorkPoint = WorkPoint,
  2936. AsnCode = model.AsnCode,
  2937. InvCode = model.InvCode,
  2938. InvBatcgNo = model.InvBatcgNo,
  2939. };
  2940. var getCount = MsSqlData.ExecuteScalar(getCountSql, para).ToInt();
  2941. if (getCount > 0)
  2942. {
  2943. throw new Exception("当前批次号已经存在检验记录");
  2944. }
  2945. string dtPre = DateTime.Now.ToString("yyyyMMdd");
  2946. string sql = @"EXEC Addins_GetSerialCode '" + WorkPoint + "','IcsMatCheckResult','CheckNo','" + "CR" + dtPre + "',4";
  2947. var serialNo = MsSqlData.ExecuteScalar(sql).ToStringExt();
  2948. var entity = new IcsMatCheckResult();
  2949. entity = ConvertExt.Mapping<IcsMatCheckResultDto, IcsMatCheckResult>(model);
  2950. entity.CheckNo = serialNo;
  2951. entity.ID = Guid.NewGuid().ToString();
  2952. entity.MUSER = MUSER;
  2953. entity.MUSERName = MUSERNAME;
  2954. entity.MTIME = dtNow;
  2955. entity.FirstCheckUser = MUSERNAME;
  2956. entity.FirstCheckTime = dtNow;
  2957. entity.WorkPoint = WorkPoint;
  2958. entity.WgNgFile = model.WgNgFile;
  2959. // entity.EATTRIBUTE3 = dtNow.ToString("yyyy-MM-dd HH:mm:ss");
  2960. MsSqlData.Insert<IcsMatCheckResult>(entity);
  2961. //合格给到仓库进行入库,不合格则由IQC组长进行判定;
  2962. #region 合格
  2963. if (model.Result == "OK")
  2964. {
  2965. Pagination pagination = new Pagination();
  2966. var itemLotDt = GetMaterialInStorageCheckDetailList(model.AsnCode, model.InvBatcgNo, model.InvCode, ref pagination);
  2967. var itemLotList = JsonConvert.DeserializeObject<List<IcsItemLotInIQCCheckDto>>(itemLotDt.ToJson());
  2968. GoodInStorage(dtNow, model, itemLotList);
  2969. }
  2970. #endregion
  2971. #region 检验项目保存
  2972. List<IcsMatCheckResultDetail> detailList = new List<IcsMatCheckResultDetail>();
  2973. foreach (var item in model.CCList)
  2974. {
  2975. IcsMatCheckResultDetail detail = ConvertExt.Mapping<IcsMatCheckResultDetailDto, IcsMatCheckResultDetail>(item);
  2976. detail.CheckNo = serialNo;
  2977. detail.ID = Guid.NewGuid().ToString();
  2978. detail.MUSER = MUSER;
  2979. detail.MUSERName = MUSERNAME;
  2980. detail.MTIME = dtNow;
  2981. detail.WorkPoint = WorkPoint;
  2982. // detail.CheckItemCod
  2983. detailList.Add(detail);
  2984. }
  2985. foreach (var item in model.WGList)
  2986. {
  2987. IcsMatCheckResultDetail detail = ConvertExt.Mapping<IcsMatCheckResultDetailDto, IcsMatCheckResultDetail>(item);
  2988. detail.CheckNo = serialNo;
  2989. detail.ID = Guid.NewGuid().ToString();
  2990. detail.MUSER = MUSER;
  2991. detail.MUSERName = MUSERNAME;
  2992. detail.MTIME = dtNow;
  2993. detail.WorkPoint = WorkPoint;
  2994. detailList.Add(detail);
  2995. }
  2996. foreach (var item in model.XNList)
  2997. {
  2998. IcsMatCheckResultDetail detail = ConvertExt.Mapping<IcsMatCheckResultDetailDto, IcsMatCheckResultDetail>(item);
  2999. detail.CheckNo = serialNo;
  3000. detail.ID = Guid.NewGuid().ToString();
  3001. detail.MUSER = MUSER;
  3002. detail.MUSERName = MUSERNAME;
  3003. detail.MTIME = dtNow;
  3004. detail.WorkPoint = WorkPoint;
  3005. detailList.Add(detail);
  3006. }
  3007. if (detailList.Count > 0)
  3008. {
  3009. MsSqlData.Insert<IcsMatCheckResultDetail>(detailList);
  3010. }
  3011. #endregion
  3012. #region 实验抽选数量拒收单
  3013. if (model.FinalItemLotList != null && model.FinalItemLotList.Count > 0)
  3014. {
  3015. // var goodList = model.FinalItemLotList.Where(x => x.LeftQty.HasValue && x.GoodQty > 0).ToList();
  3016. var ngList = model.FinalItemLotList.Where(x => x.SampleQty.HasValue && x.SampleQty > 0).ToList();
  3017. //GoodInStorage(dtNow, model, goodList);
  3018. if (ngList.Count > 0)
  3019. {
  3020. var itemLotNos = ngList.Select(x => x.LotNo);
  3021. var lotNoStr = string.Empty;
  3022. foreach (var str in itemLotNos)
  3023. {
  3024. lotNoStr += "'" + str + "',";
  3025. }
  3026. //记录日志
  3027. InsertOperateLog(serialNo, JsonConvert.SerializeObject(itemLotNos), entity.GetType().Name, "实验");
  3028. if (model.EATTRIBUTE2 == "1")
  3029. {
  3030. var msg = otherApp.CreateRejection4KBS(lotNoStr);
  3031. if (!msg.IsNullOrEmpty())
  3032. {
  3033. throw new Exception(msg);
  3034. }
  3035. }
  3036. else if (model.EATTRIBUTE2 == "2")
  3037. {
  3038. var msg = otherApp.CreateWWRejection4KBS(lotNoStr);
  3039. if (!msg.IsNullOrEmpty())
  3040. {
  3041. throw new Exception(msg);
  3042. }
  3043. }
  3044. else
  3045. {
  3046. }
  3047. SendEmail("1", model);
  3048. }
  3049. }
  3050. #endregion
  3051. }
  3052. catch (Exception ex)
  3053. {
  3054. returnValue = ex.Message;
  3055. }
  3056. return returnValue;
  3057. }
  3058. public string SaveMaterialCheckReJudgeResult(string keyValue)
  3059. {
  3060. string returnValue = string.Empty;
  3061. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  3062. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  3063. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  3064. try
  3065. {
  3066. var dtNow = DateTime.Now;
  3067. var model = JsonConvert.DeserializeObject<IcsMatCheckResultDto>(keyValue);
  3068. if (model == null)
  3069. {
  3070. throw new Exception("传入参数错误");
  3071. }
  3072. var entity = MsSqlData.Get<IcsMatCheckResult>(model.ID);
  3073. if (entity == null)
  3074. {
  3075. throw new Exception("当前数据不存在");
  3076. }
  3077. Pagination pagination = new Pagination();
  3078. var itemLotDt = GetMaterialInStorageCheckDetailList(model.AsnCode, model.InvBatcgNo, model.InvCode, ref pagination);
  3079. var itemLotList = JsonConvert.DeserializeObject<List<IcsItemLotInIQCCheckDto>>(itemLotDt.ToJson());
  3080. switch (model.JudgeRole)
  3081. {
  3082. case "IQCGroupHeader":
  3083. entity.IQCGroupHeaderResult = model.IQCGroupHeaderResult;
  3084. entity.IQCGroupHeaderRemark = model.IQCGroupHeaderRemark;
  3085. entity.IQCGroupHeaderUser = MUSERNAME;
  3086. entity.IQCGroupHeaderTime = dtNow;
  3087. entity.BRGCode = model.BRGCode;
  3088. //if (entity.IQCGroupHeaderResult == "")
  3089. //{
  3090. // entity
  3091. //}
  3092. //IQC组长 2.1.合格交给仓库进行入库,不合格由SQE工程师进行复判;
  3093. #region IQC组长
  3094. if (entity.IQCGroupHeaderResult == "OK")
  3095. {
  3096. entity.IsCheckComplete = "是";
  3097. GoodInStorage(dtNow, model, itemLotList);
  3098. }
  3099. #endregion
  3100. break;
  3101. case "IQCHeader":
  3102. entity.IQCHeaderResult = model.IQCHeaderResult;
  3103. entity.IQCHeaderRemark = model.IQCHeaderRemark;
  3104. entity.BRGCode = model.BRGCode;
  3105. entity.BadReasonCode = model.BadReasonCode;
  3106. entity.BCGCode = model.BCGCode;
  3107. entity.IQCHeaderUser = MUSERNAME;
  3108. entity.IQCHeaderTime = dtNow;
  3109. //IQC主管判定 合格后由仓库进行入库,不合格则进行最终判定,并发送邮件
  3110. if (entity.IQCHeaderResult == "OK")
  3111. {
  3112. entity.IsCheckComplete = "是";
  3113. GoodInStorage(dtNow, model, itemLotList);
  3114. }
  3115. else
  3116. {
  3117. SendEmail("3", model);
  3118. }
  3119. break;
  3120. case "SQEEngineer":
  3121. entity.SQEEngineerResult = model.SQEEngineerResult;
  3122. entity.SQEEngineerRemark = model.SQEEngineerRemark;
  3123. // entity.BRGCode = model.BRGCode;
  3124. entity.SQEEngineerUser = MUSERNAME;
  3125. entity.SQEEngineerTime = dtNow;
  3126. if (entity.SQEEngineerResult == "NG")
  3127. {
  3128. SendEmail("2", model);
  3129. }
  3130. break;
  3131. default:
  3132. break;
  3133. }
  3134. entity.EATTRIBUTE1 = model.EATTRIBUTE1;
  3135. entity.MUSER = MUSER;
  3136. entity.MUSERName = MUSERNAME;
  3137. entity.MTIME = dtNow;
  3138. entity.SQEFile = model.SQEFile;
  3139. var result = MsSqlData.Update<IcsMatCheckResult>(entity);
  3140. if (!result)
  3141. {
  3142. returnValue = "修改失败";
  3143. }
  3144. DataTable dt = new DataTable();
  3145. }
  3146. catch (Exception ex)
  3147. {
  3148. returnValue = ex.Message;
  3149. }
  3150. return returnValue;
  3151. }
  3152. private void GoodInStorage(DateTime dtNow, IcsMatCheckResultDto model, List<IcsItemLotInIQCCheckDto> list)
  3153. {
  3154. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  3155. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  3156. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  3157. if (list.Count == 0)
  3158. {
  3159. return;
  3160. }
  3161. var para = new
  3162. {
  3163. WorkPoint = WorkPoint,
  3164. };
  3165. var lotNos = list.Select(x => x.LotNo);
  3166. var sql = @"select * from ICSInspection a with(nolock) where a.LotNo in ('" + string.Join("','", lotNos) + "') and a.WorkPoint=@WorkPoint";
  3167. //查询已存在条码记录
  3168. var getList = MsSqlData.Query<ICSInspection>(sql, para).ToList();
  3169. List<ICSInspection> checkMainList4Insert = new List<ICSInspection>();
  3170. List<ICSInspection> checkMainList4Update = new List<ICSInspection>();
  3171. foreach (var item in list)
  3172. {
  3173. // var isEdit = false;
  3174. var inspection = getList.Where(x => x.LotNo == item.LotNo).FirstOrDefault();
  3175. if (inspection == null)
  3176. {
  3177. inspection = new ICSInspection();
  3178. inspection.ID = Guid.NewGuid().ToString();
  3179. inspection.LotNo = item.LotNo;
  3180. inspection.InvCode = item.InvCode;
  3181. inspection.Quantity = item.Quantity;
  3182. inspection.BCCode = model.BCGCode;
  3183. inspection.BRCode = model.BadReasonCode;
  3184. inspection.Type = "1";
  3185. //inspection.Result = false;
  3186. inspection.Enable = true;
  3187. inspection.WaiveQuantity = 0;
  3188. inspection.SampleQuantity = item.SampleQty.ToDecimal();
  3189. inspection.UnqualifiedQuantity = item.NgQty.ToDecimal();
  3190. inspection.QualifiedQuantity = inspection.Quantity - inspection.SampleQuantity - inspection.UnqualifiedQuantity;
  3191. inspection.MUSER = MUSER;
  3192. inspection.MUSERName = MUSERNAME;
  3193. inspection.MTIME = dtNow;
  3194. inspection.WorkPoint = WorkPoint;
  3195. checkMainList4Insert.Add(inspection);
  3196. }
  3197. else
  3198. {
  3199. inspection.BCCode = model.BCGCode;
  3200. inspection.BRCode = model.BadReasonCode;
  3201. inspection.WaiveQuantity = 0;
  3202. inspection.SampleQuantity = item.SampleQty.ToDecimal();
  3203. inspection.UnqualifiedQuantity = item.NgQty.ToDecimal();
  3204. inspection.QualifiedQuantity = inspection.Quantity - inspection.SampleQuantity - inspection.UnqualifiedQuantity;
  3205. inspection.MUSER = MUSER;
  3206. inspection.MUSERName = MUSERNAME;
  3207. inspection.MTIME = dtNow;
  3208. checkMainList4Update.Add(inspection);
  3209. }
  3210. }
  3211. var line = true;
  3212. if (checkMainList4Insert.Count > 0)
  3213. line = MsSqlData.Insert<ICSInspection>(checkMainList4Insert);
  3214. if (checkMainList4Update.Count > 0)
  3215. line = MsSqlData.Update<ICSInspection>(checkMainList4Update);
  3216. }
  3217. public string SaveMaterialCheckFinalJudgeResult(string keyValue)
  3218. {
  3219. string returnValue = string.Empty;
  3220. // List<decimal> list2 = new List<decimal>();
  3221. // decimal maxaa = list2.Select(x => x).ToList().Max();
  3222. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  3223. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  3224. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  3225. var otherApp = new DHICSRCVIQCsApp();
  3226. try
  3227. {
  3228. var dtNow = DateTime.Now;
  3229. var model = JsonConvert.DeserializeObject<IcsMatCheckResultDto>(keyValue);
  3230. if (model == null)
  3231. {
  3232. throw new Exception("传入参数错误");
  3233. }
  3234. var entity = MsSqlData.Get<IcsMatCheckResult>(model.ID);
  3235. if (entity == null)
  3236. {
  3237. throw new Exception("当前数据不存在");
  3238. }
  3239. if (model.FinalItemLotList == null || model.FinalItemLotList.Count == 0)
  3240. {
  3241. throw new Exception("当前检验报告不存在物料条码");
  3242. }
  3243. switch (model.FinalResult)
  3244. {
  3245. case "判退":
  3246. case "NG":
  3247. //③判退:所有的条码不合格,不能输入合格或不合格数量,点击确定即可;(条码拒收)
  3248. //使用当前基础班的拒收
  3249. //var goodList2 = model.FinalItemLotList.Where(x => x.GoodQty.HasValue && x.GoodQty > 0).ToList();
  3250. //var ngList2 = model.FinalItemLotList.Where(x => x.NgQty.HasValue && x.NgQty > 0).ToList();
  3251. #region //入库检验数据
  3252. GoodInStorage(dtNow, model, model.FinalItemLotList);
  3253. #endregion
  3254. var itemLotNos = model.FinalItemLotList.Select(x => x.LotNo);
  3255. if (itemLotNos.Count() == 0)
  3256. {
  3257. throw new Exception("不存在物料条码");
  3258. }
  3259. var lotNoStr = string.Empty;
  3260. foreach (var str in itemLotNos)
  3261. {
  3262. lotNoStr += "'" + str + "',";
  3263. }
  3264. //记录日志
  3265. InsertOperateLog(model.CheckNo, JsonConvert.SerializeObject(itemLotNos), entity.GetType().Name, "判退");
  3266. // return "";
  3267. if (entity.EATTRIBUTE2 == "1")
  3268. {
  3269. var msg = otherApp.CreateRejection4KBS(lotNoStr);
  3270. if (!msg.IsNullOrEmpty())
  3271. {
  3272. throw new Exception(msg);
  3273. }
  3274. }
  3275. else if (entity.EATTRIBUTE2 == "2")
  3276. {
  3277. var msg = otherApp.CreateWWRejection4KBS(lotNoStr);
  3278. if (!msg.IsNullOrEmpty())
  3279. {
  3280. throw new Exception(msg);
  3281. }
  3282. }
  3283. else
  3284. {
  3285. }
  3286. //发邮件
  3287. // 参考SRM邮件格式
  3288. //通过物料条码找采购订单/委外订单 采购人员 人员邮箱
  3289. //
  3290. SendEmail("1", model);
  3291. break;
  3292. case "返工":
  3293. //合格入库 新增 ICSInspection ;不合格拒收,先保存检验记录,在调用拒收单
  3294. var goodList = model.FinalItemLotList.Where(x => x.GoodQty.HasValue && x.GoodQty > 0).ToList();
  3295. var ngList = model.FinalItemLotList.Where(x => x.NgQty.HasValue && x.NgQty > 0).ToList();
  3296. #region //入库检验数据
  3297. GoodInStorage(dtNow, model, model.FinalItemLotList);
  3298. #endregion
  3299. #region //不合格拒收
  3300. if (ngList.Count > 0)
  3301. {
  3302. var itemLotNos2 = ngList.Select(x => x.LotNo);
  3303. var lotNoStr2 = string.Empty;
  3304. foreach (var str in itemLotNos2)
  3305. {
  3306. lotNoStr2 += "'" + str + "',";
  3307. }
  3308. //记录日志
  3309. InsertOperateLog(model.CheckNo, JsonConvert.SerializeObject(itemLotNos2), entity.GetType().Name, "返工");
  3310. if (entity.EATTRIBUTE2 == "1")
  3311. {
  3312. var msg = otherApp.CreateRejection4KBS(lotNoStr2);
  3313. if (!msg.IsNullOrEmpty())
  3314. {
  3315. throw new Exception(msg);
  3316. }
  3317. }
  3318. else if (entity.EATTRIBUTE2 == "2")
  3319. {
  3320. var msg = otherApp.CreateWWRejection4KBS(lotNoStr2);
  3321. if (!msg.IsNullOrEmpty())
  3322. {
  3323. throw new Exception(msg);
  3324. }
  3325. }
  3326. else
  3327. {
  3328. }
  3329. SendEmail("1", model);
  3330. }
  3331. #endregion
  3332. break;
  3333. case "让步接收":
  3334. case "合格":
  3335. entity.SpecialNo = model.SpecialNo;
  3336. entity.SpecialFile = model.SpecialFile;
  3337. var goodList3 = model.FinalItemLotList.Where(x => x.GoodQty.HasValue && x.GoodQty > 0).ToList();
  3338. var ngList3 = model.FinalItemLotList.Where(x => x.NgQty.HasValue && x.NgQty > 0).ToList();
  3339. #region //入库检验数据
  3340. GoodInStorage(dtNow, model, model.FinalItemLotList);
  3341. #endregion
  3342. #region //不合格拒收
  3343. if (ngList3.Count > 0)
  3344. {
  3345. var itemLotNos3 = ngList3.Select(x => x.LotNo);
  3346. var lotNoStr3 = string.Empty;
  3347. foreach (var str in itemLotNos3)
  3348. {
  3349. lotNoStr3 += "'" + str + "',";
  3350. }
  3351. //记录日志
  3352. InsertOperateLog(model.CheckNo, JsonConvert.SerializeObject(itemLotNos3), entity.GetType().Name, "让步接收");
  3353. if (entity.EATTRIBUTE2 == "1")
  3354. {
  3355. var msg = otherApp.CreateRejection4KBS(lotNoStr3);
  3356. if (!msg.IsNullOrEmpty())
  3357. {
  3358. throw new Exception(msg);
  3359. }
  3360. }
  3361. else if (entity.EATTRIBUTE2 == "2")
  3362. {
  3363. var msg = otherApp.CreateWWRejection4KBS(lotNoStr3);
  3364. if (!msg.IsNullOrEmpty())
  3365. {
  3366. throw new Exception(msg);
  3367. }
  3368. }
  3369. else
  3370. {
  3371. }
  3372. SendEmail("1", model);
  3373. }
  3374. #endregion
  3375. break;
  3376. default:
  3377. break;
  3378. }
  3379. entity.IsCheckComplete = "是";
  3380. entity.Remark = model.Remark;
  3381. entity.FinalResult = model.FinalResult;
  3382. entity.FinalUser = MUSERNAME;
  3383. entity.FinalTime = dtNow;
  3384. entity.MUSER = MUSER;
  3385. entity.MUSERName = MUSERNAME;
  3386. entity.MTIME = dtNow;
  3387. entity.GoodQty = model.FinalItemLotList.Sum(x => x.GoodQty ?? 0);
  3388. entity.NgQty = model.FinalItemLotList.Sum(x => x.NgQty ?? 0);
  3389. var result = MsSqlData.Update<IcsMatCheckResult>(entity);
  3390. if (!result)
  3391. {
  3392. returnValue = "修改失败";
  3393. }
  3394. }
  3395. catch (Exception ex)
  3396. {
  3397. returnValue = ex.Message;
  3398. }
  3399. return returnValue;
  3400. }
  3401. public DataTable GetMaterialCheckMain4WG(string keyValue)
  3402. {
  3403. DataTable dt = new DataTable();
  3404. // var queryParam = queryJson.ToJObject();
  3405. List<DbParameter> parameter = new List<DbParameter>();
  3406. //object Figure = GetDecimalDigits();
  3407. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  3408. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  3409. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  3410. var para = new { WorkPoint = WorkPoint };
  3411. string sql0 = @"
  3412. select *
  3413. from V_QuerySysEnumItem a
  3414. where a.F_EnCode='CheckAttr'
  3415. ";
  3416. var enumList = MsSqlData.Query<SysEnumValueDto>(sql0, para).ToList();
  3417. var chicun = enumList.Where(x => x.Ext1 == "外观").Select(x => x.value);
  3418. if (chicun.Count() == 0)
  3419. {
  3420. return new DataTable();
  3421. }
  3422. #region [SQL]
  3423. string sql = @"
  3424. select
  3425. a.ID
  3426. ,c.InvCode
  3427. ,c.InvName
  3428. ,a.ListCode CheckItemCode
  3429. ,a.ListName CheckItemName
  3430. ,a.EATTRIBUTE1 as CheckWay --
  3431. ,b.EATTRIBUTE1 as CheckAttr --
  3432. ,( select t.label from V_QuerySysEnumItem t where t.value=b.EATTRIBUTE1 and t.F_EnCode='CheckAttr'
  3433. ) as CheckAttrText
  3434. ,a.SetValueMax
  3435. ,a.SetValueMin
  3436. ,a.Unit
  3437. ,d.RulesCode
  3438. ,d.RulesName CheckAqlName
  3439. ,e.Type RulesType
  3440. ,10 as AqlQty
  3441. ,0 as GoodQty
  3442. ,0 as NgQty
  3443. ,'' as Result
  3444. ,'' as Remark
  3445. from ICSInventoryInspectionList a with(nolock)
  3446. left join ICSInventoryInspectionGroup b with(nolock) on a.InvGroupID=b.ID and a.WorkPoint=b.WorkPoint
  3447. left join ICSInventory c with(nolock) on b.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint
  3448. left join ICSInventoryInspectionRulesGroup d with(nolock) on b.InvCode=d.InvCode and b.EATTRIBUTE1=d.EATTRIBUTE1 and b.WorkPoint=d.WorkPoint
  3449. left join ICSInspectionRulesGroup e with(nolock) on d.rulescode=e.RulesCode
  3450. where 1=1
  3451. {0}
  3452. <1>
  3453. and b.EATTRIBUTE1 in ('" + string.Join("','", chicun) + "') and d.EATTRIBUTE1 in ('" + string.Join("','", chicun) + "') and a.Enable=1";
  3454. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  3455. sql = sql.Replace("<1>", " and b.InvCode='" + keyValue + "' ");
  3456. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  3457. {
  3458. sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  3459. // sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  3460. }
  3461. else
  3462. {
  3463. sql = sql.Replace("{0}", "");
  3464. }
  3465. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  3466. #endregion
  3467. return Repository().FindDataSetBySql(sql.ToString(), parameter.ToArray()).Tables[0];
  3468. }
  3469. public DataTable GetMaterialCheckMain4CC(string keyValue)
  3470. {
  3471. DataTable dt = new DataTable();
  3472. // var queryParam = queryJson.ToJObject();
  3473. List<DbParameter> parameter = new List<DbParameter>();
  3474. //object Figure = GetDecimalDigits();
  3475. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  3476. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  3477. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  3478. var para = new { WorkPoint = WorkPoint };
  3479. string sql0 = @"
  3480. select *
  3481. from V_QuerySysEnumItem a
  3482. where a.F_EnCode='CheckAttr'
  3483. ";
  3484. var enumList = MsSqlData.Query<SysEnumValueDto>(sql0, para).ToList();
  3485. var chicun = enumList.Where(x => x.Ext1 == "尺寸").Select(x => x.value);
  3486. if (chicun.Count() == 0)
  3487. {
  3488. return new DataTable();
  3489. }
  3490. #region [SQL]
  3491. string sql = @"
  3492. select
  3493. a.ID
  3494. ,c.InvCode
  3495. ,c.InvName
  3496. ,a.ListCode CheckItemCode
  3497. ,a.ListName CheckItemName
  3498. ,a.EATTRIBUTE1 as CheckWay --
  3499. ,b.EATTRIBUTE1 as CheckAttr --
  3500. ,( select t.label from V_QuerySysEnumItem t where t.value=b.EATTRIBUTE1 and t.F_EnCode='CheckAttr'
  3501. ) as CheckAttrText
  3502. ,a.SetValueMax
  3503. ,a.SetValueMin
  3504. ,a.Unit
  3505. ,d.RulesCode
  3506. ,d.RulesName CheckAqlName
  3507. ,d.RulesDesc
  3508. ,e.Type RulesType
  3509. ,0 as S1
  3510. ,0 as S2
  3511. ,0 as S3
  3512. ,0 as S4
  3513. ,0 as S5
  3514. ,0 as S6
  3515. ,0 as S7
  3516. ,0 as S8
  3517. ,0 as S9
  3518. ,0 as S10
  3519. ,'' as Result
  3520. ,'' as Remark
  3521. from ICSInventoryInspectionList a with(nolock)
  3522. left join ICSInventoryInspectionGroup b with(nolock) on a.InvGroupID=b.ID and a.WorkPoint=b.WorkPoint
  3523. left join ICSInventory c with(nolock) on b.InvCode=c.InvCode and b.WorkPoint=b.WorkPoint
  3524. left join ICSInventoryInspectionRulesGroup d with(nolock) on b.InvCode=d.InvCode and b.EATTRIBUTE1=d.EATTRIBUTE1 and b.WorkPoint=b.WorkPoint
  3525. left join ICSInspectionRulesGroup e with(nolock) on d.rulescode=e.RulesCode
  3526. where 1=1
  3527. {0}
  3528. <1>
  3529. and b.EATTRIBUTE1 in ('" + string.Join("','", chicun) + "') and d.EATTRIBUTE1 in ('" + string.Join("','", chicun) + "') and a.Enable=1";
  3530. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  3531. sql = sql.Replace("<1>", " and b.InvCode='" + keyValue + "' ");
  3532. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  3533. {
  3534. sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  3535. // sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  3536. }
  3537. else
  3538. {
  3539. sql = sql.Replace("{0}", "");
  3540. }
  3541. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  3542. #endregion
  3543. return Repository().FindDataSetBySql(sql.ToString(), parameter.ToArray()).Tables[0];
  3544. }
  3545. public DataTable GetMaterialCheckMain4XN(string keyValue)
  3546. {
  3547. DataTable dt = new DataTable();
  3548. // var queryParam = queryJson.ToJObject();
  3549. List<DbParameter> parameter = new List<DbParameter>();
  3550. //object Figure = GetDecimalDigits();
  3551. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  3552. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  3553. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  3554. var para = new { WorkPoint = WorkPoint };
  3555. string sql0 = @"
  3556. select *
  3557. from V_QuerySysEnumItem a
  3558. where a.F_EnCode='CheckAttr'
  3559. ";
  3560. var enumList = MsSqlData.Query<SysEnumValueDto>(sql0, para).ToList();
  3561. var chicun = enumList.Where(x => x.Ext1 == "性能").Select(x => x.value);
  3562. if (chicun.Count() == 0)
  3563. {
  3564. return new DataTable();
  3565. }
  3566. #region [SQL]
  3567. string sql = @"
  3568. select
  3569. a.ID
  3570. ,c.InvCode
  3571. ,c.InvName
  3572. ,a.ListCode CheckItemCode
  3573. ,a.ListName CheckItemName
  3574. ,a.EATTRIBUTE1 as CheckWay --
  3575. ,b.EATTRIBUTE1 as CheckAttr --
  3576. ,( select t.label from V_QuerySysEnumItem t where t.value=b.EATTRIBUTE1 and t.F_EnCode='CheckAttr'
  3577. ) as CheckAttrText
  3578. ,a.SetValueMax
  3579. ,a.SetValueMin
  3580. ,a.Unit
  3581. ,d.RulesCode
  3582. ,d.RulesName CheckAqlName
  3583. ,e.Type RulesType
  3584. ,0 as S1
  3585. ,0 as S2
  3586. ,0 as S3
  3587. ,0 as S4
  3588. ,0 as S5
  3589. ,0 as S6
  3590. ,0 as S7
  3591. ,0 as S8
  3592. ,0 as S9
  3593. ,0 as S10
  3594. ,'' as Result
  3595. ,'' as Remark
  3596. from ICSInventoryInspectionList a with(nolock)
  3597. left join ICSInventoryInspectionGroup b with(nolock) on a.InvGroupID=b.ID and a.WorkPoint=b.WorkPoint
  3598. left join ICSInventory c with(nolock) on b.InvCode=c.InvCode and b.WorkPoint=b.WorkPoint
  3599. left join ICSInventoryInspectionRulesGroup d with(nolock) on b.InvCode=d.InvCode and b.EATTRIBUTE1=d.EATTRIBUTE1 and b.WorkPoint=b.WorkPoint
  3600. left join ICSInspectionRulesGroup e with(nolock) on d.rulescode=e.RulesCode
  3601. where 1=1
  3602. {0}
  3603. <1>
  3604. and b.EATTRIBUTE1 in ('" + string.Join("','", chicun) + "') and d.EATTRIBUTE1 in ('" + string.Join("','", chicun) + "') and a.Enable=1";
  3605. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  3606. sql = sql.Replace("<1>", " and b.InvCode='" + keyValue + "' ");
  3607. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  3608. {
  3609. sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  3610. // sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  3611. }
  3612. else
  3613. {
  3614. sql = sql.Replace("{0}", "");
  3615. }
  3616. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  3617. #endregion
  3618. return Repository().FindDataSetBySql(sql.ToString(), parameter.ToArray()).Tables[0];
  3619. }
  3620. public DataTable GetMaterialCheckMain(string keyValue)
  3621. {
  3622. List<DbParameter> parameter = new List<DbParameter>();
  3623. string sql = @"select
  3624. a.*
  3625. from
  3626. (
  3627. select
  3628. distinct
  3629. b.ID DetailId --
  3630. ,c.ID LotNoId --ID
  3631. ,c.InvCode
  3632. ,d.InvName
  3633. ,c1.BatchCode as InvBatcgNo --
  3634. ,b.DNQuantity --
  3635. ,a.VenCode --
  3636. ,e.VenName --
  3637. ,a.AsnCode
  3638. ,b.EATTRIBUTE1 as IsUrgentitem --
  3639. ,d.InvUnit
  3640. ,c.Quantity as InvBatcgQty --
  3641. ,f.RulesCode
  3642. ,f.Id as InvRuleId
  3643. ,0 as AqlCheckQty --
  3644. ,0 as AllowNgQty --()
  3645. ,'' as Result
  3646. from ICSASN a with(nolock)
  3647. left join ICSASNDetail b with(nolock) on a.ASNCode=b.ASNCode and a.WorkPoint=b.WorkPoint
  3648. left join ICSInventoryLot c with(nolock) on b.LotNo=c.LotNo and b.WorkPoint=b.WorkPoint
  3649. left join ICSExtension c1 with(nolock) on c.ExtensionID=c1.ID and c.WorkPoint=c1.WorkPoint
  3650. left join ICSInventory d with(nolock) on c.InvCode=d.InvCode and c.WorkPoint=c.WorkPoint
  3651. left join ICSVendor e with(nolock) on a.VenCode=e.VenCode and a.WorkPoint=e.WorkPoint
  3652. left join ICSInventoryInspectionRulesGroup f with(nolock) on c.InvCode=f.InvCode and c.WorkPoint=f.WorkPoint
  3653. where 1=1
  3654. and a.WorkPoint = '{1}'
  3655. union all
  3656. select
  3657. distinct
  3658. b.ID DetailId --
  3659. ,c.ID LotNoId --ID
  3660. ,c.InvCode
  3661. ,d.InvName
  3662. ,c1.BatchCode as InvBatcgNo --
  3663. ,b.ODNQuantity --
  3664. ,a.VenCode --
  3665. ,e.VenName --
  3666. ,a.OAsnCode
  3667. ,b.EATTRIBUTE1 as IsUrgentitem --
  3668. ,d.InvUnit
  3669. ,c.Quantity as InvBatcgQty --
  3670. ,f.RulesCode
  3671. ,f.Id as InvRuleId
  3672. ,0 as AqlCheckQty --
  3673. ,0 as AllowNgQty --()
  3674. ,'' as Result
  3675. from ICSOASN a with(nolock)
  3676. left join ICSOASNDetail b with(nolock) on a.OASNCode=b.OASNCode and a.WorkPoint=b.WorkPoint
  3677. left join ICSInventoryLot c with(nolock) on b.LotNo=c.LotNo and b.WorkPoint=b.WorkPoint
  3678. left join ICSExtension c1 with(nolock) on c.ExtensionID=c1.ID and c.WorkPoint=c1.WorkPoint
  3679. left join ICSInventory d with(nolock) on c.InvCode=d.InvCode and c.WorkPoint=c.WorkPoint
  3680. left join ICSVendor e with(nolock) on a.VenCode=e.VenCode and a.WorkPoint=e.WorkPoint
  3681. left join ICSInventoryInspectionRulesGroup f with(nolock) on c.InvCode=f.InvCode and c.WorkPoint=f.WorkPoint
  3682. where 1=1
  3683. and a.WorkPoint = '{1}'
  3684. ) a
  3685. where 1=1
  3686. and a.DetailId='{0}'
  3687. ";
  3688. sql = string.Format(sql, keyValue, NFine.Code.OperatorProvider.Provider.GetCurrent().Location);
  3689. // sql = sql.Replace("{1}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  3690. var dt = Repository().FindDataSetBySql(sql.ToString(), parameter.ToArray()).Tables[0];
  3691. if (dt != null && dt.Rows.Count > 0)
  3692. {
  3693. var sql2 = @"select
  3694. a.*
  3695. from ICSInspectionRulesList a with(nolock)
  3696. where 1=1
  3697. and a.WorkPoint = '{1}'
  3698. and a.RulesID=(
  3699. select
  3700. a.ID
  3701. from ICSInspectionRulesGroup a with(nolock)
  3702. where 1=1
  3703. and a.RulesCode='{0}'
  3704. )
  3705. order by a.SetValueMin asc
  3706. ";
  3707. sql2 = string.Format(sql2, dt.Rows[0]["RulesCode"].ToString(), NFine.Code.OperatorProvider.Provider.GetCurrent().Location);
  3708. var dt2 = Repository().FindDataSetBySql(sql2.ToString(), parameter.ToArray()).Tables[0];
  3709. if (dt2 != null && dt2.Rows.Count > 0)
  3710. {
  3711. foreach (DataRow item in dt2.Rows)
  3712. {
  3713. if (item["SetValueMin"].ToDecimal() <= dt.Rows[0]["InvBatcgQty"].ToDecimal() &&
  3714. item["SetValueMax"].ToDecimal() >= dt.Rows[0]["InvBatcgQty"].ToDecimal())
  3715. {
  3716. dt.Rows[0]["AqlCheckQty"] = item["SampleQuantity"].ToDecimal();
  3717. dt.Rows[0]["AllowNgQty"] = item["EATTRIBUTE1"].ToDecimal();
  3718. }
  3719. }
  3720. }
  3721. }
  3722. return dt;
  3723. }
  3724. public DataTable GetMaterialCheckMain2(string keyValue, decimal qty)
  3725. {
  3726. List<DbParameter> parameter = new List<DbParameter>();
  3727. string sql = @"
  3728. select
  3729. a.*
  3730. from
  3731. (
  3732. select
  3733. distinct
  3734. b.ID DetailId --
  3735. ,c.ID LotNoId --ID
  3736. ,c.InvCode
  3737. ,d.InvName
  3738. ,c1.BatchCode as InvBatcgNo --
  3739. ,b.DNQuantity --
  3740. ,a.VenCode --
  3741. ,e.VenName --
  3742. ,a.AsnCode
  3743. ,b.EATTRIBUTE1 as IsUrgentitem --
  3744. ,d.InvUnit
  3745. ,c.Quantity as InvBatcgQty --
  3746. ,f.RulesCode
  3747. ,f.Id as InvRuleId
  3748. ,0 as AqlCheckQty --
  3749. ,0 as AllowNgQty --()
  3750. ,'' as Result
  3751. ,'' as WgNgFile
  3752. from ICSASN a with(nolock)
  3753. left join ICSASNDetail b with(nolock) on a.ASNCode=b.ASNCode and a.WorkPoint=b.WorkPoint
  3754. left join ICSInventoryLot c with(nolock) on b.LotNo=c.LotNo and b.WorkPoint=b.WorkPoint
  3755. left join ICSExtension c1 with(nolock) on c.ExtensionID=c1.ID and c.WorkPoint=c1.WorkPoint
  3756. left join ICSInventory d with(nolock) on c.InvCode=d.InvCode and c.WorkPoint=c.WorkPoint
  3757. left join ICSVendor e with(nolock) on a.VenCode=e.VenCode and a.WorkPoint=e.WorkPoint
  3758. left join ICSInventoryInspectionRulesGroup f with(nolock) on c.InvCode=f.InvCode and c.WorkPoint=f.WorkPoint
  3759. where 1=1
  3760. and a.WorkPoint = '{1}'
  3761. union all
  3762. select
  3763. distinct
  3764. b.ID DetailId --
  3765. ,c.ID LotNoId --ID
  3766. ,c.InvCode
  3767. ,d.InvName
  3768. ,c1.BatchCode as InvBatcgNo --
  3769. ,b.ODNQuantity --
  3770. ,a.VenCode --
  3771. ,e.VenName --
  3772. ,a.OAsnCode
  3773. ,b.EATTRIBUTE1 as IsUrgentitem --
  3774. ,d.InvUnit
  3775. ,c.Quantity as InvBatcgQty --
  3776. ,f.RulesCode
  3777. ,f.Id as InvRuleId
  3778. ,0 as AqlCheckQty --
  3779. ,0 as AllowNgQty --()
  3780. ,'' as Result
  3781. ,'' as WgNgFile
  3782. from ICSOASN a with(nolock)
  3783. left join ICSOASNDetail b with(nolock) on a.OASNCode=b.OASNCode and a.WorkPoint=b.WorkPoint
  3784. left join ICSInventoryLot c with(nolock) on b.LotNo=c.LotNo and b.WorkPoint=b.WorkPoint
  3785. left join ICSExtension c1 with(nolock) on c.ExtensionID=c1.ID and c.WorkPoint=c1.WorkPoint
  3786. left join ICSInventory d with(nolock) on c.InvCode=d.InvCode and c.WorkPoint=c.WorkPoint
  3787. left join ICSVendor e with(nolock) on a.VenCode=e.VenCode and a.WorkPoint=e.WorkPoint
  3788. left join ICSInventoryInspectionRulesGroup f with(nolock) on c.InvCode=f.InvCode and c.WorkPoint=f.WorkPoint
  3789. where 1=1
  3790. and a.WorkPoint = '{1}'
  3791. ) a
  3792. where 1=1
  3793. and a.DetailId='{0}'
  3794. ";
  3795. sql = string.Format(sql, keyValue, NFine.Code.OperatorProvider.Provider.GetCurrent().Location);
  3796. // sql = sql.Replace("{1}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  3797. var dt = Repository().FindDataSetBySql(sql.ToString(), parameter.ToArray()).Tables[0];
  3798. if (dt != null && dt.Rows.Count > 0)
  3799. {
  3800. var sql2 = @"select
  3801. a.*
  3802. from ICSInspectionRulesList a with(nolock)
  3803. where 1=1
  3804. and a.WorkPoint = '{1}'
  3805. and a.RulesID=(
  3806. select
  3807. a.ID
  3808. from ICSInspectionRulesGroup a with(nolock)
  3809. where 1=1
  3810. and a.RulesCode='{0}'
  3811. )
  3812. order by a.SetValueMin asc
  3813. ";
  3814. sql2 = string.Format(sql2, dt.Rows[0]["RulesCode"].ToString(), NFine.Code.OperatorProvider.Provider.GetCurrent().Location);
  3815. var dt2 = Repository().FindDataSetBySql(sql2.ToString(), parameter.ToArray()).Tables[0];
  3816. if (dt2 != null && dt2.Rows.Count > 0)
  3817. {
  3818. foreach (DataRow item in dt2.Rows)
  3819. {
  3820. if (item["SetValueMin"].ToDecimal() <= qty &&
  3821. item["SetValueMax"].ToDecimal() >= qty)
  3822. {
  3823. dt.Rows[0]["AqlCheckQty"] = item["SampleQuantity"].ToDecimal();
  3824. dt.Rows[0]["AllowNgQty"] = item["EATTRIBUTE1"].ToDecimal();
  3825. }
  3826. }
  3827. }
  3828. }
  3829. return dt;
  3830. }
  3831. public string UpdateUrgent(string keyValue)
  3832. {
  3833. string returnValue = string.Empty;
  3834. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  3835. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  3836. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  3837. try
  3838. {
  3839. var dtNow = DateTime.Now;
  3840. var models = JsonConvert.DeserializeObject<List<IcsMatCheckResultDto>>(keyValue);
  3841. if (models == null)
  3842. {
  3843. throw new Exception("传入参数错误");
  3844. }
  3845. foreach (var model in models)
  3846. {
  3847. var para = new
  3848. {
  3849. AsnCode = model.AsnCode,
  3850. InvBatcgNo = model.InvBatcgNo,
  3851. InvCode = model.InvCode,
  3852. WorkPoint = WorkPoint,
  3853. };
  3854. #region 送货单
  3855. var sql = @"
  3856. select a.* from ICSASNDetail a with(nolock)
  3857. where a.id in (
  3858. select
  3859. distinct a.Id
  3860. from ICSASNDetail a with(nolock)
  3861. left join ICSASN b with(nolock) on a.ASNCode=b.ASNCode
  3862. left join ICSInventoryLot c with(nolock) on a.LotNo=c.LotNo
  3863. left join ICSExtension c1 with(nolock) on c.ExtensionID=c1.ID
  3864. where 1=1
  3865. and a.ASNCode=@AsnCode
  3866. and c1.BatchCode=@InvBatcgNo
  3867. and c.InvCode=@InvCode
  3868. and a.WorkPoint=@WorkPoint
  3869. )
  3870. ";
  3871. var list = MsSqlData.Query<ICSASNDetailEntity>(sql, para).ToList();
  3872. foreach (var item in list)
  3873. {
  3874. if (item.EATTRIBUTE1 == "是")
  3875. {
  3876. continue;
  3877. }
  3878. item.EATTRIBUTE1 = "是";
  3879. item.MUSER = MUSER;
  3880. item.MUSERName = MUSERNAME;
  3881. item.MTIME = dtNow;
  3882. item.WorkPoint = WorkPoint;
  3883. var result2 = MsSqlData.Update<ICSASNDetailEntity>(item);
  3884. }
  3885. #endregion
  3886. #region 委外送货单
  3887. sql = @"select a.* from ICSOASNDetail a with(nolock)
  3888. where a.id in (
  3889. select
  3890. distinct a.Id
  3891. from ICSOASNDetail a with(nolock)
  3892. left join ICSOASN b with(nolock) on a.OASNCode=b.OASNCode
  3893. left join ICSInventoryLot c with(nolock) on a.LotNo=c.LotNo
  3894. left join ICSExtension c1 with(nolock) on c.ExtensionID=c1.ID
  3895. where 1=1
  3896. and a.OASNCode=@AsnCode
  3897. and c1.BatchCode=@InvBatcgNo
  3898. and c.InvCode=@InvCode
  3899. and a.WorkPoint=@WorkPoint
  3900. )
  3901. ";
  3902. var list2 = MsSqlData.Query<ICSOASNDetailEntity>(sql, para).ToList();
  3903. foreach (var item in list2)
  3904. {
  3905. if (item.EATTRIBUTE1 == "是")
  3906. {
  3907. continue;
  3908. }
  3909. item.EATTRIBUTE1 = "是";
  3910. item.MUSER = MUSER;
  3911. item.MUSERName = MUSERNAME;
  3912. item.MTIME = dtNow;
  3913. item.WorkPoint = WorkPoint;
  3914. var result2 = MsSqlData.Update<ICSOASNDetailEntity>(item);
  3915. }
  3916. #endregion
  3917. }
  3918. }
  3919. catch (Exception ex)
  3920. {
  3921. returnValue = ex.Message;
  3922. }
  3923. return returnValue;
  3924. }
  3925. public DataTable GetMaterialInStorageCheckDetailList(string id, string lotno, string invCode, ref Pagination pagination)
  3926. {
  3927. DataTable dt = new DataTable();
  3928. // var queryParam = queryJson.ToJObject();
  3929. List<DbParameter> parameter = new List<DbParameter>();
  3930. //object Figure = GetDecimalDigits();
  3931. #region [SQL]
  3932. string sql = @"select
  3933. ( Row_Number() over( ORDER BY a.ASNCode,a.InvBatcgNo,a.LotNo )) AS RowNo
  3934. ,a.*
  3935. from
  3936. (
  3937. select
  3938. distinct
  3939. a.ASNCode
  3940. ,d.TransCode
  3941. ,d.TransSequence
  3942. ,c.InvCode
  3943. ,inv.InvName
  3944. ,c1.BatchCode as InvBatcgNo --
  3945. ,b.LotNo
  3946. ,c.Quantity
  3947. ,f.ContainerCode as XiangCode--
  3948. ,g.ContainerCode as ZhanCode --
  3949. from ICSASN a with(nolock)
  3950. left join ICSASNDetail b with(nolock) on a.ASNCode=b.ASNCode and a.WorkPoint=b.WorkPoint
  3951. left join ICSInventoryLot c with(nolock) on b.LotNo=c.LotNo and b.WorkPoint=c.WorkPoint
  3952. left join ICSExtension c1 with(nolock) on c.ExtensionID=c1.ID
  3953. left join ICSInventoryLotDetail d on b.LotNo=d.LotNo and b.WorkPoint=b.WorkPoint
  3954. left join ICSInventory inv with(nolock) on c.InvCode=inv.InvCode and c.WorkPoint=inv.WorkPoint
  3955. left join ICSContainerLot e with(nolock) on b.LotNo=e.LotNo and b.WorkPoint=e.WorkPoint
  3956. left join ICSContainer f with(nolock) on e.ContainerID =f.ID and e.WorkPoint=f.WorkPoint
  3957. left join ICSContainer g with(nolock) on f.ContainerID=g.ID and g.ContainerType='ContainerType04' and f.WorkPoint=g.WorkPoint
  3958. where c.Quantity>0 AND 1=1
  3959. {0}
  3960. union all
  3961. select
  3962. distinct
  3963. a.OASNCode
  3964. ,d.TransCode
  3965. ,d.TransSequence
  3966. ,c.InvCode
  3967. ,inv.InvName
  3968. ,c1.BatchCode as InvBatcgNo --
  3969. ,b.LotNo
  3970. ,c.Quantity
  3971. ,f.ContainerCode as XiangCode--
  3972. ,g.ContainerCode as ZhanCode --
  3973. from ICSOASN a with(nolock)
  3974. left join ICSOASNDetail b with(nolock) on a.OASNCode=b.OASNCode and a.WorkPoint=b.WorkPoint
  3975. left join ICSInventoryLot c with(nolock) on b.LotNo=c.LotNo and b.WorkPoint=c.WorkPoint
  3976. left join ICSExtension c1 with(nolock) on c.ExtensionID=c1.ID
  3977. left join ICSInventoryLotDetail d on b.LotNo=d.LotNo and b.WorkPoint=b.WorkPoint
  3978. left join ICSInventory inv with(nolock) on c.InvCode=inv.InvCode and c.WorkPoint=inv.WorkPoint
  3979. left join ICSContainerLot e with(nolock) on b.LotNo=e.LotNo and b.WorkPoint=e.WorkPoint
  3980. left join ICSContainer f with(nolock) on e.ContainerID =f.ID and e.WorkPoint=f.WorkPoint
  3981. left join ICSContainer g with(nolock) on f.ContainerID=g.ID and g.ContainerType='ContainerType04' and f.WorkPoint=g.WorkPoint
  3982. where c.Quantity>0 AND 1=1
  3983. --and a.WorkPoint = 'UFDATA_106_2019'
  3984. -- and a.OASNCode='DN010000052200103' and c1.BatchCode=''
  3985. {0}
  3986. ) a
  3987. where a.InvCode='" + invCode + @"'
  3988. <1>
  3989. order by a.ASNCode,a.InvBatcgNo,a.LotNo
  3990. ";
  3991. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  3992. sql = sql.Replace("<1>", " and a.ASNCode='" + id + "' and a.InvBatcgNo='" + lotno + "' ");
  3993. sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  3994. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  3995. #endregion
  3996. return Repository().FindDataSetBySql(sql.ToString(), parameter.ToArray()).Tables[0];
  3997. }
  3998. public DataTable GetMaterialInStorageCheckPageList(string queryJson, ref Pagination pagination)
  3999. {
  4000. DataTable dt = new DataTable();
  4001. var queryParam = queryJson.ToJObject();
  4002. List<DbParameter> parameter = new List<DbParameter>();
  4003. //object Figure = GetDecimalDigits();
  4004. #region [SQL]
  4005. string sql = @"
  4006. select
  4007. a.*
  4008. from
  4009. (
  4010. select
  4011. distinct
  4012. max(b.ID) DetailId --
  4013. ,Max(c.ID) LotNoId --ID
  4014. ,c.InvCode
  4015. ,inv.InvName
  4016. ,c1.BatchCode as InvBatcgNo --
  4017. ,sum(b.DNQuantity) DNQuantity --
  4018. ,max(a.VenCode) VenCode --
  4019. ,max(e.VenName ) VenName --
  4020. ,a.ASNCode
  4021. ,max(b.EATTRIBUTE1) as IsUrgentItem --
  4022. ,max(inv.InvUnit) InvUnit
  4023. ,sum(c.Quantity) Quantity
  4024. ,max(c2.FileName) OutReport
  4025. ,max(c2.FilePath) FilePath
  4026. ,max(g.id) CheckID
  4027. ,case when max(g.CheckNo) is null then '否'else '是' end as IsCheck
  4028. ,max(g.Result) Result
  4029. ,max(g.FirstCheckTime) CheckDate
  4030. ,max(g.WHCode) WHCode
  4031. ,max(l.CreateDateTime) DHDate
  4032. ,max(l.DNCode) DNCode
  4033. ,'1' as DocType
  4034. from ICSASN a with(nolock)
  4035. left join ICSASNDetail b with(nolock) on a.ASNCode=b.ASNCode and a.WorkPoint=b.WorkPoint
  4036. left join ICSInventoryLot c with(nolock) on b.LotNo=c.LotNo and b.WorkPoint=b.WorkPoint
  4037. left join ICSInventoryLotDetail cc with(nolock) on b.lotno=cc.lotno and cc.WorkPoint=c.WorkPoint
  4038. left join ICSExtension c1 with(nolock) on c.ExtensionID=c1.ID
  4039. left join (
  4040. select *
  4041. from
  4042. (
  4043. select t.*
  4044. ,row_number() over(partition by t.ASNCode,t.BatchCode,t.invcode order by t.CerateTime desc) RowSeq
  4045. from ICSASNShippingReport t with(nolock)
  4046. ) t where t.RowSeq=1
  4047. ) c2 on a.ASNCode=c2.ASNCode and c1.BatchCode=c2.BatchCode and c.invcode=c2.invcode
  4048. left join ICSInventory inv with(nolock) on c.InvCode=inv.InvCode and c.WorkPoint=inv.WorkPoint
  4049. left join ICSVendor e with(nolock) on a.VenCode=e.VenCode and a.WorkPoint=e.WorkPoint
  4050. left join IcsMatCheckResult g with(nolock) on c.InvCode=g.InvCode and c1.BatchCode=g.InvBatcgNo and a.ASNCode=g.AsnCode
  4051. left join (SELECT ASNCode,InvCode,ExtensionID,max(CreateDateTime) CreateDateTime,max( t.DNCode) DNCode,PODetailID
  4052. from ICSDeliveryNotice t with(nolock) GROUP BY ASNCode,InvCode,ExtensionID,PODetailID ) l
  4053. on a.ASNCode=l.ASNCode and c.InvCode=l.InvCode and l.PODetailID=cc.TransCode+'~'+cc.TransSequence
  4054. where 1=1
  4055. <1>
  4056. {0}
  4057. and inv.InvIQC=1
  4058. and b.lotno not in
  4059. ( select a.LotNo from ICSASNDetail a
  4060. inner join ICSWareHouseLotInfo b on a.lotno=b.lotno
  4061. left join ICSInspection c on c.LotNo=a.LotNo
  4062. where c.lotno is null
  4063. )
  4064. group by c.InvCode,inv.InvName ,c1.BatchCode,a.ASNCode
  4065. union all
  4066. select
  4067. distinct
  4068. max(b.ID) DetailId --
  4069. ,Max(c.ID) LotNoId --ID
  4070. ,c.InvCode
  4071. ,d.InvName
  4072. ,c1.BatchCode as InvBatcgNo --
  4073. ,sum(b.ODNQuantity) DNQuantity --
  4074. ,max(a.VenCode) VenCode --
  4075. ,max(e.VenName ) VenName --
  4076. ,a.OASNCode as ASNCode
  4077. ,max(b.EATTRIBUTE1) as IsUrgentItem --
  4078. ,max(d.InvUnit) InvUnit
  4079. ,sum(c.Quantity) Quantity
  4080. ,max(c2.FileName) OutReport
  4081. ,max(c2.FilePath) FilePath
  4082. --,'' as OutReport
  4083. --,'' as FilePath
  4084. ,max(g.id) CheckID
  4085. ,case when max(g.CheckNo) is null then '否'else '是' end as IsCheck
  4086. ,max(g.Result) Result
  4087. ,max(g.FirstCheckTime) CheckDate
  4088. ,max(g.WHCode) WHCode
  4089. ,max(l.CreateDateTime) DHDate
  4090. ,max(l.DNCode) DNCode
  4091. ,'2' as DocType
  4092. from ICSOASN a with(nolock)
  4093. left join ICSOASNDetail b with(nolock) on a.OASNCode=b.OASNCode
  4094. left join ICSInventoryLot c with(nolock) on b.LotNo=c.LotNo
  4095. left join ICSInspection wl with(nolock) on b.LotNo=wl.LotNo and b.WorkPoint=wl.WorkPoint
  4096. left join ICSExtension c1 with(nolock) on c.ExtensionID=c1.ID
  4097. left join (
  4098. select *
  4099. from
  4100. (
  4101. select t.*
  4102. ,row_number() over(partition by t.ASNCode,t.BatchCode,t.invcode order by t.CerateTime desc) RowSeq
  4103. from ICSASNShippingReport t with(nolock)
  4104. ) t where t.RowSeq=1
  4105. ) c2 on a.OASNCode=c2.ASNCode and c1.BatchCode=c2.BatchCode and c.invcode=c2.invcode
  4106. left join ICSInventory d with(nolock) on c.InvCode=d.InvCode
  4107. left join ICSVendor e with(nolock) on a.VenCode=e.VenCode
  4108. left join IcsMatCheckResult g with(nolock) on c.InvCode=g.InvCode and c1.BatchCode=g.InvBatcgNo and a.OASNCode=g.AsnCode
  4109. left join (SELECT OASNCode,InvCode,ExtensionID,max(CreateDateTime) CreateDateTime,max( t.ODNCode) DNCode
  4110. from ICSODeliveryNotice t with(nolock) GROUP BY OASNCode,InvCode,ExtensionID )l on a.OASNCode=l.OASNCode and c.InvCode=l.InvCode and l.ExtensionID=c.ExtensionID
  4111. where 1=1
  4112. and d.InvIQC=1
  4113. and b.lotno not in
  4114. (select a.LotNo from ICSOASNDetail a
  4115. inner join ICSWareHouseLotInfo b on a.lotno=b.lotno
  4116. left join ICSInspection c on c.LotNo=a.LotNo
  4117. where c.lotno is null
  4118. )
  4119. {0}
  4120. <1>
  4121. group by c.InvCode,d.InvName ,c1.BatchCode,a.OASNCode
  4122. ) a
  4123. where 1=1 AND a.DNQuantity>0
  4124. <2>
  4125. <3>
  4126. <4>
  4127. <5>
  4128. <6>
  4129. <7>
  4130. <8>
  4131. <9>
  4132. <10>
  4133. <11>
  4134. ";
  4135. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  4136. //sql = string.Format(sql, Figure);
  4137. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  4138. #endregion
  4139. if (!string.IsNullOrWhiteSpace(queryJson))
  4140. {
  4141. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  4142. {
  4143. sql = sql.Replace("<1>", " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ");
  4144. }
  4145. else
  4146. {
  4147. sql = sql.Replace("<1>", " ");
  4148. }
  4149. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  4150. {
  4151. sql = sql.Replace("<2>", " and a.InvName like '%" + queryParam["InvName"].ToString() + "%' ");
  4152. }
  4153. else
  4154. {
  4155. sql = sql.Replace("<2>", " ");
  4156. }
  4157. if (!string.IsNullOrWhiteSpace(queryParam["StartDate"].ToString()))
  4158. {
  4159. sql = sql.Replace("<3>", " and a.DHDate>='" + queryParam["StartDate"].ToString() + " 00:00:00' ");
  4160. }
  4161. else
  4162. {
  4163. sql = sql.Replace("<3>", " ");
  4164. }
  4165. if (!string.IsNullOrWhiteSpace(queryParam["EndDate"].ToString()))
  4166. {
  4167. sql = sql.Replace("<4>", " and a.DHDate<='" + queryParam["EndDate"].ToString() + " 23:59:59' ");
  4168. }
  4169. else
  4170. {
  4171. sql = sql.Replace("<4>", " ");
  4172. }
  4173. if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString()))
  4174. {
  4175. sql = sql.Replace("<5>", " and a.ASNCode like '%" + queryParam["ASNCode"].ToString() + "%' ");
  4176. }
  4177. else
  4178. {
  4179. sql = sql.Replace("<5>", " ");
  4180. }
  4181. if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString()))
  4182. {
  4183. sql = sql.Replace("<6>", " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' ");
  4184. }
  4185. else
  4186. {
  4187. sql = sql.Replace("<6>", " ");
  4188. }
  4189. if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString()))
  4190. {
  4191. sql = sql.Replace("<7>", " and a.VenName like '%" + queryParam["VenName"].ToString() + "%' ");
  4192. }
  4193. else
  4194. {
  4195. sql = sql.Replace("<7>", " ");
  4196. }
  4197. if (!string.IsNullOrWhiteSpace(queryParam["InvBatcgNo"].ToString()))
  4198. {
  4199. sql = sql.Replace("<8>", " and a.InvBatcgNo like '%" + queryParam["InvBatcgNo"].ToString() + "%' ");
  4200. }
  4201. else
  4202. {
  4203. sql = sql.Replace("<8>", " ");
  4204. }
  4205. if (!string.IsNullOrWhiteSpace(queryParam["IsCheck"].ToString()))
  4206. {
  4207. sql = sql.Replace("<9>", " and a.IsCheck='" + queryParam["IsCheck"].ToString() + "' ");
  4208. }
  4209. else
  4210. {
  4211. sql = sql.Replace("<9>", " ");
  4212. }
  4213. if (!string.IsNullOrWhiteSpace(queryParam["CheckStartDate"].ToString()))
  4214. {
  4215. sql = sql.Replace("<10>", " and a.CheckDate>='" + queryParam["CheckStartDate"].ToString() + " 00:00:00' ");
  4216. }
  4217. else
  4218. {
  4219. sql = sql.Replace("<10>", " ");
  4220. }
  4221. if (!string.IsNullOrWhiteSpace(queryParam["CheckEndDate"].ToString()))
  4222. {
  4223. sql = sql.Replace("<11>", " and a.CheckDate<='" + queryParam["CheckEndDate"].ToString() + " 23:59:59' ");
  4224. }
  4225. else
  4226. {
  4227. sql = sql.Replace("<11>", " ");
  4228. }
  4229. }
  4230. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  4231. //{
  4232. sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  4233. // // sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  4234. //}
  4235. //else
  4236. //{
  4237. // sql = sql.Replace("{0}", "");
  4238. //}
  4239. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  4240. //{
  4241. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  4242. //}
  4243. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref pagination);
  4244. }
  4245. public string DeleteItem2CheckItem(string keyValue)
  4246. {
  4247. string returnValue = string.Empty;
  4248. try
  4249. {
  4250. var idList = JsonConvert.DeserializeObject<List<string>>(keyValue);
  4251. string sql = @"select
  4252. a.*
  4253. from ICSInventoryInspectionGroup a with(nolock)
  4254. where a.InvCode in ('" + string.Join("','", idList) + "')";
  4255. var entityList = MsSqlData.Query<ICSInventoryInspectionGroupEntity>(sql).ToList();
  4256. foreach (var item in entityList)
  4257. {
  4258. var delSql = @" delete from ICSInventoryInspectionGroup where id='" + item.ID + "' " +
  4259. " delete from ICSInventoryInspectionList where InvGroupID='" + item.ID + "' ";
  4260. var result = MsSqlData.Execute(delSql);
  4261. }
  4262. //var result = MsSqlData.Delete<ICSInventoryInspectionGroupEntity>(entityList);
  4263. //if (!result)
  4264. //{
  4265. // returnValue = "删除失败";
  4266. //}
  4267. }
  4268. catch (Exception ex)
  4269. {
  4270. returnValue = ex.Message;
  4271. }
  4272. return returnValue;
  4273. }
  4274. public string SaveItem2CheckItem(string keyValue)
  4275. {
  4276. string returnValue = string.Empty;
  4277. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  4278. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  4279. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4280. var connString = MsSqlData.FromMd5(ConfigurationManager.ConnectionStrings["connstr"].ConnectionString);
  4281. try
  4282. {
  4283. var dtNow = DateTime.Now;
  4284. var model = JsonConvert.DeserializeObject<ICSInventoryInspectionGroupDto>(keyValue);
  4285. if (model == null)
  4286. {
  4287. throw new Exception("传入参数错误");
  4288. }
  4289. using (var connection = new SqlConnection())
  4290. {
  4291. connection.ConnectionString = connString;
  4292. connection.Open();
  4293. using (var trans = connection.BeginTransaction())
  4294. {
  4295. try
  4296. {
  4297. if (model.CheckItemList.GroupBy(x => new { x.ListCode, x.InvCode }).Count() != model.CheckItemList.Count)
  4298. {
  4299. throw new Exception("当前物料检验项目代码重复");
  4300. }
  4301. foreach (var item in model.CheckItemList)
  4302. {
  4303. //string dtPre = DateTime.Now.ToString("yyyyMMdd");
  4304. //string sql = @"EXEC Addins_GetSerialCode '" + WorkPoint + "','ICSInventoryInspectionGroup','GroupCode','" + "IGC" + dtPre + "',3";
  4305. //var serialNo = MsSqlData.ExecuteScalar(sql).ToStringExt();
  4306. var entity = new ICSInventoryInspectionGroupEntity();
  4307. entity.InvCode = item.InvCode;
  4308. entity.GroupCode = model.GroupCode;
  4309. entity.GroupName = model.GroupCodeName;
  4310. entity.Enable = true;
  4311. entity.EATTRIBUTE1 = item.CheckAttr;
  4312. entity.ID = Guid.NewGuid().ToString();
  4313. entity.MUSER = MUSER;
  4314. entity.MUSERName = MUSERNAME;
  4315. entity.MTIME = dtNow;
  4316. entity.WorkPoint = WorkPoint;
  4317. connection.Insert<ICSInventoryInspectionGroupEntity>(entity, trans);
  4318. var detail = new ICSInventoryInspectionListEntity();
  4319. detail = ConvertExt.Mapping<ICSInventoryInspectionListDto, ICSInventoryInspectionListEntity>(item);
  4320. detail.InvGroupID = entity.ID;
  4321. detail.ID = Guid.NewGuid().ToString();
  4322. detail.MUSER = MUSER;
  4323. detail.MUSERName = MUSERNAME;
  4324. detail.MTIME = dtNow;
  4325. detail.WorkPoint = WorkPoint;
  4326. var sql4Count = @" select
  4327. count(1)
  4328. from
  4329. (
  4330. select
  4331. a.ID
  4332. , c.InvCode
  4333. , c.InvName
  4334. , a.ListCode
  4335. , a.ListName
  4336. , b.EATTRIBUTE1 as CheckAttr --
  4337. from ICSInventoryInspectionList a with(nolock)
  4338. left join ICSInventoryInspectionGroup b with(nolock) on a.InvGroupID = b.ID
  4339. left join ICSInventory c with(nolock) on b.InvCode = c.InvCode
  4340. ) a
  4341. where 1 = 1
  4342. and a.InvCode = @InvCode and a.ListCode=@ListCode ";
  4343. var para2 = new { InvCode = item.InvCode, ListCode = item.ListCode };
  4344. var count = connection.ExecuteScalar<int>(sql4Count, para2, trans);
  4345. if (count > 0)
  4346. {
  4347. throw new Exception("当前物料检验项目关系已经存在");
  4348. }
  4349. connection.Insert<ICSInventoryInspectionListEntity>(detail, trans);
  4350. }
  4351. trans.Commit();
  4352. }
  4353. catch (Exception ex)
  4354. {
  4355. trans.Rollback();
  4356. throw ex;
  4357. }
  4358. }
  4359. }
  4360. }
  4361. catch (Exception ex)
  4362. {
  4363. returnValue = ex.Message;
  4364. }
  4365. return returnValue;
  4366. }
  4367. public string UpdateItem2CheckItem(string keyValue)
  4368. {
  4369. string returnValue = string.Empty;
  4370. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  4371. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  4372. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4373. var connString = MsSqlData.FromMd5(ConfigurationManager.ConnectionStrings["connstr"].ConnectionString);
  4374. try
  4375. {
  4376. var dtNow = DateTime.Now;
  4377. var model = JsonConvert.DeserializeObject<ICSInventoryInspectionGroupDto>(keyValue);
  4378. if (model == null)
  4379. {
  4380. throw new Exception("传入参数错误");
  4381. }
  4382. // 校验:确保检验项目列表不为空
  4383. if (model.CheckItemList == null || !model.CheckItemList.Any())
  4384. {
  4385. throw new Exception("检验项目列表不能为空");
  4386. }
  4387. // 获取当前操作的物料编码(假设所有检验项目属于同一个物料,取第一个即可)
  4388. string targetInvCode = model.CheckItemList.FirstOrDefault()?.InvCode;
  4389. if (string.IsNullOrEmpty(targetInvCode))
  4390. {
  4391. throw new Exception("物料编码不能为空");
  4392. }
  4393. // 获取当前操作的检验项目组编码
  4394. string targetGroupCode = model.GroupCode;
  4395. if (string.IsNullOrEmpty(targetGroupCode))
  4396. {
  4397. throw new Exception("检验项目组编码不能为空");
  4398. }
  4399. using (var connection = new SqlConnection(connString))
  4400. {
  4401. connection.Open();
  4402. using (var trans = connection.BeginTransaction())
  4403. {
  4404. try
  4405. {
  4406. // 1. 先删除关联的明细表数据(ICSInventoryInspectionList)
  4407. // 条件:通过主表ID关联,主表的InvCode和GroupCode匹配当前操作
  4408. string deleteDetailSql = @"
  4409. DELETE FROM ICSInventoryInspectionList
  4410. WHERE InvGroupID IN (
  4411. SELECT ID FROM ICSInventoryInspectionGroup
  4412. WHERE InvCode = @InvCode AND GroupCode = @GroupCode
  4413. )";
  4414. var deleteDetailParams = new { InvCode = targetInvCode, GroupCode = targetGroupCode };
  4415. connection.Execute(deleteDetailSql, deleteDetailParams, trans);
  4416. // 2. 再删除主表数据(ICSInventoryInspectionGroup)
  4417. string deleteMainSql = @"
  4418. DELETE FROM ICSInventoryInspectionGroup
  4419. WHERE InvCode = @InvCode AND GroupCode = @GroupCode";
  4420. var deleteMainParams = new { InvCode = targetInvCode, GroupCode = targetGroupCode };
  4421. connection.Execute(deleteMainSql, deleteMainParams, trans);
  4422. // 3. 校验检验项目是否重复(原有逻辑保留)
  4423. if (model.CheckItemList.GroupBy(x => new { x.ListCode, x.InvCode }).Count() != model.CheckItemList.Count)
  4424. {
  4425. throw new Exception("当前物料检验项目代码重复");
  4426. }
  4427. // 4. 新增数据(原有逻辑保留,新增前已删除旧数据)
  4428. foreach (var item in model.CheckItemList)
  4429. {
  4430. // 新增主表记录
  4431. var entity = new ICSInventoryInspectionGroupEntity();
  4432. entity.InvCode = item.InvCode;
  4433. entity.GroupCode = model.GroupCode;
  4434. entity.GroupName = model.GroupCodeName; // 建议从DTO中获取GroupName,避免与Code一致
  4435. entity.Enable = true;
  4436. entity.EATTRIBUTE1 = item.CheckAttr;
  4437. entity.ID = Guid.NewGuid().ToString();
  4438. entity.MUSER = MUSER;
  4439. entity.MUSERName = MUSERNAME;
  4440. entity.MTIME = dtNow;
  4441. entity.WorkPoint = WorkPoint;
  4442. connection.Insert<ICSInventoryInspectionGroupEntity>(entity, trans);
  4443. // 新增明细表记录
  4444. var detail = ConvertExt.Mapping<ICSInventoryInspectionListDto, ICSInventoryInspectionListEntity>(item);
  4445. detail.InvGroupID = entity.ID; // 关联主表ID
  4446. detail.ID = Guid.NewGuid().ToString();
  4447. detail.MUSER = MUSER;
  4448. detail.MUSERName = MUSERNAME;
  4449. detail.MTIME = dtNow;
  4450. detail.WorkPoint = WorkPoint;
  4451. connection.Insert<ICSInventoryInspectionListEntity>(detail, trans);
  4452. }
  4453. trans.Commit();
  4454. }
  4455. catch (Exception ex)
  4456. {
  4457. trans.Rollback();
  4458. throw ex;
  4459. }
  4460. }
  4461. }
  4462. }
  4463. catch (Exception ex)
  4464. {
  4465. returnValue = ex.Message;
  4466. }
  4467. return returnValue;
  4468. }
  4469. public DataTable ExportAllItem2CheckItem(string invCode, string invName, string ListCode, string ListName)
  4470. {
  4471. DataTable dt = new DataTable();
  4472. // var queryParam = queryJson.ToJObject();
  4473. List<DbParameter> parameter = new List<DbParameter>();
  4474. //object Figure = GetDecimalDigits();
  4475. #region [SQL]
  4476. string sql = @"
  4477. select
  4478. a.*
  4479. from
  4480. (
  4481. select
  4482. a.ID
  4483. ,c.InvCode
  4484. ,c.InvName
  4485. ,a.ListCode
  4486. ,a.ListName
  4487. ,b.EATTRIBUTE1 as CheckAttr --
  4488. ,( select t.label from V_QuerySysEnumItem t where t.value=b.EATTRIBUTE1 and t.F_EnCode='CheckAttr'
  4489. ) as CheckAttrText
  4490. ,a.SetValueMax
  4491. ,a.SetValueMin
  4492. ,a.Unit
  4493. ,a.Enable
  4494. ,a.MUSER
  4495. ,a.MUSERName
  4496. ,a.MTIME
  4497. from ICSInventoryInspectionList a with(nolock)
  4498. left join ICSInventoryInspectionGroup b with(nolock) on a.InvGroupID=b.ID
  4499. left join ICSInventory c with(nolock) on b.InvCode=c.InvCode
  4500. where 1=1
  4501. {0}
  4502. ) a
  4503. where 1=1
  4504. <1>
  4505. <2>
  4506. <3>
  4507. <4> ";
  4508. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  4509. //sql = string.Format(sql, Figure);
  4510. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  4511. #endregion
  4512. if (!string.IsNullOrWhiteSpace(invCode))
  4513. {
  4514. sql = sql.Replace("<1>", " and a.InvCode like '%" + invCode + "%' ");
  4515. }
  4516. else
  4517. {
  4518. sql = sql.Replace("<1>", " ");
  4519. }
  4520. if (!string.IsNullOrWhiteSpace(invName))
  4521. {
  4522. sql = sql.Replace("<2>", " and a.InvName like '%" + invName + "%' ");
  4523. }
  4524. else
  4525. {
  4526. sql = sql.Replace("<2>", " ");
  4527. }
  4528. if (!string.IsNullOrWhiteSpace(ListCode))
  4529. {
  4530. sql = sql.Replace("<3>", " and a.ListCode =" + ListCode + " ");
  4531. }
  4532. else
  4533. {
  4534. sql = sql.Replace("<3>", " ");
  4535. }
  4536. if (!string.IsNullOrWhiteSpace(ListName))
  4537. {
  4538. sql = sql.Replace("<4>", " and a.ListName =" + ListName + " ");
  4539. }
  4540. else
  4541. {
  4542. sql = sql.Replace("<4>", " ");
  4543. }
  4544. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  4545. //{
  4546. sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  4547. // // sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  4548. //}
  4549. //else
  4550. //{
  4551. // sql = sql.Replace("{0}", "");
  4552. //}
  4553. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  4554. //{
  4555. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  4556. //}
  4557. return Repository().FindDataSetBySql(sql.ToString(), parameter.ToArray()).Tables[0];
  4558. }
  4559. /// <summary>
  4560. /// 查询物料检验项目关联表(主表)
  4561. /// </summary>
  4562. /// <param name="queryJson"></param>
  4563. /// <param name="pagination"></param>
  4564. /// <returns></returns>
  4565. public DataTable GetItemMainGridJson(string queryJson, ref Pagination pagination)
  4566. {
  4567. DataTable dt = new DataTable();
  4568. var queryParam = queryJson.ToJObject();
  4569. List<DbParameter> parameter = new List<DbParameter>();
  4570. //object Figure = GetDecimalDigits();
  4571. #region [SQL]
  4572. string sql = @"
  4573. select
  4574. a.*
  4575. from
  4576. (select distinct
  4577. a.InvCode
  4578. ,b.InvName
  4579. ,a.GroupCode
  4580. ,a.GroupName
  4581. ,a.MUSER
  4582. ,a.MUSERName
  4583. ,a.MTIME
  4584. from ICSInventoryInspectionGroup a with(nolock)
  4585. left join ICSInventory b with(nolock) on b.InvCode=a.InvCode and b.WorkPoint=a.WorkPoint
  4586. where 1=1
  4587. {0}
  4588. ) a
  4589. where 1=1
  4590. <1>
  4591. <2>
  4592. <3>
  4593. <4>
  4594. ";
  4595. #endregion
  4596. if (!string.IsNullOrWhiteSpace(queryJson))
  4597. {
  4598. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  4599. {
  4600. sql = sql.Replace("<1>", " and a.InvCode = '" + queryParam["InvCode"].ToString() + "' ");
  4601. }
  4602. else
  4603. {
  4604. sql = sql.Replace("<1>", " ");
  4605. }
  4606. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  4607. {
  4608. sql = sql.Replace("<2>", " and a.InvName like '%" + queryParam["InvName"].ToString() + "%' ");
  4609. }
  4610. else
  4611. {
  4612. sql = sql.Replace("<2>", " ");
  4613. }
  4614. if (!string.IsNullOrWhiteSpace(queryParam["GroupCode"].ToString()))
  4615. {
  4616. sql = sql.Replace("<3>", " and a.GroupCode ='" + queryParam["GroupCode"].ToString() + "' ");
  4617. }
  4618. else
  4619. {
  4620. sql = sql.Replace("<3>", " ");
  4621. }
  4622. if (!string.IsNullOrWhiteSpace(queryParam["GroupName"].ToString()))
  4623. {
  4624. sql = sql.Replace("<4>", " and a.GroupName like '%" + queryParam["GroupName"].ToString() + "%' ");
  4625. }
  4626. else
  4627. {
  4628. sql = sql.Replace("<4>", " ");
  4629. }
  4630. }
  4631. sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  4632. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref pagination);
  4633. }
  4634. public DataTable GetItemSubGridJson(string InvCode, ref Pagination pagination)
  4635. {
  4636. DataTable dt = new DataTable();
  4637. List<DbParameter> parameter = new List<DbParameter>();
  4638. string ordersql = "";
  4639. #region [SQL]
  4640. string sql = @"
  4641. select
  4642. a.*
  4643. from
  4644. (
  4645. select
  4646. a.ID
  4647. ,c.InvCode
  4648. ,c.InvName
  4649. ,a.ListCode
  4650. ,a.ListName
  4651. ,a.SetValueMax
  4652. ,a.SetValueMin
  4653. ,a.Unit
  4654. ,a.Enable
  4655. ,a.MUSER
  4656. ,a.MUSERName
  4657. ,a.MTIME
  4658. ,a.EATTRIBUTE1
  4659. ,a.EATTRIBUTE2
  4660. ,a.EATTRIBUTE3
  4661. ,a.EATTRIBUTE5
  4662. ,a.EATTRIBUTE6
  4663. ,b.Name as Type,case when a.EATTRIBUTE4='true' then '是' else '否' end CEATTRIBUTE4
  4664. , case when a.Enable='1' then '是' else '否' end CEnable
  4665. from ICSInventoryInspectionList a with(nolock)
  4666. left join ICSInventoryInspectionGroup d with(nolock) on a.InvGroupID=d.ID
  4667. left join ICSInventory c with(nolock) on d.InvCode=c.InvCode
  4668. LEFT JOIN ICSType b ON a.WorkPoint=b.WorkPoint AND b.TableCode='ICSInventoryInspectionList' AND b.ColumnCode='EATTRIBUTE6' AND a.EATTRIBUTE6=b.Code AND b.Enable='1'
  4669. where 1=1
  4670. {0}
  4671. ) a
  4672. where a.InvCode = '" + InvCode + @"'
  4673. ";
  4674. #endregion
  4675. ordersql = @" order by
  4676. case when EATTRIBUTE6 = 'Size' then 1
  4677. when EATTRIBUTE6 = 'Carton' then 2
  4678. else 3 end,
  4679. SetValueMin asc";
  4680. sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  4681. return Repository().FindTablePageBySql(sql.ToString(),ordersql.ToString(), parameter.ToArray(), ref pagination);
  4682. }
  4683. public string DeleteCheckItemGroup(string keyValue)
  4684. {
  4685. string returnValue = string.Empty;
  4686. try
  4687. {
  4688. var idList = JsonConvert.DeserializeObject<List<string>>(keyValue);
  4689. string sql = @"select
  4690. a.*
  4691. from ICSInspectionGroup a with(nolock)
  4692. where a.ID in ('" + string.Join("','", idList) + "')";
  4693. var entityList = MsSqlData.Query<ICSInspectionGroupEntity>(sql).ToList();
  4694. foreach (var item in entityList)
  4695. {
  4696. //var count = MsSqlData.ExecuteScalar(" select count(1) from IcsCheckingFixtureTransfer with(nolock) where CheckFixtureNo='" + item.CheckFixtureNo + "'").ToInt();
  4697. //if (count > 0)
  4698. //{
  4699. // throw new Exception("当前检具已经存在履历,不能删除");
  4700. //}
  4701. var count = MsSqlData.ExecuteScalar
  4702. (
  4703. " select count(1) from ICSInventoryInspectionGroup with(nolock) where GroupCode='" + item.GroupCode + "' "
  4704. ).ToInt();
  4705. if (count > 0)
  4706. {
  4707. throw new Exception("当前物料检验类型关系已经存在,不能删除");
  4708. }
  4709. }
  4710. var result = MsSqlData.Delete<ICSInspectionGroupEntity>(entityList);
  4711. if (!result)
  4712. {
  4713. returnValue = "删除失败";
  4714. }
  4715. string sql2 = @"delete from ICSInspectionList where GroupID in ('" + string.Join("','", idList) + "')";
  4716. var line = Repository().ExecuteBySql(new StringBuilder(sql2));
  4717. }
  4718. catch (Exception ex)
  4719. {
  4720. returnValue = ex.Message;
  4721. }
  4722. return returnValue;
  4723. }
  4724. public string SaveCheckItemGroup(string keyValue)
  4725. {
  4726. string returnValue = string.Empty;
  4727. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  4728. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  4729. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4730. try
  4731. {
  4732. var dtNow = DateTime.Now;
  4733. var model = JsonConvert.DeserializeObject<ICSInspectionGroupDto>(keyValue);
  4734. if (model == null)
  4735. {
  4736. throw new Exception("传入参数错误");
  4737. }
  4738. if (model.DetailList != null && model.DetailList.Count > 0)
  4739. {
  4740. if (model.DetailList.Select(x => x.ListCode).Distinct().Count() != model.DetailList.Count)
  4741. {
  4742. throw new Exception("检验项目代码重复");
  4743. }
  4744. }
  4745. if (model.ID.IsNullOrEmpty())
  4746. {
  4747. //新增
  4748. var count = MsSqlData.ExecuteScalar(" select count(1) from ICSInspectionGroup with(nolock) where GroupCode='" + model.GroupCode + "'").ToInt();
  4749. if (count > 0)
  4750. {
  4751. throw new Exception("当前检验类型已经存在");
  4752. }
  4753. model.ID = Guid.NewGuid().ToString();
  4754. model.MUSER = MUSER;
  4755. model.MUSERName = MUSERNAME;
  4756. model.MTIME = dtNow;
  4757. model.WorkPoint = WorkPoint;
  4758. var result = MsSqlData.Insert<ICSInspectionGroupEntity>(model);
  4759. if (!result)
  4760. {
  4761. returnValue = "新增失败";
  4762. }
  4763. foreach (var item in model.DetailList)
  4764. {
  4765. var detailEntity = ConvertExt.Mapping<ICSInspectionListDto, ICSInspectionListEntity>(item);
  4766. detailEntity.ID = Guid.NewGuid().ToString();
  4767. detailEntity.GroupID = model.ID;
  4768. detailEntity.MUSER = MUSER;
  4769. detailEntity.MUSERName = MUSERNAME;
  4770. detailEntity.MTIME = dtNow;
  4771. detailEntity.WorkPoint = WorkPoint;
  4772. var result2 = MsSqlData.Insert<ICSInspectionListEntity>(detailEntity);
  4773. if (!result2)
  4774. {
  4775. returnValue = "新增失败";
  4776. }
  4777. }
  4778. }
  4779. else
  4780. {
  4781. //修改
  4782. var entity = MsSqlData.Get<ICSInspectionGroupEntity>(model.ID);
  4783. if (entity == null)
  4784. {
  4785. throw new Exception("当前数据不存在");
  4786. }
  4787. ConvertExt.Mapping<ICSInspectionGroupDto, ICSInspectionGroupEntity>(model, entity);
  4788. entity.MUSER = MUSER;
  4789. entity.MUSERName = MUSERNAME;
  4790. entity.MTIME = dtNow;
  4791. var result = MsSqlData.Update<ICSInspectionGroupEntity>(entity);
  4792. if (!result)
  4793. {
  4794. returnValue = "修改失败";
  4795. }
  4796. string sql = @"select
  4797. a.*
  4798. from ICSInspectionList a with(nolock)
  4799. where a.GroupID ='" + entity.ID + "' ";
  4800. var entityList = MsSqlData.Query<ICSInspectionListEntity>(sql).ToList();
  4801. MsSqlData.Delete<ICSInspectionListEntity>(entityList);
  4802. foreach (var item in model.DetailList)
  4803. {
  4804. var detailEntity = ConvertExt.Mapping<ICSInspectionListDto, ICSInspectionListEntity>(item);
  4805. detailEntity.ID = Guid.NewGuid().ToString();
  4806. detailEntity.GroupID = model.ID;
  4807. detailEntity.MUSER = MUSER;
  4808. detailEntity.MUSERName = MUSERNAME;
  4809. detailEntity.MTIME = dtNow;
  4810. detailEntity.WorkPoint = WorkPoint;
  4811. var result2 = MsSqlData.Insert<ICSInspectionListEntity>(detailEntity);
  4812. if (!result2)
  4813. {
  4814. returnValue = "修改失败";
  4815. }
  4816. }
  4817. }
  4818. }
  4819. catch (Exception ex)
  4820. {
  4821. returnValue = ex.Message;
  4822. }
  4823. return returnValue;
  4824. }
  4825. public ICSInspectionGroupDto GetCheckItemGroup(string keyValue)
  4826. {
  4827. var returnValue = new ICSInspectionGroupDto();
  4828. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  4829. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  4830. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4831. try
  4832. {
  4833. var entity = MsSqlData.Get<ICSInspectionGroupEntity>(keyValue);
  4834. if (entity == null)
  4835. {
  4836. throw new Exception("获取单个检验项目组失败");
  4837. }
  4838. returnValue = ConvertExt.Mapping<ICSInspectionGroupEntity, ICSInspectionGroupDto>(entity);
  4839. var para = new { WorkPoint = WorkPoint };
  4840. string sql = @"select
  4841. a.*
  4842. from ICSInspectionList a with(nolock)
  4843. where a.GroupID ='" + entity.ID + "' and a.WorkPoint=@WorkPoint " +
  4844. "order by a.ListCode asc ";
  4845. var entityList = MsSqlData.Query<ICSInspectionListDto>(sql, para).ToList();
  4846. //int i = 0;
  4847. for (int i = 0; i < entityList.Count; i++)
  4848. {
  4849. entityList[i].key = i + 1;
  4850. }
  4851. returnValue.DetailList = entityList;
  4852. }
  4853. catch (Exception ex)
  4854. {
  4855. returnValue = null;
  4856. }
  4857. return returnValue;
  4858. }
  4859. public DataTable ExportAllBadReasonGroup(string bRGCode, string bRGDesc)
  4860. {
  4861. DataTable dt = new DataTable();
  4862. // var queryParam = queryJson.ToJObject();
  4863. List<DbParameter> parameter = new List<DbParameter>();
  4864. //object Figure = GetDecimalDigits();
  4865. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  4866. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  4867. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4868. #region [SQL]
  4869. string sql = @"
  4870. select
  4871. a.*
  4872. from ICSBadReasonGroup a with(nolock)
  4873. where 1=1
  4874. {0}
  4875. <1>
  4876. <2>
  4877. ";
  4878. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  4879. //sql = string.Format(sql, Figure);
  4880. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  4881. #endregion
  4882. if (!string.IsNullOrWhiteSpace(bRGCode))
  4883. {
  4884. sql = sql.Replace("<1>", " and a.bRGCode like '%" + bRGCode + "%' ");
  4885. }
  4886. else
  4887. {
  4888. sql = sql.Replace("<1>", " ");
  4889. }
  4890. if (!string.IsNullOrWhiteSpace(bRGDesc))
  4891. {
  4892. sql = sql.Replace("<2>", " and a.bRGDesc like '%" + bRGDesc + "%' ");
  4893. }
  4894. else
  4895. {
  4896. sql = sql.Replace("<2>", " ");
  4897. }
  4898. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  4899. //{
  4900. sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  4901. // // sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  4902. //}
  4903. //else
  4904. //{
  4905. // sql = sql.Replace("{0}", "");
  4906. //}
  4907. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  4908. //{
  4909. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  4910. //}
  4911. return Repository().FindDataSetBySql(sql.ToString(), parameter.ToArray()).Tables[0];
  4912. }
  4913. public string DeleteBadReasonGroup(string keyValue)
  4914. {
  4915. string returnValue = string.Empty;
  4916. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  4917. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  4918. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4919. var para = new { WorkPoint = WorkPoint };
  4920. try
  4921. {
  4922. var idList = JsonConvert.DeserializeObject<List<string>>(keyValue);
  4923. string sql = @"select
  4924. a.*
  4925. from ICSBadReasonGroup a with(nolock)
  4926. where a.ID in ('" + string.Join("','", idList) + "') and a.WorkPoint=@WorkPoint ";
  4927. var entityList = MsSqlData.Query<ICSBadReasonGroupEntity>(sql, para).ToList();
  4928. foreach (var item in entityList)
  4929. {
  4930. //var count = MsSqlData.ExecuteScalar(" select count(1) from IcsCheckingFixtureTransfer with(nolock) where CheckFixtureNo='" + item.CheckFixtureNo + "'").ToInt();
  4931. //if (count > 0)
  4932. //{
  4933. // throw new Exception("当前检具已经存在履历,不能删除");
  4934. //}
  4935. }
  4936. var result = MsSqlData.Delete<ICSBadReasonGroupEntity>(entityList);
  4937. if (!result)
  4938. {
  4939. returnValue = "删除失败";
  4940. }
  4941. string sql2 = @"delete from ICSBadReason where BRGroupID in ('" + string.Join("','", idList) + "') and WorkPoint=@WorkPoint";
  4942. var line = MsSqlData.Execute(sql2, para);
  4943. }
  4944. catch (Exception ex)
  4945. {
  4946. returnValue = ex.Message;
  4947. }
  4948. return returnValue;
  4949. }
  4950. public string SaveBadReasonGroup(string keyValue)
  4951. {
  4952. string returnValue = string.Empty;
  4953. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  4954. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  4955. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  4956. var para = new { WorkPoint = WorkPoint };
  4957. try
  4958. {
  4959. var dtNow = DateTime.Now;
  4960. var model = JsonConvert.DeserializeObject<ICSBadReasonGroupDto>(keyValue);
  4961. if (model == null)
  4962. {
  4963. throw new Exception("传入参数错误");
  4964. }
  4965. if (model.ID.IsNullOrEmpty())
  4966. {
  4967. //新增
  4968. var sql1 = @" select count(1) from ICSBadReasonGroup a with(nolock) where BRGCode='" + model.BRGCode + "' and a.WorkPoint=@WorkPoint";
  4969. var count = MsSqlData.ExecuteScalar(sql1, para).ToInt();
  4970. if (count > 0)
  4971. {
  4972. throw new Exception("当前不良状态已经存在");
  4973. }
  4974. model.ID = Guid.NewGuid().ToString();
  4975. model.MUSER = MUSER;
  4976. model.MUSERName = MUSERNAME;
  4977. model.MTIME = dtNow;
  4978. model.WorkPoint = WorkPoint;
  4979. var result = MsSqlData.Insert<ICSBadReasonGroupEntity>(model);
  4980. if (!result)
  4981. {
  4982. returnValue = "新增失败";
  4983. }
  4984. foreach (var item in model.DetailList)
  4985. {
  4986. var detailEntity = ConvertExt.Mapping<ICSBadReasonDto, ICSBadReasonEntity>(item);
  4987. detailEntity.ID = Guid.NewGuid().ToString();
  4988. detailEntity.BRGroupID = model.ID;
  4989. detailEntity.MUSER = MUSER;
  4990. detailEntity.MUSERName = MUSERNAME;
  4991. detailEntity.MTIME = dtNow;
  4992. detailEntity.WorkPoint = WorkPoint;
  4993. var result2 = MsSqlData.Insert<ICSBadReasonEntity>(detailEntity);
  4994. if (!result2)
  4995. {
  4996. returnValue = "新增失败";
  4997. }
  4998. }
  4999. }
  5000. else
  5001. {
  5002. //修改
  5003. var entity = MsSqlData.Get<ICSBadReasonGroupEntity>(model.ID);
  5004. if (entity == null)
  5005. {
  5006. throw new Exception("当前数据不存在");
  5007. }
  5008. ConvertExt.Mapping<ICSBadReasonGroupDto, ICSBadReasonGroupEntity>(model, entity);
  5009. entity.MUSER = MUSER;
  5010. entity.MUSERName = MUSERNAME;
  5011. entity.MTIME = dtNow;
  5012. var result = MsSqlData.Update<ICSBadReasonGroupEntity>(entity);
  5013. if (!result)
  5014. {
  5015. returnValue = "修改失败";
  5016. }
  5017. string sql = @"select
  5018. a.*
  5019. from ICSBadReason a with(nolock)
  5020. where a.BRGroupID ='" + entity.ID + "' and a.WorkPoint=@WorkPoint ";
  5021. var entityList = MsSqlData.Query<ICSBadReasonEntity>(sql, para).ToList();
  5022. MsSqlData.Delete<ICSBadReasonEntity>(entityList);
  5023. foreach (var item in model.DetailList)
  5024. {
  5025. var detailEntity = ConvertExt.Mapping<ICSBadReasonDto, ICSBadReasonEntity>(item);
  5026. detailEntity.ID = Guid.NewGuid().ToString();
  5027. detailEntity.BRGroupID = model.ID;
  5028. detailEntity.MUSER = MUSER;
  5029. detailEntity.MUSERName = MUSERNAME;
  5030. detailEntity.MTIME = dtNow;
  5031. detailEntity.WorkPoint = WorkPoint;
  5032. var result2 = MsSqlData.Insert<ICSBadReasonEntity>(detailEntity);
  5033. if (!result2)
  5034. {
  5035. returnValue = "修改失败";
  5036. }
  5037. }
  5038. }
  5039. }
  5040. catch (Exception ex)
  5041. {
  5042. returnValue = ex.Message;
  5043. }
  5044. return returnValue;
  5045. }
  5046. public ICSBadReasonGroupDto GetBadReasonGroup(string keyValue)
  5047. {
  5048. var returnValue = new ICSBadReasonGroupDto();
  5049. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  5050. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  5051. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  5052. var para = new { WorkPoint = WorkPoint };
  5053. try
  5054. {
  5055. var entity = MsSqlData.Get<ICSBadReasonGroupEntity>(keyValue);
  5056. if (entity == null)
  5057. {
  5058. throw new Exception("获取单个规则失败");
  5059. }
  5060. returnValue = ConvertExt.Mapping<ICSBadReasonGroupEntity, ICSBadReasonGroupDto>(entity);
  5061. string sql = @"select
  5062. a.*
  5063. from ICSBadReason a with(nolock)
  5064. where a.BRGroupID ='" + entity.ID + "' and a.WorkPoint=@WorkPoint order by a.BadReasonCode asc ";
  5065. var entityList = MsSqlData.Query<ICSBadReasonDto>(sql, para).ToList();
  5066. //int i = 0;
  5067. for (int i = 0; i < entityList.Count; i++)
  5068. {
  5069. entityList[i].key = i + 1;
  5070. }
  5071. returnValue.DetailList = entityList;
  5072. }
  5073. catch (Exception ex)
  5074. {
  5075. returnValue = null;
  5076. }
  5077. return returnValue;
  5078. }
  5079. public DataTable GetBadReasonDetailList(string id, ref Pagination pagination)
  5080. {
  5081. DataTable dt = new DataTable();
  5082. // var queryParam = queryJson.ToJObject();
  5083. List<DbParameter> parameter = new List<DbParameter>();
  5084. //object Figure = GetDecimalDigits();
  5085. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  5086. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  5087. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  5088. var para = new { WorkPoint = WorkPoint };
  5089. #region [SQL]
  5090. string sql = @"select
  5091. a.*
  5092. from ICSBadReason a with(nolock)
  5093. where 1=1
  5094. {0}
  5095. <1>
  5096. order by a.BadReasonCode asc
  5097. ";
  5098. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  5099. sql = sql.Replace("<1>", "and a.BRGroupID='" + id + "'");
  5100. sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  5101. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  5102. #endregion
  5103. return Repository().FindDataSetBySql(sql.ToString(), parameter.ToArray()).Tables[0];
  5104. }
  5105. public DataTable ExportAllBadCodeGroup(string bCGCode, string bCGDesc)
  5106. {
  5107. DataTable dt = new DataTable();
  5108. // var queryParam = queryJson.ToJObject();
  5109. List<DbParameter> parameter = new List<DbParameter>();
  5110. //object Figure = GetDecimalDigits();
  5111. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  5112. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  5113. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  5114. var para = new { WorkPoint = WorkPoint };
  5115. #region [SQL]
  5116. string sql = @"
  5117. select
  5118. a.*
  5119. from ICSBadCodeGroup a with(nolock)
  5120. where 1=1
  5121. {0}
  5122. <1>
  5123. <2>
  5124. ";
  5125. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  5126. //sql = string.Format(sql, Figure);
  5127. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  5128. #endregion
  5129. if (!string.IsNullOrWhiteSpace(bCGCode))
  5130. {
  5131. sql = sql.Replace("<1>", " and a.bCGCode like '%" + bCGCode + "%' ");
  5132. }
  5133. else
  5134. {
  5135. sql = sql.Replace("<1>", " ");
  5136. }
  5137. if (!string.IsNullOrWhiteSpace(bCGDesc))
  5138. {
  5139. sql = sql.Replace("<2>", " and a.bCGDesc like '%" + bCGDesc + "%' ");
  5140. }
  5141. else
  5142. {
  5143. sql = sql.Replace("<2>", " ");
  5144. }
  5145. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  5146. //{
  5147. sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  5148. // // sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  5149. //}
  5150. //else
  5151. //{
  5152. // sql = sql.Replace("{0}", "");
  5153. //}
  5154. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  5155. //{
  5156. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  5157. //}
  5158. return Repository().FindDataSetBySql(sql.ToString(), parameter.ToArray()).Tables[0];
  5159. }
  5160. public string DeleteBadCodeGroup(string keyValue)
  5161. {
  5162. string returnValue = string.Empty;
  5163. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  5164. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  5165. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  5166. var para = new { WorkPoint = WorkPoint };
  5167. try
  5168. {
  5169. var idList = JsonConvert.DeserializeObject<List<string>>(keyValue);
  5170. string sql = @"select
  5171. a.*
  5172. from ICSBadCodeGroup a with(nolock)
  5173. where a.ID in ('" + string.Join("','", idList) + "') and a.WorkPoint=@WorkPoint ";
  5174. var entityList = MsSqlData.Query<ICSBadCodeGroupEntity>(sql, para).ToList();
  5175. foreach (var item in entityList)
  5176. {
  5177. //var count = MsSqlData.ExecuteScalar(" select count(1) from IcsCheckingFixtureTransfer with(nolock) where CheckFixtureNo='" + item.CheckFixtureNo + "'").ToInt();
  5178. //if (count > 0)
  5179. //{
  5180. // throw new Exception("当前检具已经存在履历,不能删除");
  5181. //}
  5182. }
  5183. var result = MsSqlData.Delete<ICSBadCodeGroupEntity>(entityList);
  5184. if (!result)
  5185. {
  5186. returnValue = "删除失败";
  5187. }
  5188. string sql2 = @"delete from ICSBadCode where BCGroupID in ('" + string.Join("','", idList) + "') and WorkPoint=@WorkPoint";
  5189. var line = MsSqlData.Execute(sql2, para);
  5190. }
  5191. catch (Exception ex)
  5192. {
  5193. returnValue = ex.Message;
  5194. }
  5195. return returnValue;
  5196. }
  5197. public string SaveBadCodeGroup(string keyValue)
  5198. {
  5199. string returnValue = string.Empty;
  5200. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  5201. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  5202. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  5203. var para = new { WorkPoint = WorkPoint };
  5204. try
  5205. {
  5206. var dtNow = DateTime.Now;
  5207. var model = JsonConvert.DeserializeObject<ICSBadCodeGroupDto>(keyValue);
  5208. if (model == null)
  5209. {
  5210. throw new Exception("传入参数错误");
  5211. }
  5212. if (model.ID.IsNullOrEmpty())
  5213. {
  5214. //新增
  5215. var sql1 = @" select count(1) from ICSBadCodeGroup with(nolock) where BCGCode='" + model.BCGCode + "' and WorkPoint=@WorkPoint";
  5216. var count = MsSqlData.ExecuteScalar(sql1, para).ToInt();
  5217. if (count > 0)
  5218. {
  5219. throw new Exception("当前不良状态已经存在");
  5220. }
  5221. model.ID = Guid.NewGuid().ToString();
  5222. model.MUSER = MUSER;
  5223. model.MUSERName = MUSERNAME;
  5224. model.MTIME = dtNow;
  5225. model.WorkPoint = WorkPoint;
  5226. var result = MsSqlData.Insert<ICSBadCodeGroupEntity>(model);
  5227. if (!result)
  5228. {
  5229. returnValue = "新增失败";
  5230. }
  5231. foreach (var item in model.DetailList)
  5232. {
  5233. var detailEntity = ConvertExt.Mapping<ICSBadCodeDto, ICSBadCodeEntity>(item);
  5234. detailEntity.ID = Guid.NewGuid().ToString();
  5235. detailEntity.BCGroupID = model.ID;
  5236. detailEntity.MUSER = MUSER;
  5237. detailEntity.MUSERName = MUSERNAME;
  5238. detailEntity.MTIME = dtNow;
  5239. detailEntity.WorkPoint = WorkPoint;
  5240. var result2 = MsSqlData.Insert<ICSBadCodeEntity>(detailEntity);
  5241. if (!result2)
  5242. {
  5243. returnValue = "新增失败";
  5244. }
  5245. }
  5246. }
  5247. else
  5248. {
  5249. //修改
  5250. var entity = MsSqlData.Get<ICSBadCodeGroupEntity>(model.ID);
  5251. if (entity == null)
  5252. {
  5253. throw new Exception("当前数据不存在");
  5254. }
  5255. ConvertExt.Mapping<ICSBadCodeGroupDto, ICSBadCodeGroupEntity>(model, entity);
  5256. entity.MUSER = MUSER;
  5257. entity.MUSERName = MUSERNAME;
  5258. entity.MTIME = dtNow;
  5259. var result = MsSqlData.Update<ICSBadCodeGroupEntity>(entity);
  5260. if (!result)
  5261. {
  5262. returnValue = "修改失败";
  5263. }
  5264. string sql = @"select
  5265. a.*
  5266. from ICSBadCode a with(nolock)
  5267. where a.BCGroupID ='" + entity.ID + "' and WorkPoint=@WorkPoint ";
  5268. var entityList = MsSqlData.Query<ICSBadCodeEntity>(sql, para).ToList();
  5269. MsSqlData.Delete<ICSBadCodeEntity>(entityList);
  5270. foreach (var item in model.DetailList)
  5271. {
  5272. var detailEntity = ConvertExt.Mapping<ICSBadCodeDto, ICSBadCodeEntity>(item);
  5273. detailEntity.ID = Guid.NewGuid().ToString();
  5274. detailEntity.BCGroupID = model.ID;
  5275. detailEntity.MUSER = MUSER;
  5276. detailEntity.MUSERName = MUSERNAME;
  5277. detailEntity.MTIME = dtNow;
  5278. detailEntity.WorkPoint = WorkPoint;
  5279. var result2 = MsSqlData.Insert<ICSBadCodeEntity>(detailEntity);
  5280. if (!result2)
  5281. {
  5282. returnValue = "修改失败";
  5283. }
  5284. }
  5285. }
  5286. }
  5287. catch (Exception ex)
  5288. {
  5289. returnValue = ex.Message;
  5290. }
  5291. return returnValue;
  5292. }
  5293. public ICSBadCodeGroupDto GetBadCodeGroup(string keyValue)
  5294. {
  5295. var returnValue = new ICSBadCodeGroupDto();
  5296. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  5297. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  5298. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  5299. var para = new { WorkPoint = WorkPoint };
  5300. try
  5301. {
  5302. var entity = MsSqlData.Get<ICSBadCodeGroupEntity>(keyValue);
  5303. if (entity == null)
  5304. {
  5305. throw new Exception("获取单个规则失败");
  5306. }
  5307. returnValue = ConvertExt.Mapping<ICSBadCodeGroupEntity, ICSBadCodeGroupDto>(entity);
  5308. string sql = @"select
  5309. a.*
  5310. from ICSBadCode a with(nolock)
  5311. where a.BCGroupID ='" + entity.ID + "' and WorkPoint=@WorkPoint order by a.BadCode asc ";
  5312. var entityList = MsSqlData.Query<ICSBadCodeDto>(sql, para).ToList();
  5313. //int i = 0;
  5314. for (int i = 0; i < entityList.Count; i++)
  5315. {
  5316. entityList[i].key = i + 1;
  5317. }
  5318. returnValue.DetailList = entityList;
  5319. }
  5320. catch (Exception ex)
  5321. {
  5322. returnValue = new ICSBadCodeGroupDto();
  5323. returnValue.DetailList = new List<ICSBadCodeDto>();
  5324. }
  5325. return returnValue;
  5326. }
  5327. public string DeleteItem2AqlFile(string keyValue)
  5328. {
  5329. string returnValue = string.Empty;
  5330. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  5331. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  5332. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  5333. var para = new { WorkPoint = WorkPoint };
  5334. try
  5335. {
  5336. var idList = JsonConvert.DeserializeObject<List<string>>(keyValue);
  5337. string sql = @"select
  5338. a.*
  5339. from ICSInventoryInspectionRulesGroupFile a with(nolock)
  5340. where a.ID in ('" + string.Join("','", idList) + "') and WorkPoint=@WorkPoint ";
  5341. var entityList = MsSqlData.Query<ICSInventoryInspectionRulesGroupFile>(sql, para).ToList();
  5342. var result = MsSqlData.Delete<ICSInventoryInspectionRulesGroupFile>(entityList);
  5343. if (!result)
  5344. {
  5345. returnValue = "删除失败";
  5346. }
  5347. }
  5348. catch (Exception ex)
  5349. {
  5350. returnValue = ex.Message;
  5351. }
  5352. return returnValue;
  5353. }
  5354. public DataTable GetItem2AqlFileList(string keyValue)
  5355. {
  5356. List<DbParameter> parameter = new List<DbParameter>();
  5357. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  5358. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  5359. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  5360. var para = new { WorkPoint = WorkPoint };
  5361. string sql = @"select
  5362. a.ID
  5363. ,b.InvCode
  5364. ,b.InvName
  5365. ,b.InvStd
  5366. ,a.MUSER
  5367. ,a.MUSERName
  5368. ,a.MTIME
  5369. ,d.FileName
  5370. ,d.ID as FileID
  5371. from ICSInventoryInspectionRulesGroup a with(nolock)
  5372. join ICSInventory b with(nolock) on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  5373. join ICSInspectionRulesGroup c with(nolock) on a.RulesCode=c.RulesCode and a.WorkPoint=c.WorkPoint
  5374. join ICSInventoryInspectionRulesGroupFile d with(nolock)on a.ID=d.IIRGID and a.WorkPoint=d.WorkPoint
  5375. where 1=1
  5376. and a.workpoint='{1}'
  5377. and a.InvCode='{0}'
  5378. ";
  5379. sql = string.Format(sql, keyValue, WorkPoint);
  5380. return Repository().FindDataSetBySql(sql.ToString(), parameter.ToArray()).Tables[0];
  5381. }
  5382. public int UpLoadItemRuleFile(string id, string fileName)
  5383. {
  5384. var returnValue = 1;
  5385. var dtNow = DateTime.Now;
  5386. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  5387. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  5388. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  5389. var para = new { WorkPoint = WorkPoint };
  5390. SqlConnection conn = SqlHelper.GetDataCenterConn();
  5391. var sql1 = @" select count(1) from ICSInventoryInspectionRulesGroupFile with(nolock) where IIRGID='" + id + "' and FileName='" + fileName + "' and WorkPoint=@WorkPoint";
  5392. var count = MsSqlData.ExecuteScalar(sql1, para).ToInt();
  5393. if (count > 0)
  5394. {
  5395. throw new Exception("当前物料规则文件已经存在");
  5396. }
  5397. var count2 = MsSqlData.ExecuteScalar
  5398. (" select count(1) from ICSInventoryInspectionRulesGroupFile with(nolock) where IIRGID='" + id + "' and WorkPoint=@WorkPoint ", para).ToInt();
  5399. if (count2 >= 3)
  5400. {
  5401. throw new Exception("当前物料规则文件已经超过3个,不能再次上传");
  5402. }
  5403. ICSInventoryInspectionRulesGroupFile entity = new ICSInventoryInspectionRulesGroupFile();
  5404. entity.ID = Guid.NewGuid().ToString();
  5405. entity.IIRGID = id;
  5406. entity.FileCode = fileName;
  5407. entity.FileName = fileName;
  5408. entity.MUSER = MUSER;
  5409. entity.MUSERName = MUSERNAME;
  5410. entity.MTIME = dtNow;
  5411. entity.WorkPoint = WorkPoint;
  5412. var result2 = MsSqlData.Insert<ICSInventoryInspectionRulesGroupFile>(entity);
  5413. if (!result2)
  5414. {
  5415. returnValue = 0;
  5416. }
  5417. return returnValue;
  5418. }
  5419. public string DeleteItem2Aql(string keyValue)
  5420. {
  5421. string returnValue = string.Empty;
  5422. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  5423. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  5424. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  5425. var para = new { WorkPoint = WorkPoint };
  5426. try
  5427. {
  5428. var idList = JsonConvert.DeserializeObject<List<string>>(keyValue);
  5429. string sql = @"select
  5430. a.*
  5431. from ICSInventoryInspectionRulesGroup a with(nolock)
  5432. where a.ID in ('" + string.Join("','", idList) + "') and WorkPoint=@WorkPoint ";
  5433. var entityList = MsSqlData.Query<ICSInventoryInspectionRulesGroup>(sql, para).ToList();
  5434. foreach (var item in entityList)
  5435. {
  5436. //var count = MsSqlData.ExecuteScalar(" select count(1) from IcsCheckingFixtureTransfer with(nolock) where CheckFixtureNo='" + item.CheckFixtureNo + "'").ToInt();
  5437. //if (count > 0)
  5438. //{
  5439. // throw new Exception("当前检具已经存在履历,不能删除");
  5440. //}
  5441. string sql2 = @"delete from ICSInventoryInspectionRulesGroupFile where IIRGID in ('" + string.Join("','", idList) + "') and WorkPoint=@WorkPoint ";
  5442. var line = MsSqlData.Execute(sql2, para);
  5443. }
  5444. var result = MsSqlData.Delete<ICSInventoryInspectionRulesGroup>(entityList);
  5445. if (!result)
  5446. {
  5447. returnValue = "删除失败";
  5448. }
  5449. //string sql2 = @"delete from ICSInspectionRulesList where RulesID in ('" + string.Join("','", idList) + "')";
  5450. //var line = Repository().ExecuteBySql(new StringBuilder(sql2));
  5451. }
  5452. catch (Exception ex)
  5453. {
  5454. returnValue = ex.Message;
  5455. }
  5456. return returnValue;
  5457. }
  5458. public DataTable ExportAllItem2AqlList(string rulesCode, string rulesName, string invCode, string invName)
  5459. {
  5460. DataTable dt = new DataTable();
  5461. // var queryParam = queryJson.ToJObject();
  5462. List<DbParameter> parameter = new List<DbParameter>();
  5463. //object Figure = GetDecimalDigits();
  5464. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  5465. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  5466. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  5467. var para = new { WorkPoint = WorkPoint };
  5468. #region [SQL]
  5469. string sql = @"
  5470. select
  5471. a.*
  5472. from
  5473. (
  5474. select
  5475. b.InvCode
  5476. ,b.InvName
  5477. ,b.InvStd
  5478. ,c.RulesCode
  5479. ,c.RulesName
  5480. ,c.RulesDesc
  5481. ,a.MUSER
  5482. ,a.MUSERName
  5483. ,a.MTIME
  5484. from ICSInventoryInspectionRulesGroup a with(nolock)
  5485. join ICSInventory b with(nolock) on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  5486. join ICSInspectionRulesGroup c with(nolock) on a.RulesCode=c.RulesCode and a.WorkPoint=c.WorkPoint
  5487. where 1=1
  5488. {0}
  5489. ) a
  5490. where 1=1
  5491. --and a.wo
  5492. <1>
  5493. <2>
  5494. <3>
  5495. <4>
  5496. ";
  5497. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  5498. //sql = string.Format(sql, Figure);
  5499. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  5500. #endregion
  5501. if (!string.IsNullOrWhiteSpace(rulesCode))
  5502. {
  5503. sql = sql.Replace("<1>", " and a.InvCode like '%" + rulesCode + "%' ");
  5504. }
  5505. else
  5506. {
  5507. sql = sql.Replace("<1>", " ");
  5508. }
  5509. if (!string.IsNullOrWhiteSpace(rulesName))
  5510. {
  5511. sql = sql.Replace("<2>", " and a.InvName like '%" + rulesName + "%' ");
  5512. }
  5513. else
  5514. {
  5515. sql = sql.Replace("<2>", " ");
  5516. }
  5517. if (!string.IsNullOrWhiteSpace(invCode))
  5518. {
  5519. sql = sql.Replace("<3>", " and a.RulesCode like '%" + invCode + "%' ");
  5520. }
  5521. else
  5522. {
  5523. sql = sql.Replace("<3>", " ");
  5524. }
  5525. if (!string.IsNullOrWhiteSpace(invName))
  5526. {
  5527. sql = sql.Replace("<4>", " and a.RulesName like '%" + invName + "%' ");
  5528. }
  5529. else
  5530. {
  5531. sql = sql.Replace("<4>", " ");
  5532. }
  5533. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  5534. //{
  5535. sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  5536. // // sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  5537. //}
  5538. //else
  5539. //{
  5540. // sql = sql.Replace("{0}", "");
  5541. //}
  5542. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  5543. //{
  5544. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  5545. //}
  5546. return Repository().FindDataSetBySql(sql.ToString(), parameter.ToArray()).Tables[0];
  5547. }
  5548. public string SaveItem2Aql(string keyValue)
  5549. {
  5550. string returnValue = string.Empty;
  5551. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  5552. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  5553. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  5554. var para = new { WorkPoint = WorkPoint };
  5555. try
  5556. {
  5557. var dtNow = DateTime.Now;
  5558. var model = JsonConvert.DeserializeObject<ICSInventoryInspectionRulesGroupDto>(keyValue);
  5559. if (model == null)
  5560. {
  5561. throw new Exception("传入参数错误");
  5562. }
  5563. foreach (var item in model.ItemList)
  5564. {
  5565. foreach (var item2 in model.AqlList)
  5566. {
  5567. var count = MsSqlData.ExecuteScalar
  5568. (
  5569. " select count(1) from ICSInventoryInspectionRulesGroup a with(nolock) where InvCode='" + item.InvCode + "' and a.EATTRIBUTE1='" + model.EATTRIBUTE1 + "' and WorkPoint=@WorkPoint "
  5570. , para).ToInt();
  5571. if (count > 0)
  5572. {
  5573. throw new Exception("当前物料Aql关系已经存在");
  5574. }
  5575. var entity = new ICSInventoryInspectionRulesGroup();
  5576. entity.InvCode = item.InvCode;
  5577. entity.RulesCode = item2.RulesCode;
  5578. entity.RulesName = item2.RulesName;
  5579. entity.RulesDesc = item2.RulesDesc;
  5580. entity.Type = item2.Type;
  5581. entity.EATTRIBUTE1 = model.EATTRIBUTE1;
  5582. entity.Enable = true;
  5583. entity.Editable = true;
  5584. entity.ID = Guid.NewGuid().ToString();
  5585. entity.MUSER = MUSER;
  5586. entity.MUSERName = MUSERNAME;
  5587. entity.MTIME = dtNow;
  5588. entity.WorkPoint = WorkPoint;
  5589. var result2 = MsSqlData.Insert<ICSInventoryInspectionRulesGroup>(entity);
  5590. if (!result2)
  5591. {
  5592. returnValue = "新增失败";
  5593. }
  5594. }
  5595. }
  5596. }
  5597. catch (Exception ex)
  5598. {
  5599. returnValue = ex.Message;
  5600. }
  5601. return returnValue;
  5602. }
  5603. public List<ICSInspectionRulesGroupEntity> GetAllAqlList(string code)
  5604. {
  5605. var returnValue = new List<ICSInspectionRulesGroupEntity>();
  5606. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  5607. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  5608. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  5609. var para = new { WorkPoint = WorkPoint };
  5610. string sql = string.Empty;
  5611. if (code.IsNullOrEmpty())
  5612. {
  5613. sql = "select * from ICSInspectionRulesGroup with(nolock) where WorkPoint=@WorkPoint ";
  5614. }
  5615. else
  5616. {
  5617. sql = "select * from ICSInspectionRulesGroup with(nolock) where WorkPoint=@WorkPoint and RulesCode like '%" + code + "%'";
  5618. }
  5619. returnValue = MsSqlData.Query<ICSInspectionRulesGroupEntity>(sql, para).ToList();
  5620. return returnValue;
  5621. }
  5622. public List<ICSInventoryDto> GetAllItemList(string code)
  5623. {
  5624. var returnValue = new List<ICSInventoryDto>();
  5625. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  5626. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  5627. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  5628. var para = new { WorkPoint = WorkPoint };
  5629. string sql = @" select * from ICSInventory A with(nolock)
  5630. LEFT JOIN ICSInventoryInspectionGroup B with(nolock) on B.InvCode=A.InvCode AND B.WorkPoint=A.WorkPoint
  5631. where A.WorkPoint=@WorkPoint and A.InvIQC=1 AND B.InvCode IS NULL and A.InvCode like '%" + code + "%' ";
  5632. returnValue = MsSqlData.Query<ICSInventoryDto>(sql, para).ToList();
  5633. return returnValue;
  5634. }
  5635. public List<ICSInventoryDto> GetEditItemList(string code)
  5636. {
  5637. var returnValue = new List<ICSInventoryDto>();
  5638. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  5639. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  5640. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  5641. var para = new { WorkPoint = WorkPoint };
  5642. string sql = @" select * from ICSInventory A with(nolock)
  5643. where A.WorkPoint=@WorkPoint and A.InvCode = '" + code + "' ";
  5644. returnValue = MsSqlData.Query<ICSInventoryDto>(sql, para).ToList();
  5645. return returnValue;
  5646. }
  5647. public List<ICSInventory2InspectionGroup> GetEditInfoData(string code)
  5648. {
  5649. var returnValue = new List<ICSInventory2InspectionGroup>();
  5650. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  5651. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  5652. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  5653. var para = new { WorkPoint = WorkPoint };
  5654. string sql = @" select TOP 1 A.InvCode,A.EATTRIBUTE1 AS CheckAttr,B.F_ItemName AS CheckAttrName
  5655. ,A.GroupCode,A.GroupName from ICSInventoryInspectionGroup A
  5656. LEFT JOIN Sys_SRM_ItemsDetail B ON B.F_ItemCode=A.EATTRIBUTE1
  5657. LEFT JOIN Sys_SRM_Items C ON C.F_Id=B.F_ItemId AND C.F_EnCode='InspectionGroupType'
  5658. where A.InvCode='" + code + "' and A.WorkPoint='" + WorkPoint + "'";
  5659. returnValue = MsSqlData.Query<ICSInventory2InspectionGroup>(sql, para).ToList();
  5660. return returnValue;
  5661. }
  5662. public List<ICSInventoryDto> GetItemCodeSearch(string code)
  5663. {
  5664. var returnValue = new List<ICSInventoryDto>();
  5665. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  5666. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  5667. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  5668. var para = new { WorkPoint = WorkPoint };
  5669. string sql = @" select A.InvCode,A.InvName from ICSInventory A with(nolock)
  5670. LEFT JOIN ICSInventoryInspectionGroup B with(nolock) on B.InvCode = A.InvCode AND B.WorkPoint = A.WorkPoint
  5671. where A.WorkPoint = @WorkPoint and A.InvIQC = 1 AND B.InvCode IS NULL and A.InvCode like '%" + code + "%' ";
  5672. returnValue = MsSqlData.Query<ICSInventoryDto>(sql, para).ToList();
  5673. return returnValue;
  5674. }
  5675. public DataTable ExportAllAqlList(string rulesCode, string rulesName, string enable)
  5676. {
  5677. DataTable dt = new DataTable();
  5678. //var queryParam = queryJson.ToJObject();
  5679. List<DbParameter> parameter = new List<DbParameter>();
  5680. //object Figure = GetDecimalDigits();
  5681. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  5682. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  5683. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  5684. var para = new { WorkPoint = WorkPoint };
  5685. #region [SQL]
  5686. string sql = @"
  5687. select
  5688. case when a.Enable=1 then '是'
  5689. else '否' end as
  5690. ,a.GroupCode AS
  5691. ,a.GroupName AS
  5692. ,c.Name AS
  5693. ,b.ListCode AS
  5694. ,b.ListName AS
  5695. ,b.SetValueMin AS
  5696. ,b.SetValueMax AS
  5697. ,b.Unit AS
  5698. ,b.EATTRIBUTE1 AS
  5699. ,b.EATTRIBUTE2 AS
  5700. ,b.EATTRIBUTE3 AS
  5701. ,Case When b.EATTRIBUTE4='True' Then '是' ELSE '否' END AS
  5702. ,b.EATTRIBUTE5 AS AQL代码
  5703. ,Case When b.Enable='True' Then '是' ELSE '否' END AS
  5704. from ICSInspectionGroup a with(nolock)
  5705. LEFT JOIN ICSInspectionList b with(nolock)
  5706. on b.GroupID=a.ID AND b.WorkPoint=a.WorkPoint
  5707. LEFT JOIN ICSType c with(nolock)
  5708. on c.ColumnCode='EATTRIBUTE6' AND c.TableCode='ICSInspectionList' AND c.Code=b.EATTRIBUTE6
  5709. where 1=1
  5710. {0}
  5711. <1>
  5712. <2>
  5713. <3>
  5714. ";
  5715. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  5716. //sql = string.Format(sql, Figure);
  5717. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  5718. #endregion
  5719. if (!string.IsNullOrWhiteSpace(rulesCode))
  5720. {
  5721. sql = sql.Replace("<1>", " and a.GroupCode like '%" + rulesCode + "%' ");
  5722. }
  5723. else
  5724. {
  5725. sql = sql.Replace("<1>", " ");
  5726. }
  5727. if (!string.IsNullOrWhiteSpace(rulesName))
  5728. {
  5729. sql = sql.Replace("<2>", " and a.GroupName like '%" + rulesName + "%' ");
  5730. }
  5731. else
  5732. {
  5733. sql = sql.Replace("<2>", " ");
  5734. }
  5735. if (!string.IsNullOrWhiteSpace(enable))
  5736. {
  5737. sql = sql.Replace("<3>", " and a.Enable =" + enable + " ");
  5738. }
  5739. else
  5740. {
  5741. sql = sql.Replace("<3>", " ");
  5742. }
  5743. sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  5744. return Repository().FindDataSetBySql(sql.ToString(), parameter.ToArray()).Tables[0];
  5745. }
  5746. public ICSInspectionRulesGroupDto GetAql(string keyValue)
  5747. {
  5748. var returnValue = new ICSInspectionRulesGroupDto();
  5749. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  5750. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  5751. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  5752. var para = new { WorkPoint = WorkPoint };
  5753. try
  5754. {
  5755. var entity = MsSqlData.Get<ICSInspectionRulesGroupEntity>(keyValue);
  5756. if (entity == null)
  5757. {
  5758. throw new Exception("获取单个规则失败");
  5759. }
  5760. returnValue = ConvertExt.Mapping<ICSInspectionRulesGroupEntity, ICSInspectionRulesGroupDto>(entity);
  5761. string sql = @" select
  5762. a.*
  5763. from ICSInspectionRulesList a with(nolock)
  5764. where a.RulesID ='" + entity.ID + @"' and WorkPoint=@WorkPoint
  5765. Order by SetValueMin";
  5766. var entityList = MsSqlData.Query<ICSInspectionRulesListDto>(sql, para).ToList();
  5767. //int i = 0;
  5768. for (int i = 0; i < entityList.Count; i++)
  5769. {
  5770. entityList[i].key = i + 1;
  5771. }
  5772. returnValue.DetailList = entityList;
  5773. }
  5774. catch (Exception ex)
  5775. {
  5776. returnValue = null;
  5777. }
  5778. return returnValue;
  5779. }
  5780. public ICSInspectionGroupDto GetGroup(string keyValue)
  5781. {
  5782. var returnValue = new ICSInspectionGroupDto();
  5783. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  5784. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  5785. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  5786. var para = new { WorkPoint = WorkPoint };
  5787. try
  5788. {
  5789. var entity = MsSqlData.Get<ICSInspectionGroupEntity>(keyValue);
  5790. if (entity == null)
  5791. {
  5792. throw new Exception("获取单个规则失败");
  5793. }
  5794. returnValue = ConvertExt.Mapping<ICSInspectionGroupEntity, ICSInspectionGroupDto>(entity);
  5795. string sql = @"select
  5796. a.*
  5797. from ICSInspectionList a with(nolock)
  5798. where a.GroupID ='" + entity.ID + @"' and WorkPoint=@WorkPoint
  5799. order by
  5800. case when a.EATTRIBUTE6 = 'Size' then 1
  5801. when a.EATTRIBUTE6 = 'Carton' then 2
  5802. else 3 end,
  5803. a.SetValueMin asc";
  5804. var entityList = MsSqlData.Query<ICSInspectionListDto>(sql, para).ToList();
  5805. for (int i = 0; i < entityList.Count; i++)
  5806. {
  5807. entityList[i].key = i + 1;
  5808. }
  5809. returnValue.DetailList = entityList;
  5810. }
  5811. catch (Exception ex)
  5812. {
  5813. returnValue = null;
  5814. }
  5815. return returnValue;
  5816. }
  5817. public DataTable GetICSAql()
  5818. {
  5819. var returnValue = new ICSInspectionRulesGroupDto();
  5820. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  5821. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  5822. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  5823. var para = new { WorkPoint = WorkPoint };
  5824. DataTable dt;
  5825. try
  5826. {
  5827. string sql = $@"select
  5828. a.RulesCode Code,a.RulesName+'('+a.RulesCode+')' Name
  5829. from ICSInspectionRulesGroup a with(nolock)
  5830. where a.Enable ='1' and WorkPoint='{WorkPoint}' ";
  5831. dt = SqlHelper.ExecuteTable(sql);
  5832. }
  5833. catch (Exception ex)
  5834. {
  5835. throw new Exception(ex.Message);
  5836. }
  5837. return dt;
  5838. }
  5839. public string SaveAql(string keyValue)
  5840. {
  5841. string returnValue = string.Empty;
  5842. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  5843. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  5844. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  5845. var para = new { WorkPoint = WorkPoint };
  5846. try
  5847. {
  5848. var dtNow = DateTime.Now;
  5849. var model = JsonConvert.DeserializeObject<ICSInspectionRulesGroupDto>(keyValue);
  5850. if (model == null)
  5851. {
  5852. throw new Exception("传入参数错误");
  5853. }
  5854. if (model.ID.IsNullOrEmpty())
  5855. {
  5856. //新增
  5857. var sql1 = @" select count(1) from ICSInspectionRulesGroup with(nolock) where RulesCode='" + model.RulesCode + "' and WorkPoint=@WorkPoint ";
  5858. var count = MsSqlData.ExecuteScalar(sql1, para).ToInt();
  5859. if (count > 0)
  5860. {
  5861. throw new Exception("当前规则代码已经存在");
  5862. }
  5863. model.ID = Guid.NewGuid().ToString();
  5864. model.MUSER = MUSER;
  5865. model.Type = "1";
  5866. model.MUSERName = MUSERNAME;
  5867. model.MTIME = dtNow;
  5868. model.WorkPoint = WorkPoint;
  5869. var result = MsSqlData.Insert<ICSInspectionRulesGroupEntity>(model);
  5870. if (!result)
  5871. {
  5872. returnValue = "新增失败";
  5873. }
  5874. foreach (var item in model.DetailList)
  5875. {
  5876. var detailEntity = ConvertExt.Mapping<ICSInspectionRulesListDto, ICSInspectionRulesListEntity>(item);
  5877. detailEntity.ID = Guid.NewGuid().ToString();
  5878. detailEntity.RulesID = model.ID;
  5879. detailEntity.Enable = true;
  5880. detailEntity.MUSER = MUSER;
  5881. detailEntity.MUSERName = MUSERNAME;
  5882. detailEntity.MTIME = dtNow;
  5883. detailEntity.WorkPoint = WorkPoint;
  5884. var result2 = MsSqlData.Insert<ICSInspectionRulesListEntity>(detailEntity);
  5885. if (!result2)
  5886. {
  5887. returnValue = "新增失败";
  5888. }
  5889. }
  5890. }
  5891. else
  5892. {
  5893. //修改
  5894. var entity = MsSqlData.Get<ICSInspectionRulesGroupEntity>(model.ID);
  5895. if (entity == null)
  5896. {
  5897. throw new Exception("当前数据不存在");
  5898. }
  5899. ConvertExt.Mapping<ICSInspectionRulesGroupDto, ICSInspectionRulesGroupEntity>(model, entity);
  5900. entity.MUSER = MUSER;
  5901. entity.MUSERName = MUSERNAME;
  5902. entity.MTIME = dtNow;
  5903. var result = MsSqlData.Update<ICSInspectionRulesGroupEntity>(entity);
  5904. if (!result)
  5905. {
  5906. returnValue = "修改失败";
  5907. }
  5908. string sql = @"select
  5909. a.*
  5910. from ICSInspectionRulesList a with(nolock)
  5911. where a.RulesID ='" + entity.ID + "' and WorkPoint=@WorkPoint ";
  5912. var entityList = MsSqlData.Query<ICSInspectionRulesListEntity>(sql, para).ToList();
  5913. MsSqlData.Delete<ICSInspectionRulesListEntity>(entityList);
  5914. foreach (var item in model.DetailList)
  5915. {
  5916. var detailEntity = ConvertExt.Mapping<ICSInspectionRulesListDto, ICSInspectionRulesListEntity>(item);
  5917. detailEntity.ID = Guid.NewGuid().ToString();
  5918. detailEntity.RulesID = model.ID;
  5919. detailEntity.Enable = true;
  5920. detailEntity.MUSER = MUSER;
  5921. detailEntity.MUSERName = MUSERNAME;
  5922. detailEntity.MTIME = dtNow;
  5923. detailEntity.WorkPoint = WorkPoint;
  5924. var result2 = MsSqlData.Insert<ICSInspectionRulesListEntity>(detailEntity);
  5925. if (!result2)
  5926. {
  5927. returnValue = "修改失败";
  5928. }
  5929. }
  5930. }
  5931. }
  5932. catch (Exception ex)
  5933. {
  5934. returnValue = ex.Message;
  5935. }
  5936. return returnValue;
  5937. }
  5938. public string SaveCheckGroup(string keyValue)
  5939. {
  5940. string returnValue = string.Empty;
  5941. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  5942. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  5943. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  5944. var para = new { WorkPoint = WorkPoint };
  5945. try
  5946. {
  5947. var dtNow = DateTime.Now;
  5948. var model = JsonConvert.DeserializeObject<ICSInspectionGroupDto>(keyValue);
  5949. if (model == null)
  5950. {
  5951. throw new Exception("传入参数错误");
  5952. }
  5953. var checkList = model.DetailList.GroupBy(x => new { x.ListCode });
  5954. if (checkList.Count() != model.DetailList.Count())
  5955. {
  5956. throw new Exception("存在检验项目代码重复,一个检验项目组中不能有相同的检验项目!");
  5957. }
  5958. if (model.ID.IsNullOrEmpty())
  5959. {
  5960. //新增
  5961. var sql1 = @" select count(1) from ICSInspectionGroup with(nolock) where GroupCode='" + model.GroupCode + "' and WorkPoint=@WorkPoint ";
  5962. var count = MsSqlData.ExecuteScalar(sql1, para).ToInt();
  5963. if (count > 0)
  5964. {
  5965. throw new Exception("当前检验项目组代码已经存在");
  5966. }
  5967. model.ID = Guid.NewGuid().ToString();
  5968. model.MUSER = MUSER;
  5969. model.MUSERName = MUSERNAME;
  5970. model.MTIME = dtNow;
  5971. model.WorkPoint = WorkPoint;
  5972. var result = MsSqlData.Insert<ICSInspectionGroupEntity>(model);
  5973. if (!result)
  5974. {
  5975. returnValue = "新增失败";
  5976. }
  5977. foreach (var item in model.DetailList)
  5978. {
  5979. var detailEntity = ConvertExt.Mapping<ICSInspectionListDto, ICSInspectionListEntity>(item);
  5980. detailEntity.ID = Guid.NewGuid().ToString();
  5981. detailEntity.GroupID = model.ID;
  5982. //detailEntity.Enable = model.Enable ;
  5983. detailEntity.MUSER = MUSER;
  5984. detailEntity.MUSERName = MUSERNAME;
  5985. detailEntity.MTIME = dtNow;
  5986. detailEntity.WorkPoint = WorkPoint;
  5987. var result2 = MsSqlData.Insert<ICSInspectionListEntity>(detailEntity);
  5988. if (!result2)
  5989. {
  5990. returnValue = "新增失败";
  5991. }
  5992. }
  5993. }
  5994. else
  5995. {
  5996. //修改
  5997. var entity = MsSqlData.Get<ICSInspectionGroupEntity>(model.ID);
  5998. if (entity == null)
  5999. {
  6000. throw new Exception("当前数据不存在");
  6001. }
  6002. ConvertExt.Mapping<ICSInspectionGroupDto, ICSInspectionGroupEntity>(model, entity);
  6003. entity.MUSER = MUSER;
  6004. entity.MUSERName = MUSERNAME;
  6005. entity.MTIME = dtNow;
  6006. var result = MsSqlData.Update<ICSInspectionGroupEntity>(entity);
  6007. if (!result)
  6008. {
  6009. returnValue = "修改失败";
  6010. }
  6011. string sql = @"select
  6012. a.*
  6013. from ICSInspectionList a with(nolock)
  6014. where a.GroupID ='" + entity.ID + "' and WorkPoint=@WorkPoint ";
  6015. var entityList = MsSqlData.Query<ICSInspectionListEntity>(sql, para).ToList();
  6016. MsSqlData.Delete<ICSInspectionListEntity>(entityList);
  6017. foreach (var item in model.DetailList)
  6018. {
  6019. var detailEntity = ConvertExt.Mapping<ICSInspectionListDto, ICSInspectionListEntity>(item);
  6020. detailEntity.ID = Guid.NewGuid().ToString();
  6021. detailEntity.GroupID = model.ID;
  6022. //detailEntity.Enable = true;
  6023. detailEntity.MUSER = MUSER;
  6024. detailEntity.MUSERName = MUSERNAME;
  6025. detailEntity.MTIME = dtNow;
  6026. detailEntity.WorkPoint = WorkPoint;
  6027. var result2 = MsSqlData.Insert<ICSInspectionListEntity>(detailEntity);
  6028. if (!result2)
  6029. {
  6030. returnValue = "修改失败";
  6031. }
  6032. }
  6033. }
  6034. }
  6035. catch (Exception ex)
  6036. {
  6037. returnValue = ex.Message;
  6038. }
  6039. return returnValue;
  6040. }
  6041. public DataTable GetAqlSubGridJsonList(string id, ref Pagination pagination)
  6042. {
  6043. DataTable dt = new DataTable();
  6044. // var queryParam = queryJson.ToJObject();
  6045. List<DbParameter> parameter = new List<DbParameter>();
  6046. //object Figure = GetDecimalDigits();
  6047. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  6048. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  6049. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  6050. var para = new { WorkPoint = WorkPoint };
  6051. #region [SQL]
  6052. string sql = @"select
  6053. a.*,b.Name as Type
  6054. from ICSInspectionRulesList a with(nolock)
  6055. LEFT JOIN ICSType b ON a.WorkPoint=b.WorkPoint AND b.TableCode='ICSInspectionRulesList' AND b.ColumnCode='EATTRIBUTE2' AND a.EATTRIBUTE2=b.Code AND b.Enable='1'
  6056. where 1=1
  6057. {0}
  6058. <1>
  6059. order by a.SetValueMin asc
  6060. ";
  6061. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  6062. sql = sql.Replace("<1>", "and a.RulesID='" + id + "'");
  6063. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  6064. #endregion
  6065. sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  6066. return Repository().FindDataSetBySql(sql.ToString(), parameter.ToArray()).Tables[0];
  6067. }
  6068. public DataTable GetGroupSubGridJsonList(string id, ref Pagination pagination)
  6069. {
  6070. DataTable dt = new DataTable();
  6071. // var queryParam = queryJson.ToJObject();
  6072. List<DbParameter> parameter = new List<DbParameter>();
  6073. //object Figure = GetDecimalDigits();
  6074. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  6075. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  6076. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  6077. var para = new { WorkPoint = WorkPoint };
  6078. #region [SQL]
  6079. string sql = @"select
  6080. a.*,b.Name as Type,case when a.EATTRIBUTE4='true' then '是' else '否' end CEATTRIBUTE4, case when a.Enable='1' then '是' else '否' end CEnable
  6081. from ICSInspectionList a with(nolock)
  6082. LEFT JOIN ICSType b ON a.WorkPoint=b.WorkPoint AND b.TableCode='ICSInspectionList' AND b.ColumnCode='EATTRIBUTE6' AND a.EATTRIBUTE6=b.Code AND b.Enable='1'
  6083. where 1=1
  6084. {0}
  6085. <1>
  6086. order by
  6087. case when a.EATTRIBUTE6 = 'Size' then 1
  6088. when a.EATTRIBUTE6 = 'Carton' then 2
  6089. else 3 end,
  6090. a.SetValueMin asc
  6091. ";
  6092. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  6093. sql = sql.Replace("<1>", "and a.GroupID='" + id + "'");
  6094. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  6095. #endregion
  6096. sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  6097. return Repository().FindDataSetBySql(sql.ToString(), parameter.ToArray()).Tables[0];
  6098. }
  6099. public List<SysEnumValueDto> GetSelectItemList(string key)
  6100. {
  6101. var returnValue = new List<SysEnumValueDto>();
  6102. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  6103. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  6104. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  6105. string sql = @"select
  6106. b.F_EnCode
  6107. ,b.F_FullName
  6108. ,a.F_ItemCode as value
  6109. ,a.F_ItemName as label
  6110. ,a.F_Define1 as Ext1
  6111. ,a.F_Define2 as Ext2
  6112. ,a.F_Define3 as Ext3
  6113. ,a.F_Define4 as Ext4
  6114. from [dbo].[Sys_SRM_ItemsDetail] a with(nolock)
  6115. left join [Sys_SRM_Items] b with(nolock) on a.F_ItemId=b.F_Id
  6116. where b.F_EnCode=@EnCode
  6117. ";
  6118. var para = new
  6119. {
  6120. EnCode = key,
  6121. };
  6122. returnValue = MsSqlData.Query<SysEnumValueDto>(sql, para).ToList();
  6123. for (int i = 0; i < returnValue.Count; i++)
  6124. {
  6125. returnValue[i].key = i + 1;
  6126. }
  6127. return returnValue;
  6128. }
  6129. public DataTable GetSelectCheckGroup()
  6130. {
  6131. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  6132. string sql = $@"SELECT GroupCode Code,GroupName Name FROM ICSInspectionGroup WHERE Enable='1' and WorkPoint='{WorkPoint}' ";
  6133. var returnValue = SqlHelper.ExecuteTable(sql);
  6134. return returnValue;
  6135. }
  6136. public void InsertOperateLog(string key, string data, string entityName = null, string sourceType = null)
  6137. {
  6138. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  6139. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  6140. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  6141. var dtNow = DateTime.Now;
  6142. var entity = new SysModifyLog();
  6143. entity.BillCode = key;
  6144. entity.BillType = "Add";
  6145. entity.SourceType = sourceType;
  6146. entity.EntityName = entityName;
  6147. entity.JsonData = data;
  6148. entity.TenantId = WorkPoint;
  6149. entity.CreationTime = dtNow;
  6150. entity.CreatorUserId = MUSER;
  6151. entity.CreatorUserName = MUSERNAME;
  6152. entity.LastModificationTime = dtNow;
  6153. entity.LastModifierUserId = MUSER;
  6154. entity.LastModifierUserName = MUSERNAME;
  6155. var result2 = MsSqlData.Insert<SysModifyLog>(entity);
  6156. }
  6157. private void SendEmail(string type, IcsMatCheckResultDto model)
  6158. {
  6159. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  6160. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  6161. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  6162. try
  6163. {
  6164. List<DbParameter> parameter = new List<DbParameter>();
  6165. List<DbParameter> parameter1 = new List<DbParameter>();
  6166. string sqls = @" select *
  6167. from V_QuerySysEnumItem a
  6168. where a.F_EnCode = 'SQEPD'";
  6169. DataTable dts = Repository().FindDataSetBySql(sqls.ToString(), parameter1.ToArray()).Tables[0];
  6170. if (dts == null || dts.Rows.Count == 0)
  6171. {
  6172. return;
  6173. }
  6174. string Email = string.Empty;
  6175. foreach (DataRow drs in dts.Rows)
  6176. {
  6177. Email += drs["Ext1"].ToString() + ",";
  6178. }
  6179. if (type == "1")
  6180. {
  6181. SendEmail(model, Email);
  6182. }
  6183. else if (type == "2")
  6184. {
  6185. SendEmailSQE(model, Email);
  6186. }
  6187. else
  6188. {
  6189. SendEmailIQC(model, Email);
  6190. }
  6191. }
  6192. catch (Exception ex)
  6193. {
  6194. InsertOperateLog(model.CheckNo, JsonConvert.SerializeObject(ex), new IcsMatCheckResult().GetType().Name, "拒收单邮件");
  6195. }
  6196. }
  6197. private void SendEmail(IcsMatCheckResultDto model, string email)
  6198. {
  6199. try
  6200. {
  6201. DateTime dtNow = DateTime.Now;
  6202. string MailOpen = ConfigurationManager.ConnectionStrings["MailOpen"].ConnectionString;
  6203. if (MailOpen == "true")
  6204. {
  6205. string SendHost = ConfigurationManager.ConnectionStrings["SendHost"].ConnectionString;
  6206. string StrSendPort = ConfigurationManager.ConnectionStrings["SendPort"].ConnectionString;
  6207. int SendPort = 25;
  6208. if (!string.IsNullOrEmpty(StrSendPort))
  6209. SendPort = Convert.ToInt32(ConfigurationManager.ConnectionStrings["SendPort"].ConnectionString);
  6210. string SendDisplayName = ConfigurationManager.ConnectionStrings["SendDisplayName"].ConnectionString;
  6211. string SendAddress = ConfigurationManager.ConnectionStrings["SendAddress"].ConnectionString;
  6212. string SendPassword = ConfigurationManager.ConnectionStrings["SendPassword"].ConnectionString;
  6213. string TOAddress = email;
  6214. string CCAddress = "";
  6215. string Subject = "您好!有来自检验拒收的订单";
  6216. bool isBodyHtml = false;
  6217. string body = "";
  6218. body += "\r\n";
  6219. body += "您好!有来自SQE拒收的信息:供应商:" + model.VenName + " ,到货时间:" + model.DHDate.Value.ToShortDateString() + " ,物料编码:" + model.InvCode + ",物料名称:"
  6220. + model.InvName + ",来料数量:" + model.FinalItemLotList.Sum(x => x.Quantity) + ",拒收数量:" + model.FinalItemLotList.Sum(x => x.NgQty) + ",可登陆咖博士WMS系统查看相关信息!";
  6221. body += "\r\n";
  6222. body += " ";
  6223. body += "\r\n";
  6224. body += " 苏州咖博士咖啡系统科技有限公司";
  6225. body += "\r\n";
  6226. body += " " + dtNow.ToString("yyyy-MM-dd");
  6227. string StrConn = MsSqlData.FromMd5(ConfigurationManager.ConnectionStrings["connstr"].ConnectionString);
  6228. //try
  6229. //{
  6230. if (!string.IsNullOrEmpty(TOAddress))
  6231. {
  6232. //MailHelper.SendEmail(StrConn, SendHost, SendPort, SendDisplayName, SendAddress, SendPassword, TOAddress, CCAddress, Subject, isBodyHtml, body, POCode);
  6233. ICSSendMail.SendEmail(StrConn, SendHost, SendPort, SendDisplayName, SendAddress, SendPassword, TOAddress, CCAddress, Subject, isBodyHtml, body);
  6234. }
  6235. else
  6236. {
  6237. //throw new Exception("供应商邮箱地址未维护,邮件发送失败!");
  6238. // msg += "供应商:" + cVenCode + "邮箱地址未维护,邮件发送失败!";
  6239. }
  6240. //}
  6241. //catch (Exception ex)
  6242. //{
  6243. //InsertData(StrConn, SendHost, SendPort, SendDisplayName, SendAddress, SendPassword, TOAddress, CCAddress, Subject, isBodyHtml, body, "0", "");
  6244. //}
  6245. }
  6246. }
  6247. catch (Exception ex)
  6248. {
  6249. throw new Exception("供应商:" + model.VenName + "邮件发送失败! \r\n" + ex.Message);
  6250. // msg += "供应商:" + cVenCode + "邮件发送失败! \r\n" + ex.Message;
  6251. // InsertOperateLog("拒收单邮件", JsonConvert.SerializeObject(ex), new IcsMatCheckResult().GetType().Name, "判退");
  6252. }
  6253. }
  6254. private void SendEmailSQE(IcsMatCheckResultDto model, string email)
  6255. {
  6256. try
  6257. {
  6258. DateTime dtNow = DateTime.Now;
  6259. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  6260. string MailOpen = ConfigurationManager.ConnectionStrings["MailOpen"].ConnectionString;
  6261. if (MailOpen == "true")
  6262. {
  6263. string SendHost = ConfigurationManager.ConnectionStrings["SendHost"].ConnectionString;
  6264. string StrSendPort = ConfigurationManager.ConnectionStrings["SendPort"].ConnectionString;
  6265. int SendPort = 25;
  6266. if (!string.IsNullOrEmpty(StrSendPort))
  6267. SendPort = Convert.ToInt32(ConfigurationManager.ConnectionStrings["SendPort"].ConnectionString);
  6268. string SendDisplayName = ConfigurationManager.ConnectionStrings["SendDisplayName"].ConnectionString;
  6269. string SendAddress = ConfigurationManager.ConnectionStrings["SendAddress"].ConnectionString;
  6270. string SendPassword = ConfigurationManager.ConnectionStrings["SendPassword"].ConnectionString;
  6271. //查询 不良分类
  6272. string sql = $" select BcgDesc from ICSBadCodeGroup where workpoint='{WorkPoint}' and bcgcode='{model.BRGCode}' ";
  6273. var dt = SqlHelper.CmdExecuteDataTable(sql);
  6274. string TOAddress = email;
  6275. string CCAddress = "";
  6276. string Subject = "您好!有来自SQE复判NG的信息";
  6277. bool isBodyHtml = false;
  6278. string body = "";
  6279. body += "\r\n";
  6280. body += "您好!有来自SQE复判NG的信息:供应商:" + model.VenName + " ,到货时间:" + model.DHDate.Value.ToShortDateString() + " ,物料编码:" + model.InvCode + ",物料名称:"
  6281. + model.InvName + ",来料数量:" + model.InvBatcgQty + ",不良分类:" + dt.Rows[0]["BcgDesc"] + ",SQE处理方案:" + model.EATTRIBUTE1 + ",可登陆咖博士WMS系统查看相关信息!";
  6282. body += "\r\n";
  6283. body += " ";
  6284. body += "\r\n";
  6285. body += " 苏州咖博士咖啡系统科技有限公司";
  6286. body += "\r\n";
  6287. body += " " + dtNow.ToString("yyyy-MM-dd");
  6288. string StrConn = MsSqlData.FromMd5(ConfigurationManager.ConnectionStrings["connstr"].ConnectionString);
  6289. //try
  6290. //{
  6291. if (!string.IsNullOrEmpty(TOAddress))
  6292. {
  6293. //MailHelper.SendEmail(StrConn, SendHost, SendPort, SendDisplayName, SendAddress, SendPassword, TOAddress, CCAddress, Subject, isBodyHtml, body, POCode);
  6294. ICSSendMail.SendEmail(StrConn, SendHost, SendPort, SendDisplayName, SendAddress, SendPassword, TOAddress, CCAddress, Subject, isBodyHtml, body);
  6295. }
  6296. else
  6297. {
  6298. //throw new Exception("供应商邮箱地址未维护,邮件发送失败!");
  6299. // msg += "供应商:" + cVenCode + "邮箱地址未维护,邮件发送失败!";
  6300. }
  6301. //}
  6302. //catch (Exception ex)
  6303. //{
  6304. //InsertData(StrConn, SendHost, SendPort, SendDisplayName, SendAddress, SendPassword, TOAddress, CCAddress, Subject, isBodyHtml, body, "0", "");
  6305. //}
  6306. }
  6307. }
  6308. catch (Exception ex)
  6309. {
  6310. throw new Exception("供应商:" + model.VenName + "邮件发送失败! \r\n" + ex.Message);
  6311. // msg += "供应商:" + cVenCode + "邮件发送失败! \r\n" + ex.Message;
  6312. // InsertOperateLog("拒收单邮件", JsonConvert.SerializeObject(ex), new IcsMatCheckResult().GetType().Name, "判退");
  6313. }
  6314. }
  6315. private void SendEmailIQC(IcsMatCheckResultDto model, string email)
  6316. {
  6317. try
  6318. {
  6319. DateTime dtNow = DateTime.Now;
  6320. string MailOpen = ConfigurationManager.ConnectionStrings["MailOpen"].ConnectionString;
  6321. if (MailOpen == "true")
  6322. {
  6323. string SendHost = ConfigurationManager.ConnectionStrings["SendHost"].ConnectionString;
  6324. string StrSendPort = ConfigurationManager.ConnectionStrings["SendPort"].ConnectionString;
  6325. int SendPort = 25;
  6326. if (!string.IsNullOrEmpty(StrSendPort))
  6327. SendPort = Convert.ToInt32(ConfigurationManager.ConnectionStrings["SendPort"].ConnectionString);
  6328. string SendDisplayName = ConfigurationManager.ConnectionStrings["SendDisplayName"].ConnectionString;
  6329. string SendAddress = ConfigurationManager.ConnectionStrings["SendAddress"].ConnectionString;
  6330. string SendPassword = ConfigurationManager.ConnectionStrings["SendPassword"].ConnectionString;
  6331. string TOAddress = email;
  6332. string CCAddress = "";
  6333. string Subject = "您好!有来自IQC复判NG的信息";
  6334. bool isBodyHtml = false;
  6335. string body = "";
  6336. body += "\r\n";
  6337. body += "您好!有来自IQC复判NG的信息:供应商:" + model.VenName + " ,到货时间:" + model.DHDate.Value.ToShortDateString() + " ,物料编码:" + model.InvCode + ",物料名称:"
  6338. + model.InvName + ",来料数量:" + model.InvBatcgQty + ",可登陆咖博士WMS系统查看相关信息!";
  6339. body += "\r\n";
  6340. body += " ";
  6341. body += "\r\n";
  6342. body += " 苏州咖博士咖啡系统科技有限公司";
  6343. body += "\r\n";
  6344. body += " " + dtNow.ToString("yyyy-MM-dd");
  6345. string StrConn = MsSqlData.FromMd5(ConfigurationManager.ConnectionStrings["connstr"].ConnectionString);
  6346. //try
  6347. //{
  6348. if (!string.IsNullOrEmpty(TOAddress))
  6349. {
  6350. //MailHelper.SendEmail(StrConn, SendHost, SendPort, SendDisplayName, SendAddress, SendPassword, TOAddress, CCAddress, Subject, isBodyHtml, body, POCode);
  6351. ICSSendMail.SendEmail(StrConn, SendHost, SendPort, SendDisplayName, SendAddress, SendPassword, TOAddress, CCAddress, Subject, isBodyHtml, body);
  6352. }
  6353. else
  6354. {
  6355. //throw new Exception("供应商邮箱地址未维护,邮件发送失败!");
  6356. // msg += "供应商:" + cVenCode + "邮箱地址未维护,邮件发送失败!";
  6357. }
  6358. //}
  6359. //catch (Exception ex)
  6360. //{
  6361. //InsertData(StrConn, SendHost, SendPort, SendDisplayName, SendAddress, SendPassword, TOAddress, CCAddress, Subject, isBodyHtml, body, "0", "");
  6362. //}
  6363. }
  6364. }
  6365. catch (Exception ex)
  6366. {
  6367. throw new Exception("供应商:" + model.VenName + "邮件发送失败! \r\n" + ex.Message);
  6368. // msg += "供应商:" + cVenCode + "邮件发送失败! \r\n" + ex.Message;
  6369. // InsertOperateLog("拒收单邮件", JsonConvert.SerializeObject(ex), new IcsMatCheckResult().GetType().Name, "判退");
  6370. }
  6371. }
  6372. /// <summary>
  6373. /// 采购
  6374. /// </summary>
  6375. /// <param name="jqgridparam"></param>
  6376. /// <returns></returns>
  6377. public DataTable GetICSInspection(ref Pagination jqgridparam, string MenuID, string queryJson)
  6378. {
  6379. string DataActionsql = actionapp.DataActionSqlGet(MenuID);
  6380. string ERPSign = Configs.GetValue("ERPSign");
  6381. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  6382. DataTable dt = new DataTable();
  6383. var queryParam = queryJson.ToJObject();
  6384. List<DbParameter> parameter = new List<DbParameter>();
  6385. string sql = string.Empty;
  6386. if (ERPSign == "U8")
  6387. {
  6388. sql = @"
  6389. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1'))
  6390. drop table #TempLLData_1
  6391. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1_1'))
  6392. drop table #TempLLData_1_1
  6393. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_1'))
  6394. drop table #TempIcsinsp_1
  6395. select *
  6396. into #TempIcsinsp_1
  6397. from dbo.ICSInspection
  6398. where workpoint='" + WorkPoint + @"' and Enable='1'
  6399. select DISTINCT
  6400. a.ID as DHID,
  6401. d.ID ,
  6402. l.EATTRIBUTE3 as Address,
  6403. h.EATTRIBUTE5,
  6404. h.EATTRIBUTE6,
  6405. h.EATTRIBUTE7,
  6406. h.ID as JYID,
  6407. a.DNCode ,
  6408. -- a.Sequence ,
  6409. a.ASNCode ,
  6410. l.POCode,
  6411. c.InvCode ,
  6412. c.InvName ,
  6413. c.INVSTD ,
  6414. c.ClassName,
  6415. c.EATTRIBUTE3 as InvEATTRIBUTE3,
  6416. CAST(b.DNQuantity as decimal(18,4)) as AllNumber,
  6417. CAST(ISNULL(h.QualifiedQuantity, b.DNQuantity)as decimal(18,4))as YLOTQTY ,
  6418. CAST(ISNULL(h.UnqualifiedQuantity, 0) as decimal(18,4)) as NLOTQTY,
  6419. CAST(ISNULL(h.WaiveQuantity, 0) as decimal(18,4)) as SpecialQTY,
  6420. CASE WHEN isnull(task.ValueParameters,'') =''THEN '否' ELSE '是' END AS IsPrint,
  6421. --CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) as SampleQuantity,
  6422. c.InvUnit ,
  6423. b.LotNo ,
  6424. g.BadReasonDesc as BadReasonDesc ,
  6425. g.BadReasonCode as BRCodeValue,
  6426. j.BadCode as BCCodeValue,
  6427. j.BadDesc as BadDesc,
  6428. k.ContainerID,
  6429. q.ContainerCode,
  6430. isnull(h.EATTRIBUTE2,'') as InspectionEATTRIBUTE2,
  6431. isnull(h.MUSERName,'') MUSERName,
  6432. CONVERT(VARCHAR(100),d.ProductDate,120) as ProductTime,
  6433. CONVERT(VARCHAR(100),a.CreateDateTime,120) as CreateDateTime,
  6434. CONVERT(VARCHAR(100),h.MTIME,120) as MTIME,
  6435. CASE WHEN isnull(h.ID,'') =''THEN '' ELSE '' END AS TestState,
  6436. a.VenCode,
  6437. m.VenName,
  6438. CASE WHEN lotInfo.ID is null THEN '否' ELSE '是' END as IsWH,
  6439. isnull(h.MUSERName,'') as Surveyor,
  6440. h.MTime as ProvingTime
  6441. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  6442. , CASE WHEN h.Result='1' THEN '' when h.Result='0' THEN '' ELSE '' END AS Result,
  6443. n.FileName
  6444. ,CASE WHEN isnull(h.ID,'') ='' and s.Type='Quantity' THEN isnull(p.SampleQuantity,0)
  6445. WHEN isnull(h.ID,'') ='' and s.Type='Ratio' THEN isnull(p.SampleQuantity,0)*b.DNQuantity ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity
  6446. ,o.Editable
  6447. ,(CASE ISNULL((SELECT COUNT(1) FROM dbo.ICSInspection hH2
  6448. WHERE hH2.LotNo=b.LotNo AND hH2.WorkPoint=b.WorkPoint),0)
  6449. WHEN 0 THEN '' WHEN 1 THEN '是' else '否' end ) IsFirstCK
  6450. ,case d.EATTRIBUTE6 when '1' then '是' else '否' end IsUrgent,
  6451. case when isnull(qq.EATTRIBUTE1,'')='' then '否' else '是' end Rejected,c.InvIQC{2}
  6452. into #TempLLData_1
  6453. FROM ICSDeliveryNotice a
  6454. inner JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint
  6455. inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint and c.InvIQC='1'
  6456. inner JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.ExtensionID=d.ExtensionID AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  6457. left join ICSInventoryLotDetail e on d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint
  6458. LEFT JOIN #TempIcsinsp_1 h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint
  6459. LEFT JOIN (SELECT DISTINCT ValueParameters FROM Sys_LableTask) task ON task.ValueParameters=h.ID
  6460. left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  6461. left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  6462. LEFT JOIN ICSContainerLot k ON b.LotNo=k.LotNo AND b.WorkPoint=k.WorkPoint
  6463. LEFT JOIN ICSContainer q on k.ContainerID=q.ContainerID AND k.WorkPoint=q.WorkPoint
  6464. inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND d.WorkPoint=l.WorkPoint
  6465. left join ICSExtension f on d.ExtensionID=f.ID and d.WorkPoint=f.WorkPoint
  6466. left join dbo.ICSVendor m on a.VenCode=m.VenCode and a.WorkPoint=m.WorkPoint
  6467. left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint
  6468. LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint
  6469. left JOIN ICSInspectionRulesGroup s ON o.RulesCode=s.RulesCode AND o.WorkPoint=s.WorkPoint
  6470. LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND b.DNQuantity BETWEEN p.SetValueMin AND p.SetValueMax
  6471. left join ICSDeliveryNotice qq on e.LotNo =qq.EATTRIBUTE1 and qq.DNType='3' and a.WorkPoint=qq.WorkPoint
  6472. left JOIN ICSWareHouseLotInfo lotInfo ON lotInfo.LotNo=e.LotNo AND lotInfo.WorkPoint=e.WorkPoint
  6473. where b.LotNo is not null and a.DNType='1' AND a.WorkPoint='{1}' {0}
  6474. select * into #TempLLData_1_1 from #TempLLData_1 where InvIQC='1'
  6475. ";
  6476. }
  6477. else
  6478. {
  6479. sql = @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1'))
  6480. drop table #TempLLData_1
  6481. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_1'))
  6482. drop table #TempIcsinsp_1
  6483. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1_1'))
  6484. drop table #TempLLData_1_1
  6485. select *
  6486. into #TempIcsinsp_1
  6487. from dbo.ICSInspection
  6488. where workpoint='" + WorkPoint + @"' and Enable='1'
  6489. select DISTINCT
  6490. a.ID as DHID,
  6491. l.EATTRIBUTE3 as Address,
  6492. h.EATTRIBUTE5,
  6493. h.EATTRIBUTE6,
  6494. h.EATTRIBUTE7,
  6495. d.ID ,
  6496. h.ID as JYID,
  6497. a.DNCode ,
  6498. a.Sequence ,
  6499. a.ASNCode ,
  6500. l.POCode,
  6501. c.InvCode ,
  6502. c.InvName ,
  6503. c.INVSTD ,
  6504. c.ClassName,
  6505. c.EATTRIBUTE3 as InvEATTRIBUTE3,
  6506. isnull(h.EATTRIBUTE2,'') as InspectionEATTRIBUTE2,
  6507. CAST(d.Quantity as decimal(18,4)) as AllNumber,
  6508. CAST(ISNULL(h.QualifiedQuantity, d.Quantity)as decimal(18,4))as YLOTQTY ,
  6509. CAST(ISNULL(h.UnqualifiedQuantity, 0) as decimal(18,4)) as NLOTQTY,
  6510. CAST(ISNULL(h.WaiveQuantity, 0) as decimal(18,4)) as SpecialQTY,
  6511. CASE WHEN isnull(task.ValueParameters,'') =''THEN '否' ELSE '是' END AS IsPrint,
  6512. CASE WHEN lotInfo.ID is null THEN '否' ELSE '是' END as IsWH,
  6513. -- CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) as SampleQuantity,
  6514. c.InvUnit ,
  6515. d.LotNo ,
  6516. g.BadReasonDesc as BadReasonDesc ,
  6517. g.BadReasonCode as BRCodeValue,
  6518. j.BadCode as BCCodeValue,
  6519. j.BadDesc as BadDesc,
  6520. k.ContainerID,
  6521. isnull(h.MUSERName,'') MUSERName,
  6522. CONVERT(VARCHAR(100),d.ProductDate,120) as ProductTime,
  6523. CONVERT(VARCHAR(100),a.CreateDateTime,120) as CreateDateTime,
  6524. CONVERT(VARCHAR(100),h.MTIME,120) as MTIME,
  6525. CASE WHEN isnull(h.ID,'') =''THEN '' ELSE '' END AS TestState,
  6526. a.VenCode,
  6527. m.VenName,
  6528. isnull(h.MUSERName,'') as Surveyor,
  6529. h.MTime as ProvingTime
  6530. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4 ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  6531. ,CASE WHEN h.Result='1' THEN '' when h.Result='0' THEN '' ELSE '' END AS Result,
  6532. n.FileName
  6533. ,CASE WHEN isnull(h.ID,'') ='' and s.Type='Quantity' THEN isnull(p.SampleQuantity,0)
  6534. WHEN isnull(h.ID,'') ='' and s.Type='Ratio' THEN isnull(p.SampleQuantity,0)*b.DNQuantity ELSE CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) END AS SampleQuantity
  6535. ,o.Editable
  6536. ,(CASE ISNULL((SELECT COUNT(1) FROM dbo.ICSInspection hH2
  6537. WHERE hH2.LotNo=d.LotNo AND hH2.WorkPoint=a.WorkPoint),0)
  6538. WHEN 0 THEN '' WHEN 1 THEN '是' else '否' end ) IsFirstCK
  6539. , case d.EATTRIBUTE6 when '1' then '是' else '否' end IsUrgent,c.InvIQC{2}
  6540. into #TempLLData_1
  6541. FROM ICSDeliveryNotice a
  6542. --inner JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint
  6543. left join ICSInventoryLotDetail e on a.DNCode=e.TransCode and a.Sequence=e.TransSequence and a.WorkPoint=e.WorkPoint
  6544. inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint and c.InvIQC='1'
  6545. inner JOIN ICSInventoryLot d ON e.LotNo=d.LotNo AND a.InvCode=d.InvCode AND a.WorkPoint=d.WorkPoint
  6546. LEFT JOIN #TempIcsinsp_1 h ON h.LotNo=d.LotNo AND h.WorkPoint=a.WorkPoint
  6547. LEFT JOIN (SELECT DISTINCT ValueParameters FROM Sys_LableTask) task ON task.ValueParameters=h.ID
  6548. left join ICSBadReason g on h.BRCode =g.BadReasonCode and h.WorkPoint=g.WorkPoint
  6549. left join ICSBadCode j on h.BCCode =j.BadCode and h.WorkPoint=j.WorkPoint
  6550. LEFT JOIN ICSContainerLot k ON d.LotNo=k.LotNo AND a.WorkPoint=k.WorkPoint
  6551. inner JOIN ICSPurchaseOrder l ON a.PODetailID=l.PODetailID AND a.WorkPoint=l.WorkPoint
  6552. left join ICSExtension f on d.ExtensionID=f.ID and d.WorkPoint=f.WorkPoint
  6553. left join dbo.ICSVendor m on a.VenCode=m.VenCode and a.WorkPoint=m.WorkPoint
  6554. left join ICSInspectionFile n on h.id=n.InspectionID and h.WorkPoint=n.WorkPoint
  6555. LEFT JOIN ICSInventoryInspectionRulesGroup o ON a.InvCode=o.InvCode AND a.WorkPoint=o.WorkPoint
  6556. left JOIN ICSInspectionRulesGroup s ON o.RulesCode=s.RulesCode AND o.WorkPoint=s.WorkPoint
  6557. LEFT JOIN ICSInventoryInspectionRuleslist p ON o.id=p.invrulesid AND o.WorkPoint=p.WorkPoint AND d.Quantity BETWEEN p.SetValueMax AND p.SetValueMin
  6558. left JOIN ICSWareHouseLotInfo lotInfo ON lotInfo.LotNo=e.LotNo AND lotInfo.WorkPoint=e.WorkPoint
  6559. where d.LotNo is not null and a.DNType='1' AND a.WorkPoint='{1}' {0}
  6560. select * into #TempLLData_1_1 from #TempLLData_1
  6561. ";
  6562. }
  6563. string wheresql = "";
  6564. if (!string.IsNullOrWhiteSpace(queryJson))
  6565. {
  6566. if (!string.IsNullOrWhiteSpace(queryParam["POCode"].ToString()))
  6567. {
  6568. wheresql += " and a.DNCode like '%" + queryParam["POCode"].ToString() + "%' ";
  6569. }
  6570. if (!string.IsNullOrWhiteSpace(queryParam["ASNCode"].ToString()))
  6571. {
  6572. wheresql += " and a.ASNCode like '%" + queryParam["ASNCode"].ToString() + "%' ";
  6573. }
  6574. if (!string.IsNullOrWhiteSpace(queryParam["CaiGouCode"].ToString()))
  6575. {
  6576. wheresql += " and l.POCode like '%" + queryParam["CaiGouCode"].ToString() + "%' ";
  6577. }
  6578. if (!string.IsNullOrWhiteSpace(queryParam["VenCode"].ToString()))
  6579. {
  6580. wheresql += " and a.VenCode like '%" + queryParam["VenCode"].ToString() + "%' ";
  6581. }
  6582. if (!string.IsNullOrWhiteSpace(queryParam["VenName"].ToString()))
  6583. {
  6584. wheresql += " and m.VenName like '%" + queryParam["VenName"].ToString() + "%' ";
  6585. }
  6586. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  6587. {
  6588. wheresql += " and c.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  6589. }
  6590. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  6591. {
  6592. wheresql += " and c.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  6593. }
  6594. if (!string.IsNullOrWhiteSpace(queryParam["InvStd"].ToString()))
  6595. {
  6596. wheresql += " and c.InvStd like '%" + queryParam["InvStd"].ToString() + "%' ";
  6597. }
  6598. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  6599. {
  6600. wheresql += " and f.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  6601. }
  6602. if (!string.IsNullOrWhiteSpace(queryParam["CusBatch"].ToString()))
  6603. {
  6604. wheresql += " and d.EATTRIBUTE3 like '%" + queryParam["CusBatch"].ToString() + "%' ";
  6605. }
  6606. if (!string.IsNullOrWhiteSpace(queryParam["TimeFrom"].ToString()))
  6607. {
  6608. wheresql += " and a.CreateDateTime >= '" + queryParam["TimeFrom"].ToString() + "' ";
  6609. }
  6610. if (!string.IsNullOrWhiteSpace(queryParam["TimeArrive"].ToString()))
  6611. {
  6612. wheresql += " and a.CreateDateTime <= '" + queryParam["TimeArrive"].ToString() + "' ";
  6613. }
  6614. if (!string.IsNullOrWhiteSpace(queryParam["LotNO"].ToString()))
  6615. {
  6616. wheresql += " and b.LotNO like '%" + queryParam["LotNO"].ToString() + "%' ";
  6617. }
  6618. if (!string.IsNullOrWhiteSpace(queryParam["selIsUrgent"].ToString()))
  6619. {
  6620. wheresql += " and case d.EATTRIBUTE6 when '1' then '是' else '否' end = '" + queryParam["selIsUrgent"].ToString() + "' ";
  6621. }
  6622. if (!string.IsNullOrWhiteSpace(queryParam["ReleaseState"].ToString()))
  6623. {
  6624. string ReleaseState = queryParam["ReleaseState"].ToString();
  6625. if (ReleaseState == "1")
  6626. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='已检验'";
  6627. else if (ReleaseState == "0")
  6628. wheresql += " and CASE WHEN isnull(h.ID,'') =''THEN '未检验' ELSE '已检验' END='未检验'";
  6629. else
  6630. wheresql += " ";
  6631. }
  6632. if (!string.IsNullOrWhiteSpace(queryParam["selIsWH"].ToString()))
  6633. {
  6634. if (queryParam["selIsWH"].ToString() == "0")
  6635. {
  6636. wheresql += " and lotInfo.ID is null ";
  6637. }
  6638. if (queryParam["selIsWH"].ToString() == "1")
  6639. {
  6640. wheresql += " and lotInfo.ID is not null ";
  6641. }
  6642. }
  6643. if (!string.IsNullOrWhiteSpace(queryParam["selIsPrint"].ToString()))
  6644. {
  6645. string printState = queryParam["selIsPrint"].ToString();
  6646. if (printState == "否")
  6647. wheresql += " and isnull(task.ValueParameters,'') ='' ";
  6648. else if (printState == "是")
  6649. wheresql += " and isnull(task.ValueParameters,'') <>''";
  6650. }
  6651. if (!string.IsNullOrWhiteSpace(queryParam["selEnableShow"].ToString()))
  6652. {
  6653. string selEnableShow = queryParam["selEnableShow"].ToString();
  6654. if (selEnableShow == "1")
  6655. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) <= 0";
  6656. else if (selEnableShow == "0")
  6657. wheresql += " and ISNULL(h.UnqualifiedQuantity, 0) > 0";
  6658. }
  6659. if (!string.IsNullOrWhiteSpace(queryParam["Rejected"].ToString()))
  6660. {
  6661. string selEnableShow = queryParam["Rejected"].ToString();
  6662. if (selEnableShow == "1")
  6663. wheresql += "and isnull(qq.EATTRIBUTE1,'')<>''";
  6664. else if (selEnableShow == "2")
  6665. wheresql += "and isnull(qq.EATTRIBUTE1,'')=''";
  6666. }
  6667. if (!string.IsNullOrWhiteSpace(queryParam["EATTRIBUTE7"].ToString()))
  6668. {
  6669. wheresql += " and l.EATTRIBUTE7 like '%" + queryParam["EATTRIBUTE7"].ToString() + "%' ";
  6670. }
  6671. }
  6672. wheresql += " " + DataActionsql;
  6673. List<string> tableName = new List<string> { "ICSInspection", "ICSInventory" };
  6674. List<string> tablenameJC = new List<string> { "h.", "c." };
  6675. //sql = SqlHelper.GetEATTRIBUTE(sql, "ICSInspection", "", wheresql, WorkPoint);//
  6676. sql = SqlHelper.GetEATTRIBUTE(sql, tableName, tablenameJC, wheresql, WorkPoint);//
  6677. //sql = string.Format(sql, wheresql, WorkPoint);
  6678. return Repository().FindTablePageBySql_OtherTemp(sql, "#TempLLData_1_1",
  6679. @" if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempLLData_1'))
  6680. drop table #TempLLData_1
  6681. if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TempIcsinsp_1'))
  6682. drop table #TempIcsinsp_1
  6683. if exists(select * from tempdb..sysobjects where id = object_id('tempdb..#TempLLData_1_1'))
  6684. drop table #TempLLData_1_1 ",
  6685. "connstr", parameter.ToArray(), ref jqgridparam);
  6686. // return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  6687. }
  6688. /// <summary>
  6689. /// 新增检验
  6690. /// </summary>
  6691. /// <param name="queryJson"></param>
  6692. /// <returns></returns>
  6693. public string CreateICSInspection(string keyValue, string ICSInspections)
  6694. {
  6695. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  6696. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  6697. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  6698. string msg = "";
  6699. string sql = string.Empty;
  6700. JArray res = (JArray)JsonConvert.DeserializeObject(ICSInspections);
  6701. try
  6702. {
  6703. foreach (var item in res)
  6704. {
  6705. object CARID = Guid.NewGuid();
  6706. JObject jo = (JObject)item;
  6707. string sqls = string.Empty;
  6708. string type = jo["Type"].ToString();
  6709. if (jo["FlagVersion"].ToString() == "1")
  6710. {
  6711. #region 2024-08-09 检验添加是否入库验证
  6712. var checksql = $@"SELECT ID FROM ICSWareHouseLotInfo WHERE LotNo='{jo["LotNo"]}' AND WorkPoint='{WorkPoint}'";
  6713. var checkdt = SqlHelper.CmdExecuteDataTable(checksql);
  6714. if (checkdt.Rows.Count > 0)
  6715. {
  6716. msg = $"条码:{jo["LotNo"]}已经入库,不能再次检验";
  6717. return msg;
  6718. }
  6719. #endregion
  6720. if (!string.IsNullOrWhiteSpace(jo["JYID"].ToString()))
  6721. {
  6722. sqls += "update ICSInspectionDetailGroup set InspectionID='{2}' WHERE InspectionID='{3}' and WorkPoint='{1}' ";
  6723. }
  6724. sqls += @"update ICSInspection set Enable='0' WHERE LotNO='{0}' and Enable='1' and WorkPoint='{1}'";
  6725. sqls = string.Format(sqls, jo["LotNo"].ToString(), WorkPoint, CARID, jo["JYID"].ToString());
  6726. SqlHelper.CmdExecuteNonQueryLi(sqls);
  6727. sql += @"INSERT INTO dbo.ICSInspection
  6728. ( ID ,LotNo,InvCode ,Quantity,QualifiedQuantity ,UnqualifiedQuantity,WaiveQuantity,BCCode,BRCode,Type,MTIME,MUSER ,MUSERName ,WorkPoint ,Enable,SampleQuantity,Result,EATTRIBUTE1)
  6729. Values('{13}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}',getdate(),'{9}','{10}','{11}','1','{12}','{14}','{15}')
  6730. ";
  6731. sql = string.Format(sql, jo["LotNo"].ToString(), jo["InvCode"].ToString(), jo["AllNumber"].ToString(), jo["YLOTQTY"].ToString(), jo["NLOTQTY"].ToString(), jo["SpecialQTY"].ToString(), jo["BCCode"].ToString(), jo["BRCode"].ToString(), jo["Type"].ToString(), MUSER, MUSERNAME, WorkPoint, jo["SampleQuantity"].ToString(), CARID, jo["Result"].ToString(), jo["FlagVersion"].ToString());
  6732. }
  6733. else
  6734. {
  6735. var lotNosql = string.Empty;
  6736. var dt = new DataTable();
  6737. if (jo["FlagVersion"].ToString() == "2")
  6738. {
  6739. //获取各种单据类型的条码数量信息
  6740. if (type == "1")
  6741. {
  6742. lotNosql = $@"SELECT b.LotNo,b.Quantity,b.InvCode FROM ICSDeliveryNotice a
  6743. INNER JOIN ICSInventoryLot b ON a.ExtensionID=b.ExtensionID AND a.WorkPoint=b.WorkPoint
  6744. INNER JOIN ICSASNDetail c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint AND a.ASNCode=c.ASNCode
  6745. INNER JOIN ICSExtension d ON d.ID=b.ExtensionID AND b.WorkPoint=d.WorkPoint
  6746. LEFT JOIN ICSInventoryLotDetail m ON m.LotNo= c.LotNo AND m.WorkPoint= c.WorkPoint
  6747. INNER JOIN ICSPurchaseOrder l ON m.TransID = l.ID AND m.WorkPoint= l.WorkPoint AND l.POID=a.POID
  6748. AND l.PODetailID=a.PODetailID
  6749. WHERE d.BatchCode='{jo["BatchCode"]}' AND a.WorkPoint='{WorkPoint}' AND a.DNCode='{jo["DNCode"]}' AND a.Sequence='{jo["Sequence"]}' AND a.DNType='1'";
  6750. }
  6751. else if (type == "2")
  6752. {
  6753. lotNosql = $@"SELECT d.LotNo,d.Quantity,d.InvCode FROM ICSODeliveryNotice a
  6754. LEFT JOIN ICSOASNDetail b ON a.OASNCode = b.OASNCode AND a.WorkPoint = b.WorkPoint
  6755. inner JOIN ICSInventoryLot d ON b.LotNo = d.LotNo AND a.InvCode = d.InvCode AND b.WorkPoint = d.WorkPoint
  6756. left join ICSInventoryLotDetail e on d.LotNo = e.LotNo and d.WorkPoint = e.WorkPoint
  6757. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  6758. inner JOIN ICSOutsourcingOrder l ON e.TransID = l.ID AND d.WorkPoint = l.WorkPoint
  6759. WHERE a.WorkPoint = '{WorkPoint}' AND a.ODNCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' AND f.BatchCode = '{jo["BatchCode"]}' AND a.ODNType = '1'";
  6760. }
  6761. else if (type == "3")
  6762. {
  6763. lotNosql = $@"SELECT e.LotNo,e.Quantity,e.Invcode from ICSMO a
  6764. inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint = c.WorkPoint--and c.InvIQC = '1'
  6765. left join ICSInventoryLotDetail b on a.MOCode = b.TransCode and a.Sequence = b.TransSequence and a.WorkPoint = b.WorkPoint
  6766. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  6767. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint AND e.ExtensionID = f.ID
  6768. WHERE a.WorkPoint = '{WorkPoint}' AND a.MOCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' AND f.BatchCode = '{jo["BatchCode"]}' ";
  6769. }
  6770. else if (type == "4")
  6771. {
  6772. lotNosql = $@"SELECT e.LotNo,e.Quantity,e.Invcode from ICSOtherIn a
  6773. inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint = c.WorkPoint and c.InvIQC = '1'
  6774. left join ICSInventoryLotDetail b on a.InCode = b.TransCode and a.Sequence = b.TransSequence and a.WorkPoint = b.WorkPoint
  6775. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint AND ISNULL(e.EATTRIBUTE1,'')= ''
  6776. left join ICSExtension f on e.ExtensionID = f.ID and e.WorkPoint = f.WorkPoint
  6777. WHERE a.WorkPoint = '{WorkPoint}' AND a.InCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' AND f.BatchCode = '{jo["BatchCode"]}' ";
  6778. }
  6779. else if (type == "5")
  6780. {
  6781. lotNosql = $@"SELECT e.LotNo,e.Quantity,e.Invcode from ICSMOApplyNeg a
  6782. LEFT JOIN ICSMOApplyNegDetail ad ON a.ApplyNegCode = ad.ApplyNegCode AND a.WorkPoint = ad.WorkPoint
  6783. inner JOIN dbo.ICSInventory c ON ad.InvCode = c.InvCode AND ad.WorkPoint = c.WorkPoint--and c.InvIQC = '1'
  6784. left join ICSInventoryLotDetail b on a.ApplyNegCode = b.TransCode and ad.Sequence = b.TransSequence and ad.WorkPoint = b.WorkPoint
  6785. left join ICSExtension f on ad.ExtensionID = f.ID and ad.WorkPoint = f.WorkPoint
  6786. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint
  6787. WHERE a.WorkPoint = '{WorkPoint}' AND a.ApplyNegCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' AND f.BatchCode = '{jo["BatchCode"]}' ";
  6788. }
  6789. else if (type == "6")
  6790. {
  6791. lotNosql = $@" SELECT e.LotNo,e.Quantity,e.Invcode from ICSOApplyNeg a
  6792. LEFT JOIN ICSOApplyNegDetail ad ON a.OApplyNegCode = ad.OApplyNegCode AND a.WorkPoint = ad.WorkPoint
  6793. inner JOIN dbo.ICSInventory c ON ad.InvCode = c.InvCode AND ad.WorkPoint = c.WorkPoint--and c.InvIQC = '1'
  6794. left join ICSInventoryLotDetail b on a.OApplyNegCode = b.TransCode and ad.Sequence = b.TransSequence and ad.WorkPoint = b.WorkPoint
  6795. left join ICSExtension f on ad.ExtensionID = f.ID and ad.WorkPoint = f.WorkPoint
  6796. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint
  6797. WHERE a.WorkPoint = '{WorkPoint}' AND a.OApplyNegCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' AND f.BatchCode = '{jo["BatchCode"]}' ";
  6798. }
  6799. else if (type == "7")
  6800. {
  6801. lotNosql = $@" SELECT e.LotNo,e.Quantity,e.Invcode from ICSOApplyNeg a
  6802. from ICSSDN a
  6803. inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint = c.WorkPoint--and c.InvIQC = '1'
  6804. left join ICSInventoryLotDetail b on a.SDNCode = b.TransCode and a.Sequence = b.TransSequence and a.WorkPoint = b.WorkPoint
  6805. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  6806. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint
  6807. WHERE a.WorkPoint = '{WorkPoint}' AND a.SDNCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' AND f.BatchCode = '{jo["BatchCode"]}' ";
  6808. }
  6809. else if (type == "8")
  6810. {
  6811. lotNosql = $@" SELECT d.LotNo,d.Quantity,d.Invcode FROM ICSDeliveryNotice a
  6812. left join ICSInventoryLotDetail e on a.DNCode = e.TransCode and a.Sequence = e.TransSequence and a.WorkPoint = e.WorkPoint
  6813. inner JOIN ICSInventory c ON a.InvCode = c.InvCode and a.WorkPoint = c.WorkPoint-- and c.InvIQC = '1'
  6814. inner JOIN ICSInventoryLot d ON e.LotNo = d.LotNo AND a.InvCode = d.InvCode AND a.WorkPoint = d.WorkPoint and d.type = '7'
  6815. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  6816. WHERE a.WorkPoint = '{WorkPoint}' AND a.DNCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' AND f.BatchCode = '{jo["BatchCode"]}' and a.DNType = '1' ";
  6817. }
  6818. else if (type == "9")
  6819. {
  6820. lotNosql = $@" SELECT d.LotNo,d.Quantity,d.Invcode
  6821. FROM ICSODeliveryNotice a
  6822. inner join ICSInventoryLotDetail e on e.TransCode = a.ODNCode AND e.TransSequence = a.Sequence AND e.WorkPoint = a.WorkPoint
  6823. inner JOIN ICSInventoryLot d ON d.LotNo = e.LotNo and d.WorkPoint = e.WorkPoint and d.type = '8'
  6824. inner JOIN ICSInventory c ON a.InvCode = c.InvCode and a.WorkPoint = c.WorkPoint--and c.InvIQC = '1'
  6825. LEFT JOIN dbo.ICSInspection h ON h.LotNo = d.LotNo AND h.WorkPoint = d.WorkPoint
  6826. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  6827. WHERE a.WorkPoint = '{WorkPoint}' AND a.ODNCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' AND f.BatchCode = '{jo["BatchCode"]}' ";
  6828. }
  6829. else if (type == "10")
  6830. {
  6831. lotNosql = $@" SELECT e.LotNo,e.Quantity,e.Invcode
  6832. from ICSMO a
  6833. inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint = c.WorkPoint--and c.InvIQC = '1'
  6834. LEFT JOIN ICSMOPick pick ON a.MODetailID = pick.MODetailID AND a.WorkPoint = pick.WorkPoint AND pick.EATTRIBUTE1 = '1'
  6835. left join ICSInventoryLotDetail b on a.MOCode = b.TransCode and a.Sequence + '~' + pick.Sequence = b.TransSequence and a.WorkPoint = b.WorkPoint
  6836. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  6837. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint
  6838. WHERE a.WorkPoint = '{WorkPoint}' AND a.MOCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' AND f.BatchCode = '{jo["BatchCode"]}' AND a.MOStatus <> '3' ";
  6839. }
  6840. }
  6841. else if (jo["FlagVersion"].ToString() == "3")
  6842. {
  6843. if (type == "1")
  6844. {
  6845. lotNosql = $@"SELECT b.LotNo,b.Quantity,b.InvCode FROM ICSDeliveryNotice a
  6846. INNER JOIN ICSInventoryLot b ON a.ExtensionID=b.ExtensionID AND a.WorkPoint=b.WorkPoint
  6847. INNER JOIN ICSASNDetail c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint AND a.ASNCode=c.ASNCode
  6848. INNER JOIN ICSExtension d ON d.ID=b.ExtensionID AND b.WorkPoint=d.WorkPoint
  6849. LEFT JOIN ICSInventoryLotDetail m ON m.LotNo= c.LotNo AND m.WorkPoint= c.WorkPoint
  6850. INNER JOIN ICSPurchaseOrder l ON m.TransID = l.ID AND m.WorkPoint= l.WorkPoint AND l.POID=a.POID
  6851. AND l.PODetailID=a.PODetailID
  6852. WHERE a.WorkPoint='{WorkPoint}' AND a.DNCode='{jo["DNCode"]}' AND a.Sequence='{jo["Sequence"]}' AND a.DNType='1'";
  6853. }
  6854. else if (type == "2")
  6855. {
  6856. lotNosql = $@"SELECT d.LotNo,d.Quantity,d.InvCode FROM ICSODeliveryNotice a
  6857. LEFT JOIN ICSOASNDetail b ON a.OASNCode = b.OASNCode AND a.WorkPoint = b.WorkPoint
  6858. inner JOIN ICSInventoryLot d ON b.LotNo = d.LotNo AND a.InvCode = d.InvCode AND b.WorkPoint = d.WorkPoint
  6859. left join ICSInventoryLotDetail e on d.LotNo = e.LotNo and d.WorkPoint = e.WorkPoint
  6860. inner JOIN ICSOutsourcingOrder l ON e.TransID = l.ID AND d.WorkPoint = l.WorkPoint
  6861. WHERE a.WorkPoint = '{WorkPoint}' AND a.ODNCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' AND a.ODNType = '1'";
  6862. }
  6863. else if (type == "3")
  6864. {
  6865. lotNosql = $@"SELECT e.LotNo,e.Quantity,e.Invcode from ICSMO a
  6866. inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint --and c.InvIQC='1'
  6867. left join ICSInventoryLotDetail b on a.MOCode=b.TransCode and a.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint
  6868. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  6869. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint AND e.ExtensionID=f.ID
  6870. WHERE a.WorkPoint='{WorkPoint}' AND a.MOCode='{jo["DNCode"]}' AND a.Sequence='{jo["Sequence"]}' ";
  6871. }
  6872. else if (type == "4")
  6873. {
  6874. lotNosql = $@"SELECT e.LotNo,e.Quantity,e.Invcode from ICSOtherIn a
  6875. inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint = c.WorkPoint and c.InvIQC = '1'
  6876. left join ICSInventoryLotDetail b on a.InCode = b.TransCode and a.Sequence = b.TransSequence and a.WorkPoint = b.WorkPoint
  6877. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint AND ISNULL(e.EATTRIBUTE1,'')= ''
  6878. left join ICSExtension f on e.ExtensionID = f.ID and e.WorkPoint = f.WorkPoint
  6879. WHERE a.WorkPoint = '{WorkPoint}' AND a.InCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' ";
  6880. }
  6881. else if (type == "5")
  6882. {
  6883. lotNosql = $@"SELECT e.LotNo,e.Quantity,e.Invcode from ICSMOApplyNeg a
  6884. LEFT JOIN ICSMOApplyNegDetail ad ON a.ApplyNegCode = ad.ApplyNegCode AND a.WorkPoint = ad.WorkPoint
  6885. inner JOIN dbo.ICSInventory c ON ad.InvCode = c.InvCode AND ad.WorkPoint = c.WorkPoint--and c.InvIQC = '1'
  6886. left join ICSInventoryLotDetail b on a.ApplyNegCode = b.TransCode and ad.Sequence = b.TransSequence and ad.WorkPoint = b.WorkPoint
  6887. left join ICSExtension f on ad.ExtensionID = f.ID and ad.WorkPoint = f.WorkPoint
  6888. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint
  6889. WHERE a.WorkPoint = '{WorkPoint}' AND a.ApplyNegCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' ";
  6890. }
  6891. else if (type == "6")
  6892. {
  6893. lotNosql = $@" SELECT e.LotNo,e.Quantity,e.Invcode from ICSOApplyNeg a
  6894. LEFT JOIN ICSOApplyNegDetail ad ON a.OApplyNegCode = ad.OApplyNegCode AND a.WorkPoint = ad.WorkPoint
  6895. inner JOIN dbo.ICSInventory c ON ad.InvCode = c.InvCode AND ad.WorkPoint = c.WorkPoint--and c.InvIQC = '1'
  6896. left join ICSInventoryLotDetail b on a.OApplyNegCode = b.TransCode and ad.Sequence = b.TransSequence and ad.WorkPoint = b.WorkPoint
  6897. left join ICSExtension f on ad.ExtensionID = f.ID and ad.WorkPoint = f.WorkPoint
  6898. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint
  6899. WHERE a.WorkPoint = '{WorkPoint}' AND a.OApplyNegCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' ";
  6900. }
  6901. else if (type == "7")
  6902. {
  6903. lotNosql = $@" SELECT e.LotNo,e.Quantity,e.Invcode from ICSOApplyNeg a
  6904. from ICSSDN a
  6905. inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint = c.WorkPoint--and c.InvIQC = '1'
  6906. left join ICSInventoryLotDetail b on a.SDNCode = b.TransCode and a.Sequence = b.TransSequence and a.WorkPoint = b.WorkPoint
  6907. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  6908. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint
  6909. WHERE a.WorkPoint = '{WorkPoint}' AND a.SDNCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' ";
  6910. }
  6911. else if (type == "8")
  6912. {
  6913. lotNosql = $@" SELECT d.LotNo,d.Quantity,d.Invcode FROM ICSDeliveryNotice a
  6914. left join ICSInventoryLotDetail e on a.DNCode = e.TransCode and a.Sequence = e.TransSequence and a.WorkPoint = e.WorkPoint
  6915. inner JOIN ICSInventory c ON a.InvCode = c.InvCode and a.WorkPoint = c.WorkPoint-- and c.InvIQC = '1'
  6916. inner JOIN ICSInventoryLot d ON e.LotNo = d.LotNo AND a.InvCode = d.InvCode AND a.WorkPoint = d.WorkPoint and d.type = '7'
  6917. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  6918. WHERE a.WorkPoint = '{WorkPoint}' AND a.DNCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' and a.DNType = '1' ";
  6919. }
  6920. else if (type == "9")
  6921. {
  6922. lotNosql = $@" SELECT d.LotNo,d.Quantity,d.Invcode
  6923. FROM ICSODeliveryNotice a
  6924. inner join ICSInventoryLotDetail e on e.TransCode = a.ODNCode AND e.TransSequence = a.Sequence AND e.WorkPoint = a.WorkPoint
  6925. inner JOIN ICSInventoryLot d ON d.LotNo = e.LotNo and d.WorkPoint = e.WorkPoint and d.type = '8'
  6926. inner JOIN ICSInventory c ON a.InvCode = c.InvCode and a.WorkPoint = c.WorkPoint--and c.InvIQC = '1'
  6927. LEFT JOIN dbo.ICSInspection h ON h.LotNo = d.LotNo AND h.WorkPoint = d.WorkPoint
  6928. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  6929. WHERE a.WorkPoint = '{WorkPoint}' AND a.ODNCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' ";
  6930. }
  6931. else if (type == "10")
  6932. {
  6933. lotNosql = $@" SELECT e.LotNo,e.Quantity,e.Invcode
  6934. from ICSMO a
  6935. inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint = c.WorkPoint--and c.InvIQC = '1'
  6936. LEFT JOIN ICSMOPick pick ON a.MODetailID = pick.MODetailID AND a.WorkPoint = pick.WorkPoint AND pick.EATTRIBUTE1 = '1'
  6937. left join ICSInventoryLotDetail b on a.MOCode = b.TransCode and a.Sequence + '~' + pick.Sequence = b.TransSequence and a.WorkPoint = b.WorkPoint
  6938. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  6939. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint
  6940. WHERE a.WorkPoint = '{WorkPoint}' AND a.MOCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' AND a.MOStatus <> '3' ";
  6941. }
  6942. }
  6943. else
  6944. {
  6945. if (type == "1")
  6946. {
  6947. lotNosql = $@"SELECT b.LotNo,b.Quantity,b.InvCode FROM ICSDeliveryNotice a
  6948. INNER JOIN ICSInventoryLot b ON a.ExtensionID=b.ExtensionID AND a.WorkPoint=b.WorkPoint
  6949. INNER JOIN ICSASNDetail c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint AND a.ASNCode=c.ASNCode
  6950. INNER JOIN ICSExtension d ON d.ID=b.ExtensionID AND b.WorkPoint=d.WorkPoint
  6951. LEFT JOIN ICSInventoryLotDetail m ON m.LotNo= c.LotNo AND m.WorkPoint= c.WorkPoint
  6952. INNER JOIN ICSPurchaseOrder l ON m.TransID = l.ID AND m.WorkPoint= l.WorkPoint AND l.POID=a.POID
  6953. AND l.PODetailID=a.PODetailID
  6954. WHERE a.WorkPoint='{WorkPoint}' AND a.DNCode='{jo["DNCode"]}' AND a.DNType='1'";
  6955. }
  6956. else if (type == "2")
  6957. {
  6958. lotNosql = $@"SELECT d.LotNo,d.Quantity,d.InvCode FROM ICSODeliveryNotice a
  6959. LEFT JOIN ICSOASNDetail b ON a.OASNCode = b.OASNCode AND a.WorkPoint = b.WorkPoint
  6960. inner JOIN ICSInventoryLot d ON b.LotNo = d.LotNo AND a.InvCode = d.InvCode AND b.WorkPoint = d.WorkPoint
  6961. left join ICSInventoryLotDetail e on d.LotNo = e.LotNo and d.WorkPoint = e.WorkPoint
  6962. inner JOIN ICSOutsourcingOrder l ON e.TransID = l.ID AND d.WorkPoint = l.WorkPoint
  6963. WHERE a.WorkPoint = '{WorkPoint}' AND a.ODNCode = '{jo["DNCode"]}' AND a.ODNType = '1'";
  6964. }
  6965. else if (type == "3")
  6966. {
  6967. lotNosql = $@"SELECT e.LotNo,e.Quantity,e.Invcode from ICSMO a
  6968. inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint=c.WorkPoint --and c.InvIQC='1'
  6969. left join ICSInventoryLotDetail b on a.MOCode=b.TransCode and a.Sequence=b.TransSequence and a.WorkPoint=b.WorkPoint
  6970. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  6971. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo=b.LotNo AND e.WorkPoint=b.WorkPoint AND e.ExtensionID=f.ID
  6972. WHERE a.WorkPoint='{WorkPoint}' AND a.MOCode='{jo["DNCode"]}' ";
  6973. }
  6974. else if (type == "4")
  6975. {
  6976. lotNosql = $@"SELECT e.LotNo,e.Quantity,e.Invcode from ICSOtherIn a
  6977. inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint = c.WorkPoint and c.InvIQC = '1'
  6978. left join ICSInventoryLotDetail b on a.InCode = b.TransCode and a.Sequence = b.TransSequence and a.WorkPoint = b.WorkPoint
  6979. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint AND ISNULL(e.EATTRIBUTE1,'')= ''
  6980. left join ICSExtension f on e.ExtensionID = f.ID and e.WorkPoint = f.WorkPoint
  6981. WHERE a.WorkPoint = '{WorkPoint}' AND a.InCode = '{jo["DNCode"]}' AND a.Sequence = '{jo["Sequence"]}' AND f.BatchCode = '{jo["BatchCode"]}' ";
  6982. }
  6983. else if (type == "5")
  6984. {
  6985. lotNosql = $@"SELECT e.LotNo,e.Quantity,e.Invcode from ICSMOApplyNeg a
  6986. LEFT JOIN ICSMOApplyNegDetail ad ON a.ApplyNegCode = ad.ApplyNegCode AND a.WorkPoint = ad.WorkPoint
  6987. inner JOIN dbo.ICSInventory c ON ad.InvCode = c.InvCode AND ad.WorkPoint = c.WorkPoint--and c.InvIQC = '1'
  6988. left join ICSInventoryLotDetail b on a.ApplyNegCode = b.TransCode and ad.Sequence = b.TransSequence and ad.WorkPoint = b.WorkPoint
  6989. left join ICSExtension f on ad.ExtensionID = f.ID and ad.WorkPoint = f.WorkPoint
  6990. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint
  6991. WHERE a.WorkPoint = '{WorkPoint}' AND a.ApplyNegCode = '{jo["DNCode"]}' ";
  6992. }
  6993. else if (type == "6")
  6994. {
  6995. lotNosql = $@" SELECT e.LotNo,e.Quantity,e.Invcode from ICSOApplyNeg a
  6996. LEFT JOIN ICSOApplyNegDetail ad ON a.OApplyNegCode = ad.OApplyNegCode AND a.WorkPoint = ad.WorkPoint
  6997. inner JOIN dbo.ICSInventory c ON ad.InvCode = c.InvCode AND ad.WorkPoint = c.WorkPoint--and c.InvIQC = '1'
  6998. left join ICSInventoryLotDetail b on a.OApplyNegCode = b.TransCode and ad.Sequence = b.TransSequence and ad.WorkPoint = b.WorkPoint
  6999. left join ICSExtension f on ad.ExtensionID = f.ID and ad.WorkPoint = f.WorkPoint
  7000. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint
  7001. WHERE a.WorkPoint = '{WorkPoint}' AND a.OApplyNegCode = '{jo["DNCode"]}' ";
  7002. }
  7003. else if (type == "7")
  7004. {
  7005. lotNosql = $@" SELECT e.LotNo,e.Quantity,e.Invcode from ICSOApplyNeg a
  7006. from ICSSDN a
  7007. inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint = c.WorkPoint--and c.InvIQC = '1'
  7008. left join ICSInventoryLotDetail b on a.SDNCode = b.TransCode and a.Sequence = b.TransSequence and a.WorkPoint = b.WorkPoint
  7009. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  7010. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint
  7011. WHERE a.WorkPoint = '{WorkPoint}' AND a.SDNCode = '{jo["DNCode"]}' ";
  7012. }
  7013. else if (type == "8")
  7014. {
  7015. lotNosql = $@" SELECT d.LotNo,d.Quantity,d.Invcode FROM ICSDeliveryNotice a
  7016. left join ICSInventoryLotDetail e on a.DNCode = e.TransCode and a.Sequence = e.TransSequence and a.WorkPoint = e.WorkPoint
  7017. inner JOIN ICSInventory c ON a.InvCode = c.InvCode and a.WorkPoint = c.WorkPoint-- and c.InvIQC = '1'
  7018. inner JOIN ICSInventoryLot d ON e.LotNo = d.LotNo AND a.InvCode = d.InvCode AND a.WorkPoint = d.WorkPoint and d.type = '7'
  7019. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  7020. WHERE a.WorkPoint = '{WorkPoint}' AND a.DNCode = '{jo["DNCode"]}' and a.DNType = '1' ";
  7021. }
  7022. else if (type == "9")
  7023. {
  7024. lotNosql = $@" SELECT d.LotNo,d.Quantity,d.Invcode
  7025. FROM ICSODeliveryNotice a
  7026. inner join ICSInventoryLotDetail e on e.TransCode = a.ODNCode AND e.TransSequence = a.Sequence AND e.WorkPoint = a.WorkPoint
  7027. inner JOIN ICSInventoryLot d ON d.LotNo = e.LotNo and d.WorkPoint = e.WorkPoint and d.type = '8'
  7028. inner JOIN ICSInventory c ON a.InvCode = c.InvCode and a.WorkPoint = c.WorkPoint--and c.InvIQC = '1'
  7029. LEFT JOIN dbo.ICSInspection h ON h.LotNo = d.LotNo AND h.WorkPoint = d.WorkPoint
  7030. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  7031. WHERE a.WorkPoint = '{WorkPoint}' AND a.ODNCode = '{jo["DNCode"]}' ";
  7032. }
  7033. else if (type == "10")
  7034. {
  7035. lotNosql = $@" SELECT e.LotNo,e.Quantity,e.Invcode
  7036. from ICSMO a
  7037. inner JOIN dbo.ICSInventory c ON a.InvCode = c.InvCode AND a.WorkPoint = c.WorkPoint--and c.InvIQC = '1'
  7038. LEFT JOIN ICSMOPick pick ON a.MODetailID = pick.MODetailID AND a.WorkPoint = pick.WorkPoint AND pick.EATTRIBUTE1 = '1'
  7039. left join ICSInventoryLotDetail b on a.MOCode = b.TransCode and a.Sequence + '~' + pick.Sequence = b.TransSequence and a.WorkPoint = b.WorkPoint
  7040. left join ICSExtension f on a.ExtensionID = f.ID and a.WorkPoint = f.WorkPoint
  7041. LEFT JOIN dbo.ICSInventoryLot e ON e.LotNo = b.LotNo AND e.WorkPoint = b.WorkPoint
  7042. WHERE a.WorkPoint = '{WorkPoint}' AND a.MOCode = '{jo["DNCode"]}' AND a.MOStatus <> '3' ";
  7043. }
  7044. }
  7045. dt = SqlHelper.CmdExecuteDataTable(lotNosql);
  7046. if (dt.Rows.Count > 0)
  7047. {
  7048. for (int i = 0; i < dt.Rows.Count; i++)
  7049. {
  7050. #region 2024-08-09 检验添加是否入库验证
  7051. var checksql = $@"SELECT ID FROM ICSWareHouseLotInfo WHERE LotNo='{dt.Rows[i]["LotNo"]}' AND WorkPoint='{WorkPoint}'";
  7052. var checkdt = SqlHelper.CmdExecuteDataTable(checksql);
  7053. if (checkdt.Rows.Count > 0)
  7054. {
  7055. msg = $"条码:{jo["LotNo"]}已经入库,不能再次检验";
  7056. return msg;
  7057. }
  7058. #endregion
  7059. object id = Guid.NewGuid();
  7060. sql += $@" update ICSInspectionDetailGroup set InspectionID='{id}' WHERE InspectionID=(Select ID from ICSInspection WHERE LotNO='{dt.Rows[i]["LotNo"]}' and Enable='1' and WorkPoint='{WorkPoint}') and WorkPoint='{WorkPoint}' ;
  7061. update ICSInspection set Enable='0' WHERE LotNO='{dt.Rows[i]["LotNo"]}' and Enable='1' and WorkPoint='{WorkPoint}' ;
  7062. INSERT INTO dbo.ICSInspection ( ID ,LotNo,InvCode ,Quantity,QualifiedQuantity ,UnqualifiedQuantity,WaiveQuantity,BCCode,BRCode,Type,MTIME,MUSER ,MUSERName ,WorkPoint ,Enable,SampleQuantity,Result,EATTRIBUTE1)
  7063. Values('{id}','{dt.Rows[i]["LotNo"]}','{dt.Rows[i]["InvCode"]}','{dt.Rows[i]["Quantity"]}','{dt.Rows[i]["Quantity"]}','0','0','','','{type}',getdate(),'{MUSER}','{MUSERNAME}','{WorkPoint}','1','0','1','{jo["FlagVersion"]}') ; ";
  7064. }
  7065. }
  7066. }
  7067. }
  7068. //}
  7069. if (SqlHelper.ExecuteNonQuery(sql) > 0)
  7070. {
  7071. }
  7072. else
  7073. {
  7074. msg = "新增失败";
  7075. }
  7076. }
  7077. catch (Exception ex)
  7078. {
  7079. throw new Exception(ex.Message);
  7080. }
  7081. return msg;
  7082. }
  7083. public DataTable GetRulesDetail(string LotNo)
  7084. {
  7085. DataTable dt = new DataTable();
  7086. //var queryParam = queryJson.ToJObject();
  7087. List<DbParameter> parameter = new List<DbParameter>();
  7088. string sql = string.Empty;
  7089. //增加pp子表查询 主要查询U8到货单数量
  7090. sql = @"select DISTINCT
  7091. CAST(ISNULL(h.SampleQuantity, 0) as decimal(18,4)) as SampleQuantity,
  7092. b.LotNo ,
  7093. b.Quantity,
  7094. '',
  7095. g.RulesCode,
  7096. c.InvCode,
  7097. c.InvStd,
  7098. c.InvName,h.UnqualifiedQuantity,h.EATTRIBUTE2,h.EATTRIBUTE3,h.WaiveQuantity,h.EATTRIBUTE4
  7099. ,h.EATTRIBUTE5,h.EATTRIBUTE6,h.EATTRIBUTE7,h.EATTRIBUTE8
  7100. ,Case When h.Result=1 then 'OK' ELSE 'NG' END AS Result
  7101. FROM ICSDeliveryNotice a
  7102. inner JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint
  7103. inner JOIN ICSInventory c ON a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint --and c.InvIQC='1'
  7104. inner JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  7105. left join ICSInventoryLotDetail e on d.LotNo=e.LotNo and d.WorkPoint=e.WorkPoint
  7106. LEFT JOIN dbo.ICSInspection h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint --and Enable='1'
  7107. LEFT JOIN ICSInventoryInspectionRulesGroup g ON c.InvCode=g.InvCode AND c.WorkPoint=g.WorkPoint
  7108. Where b.LotNo='" + LotNo + "'";
  7109. return Repository().FindTableBySql(sql.ToString());
  7110. }
  7111. public DataTable GetInventoryInspectionNew(ref Pagination jqgridparam, string InvCode, int? SampleQuantity, string ResultINp, string JYID, string LotNo, decimal AllNumber)
  7112. {
  7113. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  7114. DataTable dt = new DataTable();
  7115. List<DbParameter> parameter = new List<DbParameter>();
  7116. string sql = string.Empty;
  7117. if (ResultINp == "")
  7118. {
  7119. sql += @" IF EXISTS (SELECT ID FROM ICSInspectionDetailGroup WHERE InspectionID='{3}' )
  7120. BEGIN
  7121. declare @sql varchar(8000)
  7122. select distinct b.ID,i.GroupCode,i.GroupName,b.EATTRIBUTE1 AS InspectStander,b.EATTRIBUTE6,b.EATTRIBUTE7,c.InspectionID,b.ListCode, '{0}' AS UnqualifiedQuantity ,b.ListName,b.Unit,b.SetValueMax,b.SetValueMin,d.SetValue,CASE WHEN c.Result='0' THEN 'NG' when ISNULL(c.Result,'')='' THEN 'OK' ELSE 'OK' END AS Result,d.Sequence ,g.EATTRIBUTE1 ,case when g.EATTRIBUTE2='1' then g.SampleQuantity ELSE {4}*0.01*
  7123. g.SampleQuantity END SamplingQuantity ,f.RulesCode,b.EATTRIBUTE5,c.EATTRIBUTE30
  7124. into #TempSORRFQ
  7125. from ICSInventoryInspectionGroup a
  7126. left join ICSInventoryInspectionList b on a.ID=b.InvGroupID and a.WorkPoint=b.WorkPoint
  7127. LEFT JOIN ICSInspectionList h on h.ListCode=b.ListCode and h.WorkPoint=b.WorkPoint
  7128. LEFT JOIN ICSInspectionGroup i on i.ID=h.GroupID and i.WorkPoint=h.WorkPoint
  7129. left join ICSInspectionDetailGroup c on b.ListCode=c.ListCode and a.GroupCode=c.GroupCode and b.WorkPoint=c.WorkPoint
  7130. left JOIN ICSInspectionDetail d ON c.ID=d.DetailGroupID AND c.WorkPoint=d.WorkPoint
  7131. left join ICSInspectionGroup e ON a.GroupCode=e.GroupCode and e.WorkPoint=a.WorkPoint
  7132. LEFT JOIN ICSInspectionRulesGroup f ON f.RulesCode=b.EATTRIBUTE5 AND f.WorkPoint=b.WorkPoint
  7133. LEFT JOIN ICSInspectionRulesList g ON f.id=g.RulesID AND f.WorkPoint=g.WorkPoint AND g.SetValueMin<={4} AND g.SetValueMax>={4}
  7134. where a.InvCode='{0}' and b.Enable='1' and a.WorkPoint='{1}'and c.InspectionID='{3}' and b.EATTRIBUTE6='Size'
  7135. If (SELECT top 1 Sequence FROM #TempSORRFQ) is not null
  7136. BEGIN
  7137. select @sql=isnull(@sql+',','')+' ['+Sequence+']'
  7138. from(select distinct Sequence from #TempSORRFQ)as a
  7139. set @sql='SELECT STUFF((select'','' + Sequence from (SELECT DISTINCT Sequence FROM #TempSORRFQ ) DD for xml path('''')),1,1,'''') as IsTou,*
  7140. FROM #TempSORRFQ PIVOT(MAX(SetValue) FOR Sequence IN ('+@sql+'))a '
  7141. exec(@sql);
  7142. END
  7143. ELSE
  7144. BEGIN
  7145. SELECT * FROM #TempSORRFQ
  7146. END
  7147. drop table #TempSORRFQ;
  7148. END
  7149. ELSE
  7150. BEGIN
  7151. select DISTINCT b.ID,a.GroupCode,a.GroupName,b.EATTRIBUTE1 AS InspectStander,b.EATTRIBUTE6,b.EATTRIBUTE7,'' as InspectionID,b.ListCode, 0 AS UnqualifiedQuantity ,b.ListName,b.Unit,b.SetValueMax,b.SetValueMin,'' AS SetValue,'OK' AS Result,g.EATTRIBUTE1 ,case when g.EATTRIBUTE2='1' then g.SampleQuantity ELSE {4}*0.01*
  7152. g.SampleQuantity END SamplingQuantity ,f.RulesCode,b.EATTRIBUTE5,'' AS EATTRIBUTE30
  7153. from ICSInventoryInspectionGroup a
  7154. left join ICSInventoryInspectionList b on a.ID=b.InvGroupID and a.WorkPoint=b.WorkPoint
  7155. LEFT JOIN ICSInspectionList h on h.ListCode=b.ListCode and h.WorkPoint=b.WorkPoint
  7156. left join ICSInspectionGroup e ON a.GroupCode=e.GroupCode and e.WorkPoint=a.WorkPoint
  7157. LEFT JOIN ICSInspectionRulesGroup f ON f.RulesCode=b.EATTRIBUTE5 AND f.WorkPoint=b.WorkPoint
  7158. LEFT JOIN ICSInspectionRulesList g ON f.id=g.RulesID AND f.WorkPoint=g.WorkPoint AND g.SetValueMin<={4} AND g.SetValueMax>={4}
  7159. where a.InvCode='{0}' and b.Enable='1' and a.WorkPoint='{1}' and b.EATTRIBUTE6='Size'
  7160. END
  7161. ";
  7162. sql = string.Format(sql, InvCode, WorkPoint, JYID, LotNo, AllNumber);
  7163. return SqlHelper.CmdExecuteDataTable(sql);
  7164. }
  7165. else
  7166. {
  7167. sql += @" declare @sql varchar(8000)
  7168. select b.ID,i.GroupCode,i.GroupName,b.EATTRIBUTE1 AS InspectStander,b.EATTRIBUTE6,b.EATTRIBUTE7,c.InspectionID,b.ListCode, c.UnqualifiedQuantity ,b.ListName,b.Unit,b.SetValueMax,b.SetValueMin,d.SetValue,CASE WHEN c.Result='0' THEN 'NG' when ISNULL(c.Result,'')='' THEN 'OK' ELSE 'OK' END AS Result,d.Sequence,c.EATTRIBUTE1 BadReason,g.EATTRIBUTE1 ,case when g.EATTRIBUTE2='1' then g.SampleQuantity ELSE {4}*0.01*g.SampleQuantity END SamplingQuantity ,f.RulesCode,b.EATTRIBUTE5,c.EATTRIBUTE30
  7169. into #TempSORRFQ
  7170. from ICSInventoryInspectionGroup a
  7171. inner join ICSInventoryInspectionList b on a.ID=b.InvGroupID and a.WorkPoint=b.WorkPoint
  7172. LEFT JOIN ICSInspectionList h on h.ListCode=b.ListCode and h.WorkPoint=b.WorkPoint
  7173. LEFT JOIN ICSInspectionGroup i on i.GroupCode=a.GroupCode and i.WorkPoint=h.WorkPoint
  7174. left join ICSInspectionDetailGroup c on b.ListCode=c.ListCode and a.GroupCode=c.GroupCode and b.WorkPoint=c.WorkPoint
  7175. left JOIN ICSInspectionDetail d ON c.ID=d.DetailGroupID AND c.WorkPoint=d.WorkPoint
  7176. left join ICSInspectionGroup e ON a.GroupCode=e.GroupCode and e.WorkPoint=a.WorkPoint
  7177. LEFT JOIN ICSInspectionRulesGroup f ON f.RulesCode=b.EATTRIBUTE5 AND f.WorkPoint=b.WorkPoint
  7178. LEFT JOIN ICSInspectionRulesList g ON f.id=g.RulesID AND f.WorkPoint=g.WorkPoint AND g.SetValueMin<={4} AND g.SetValueMax>={4}
  7179. where a.InvCode='{0}' and b.Enable='1' and a.WorkPoint='{1}'and (c.InspectionID='{2}' or c.InspectionID='{3}' ) and b.EATTRIBUTE6='Size'
  7180. If (SELECT top 1 Sequence FROM #TempSORRFQ) is not null
  7181. BEGIN
  7182. select @sql=isnull(@sql+',','')+' ['+Sequence+']'
  7183. from(select distinct Sequence from #TempSORRFQ)as a
  7184. set @sql='SELECT STUFF((select'','' + Sequence from (SELECT DISTINCT Sequence FROM #TempSORRFQ ) DD for xml path('''')),1,1,'''') as IsTou,*
  7185. FROM #TempSORRFQ PIVOT(MAX(SetValue) FOR Sequence IN ('+@sql+'))a '
  7186. exec(@sql)
  7187. END
  7188. ELSE
  7189. BEGIN
  7190. SELECT * FROM #TempSORRFQ
  7191. END
  7192. ";
  7193. sql = string.Format(sql, InvCode, WorkPoint, JYID, LotNo, AllNumber);
  7194. return SqlHelper.FindTablePageBySql_OtherTempSORRFQ(sql.ToString(), " " + "#TempSORRFQ" + " ", " drop table #TempSORRFQ", parameter.ToArray(), ref jqgridparam);
  7195. }
  7196. }
  7197. public DataTable GetInventoryInspectionNew1(ref Pagination jqgridparam, string InvCode, int? SampleQuantity, string ResultINp, string JYID, string LotNo, decimal AllNumber)
  7198. {
  7199. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  7200. DataTable dt = new DataTable();
  7201. List<DbParameter> parameter = new List<DbParameter>();
  7202. string sql = string.Empty;
  7203. if (ResultINp == "")
  7204. {
  7205. sql += @"
  7206. select DISTINCT b.ID,A.GroupCode,A.GroupName,b.EATTRIBUTE1 AS InspectStander,b.EATTRIBUTE6,b.EATTRIBUTE7,'' as InspectionID,b.ListCode, 0 AS UnqualifiedQuantity ,b.ListName,b.Unit,b.SetValueMax,b.SetValueMin,'OK' AS Result
  7207. ,g.EATTRIBUTE1 ,case when g.EATTRIBUTE2='1' then g.SampleQuantity ELSE {4}*0.01*g.SampleQuantity END SamplingQuantity ,f.RulesCode,b.EATTRIBUTE5,'' AS EATTRIBUTE30
  7208. from ICSInventoryInspectionGroup a
  7209. left join ICSInventoryInspectionList b on a.ID=b.InvGroupID and a.WorkPoint=b.WorkPoint
  7210. left join ICSInspectionGroup e ON a.GroupCode=e.GroupCode and e.WorkPoint=a.WorkPoint
  7211. LEFT JOIN ICSInspectionList h on h.ListCode=b.ListCode and h.GroupID=e.ID and h.WorkPoint=b.WorkPoint
  7212. LEFT JOIN ICSInspectionRulesGroup f ON f.RulesCode=b.EATTRIBUTE5 AND f.WorkPoint=b.WorkPoint
  7213. LEFT JOIN ICSInspectionRulesList g ON f.id=g.RulesID AND f.WorkPoint=g.WorkPoint AND g.SetValueMin<={4} AND g.SetValueMax>={4}
  7214. where a.InvCode='{0}' and b.Enable='1' and a.WorkPoint='{1}' and b.EATTRIBUTE6='Carton'
  7215. ";
  7216. sql = string.Format(sql, InvCode, WorkPoint, JYID, LotNo, AllNumber);
  7217. return SqlHelper.CmdExecuteDataTable(sql);
  7218. }
  7219. else
  7220. {
  7221. sql += @" declare @sql varchar(8000)
  7222. select b.ID,A.GroupCode,A.GroupName,b.EATTRIBUTE1 AS InspectStander,b.EATTRIBUTE6,b.EATTRIBUTE7,c.InspectionID,b.ListCode, c.UnqualifiedQuantity ,b.ListName,b.Unit,b.SetValueMax,b.SetValueMin,d.SetValue,CASE WHEN c.Result='0' THEN 'NG' when ISNULL(c.Result,'')='' THEN 'OK' ELSE 'OK' END AS Result,d.Sequence,c.EATTRIBUTE1 BadReason, g.EATTRIBUTE1 ,case when g.EATTRIBUTE2='1' then g.SampleQuantity ELSE {4}*0.01*
  7223. g.SampleQuantity END SamplingQuantity ,f.RulesCode,b.EATTRIBUTE5,c.EATTRIBUTE30
  7224. into #TempSORRFQ
  7225. from ICSInventoryInspectionGroup a
  7226. inner join ICSInventoryInspectionList b on a.ID=b.InvGroupID and a.WorkPoint=b.WorkPoint
  7227. left join ICSInspectionDetailGroup c on b.ListCode=c.ListCode and a.GroupCode=c.GroupCode and b.WorkPoint=c.WorkPoint
  7228. left JOIN ICSInspectionDetail d ON c.ID=d.DetailGroupID AND c.WorkPoint=d.WorkPoint
  7229. left join ICSInspectionGroup e ON a.GroupCode=e.GroupCode and e.WorkPoint=a.WorkPoint
  7230. LEFT JOIN ICSInspectionList h on h.ListCode=b.ListCode and h.GroupID=e.ID and h.WorkPoint=b.WorkPoint
  7231. LEFT JOIN ICSInspectionRulesGroup f ON f.RulesCode=b.EATTRIBUTE5 AND f.WorkPoint=b.WorkPoint
  7232. LEFT JOIN ICSInspectionRulesList g ON f.id=g.RulesID AND f.WorkPoint=g.WorkPoint AND g.SetValueMin<={4} AND g.SetValueMax>={4}
  7233. where a.InvCode='{0}' and b.Enable='1' and a.WorkPoint='{1}'and (c.InspectionID='{2}' or c.InspectionID='{3}' ) and b.EATTRIBUTE6='Carton'
  7234. If (SELECT top 1 Sequence FROM #TempSORRFQ) is not null
  7235. BEGIN
  7236. select @sql=isnull(@sql+',','')+' ['+Sequence+']'
  7237. from(select distinct Sequence from #TempSORRFQ)as a
  7238. set @sql='SELECT STUFF((select'','' + Sequence from (SELECT DISTINCT Sequence FROM #TempSORRFQ ) DD for xml path('''')),1,1,'''') as IsTou,*
  7239. FROM #TempSORRFQ PIVOT(MAX(SetValue) FOR Sequence IN ('+@sql+'))a '
  7240. exec(@sql)
  7241. END
  7242. ELSE
  7243. BEGIN
  7244. SELECT * FROM #TempSORRFQ
  7245. END
  7246. ";
  7247. sql = string.Format(sql, InvCode, WorkPoint, JYID, LotNo, AllNumber);
  7248. return SqlHelper.FindTablePageBySql_OtherTempSORRFQ(sql.ToString(), " " + "#TempSORRFQ" + " ", " drop table #TempSORRFQ", parameter.ToArray(), ref jqgridparam);
  7249. }
  7250. }
  7251. /// <summary>
  7252. /// 检验修改
  7253. /// </summary>
  7254. /// <param name="ICSMTDOC"></param>
  7255. /// <param name="InvCode"></param>
  7256. /// <param name="ResultINp"></param>
  7257. /// <returns></returns>
  7258. public string UpdateICSInspectionDetailNew(string ICSMTDOC, string InvCode, string JYID, string AllNumber, string YLOTQTY, string NLOTQTY, string WaiveQuantity, string Filtering, string SpecialNumber, string ResultINp, string SpecialPicks, string Lot, string Type, decimal CJQty, string LotResult, decimal Manhours, decimal Rejections, decimal OtherNumber)
  7259. {
  7260. string msg = "";
  7261. try
  7262. {
  7263. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  7264. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  7265. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  7266. StringBuilder sqlBuilder = new StringBuilder();
  7267. JArray res = (JArray)JsonConvert.DeserializeObject(ICSMTDOC);
  7268. bool ISOK = true;
  7269. string ID = string.Empty;
  7270. // 删除操作 - 使用参数化查询
  7271. string deleteSql = @"DELETE c from ICSInspection a
  7272. left join ICSInspectionDetailGroup b on a.ID = b.inspectionID and a.workPoint = b.workPoint
  7273. left join ICSInspectionDetail c on b.id = c.DetailGroupID and b.workPoint = c.workPoint
  7274. Where a.ID=@JYID";
  7275. sqlBuilder.AppendLine("BEGIN TRANSACTION;");
  7276. // 这里应该使用参数化执行,但为了保持您的结构,暂时拼接
  7277. sqlBuilder.AppendLine($"DELETE c from ICSInspection a left join ICSInspectionDetailGroup b on a.ID = b.inspectionID and a.workPoint = b.workPoint left join ICSInspectionDetail c on b.id = c.DetailGroupID and b.workPoint = c.workPoint Where a.ID='{JYID}';");
  7278. sqlBuilder.AppendLine($"DELETE ICSInspectionDetailGroup where inspectionID='{JYID}';");
  7279. foreach (var item in res)
  7280. {
  7281. string Guids = Guid.NewGuid().ToString();
  7282. JObject jo = (JObject)item;
  7283. JArray detailres = (JArray)JsonConvert.DeserializeObject(jo["LWFiledName"].ToString());
  7284. // 处理结果字段
  7285. string resultValue = jo["Result"]?.ToString() ?? "";
  7286. string resultSqlValue = !string.IsNullOrEmpty(resultValue) ? $"'{resultValue.Replace("'", "''")}'" : "NULL";
  7287. // 处理其他可能为空的字段
  7288. string listCode = jo["ListCode"]?.ToString() ?? "";
  7289. string listName = jo["ListName"]?.ToString() ?? "";
  7290. string unit = jo["Unit"]?.ToString() ?? "";
  7291. string setValueMax = jo["SetValueMax"]?.ToString() ?? "";
  7292. string setValueMin = jo["SetValueMin"]?.ToString() ?? "";
  7293. string setValue = jo["SetValue"]?.ToString() ?? "";
  7294. string groupCode = jo["GroupCode"]?.ToString() ?? "";
  7295. string groupName = jo["GroupName"]?.ToString() ?? "";
  7296. string badReason = jo["BadReason"]?.ToString() ?? "";
  7297. string samplingQuantity = jo["SamplingQuantity"]?.ToString() ?? "";
  7298. string memo = jo["Memo"]?.ToString() ?? "";
  7299. // 构建插入ICSInspectionDetailGroup的SQL
  7300. sqlBuilder.AppendLine($@"
  7301. INSERT INTO dbo.ICSInspectionDetailGroup
  7302. (ID, InspectionID, ListCode, ListName, Unit, SetValueMax, SetValueMin,
  7303. UnqualifiedQuantity, Result, MUSER, MUSERName, MTIME, WorkPoint,
  7304. GroupCode, GroupName, EATTRIBUTE1, EATTRIBUTE2, EATTRIBUTE30)
  7305. VALUES(
  7306. '{Guids}',
  7307. '{jo["InspectionID"]?.ToString().Replace("'", "''") ?? ""}',
  7308. {(string.IsNullOrEmpty(listCode) ? "NULL" : $"'{listCode.Replace("'", "''")}'")},
  7309. {(string.IsNullOrEmpty(listName) ? "NULL" : $"'{listName.Replace("'", "''")}'")},
  7310. {(string.IsNullOrEmpty(unit) ? "NULL" : $"'{unit.Replace("'", "''")}'")},
  7311. {(string.IsNullOrEmpty(setValueMax) ? "NULL" : $"'{setValueMax.Replace("'", "''")}'")},
  7312. {(string.IsNullOrEmpty(setValueMin) ? "NULL" : $"'{setValueMin.Replace("'", "''")}'")},
  7313. {(string.IsNullOrEmpty(setValue) ? "NULL" : $"'{setValue.Replace("'", "''")}'")},
  7314. {resultSqlValue},
  7315. '{MUSER}',
  7316. '{MUSERNAME}',
  7317. GETDATE(),
  7318. '{WorkPoint}',
  7319. {(string.IsNullOrEmpty(groupCode) ? "NULL" : $"'{groupCode.Replace("'", "''")}'")},
  7320. {(string.IsNullOrEmpty(groupName) ? "NULL" : $"'{groupName.Replace("'", "''")}'")},
  7321. {(string.IsNullOrEmpty(badReason) ? "NULL" : $"'{badReason.Replace("'", "''")}'")},
  7322. {(string.IsNullOrEmpty(samplingQuantity) ? "NULL" : $"'{samplingQuantity.Replace("'", "''")}'")},
  7323. {(string.IsNullOrEmpty(memo) ? "NULL" : $"'{memo.Replace("'", "''")}'")}
  7324. );");
  7325. foreach (var itemdetail in detailres)
  7326. {
  7327. JObject jodetail = (JObject)itemdetail;
  7328. // 处理SetValue字段 - 关键修改点
  7329. string setValueDetail = jodetail["FiledNamevalue"]?.ToString() ?? "";
  7330. string setValueSql = string.IsNullOrEmpty(setValueDetail) ? "NULL" : $"'{setValueDetail.Replace("'", "''")}'";
  7331. string sequence = jodetail["FiledNamekey"]?.ToString() ?? "";
  7332. sqlBuilder.AppendLine($@"
  7333. INSERT INTO dbo.ICSInspectionDetail
  7334. (ID, DetailGroupID, Sequence, SetValue, Result, MUSER, MUSERName, MTIME, WorkPoint)
  7335. VALUES(
  7336. NEWID(),
  7337. '{Guids}',
  7338. {(string.IsNullOrEmpty(sequence) ? "NULL" : $"'{sequence.Replace("'", "''")}'")},
  7339. {setValueSql},
  7340. {resultSqlValue},
  7341. '{MUSER}',
  7342. '{MUSERNAME}',
  7343. GETDATE(),
  7344. '{WorkPoint}'
  7345. );");
  7346. if (resultValue == "0")
  7347. {
  7348. ISOK = false;
  7349. }
  7350. }
  7351. ID = jo["InspectionID"]?.ToString() ?? "";
  7352. }
  7353. // 处理更新ICSInspection表的SQL
  7354. string resultUpdate = ISOK ? "1" : "0";
  7355. sqlBuilder.AppendLine($@"
  7356. UPDATE ICSInspection
  7357. SET Result='{resultUpdate}',
  7358. QualifiedQuantity='{YLOTQTY}',
  7359. UnqualifiedQuantity='{NLOTQTY}',
  7360. WaiveQuantity='{WaiveQuantity}',
  7361. SampleQuantity='{CJQty}',
  7362. EATTRIBUTE2='{Filtering}',
  7363. EATTRIBUTE3='{SpecialNumber}',
  7364. EATTRIBUTE4='{SpecialPicks}',
  7365. EATTRIBUTE5='{Manhours}',
  7366. EATTRIBUTE6='{Rejections}',
  7367. EATTRIBUTE7='{OtherNumber}'
  7368. WHERE ID='{ID}';");
  7369. sqlBuilder.AppendLine("COMMIT TRANSACTION;");
  7370. if (SqlHelper.CmdExecuteNonQueryLi(sqlBuilder.ToString()) > 0)
  7371. {
  7372. msg = "";
  7373. }
  7374. else
  7375. {
  7376. msg = "绑定失败";
  7377. }
  7378. }
  7379. catch (Exception ex)
  7380. {
  7381. msg = ex.Message;
  7382. }
  7383. return msg;
  7384. }
  7385. /// <summary>
  7386. /// 检验保存
  7387. /// </summary>
  7388. /// <param name="ICSMTDOC"></param>
  7389. /// <param name="InvCode"></param>
  7390. /// <param name="ResultINp"></param>
  7391. /// <returns></returns>
  7392. public string SaveICSInspectionDetailNew(string ICSMTDOC, string InvCode, string JYID, string AllNumber, string YLOTQTY, string NLOTQTY, string WaiveQuantity, string Filtering, string SpecialNumber, string ResultINp, string SpecialPicks, string Lot, string Type, decimal CJQty, string LotResult, decimal Manhours, decimal Rejections, decimal OtherNumber)
  7393. {
  7394. string msg = "";
  7395. try
  7396. {
  7397. object CARID = Guid.NewGuid();
  7398. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  7399. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  7400. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  7401. JArray res = (JArray)JsonConvert.DeserializeObject(ICSMTDOC);
  7402. bool ISOK = true;
  7403. string ID = string.Empty;
  7404. string sql = $@"DELETE from ICSInspectionDetail where DetailGroupID in(SELECT ID from ICSInspectionDetailGroup where InspectionID='{Lot}' AND workPoint='{WorkPoint}')
  7405. DELETE from ICSInspectionDetailGroup where InspectionID='{Lot}' AND workPoint='{WorkPoint}'";
  7406. if (string.IsNullOrEmpty(JYID) || JYID == "null")
  7407. {
  7408. sql += $@"
  7409. INSERT INTO dbo.ICSInspection ( ID ,LotNo,InvCode ,Quantity,QualifiedQuantity ,UnqualifiedQuantity,WaiveQuantity,BCCode,BRCode,Type,MTIME,MUSER ,MUSERName ,WorkPoint ,Enable,SampleQuantity,EATTRIBUTE2,EATTRIBUTE3,EATTRIBUTE4,EATTRIBUTE5,EATTRIBUTE6,EATTRIBUTE7)
  7410. Values('{CARID}','{Lot}','{InvCode}','{AllNumber}','{YLOTQTY}','{NLOTQTY}','{WaiveQuantity}','','','{Type}',getdate(),'{MUSER}','{MUSERNAME}','{WorkPoint}','1','{CJQty}','{Filtering}','{SpecialNumber}','{SpecialPicks}','{Manhours}','{Rejections}','{OtherNumber}')
  7411. ";
  7412. }
  7413. else
  7414. {
  7415. CARID = JYID;
  7416. }
  7417. foreach (var item in res)
  7418. {
  7419. string Guids = Guid.NewGuid().ToString();
  7420. JObject jo = (JObject)item;
  7421. JArray detailres = (JArray)JsonConvert.DeserializeObject(jo["LWFiledName"].ToString());
  7422. sql += @"
  7423. INSERT INTO dbo.ICSInspectionDetailGroup
  7424. ( ID ,InspectionID,ListCode ,ListName ,
  7425. Unit ,SetValueMax ,SetValueMin ,UnqualifiedQuantity ,Result, MUSER ,MUSERName ,MTIME, WorkPoint,GroupCode,GroupName,EATTRIBUTE1,EATTRIBUTE2,EATTRIBUTE30)
  7426. values('{0}','{1}','{2}','{3}','{4}',{5},{6},{7},'{8}','{9}','{10}',getdate(),'{11}','{12}','{13}','{14}','{15}','{16}')";
  7427. var b = jo["ListCode"].ToString();
  7428. var a = jo["SetValueMin"].ToString();
  7429. sql = string.Format(sql, Guids, CARID, jo["ListCode"].ToString(), jo["ListName"].ToString(), jo["Unit"].ToString(),
  7430. jo["SetValueMax"].ToString() == "" ? "null" : jo["SetValueMax"].ToString(), jo["SetValueMin"].ToString() == "" ? "null" : jo["SetValueMin"].ToString(), jo["SetValue"].ToString() == "" ? "null" : jo["SetValue"].ToString(), jo["Result"].ToString()
  7431. , MUSER, MUSERNAME, WorkPoint, jo["GroupCode"].ToString(), jo["GroupName"].ToString(), jo["BadReason"].ToString(), jo["SamplingQuantity"].ToString(), jo["Memo"].ToString());
  7432. foreach (var itemdetail in detailres)
  7433. {
  7434. JObject jodetail = (JObject)itemdetail;
  7435. if (string.IsNullOrWhiteSpace(ResultINp))
  7436. {
  7437. sql += @"
  7438. INSERT INTO dbo.ICSInspectionDetail
  7439. ( ID ,DetailGroupID,Sequence ,SetValue ,Result, MUSER ,MUSERName ,MTIME, WorkPoint)
  7440. values(newid(),'{0}','{1}','{2}','{3}','{4}','{5}',getdate(),'{6}')";
  7441. sql = string.Format(sql, Guids, jodetail["FiledNamekey"].ToString(), jodetail["FiledNamevalue"].ToString(),
  7442. jo["Result"].ToString(),
  7443. MUSER, MUSERNAME, WorkPoint);
  7444. }
  7445. else
  7446. {
  7447. sql += @" update ICSInspectionDetail set InspectionID='{0}',ListCode='{1}',ListName='{2}', Unit='{3}' ,SetValueMax='{4}' ,SetValueMin='{5}' ,SetValue='{6}' ,Result='{7}', MUSER='{8}' ,MUSERName='{9}' ,MTIME=getdate(), WorkPoint='{10}', GroupCode='{11}', GroupName='{12}',EATTRIBUTE1='{14}' where ID='{13}'";
  7448. sql = string.Format(sql, jodetail["InspectionID"].ToString(), jodetail["ListCode"].ToString(), jodetail["ListName"].ToString(), jodetail["Unit"].ToString(), jodetail["SetValueMax"].ToString(), jodetail["SetValueMin"].ToString(), jodetail["SetValue"].ToString(), jodetail["Result"].ToString(), MUSER, MUSERNAME, WorkPoint, jodetail["GroupCode"].ToString(), jodetail["GroupName"].ToString(), jodetail["ID"].ToString(), jodetail["NUM"].ToString());
  7449. }
  7450. if (jo["Result"].ToString() == "0")
  7451. {
  7452. ISOK = false;
  7453. }
  7454. }
  7455. ID = jo["InspectionID"].ToString();
  7456. }
  7457. if (ISOK == true)
  7458. {
  7459. sql += @" update ICSInspection set Result='{0}' where ID='{1}'";
  7460. sql = string.Format(sql, 1, CARID);
  7461. }
  7462. else
  7463. {
  7464. sql += @" update ICSInspection set Result='{0}' where ID='{1}'";
  7465. sql = string.Format(sql, 0, CARID);
  7466. }
  7467. if (SqlHelper.CmdExecuteNonQueryLi(sql) > 0)
  7468. {
  7469. }
  7470. else
  7471. {
  7472. msg = "绑定失败";
  7473. }
  7474. }
  7475. catch (Exception ex)
  7476. {
  7477. msg = ex.Message;
  7478. }
  7479. return msg;
  7480. }
  7481. }
  7482. }