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.

974 lines
36 KiB

3 weeks ago
  1. using Newtonsoft.Json;
  2. using NFine.Application.Entity;
  3. using NFine.Application.Models;
  4. using NFine.Code;
  5. using NFine.Data.Extensions;
  6. using NFine.Domain._03_Entity.SRM;
  7. using NFine.Repository;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Data;
  11. using System.Data.Common;
  12. using System.Data.SqlClient;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using System.Web;
  17. namespace NFine.Application.WMS
  18. {
  19. public class CheckingFixtureApp : RepositoryFactory<ICSVendor>
  20. {
  21. public DataTable GetGridJsonChengPing(string queryJson, string type,ref Pagination pagination)
  22. {
  23. DataTable dt = new DataTable();
  24. var queryParam = queryJson.ToJObject();
  25. List<DbParameter> parameter = new List<DbParameter>();
  26. //object Figure = GetDecimalDigits();
  27. string sql = string.Empty;
  28. #region [SQL]
  29. if (type=="1")
  30. {
  31. sql = @"
  32. select 0 Code
  33. ,case when a.Status='' then (select top 1 TransferUserName from IcsCheckingFixtureTransfer t with(nolock)
  34. where t.CheckFixtureNo=a.CheckFixtureNo and t.TransferType=''
  35. order by t.MTIME desc)
  36. else '' end as TransferUserName
  37. ,(select top 1 MTIME from IcsCheckingFixtureTransfer t with(nolock)
  38. where t.CheckFixtureNo=a.CheckFixtureNo and t.TransferType=''
  39. order by t.MTIME desc) TransferTime
  40. ,a.*,case when DATEDIFF(day, GETDATE(),a.VerifyDate)+a.VerifyPeriodDay<0 then 'red' WHEN DATEDIFF (day,GETDATE(),a.VerifyDate)+a.VerifyPeriodDay>=0 AND DATEDIFF(day, GETDATE(),a.VerifyDate)+a.VerifyPeriodDay <=10 THEN 'yellow' ELSE '' END AS DiffDate
  41. from IcsCheckingFixture a
  42. where a.Status !='' and a.Status !=''
  43. --and a.CheckFixtureNo='CS001'
  44. --order by a.MTIME desc
  45. <1>
  46. <2>
  47. <3>
  48. <4>
  49. <5>
  50. <6>
  51. <7>
  52. ";
  53. if (!string.IsNullOrWhiteSpace(queryParam["JJStatus"].ToString()))
  54. {
  55. if (queryParam["JJStatus"].ToString() == "临近过期")
  56. {
  57. sql = sql.Replace("<7>", "and DATEDIFF(day,GETDATE(),a.VerifyDate)+a.VerifyPeriodDay>=0 AND DATEDIFF(day, GETDATE(),a.VerifyDate)+a.VerifyPeriodDay <=10 ");
  58. }
  59. else if (queryParam["JJStatus"].ToString() == "已过期")
  60. {
  61. sql = sql.Replace("<7>", " and DATEDIFF(day, GETDATE(),a.VerifyDate)+a.VerifyPeriodDay<0 ");
  62. }
  63. else if (queryParam["JJStatus"].ToString() == "正常")
  64. {
  65. sql = sql.Replace("<7>", " and DATEDIFF(day, GETDATE(),a.VerifyDate)+a.VerifyPeriodDay>10 ");
  66. }
  67. else
  68. {
  69. sql = sql.Replace("<7>", " ");
  70. }
  71. }
  72. else
  73. {
  74. sql = sql.Replace("<7>", " ");
  75. }
  76. }
  77. else
  78. {
  79. sql = @"
  80. select 0 Code
  81. ,case when a.Status='' then (select top 1 TransferUserName from IcsCheckingFixtureTransfer t with(nolock)
  82. where t.CheckFixtureNo=a.CheckFixtureNo and t.TransferType=''
  83. order by t.MTIME desc)
  84. else '' end as TransferUserName
  85. ,(select top 1 MTIME from IcsCheckingFixtureTransfer t with(nolock)
  86. where t.CheckFixtureNo=a.CheckFixtureNo and t.TransferType=''
  87. order by t.MTIME desc) TransferTime
  88. ,a.*,case when DATEDIFF(day, GETDATE(),a.VerifyDate)<0 then 'red' WHEN DATEDIFF (day, GETDATE (),a.VerifyDate)>=0 AND DATEDIFF(day, GETDATE (),a.VerifyDate)<=10 THEN 'yellow' ELSE '' END AS DiffDate
  89. from IcsCheckingFixture a
  90. where a.Status =''
  91. --and a.CheckFixtureNo='CS001'
  92. --order by a.MTIME desc
  93. <1>
  94. <2>
  95. <3>
  96. <4>
  97. <5>
  98. <6>
  99. ";
  100. }
  101. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  102. //sql = string.Format(sql, Figure);
  103. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  104. #endregion
  105. if (!string.IsNullOrWhiteSpace(queryJson))
  106. {
  107. if (!string.IsNullOrWhiteSpace(queryParam["CheckCode"].ToString()))
  108. {
  109. sql = sql.Replace("<1>", " and a.CheckFixtureNo like '%" + queryParam["CheckCode"].ToString() + "%' ");
  110. }
  111. else
  112. {
  113. sql = sql.Replace("<1>", " ");
  114. }
  115. if (!string.IsNullOrWhiteSpace(queryParam["CheckFixtureName"].ToString()))
  116. {
  117. sql = sql.Replace("<2>", " and a.CheckFixtureName like '%" + queryParam["CheckFixtureName"].ToString() + "%' ");
  118. }
  119. else
  120. {
  121. sql = sql.Replace("<2>", " ");
  122. }
  123. if (!string.IsNullOrWhiteSpace(queryParam["Status"].ToString()))
  124. {
  125. sql = sql.Replace("<3>", " and a.Status ='" + queryParam["Status"].ToString() + "' ");
  126. }
  127. else
  128. {
  129. sql = sql.Replace("<3>", " ");
  130. }
  131. if (!string.IsNullOrWhiteSpace(queryParam["CustomerItemCode"].ToString()))
  132. {
  133. sql = sql.Replace("<4>", " and a.CustomerItemCode like '%" + queryParam["CustomerItemCode"].ToString() + "%' ");
  134. }
  135. else
  136. {
  137. sql = sql.Replace("<4>", " ");
  138. }
  139. if (!string.IsNullOrWhiteSpace(queryParam["VerifyDateBegin"].ToString()))
  140. {
  141. sql = sql.Replace("<5>", " and a.VerifyDate>='" + queryParam["VerifyDateBegin"].ToString() + " 00:00:00' ");
  142. }
  143. else
  144. {
  145. sql = sql.Replace("<5>", " ");
  146. }
  147. if (!string.IsNullOrWhiteSpace(queryParam["VerifyDateEnd"].ToString()))
  148. {
  149. sql = sql.Replace("<6>", " and a.VerifyDate<='" + queryParam["VerifyDateEnd"].ToString() + " 23:59:59' ");
  150. }
  151. else
  152. {
  153. sql = sql.Replace("<6>", " ");
  154. }
  155. }
  156. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  157. //{
  158. // sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  159. // // sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  160. //}
  161. //else
  162. //{
  163. // sql = sql.Replace("{0}", "");
  164. //}
  165. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  166. //{
  167. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  168. //}
  169. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref pagination);
  170. }
  171. public List<SysEnumValueDto> GetLocationList(string keyValue)
  172. {
  173. var returnValue = new List<SysEnumValueDto>();
  174. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  175. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  176. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  177. object para = new {WorkPoint=WorkPoint };
  178. var sql = @" select
  179. a.LocationCode as value
  180. ,a.LocationName as label
  181. from ICSLocation a with(nolock)
  182. where 1=1
  183. --and a.F_Account='CS001'
  184. and a.WorkPoint=@WorkPoint
  185. order by a.MTIME desc";
  186. returnValue = MsSqlData.Query<SysEnumValueDto>(sql, para).ToList();
  187. for (int i = 0; i < returnValue.Count; i++)
  188. {
  189. returnValue[i].key = i + 1;
  190. }
  191. return returnValue;
  192. }
  193. public IcsCheckingFixture GetCheckingFixture(string keyValue)
  194. {
  195. var entity = new IcsCheckingFixture();
  196. try
  197. {
  198. entity = MsSqlData.Get<IcsCheckingFixture>(keyValue);
  199. }
  200. catch (Exception ex)
  201. {
  202. //entity = null;
  203. }
  204. return entity;
  205. }
  206. public string DeleteCheckingFixture(string keyValue)
  207. {
  208. string returnValue = string.Empty;
  209. try
  210. {
  211. var idList = JsonConvert.DeserializeObject<List<string>>(keyValue);
  212. string sql = @"select
  213. a.*
  214. from IcsCheckingFixture a with(nolock)
  215. where a.ID in ('" + string.Join("','", idList) + "')";
  216. var entityList = MsSqlData.Query<IcsCheckingFixture>(sql).ToList();
  217. foreach (var item in entityList)
  218. {
  219. var count = MsSqlData.ExecuteScalar(" select count(1) from IcsCheckingFixtureTransfer with(nolock) where CheckFixtureNo='" + item.CheckFixtureNo + "'").ToInt();
  220. if (count > 0)
  221. {
  222. throw new Exception("当前检具已经存在履历,不能删除");
  223. }
  224. }
  225. var result = MsSqlData.Delete<IcsCheckingFixture>(entityList);
  226. if (!result)
  227. {
  228. returnValue = "删除失败";
  229. }
  230. }
  231. catch (Exception ex)
  232. {
  233. returnValue = ex.Message;
  234. }
  235. return returnValue;
  236. }
  237. public string PostSealed(string type, string keyValue,string time)
  238. {
  239. string returnValue = string.Empty;
  240. try
  241. {
  242. List<IcsCheckingFixture> entityList=new List<IcsCheckingFixture>();
  243. if (type=="封存")
  244. {
  245. var idList = JsonConvert.DeserializeObject<List<string>>(keyValue);
  246. string sql = @"select
  247. a.*
  248. from IcsCheckingFixture a with(nolock)
  249. where a.ID in ('" + string.Join("','", idList) + "')";
  250. entityList = MsSqlData.Query<IcsCheckingFixture>(sql).ToList();
  251. for (int i = 0; i < entityList.Count; i++)
  252. {
  253. if (entityList[i].Status != "在库")
  254. {
  255. throw new Exception("当前检具状态不是在库状态,不能封存!");
  256. }
  257. entityList[i].Status = "封存";
  258. entityList[i].VerifyDate = null;
  259. }
  260. } else
  261. {
  262. var idList = keyValue.Substring(1, keyValue.Length-2).Split(',').ToList();
  263. string sql = @"select
  264. a.*
  265. from IcsCheckingFixture a with(nolock)
  266. where a.ID in ('" + string.Join("','", idList) + "')";
  267. entityList = MsSqlData.Query<IcsCheckingFixture>(sql).ToList();
  268. for (int i = 0; i < entityList.Count; i++)
  269. {
  270. if (entityList[i].Status != "封存")
  271. {
  272. throw new Exception("当前检具状态不是在封存态,不能解封!");
  273. }
  274. entityList[i].Status = "在库";
  275. entityList[i].VerifyDate = time.ToDate();
  276. }
  277. }
  278. var result = MsSqlData.Update<IcsCheckingFixture>(entityList);
  279. if (!result)
  280. {
  281. returnValue = "修改失败";
  282. }
  283. }
  284. catch (Exception ex)
  285. {
  286. returnValue = ex.Message;
  287. }
  288. return returnValue;
  289. }
  290. public DataTable ExportAll(string id, string checkFixtureName, string status)
  291. {
  292. DataTable dt = new DataTable();
  293. // var queryParam = queryJson.ToJObject();
  294. List<DbParameter> parameter = new List<DbParameter>();
  295. //object Figure = GetDecimalDigits();
  296. #region [SQL]
  297. string sql = @"
  298. select
  299. a.*
  300. from IcsCheckingFixture a
  301. where 1=1
  302. --and a.CheckFixtureNo='CS001'
  303. --order by a.MTIME desc
  304. <1>
  305. <2>
  306. <3>
  307. ";
  308. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  309. //sql = string.Format(sql, Figure);
  310. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  311. #endregion
  312. if (!string.IsNullOrWhiteSpace(id))
  313. {
  314. sql = sql.Replace("<1>", " and a.CheckFixtureNo like '%" + id + "%' ");
  315. }
  316. else
  317. {
  318. sql = sql.Replace("<1>", " ");
  319. }
  320. if (!string.IsNullOrWhiteSpace(checkFixtureName))
  321. {
  322. sql = sql.Replace("<2>", " and a.CheckFixtureName like '%" + checkFixtureName + "%' ");
  323. }
  324. else
  325. {
  326. sql = sql.Replace("<2>", " ");
  327. }
  328. if (!string.IsNullOrWhiteSpace(status))
  329. {
  330. sql = sql.Replace("<3>", " and a.Status ='" + status + "' ");
  331. }
  332. else
  333. {
  334. sql = sql.Replace("<3>", " ");
  335. }
  336. return Repository().FindDataSetBySql(sql.ToString(), parameter.ToArray()).Tables[0];
  337. }
  338. //public string PrintLabel(string keyValue)
  339. //{
  340. // string strPrintFileName = Server.MapPath("/ReportFile/") + "lot. fr3";
  341. // PrintIson pJson = new PrintIson(Server, MapPath("./PrintTemp"), strPrintFileName).
  342. // pJson.CheckRegister("苏州智合诚信息科技有限公司", "56D3B4C172D0D140841CAC98A58A819F4E2SEDA5D6E45711DDD64F6A439F68B6A7870CD7DAFD69A919CBS70207FE4BB206F92BE3D53C221B019E0797E73? 9EBA4"): //注册信息
  343. // pJson.MasterOptions(1, "ASNCode".
  344. // //主从关系
  345. // false):
  346. // SetCookieAndURL(pJson);// 设置控件调用的Cookie值,判断是否安装了打印控件
  347. //}
  348. public string SetData_PR(string savePath)
  349. {
  350. string returnValue = string.Empty;
  351. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  352. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  353. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  354. SqlConnection conn = SqlHelper.GetDataCenterConn();
  355. DataTable data = FileToExcel.ExcelToTable(savePath);
  356. DateTime time = DateTime.Now;
  357. //DataSet dsSave = new DataSet();
  358. //dsSave.Tables.Add(data.Copy());
  359. //dsSave.Tables[0].TableName = "IcsCheckingFixture";
  360. List<IcsCheckingFixture> list = new List<IcsCheckingFixture>();
  361. for (int i = 0; i < data.Rows.Count; i++)
  362. {
  363. var item = data.Rows[i];
  364. if (item["检具编码"].ToStringExt() == "")
  365. {
  366. throw new Exception("第" + (i + 1) + "行," + "检具编码为空");
  367. }
  368. if (item["客户名称 "].ToStringExt() == "")
  369. {
  370. throw new Exception("第" + (i + 1) + "行," + "客户名称为空");
  371. }
  372. IcsCheckingFixture entity = new IcsCheckingFixture();
  373. entity.ID = Guid.NewGuid().ToString();
  374. entity.CheckFixtureNo = item["检具编码"].ToStringExt();
  375. entity.CheckFixtureName = item["客户名称 "].ToStringExt();
  376. entity.CustomerItemCode = item["客户料号"].ToStringExt();
  377. entity.Useage = item["用途"].ToStringExt();
  378. entity.Std = item["规格"].ToStringExt();
  379. entity.Unit = item["单位"].ToStringExt();
  380. entity.Remark = item["备注"].ToStringExt();
  381. entity.VerifyDate = item["校验日期"].ToDate();
  382. entity.VerifyPeriodDay = item["校验周期"].ToInt();
  383. entity.Status = "在库";
  384. entity.MUSER = MUSER;
  385. entity.MUSERName = MUSERNAME;
  386. entity.MTIME = time;
  387. entity.WorkPoint = WorkPoint;
  388. entity.VerifyPeriodDay = entity.VerifyPeriodDay == 0 ? null : entity.VerifyPeriodDay;
  389. list.Add(entity);
  390. }
  391. if (list.Count == 0)
  392. {
  393. throw new Exception("没有导入数据");
  394. }
  395. var result = MsSqlData.Insert<IcsCheckingFixture>(list);
  396. if (!result)
  397. {
  398. throw new Exception("导入失败");
  399. }
  400. returnValue = "true";
  401. return returnValue;
  402. }
  403. public string DeleteTransfer(string keyValue)
  404. {
  405. string returnValue = string.Empty;
  406. try
  407. {
  408. var dtNow = DateTime.Now;
  409. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  410. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  411. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  412. //当前删除的流转单号
  413. var transfer = MsSqlData
  414. .Query<IcsCheckingFixtureTransfer>("select top 1 * from IcsCheckingFixtureTransfer with(nolock) where id='" + keyValue + "'")
  415. .FirstOrDefault();
  416. if (transfer == null)
  417. {
  418. throw new Exception("当前检具流转记录不存在");
  419. }
  420. var checkFixyure = MsSqlData
  421. .Query<IcsCheckingFixture>("select top 1 * from IcsCheckingFixture with(nolock) where CheckFixtureNo='" + transfer.CheckFixtureNo + "'")
  422. .FirstOrDefault();
  423. if (checkFixyure == null)
  424. {
  425. throw new Exception("当前检具档案不存在");
  426. }
  427. // //当前检具的最新流转单号
  428. var transferNew = MsSqlData
  429. .Query<IcsCheckingFixtureTransfer>(
  430. "select top 1 * from IcsCheckingFixtureTransfer a with(nolock) where CheckFixtureNo='" + transfer.CheckFixtureNo + "' and a.IsDelete='N' order by a.MTIME desc")
  431. .FirstOrDefault();
  432. if (transferNew == null)
  433. {
  434. throw new Exception("当前检具流转记录不存在");
  435. }
  436. if (transferNew.TransferNo != transfer.TransferNo)
  437. {
  438. throw new Exception("当前检具已经存在最新的流转记录,不能删除之前的记录");
  439. }
  440. //软删除
  441. transfer.IsDelete = "Y";
  442. transfer.DeleteUser = MUSER;
  443. transfer.DeleteUserName = MUSERNAME;
  444. transfer.DeleteTime = dtNow;
  445. var result = MsSqlData.Update<IcsCheckingFixtureTransfer>(transfer);
  446. if (!result)
  447. {
  448. returnValue = "删除失败";
  449. }
  450. checkFixyure.LastTransferDate = dtNow;
  451. checkFixyure.Status = transfer.OldStatus;
  452. checkFixyure.LocationCode = checkFixyure.EATTRIBUTE1;
  453. result = MsSqlData.Update<IcsCheckingFixture>(checkFixyure);
  454. if (!result)
  455. {
  456. returnValue = "删除失败";
  457. }
  458. }
  459. catch (Exception ex)
  460. {
  461. returnValue = ex.Message;
  462. }
  463. return returnValue;
  464. }
  465. public DataTable ExportAllTransfer(string CheckFixtureNo, string checkFixtureName, string status, string transferType)
  466. {
  467. DataTable dt = new DataTable();
  468. // var queryParam = queryJson.ToJObject();
  469. List<DbParameter> parameter = new List<DbParameter>();
  470. //object Figure = GetDecimalDigits();
  471. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  472. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  473. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  474. #region [SQL]
  475. string sql = @"
  476. select
  477. a.*
  478. from
  479. (
  480. select
  481. a.ID
  482. ,a.TransferType
  483. ,a.TransferNo
  484. ,a.TransferUser
  485. ,a.TransferUserName
  486. ,a.CheckFixtureNo
  487. ,b.CheckFixtureName
  488. ,b.CustomerItemCode
  489. ,b.Useage
  490. ,b.Std
  491. ,b.Unit
  492. ,a.Remark
  493. ,a.MUSERName
  494. ,a.MTIME
  495. from IcsCheckingFixtureTransfer a with(nolock)
  496. left join IcsCheckingFixture b with(nolock) on a.CheckFixtureNo=b.CheckFixtureNo and a.WorkPoint=b.WorkPoint
  497. <5>
  498. --and a.CheckFixtureNo='JY001'
  499. --order by a.MTIME desc
  500. ) a
  501. where 1=1
  502. <1>
  503. <2>
  504. <3>
  505. <4>
  506. ";
  507. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  508. //sql = string.Format(sql, Figure);
  509. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  510. #endregion
  511. if (!string.IsNullOrWhiteSpace(CheckFixtureNo))
  512. {
  513. sql = sql.Replace("<1>", " and a.CheckFixtureNo like '%" + CheckFixtureNo + "%' ");
  514. }
  515. else
  516. {
  517. sql = sql.Replace("<1>", " ");
  518. }
  519. if (!string.IsNullOrWhiteSpace(checkFixtureName))
  520. {
  521. sql = sql.Replace("<2>", " and a.CheckFixtureName like '%" + checkFixtureName + "%' ");
  522. }
  523. else
  524. {
  525. sql = sql.Replace("<2>", " ");
  526. }
  527. if (!string.IsNullOrWhiteSpace(status))
  528. {
  529. sql = sql.Replace("<3>", " and a.TransferNo ='" + status + "' ");
  530. }
  531. else
  532. {
  533. sql = sql.Replace("<3>", " ");
  534. }
  535. if (!string.IsNullOrWhiteSpace(transferType))
  536. {
  537. sql = sql.Replace("<4>", " and a.TransferType ='" + transferType + "' ");
  538. }
  539. else
  540. {
  541. sql = sql.Replace("<4>", " ");
  542. }
  543. sql = sql.Replace("<5>", " where a.WorkPoint ='" + WorkPoint + "' ");
  544. return Repository().FindDataSetBySql(sql.ToString(), parameter.ToArray()).Tables[0];
  545. }
  546. public IcsCheckingFixture GetCheckingFixtureByNo(string keyValue)
  547. {
  548. var returnValue = new IcsCheckingFixture();
  549. try
  550. {
  551. var checkFixyure = MsSqlData
  552. .Query<IcsCheckingFixture>("select top 1 * from IcsCheckingFixture with(nolock) where CheckFixtureNo='" + keyValue + "'")
  553. .FirstOrDefault();
  554. if (checkFixyure == null)
  555. {
  556. throw new Exception("当前检具档案不存在");
  557. }
  558. returnValue = checkFixyure;
  559. }
  560. catch (Exception ex)
  561. {
  562. returnValue = new IcsCheckingFixture();
  563. }
  564. return returnValue;
  565. }
  566. public DataTable GetUserInfo(string keyValue)
  567. {
  568. List<DbParameter> parameter = new List<DbParameter>();
  569. var sql = @"select
  570. a.*
  571. from sys_srm_user a with(nolock)
  572. where 1 = 1
  573. and a.F_Account = '" + keyValue + "' order by a.F_CreatorTime desc ";
  574. return Repository().FindDataSetBySql(sql.ToString(), parameter.ToArray()).Tables[0];
  575. }
  576. public string SaveTransfer(string keyValue)
  577. {
  578. string returnValue = string.Empty;
  579. DateTime dtNow = DateTime.Now;
  580. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  581. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  582. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  583. string newStatus = string.Empty;
  584. try
  585. {
  586. string dtPre = DateTime.Now.ToString("yyyyMMdd");
  587. string sql = @"EXEC Addins_GetSerialCode '" + WorkPoint + "','IcsCheckingFixtureTransfer','TransferNo','" + "LZ" + dtPre + "',3";
  588. var serialNo = MsSqlData.ExecuteScalar(sql).ToStringExt();
  589. var model = JsonConvert.DeserializeObject<IcsCheckingFixtureTransferDto>(keyValue);
  590. var count = MsSqlData.ExecuteScalar(" select count(1) from IcsCheckingFixtureTransfer with(nolock) where TransferNo='" + serialNo + "'").ToInt();
  591. if (count > 0)
  592. {
  593. throw new Exception("当前单据已经存在");
  594. }
  595. //count = MsSqlData.ExecuteScalar(" select count(1) from ICSLocation with(nolock) where LocationCode='" + model.LocationCode + "'").ToInt();
  596. //if (count == 0)
  597. //{
  598. // throw new Exception("当前库位不存在");
  599. //}
  600. var checkFixyure = MsSqlData
  601. .Query<IcsCheckingFixture>("select top 1 * from IcsCheckingFixture with(nolock) where CheckFixtureNo='" + model.CheckFixtureNo + "'")
  602. .FirstOrDefault();
  603. if (checkFixyure == null)
  604. {
  605. throw new Exception("当前检具档案不存在");
  606. }
  607. if (checkFixyure.Status == "报废")
  608. {
  609. throw new Exception("当前检具档案已经报废,不能再次操作");
  610. }
  611. if (model.TransferType == "领用")
  612. {
  613. if (checkFixyure.Status == "领用")
  614. {
  615. throw new Exception("当前检具已经被领用,不能再次领用");
  616. }
  617. if (checkFixyure.VerifyDate.ToDate().AddDays(checkFixyure.VerifyPeriodDay.ToInt()) <DateTime.Now)
  618. {
  619. throw new Exception("检验过期,禁止领用!");
  620. }
  621. checkFixyure.ReceiveUser = model.TransferUserName;
  622. newStatus = "领用";
  623. checkFixyure.EATTRIBUTE1 = model.EATTRIBUTE1;
  624. // checkFixyure.LocationCode = "";
  625. }
  626. else if (model.TransferType == "归还")
  627. {
  628. if (checkFixyure.Status == "在库")
  629. {
  630. throw new Exception("当前检具已经在库,不能归还");
  631. }
  632. checkFixyure.ReceiveUser = null;
  633. newStatus = "在库";
  634. checkFixyure.EATTRIBUTE1 = "";
  635. // checkFixyure.LocationCode = model.LocationCode;
  636. }
  637. else if (model.TransferType == "报废")
  638. {
  639. if (checkFixyure.Status != "在库")
  640. {
  641. throw new Exception("当前检具不是在库,不能报废");
  642. }
  643. checkFixyure.ReceiveUser = null;
  644. newStatus = "报废";
  645. // checkFixyure.EATTRIBUTE1 = checkFixyure.LocationCode;
  646. // checkFixyure.LocationCode = "";
  647. }
  648. else
  649. {
  650. newStatus = "在库";
  651. }
  652. var entity = ConvertExt.Mapping<IcsCheckingFixtureTransferDto, IcsCheckingFixtureTransfer>(model);
  653. entity.ID = Guid.NewGuid().ToString();
  654. entity.TransferNo = serialNo;//单据编码
  655. entity.OldStatus = checkFixyure.Status;
  656. entity.NewStatus = newStatus;
  657. entity.MUSER = MUSER;
  658. entity.MUSERName = MUSERNAME;
  659. entity.MTIME = dtNow;
  660. entity.WorkPoint = WorkPoint;
  661. entity.IsDelete = "N";
  662. var result = MsSqlData.Insert<IcsCheckingFixtureTransfer>(entity);
  663. if (!result)
  664. {
  665. returnValue = "新增失败";
  666. }
  667. //更新档案最新流转日期
  668. checkFixyure.LastTransferDate = dtNow;
  669. checkFixyure.Status = newStatus;
  670. result = MsSqlData.Update<IcsCheckingFixture>(checkFixyure);
  671. if (!result)
  672. {
  673. returnValue = "新增失败";
  674. }
  675. }
  676. catch (Exception ex)
  677. {
  678. returnValue = ex.Message;
  679. }
  680. return returnValue;
  681. }
  682. public DataTable QueryTransferList(string queryJson, ref Pagination pagination)
  683. {
  684. DataTable dt = new DataTable();
  685. var queryParam = queryJson.ToJObject();
  686. List<DbParameter> parameter = new List<DbParameter>();
  687. //object Figure = GetDecimalDigits();
  688. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  689. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  690. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  691. #region [SQL]
  692. string sql = @"
  693. select
  694. a.*
  695. from
  696. (
  697. select
  698. a.ID
  699. ,a.TransferType
  700. ,a.TransferNo
  701. ,a.TransferUser
  702. ,a.TransferUserName
  703. ,a.CheckFixtureNo
  704. ,b.CheckFixtureName
  705. ,b.CustomerItemCode
  706. ,b.Useage
  707. ,b.Std
  708. ,b.Unit
  709. ,a.Remark
  710. ,a.MUSERName
  711. ,a.MTIME
  712. from IcsCheckingFixtureTransfer a with(nolock)
  713. left join IcsCheckingFixture b with(nolock) on a.CheckFixtureNo=b.CheckFixtureNo and a.WorkPoint=b.WorkPoint
  714. <10>
  715. and a.IsDelete='N'
  716. --and a.CheckFixtureNo='JY001'
  717. --order by a.MTIME desc
  718. ) a
  719. where 1=1
  720. <1>
  721. <2>
  722. <3>
  723. <4>
  724. <5>
  725. <6>
  726. ";
  727. // sql += " WHERE 1=1 and a.MOStatus<>'3' ";
  728. //sql = string.Format(sql, Figure);
  729. //sql = string.Format(sql, DbHelper.GetErpIp(), DbHelper.GetErpName());
  730. #endregion
  731. if (!string.IsNullOrWhiteSpace(queryJson))
  732. {
  733. if (!string.IsNullOrWhiteSpace(queryParam["CheckFixtureNo"].ToString()))
  734. {
  735. sql = sql.Replace("<1>", " and a.CheckFixtureNo like '%" + queryParam["CheckFixtureNo"].ToString() + "%' ");
  736. }
  737. else
  738. {
  739. sql = sql.Replace("<1>", " ");
  740. }
  741. if (!string.IsNullOrWhiteSpace(queryParam["CheckFixtureName"].ToString()))
  742. {
  743. sql = sql.Replace("<2>", " and a.CheckFixtureName like '%" + queryParam["CheckFixtureName"].ToString() + "%' ");
  744. }
  745. else
  746. {
  747. sql = sql.Replace("<2>", " ");
  748. }
  749. if (!string.IsNullOrWhiteSpace(queryParam["TransferNo"].ToString()))
  750. {
  751. sql = sql.Replace("<3>", " and a.TransferNo like '%" + queryParam["TransferNo"].ToString() + "%' ");
  752. }
  753. else
  754. {
  755. sql = sql.Replace("<3>", " ");
  756. }
  757. if (!string.IsNullOrWhiteSpace(queryParam["TransferType"].ToString()))
  758. {
  759. sql = sql.Replace("<4>", " and a.TransferType ='" + queryParam["TransferType"].ToString() + "' ");
  760. }
  761. else
  762. {
  763. sql = sql.Replace("<4>", " ");
  764. }
  765. if (!string.IsNullOrWhiteSpace(queryParam["VerifyDateBegin"].ToString()))
  766. {
  767. sql = sql.Replace("<5>", " and a.MTIME>='" + queryParam["VerifyDateBegin"].ToString() + " 00:00:00' ");
  768. }
  769. else
  770. {
  771. sql = sql.Replace("<5>", " ");
  772. }
  773. if (!string.IsNullOrWhiteSpace(queryParam["VerifyDateEnd"].ToString()))
  774. {
  775. sql = sql.Replace("<6>", " and a.MTIME<='" + queryParam["VerifyDateEnd"].ToString() + " 23:59:59' ");
  776. }
  777. else
  778. {
  779. sql = sql.Replace("<6>", " ");
  780. }
  781. }
  782. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  783. //{
  784. // sql = sql.Replace("{0}", "and a.WorkPoint = '" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'");
  785. // // sql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  786. //}
  787. //else
  788. //{
  789. // sql = sql.Replace("{0}", "");
  790. //}
  791. //if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode == "Vendor")
  792. //{
  793. // sql += " and a.VenCode='" + NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode + "'";
  794. //}
  795. sql = sql.Replace("<10>", " where a.WorkPoint ='" + WorkPoint + "' ");
  796. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref pagination);
  797. }
  798. public string SaveCheckingFixture(string keyValue)
  799. {
  800. string returnValue = string.Empty;
  801. string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  802. string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName;
  803. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  804. try
  805. {
  806. var model = JsonConvert.DeserializeObject<IcsCheckingFixtureDto>(keyValue);
  807. int count = 0;
  808. count = MsSqlData.ExecuteScalar(" select count(1) from ICSLocation with(nolock) where LocationCode='" + model.LocationCode + "'").ToInt();
  809. if (count == 0)
  810. {
  811. throw new Exception("当前库位不存在");
  812. }
  813. if (string.IsNullOrEmpty(model.ID))
  814. {
  815. //新增
  816. count = MsSqlData.ExecuteScalar(" select count(1) from IcsCheckingFixture with(nolock) where CheckFixtureNo='" + model.CheckFixtureNo + "'").ToInt();
  817. if (count > 0)
  818. {
  819. throw new Exception("当前代码已经存在");
  820. }
  821. var entity = ConvertExt.Mapping<IcsCheckingFixtureDto, IcsCheckingFixture>(model);
  822. entity.ID = Guid.NewGuid().ToString();
  823. entity.Status = "在库";
  824. entity.MUSER = MUSER;
  825. entity.MUSERName = MUSERNAME;
  826. entity.MTIME = DateTime.Now;
  827. entity.WorkPoint = WorkPoint;
  828. var result = MsSqlData.Insert<IcsCheckingFixture>(entity);
  829. if (!result)
  830. {
  831. returnValue = "新增失败";
  832. }
  833. }
  834. else
  835. { //修改
  836. var entity = MsSqlData.Get<IcsCheckingFixture>(model.ID);
  837. if (entity == null)
  838. {
  839. throw new Exception("当前数据不存在");
  840. }
  841. ConvertExt.Mapping<IcsCheckingFixtureDto, IcsCheckingFixture>(model, entity);
  842. //entity.MUSER = MUSER;
  843. //entity.MUSERName = MUSERNAME;
  844. // entity.MTIME = DateTime.Now;
  845. var result = MsSqlData.Update<IcsCheckingFixture>(entity);
  846. if (!result)
  847. {
  848. returnValue = "修改失败";
  849. }
  850. }
  851. }
  852. catch (Exception ex)
  853. {
  854. returnValue = ex.Message;
  855. }
  856. return returnValue;
  857. }
  858. }
  859. }