|
@@ -0,0 +1,1444 @@
|
|
|
+using AutoMapper;
|
|
|
+using BizService;
|
|
|
+using Microsoft.Extensions.Logging;
|
|
|
+using Model.Dto;
|
|
|
+using Model.Entities;
|
|
|
+using Newtonsoft.Json;
|
|
|
+using PLCTool.Common;
|
|
|
+using Prism.Commands;
|
|
|
+using Prism.Events;
|
|
|
+using Prism.Mvvm;
|
|
|
+using Prism.Services.Dialogs;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Collections.ObjectModel;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using System.Windows;
|
|
|
+
|
|
|
+namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
|
+{
|
|
|
+
|
|
|
+ public class RetryTestViewModel : BindableBase, IDialogAware
|
|
|
+ {
|
|
|
+ private readonly IDialogService _dialog;
|
|
|
+ private readonly IEventAggregator _aggregator;
|
|
|
+ private readonly IOptionConfigService _optionConfigService;
|
|
|
+ private readonly IBasicPlcTestSchemeService _basicPlcTestSchemeService;
|
|
|
+ private readonly IBasicPlcTestSchemeDtlService _basicPlcTestSchemeDtlService;
|
|
|
+ private readonly IBizTestRecordService _iBizTestRecordService;
|
|
|
+ private readonly IBizTestRecordDtlService _iBizTestRecordDtlService;
|
|
|
+ private readonly IMapper _mapper;
|
|
|
+ private readonly ILogger _logger;
|
|
|
+ private List<OptionConfigDto> _optionConfigs;
|
|
|
+
|
|
|
+ private DateTime startTime = DateTime.Now;
|
|
|
+ private DateTime endTime = DateTime.Now;
|
|
|
+ private int testStatus = 0; //测试状态
|
|
|
+ private int testResult = 0; //测试结果
|
|
|
+ private long schId = 0; //方案ID
|
|
|
+ private long globalSchDetailId = 0; //测试方案明细ID
|
|
|
+ private long globalDeviceId = 0; //设备ID
|
|
|
+ private BizTestRecordDtlDto bizTestRecordDtlDto = new BizTestRecordDtlDto(); //测试方案明细表
|
|
|
+ private const string TestMode = "重新测试";
|
|
|
+
|
|
|
+ private int delayTime = 20;
|
|
|
+ public RetryTestViewModel(IDialogService dialog, IEventAggregator aggregator, IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService, IBizTestRecordService iBizTestRecordService, IBizTestRecordDtlService iBizTestRecordDtlService, IMapper mapper, ILogger logger)
|
|
|
+ {
|
|
|
+ _dialog = dialog;
|
|
|
+ _aggregator = aggregator;
|
|
|
+ _optionConfigService = optionConfigService;
|
|
|
+ _basicPlcTestSchemeService = basicPlcTestSchemeService;
|
|
|
+ _basicPlcTestSchemeDtlService = basicPlcTestSchemeDtlService;
|
|
|
+ _iBizTestRecordDtlService = iBizTestRecordDtlService;
|
|
|
+ _iBizTestRecordService = iBizTestRecordService;
|
|
|
+ _mapper = mapper;
|
|
|
+ _logger = logger;
|
|
|
+ CloseCommand = new DelegateCommand(Close);
|
|
|
+ StartCommand = new DelegateCommand<object>(Start);
|
|
|
+ PreviousCommand = new DelegateCommand<object>(Previous);
|
|
|
+ NextCommand = new DelegateCommand<object>(Next);
|
|
|
+ DoneCommand = new DelegateCommand<object>(Done);
|
|
|
+ ItemChangeCommand = new DelegateCommand(ItemChange);
|
|
|
+ BeforeConList = new ObservableCollection<BasPlcItemConfigDto>();
|
|
|
+ InConList = new ObservableCollection<BasPlcItemConfigDto>();
|
|
|
+ OutConList = new ObservableCollection<BasPlcItemConfigDto>();
|
|
|
+ GetConfigOption();
|
|
|
+
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 选中测试项
|
|
|
+ /// </summary>
|
|
|
+ private void ItemChange()
|
|
|
+ {
|
|
|
+ var findDtlMsg = _basicPlcTestSchemeDtlService.FindAllBySchId(schId)?.FirstOrDefault(X => X.item_name == SelectItem);
|
|
|
+ if (findDtlMsg != null)
|
|
|
+ {
|
|
|
+ int id = Convert.ToInt32(findDtlMsg.scheme_dtl_id);
|
|
|
+ // 根据 测试方案明细主键ID 查找测试方案id 及方案名和设备名
|
|
|
+ globalSchDetailId = id;
|
|
|
+ GetDetailInfo(id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ #region idialog接口实现
|
|
|
+ public string Title { set; get; } = "手动测试";
|
|
|
+
|
|
|
+ public event Action<IDialogResult> RequestClose;
|
|
|
+
|
|
|
+ public bool CanCloseDialog()
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void OnDialogClosed()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void OnDialogOpened(IDialogParameters parameters)
|
|
|
+ {
|
|
|
+ //编辑
|
|
|
+ var getMsg = parameters.GetValues<long>("Key");
|
|
|
+ ///值不为空,表示修改
|
|
|
+ if (getMsg != null)
|
|
|
+ {
|
|
|
+ foreach (var item in getMsg)
|
|
|
+ {
|
|
|
+ //测试方案号
|
|
|
+ schId = item;
|
|
|
+ var schDtls = _basicPlcTestSchemeDtlService.FindAllBySchId(schId).OrderBy(x => x.scheme_dtl_id).ToList(); ;
|
|
|
+ //不合格项目集合
|
|
|
+ List<bas_plc_test_scheme_dtl> reTrysList = new List<bas_plc_test_scheme_dtl>();
|
|
|
+ //查找不合格项目
|
|
|
+ foreach (var sch in schDtls)
|
|
|
+ {
|
|
|
+
|
|
|
+ long dtlId = sch.scheme_dtl_id;
|
|
|
+ var dtlResult = _iBizTestRecordDtlService.FindRecordDetailBySchDtlID(dtlId)?.OrderByDescending(x => x.start_test_time)?.ToArray();
|
|
|
+ if((dtlResult!=null)&&(dtlResult.Length!=0))
|
|
|
+ {
|
|
|
+ //时间最新的结果 ,不通过
|
|
|
+ if (dtlResult[0].test_result==0)
|
|
|
+ {
|
|
|
+ SchItems.Add(sch.item_name);
|
|
|
+
|
|
|
+ reTrysList.Add(sch);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //默认显示第一个测试项的信息
|
|
|
+ if (reTrysList.Count != 0)
|
|
|
+ {
|
|
|
+ int id = Convert.ToInt32(reTrysList[0].scheme_dtl_id);
|
|
|
+ globalSchDetailId = id;
|
|
|
+ // 根据 测试方案明细主键ID 查找测试方案id 及方案名和设备名
|
|
|
+ GetDetailInfo(id);
|
|
|
+ SelectItemIndex = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //获取设备id
|
|
|
+ var getDes = parameters.GetValues<long>("Key2");
|
|
|
+ if (getDes != null)
|
|
|
+ {
|
|
|
+ foreach (var item in getDes)
|
|
|
+ {
|
|
|
+ globalDeviceId = item;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// //根据 测试方案明细主键ID 查找测试方案id 及方案名和设备名
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id"></param>
|
|
|
+ private void GetDetailInfo(int schDetailId)
|
|
|
+ {
|
|
|
+ //根据 测试方案明细主键ID 查找测试方案id 及方案名和设备名
|
|
|
+ var findEntity = _basicPlcTestSchemeDtlService.Find(schDetailId);
|
|
|
+ var findresult = _mapper.Map<bas_plc_test_scheme_dtl, BasicPlcTestSchemeDtlDto>(findEntity);
|
|
|
+ if (findresult != null)
|
|
|
+ {
|
|
|
+ //根据方案id 在方案表中查找方案名 设备名
|
|
|
+ schId = findresult.SchemeId.Value; //方案id,方便下一步查找
|
|
|
+ int intSchId = Convert.ToInt32(findresult.SchemeId);
|
|
|
+
|
|
|
+ var findSch = _basicPlcTestSchemeService.Find(intSchId);
|
|
|
+ if (findSch != null)
|
|
|
+ {
|
|
|
+ ScheduleName = findSch.scheme_name;
|
|
|
+ DeviceKindName = findSch.devicekind_name;
|
|
|
+
|
|
|
+ }
|
|
|
+ TestName = findresult.ItemName;
|
|
|
+ SelectTest = findresult.ItemType;
|
|
|
+ //前置项解析
|
|
|
+ string preconStr = findresult.Precondition.ToString();
|
|
|
+ if (!string.IsNullOrEmpty(preconStr))
|
|
|
+ {
|
|
|
+ JsonModel preconditionModel = JsonConvert.DeserializeObject<JsonModel>(preconStr);
|
|
|
+ BeforeSelectJudge = preconditionModel.ItemType;
|
|
|
+ SelectLogic = preconditionModel.ItemLogical;
|
|
|
+ BeforeDetail = preconditionModel.Description;
|
|
|
+ BeforeConList.Clear();
|
|
|
+ foreach (var detail in preconditionModel.DetailInfo)
|
|
|
+ {
|
|
|
+ BasPlcItemConfigDto basPlcItemConfigDto = new BasPlcItemConfigDto();
|
|
|
+ basPlcItemConfigDto.Id = detail.Id;
|
|
|
+ basPlcItemConfigDto.PlcItem = detail.PlcItem;
|
|
|
+ basPlcItemConfigDto.PlcAddress = detail.PlcAddress;
|
|
|
+ basPlcItemConfigDto.PlcAddType = detail.PlcAddType;
|
|
|
+ basPlcItemConfigDto.PlcValue = detail.PlcValue;
|
|
|
+ basPlcItemConfigDto.Remark = detail.Remark;
|
|
|
+ BeforeConList.Add(basPlcItemConfigDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //输入项解析
|
|
|
+ string inStr = findresult.Action.ToString();
|
|
|
+ if (!string.IsNullOrEmpty(inStr))
|
|
|
+ {
|
|
|
+ JsonModel inModel = JsonConvert.DeserializeObject<JsonModel>(inStr);
|
|
|
+ SelectInJudge = inModel.ItemType;
|
|
|
+ InSelectLogic = inModel.ItemLogical;
|
|
|
+ InDetail = inModel.Description;
|
|
|
+ InConList.Clear();
|
|
|
+ foreach (var detail in inModel.DetailInfo)
|
|
|
+ {
|
|
|
+ BasPlcItemConfigDto basPlcItemConfigDto = new BasPlcItemConfigDto();
|
|
|
+ basPlcItemConfigDto.Id = detail.Id;
|
|
|
+ basPlcItemConfigDto.PlcItem = detail.PlcItem;
|
|
|
+ basPlcItemConfigDto.PlcAddress = detail.PlcAddress;
|
|
|
+ basPlcItemConfigDto.PlcAddType = detail.PlcAddType;
|
|
|
+ basPlcItemConfigDto.PlcValue = detail.PlcValue;
|
|
|
+ basPlcItemConfigDto.Remark = detail.Remark;
|
|
|
+ InConList.Add(basPlcItemConfigDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //输出项解析
|
|
|
+ string outStr = findresult.JudgementResult.ToString();
|
|
|
+ if (!string.IsNullOrEmpty(outStr))
|
|
|
+ {
|
|
|
+ JsonModel outModel = JsonConvert.DeserializeObject<JsonModel>(outStr);
|
|
|
+ SelectOutJudge = outModel.ItemType;
|
|
|
+ OutSelectLogic = outModel.ItemLogical;
|
|
|
+ OutDetail = outModel.Description;
|
|
|
+ OutConList.Clear();
|
|
|
+ foreach (var detail in outModel.DetailInfo)
|
|
|
+ {
|
|
|
+ BasPlcItemConfigDto basPlcItemConfigDto = new BasPlcItemConfigDto();
|
|
|
+ basPlcItemConfigDto.Id = detail.Id;
|
|
|
+ basPlcItemConfigDto.PlcItem = detail.PlcItem;
|
|
|
+ basPlcItemConfigDto.PlcAddress = detail.PlcAddress;
|
|
|
+ basPlcItemConfigDto.PlcAddType = detail.PlcAddType;
|
|
|
+ basPlcItemConfigDto.PlcValue = detail.PlcValue;
|
|
|
+ basPlcItemConfigDto.Remark = detail.Remark;
|
|
|
+ OutConList.Add(basPlcItemConfigDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 私有发方法
|
|
|
+ /// <summary>
|
|
|
+ /// 增加或更新测试记录
|
|
|
+ /// </summary>
|
|
|
+ private void AddTestRecord()
|
|
|
+ {
|
|
|
+
|
|
|
+ //记录记录主表中是否有这个方案的记录,没有则添加
|
|
|
+ var findRecord = _iBizTestRecordService.FindRecorddByDeviceIdAndSchname(globalDeviceId, ScheduleName);
|
|
|
+ if (findRecord == null)
|
|
|
+ {
|
|
|
+ //状态status 没有赋值
|
|
|
+ BizTestRecordDto bizTestRecordDto = new BizTestRecordDto();
|
|
|
+ bizTestRecordDto.RecordName = ScheduleName + "_Record";
|
|
|
+ bizTestRecordDto.SchemeName = ScheduleName;
|
|
|
+ bizTestRecordDto.DeviceId = globalDeviceId;
|
|
|
+ bizTestRecordDto.Tester = Appsession.UserName;
|
|
|
+ bizTestRecordDto.StartTestTime = startTime;
|
|
|
+ bizTestRecordDto.FinishTestTime = endTime;
|
|
|
+ bizTestRecordDto.CreateBy = Appsession.UserName;
|
|
|
+ bizTestRecordDto.CreateTime = DateTime.Now;
|
|
|
+ bizTestRecordDto.UpdateBy = Appsession.UserName;
|
|
|
+ bizTestRecordDto.UpdateTime = DateTime.Now;
|
|
|
+ var testRecord = _mapper.Map<BizTestRecordDto, biz_test_record>(bizTestRecordDto);
|
|
|
+ _iBizTestRecordService.Add(testRecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 获取记录明细
|
|
|
+ /// </summary>
|
|
|
+ private void AddDtltRecord(long schDetailId)
|
|
|
+ {
|
|
|
+ //查找record ID
|
|
|
+ long recordId = 0;
|
|
|
+ var findRecordID = _iBizTestRecordService.FindRecorddByDeviceIdAndSchname(globalDeviceId, ScheduleName);
|
|
|
+ if (findRecordID != null)
|
|
|
+ {
|
|
|
+ recordId = findRecordID.record_id;
|
|
|
+ }
|
|
|
+ testStatus = 99;//测试状态赋值为99
|
|
|
+ //状态status 没有赋值
|
|
|
+
|
|
|
+ bizTestRecordDtlDto.RecordId = recordId;
|
|
|
+ bizTestRecordDtlDto.SchemeDtlId = schDetailId;
|
|
|
+ bizTestRecordDtlDto.StartTestTime = startTime;
|
|
|
+ bizTestRecordDtlDto.FinishTestTime = endTime;
|
|
|
+ bizTestRecordDtlDto.TestMode = TestMode;
|
|
|
+ bizTestRecordDtlDto.Status = testStatus;
|
|
|
+ bizTestRecordDtlDto.TestResult = GetTestResult();
|
|
|
+ bizTestRecordDtlDto.CreateBy = Appsession.UserName;
|
|
|
+ bizTestRecordDtlDto.CreateTime = startTime;
|
|
|
+ bizTestRecordDtlDto.UpdateBy = Appsession.UserName;
|
|
|
+ bizTestRecordDtlDto.UpdateTime = DateTime.Now;
|
|
|
+ //更新时间
|
|
|
+ bizTestRecordDtlDto.UpdateBy = Appsession.UserName;
|
|
|
+ bizTestRecordDtlDto.UpdateTime = DateTime.Now;
|
|
|
+
|
|
|
+ var testRecordDtl = _mapper.Map<BizTestRecordDtlDto, biz_test_record_dtl>(bizTestRecordDtlDto);
|
|
|
+ _iBizTestRecordDtlService.Add(testRecordDtl);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 判定结果
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ private int GetTestResult()
|
|
|
+ {
|
|
|
+ //前置项
|
|
|
+ int beforeResult = 0;
|
|
|
+ int inResult = 0;
|
|
|
+ int outResult = 0;
|
|
|
+ if (BeforeConList.Count == 0)
|
|
|
+ {
|
|
|
+ beforeResult = 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (SelectLogic == "OR")
|
|
|
+ {
|
|
|
+ var find = BeforeConList.FirstOrDefault(x => x.TestResult == "通过");
|
|
|
+ if (find != null)
|
|
|
+ {
|
|
|
+ beforeResult = 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ beforeResult = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (SelectLogic == "AND" || SelectLogic == "ONLY")
|
|
|
+ {
|
|
|
+ var find = BeforeConList.FirstOrDefault(x => x.TestResult == "不通过");
|
|
|
+ if (find != null)
|
|
|
+ {
|
|
|
+ beforeResult = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (SelectLogic == "NULL")
|
|
|
+ {
|
|
|
+
|
|
|
+ beforeResult = 1;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //输入项
|
|
|
+ if (InConList.Count == 0)
|
|
|
+ {
|
|
|
+ inResult = 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (InSelectLogic == "OR")
|
|
|
+ {
|
|
|
+ var find = InConList.FirstOrDefault(x => x.TestResult == "通过");
|
|
|
+ if (find != null)
|
|
|
+ {
|
|
|
+ inResult = 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ inResult = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (InSelectLogic == "AND" || InSelectLogic == "ONLY")
|
|
|
+ {
|
|
|
+ var find = InConList.FirstOrDefault(x => x.TestResult == "不通过");
|
|
|
+ if (find != null)
|
|
|
+ {
|
|
|
+ inResult = 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ inResult = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (InSelectLogic == "NULL")
|
|
|
+ {
|
|
|
+
|
|
|
+ inResult = 1;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //输出项
|
|
|
+ if (OutConList.Count == 0)
|
|
|
+ {
|
|
|
+ outResult = 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (OutSelectLogic == "OR")
|
|
|
+ {
|
|
|
+ var find = OutConList.FirstOrDefault(x => x.TestResult == "通过");
|
|
|
+ if (find != null)
|
|
|
+ {
|
|
|
+ outResult = 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ outResult = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (OutSelectLogic == "AND" || OutSelectLogic == "ONLY")
|
|
|
+ {
|
|
|
+ var find = OutConList.FirstOrDefault(x => x.TestResult == "不通过");
|
|
|
+ if (find != null)
|
|
|
+ {
|
|
|
+ outResult = 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ outResult = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (OutSelectLogic == "NULL")
|
|
|
+ {
|
|
|
+
|
|
|
+ outResult = 1;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (beforeResult == 1 && inResult == 1 && outResult == 1)
|
|
|
+ {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 更新测试记录
|
|
|
+ /// </summary>
|
|
|
+ private void UpdateTesDtltRecord()
|
|
|
+ {
|
|
|
+
|
|
|
+ var testRecordDtl = _mapper.Map<BizTestRecordDtlDto, biz_test_record_dtl>(bizTestRecordDtlDto);
|
|
|
+ _iBizTestRecordDtlService.Edit(testRecordDtl);
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 完成时间
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="obj"></param>
|
|
|
+ private void Done(object obj)
|
|
|
+ {
|
|
|
+ endTime = DateTime.Now;
|
|
|
+ RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Next(object obj)
|
|
|
+ {
|
|
|
+ StepIndex = 0;
|
|
|
+ ///查找方案下的所有方案明细,并排序,
|
|
|
+ var basicSchDtls = _basicPlcTestSchemeDtlService.FindAllBySchId(schId)?.OrderBy(x => x.scheme_dtl_id);
|
|
|
+ foreach (var item in basicSchDtls)
|
|
|
+ {
|
|
|
+ //在测试结果明细中查看
|
|
|
+ long schDetailId = item.scheme_dtl_id;
|
|
|
+ if (schDetailId > globalSchDetailId)
|
|
|
+ {
|
|
|
+ globalSchDetailId = schDetailId;
|
|
|
+ int id = Convert.ToInt32(schDetailId);
|
|
|
+ SelectItemIndex++;
|
|
|
+ //界面显示
|
|
|
+ GetDetailInfo(id);
|
|
|
+ //记录记录明细表中是否有这个方案明细ID的记录,没有则添加,有则更新记录状态
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ long maxDtlId = basicSchDtls.Select(x => x.scheme_dtl_id).Max();
|
|
|
+ if (globalSchDetailId == maxDtlId)
|
|
|
+ {
|
|
|
+ MessageBox.Show("已是此测试方案最后一个测试项!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Previous(object obj)
|
|
|
+ {
|
|
|
+ StepIndex = 0;
|
|
|
+ ///查找方案下的所有方案明细,并排序,
|
|
|
+ var basicSchDtls = _basicPlcTestSchemeDtlService.FindAllBySchId(schId)?.OrderByDescending(x => x.scheme_dtl_id);
|
|
|
+ foreach (var item in basicSchDtls)
|
|
|
+ {
|
|
|
+ //在测试结果明细中查看
|
|
|
+ long schDetailId = item.scheme_dtl_id;
|
|
|
+ if (schDetailId < globalSchDetailId)
|
|
|
+ {
|
|
|
+ globalSchDetailId = schDetailId;
|
|
|
+ int id = Convert.ToInt32(schDetailId);
|
|
|
+ SelectItemIndex--;
|
|
|
+ //界面显示
|
|
|
+ GetDetailInfo(id);
|
|
|
+ //记录记录明细表中是否有这个方案明细ID的记录,没有则添加,有则更新记录状态
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ long maxDtlId = basicSchDtls.Select(x => x.scheme_dtl_id).Min();
|
|
|
+ if (globalSchDetailId == maxDtlId)
|
|
|
+ {
|
|
|
+ SelectItemIndex = 0;
|
|
|
+ MessageBox.Show("已是此测试方案的第一个测试项!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 开始检测
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="obj"></param>
|
|
|
+ private async void Start(object obj)
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ StartEnalbe = false;
|
|
|
+ _logger.LogInformation($"开始手动测试。方案名{ScheduleName},测试项{TestName}");
|
|
|
+ //开始时间
|
|
|
+ startTime = DateTime.Now;
|
|
|
+ //增加测试记录主表
|
|
|
+ AddTestRecord();
|
|
|
+
|
|
|
+ //前置项
|
|
|
+ bool preBool = TestPreceditionMethod();
|
|
|
+ if (!preBool)
|
|
|
+ {
|
|
|
+ StepIndex = 0;
|
|
|
+ StartEnalbe = true;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //输入项
|
|
|
+ bool isAction = TestActionMethod();
|
|
|
+ if (!isAction)
|
|
|
+ {
|
|
|
+ StepIndex = 0;
|
|
|
+ StartEnalbe = true;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //输出项
|
|
|
+ bool isJudgeResult = await TestJudgementMethod();
|
|
|
+ if (!isJudgeResult)
|
|
|
+ {
|
|
|
+ StepIndex = 0;
|
|
|
+ StartEnalbe = true;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //将测试结果添加到数据库
|
|
|
+
|
|
|
+ AddDtltRecord(globalSchDetailId);
|
|
|
+
|
|
|
+ _logger.LogInformation($"手动测试完成。方案名{ScheduleName},测试项{TestName}");
|
|
|
+ StartEnalbe = true;
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 更新测试结果
|
|
|
+ /// </summary>
|
|
|
+ private void UpdateTestRecord()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 测试前置项目
|
|
|
+ /// </summary>
|
|
|
+ private bool TestPreceditionMethod()
|
|
|
+ {
|
|
|
+ switch (BeforeSelectJudge)
|
|
|
+ {
|
|
|
+ case "人工判定":
|
|
|
+ //弹出确认的对话框
|
|
|
+ if (string.IsNullOrEmpty(BeforeDetail))
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ MessageBoxResult boxResult = MessageBox.Show(BeforeDetail, "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
|
|
|
+ if (boxResult == MessageBoxResult.OK)
|
|
|
+ {
|
|
|
+ //前置项测试结果json转化
|
|
|
+ string prefixJsonStr = ModelToJsonToStr(BeforeSelectJudge, SelectLogic, BeforeDetail, BeforeConList);
|
|
|
+ //json字符串
|
|
|
+ bizTestRecordDtlDto.PreconditionFinal = prefixJsonStr;
|
|
|
+ bizTestRecordDtlDto.PreconditionResult = "通过";
|
|
|
+ StepIndex = 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ case "自动判定":
|
|
|
+ //读取plc的值
|
|
|
+ switch (SelectLogic)
|
|
|
+ {
|
|
|
+ case "NULL":
|
|
|
+ //弹出确认的对话框
|
|
|
+ if (string.IsNullOrEmpty(BeforeDetail))
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ MessageBoxResult boxResultAuto = MessageBox.Show(BeforeDetail, "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
|
|
|
+ if (boxResultAuto == MessageBoxResult.OK)
|
|
|
+ {
|
|
|
+ //前置项测试结果json转化
|
|
|
+ string prefixJsonStr = ModelToJsonToStr(BeforeSelectJudge, SelectLogic, BeforeDetail, BeforeConList);
|
|
|
+ //json字符串
|
|
|
+ bizTestRecordDtlDto.PreconditionFinal = prefixJsonStr;
|
|
|
+ bizTestRecordDtlDto.PreconditionResult = "通过";
|
|
|
+ StepIndex = 1;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "AND":
|
|
|
+ case "ONLY":
|
|
|
+ case "OR":
|
|
|
+ ReadPredice(SelectLogic);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "ORDER":
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ReadPredice(string strLogic)
|
|
|
+ {
|
|
|
+ int countCond = 0;
|
|
|
+ foreach (var item in BeforeConList.OrderBy(x => x.Id))
|
|
|
+ {
|
|
|
+ string plcAddress = item.PlcAddress;
|
|
|
+ string plcAddType = item.PlcAddType;
|
|
|
+ string plcValue = item.PlcValue;
|
|
|
+
|
|
|
+ switch (plcAddType)
|
|
|
+ {
|
|
|
+ case "bool":
|
|
|
+ string readResult = PLCCom.GetInstance().ReadPlcObject(plcAddress, VarType.Bit);
|
|
|
+ ///实时值记录
|
|
|
+
|
|
|
+ item.RealValue = readResult;
|
|
|
+ item.TestTime = DateTime.Now;
|
|
|
+ if (readResult.Trim() == plcValue?.Trim())
|
|
|
+ {
|
|
|
+ item.TestResult = "通过";
|
|
|
+ countCond++;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ item.TestResult = "不通过";
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "word":
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //测试记录存入数据库
|
|
|
+ //前置项测试结果json转化
|
|
|
+ string prefixJsonStr = ModelToJsonToStr(BeforeSelectJudge, SelectLogic, BeforeDetail, BeforeConList);
|
|
|
+ //json字符串
|
|
|
+ bizTestRecordDtlDto.PreconditionFinal = prefixJsonStr;
|
|
|
+ //条件满足
|
|
|
+ switch (strLogic)
|
|
|
+ {
|
|
|
+ case "AND":
|
|
|
+ case "ONLY":
|
|
|
+ if ((countCond == BeforeConList.Count) && (countCond != 0))
|
|
|
+ {
|
|
|
+ bizTestRecordDtlDto.PreconditionResult = "通过";
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ bizTestRecordDtlDto.PreconditionResult = "不通过";
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "OR":
|
|
|
+ if ((countCond != 0))
|
|
|
+ {
|
|
|
+ bizTestRecordDtlDto.PreconditionResult = "通过";
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ bizTestRecordDtlDto.PreconditionResult = "不通过";
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ StepIndex = 1;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 输入项写入
|
|
|
+ /// </summary>
|
|
|
+ private bool TestActionMethod()
|
|
|
+ {
|
|
|
+ bool isActionResult = true;
|
|
|
+ switch (SelectInJudge)
|
|
|
+ {
|
|
|
+ case "人工判定":
|
|
|
+ //弹出确认的对话框
|
|
|
+ MessageBoxResult boxResult = MessageBox.Show(InDetail, "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
|
|
|
+ if (boxResult == MessageBoxResult.OK)
|
|
|
+ {
|
|
|
+ //前置项测试结果json转化
|
|
|
+ string actionJsonStr = ModelToJsonToStr(SelectInJudge, InSelectLogic, InDetail, InConList);
|
|
|
+ //json字符串
|
|
|
+ bizTestRecordDtlDto.ActionFinal = actionJsonStr;
|
|
|
+ bizTestRecordDtlDto.ActionResult = "通过";
|
|
|
+ StepIndex = 2;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ isActionResult = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ case "自动判定":
|
|
|
+ //读取plc的值
|
|
|
+ switch (InSelectLogic)
|
|
|
+ {
|
|
|
+ case "NULL":
|
|
|
+ //弹出确认的对话框
|
|
|
+ MessageBoxResult boxResultAction = MessageBox.Show(InDetail, "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
|
|
|
+ if (boxResultAction == MessageBoxResult.OK)
|
|
|
+ {
|
|
|
+ //前置项测试结果json转化
|
|
|
+ string actionJsonStr = ModelToJsonToStr(SelectInJudge, InSelectLogic, InDetail, InConList);
|
|
|
+ //json字符串
|
|
|
+ bizTestRecordDtlDto.ActionFinal = actionJsonStr;
|
|
|
+ bizTestRecordDtlDto.ActionResult = "通过";
|
|
|
+ StepIndex = 2;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ isActionResult = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ case "AND":
|
|
|
+ case "ONLY":
|
|
|
+ case "OR":
|
|
|
+ isActionResult = SendActionToPLC(InSelectLogic);
|
|
|
+ break;
|
|
|
+
|
|
|
+ case "ORDER":
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return isActionResult;
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 发送命令给PLC
|
|
|
+ /// </summary>
|
|
|
+ private bool SendActionToPLC(string strActionLogic)
|
|
|
+ {
|
|
|
+ bool isAction = true;
|
|
|
+ int countCond = 0;
|
|
|
+ foreach (var item in InConList.OrderBy(x => x.Id))
|
|
|
+ {
|
|
|
+ string plcAddress = item.PlcAddress;
|
|
|
+ string plcAddType = item.PlcAddType;
|
|
|
+ string plcValue = item.PlcValue;
|
|
|
+
|
|
|
+ switch (plcAddType)
|
|
|
+ {
|
|
|
+ case "bool":
|
|
|
+
|
|
|
+ DialogParameters parm = new DialogParameters();
|
|
|
+ parm.Add("Key", plcAddress);
|
|
|
+ parm.Add("Key2", plcValue);
|
|
|
+ //弹出写入对话框
|
|
|
+ _dialog.ShowDialog("WritePLCView", parm, async callback =>
|
|
|
+ {
|
|
|
+ if (callback.Result == ButtonResult.OK)
|
|
|
+ {
|
|
|
+ string plcRealValue = callback.Parameters.GetValue<string>("ReturnValue");
|
|
|
+ bool writeResult = PLCCom.GetInstance().WritePlcObject(plcAddress, VarType.Bit, plcRealValue);
|
|
|
+ ///实时值记录
|
|
|
+ item.RealValue = plcRealValue;
|
|
|
+ item.TestTime = DateTime.Now;
|
|
|
+ if (writeResult)
|
|
|
+ {
|
|
|
+ ///单个测试项通过
|
|
|
+ item.TestResult = "通过";
|
|
|
+ countCond++;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ item.TestResult = "不通过";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ isAction = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ case "word":
|
|
|
+ DialogParameters parm2 = new DialogParameters();
|
|
|
+ parm2.Add("Key", plcAddress);
|
|
|
+ parm2.Add("Key2", plcValue);
|
|
|
+ //弹出写入对话框
|
|
|
+ _dialog.ShowDialog("WritePLCView", parm2, async callback =>
|
|
|
+ {
|
|
|
+ if (callback.Result == ButtonResult.OK)
|
|
|
+ {
|
|
|
+ string plcRealValue = callback.Parameters.GetValue<string>("ReturnValue");
|
|
|
+ bool writeResult = PLCCom.GetInstance().WritePlcObject(plcAddress, VarType.Word, plcRealValue);
|
|
|
+ ///实时值记录
|
|
|
+ item.RealValue = plcRealValue;
|
|
|
+ item.TestTime = DateTime.Now;
|
|
|
+ if (writeResult)
|
|
|
+ {
|
|
|
+ ///单个测试项通过
|
|
|
+ item.TestResult = "通过";
|
|
|
+ countCond++;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ item.TestResult = "不通过";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ isAction = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if (!isAction)
|
|
|
+ {
|
|
|
+ return isAction;
|
|
|
+ }
|
|
|
+ //测试记录存入数据库
|
|
|
+ //前置项测试结果json转化
|
|
|
+ string actionJsonStr = ModelToJsonToStr(SelectInJudge, InSelectLogic, InDetail, InConList);
|
|
|
+ //json字符串
|
|
|
+ bizTestRecordDtlDto.ActionFinal = actionJsonStr;
|
|
|
+ //条件满足
|
|
|
+
|
|
|
+ //条件满足
|
|
|
+ switch (strActionLogic)
|
|
|
+ {
|
|
|
+ case "AND":
|
|
|
+ case "ONLY":
|
|
|
+ if ((countCond == BeforeConList.Count) && (countCond != 0))
|
|
|
+ {
|
|
|
+ bizTestRecordDtlDto.ActionResult = "通过";
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ bizTestRecordDtlDto.ActionResult = "不通过";
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "OR":
|
|
|
+ if ((countCond != 0))
|
|
|
+ {
|
|
|
+ bizTestRecordDtlDto.ActionResult = "通过";
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ bizTestRecordDtlDto.ActionResult = "不通过";
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ StepIndex = 2;
|
|
|
+ return isAction;
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 结果项判定
|
|
|
+ /// </summary>
|
|
|
+ private async Task<bool> TestJudgementMethod()
|
|
|
+ {
|
|
|
+ bool isJudge = true;
|
|
|
+ switch (SelectOutJudge)
|
|
|
+ {
|
|
|
+ case "人工判定":
|
|
|
+ //弹出确认的对话框
|
|
|
+ MessageBoxResult boxResult = MessageBox.Show(OutDetail, "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
|
|
|
+ if (boxResult == MessageBoxResult.OK)
|
|
|
+ {
|
|
|
+ bizTestRecordDtlDto.JudgementResult = "通过";
|
|
|
+ StepIndex = 3;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ isJudge = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ case "自动判定":
|
|
|
+ //读取plc的值
|
|
|
+ switch (OutSelectLogic)
|
|
|
+ {
|
|
|
+ case "NULL":
|
|
|
+ bizTestRecordDtlDto.JudgementResult = "通过";
|
|
|
+ StepIndex = 3;
|
|
|
+ break;
|
|
|
+ case "AND":
|
|
|
+ case "ONLY":
|
|
|
+ case "OR":
|
|
|
+ await ReadJudge(OutSelectLogic);
|
|
|
+ break;
|
|
|
+ case "ORDER":
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ //更新测试记录
|
|
|
+ //更新测试记录
|
|
|
+ endTime = DateTime.Now;
|
|
|
+
|
|
|
+ return isJudge;
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 读取结果
|
|
|
+ /// </summary>
|
|
|
+ private async Task ReadJudge(String strLogic)
|
|
|
+ {
|
|
|
+ int countCond = 0;
|
|
|
+ DateTime entryTime = DateTime.Now;
|
|
|
+ foreach (var item in OutConList.OrderBy(x => x.Id))
|
|
|
+ {
|
|
|
+ string plcAddress = item.PlcAddress;
|
|
|
+ string plcAddType = item.PlcAddType;
|
|
|
+ string plcValue = item.PlcValue;
|
|
|
+
|
|
|
+ switch (plcAddType)
|
|
|
+ {
|
|
|
+
|
|
|
+ case "bool":
|
|
|
+
|
|
|
+ string readResult = string.Empty;
|
|
|
+ //一直读
|
|
|
+ await Task.Run(async () =>
|
|
|
+ {
|
|
|
+ while (entryTime.AddMilliseconds(delayTime * 1000) > DateTime.Now)
|
|
|
+ {
|
|
|
+ //显示进度条
|
|
|
+ System.Windows.Application.Current.Dispatcher.Invoke((delegate
|
|
|
+ {
|
|
|
+ ProVisibility = Visibility.Visible;
|
|
|
+ }));
|
|
|
+
|
|
|
+ readResult = PLCCom.GetInstance().ReadPlcObject(plcAddress, VarType.Bit);
|
|
|
+ if (readResult == item.PlcValue)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ await Task.Delay(1000);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //可能有多个条件判定的,第二次时间到了直接跳出延时,直接读取,不用在延时20s
|
|
|
+ readResult = PLCCom.GetInstance().ReadPlcObject(plcAddress, VarType.Bit);
|
|
|
+ ProVisibility = Visibility.Hidden;
|
|
|
+ ///实时值记录
|
|
|
+ item.RealValue = readResult;
|
|
|
+ item.TestTime = DateTime.Now;
|
|
|
+ if (readResult.Trim() == plcValue?.Trim())
|
|
|
+ {
|
|
|
+ item.TestResult = "通过";
|
|
|
+ countCond++;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ item.TestResult = "不通过";
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ case "word":
|
|
|
+ // DateTime entryTime2 = DateTime.Now;
|
|
|
+ string readResult2 = string.Empty;
|
|
|
+ //一直读
|
|
|
+ await Task.Run(async () =>
|
|
|
+ {
|
|
|
+ while (entryTime.AddMilliseconds(delayTime * 1000) > DateTime.Now)
|
|
|
+ {
|
|
|
+ //显示进度条
|
|
|
+ System.Windows.Application.Current.Dispatcher.Invoke((delegate
|
|
|
+ {
|
|
|
+ ProVisibility = Visibility.Visible;
|
|
|
+ }));
|
|
|
+
|
|
|
+ readResult2 = PLCCom.GetInstance().ReadPlcObject(plcAddress, VarType.Word);
|
|
|
+ if (readResult2 == item.PlcValue)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ await Task.Delay(1000);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //可能有多个条件判定的,第二次直接跳出延时,直接读取
|
|
|
+ readResult2 = PLCCom.GetInstance().ReadPlcObject(plcAddress, VarType.Word);
|
|
|
+ ProVisibility = Visibility.Hidden;
|
|
|
+ ///实时值记录
|
|
|
+ item.RealValue = readResult2;
|
|
|
+ item.TestTime = DateTime.Now;
|
|
|
+ if (readResult2.Trim() == plcValue?.Trim())
|
|
|
+ {
|
|
|
+ item.TestResult = "通过";
|
|
|
+ countCond++;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ item.TestResult = "不通过";
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //测试记录存入数据库
|
|
|
+ //输出项测试结果json转化
|
|
|
+ string prefixJsonStr = ModelToJsonToStr(SelectOutJudge, OutSelectLogic, OutDetail, OutConList);
|
|
|
+ //json字符串
|
|
|
+ bizTestRecordDtlDto.JudgementResultFinal = prefixJsonStr;
|
|
|
+ //条件满足
|
|
|
+ switch (strLogic)
|
|
|
+ {
|
|
|
+ case "AND":
|
|
|
+ case "ONLY":
|
|
|
+ if ((countCond == OutConList.Count) && (countCond != 0))
|
|
|
+ {
|
|
|
+ bizTestRecordDtlDto.JudgementResult = "通过";
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ bizTestRecordDtlDto.JudgementResult = "不通过";
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "OR":
|
|
|
+ if (countCond != 0)
|
|
|
+ {
|
|
|
+ bizTestRecordDtlDto.JudgementResult = "通过";
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ bizTestRecordDtlDto.JudgementResult = "不通过";
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ StepIndex = 3;
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 获取配置
|
|
|
+ /// </summary>
|
|
|
+ private void GetConfigOption()
|
|
|
+ {
|
|
|
+ var configList = _optionConfigService.QueryList();
|
|
|
+ _optionConfigs = _mapper.Map<List<OptionConfig>, List<OptionConfigDto>>(configList);
|
|
|
+ var tests = _optionConfigs.FindAll(x => x.TypeID == 1);
|
|
|
+ TestKinds = new List<string>();
|
|
|
+ foreach (var test in tests)
|
|
|
+ {
|
|
|
+ TestKinds.Add(test.ContentOption);
|
|
|
+ }
|
|
|
+
|
|
|
+ //测试项类型
|
|
|
+ var judges = _optionConfigs.FindAll(x => x.TypeID == 2);
|
|
|
+ foreach (var judge in judges)
|
|
|
+ {
|
|
|
+ BeforeJudgeKinds.Add(judge.ContentOption);
|
|
|
+ InJudgeKinds.Add(judge.ContentOption);
|
|
|
+ OutJudgeKinds.Add(judge.ContentOption);
|
|
|
+ }
|
|
|
+
|
|
|
+ //判定逻辑
|
|
|
+ var logics = _optionConfigs.FindAll(x => x.TypeID == 3);
|
|
|
+ foreach (var logic in logics)
|
|
|
+ {
|
|
|
+ JudgeLogicKinds.Add(logic.ContentOption);
|
|
|
+ InJudgeLogicKinds.Add(logic.ContentOption);
|
|
|
+ OutJudgeLogicKinds.Add(logic.ContentOption);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 关闭按钮
|
|
|
+ /// </summary>
|
|
|
+ private void Close()
|
|
|
+ {
|
|
|
+ MessageBoxResult boxResult = MessageBox.Show("确认退出自动测试", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
|
|
|
+ if (boxResult == MessageBoxResult.OK)
|
|
|
+ {
|
|
|
+
|
|
|
+ RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// mode转json
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="itemType"></param>
|
|
|
+ /// <param name="itemLogical"></param>
|
|
|
+ /// <param name="description"></param>
|
|
|
+ /// <param name="conList"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+
|
|
|
+ private string ModelToJsonToStr(string itemType, string itemLogical, string description, ObservableCollection<BasPlcItemConfigDto> conList)
|
|
|
+ {
|
|
|
+ JsonModel prefixJsonModel = new JsonModel();
|
|
|
+ prefixJsonModel.ItemType = itemType;
|
|
|
+ prefixJsonModel.ItemLogical = itemLogical;
|
|
|
+ prefixJsonModel.Description = description;
|
|
|
+ prefixJsonModel.DetailInfo = new List<DetailPLC>();
|
|
|
+ foreach (var item in conList)
|
|
|
+ {
|
|
|
+ DetailPLC plcItem = new DetailPLC();
|
|
|
+ plcItem.Id = item.Id;
|
|
|
+ plcItem.PlcItem = item.PlcItem;
|
|
|
+ plcItem.PlcAddress = item.PlcAddress;
|
|
|
+ plcItem.PlcAddType = item.PlcAddType;
|
|
|
+ plcItem.PlcValue = item.PlcValue;
|
|
|
+ plcItem.RealValue = item.RealValue;
|
|
|
+ plcItem.TestTime = item.TestTime;
|
|
|
+ plcItem.TestResult = item.TestResult;
|
|
|
+ plcItem.Remark = item.Remark;
|
|
|
+ prefixJsonModel.DetailInfo.Add(plcItem);
|
|
|
+
|
|
|
+ }
|
|
|
+ string prefixJsonStr = JsonConvert.SerializeObject(prefixJsonModel);
|
|
|
+ return prefixJsonStr;
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+
|
|
|
+ #region 命令绑定
|
|
|
+ public DelegateCommand CloseCommand { set; get; }
|
|
|
+
|
|
|
+ public DelegateCommand<object> StartCommand { set; get; }
|
|
|
+ public DelegateCommand<object> PreviousCommand { set; get; }
|
|
|
+
|
|
|
+ public DelegateCommand<object> NextCommand { set; get; }
|
|
|
+
|
|
|
+ public DelegateCommand<object> DoneCommand { set; get; }
|
|
|
+ public DelegateCommand ItemChangeCommand { set; get; }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+ #region 变量绑定
|
|
|
+ /// <summary>
|
|
|
+ /// 测试方案编码
|
|
|
+ /// </summary>
|
|
|
+ private string scheduleName;
|
|
|
+ public string ScheduleName
|
|
|
+ {
|
|
|
+ get { return scheduleName; }
|
|
|
+ set { scheduleName = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 设备名称
|
|
|
+ /// </summary>
|
|
|
+ private string deviceKindName;
|
|
|
+ public string DeviceKindName
|
|
|
+ {
|
|
|
+ get { return deviceKindName; }
|
|
|
+ set { deviceKindName = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 测试项名称
|
|
|
+ /// </summary>
|
|
|
+ private string testName;
|
|
|
+ public string TestName
|
|
|
+ {
|
|
|
+ get { return testName; }
|
|
|
+ set { testName = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 测试项类型
|
|
|
+ /// </summary>
|
|
|
+ private List<string> testKinds = new List<string>();
|
|
|
+ public List<string> TestKinds
|
|
|
+ {
|
|
|
+ get { return testKinds; }
|
|
|
+ set { testKinds = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ ///
|
|
|
+ /// </summary>
|
|
|
+ private string selectTest;
|
|
|
+ public string SelectTest
|
|
|
+ {
|
|
|
+ get { return selectTest; }
|
|
|
+ set { selectTest = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 判定类型(前置项)
|
|
|
+ /// </summary>
|
|
|
+ private List<string> beforeJudgeKinds = new List<string>();
|
|
|
+ public List<string> BeforeJudgeKinds
|
|
|
+ {
|
|
|
+ get { return beforeJudgeKinds; }
|
|
|
+ set { beforeJudgeKinds = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ private string beforeSelectJudge;
|
|
|
+ public string BeforeSelectJudge
|
|
|
+ {
|
|
|
+ get { return beforeSelectJudge; }
|
|
|
+ set { beforeSelectJudge = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 逻辑判断
|
|
|
+ /// </summary>
|
|
|
+ private List<string> judgeLogicKinds = new List<string>();
|
|
|
+ public List<string> JudgeLogicKinds
|
|
|
+ {
|
|
|
+ get { return judgeLogicKinds; }
|
|
|
+ set { judgeLogicKinds = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ private string selectLogic;
|
|
|
+ public string SelectLogic
|
|
|
+ {
|
|
|
+ get { return selectLogic; }
|
|
|
+ set { selectLogic = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ private string beforeDetail;
|
|
|
+ public string BeforeDetail
|
|
|
+ {
|
|
|
+ get { return beforeDetail; }
|
|
|
+ set { beforeDetail = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+
|
|
|
+ private ObservableCollection<BasPlcItemConfigDto> beforeConList;
|
|
|
+ public ObservableCollection<BasPlcItemConfigDto> BeforeConList
|
|
|
+ {
|
|
|
+ get { return beforeConList; }
|
|
|
+ set { beforeConList = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 判定类型(输入项)
|
|
|
+ /// </summary>
|
|
|
+ private List<string> inJudgeKinds = new List<string>();
|
|
|
+ public List<string> InJudgeKinds
|
|
|
+ {
|
|
|
+ get { return inJudgeKinds; }
|
|
|
+ set { inJudgeKinds = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ private string selectInJudge;
|
|
|
+ public string SelectInJudge
|
|
|
+ {
|
|
|
+ get { return selectInJudge; }
|
|
|
+ set { selectInJudge = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 逻辑判断
|
|
|
+ /// </summary>
|
|
|
+ private List<string> inJudgeLogicKinds = new List<string>();
|
|
|
+ public List<string> InJudgeLogicKinds
|
|
|
+ {
|
|
|
+ get { return inJudgeLogicKinds; }
|
|
|
+ set { inJudgeLogicKinds = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ private string inSelectLogic;
|
|
|
+ public string InSelectLogic
|
|
|
+ {
|
|
|
+ get { return inSelectLogic; }
|
|
|
+ set { inSelectLogic = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ private string inDetail;
|
|
|
+ public string InDetail
|
|
|
+ {
|
|
|
+ get { return inDetail; }
|
|
|
+ set { inDetail = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+
|
|
|
+ private ObservableCollection<BasPlcItemConfigDto> inConList;
|
|
|
+ public ObservableCollection<BasPlcItemConfigDto> InConList
|
|
|
+ {
|
|
|
+ get { return inConList; }
|
|
|
+ set { inConList = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 判定类型(结果项)
|
|
|
+ /// </summary>
|
|
|
+ private List<string> outJudgeKinds = new List<string>();
|
|
|
+ public List<string> OutJudgeKinds
|
|
|
+ {
|
|
|
+ get { return outJudgeKinds; }
|
|
|
+ set { outJudgeKinds = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ private string selectOutJudge;
|
|
|
+ public string SelectOutJudge
|
|
|
+ {
|
|
|
+ get { return selectOutJudge; }
|
|
|
+ set { selectOutJudge = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 逻辑判断
|
|
|
+ /// </summary>
|
|
|
+ private List<string> outJudgeLogicKinds = new List<string>();
|
|
|
+ public List<string> OutJudgeLogicKinds
|
|
|
+ {
|
|
|
+ get { return outJudgeLogicKinds; }
|
|
|
+ set { outJudgeLogicKinds = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ private string outSelectLogic;
|
|
|
+ public string OutSelectLogic
|
|
|
+ {
|
|
|
+ get { return outSelectLogic; }
|
|
|
+ set { outSelectLogic = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+
|
|
|
+ private string outDetail;
|
|
|
+ public string OutDetail
|
|
|
+ {
|
|
|
+ get { return outDetail; }
|
|
|
+ set { outDetail = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ private ObservableCollection<BasPlcItemConfigDto> outConList;
|
|
|
+ public ObservableCollection<BasPlcItemConfigDto> OutConList
|
|
|
+ {
|
|
|
+ get { return outConList; }
|
|
|
+ set { outConList = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+
|
|
|
+ private int stepIndex = 0;
|
|
|
+ public int StepIndex
|
|
|
+ {
|
|
|
+ get { return stepIndex; }
|
|
|
+ set { stepIndex = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Visibility proVisibility = Visibility.Hidden;
|
|
|
+ public Visibility ProVisibility
|
|
|
+ {
|
|
|
+ get { return proVisibility; }
|
|
|
+ set { proVisibility = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ private bool startEnalbe = true;
|
|
|
+ public bool StartEnalbe
|
|
|
+ {
|
|
|
+ get { return startEnalbe; }
|
|
|
+ set { startEnalbe = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ //所有测试项列表
|
|
|
+ private List<string> schItems = new List<string>();
|
|
|
+ public List<string> SchItems
|
|
|
+ {
|
|
|
+ get { return schItems; }
|
|
|
+ set { schItems = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ //所选测试方案
|
|
|
+ private string selectItem;
|
|
|
+ public string SelectItem
|
|
|
+ {
|
|
|
+ get { return selectItem; }
|
|
|
+ set { selectItem = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+
|
|
|
+ private int selectItemIndex;
|
|
|
+ public int SelectItemIndex
|
|
|
+ {
|
|
|
+ get { return selectItemIndex; }
|
|
|
+ set { selectItemIndex = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ }
|
|
|
+}
|