AutoTestViewModel.cs 58 KB

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