ResultQueryViewModel.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  1. using AutoMapper;
  2. using BizService;
  3. using Microsoft.Extensions.Logging;
  4. using MiniExcelLibs;
  5. using Model.Dto;
  6. using Model.Entities;
  7. using PLCTool.Pdf;
  8. using Prism.Commands;
  9. using Prism.Mvvm;
  10. using Prism.Services.Dialogs;
  11. using QuestPDF.Infrastructure;
  12. using QuestPDF;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Collections.ObjectModel;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Threading.Tasks;
  19. using Newtonsoft.Json;
  20. using QuestPDF.Fluent;
  21. using System.Windows;
  22. using Prism.Regions;
  23. namespace PLCTool.ViewModels.BusinessManageViewModel
  24. {
  25. public class ResultQueryViewModel : BindableBase,INavigationAware
  26. {
  27. private readonly IRegionManager _regionManager;
  28. private readonly IBasicDeviceService _iBasicDeviceService;
  29. private readonly IBasicDeviceKindService _iBasicDeviceKindService;
  30. private readonly IBasicProjectService _iBasicProjectService;
  31. private readonly IBasicPlcTestSchemeService _basicPlcTestSchemeService;
  32. private readonly IBizTestRecordDtlService _iBizTestRecordDtlService;
  33. private readonly IBizTestRecordService _iBizTestRecordService;
  34. private readonly IBasicPlcTestSchemeDtlService _iBasicPlcTestSchemeDtlService;
  35. private readonly IMapper _mapper;
  36. private readonly IDialogService _dialog;
  37. private readonly ILogger _logger;
  38. private List<DeviceDtlWithResultModel> allDeviceAndSchResultList = new List<DeviceDtlWithResultModel>();//所有设备,并带有测试方案
  39. private List<DeviceDtlWithResultModel> allDeviceList = new List<DeviceDtlWithResultModel>();//所有方案
  40. private List<DeviceDtlWithResultModel> conditionDevices = new List<DeviceDtlWithResultModel>();//符合条件的方案
  41. private string selectProjectName;
  42. public ResultQueryViewModel(IBasicDeviceService iBasicDeviceService, IBasicDeviceKindService iBasicDeviceKindService, IBasicProjectService iBasicProjectService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBizTestRecordDtlService iBizTestRecordDtlService, IBizTestRecordService iBizTestRecordService, IBasicPlcTestSchemeDtlService iBasicPlcTestSchemeDtlService, IRegionManager regionManager,IMapper mapper, IDialogService dialog, ILogger logger)
  43. {
  44. _iBasicDeviceService = iBasicDeviceService;
  45. _iBasicDeviceKindService = iBasicDeviceKindService;
  46. _iBasicProjectService = iBasicProjectService;
  47. _basicPlcTestSchemeService = basicPlcTestSchemeService;
  48. _iBizTestRecordService= iBizTestRecordService;
  49. _iBizTestRecordDtlService= iBizTestRecordDtlService;
  50. _iBasicPlcTestSchemeDtlService = iBasicPlcTestSchemeDtlService;
  51. _regionManager = regionManager;
  52. _mapper = mapper;
  53. _dialog = dialog;
  54. _logger = logger;
  55. QueryCommand = new DelegateCommand<object>(Query);
  56. ExportCommand = new DelegateCommand<string>(Export);
  57. CheckDetailCommand = new DelegateCommand<object>(CheckDetail);
  58. ResetCommand = new DelegateCommand<object>(Reset);
  59. OnLoadCommand = new DelegateCommand(OnLoad);
  60. PdfReportCommand = new DelegateCommand<object>(CreatePdf);
  61. UnqualifiedCommand = new DelegateCommand<object>(RetryTest);
  62. DgSelectChangeCommand = new DelegateCommand<object>(DgSelect);
  63. GoBackCommand = new DelegateCommand<object>(GoBack);
  64. }
  65. #region 私有方法
  66. /// <summary>
  67. /// 重新测试不合格项
  68. /// </summary>
  69. /// <param name="obj"></param>
  70. private void RetryTest(object obj)
  71. {
  72. object[] multiObj = obj as object[];
  73. //测试方案明细主键ID
  74. long id = (long)multiObj[0];
  75. long deviceId = (long)multiObj[1];
  76. DialogParameters parm = new DialogParameters();
  77. parm.Add("Key", id);
  78. parm.Add("Key2", deviceId);
  79. //弹出详情对话框
  80. //弹出详情对话框
  81. _dialog.ShowDialog("RetryTestView", parm, async callback =>
  82. {
  83. if (callback.Result == ButtonResult.OK)
  84. {
  85. //更新表格,重新获取
  86. }
  87. });
  88. }
  89. /// <summary>
  90. /// 加载页面
  91. /// </summary>
  92. private void OnLoad()
  93. {
  94. DeviceKindNameList.Clear();
  95. DeviceKindNameList.Add("---");
  96. ProjectNameList.Clear();
  97. ProjectNameList.Add("---");
  98. var Kinds = _iBasicDeviceKindService.FindAllDeviceKind();
  99. foreach (var kind in Kinds)
  100. {
  101. DeviceKindNameList.Add(kind);
  102. }
  103. var projects = _iBasicProjectService.FindAllProject();
  104. foreach (var project in projects)
  105. {
  106. ProjectNameList.Add(project);
  107. }
  108. DeviceKindName = "---";
  109. ProjectName = "---";
  110. GetProjectConfig();
  111. }
  112. private void Reset(object obj)
  113. {
  114. DeviceNo = string.Empty;
  115. DeviceName = string.Empty;
  116. DeviceKindName = "---";
  117. ProjectName = "---";
  118. StartTime = string.Empty;
  119. EndTime = string.Empty;
  120. }
  121. /// <summary>
  122. /// 查看详情
  123. /// </summary>
  124. /// <param name="obj"></param>
  125. private void CheckDetail(object obj)
  126. {
  127. //recordID
  128. long id = Convert.ToInt64(obj);
  129. DialogParameters parm = new DialogParameters();
  130. parm.Add("Key", id);
  131. //弹出详情对话框
  132. //弹出详情对话框
  133. _dialog.ShowDialog("TestResultDetailView", parm, async callback =>
  134. {
  135. if (callback.Result == ButtonResult.OK)
  136. {
  137. //更新表格,重新获取
  138. //GetContent();
  139. }
  140. });
  141. }
  142. /// <summary>
  143. /// 查询
  144. /// </summary>
  145. /// <param name="obj"></param>
  146. private void Query(object obj)
  147. {
  148. if ((!string.IsNullOrEmpty(StartTime)) && (!string.IsNullOrEmpty(EndTime)))
  149. {
  150. if (Convert.ToDateTime(StartTime) > Convert.ToDateTime(EndTime))
  151. {
  152. MessageBox.Show("起始时间大于结束时间,请重新输入", "确认", MessageBoxButton.OK, MessageBoxImage.Warning);
  153. return;
  154. }
  155. }
  156. conditionDevices = (from a in allDeviceList
  157. where (string.IsNullOrEmpty(DeviceName) ? true : (a.DeviceName == DeviceName))
  158. && (string.IsNullOrEmpty(DeviceNo) ? true : (a.DeviceNo == DeviceNo))
  159. && ((DeviceKindName == "---") ? true : (a.DeviceKindName == DeviceKindName))
  160. && ((ProjectName == "---") ? true : (a.ProjectName == ProjectName))
  161. && (EndTime == string.Empty ? true : (a.CreateTime < Convert.ToDateTime(EndTime)) && (Convert.ToDateTime(StartTime) < a.CreateTime))
  162. select a).ToList();
  163. //默认显示的第一页
  164. conditionDevices = conditionDevices.OrderBy(x => x.DeviceId).ToList();
  165. Getpage();
  166. }
  167. private void Export(string obj)
  168. {
  169. using (System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog()
  170. {
  171. //设置文件类型
  172. //书写规则例如:txt files(*.txt)|*.txt
  173. Filter = "Excel files(*.xlsx)|*.xlsx|All files(*.*)|*.*",
  174. //设置默认文件名(可以不设置)
  175. FileName = "项目配置表",
  176. //获取或设置一个值,该值指示如果用户省略扩展名,文件对话框是否自动在文件名中添加扩展名。(可以不设置)
  177. AddExtension = true,
  178. //保存对话框是否记忆上次打开的目录
  179. RestoreDirectory = true
  180. })
  181. {
  182. // Show save file dialog box
  183. //点了保存按钮进入
  184. if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  185. {
  186. try
  187. {
  188. //获得文件路径
  189. string localFilePath = saveFileDialog.FileName.ToString();
  190. //获取文件内容
  191. MiniExcel.SaveAs(localFilePath, DeviceResultItemList);
  192. }
  193. catch (Exception ex)
  194. {
  195. _logger.LogError(ex.ToString());
  196. }
  197. }
  198. }
  199. }
  200. /// <summary>
  201. /// 单元格查看
  202. /// </summary>
  203. /// <param name="obj"></param>
  204. private void DgSelect(object obj)
  205. {
  206. DeviceDtlWithResultModel dtlSch = (DeviceDtlWithResultModel)obj;
  207. if (dtlSch != null)
  208. {
  209. SchItemResultList = new ObservableCollection<DeviceDtlWithResultModel>(allDeviceAndSchResultList.FindAll(x => ((x.ProjectName == dtlSch.ProjectName) && (x.DeviceName == dtlSch.DeviceName))));
  210. }
  211. }
  212. /// <summary>
  213. /// 返回界面
  214. /// </summary>
  215. /// <param name="obj"></param>
  216. /// <exception cref="NotImplementedException"></exception>
  217. private void GoBack(object obj)
  218. {
  219. _regionManager.Regions["ContentRegion"].RequestNavigate("ProjectTestResultView");
  220. }
  221. /// <summary>
  222. /// 获取所有项目
  223. /// </summary>
  224. private void GetProjectConfig()
  225. {
  226. allDeviceAndSchResultList.Clear();
  227. allDeviceList.Clear();
  228. conditionDevices.Clear();
  229. //所有测试方案
  230. var schlist = _basicPlcTestSchemeService.QueryList();
  231. var schDtoList = _mapper.Map<List<bas_plc_test_scheme>, List<BasicPlcTestSchemeDto>>(schlist);
  232. //测试记录中的所有设备
  233. var deviceIds=_iBizTestRecordService.QueryList().Select(X => X.device_id).Distinct();
  234. foreach (var deviceId in deviceIds)
  235. {
  236. List<DateTime> startDateTimes = new List<DateTime>();
  237. List<DateTime> endDateTimes = new List<DateTime>();
  238. var deviceMsg = _iBasicDeviceService.Find(((int)deviceId));
  239. if(deviceMsg != null)
  240. {
  241. string deviceKind = _iBasicDeviceKindService.Find((int)deviceMsg.device_kind_id)?.devicekind_name;
  242. string projectName = _iBasicProjectService.Find((int)deviceMsg.project_id)?.project_name;
  243. //记录设备下的方案通过个数
  244. int deviceCountResult = 0;
  245. string deviceTestResult = string.Empty;
  246. //查找哦记录有的方案
  247. var recordMsgs=_iBizTestRecordService.FindRecordByDeviceId(deviceId);
  248. foreach ( var sch in recordMsgs)
  249. {
  250. string testStatus = "已完成";
  251. long schId=(long)_basicPlcTestSchemeService.FindByNameAndType(sch.scheme_name, deviceKind)?.scheme_id;
  252. //计算测试结果
  253. string testResult = string.Empty;
  254. int countResult = 0;
  255. var records = _iBizTestRecordDtlService.FindRecordDetailByRecordID(sch.record_id);
  256. //
  257. var schDtls=_iBasicPlcTestSchemeDtlService.FindAllBySchId(schId);
  258. //循环所有测试项,有一个不合格,则整个测试方案不合格
  259. foreach(var dtl in schDtls)
  260. {
  261. //选取开始时间最大的一个数据,查看测试结果
  262. long schDtId = dtl.scheme_dtl_id;
  263. var findRecords=records.FindAll(x => x.scheme_dtl_id == schDtId).OrderByDescending(x=>x.start_test_time).ToArray();
  264. if(findRecords.Length>0)
  265. {
  266. int result = (int)findRecords[0]?.test_result.Value;
  267. if(result==0)
  268. {
  269. testResult = "不通过";
  270. break;
  271. }
  272. else
  273. {
  274. countResult++;
  275. }
  276. }
  277. //如果在测试记录中没有找到这个测试项,表示没有测试完所有的测试项)
  278. var findSchDtl = records.FirstOrDefault(x => x.scheme_dtl_id == schDtId);
  279. if(findSchDtl==null)
  280. {
  281. testStatus = "未完成";
  282. }
  283. }
  284. //测试结果
  285. if(countResult== schDtls.Count)
  286. {
  287. testResult = "通过";
  288. }
  289. //计算这个设备是否通过
  290. if(testResult == "通过")
  291. {
  292. deviceCountResult++;
  293. }
  294. //加入时间集合
  295. startDateTimes.Add(sch.start_test_time.Value);
  296. endDateTimes.Add(sch.finish_test_time.Value);
  297. //把
  298. allDeviceAndSchResultList.Add(new DeviceDtlWithResultModel()
  299. {
  300. RecordId = sch.record_id,
  301. DeviceId = deviceMsg.device_id,
  302. DeviceNo = deviceMsg.device_no,
  303. DeviceName = deviceMsg.device_name,
  304. DeviceKindName = deviceKind,
  305. ProjectName = projectName,
  306. StartTestTime =(DateTime) startDateTimes?.Min(),//取最小时间
  307. FinishTestTime = (DateTime)endDateTimes?.Max(),//取最大时间
  308. TestResult = testResult,
  309. SchemeName = sch.scheme_name,
  310. SchemeId = schId,
  311. CreateTime = sch.start_test_time.Value,
  312. CreateBy=sch.create_by,
  313. Remark=sch.remark,
  314. TestStatus=testStatus,
  315. });
  316. }
  317. //计算这个设备是否所有的方案都通过
  318. if ((deviceCountResult!=0)&&(deviceCountResult == recordMsgs.Count))
  319. {
  320. deviceTestResult = "通过";
  321. }
  322. else
  323. {
  324. deviceTestResult = "不通过";
  325. }
  326. //只添加选择的项目
  327. if (projectName == selectProjectName)
  328. {
  329. //这里不添加方案名称
  330. allDeviceList.Add(new DeviceDtlWithResultModel()
  331. {
  332. DeviceId = deviceMsg.device_id,
  333. DeviceNo = deviceMsg.device_no,
  334. DeviceName = deviceMsg.device_name,
  335. DeviceKindName = deviceKind,
  336. ProjectName = projectName,
  337. StartTestTime = startDateTimes.Min(),//取最小时间
  338. CreateTime=deviceMsg.create_time,
  339. CreateBy=deviceMsg.create_by,
  340. TestResult = deviceTestResult
  341. });
  342. conditionDevices.Add(new DeviceDtlWithResultModel()
  343. {
  344. DeviceId = deviceMsg.device_id,
  345. DeviceNo = deviceMsg.device_no,
  346. DeviceName = deviceMsg.device_name,
  347. DeviceKindName = deviceKind,
  348. ProjectName = projectName,
  349. StartTestTime = startDateTimes.Min(),//取最小时间
  350. CreateTime = deviceMsg.create_time,
  351. CreateBy = deviceMsg.create_by,
  352. TestResult = deviceTestResult
  353. });
  354. }
  355. }
  356. }
  357. conditionDevices = conditionDevices.OrderBy(x => x.DeviceId).ToList();
  358. Getpage();
  359. }
  360. /// <summary>
  361. /// 获取页面
  362. /// </summary>
  363. private void Getpage()
  364. {
  365. CurrentPage = 1;
  366. TotalCount = conditionDevices.Count;
  367. CurrentPageChanged();
  368. }
  369. /// <summary>
  370. /// 页面变化
  371. /// </summary>
  372. private void CurrentPageChanged()
  373. {
  374. DeviceResultItemList.Clear();
  375. foreach (var i in conditionDevices.Skip((CurrentPage - 1) * CountPerPage).Take(CountPerPage))
  376. {
  377. DeviceResultItemList.Add(i);
  378. }
  379. }
  380. /// <summary>
  381. /// 生成pdf
  382. /// </summary>
  383. /// <param name="obj"></param>
  384. public void CreatePdf(object obj)
  385. {
  386. List<biz_test_record_dtl> allRecordDtls = new List<biz_test_record_dtl>();
  387. object[] multiObj = obj as object[];
  388. //测试结果和设备id
  389. string testResult = (string)multiObj[0];
  390. long deviceId = (long)multiObj[1];
  391. //项目名称
  392. string projectName = (string)multiObj[2];
  393. //查找recordid
  394. var recordMsgs=_iBizTestRecordService.FindRecordByDeviceId((int)deviceId);
  395. //查找这个id的所有测试记录
  396. foreach(var recordMsg in recordMsgs)
  397. {
  398. //一条reoordid对应可能有多次测试记录
  399. var recordDtls = _iBizTestRecordDtlService.FindRecordDetailByRecordID(recordMsg.record_id);
  400. foreach(var record in recordDtls)
  401. {
  402. allRecordDtls.Add(record);
  403. }
  404. }
  405. //查找详细记录
  406. string deviceName = _iBasicDeviceService.Find((int)deviceId).device_name;
  407. try
  408. {
  409. Settings.License = LicenseType.Community;
  410. var model = GetReportPLCInfo(projectName,deviceName, allRecordDtls,testResult);
  411. var document = new InvoiceDocument(model);
  412. //pdf名称为轴编号+时间
  413. //输出文件
  414. using (System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog()
  415. {
  416. //设置文件类型
  417. //书写规则例如:txt files(*.txt)|*.txt
  418. Filter = "pdf文件|*.pdf",
  419. //设置默认文件名(可以不设置)
  420. FileName = "报表" + string.Format("{0:yyyyMMddHHmm}", DateTime.Now),
  421. //获取或设置一个值,该值指示如果用户省略扩展名,文件对话框是否自动在文件名中添加扩展名。(可以不设置)
  422. AddExtension = true,
  423. //保存对话框是否记忆上次打开的目录
  424. RestoreDirectory = true
  425. })
  426. {
  427. //点了保存按钮进入
  428. if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  429. {
  430. //获得文件路径
  431. string localFilePath = saveFileDialog.FileName.ToString();
  432. document.GeneratePdf(localFilePath);
  433. }
  434. }
  435. }
  436. catch (Exception ex)
  437. {
  438. _logger.LogError(ex.ToString());
  439. }
  440. }
  441. /// <summary>
  442. /// pdf报告相关信息
  443. /// </summary>
  444. /// <param name="schDtlId"></param>
  445. /// <returns></returns>
  446. private InvoiceModel GetReportPLCInfo(string projectName,string deviceName,List<biz_test_record_dtl> recordDtls,string testResult)
  447. {
  448. //测试方案明细主键ID
  449. InvoiceModel invoiceModel = new InvoiceModel();
  450. invoiceModel.ReportPLCModels = new List<ReportPLCModel>();
  451. invoiceModel.ProjectName = projectName;
  452. invoiceModel.DeviceName = deviceName;
  453. foreach (var each in recordDtls)
  454. {
  455. long recordId = each.record_id.Value;
  456. long schDtlid = each.scheme_dtl_id;
  457. var schDtlRelt = _iBasicPlcTestSchemeDtlService.Find((int)schDtlid);
  458. if(schDtlRelt != null)
  459. {
  460. //查找方案名
  461. long schId = schDtlRelt.scheme_id.Value;
  462. string schEachName = _basicPlcTestSchemeService.Find((int)schId)?.scheme_name;
  463. string schItemName = schDtlRelt.item_name;
  464. string schItemType = string.Empty;
  465. int typeNo = schDtlRelt.item_type.Value;
  466. switch (typeNo)
  467. {
  468. case 0:
  469. schItemType = "前置项";
  470. break;
  471. case 1:
  472. schItemType = "PLC点位测试项";
  473. break;
  474. case 2:
  475. schItemType = "Robot动作测试";
  476. break;
  477. }
  478. //根据测试结果明细
  479. if (each != null)
  480. { //前置项结果解析
  481. string preconStr = each.precondition_final?.ToString();
  482. if (!string.IsNullOrEmpty(preconStr))
  483. {
  484. JsonModel preconditionModel = JsonConvert.DeserializeObject<JsonModel>(preconStr);
  485. foreach (var detail in preconditionModel.DetailInfo)
  486. {
  487. invoiceModel.ReportPLCModels.Add(new ReportPLCModel()
  488. {
  489. SchName= schEachName,
  490. ItemName = schItemName,
  491. ItemType = schItemType,
  492. Type = "前置项",
  493. JudgeType = preconditionModel.ItemType,
  494. SelectLogic = preconditionModel.ItemLogical,
  495. Detail = preconditionModel.Description,
  496. Id = detail.Id,
  497. PlcAddress = detail.PlcAddress,
  498. PlcItem = detail.PlcItem,
  499. PlcValue = detail.PlcValue,
  500. Remark = detail.Remark,
  501. TestTime = detail.TestTime,
  502. RealValue = detail.RealValue,
  503. TestResult = detail.TestResult,
  504. });
  505. }
  506. }
  507. //输入项解析
  508. string inStr = each.action_final?.ToString();
  509. if (!string.IsNullOrEmpty(inStr))
  510. {
  511. JsonModel inModel = JsonConvert.DeserializeObject<JsonModel>(inStr);
  512. foreach (var detail in inModel.DetailInfo)
  513. {
  514. invoiceModel.ReportPLCModels.Add(new ReportPLCModel()
  515. {
  516. SchName = schEachName,
  517. ItemName = schItemName,
  518. ItemType = schItemType,
  519. Type = "输入项",
  520. JudgeType = inModel.ItemType,
  521. SelectLogic = inModel.ItemLogical,
  522. Detail = inModel.Description,
  523. Id = detail.Id,
  524. PlcAddress = detail.PlcAddress,
  525. PlcItem = detail.PlcItem,
  526. PlcValue = detail.PlcValue,
  527. Remark = detail.Remark,
  528. TestTime = detail.TestTime,
  529. RealValue = detail.RealValue,
  530. TestResult = detail.TestResult,
  531. });
  532. }
  533. }
  534. //输出项解析
  535. string outStr = each.judgement_result_final?.ToString();
  536. if (!string.IsNullOrEmpty(outStr))
  537. {
  538. JsonModel outModel = JsonConvert.DeserializeObject<JsonModel>(outStr);
  539. foreach (var detail in outModel.DetailInfo)
  540. {
  541. invoiceModel.ReportPLCModels.Add(new ReportPLCModel()
  542. {
  543. SchName = schEachName,
  544. ItemName = schItemName,
  545. ItemType = schItemType,
  546. Type = "结果项",
  547. JudgeType = outModel.ItemType,
  548. SelectLogic = outModel.ItemLogical,
  549. Detail = outModel.Description,
  550. Id = detail.Id,
  551. PlcAddress = detail.PlcAddress,
  552. PlcItem = detail.PlcItem,
  553. PlcValue = detail.PlcValue,
  554. Remark = detail.Remark,
  555. TestTime = detail.TestTime,
  556. RealValue = detail.RealValue,
  557. TestResult = detail.TestResult,
  558. });
  559. }
  560. }
  561. }
  562. }
  563. }
  564. //判断方案结果是否通过
  565. //var testCount = allDeviceList.FindAll(X => X.SchemeName == findSch.scheme_name && X.TestResult == "通过")?.Count;
  566. //if (testCount == allResult.Count)
  567. //{
  568. // invoiceModel.FinalReuslt = "通过";
  569. //}
  570. //else
  571. //{
  572. // invoiceModel.FinalReuslt = "不通过";
  573. //}
  574. invoiceModel.FinalReuslt = testResult;
  575. return invoiceModel;
  576. }
  577. public void OnNavigatedTo(NavigationContext navigationContext)
  578. {
  579. //编辑
  580. var getMsg = navigationContext.Parameters.GetValues<string>("Key");
  581. ///值不为空,表示修改,为空表示新增
  582. if (getMsg != null)
  583. {
  584. foreach (var item in getMsg)
  585. {
  586. selectProjectName = item;
  587. }
  588. }
  589. }
  590. public bool IsNavigationTarget(NavigationContext navigationContext)
  591. {
  592. return true;
  593. }
  594. public void OnNavigatedFrom(NavigationContext navigationContext)
  595. {
  596. }
  597. #endregion
  598. #region 命令绑定
  599. public DelegateCommand<object> QueryCommand { set; get; }
  600. public DelegateCommand<string> ExportCommand { set; get; }
  601. public DelegateCommand<object> ResetCommand { set; get; }
  602. public DelegateCommand OnLoadCommand { set; get; }
  603. public DelegateCommand<object> CheckDetailCommand { set; get; }
  604. public DelegateCommand<object> UnqualifiedCommand { set; get; }
  605. public DelegateCommand<object> PdfReportCommand { set; get; }
  606. public DelegateCommand<object> DgSelectChangeCommand { set; get; }
  607. public DelegateCommand<object> GoBackCommand { set; get; }
  608. #endregion
  609. #region 数据绑定
  610. private ObservableCollection<DeviceDtlWithResultModel> deviceResultItemList = new ObservableCollection<DeviceDtlWithResultModel>();
  611. public ObservableCollection<DeviceDtlWithResultModel> DeviceResultItemList
  612. {
  613. get { return deviceResultItemList; }
  614. set { deviceResultItemList = value; RaisePropertyChanged(); }
  615. }
  616. private ObservableCollection<DeviceDtlWithResultModel> schItemResultList = new ObservableCollection<DeviceDtlWithResultModel>();
  617. public ObservableCollection<DeviceDtlWithResultModel> SchItemResultList
  618. {
  619. get { return schItemResultList; }
  620. set { schItemResultList = value; RaisePropertyChanged(); }
  621. }
  622. /// <summary>
  623. /// 设备编号
  624. /// </summary>
  625. private string devicedNo;
  626. public string DeviceNo
  627. {
  628. get { return devicedNo; }
  629. set { devicedNo = value; RaisePropertyChanged(); }
  630. }
  631. /// <summary>
  632. /// 设备类型名称
  633. /// </summary>
  634. private string deviceName;
  635. public string DeviceName
  636. {
  637. get { return deviceName; }
  638. set { deviceName = value; RaisePropertyChanged(); }
  639. }
  640. private string projectName;
  641. public string ProjectName
  642. {
  643. get { return projectName; }
  644. set { projectName = value; RaisePropertyChanged(); }
  645. }
  646. private string deviceKindName;
  647. public string DeviceKindName
  648. {
  649. get { return deviceKindName; }
  650. set { deviceKindName = value; RaisePropertyChanged(); }
  651. }
  652. /// <summary>
  653. /// 项目名称
  654. /// </summary>
  655. private ObservableCollection<string> projectNameList = new ObservableCollection<string>();
  656. public ObservableCollection<string> ProjectNameList
  657. {
  658. get { return projectNameList; }
  659. set { projectNameList = value; RaisePropertyChanged(); }
  660. }
  661. /// <summary>
  662. /// 开始时间
  663. /// </summary>
  664. private string startTime = DateTime.Now.AddDays(-1).ToString();
  665. public string StartTime
  666. {
  667. get { return startTime; }
  668. set { startTime = value; RaisePropertyChanged(); }
  669. }
  670. private string endTime = DateTime.Now.ToString();
  671. public string EndTime
  672. {
  673. get { return endTime; }
  674. set { endTime = value; RaisePropertyChanged(); }
  675. }
  676. /// <summary>
  677. /// 设备类型
  678. /// </summary>
  679. private ObservableCollection<string> deviceKindNameList = new ObservableCollection<string>();
  680. public ObservableCollection<string> DeviceKindNameList
  681. {
  682. get { return deviceKindNameList; }
  683. set { deviceKindNameList = value; RaisePropertyChanged(); }
  684. }
  685. /// <summary>
  686. /// 总条数
  687. /// </summary>
  688. private int totalCount;
  689. public int TotalCount
  690. {
  691. get { return totalCount; }
  692. set { totalCount = value; RaisePropertyChanged(); CurrentPageChanged(); }
  693. }
  694. /// <summary>
  695. /// 每页数量
  696. /// </summary>
  697. private int countPerPage = 15;
  698. public int CountPerPage
  699. {
  700. get { return countPerPage; }
  701. set { countPerPage = value; RaisePropertyChanged(); CurrentPageChanged(); }
  702. }
  703. /// <summary>
  704. /// 单前页
  705. /// </summary>
  706. private int currentPage = 1;
  707. public int CurrentPage
  708. {
  709. get { return currentPage; }
  710. set { currentPage = value; RaisePropertyChanged(); CurrentPageChanged(); }
  711. }
  712. #endregion
  713. }
  714. }