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.

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