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.

6830 lines
258 KiB

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