ManualTestViewModel.cs 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615
  1. using AutoMapper;
  2. using BizService;
  3. using Microsoft.Extensions.Logging;
  4. using Model.Dto;
  5. using Model.Entities;
  6. using NetTaste;
  7. using Newtonsoft.Json;
  8. using OmronFinsTCP.Net;
  9. using PLCTool.Common;
  10. using PLCTool.Events;
  11. using Prism.Commands;
  12. using Prism.Events;
  13. using Prism.Mvvm;
  14. using Prism.Services.Dialogs;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Collections.ObjectModel;
  18. using System.Configuration;
  19. using System.Linq;
  20. using System.Linq.Expressions;
  21. using System.Text;
  22. using System.Threading.Tasks;
  23. using System.Windows;
  24. using WPFDevelopers.Controls.Runtimes.Shell32;
  25. using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
  26. namespace PLCTool.ViewModels.BusinessManageViewModel
  27. {
  28. public class ManualTestViewModel : BindableBase, IDialogAware
  29. {
  30. private readonly IDialogService _dialog;
  31. private readonly IEventAggregator _aggregator;
  32. private readonly IOptionConfigService _optionConfigService;
  33. private readonly IBasicPlcTestSchemeService _basicPlcTestSchemeService;
  34. private readonly IBasicPlcTestSchemeDtlService _basicPlcTestSchemeDtlService;
  35. private readonly IBizTestRecordService _iBizTestRecordService;
  36. private readonly IBizTestRecordDtlService _iBizTestRecordDtlService;
  37. private readonly IMapper _mapper;
  38. private readonly ILogger _logger;
  39. private List<OptionConfigDto> _optionConfigs;
  40. private DateTime startTime= DateTime.Now;
  41. private DateTime endTime=DateTime.Now;
  42. private int testStatus = 0; //测试状态
  43. private int testResult = 0; //测试结果
  44. private long schId = 0; //方案ID
  45. private long globalSchDetailId = 0; //测试方案明细ID
  46. private long globalDeviceId = 0; //设备ID
  47. private long globalSort = 0; //排序
  48. private BizTestRecordDtlDto bizTestRecordDtlDto = new BizTestRecordDtlDto(); //测试方案明细表
  49. private const string TestMode = "手动测试";
  50. private List<bas_plc_test_scheme_dtl> allSchDtlsById = new List<bas_plc_test_scheme_dtl>(); //测试方案明细项目
  51. private int defaultDelayTime = Convert.ToInt32(ConfigurationManager.AppSettings["DelayTime"]);
  52. private int delayTime;
  53. public ManualTestViewModel(IDialogService dialog, IEventAggregator aggregator, IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService, IBizTestRecordService iBizTestRecordService, IBizTestRecordDtlService iBizTestRecordDtlService,IMapper mapper,ILogger logger)
  54. {
  55. _dialog = dialog;
  56. _aggregator = aggregator;
  57. _optionConfigService = optionConfigService;
  58. _basicPlcTestSchemeService = basicPlcTestSchemeService;
  59. _basicPlcTestSchemeDtlService = basicPlcTestSchemeDtlService;
  60. _iBizTestRecordDtlService = iBizTestRecordDtlService;
  61. _iBizTestRecordService= iBizTestRecordService;
  62. _mapper = mapper;
  63. _logger = logger;
  64. CloseCommand = new DelegateCommand(Close);
  65. StartCommand = new DelegateCommand<object>(Start);
  66. PreviousCommand = new DelegateCommand<object>(Previous);
  67. NextCommand = new DelegateCommand<object>(Next);
  68. DoneCommand = new DelegateCommand<object>(Done);
  69. ItemChangeCommand = new DelegateCommand(ItemChange);
  70. ResetCommand = new DelegateCommand(Reset);
  71. BeforeConList = new ObservableCollection<BasPlcItemConfigDto>();
  72. InConList = new ObservableCollection<BasPlcItemConfigDto>();
  73. OutConList = new ObservableCollection<BasPlcItemConfigDto>();
  74. GetConfigOption();
  75. }
  76. /// <summary>
  77. /// 选中测试项
  78. /// </summary>
  79. private void ItemChange()
  80. {
  81. var findDtlMsg = allSchDtlsById?.FirstOrDefault(X => X.item_name == SelectItem);
  82. if(findDtlMsg != null)
  83. {
  84. int id = Convert.ToInt32(findDtlMsg.scheme_dtl_id);
  85. // 根据 测试方案明细主键ID 查找测试方案id 及方案名和设备名
  86. globalSchDetailId = id;
  87. globalSort = findDtlMsg.sort;
  88. GetDetailInfo(id);
  89. }
  90. }
  91. /// <summary>
  92. /// 复位PLC
  93. /// </summary>
  94. private async void Reset()
  95. {
  96. PLCConnectionFactory.CreatePLCCont().ResetPLC("1.00", VarType.Bit, "0");
  97. await Task.Delay(1000);
  98. PLCConnectionFactory.CreatePLCCont().ResetPLC("1.00", VarType.Bit, "1");
  99. await Task.Delay(1000);
  100. bool isResult=PLCConnectionFactory.CreatePLCCont().ResetPLC("1.00", VarType.Bit, "0");
  101. if(isResult)
  102. {
  103. MessageBox.Show("复位成功!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
  104. }
  105. }
  106. #region idialog接口实现
  107. public string Title { set; get; } = "手动测试";
  108. public event Action<IDialogResult> RequestClose;
  109. public bool CanCloseDialog()
  110. {
  111. return true;
  112. }
  113. public void OnDialogClosed()
  114. {
  115. }
  116. public void OnDialogOpened(IDialogParameters parameters)
  117. {
  118. //编辑
  119. var getMsg = parameters.GetValues<long>("Key");
  120. ///值不为空,表示修改
  121. if (getMsg != null)
  122. {
  123. foreach (var item in getMsg)
  124. {
  125. //测试方案号
  126. schId = item;
  127. allSchDtlsById = _basicPlcTestSchemeDtlService.FindAllBySchId(schId);
  128. var schDtls= allSchDtlsById.OrderBy(x => x.sort).ThenBy(x => x.scheme_dtl_id).ToList(); ;
  129. foreach(var sch in schDtls)
  130. {
  131. long dtlId = sch.scheme_dtl_id;
  132. SchItems.Add(sch.item_name);
  133. }
  134. //默认显示第一个测试项的信息
  135. if(schDtls.Count!=0)
  136. {
  137. int id = Convert.ToInt32(schDtls[0].scheme_dtl_id);
  138. globalSchDetailId = id;
  139. // 根据 测试方案明细主键ID 查找测试方案id 及方案名和设备名
  140. GetDetailInfo(id);
  141. SelectItemIndex = 0;
  142. }
  143. //globalSchDetailId = item; //测试方案明细ID
  144. //int id = Convert.ToInt32(item);
  145. //// 根据 测试方案明细主键ID 查找测试方案id 及方案名和设备名
  146. //GetDetailInfo(id);
  147. }
  148. }
  149. //获取设备id
  150. var getDes = parameters.GetValues<long>("Key2");
  151. if(getDes != null)
  152. {
  153. foreach(var item in getDes)
  154. {
  155. globalDeviceId = item;
  156. }
  157. }
  158. }
  159. /// <summary>
  160. /// 发送log之界面显示
  161. /// </summary>
  162. /// <param name="msg"></param>
  163. private void SendLogToDis(string msg)
  164. {
  165. _aggregator.GetEvent<LogEvent>().Publish(new LogMessage
  166. {
  167. LogTime = DateTime.Now,
  168. LogMsg = msg
  169. });
  170. }
  171. /// <summary>
  172. /// //根据 测试方案明细主键ID 查找测试方案id 及方案名和设备名
  173. /// </summary>
  174. /// <param name="id"></param>
  175. private void GetDetailInfo(int schDetailId)
  176. {
  177. //根据 测试方案明细主键ID 查找测试方案id 及方案名和设备名
  178. var findEntity = _basicPlcTestSchemeDtlService.Find(schDetailId);
  179. var findresult = _mapper.Map<bas_plc_test_scheme_dtl, BasicPlcTestSchemeDtlDto>(findEntity);
  180. if (findresult != null)
  181. {
  182. //根据方案id 在方案表中查找方案名 设备名
  183. schId = findresult.SchemeId.Value; //方案id,方便下一步查找
  184. int intSchId = Convert.ToInt32(findresult.SchemeId);
  185. var findSch = _basicPlcTestSchemeService.Find(intSchId);
  186. if (findSch != null)
  187. {
  188. ScheduleName = findSch.scheme_name;
  189. DeviceKindName = findSch.devicekind_name;
  190. }
  191. TestName = findresult.ItemName;
  192. SelectTest = findresult.ItemType;
  193. //测试时间
  194. if(findresult.ItemTime == 0)
  195. {
  196. delayTime = defaultDelayTime;
  197. }
  198. else
  199. {
  200. delayTime = findresult.ItemTime;
  201. }
  202. //前置项解析
  203. string preconStr = findresult.Precondition.ToString();
  204. if (!string.IsNullOrEmpty(preconStr))
  205. {
  206. JsonModel preconditionModel = JsonConvert.DeserializeObject<JsonModel>(preconStr);
  207. BeforeSelectJudge = preconditionModel.ItemType;
  208. SelectLogic = preconditionModel.ItemLogical;
  209. BeforeDetail = preconditionModel.Description;
  210. BeforeConList.Clear();
  211. foreach (var detail in preconditionModel.DetailInfo)
  212. {
  213. BasPlcItemConfigDto basPlcItemConfigDto = new BasPlcItemConfigDto();
  214. basPlcItemConfigDto.Id=detail.Id;
  215. basPlcItemConfigDto.PlcItem = detail.PlcItem;
  216. basPlcItemConfigDto.PlcAddress = detail.PlcAddress;
  217. basPlcItemConfigDto.PlcAddType = detail.PlcAddType;
  218. basPlcItemConfigDto.PlcValue = detail.PlcValue;
  219. basPlcItemConfigDto.Remark = detail.Remark;
  220. BeforeConList.Add(basPlcItemConfigDto);
  221. }
  222. }
  223. //输入项解析
  224. string inStr = findresult.Action.ToString();
  225. if (!string.IsNullOrEmpty(inStr))
  226. {
  227. JsonModel inModel = JsonConvert.DeserializeObject<JsonModel>(inStr);
  228. SelectInJudge = inModel.ItemType;
  229. InSelectLogic = inModel.ItemLogical;
  230. InDetail = inModel.Description;
  231. InConList.Clear();
  232. foreach (var detail in inModel.DetailInfo)
  233. {
  234. BasPlcItemConfigDto basPlcItemConfigDto = new BasPlcItemConfigDto();
  235. basPlcItemConfigDto.Id = detail.Id;
  236. basPlcItemConfigDto.PlcItem = detail.PlcItem;
  237. basPlcItemConfigDto.PlcAddress = detail.PlcAddress;
  238. basPlcItemConfigDto.PlcAddType = detail.PlcAddType;
  239. basPlcItemConfigDto.PlcValue = detail.PlcValue;
  240. basPlcItemConfigDto.Remark = detail.Remark;
  241. InConList.Add(basPlcItemConfigDto);
  242. }
  243. }
  244. //输出项解析
  245. string outStr = findresult.JudgementResult.ToString();
  246. if (!string.IsNullOrEmpty(outStr))
  247. {
  248. JsonModel outModel = JsonConvert.DeserializeObject<JsonModel>(outStr);
  249. SelectOutJudge = outModel.ItemType;
  250. OutSelectLogic = outModel.ItemLogical;
  251. OutDetail = outModel.Description;
  252. OutConList.Clear();
  253. foreach (var detail in outModel.DetailInfo)
  254. {
  255. BasPlcItemConfigDto basPlcItemConfigDto = new BasPlcItemConfigDto();
  256. basPlcItemConfigDto.Id = detail.Id;
  257. basPlcItemConfigDto.PlcItem = detail.PlcItem;
  258. basPlcItemConfigDto.PlcAddress = detail.PlcAddress;
  259. basPlcItemConfigDto.PlcAddType = detail.PlcAddType;
  260. basPlcItemConfigDto.PlcValue = detail.PlcValue;
  261. basPlcItemConfigDto.Remark = detail.Remark;
  262. OutConList.Add(basPlcItemConfigDto);
  263. }
  264. }
  265. }
  266. }
  267. #endregion
  268. #region 私有发方法
  269. /// <summary>
  270. /// 增加或更新测试记录
  271. /// </summary>
  272. private void AddTestRecord()
  273. {
  274. //记录记录主表中是否有这个方案的记录,没有则添加
  275. var findRecord = _iBizTestRecordService.FindRecorddByDeviceIdAndSchname(globalDeviceId,ScheduleName);
  276. if (findRecord == null)
  277. {
  278. //状态status 没有赋值
  279. BizTestRecordDto bizTestRecordDto = new BizTestRecordDto();
  280. bizTestRecordDto.RecordName = ScheduleName + "_Record";
  281. bizTestRecordDto.SchemeName = ScheduleName;
  282. bizTestRecordDto.DeviceId = globalDeviceId;
  283. bizTestRecordDto.Tester = Appsession.UserName;
  284. bizTestRecordDto.StartTestTime = startTime;
  285. bizTestRecordDto.FinishTestTime = endTime;
  286. bizTestRecordDto.CreateBy = Appsession.UserName;
  287. bizTestRecordDto.CreateTime = DateTime.Now;
  288. bizTestRecordDto.UpdateBy = Appsession.UserName;
  289. bizTestRecordDto.UpdateTime = DateTime.Now;
  290. var testRecord = _mapper.Map<BizTestRecordDto, biz_test_record>(bizTestRecordDto);
  291. _iBizTestRecordService.Add(testRecord);
  292. }
  293. }
  294. /// <summary>
  295. /// 获取记录明细
  296. /// </summary>
  297. private void AddDtltRecord(long schDetailId)
  298. {
  299. //查找record ID
  300. long recordId = 0;
  301. var findRecordID = _iBizTestRecordService.FindRecorddByDeviceIdAndSchname(globalDeviceId, ScheduleName);
  302. if (findRecordID != null)
  303. {
  304. recordId = findRecordID.record_id;
  305. }
  306. testStatus = 99;//测试状态赋值为99
  307. //状态status 没有赋值
  308. DateTime finishTime = DateTime.Now;
  309. bizTestRecordDtlDto.RecordId = recordId;
  310. bizTestRecordDtlDto.SchemeDtlId = schDetailId;
  311. bizTestRecordDtlDto.StartTestTime = startTime;
  312. bizTestRecordDtlDto.FinishTestTime = endTime;
  313. bizTestRecordDtlDto.TestMode = TestMode;
  314. bizTestRecordDtlDto.Status = testStatus;
  315. bizTestRecordDtlDto.TestResult = GetTestResult();
  316. bizTestRecordDtlDto.CreateBy = Appsession.UserName;
  317. bizTestRecordDtlDto.CreateTime = startTime;
  318. bizTestRecordDtlDto.UpdateBy = Appsession.UserName;
  319. bizTestRecordDtlDto.UpdateTime = finishTime;
  320. var testRecordDtl = _mapper.Map<BizTestRecordDtlDto, biz_test_record_dtl>(bizTestRecordDtlDto);
  321. _iBizTestRecordDtlService.Add(testRecordDtl);
  322. //跟新测试记录的_iBizTestRecord的完成时间
  323. var findRecord = _iBizTestRecordService.Find((int)recordId);
  324. if (findRecord != null)
  325. {
  326. findRecord.finish_test_time = finishTime;
  327. _iBizTestRecordService.Edit(findRecord);
  328. }
  329. }
  330. /// <summary>
  331. /// 前置项结果判定
  332. /// </summary>
  333. /// <returns></returns>
  334. private int GetPrecedtionResult()
  335. {
  336. //前置项
  337. int beforeResult = 0;
  338. if (BeforeConList.Count == 0)
  339. {
  340. beforeResult = 1;
  341. }
  342. else
  343. {
  344. if (SelectLogic == "OR")
  345. {
  346. var find = BeforeConList.FirstOrDefault(x => x.TestResult == "通过");
  347. if (find != null)
  348. {
  349. beforeResult = 1;
  350. }
  351. else
  352. {
  353. beforeResult = 0;
  354. }
  355. }
  356. else
  357. {
  358. if (SelectLogic == "AND" || SelectLogic == "ONLY")
  359. {
  360. var find = BeforeConList.FirstOrDefault(x => x.TestResult == "不通过");
  361. if (find != null)
  362. {
  363. beforeResult = 0;
  364. }
  365. else
  366. {
  367. beforeResult = 1;
  368. }
  369. }
  370. else
  371. {
  372. if (SelectLogic == "NULL")
  373. {
  374. beforeResult = 1;
  375. }
  376. }
  377. }
  378. }
  379. return beforeResult;
  380. }
  381. /// <summary>
  382. /// 判定结果
  383. /// </summary>
  384. /// <returns></returns>
  385. private int GetTestResult()
  386. {
  387. //前置项
  388. int beforeResult = 0;
  389. int inResult= 0;
  390. int outResult = 0;
  391. if(BeforeConList.Count==0)
  392. {
  393. beforeResult = 1;
  394. }
  395. else
  396. {
  397. if (SelectLogic == "OR")
  398. {
  399. var find = BeforeConList.FirstOrDefault(x => x.TestResult == "通过");
  400. if (find != null)
  401. {
  402. beforeResult = 1;
  403. }
  404. else
  405. {
  406. beforeResult = 0;
  407. }
  408. }
  409. else
  410. {
  411. if (SelectLogic == "AND" || SelectLogic == "ONLY")
  412. {
  413. var find = BeforeConList.FirstOrDefault(x => x.TestResult == "不通过");
  414. if (find != null)
  415. {
  416. beforeResult = 0;
  417. }
  418. else
  419. {
  420. beforeResult = 1;
  421. }
  422. }
  423. else
  424. {
  425. if (SelectLogic == "NULL")
  426. {
  427. beforeResult = 1;
  428. }
  429. }
  430. }
  431. }
  432. //输入项
  433. if(InConList.Count==0)
  434. {
  435. inResult = 1;
  436. }
  437. else
  438. {
  439. if (InSelectLogic == "OR")
  440. {
  441. var find = InConList.FirstOrDefault(x => x.TestResult == "通过");
  442. if (find != null)
  443. {
  444. inResult = 1;
  445. }
  446. else
  447. {
  448. inResult = 0;
  449. }
  450. }
  451. else
  452. {
  453. if (InSelectLogic == "AND" || InSelectLogic == "ONLY")
  454. {
  455. var find = InConList.FirstOrDefault(x => x.TestResult == "不通过");
  456. if (find != null)
  457. {
  458. inResult = 0;
  459. }
  460. else
  461. {
  462. inResult = 1;
  463. }
  464. }
  465. else
  466. {
  467. if (InSelectLogic == "NULL")
  468. {
  469. inResult = 1;
  470. }
  471. }
  472. }
  473. }
  474. //输出项
  475. if(OutConList.Count==0)
  476. {
  477. outResult = 1;
  478. }
  479. else
  480. {
  481. if (OutSelectLogic == "OR")
  482. {
  483. var find = OutConList.FirstOrDefault(x => x.TestResult == "通过");
  484. if (find != null)
  485. {
  486. outResult = 1;
  487. }
  488. else
  489. {
  490. outResult = 0;
  491. }
  492. }
  493. else
  494. {
  495. if (OutSelectLogic == "AND" || OutSelectLogic == "ONLY")
  496. {
  497. var find = OutConList.FirstOrDefault(x => x.TestResult == "不通过");
  498. if (find != null)
  499. {
  500. outResult = 0;
  501. }
  502. else
  503. {
  504. outResult = 1;
  505. }
  506. }
  507. else
  508. {
  509. if (OutSelectLogic == "NULL")
  510. {
  511. outResult = 1;
  512. }
  513. }
  514. }
  515. }
  516. if(beforeResult==1&&inResult==1&&outResult==1)
  517. {
  518. return 1;
  519. }
  520. else
  521. {
  522. return 0;
  523. }
  524. }
  525. /// <summary>
  526. /// 更新测试记录
  527. /// </summary>
  528. private void UpdateTesDtltRecord()
  529. {
  530. var testRecordDtl = _mapper.Map<BizTestRecordDtlDto, biz_test_record_dtl>(bizTestRecordDtlDto);
  531. _iBizTestRecordDtlService.Edit(testRecordDtl);
  532. }
  533. /// <summary>
  534. /// 完成时间
  535. /// </summary>
  536. /// <param name="obj"></param>
  537. private void Done(object obj)
  538. {
  539. endTime = DateTime.Now;
  540. RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
  541. }
  542. private void Next(object obj)
  543. {
  544. StepIndex = 0;
  545. long maxSort = allSchDtlsById.Select(x => x.sort).Max();
  546. ///查找方案下的所有方案明细,并排序,
  547. if (maxSort!=0)
  548. {
  549. if(globalSort< maxSort)
  550. {
  551. globalSort++;
  552. var findSort = allSchDtlsById.FirstOrDefault(x => x.sort == globalSort);
  553. if (findSort != null)
  554. {
  555. int id = Convert.ToInt32(findSort.scheme_dtl_id);
  556. globalSchDetailId = findSort.scheme_dtl_id;
  557. SelectItemIndex++;
  558. //界面显示
  559. GetDetailInfo(id);
  560. }
  561. }
  562. else
  563. {
  564. MessageBox.Show("已是此测试方案最后一个测试项!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
  565. }
  566. }
  567. //兼容没加排序字段以前的
  568. else
  569. {
  570. var basicSchDtls = allSchDtlsById?.OrderBy(x => x.scheme_dtl_id);
  571. foreach (var item in basicSchDtls)
  572. {
  573. //在测试结果明细中查看
  574. long schDetailId = item.scheme_dtl_id;
  575. if (schDetailId > globalSchDetailId)
  576. {
  577. globalSchDetailId = schDetailId;
  578. int id = Convert.ToInt32(schDetailId);
  579. SelectItemIndex++;
  580. //界面显示
  581. GetDetailInfo(id);
  582. //记录记录明细表中是否有这个方案明细ID的记录,没有则添加,有则更新记录状态
  583. break;
  584. }
  585. long maxDtlId = basicSchDtls.Select(x => x.scheme_dtl_id).Max();
  586. if (globalSchDetailId == maxDtlId)
  587. {
  588. MessageBox.Show("已是此测试方案最后一个测试项!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
  589. break;
  590. }
  591. }
  592. }
  593. }
  594. private void Previous(object obj)
  595. {
  596. StepIndex = 0;
  597. int maxSort = allSchDtlsById.Select(x => x.sort).Max();
  598. if(maxSort!=0)
  599. {
  600. if (globalSort>1)
  601. {
  602. globalSort--;
  603. var findSort = allSchDtlsById.FirstOrDefault(x => x.sort == globalSort);
  604. if (findSort != null)
  605. {
  606. int id = Convert.ToInt32(findSort.scheme_dtl_id);
  607. globalSchDetailId = findSort.scheme_dtl_id;
  608. SelectItemIndex--;
  609. //界面显示
  610. GetDetailInfo(id);
  611. }
  612. }
  613. else
  614. {
  615. SelectItemIndex = 0;
  616. MessageBox.Show("已是此测试方案的第一个测试项!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
  617. }
  618. }
  619. else
  620. {///查找方案下的所有方案明细,并排序,
  621. var basicSchDtls = allSchDtlsById?.OrderByDescending(x => x.sort).ThenByDescending(x => x.scheme_dtl_id);
  622. foreach (var item in basicSchDtls)
  623. {
  624. //在测试结果明细中查看
  625. long schDetailId = item.scheme_dtl_id;
  626. if (schDetailId < globalSchDetailId)
  627. {
  628. globalSchDetailId = schDetailId;
  629. int id = Convert.ToInt32(schDetailId);
  630. SelectItemIndex--;
  631. //界面显示
  632. GetDetailInfo(id);
  633. //记录记录明细表中是否有这个方案明细ID的记录,没有则添加,有则更新记录状态
  634. break;
  635. }
  636. }
  637. long maxDtlId = basicSchDtls.Select(x => x.scheme_dtl_id).Min();
  638. if (globalSchDetailId == maxDtlId)
  639. {
  640. SelectItemIndex = 0;
  641. MessageBox.Show("已是此测试方案的第一个测试项!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
  642. }
  643. }
  644. }
  645. /// <summary>
  646. /// 开始检测
  647. /// </summary>
  648. /// <param name="obj"></param>
  649. private async void Start(object obj)
  650. {
  651. StartEnalbe = false;
  652. _logger.LogInformation($"开始手动测试。方案名{ScheduleName},测试项{TestName}");
  653. SendLogToDis($"开始手动测试。方案名{ScheduleName},测试项{TestName}");
  654. //开始时间
  655. startTime = DateTime.Now;
  656. //增加测试记录主表
  657. AddTestRecord();
  658. //前置项
  659. bool preBool=TestPreceditionMethod();
  660. if(!preBool)
  661. {
  662. StepIndex = 0;
  663. StartEnalbe = true;
  664. return;
  665. }
  666. //前置项结果判断
  667. int preceditionResult=GetPrecedtionResult();
  668. if( preceditionResult == 0 )
  669. {
  670. MessageBoxResult boxResult = MessageBox.Show("前置项条件不满足,请确认前置条件!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
  671. StartEnalbe = true;
  672. return;
  673. }
  674. //输入项
  675. bool isAction=TestActionMethod();
  676. if (!isAction)
  677. {
  678. StepIndex = 0;
  679. StartEnalbe = true;
  680. return;
  681. }
  682. //输出项
  683. bool isJudgeResult=await TestJudgementMethod();
  684. if (!isJudgeResult)
  685. {
  686. StepIndex = 0;
  687. StartEnalbe = true;
  688. return;
  689. }
  690. //将测试结果添加到数据库
  691. AddDtltRecord(globalSchDetailId);
  692. SendLogToDis($"手动测试完成。方案名{ScheduleName},测试项{TestName}");
  693. _logger.LogInformation($"手动测试完成。方案名{ScheduleName},测试项{TestName}");
  694. StartEnalbe = true;
  695. }
  696. /// <summary>
  697. /// 更新测试结果
  698. /// </summary>
  699. private void UpdateTestRecord()
  700. {
  701. }
  702. /// <summary>
  703. /// 测试前置项目
  704. /// </summary>
  705. private bool TestPreceditionMethod()
  706. {
  707. switch (BeforeSelectJudge)
  708. {
  709. case "人工判定":
  710. //弹出确认的对话框
  711. if(string.IsNullOrEmpty(BeforeDetail))
  712. {
  713. return true;
  714. }
  715. MessageBoxResult boxResult = MessageBox.Show(BeforeDetail, "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
  716. if (boxResult == MessageBoxResult.OK)
  717. {
  718. //前置项测试结果json转化
  719. string prefixJsonStr = ModelToJsonToStr(BeforeSelectJudge, SelectLogic, BeforeDetail, BeforeConList);
  720. //json字符串
  721. bizTestRecordDtlDto.PreconditionFinal = prefixJsonStr;
  722. bizTestRecordDtlDto.PreconditionResult = "通过";
  723. StepIndex = 1;
  724. }
  725. else
  726. {
  727. return false;
  728. }
  729. break;
  730. case "自动判定":
  731. //读取plc的值
  732. switch (SelectLogic)
  733. {
  734. case "NULL":
  735. //弹出确认的对话框
  736. if (string.IsNullOrEmpty(BeforeDetail))
  737. {
  738. return true;
  739. }
  740. MessageBoxResult boxResultAuto = MessageBox.Show(BeforeDetail, "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
  741. if (boxResultAuto == MessageBoxResult.OK)
  742. {
  743. //前置项测试结果json转化
  744. string prefixJsonStr = ModelToJsonToStr(BeforeSelectJudge, SelectLogic, BeforeDetail, BeforeConList);
  745. //json字符串
  746. bizTestRecordDtlDto.PreconditionFinal = prefixJsonStr;
  747. bizTestRecordDtlDto.PreconditionResult = "通过";
  748. StepIndex = 1;
  749. }
  750. else
  751. {
  752. return false;
  753. }
  754. break;
  755. case "AND":
  756. case "ONLY":
  757. case "OR":
  758. ReadPredice(SelectLogic);
  759. break;
  760. case "ORDER":
  761. break;
  762. }
  763. break;
  764. }
  765. return true;
  766. }
  767. private void ReadPredice(string strLogic)
  768. {
  769. int countCond = 0;
  770. foreach (var item in BeforeConList.OrderBy(x=>x.Id))
  771. {
  772. string plcAddress = item.PlcAddress;
  773. string plcAddType = item.PlcAddType;
  774. string plcValue = item.PlcValue;
  775. switch (plcAddType)
  776. {
  777. case "bool":
  778. string readResult = PLCConnectionFactory.CreatePLCCont().ReadPlcObject(plcAddress, VarType.Bit);
  779. ///实时值记录
  780. item.RealValue = readResult;
  781. item.TestTime = DateTime.Now;
  782. if (readResult.Trim() == plcValue?.Trim())
  783. {
  784. item.TestResult = "通过";
  785. countCond++;
  786. }
  787. else
  788. {
  789. item.TestResult = "不通过";
  790. }
  791. break;
  792. case "word":
  793. break;
  794. }
  795. }
  796. //测试记录存入数据库
  797. //前置项测试结果json转化
  798. string prefixJsonStr = ModelToJsonToStr(BeforeSelectJudge, SelectLogic, BeforeDetail, BeforeConList);
  799. //json字符串
  800. bizTestRecordDtlDto.PreconditionFinal = prefixJsonStr;
  801. //条件满足
  802. switch (strLogic)
  803. {
  804. case "AND":
  805. case "ONLY":
  806. if ((countCond == BeforeConList.Count) && (countCond != 0))
  807. {
  808. bizTestRecordDtlDto.PreconditionResult = "通过";
  809. }
  810. else
  811. {
  812. bizTestRecordDtlDto.PreconditionResult = "不通过";
  813. }
  814. break;
  815. case "OR":
  816. if ( (countCond != 0))
  817. {
  818. bizTestRecordDtlDto.PreconditionResult = "通过";
  819. }
  820. else
  821. {
  822. bizTestRecordDtlDto.PreconditionResult = "不通过";
  823. }
  824. break;
  825. }
  826. StepIndex = 1;
  827. }
  828. /// <summary>
  829. /// 输入项写入
  830. /// </summary>
  831. private bool TestActionMethod()
  832. {
  833. bool isActionResult = true;
  834. switch (SelectInJudge)
  835. {
  836. case "人工判定":
  837. //弹出确认的对话框
  838. MessageBoxResult boxResult = MessageBox.Show(InDetail, "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
  839. if (boxResult == MessageBoxResult.OK)
  840. {
  841. //前置项测试结果json转化
  842. string actionJsonStr = ModelToJsonToStr(SelectInJudge, InSelectLogic, InDetail, InConList);
  843. //json字符串
  844. bizTestRecordDtlDto.ActionFinal = actionJsonStr;
  845. bizTestRecordDtlDto.ActionResult = "通过";
  846. StepIndex = 2;
  847. }
  848. else
  849. {
  850. isActionResult= false;
  851. }
  852. break;
  853. case "自动判定":
  854. //读取plc的值
  855. switch (InSelectLogic)
  856. {
  857. case "NULL":
  858. //弹出确认的对话框
  859. MessageBoxResult boxResultAction = MessageBox.Show(InDetail, "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
  860. if (boxResultAction == MessageBoxResult.OK)
  861. {
  862. //前置项测试结果json转化
  863. string actionJsonStr = ModelToJsonToStr(SelectInJudge, InSelectLogic, InDetail, InConList);
  864. //json字符串
  865. bizTestRecordDtlDto.ActionFinal = actionJsonStr;
  866. bizTestRecordDtlDto.ActionResult = "通过";
  867. StepIndex = 2;
  868. }
  869. else
  870. {
  871. isActionResult = false;
  872. }
  873. break;
  874. case "AND":
  875. case "ONLY":
  876. case "OR":
  877. isActionResult =SendActionToPLC(InSelectLogic);
  878. break;
  879. case "ORDER":
  880. break;
  881. }
  882. break;
  883. }
  884. return isActionResult;
  885. }
  886. /// <summary>
  887. /// 发送命令给PLC
  888. /// </summary>
  889. private bool SendActionToPLC(string strActionLogic)
  890. {
  891. bool isAction = true;
  892. int countCond = 0;
  893. foreach (var item in InConList.OrderBy(x => x.Id))
  894. {
  895. string plcAddress = item.PlcAddress;
  896. string plcAddType = item.PlcAddType;
  897. string plcValue = item.PlcValue;
  898. switch (plcAddType)
  899. {
  900. case "bool":
  901. DialogParameters parm = new DialogParameters();
  902. parm.Add("Key", plcAddress);
  903. parm.Add("Key2", plcValue);
  904. //弹出写入对话框
  905. _dialog.ShowDialog("WritePLCView", parm, async callback =>
  906. {
  907. if (callback.Result == ButtonResult.OK)
  908. {
  909. string plcRealValue = callback.Parameters.GetValue<string>("ReturnValue");
  910. bool writeResult = PLCConnectionFactory.CreatePLCCont().WritePlcObject(plcAddress, VarType.Bit, plcRealValue);
  911. ///实时值记录
  912. item.RealValue = plcRealValue;
  913. item.TestTime = DateTime.Now;
  914. if (writeResult)
  915. {
  916. ///单个测试项通过
  917. item.TestResult = "通过";
  918. countCond++;
  919. }
  920. else
  921. {
  922. item.TestResult = "不通过";
  923. }
  924. }
  925. else
  926. {
  927. isAction= false;
  928. }
  929. });
  930. break;
  931. case "word":
  932. DialogParameters parm2 = new DialogParameters();
  933. parm2.Add("Key", plcAddress);
  934. parm2.Add("Key2", plcValue);
  935. //弹出写入对话框
  936. _dialog.ShowDialog("WritePLCView", parm2, async callback =>
  937. {
  938. if (callback.Result == ButtonResult.OK)
  939. {
  940. string plcRealValue = callback.Parameters.GetValue<string>("ReturnValue");
  941. bool writeResult = PLCConnectionFactory.CreatePLCCont().WritePlcObject(plcAddress, VarType.Word, plcRealValue);
  942. ///实时值记录
  943. item.RealValue = plcRealValue;
  944. item.TestTime = DateTime.Now;
  945. if (writeResult)
  946. {
  947. ///单个测试项通过
  948. item.TestResult = "通过";
  949. countCond++;
  950. }
  951. else
  952. {
  953. item.TestResult = "不通过";
  954. }
  955. }
  956. else
  957. {
  958. isAction = false;
  959. }
  960. });
  961. break;
  962. }
  963. }
  964. if(!isAction)
  965. {
  966. return isAction;
  967. }
  968. //测试记录存入数据库
  969. //前置项测试结果json转化
  970. string actionJsonStr = ModelToJsonToStr(SelectInJudge, InSelectLogic, InDetail, InConList);
  971. //json字符串
  972. bizTestRecordDtlDto.ActionFinal = actionJsonStr;
  973. //条件满足
  974. //条件满足
  975. switch (strActionLogic)
  976. {
  977. case "AND":
  978. case "ONLY":
  979. if ((countCond == BeforeConList.Count) && (countCond != 0))
  980. {
  981. bizTestRecordDtlDto.ActionResult = "通过";
  982. }
  983. else
  984. {
  985. bizTestRecordDtlDto.ActionResult = "不通过";
  986. }
  987. break;
  988. case "OR":
  989. if ((countCond != 0))
  990. {
  991. bizTestRecordDtlDto.ActionResult = "通过";
  992. }
  993. else
  994. {
  995. bizTestRecordDtlDto.ActionResult = "不通过";
  996. }
  997. break;
  998. }
  999. StepIndex = 2;
  1000. return isAction;
  1001. }
  1002. /// <summary>
  1003. /// 结果项判定
  1004. /// </summary>
  1005. private async Task<bool> TestJudgementMethod()
  1006. {
  1007. bool isJudge = true;
  1008. switch (SelectOutJudge)
  1009. {
  1010. case "人工判定":
  1011. //弹出确认的对话框
  1012. MessageBoxResult boxResult = MessageBox.Show(OutDetail, "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
  1013. if (boxResult == MessageBoxResult.OK)
  1014. {
  1015. bizTestRecordDtlDto.JudgementResult = "通过";
  1016. StepIndex = 3;
  1017. }
  1018. else
  1019. {
  1020. isJudge = false;
  1021. }
  1022. break;
  1023. case "自动判定":
  1024. //读取plc的值
  1025. switch (OutSelectLogic)
  1026. {
  1027. case "NULL":
  1028. bizTestRecordDtlDto.JudgementResult = "通过";
  1029. StepIndex = 3;
  1030. break;
  1031. case "AND":
  1032. case "ONLY":
  1033. case "OR":
  1034. await ReadJudge(OutSelectLogic);
  1035. break;
  1036. case "ORDER":
  1037. break;
  1038. }
  1039. break;
  1040. }
  1041. //更新测试记录
  1042. //更新测试记录
  1043. endTime = DateTime.Now;
  1044. return isJudge;
  1045. }
  1046. /// <summary>
  1047. /// 读取结果
  1048. /// </summary>
  1049. private async Task ReadJudge(String strLogic)
  1050. {
  1051. int countCond = 0;
  1052. DateTime entryTime = DateTime.Now;
  1053. foreach (var item in OutConList.OrderBy(x => x.Id))
  1054. {
  1055. string plcAddress = item.PlcAddress;
  1056. string plcAddType = item.PlcAddType;
  1057. string plcValue = item.PlcValue;
  1058. switch (plcAddType)
  1059. {
  1060. case "bool":
  1061. string readResult = string.Empty;
  1062. //一直读
  1063. await Task.Run(async () =>
  1064. {
  1065. while (entryTime.AddMilliseconds(delayTime * 1000) > DateTime.Now)
  1066. {
  1067. //显示进度条
  1068. System.Windows.Application.Current.Dispatcher.Invoke((delegate
  1069. {
  1070. ProVisibility = Visibility.Visible;
  1071. }));
  1072. //先延时,在读取,避免读取传感器刚开始的数据
  1073. await Task.Delay(1000);
  1074. readResult = PLCConnectionFactory.CreatePLCCont().ReadPlcObject(plcAddress, VarType.Bit);
  1075. if (readResult == item.PlcValue)
  1076. {
  1077. break;
  1078. }
  1079. }
  1080. });
  1081. //可能有多个条件判定的,第二次时间到了直接跳出延时,直接读取,不用在延时20s
  1082. readResult = PLCConnectionFactory.CreatePLCCont().ReadPlcObject(plcAddress, VarType.Bit);
  1083. ProVisibility = Visibility.Hidden;
  1084. ///实时值记录
  1085. item.RealValue = readResult;
  1086. item.TestTime = DateTime.Now;
  1087. if (readResult.Trim() == plcValue?.Trim())
  1088. {
  1089. item.TestResult = "通过";
  1090. countCond++;
  1091. }
  1092. else
  1093. {
  1094. item.TestResult = "不通过";
  1095. }
  1096. break;
  1097. case "word":
  1098. // DateTime entryTime2 = DateTime.Now;
  1099. string readResult2 = string.Empty;
  1100. //一直读
  1101. await Task.Run(async () =>
  1102. {
  1103. while (entryTime.AddMilliseconds(delayTime * 1000) > DateTime.Now)
  1104. {
  1105. //显示进度条
  1106. System.Windows.Application.Current.Dispatcher.Invoke((delegate
  1107. {
  1108. ProVisibility = Visibility.Visible;
  1109. }));
  1110. readResult2 = PLCConnectionFactory.CreatePLCCont().ReadPlcObject(plcAddress, VarType.Word);
  1111. if (readResult2 == item.PlcValue)
  1112. {
  1113. break;
  1114. }
  1115. await Task.Delay(1000);
  1116. }
  1117. });
  1118. //可能有多个条件判定的,第二次直接跳出延时,直接读取
  1119. readResult2 = PLCConnectionFactory.CreatePLCCont().ReadPlcObject(plcAddress, VarType.Word);
  1120. ProVisibility = Visibility.Hidden;
  1121. ///实时值记录
  1122. item.RealValue = readResult2;
  1123. item.TestTime = DateTime.Now;
  1124. if (readResult2.Trim() == plcValue?.Trim())
  1125. {
  1126. item.TestResult = "通过";
  1127. countCond++;
  1128. }
  1129. else
  1130. {
  1131. item.TestResult = "不通过";
  1132. }
  1133. break;
  1134. }
  1135. }
  1136. //测试记录存入数据库
  1137. //输出项测试结果json转化
  1138. string prefixJsonStr = ModelToJsonToStr(SelectOutJudge, OutSelectLogic, OutDetail, OutConList);
  1139. //json字符串
  1140. bizTestRecordDtlDto.JudgementResultFinal = prefixJsonStr;
  1141. //条件满足
  1142. switch(strLogic)
  1143. {
  1144. case "AND":
  1145. case "ONLY":
  1146. if ((countCond == OutConList.Count) && (countCond != 0))
  1147. {
  1148. bizTestRecordDtlDto.JudgementResult = "通过";
  1149. }
  1150. else
  1151. {
  1152. bizTestRecordDtlDto.JudgementResult = "不通过";
  1153. }
  1154. break;
  1155. case "OR":
  1156. if ( countCond != 0)
  1157. {
  1158. bizTestRecordDtlDto.JudgementResult = "通过";
  1159. }
  1160. else
  1161. {
  1162. bizTestRecordDtlDto.JudgementResult = "不通过";
  1163. }
  1164. break;
  1165. }
  1166. StepIndex = 3;
  1167. }
  1168. /// <summary>
  1169. /// 获取配置
  1170. /// </summary>
  1171. private void GetConfigOption()
  1172. {
  1173. var configList = _optionConfigService.QueryList();
  1174. _optionConfigs = _mapper.Map<List<OptionConfig>, List<OptionConfigDto>>(configList);
  1175. var tests = _optionConfigs.FindAll(x => x.TypeID == 1);
  1176. TestKinds = new List<string>();
  1177. foreach (var test in tests)
  1178. {
  1179. TestKinds.Add(test.ContentOption);
  1180. }
  1181. //测试项类型
  1182. var judges = _optionConfigs.FindAll(x => x.TypeID == 2);
  1183. foreach (var judge in judges)
  1184. {
  1185. BeforeJudgeKinds.Add(judge.ContentOption);
  1186. InJudgeKinds.Add(judge.ContentOption);
  1187. OutJudgeKinds.Add(judge.ContentOption);
  1188. }
  1189. //判定逻辑
  1190. var logics = _optionConfigs.FindAll(x => x.TypeID == 3);
  1191. foreach (var logic in logics)
  1192. {
  1193. JudgeLogicKinds.Add(logic.ContentOption);
  1194. InJudgeLogicKinds.Add(logic.ContentOption);
  1195. OutJudgeLogicKinds.Add(logic.ContentOption);
  1196. }
  1197. }
  1198. /// <summary>
  1199. /// 关闭按钮
  1200. /// </summary>
  1201. private void Close()
  1202. {
  1203. MessageBoxResult boxResult = MessageBox.Show("确认退出自动测试", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
  1204. if (boxResult == MessageBoxResult.OK)
  1205. {
  1206. RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
  1207. }
  1208. }
  1209. /// <summary>
  1210. /// mode转json
  1211. /// </summary>
  1212. /// <param name="itemType"></param>
  1213. /// <param name="itemLogical"></param>
  1214. /// <param name="description"></param>
  1215. /// <param name="conList"></param>
  1216. /// <returns></returns>
  1217. private string ModelToJsonToStr(string itemType, string itemLogical, string description, ObservableCollection<BasPlcItemConfigDto> conList)
  1218. {
  1219. JsonModel prefixJsonModel = new JsonModel();
  1220. prefixJsonModel.ItemType = itemType;
  1221. prefixJsonModel.ItemLogical = itemLogical;
  1222. prefixJsonModel.Description = description;
  1223. prefixJsonModel.DetailInfo = new List<DetailPLC>();
  1224. foreach (var item in conList)
  1225. {
  1226. DetailPLC plcItem = new DetailPLC();
  1227. plcItem.Id = item.Id;
  1228. plcItem.PlcItem = item.PlcItem;
  1229. plcItem.PlcAddress = item.PlcAddress;
  1230. plcItem.PlcAddType = item.PlcAddType;
  1231. plcItem.PlcValue = item.PlcValue;
  1232. plcItem.RealValue = item.RealValue;
  1233. plcItem.TestTime = item.TestTime;
  1234. plcItem.TestResult = item.TestResult;
  1235. plcItem.Remark = item.Remark;
  1236. prefixJsonModel.DetailInfo.Add(plcItem);
  1237. }
  1238. string prefixJsonStr = JsonConvert.SerializeObject(prefixJsonModel);
  1239. return prefixJsonStr;
  1240. }
  1241. #endregion
  1242. #region 命令绑定
  1243. public DelegateCommand CloseCommand { set; get; }
  1244. public DelegateCommand<object> StartCommand { set; get; }
  1245. public DelegateCommand<object> PreviousCommand { set; get; }
  1246. public DelegateCommand<object> NextCommand { set; get; }
  1247. public DelegateCommand<object> DoneCommand { set; get; }
  1248. public DelegateCommand ItemChangeCommand { set; get; }
  1249. public DelegateCommand ResetCommand { set; get; }
  1250. #endregion
  1251. #region 变量绑定
  1252. /// <summary>
  1253. /// 测试方案编码
  1254. /// </summary>
  1255. private string scheduleName;
  1256. public string ScheduleName
  1257. {
  1258. get { return scheduleName; }
  1259. set { scheduleName = value; RaisePropertyChanged(); }
  1260. }
  1261. /// <summary>
  1262. /// 设备名称
  1263. /// </summary>
  1264. private string deviceKindName;
  1265. public string DeviceKindName
  1266. {
  1267. get { return deviceKindName; }
  1268. set { deviceKindName = value; RaisePropertyChanged(); }
  1269. }
  1270. /// <summary>
  1271. /// 测试项名称
  1272. /// </summary>
  1273. private string testName;
  1274. public string TestName
  1275. {
  1276. get { return testName; }
  1277. set { testName = value; RaisePropertyChanged(); }
  1278. }
  1279. /// <summary>
  1280. /// 测试项类型
  1281. /// </summary>
  1282. private List<string> testKinds = new List<string>();
  1283. public List<string> TestKinds
  1284. {
  1285. get { return testKinds; }
  1286. set { testKinds = value; RaisePropertyChanged(); }
  1287. }
  1288. /// <summary>
  1289. ///
  1290. /// </summary>
  1291. private string selectTest;
  1292. public string SelectTest
  1293. {
  1294. get { return selectTest; }
  1295. set { selectTest = value; RaisePropertyChanged(); }
  1296. }
  1297. /// <summary>
  1298. /// 判定类型(前置项)
  1299. /// </summary>
  1300. private List<string> beforeJudgeKinds = new List<string>();
  1301. public List<string> BeforeJudgeKinds
  1302. {
  1303. get { return beforeJudgeKinds; }
  1304. set { beforeJudgeKinds = value; RaisePropertyChanged(); }
  1305. }
  1306. private string beforeSelectJudge;
  1307. public string BeforeSelectJudge
  1308. {
  1309. get { return beforeSelectJudge; }
  1310. set { beforeSelectJudge = value; RaisePropertyChanged(); }
  1311. }
  1312. /// <summary>
  1313. /// 逻辑判断
  1314. /// </summary>
  1315. private List<string> judgeLogicKinds = new List<string>();
  1316. public List<string> JudgeLogicKinds
  1317. {
  1318. get { return judgeLogicKinds; }
  1319. set { judgeLogicKinds = value; RaisePropertyChanged(); }
  1320. }
  1321. private string selectLogic;
  1322. public string SelectLogic
  1323. {
  1324. get { return selectLogic; }
  1325. set { selectLogic = value; RaisePropertyChanged(); }
  1326. }
  1327. private string beforeDetail;
  1328. public string BeforeDetail
  1329. {
  1330. get { return beforeDetail; }
  1331. set { beforeDetail = value; RaisePropertyChanged(); }
  1332. }
  1333. private ObservableCollection<BasPlcItemConfigDto> beforeConList;
  1334. public ObservableCollection<BasPlcItemConfigDto> BeforeConList
  1335. {
  1336. get { return beforeConList; }
  1337. set { beforeConList = value; RaisePropertyChanged(); }
  1338. }
  1339. /// <summary>
  1340. /// 判定类型(输入项)
  1341. /// </summary>
  1342. private List<string> inJudgeKinds = new List<string>();
  1343. public List<string> InJudgeKinds
  1344. {
  1345. get { return inJudgeKinds; }
  1346. set { inJudgeKinds = value; RaisePropertyChanged(); }
  1347. }
  1348. private string selectInJudge;
  1349. public string SelectInJudge
  1350. {
  1351. get { return selectInJudge; }
  1352. set { selectInJudge = value; RaisePropertyChanged(); }
  1353. }
  1354. /// <summary>
  1355. /// 逻辑判断
  1356. /// </summary>
  1357. private List<string> inJudgeLogicKinds = new List<string>();
  1358. public List<string> InJudgeLogicKinds
  1359. {
  1360. get { return inJudgeLogicKinds; }
  1361. set { inJudgeLogicKinds = value; RaisePropertyChanged(); }
  1362. }
  1363. private string inSelectLogic;
  1364. public string InSelectLogic
  1365. {
  1366. get { return inSelectLogic; }
  1367. set { inSelectLogic = value; RaisePropertyChanged(); }
  1368. }
  1369. private string inDetail;
  1370. public string InDetail
  1371. {
  1372. get { return inDetail; }
  1373. set { inDetail = value; RaisePropertyChanged(); }
  1374. }
  1375. private ObservableCollection<BasPlcItemConfigDto> inConList;
  1376. public ObservableCollection<BasPlcItemConfigDto> InConList
  1377. {
  1378. get { return inConList; }
  1379. set { inConList = value; RaisePropertyChanged(); }
  1380. }
  1381. /// <summary>
  1382. /// 判定类型(结果项)
  1383. /// </summary>
  1384. private List<string> outJudgeKinds = new List<string>();
  1385. public List<string> OutJudgeKinds
  1386. {
  1387. get { return outJudgeKinds; }
  1388. set { outJudgeKinds = value; RaisePropertyChanged(); }
  1389. }
  1390. private string selectOutJudge;
  1391. public string SelectOutJudge
  1392. {
  1393. get { return selectOutJudge; }
  1394. set { selectOutJudge = value; RaisePropertyChanged(); }
  1395. }
  1396. /// <summary>
  1397. /// 逻辑判断
  1398. /// </summary>
  1399. private List<string> outJudgeLogicKinds = new List<string>();
  1400. public List<string> OutJudgeLogicKinds
  1401. {
  1402. get { return outJudgeLogicKinds; }
  1403. set { outJudgeLogicKinds = value; RaisePropertyChanged(); }
  1404. }
  1405. private string outSelectLogic;
  1406. public string OutSelectLogic
  1407. {
  1408. get { return outSelectLogic; }
  1409. set { outSelectLogic = value; RaisePropertyChanged(); }
  1410. }
  1411. private string outDetail;
  1412. public string OutDetail
  1413. {
  1414. get { return outDetail; }
  1415. set { outDetail = value; RaisePropertyChanged(); }
  1416. }
  1417. private ObservableCollection<BasPlcItemConfigDto> outConList;
  1418. public ObservableCollection<BasPlcItemConfigDto> OutConList
  1419. {
  1420. get { return outConList; }
  1421. set { outConList = value; RaisePropertyChanged(); }
  1422. }
  1423. private int stepIndex = 0;
  1424. public int StepIndex
  1425. {
  1426. get { return stepIndex; }
  1427. set { stepIndex = value; RaisePropertyChanged(); }
  1428. }
  1429. private Visibility proVisibility =Visibility.Hidden;
  1430. public Visibility ProVisibility
  1431. {
  1432. get { return proVisibility; }
  1433. set { proVisibility = value; RaisePropertyChanged(); }
  1434. }
  1435. private bool startEnalbe = true;
  1436. public bool StartEnalbe
  1437. {
  1438. get { return startEnalbe; }
  1439. set { startEnalbe = value; RaisePropertyChanged(); }
  1440. }
  1441. //所有测试项列表
  1442. private List<string> schItems = new List<string>();
  1443. public List<string> SchItems
  1444. {
  1445. get { return schItems; }
  1446. set { schItems = value; RaisePropertyChanged(); }
  1447. }
  1448. //所选测试方案
  1449. private string selectItem;
  1450. public string SelectItem
  1451. {
  1452. get { return selectItem; }
  1453. set { selectItem = value; RaisePropertyChanged(); }
  1454. }
  1455. private int selectItemIndex;
  1456. public int SelectItemIndex
  1457. {
  1458. get { return selectItemIndex; }
  1459. set { selectItemIndex = value; RaisePropertyChanged(); }
  1460. }
  1461. #endregion
  1462. }
  1463. }