瀏覽代碼

修改自动测试

user_lt 1 年之前
父節點
當前提交
ebdb62464a

+ 62 - 0
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/AddOrEditSchViewModel.cs

@@ -352,6 +352,65 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
         /// <param name="obj"></param>
         /// <param name="obj"></param>
         private void Sure(string obj)
         private void Sure(string obj)
         {
         {
+            if (string.IsNullOrEmpty(ScheduleName))
+            {
+                MessageBox.Show("请填写测试项名称!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            if (string.IsNullOrEmpty(DeviceName))
+            {
+                MessageBox.Show("请填写设备名称!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            if (string.IsNullOrEmpty(SelectTest))
+            {
+                MessageBox.Show("请选择测试项类型!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            if (string.IsNullOrEmpty(TestName))
+            {
+                MessageBox.Show("请填写测试项名称!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            if (string.IsNullOrEmpty(BeforeSelectJudge))
+            {
+                MessageBox.Show("请填写前置项测试项测试类型!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            //前置项
+            if (string.IsNullOrEmpty(BeforeSelectJudge))
+            {
+                MessageBox.Show("请填写前置项测试项测试类型!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            if (string.IsNullOrEmpty(SelectLogic))
+            {
+                MessageBox.Show("请填写前置项判定逻辑!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            //输入项
+            if (string.IsNullOrEmpty(SelectInJudge))
+            {
+                MessageBox.Show("请填写输入项测试项测试类型!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            if (string.IsNullOrEmpty(InSelectLogic))
+            {
+                MessageBox.Show("请填写输入项判定逻辑!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            //输出项
+            if (string.IsNullOrEmpty(SelectOutJudge))
+            {
+                MessageBox.Show("请填写输出项测试项测试类型!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            if (string.IsNullOrEmpty(OutSelectLogic))
+            {
+                MessageBox.Show("请填写输出项判定逻辑!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+
             if (Title == "新增方案")
             if (Title == "新增方案")
             {
             {
                 var finsSche = _basicPlcTestSchemeService.FindByName(ScheduleName);
                 var finsSche = _basicPlcTestSchemeService.FindByName(ScheduleName);
@@ -396,6 +455,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             }
             }
 
 
         }
         }
+     
         /// <summary>
         /// <summary>
         /// 方案明细添加到数据库
         /// 方案明细添加到数据库
         /// </summary>
         /// </summary>
@@ -451,6 +511,8 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
                     {
                     {
                         schDtlDto.SchemeDtlId = schDtl.scheme_dtl_id;
                         schDtlDto.SchemeDtlId = schDtl.scheme_dtl_id;
                         bas_plc_test_scheme_dtl schDtlEntityEdit = _mapper.Map<BasicPlcTestSchemeDtlDto, bas_plc_test_scheme_dtl>(schDtlDto);
                         bas_plc_test_scheme_dtl schDtlEntityEdit = _mapper.Map<BasicPlcTestSchemeDtlDto, bas_plc_test_scheme_dtl>(schDtlDto);
+                        //ItemType 转化
+                        schDtlEntityEdit.item_type = StrToItemType(schDtlDto.ItemType);
                         bool isSucc = _basicPlcTestSchemeDtlService.Edit(schDtlEntityEdit);
                         bool isSucc = _basicPlcTestSchemeDtlService.Edit(schDtlEntityEdit);
                         if (isSucc)
                         if (isSucc)
                         {
                         {

+ 527 - 218
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/AutoTestViewModel.cs

@@ -15,12 +15,14 @@ using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Collections.ObjectModel;
 using System.Linq;
 using System.Linq;
 using System.Text;
 using System.Text;
+using System.Threading;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows;
 
 
 namespace PLCTool.ViewModels.BusinessManageViewModel
 namespace PLCTool.ViewModels.BusinessManageViewModel
 {
 {
 
 
+
     public class AutoTestViewModel : BindableBase, IDialogAware
     public class AutoTestViewModel : BindableBase, IDialogAware
     {
     {
         private readonly IDialogService _dialog;
         private readonly IDialogService _dialog;
@@ -41,8 +43,9 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         private long schId = 0; //方案ID
         private long schId = 0; //方案ID
         private long globalSchDetailId = 0; //测试方案明细ID
         private long globalSchDetailId = 0; //测试方案明细ID
         private BizTestRecordDtlDto bizTestRecordDtlDto = new BizTestRecordDtlDto(); //测试方案明细表
         private BizTestRecordDtlDto bizTestRecordDtlDto = new BizTestRecordDtlDto(); //测试方案明细表
-        private const string TestMode = "手动测试";
-
+        private const string TestMode = "自动测试";
+        ManualResetEvent m = new ManualResetEvent(true); //实例化阻塞事件
+        CancellationTokenSource tokensource = new CancellationTokenSource(); //声明令牌
         public AutoTestViewModel(IDialogService dialog, IEventAggregator aggregator, IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService, IBizTestRecordService iBizTestRecordService, IBizTestRecordDtlService iBizTestRecordDtlService, IMapper mapper, ILogger logger)
         public AutoTestViewModel(IDialogService dialog, IEventAggregator aggregator, IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService, IBizTestRecordService iBizTestRecordService, IBizTestRecordDtlService iBizTestRecordDtlService, IMapper mapper, ILogger logger)
         {
         {
             _dialog = dialog;
             _dialog = dialog;
@@ -55,10 +58,9 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
             _mapper = mapper;
             _mapper = mapper;
             _logger = logger;
             _logger = logger;
             CloseCommand = new DelegateCommand(Close);
             CloseCommand = new DelegateCommand(Close);
-            StartCommand = new DelegateCommand<object>(Start);
-            PreviousCommand = new DelegateCommand<object>(Previous);
-            NextCommand = new DelegateCommand<object>(Next);
-            DoneCommand = new DelegateCommand<object>(Done);
+            StartCommand = new DelegateCommand(Start);
+            StopOrContinueCommand = new DelegateCommand<object>(StopOrContinueMethod);
+          
             BeforeConList = new ObservableCollection<BasPlcItemConfigDto>();
             BeforeConList = new ObservableCollection<BasPlcItemConfigDto>();
             InConList = new ObservableCollection<BasPlcItemConfigDto>();
             InConList = new ObservableCollection<BasPlcItemConfigDto>();
             OutConList = new ObservableCollection<BasPlcItemConfigDto>();
             OutConList = new ObservableCollection<BasPlcItemConfigDto>();
@@ -66,11 +68,29 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
 
 
         }
         }
 
 
+        private void StopOrContinueMethod(object obj)
+        {
+            if(StopOrContinueCont=="暂停")
+            {
+                m.Reset();  //阻塞线程
+                StopOrContinueCont = "继续";
+            }
+            else
+            {
+                if (StopOrContinueCont == "继续")
+                {
+                    m.Set();  //继续线程
+                    StopOrContinueCont = "暂停";
+                }
+            }
+          
+        }
+
 
 
 
 
 
 
         #region idialog接口实现
         #region idialog接口实现
-        public string Title { set; get; } = "手动测试";
+        public string Title { set; get; } = "动测试";
 
 
         public event Action<IDialogResult> RequestClose;
         public event Action<IDialogResult> RequestClose;
 
 
@@ -224,7 +244,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         /// <summary>
         /// <summary>
         /// 增加测试记录明细
         /// 增加测试记录明细
         /// </summary>
         /// </summary>
-        private void AddTesDtltRecord(long schDetailId)
+        private void AddOrEditTesDtltRecord(long schDetailId)
         {
         {
             //查找record ID
             //查找record ID
             long recordId = 0;
             long recordId = 0;
@@ -234,105 +254,206 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                 recordId = findRecordID.record_id;
                 recordId = findRecordID.record_id;
             }
             }
             testStatus = 99;//测试状态赋值为99
             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;
             //记录记录明细表中是否有这个方案明细ID的记录,没有则添加,有则更新记录状态
             //记录记录明细表中是否有这个方案明细ID的记录,没有则添加,有则更新记录状态
             var findRecordDetail = _iBizTestRecordDtlService.FindRecordDetailBySchDtlID(schDetailId);
             var findRecordDetail = _iBizTestRecordDtlService.FindRecordDetailBySchDtlID(schDetailId);
             if (findRecordDetail == null)
             if (findRecordDetail == null)
             {
             {
-                //状态status 没有赋值
 
 
-                bizTestRecordDtlDto.RecordId = recordId;
-                bizTestRecordDtlDto.SchemeDtlId = schDetailId;
-                bizTestRecordDtlDto.StartTestTime = startTime;
-                bizTestRecordDtlDto.FinishTestTime = endTime;
-                bizTestRecordDtlDto.TestMode = TestMode;
-                bizTestRecordDtlDto.Status = testStatus;
-                bizTestRecordDtlDto.TestResult = testResult;
-                bizTestRecordDtlDto.CreateBy = Appsession.UserName;
-                bizTestRecordDtlDto.CreateTime = DateTime.Now;
-                bizTestRecordDtlDto.UpdateBy = Appsession.UserName;
-                bizTestRecordDtlDto.UpdateTime = DateTime.Now;
                 var testRecordDtl = _mapper.Map<BizTestRecordDtlDto, biz_test_record_dtl>(bizTestRecordDtlDto);
                 var testRecordDtl = _mapper.Map<BizTestRecordDtlDto, biz_test_record_dtl>(bizTestRecordDtlDto);
                 _iBizTestRecordDtlService.Add(testRecordDtl);
                 _iBizTestRecordDtlService.Add(testRecordDtl);
             }
             }
+            else
+            {
+                bizTestRecordDtlDto.RecordDtlId = findRecordDetail.record_dtl_id;
+                //更新时间
+                bizTestRecordDtlDto.UpdateBy = Appsession.UserName;
+                bizTestRecordDtlDto.UpdateTime = DateTime.Now;
+                UpdateTesDtltRecord();
+            }
+
+
 
 
         }
         }
 
 
+        private int GetTestResult()
+        {
+
+            foreach (var item in BeforeConList)
+            {
+                if (item.TestResult == "不合格" || string.IsNullOrEmpty(item.TestResult))
+                {
+
+                    return 0;
+                }
+
+            }
+            foreach (var item in InConList)
+            {
+                if (item.TestResult == "不合格" || string.IsNullOrEmpty(item.TestResult))
+                {
 
 
+                    return 0;
+                }
+            }
+            foreach (var item in OutConList)
+            {
+                if (item.TestResult == "不合格" || string.IsNullOrEmpty(item.TestResult))
+                {
+                    return 0;
+                }
+            }
+
+            return 1;
+        }
+        /// <summary>
+        /// 更新测试记录
+        /// </summary>
         private void UpdateTesDtltRecord()
         private void UpdateTesDtltRecord()
         {
         {
 
 
             var testRecordDtl = _mapper.Map<BizTestRecordDtlDto, biz_test_record_dtl>(bizTestRecordDtlDto);
             var testRecordDtl = _mapper.Map<BizTestRecordDtlDto, biz_test_record_dtl>(bizTestRecordDtlDto);
             _iBizTestRecordDtlService.Edit(testRecordDtl);
             _iBizTestRecordDtlService.Edit(testRecordDtl);
         }
         }
+       
+    
         /// <summary>
         /// <summary>
-        /// 完成时间
+        /// 下一步
         /// </summary>
         /// </summary>
-        /// <param name="obj"></param>
-        private void Done(object obj)
+        private void Next( )
         {
         {
-            endTime = DateTime.Now;
+            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);
+                    //界面显示
+                    GetDetailInfo(id);
+                    //记录记录明细表中是否有这个方案明细ID的记录,没有则添加,有则更新记录状态
+                    break;
+                }
+               
+            }
+            long maxDtlId = basicSchDtls.Select(x => x.scheme_dtl_id).Max();
+            if (globalSchDetailId== maxDtlId)
+            {
+                MessageBox.Show("已是此测试方案最后一个测试项!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
+            }
         }
         }
 
 
-        private void Next(object obj)
+        private void Previous(object obj)
         {
         {
+            StepIndex = 0;
             ///查找方案下的所有方案明细,并排序,
             ///查找方案下的所有方案明细,并排序,
             var basicSchDtls = _basicPlcTestSchemeDtlService.FindAllBySchId(schId)?.OrderBy(x => x.scheme_dtl_id);
             var basicSchDtls = _basicPlcTestSchemeDtlService.FindAllBySchId(schId)?.OrderBy(x => x.scheme_dtl_id);
             foreach (var item in basicSchDtls)
             foreach (var item in basicSchDtls)
             {
             {
                 //在测试结果明细中查看
                 //在测试结果明细中查看
                 long schDetailId = item.scheme_dtl_id;
                 long schDetailId = item.scheme_dtl_id;
-                if (schDetailId > globalSchDetailId)
+                if (schDetailId < globalSchDetailId)
                 {
                 {
                     globalSchDetailId = schDetailId;
                     globalSchDetailId = schDetailId;
                     int id = Convert.ToInt32(schDetailId);
                     int id = Convert.ToInt32(schDetailId);
                     //界面显示
                     //界面显示
                     GetDetailInfo(id);
                     GetDetailInfo(id);
                     //记录记录明细表中是否有这个方案明细ID的记录,没有则添加,有则更新记录状态
                     //记录记录明细表中是否有这个方案明细ID的记录,没有则添加,有则更新记录状态
-                    var findRecordDetail = _iBizTestRecordDtlService.FindRecordDetailBySchDtlID(schDetailId);
-                    if (findRecordDetail == null)
-                    {
-
-                        //增加测试记录明细
-                        AddTesDtltRecord(globalSchDetailId);
 
 
-                    }
                     break;
                     break;
-
-
+                }
+                else
+                {
+                    MessageBox.Show("已是此测试方案第一个测试项!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
                 }
                 }
 
 
 
 
             }
             }
         }
         }
+        /// <summary>
+        /// 开始检测
+        /// </summary>
+        /// <param name="obj"></param>
+        private async void Start()
+        {
+            CancellationToken cancellationToken = tokensource.Token;
+            await Task.Run(async() =>  //模拟耗时任务
+            {
+                if (cancellationToken.IsCancellationRequested)
+                {
+                    return;
+                }
+                m.WaitOne(); //当m等于true,才会往下执行,否则一直在此等待
 
 
-        private void Previous(object obj)
+                //开始时间
+                startTime = DateTime.Now;
+                //增加测试记录主表
+                AddTestRecord();
+
+                //前置项
+                bool preBool = TestPreceditionMethod();
+
+
+                //输入项
+                bool isAction = TestActionMethod();
+
+
+                //输出项
+                bool isJudgeResult = await TestJudgementMethod();
+                //下一项
+                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);
+                        //界面显示
+                        GetDetailInfo(id);
+                        //递归调用
+                        Start();
+                    }
+
+                }
+            }, cancellationToken);//绑定令牌到多线程
+
+
+
+     
+            
+
+        }
+        /// <summary>
+        /// 更新测试结果
+        /// </summary>
+        private void UpdateTestRecord()
         {
         {
 
 
         }
         }
         /// <summary>
         /// <summary>
-        /// 开始检测
+        /// 测试前置项目
         /// </summary>
         /// </summary>
-        /// <param name="obj"></param>
-        private void Start(object obj)
-        {
-            //开始时间
-            startTime = DateTime.Now;
-            //增加测试记录主表
-            AddTestRecord();
-            //增加测试记录明细表
-            AddTesDtltRecord(globalSchDetailId);
-            //前置项
-            TestPreceditionMethod();
-            MessageBox.Show("前置项测试完成!", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
-            //输入项
-            TestActionMethod();
-            MessageBox.Show("输入项测试完成!", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
-            //输出项
-            TestJudgementMethod();
-            MessageBox.Show("输出项测试完成!", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
-        }
-
-        private void TestPreceditionMethod()
+        private bool TestPreceditionMethod()
         {
         {
             switch (BeforeSelectJudge)
             switch (BeforeSelectJudge)
             {
             {
@@ -341,9 +462,17 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                     MessageBoxResult boxResult = MessageBox.Show(BeforeDetail, "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
                     MessageBoxResult boxResult = MessageBox.Show(BeforeDetail, "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
                     if (boxResult == MessageBoxResult.OK)
                     if (boxResult == MessageBoxResult.OK)
                     {
                     {
+                        //前置项测试结果json转化
+                        string prefixJsonStr = ModelToJsonToStr(BeforeSelectJudge, SelectLogic, BeforeDetail, BeforeConList);
+                        //json字符串
+                        bizTestRecordDtlDto.PreconditionFinal = prefixJsonStr;
                         bizTestRecordDtlDto.PreconditionResult = "合格";
                         bizTestRecordDtlDto.PreconditionResult = "合格";
                         StepIndex = 1;
                         StepIndex = 1;
                     }
                     }
+                    else
+                    {
+                        return false;
+                    }
 
 
                     break;
                     break;
                 case "自动判定":
                 case "自动判定":
@@ -351,59 +480,26 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                     switch (SelectLogic)
                     switch (SelectLogic)
                     {
                     {
                         case "NULL":
                         case "NULL":
-                            break;
-                        case "AND":
-                        case "ONLY":
-                            int countCond = 0;
-                            foreach (var item in BeforeConList)
-                            {
-                                string plcAddress = item.PlcAddress;
-                                string plcAddType = item.PlcAddType;
-                                string plcValue = item.PlcValue;
-
-                                switch (plcAddType)
-                                {
-                                    case "bool":
-                                        // string readResult = PLCCom.GetInstance().ReadPlcObject(plcAddress, VarType.Bit);
-                                        ///实时值记录
-                                        string readResult = "1";
-                                        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;
-                            //条件满足
-                            if (countCond == BeforeConList.Count)
+                            //弹出确认的对话框
+                            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 = "合格";
                                 bizTestRecordDtlDto.PreconditionResult = "合格";
                                 StepIndex = 1;
                                 StepIndex = 1;
                             }
                             }
                             else
                             else
                             {
                             {
-                                bizTestRecordDtlDto.PreconditionResult = "不合格";
+                                return false;
                             }
                             }
-
                             break;
                             break;
+                        case "AND":
+                        case "ONLY":
                         case "OR":
                         case "OR":
+                            ReadPredice(SelectLogic);
                             break;
                             break;
 
 
                         case "ORDER":
                         case "ORDER":
@@ -412,10 +508,86 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                     break;
                     break;
             }
             }
             //更新测试记录
             //更新测试记录
-            UpdateTesDtltRecord();
+            AddOrEditTesDtltRecord(globalSchDetailId);
+            return true;
         }
         }
-        private void TestActionMethod()
+
+        private void ReadPredice(string strLogic)
         {
         {
+            int countCond = 0;
+            foreach (var item in BeforeConList)
+            {
+                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)
             switch (SelectInJudge)
             {
             {
                 case "人工判定":
                 case "人工判定":
@@ -423,9 +595,17 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                     MessageBoxResult boxResult = MessageBox.Show(InDetail, "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
                     MessageBoxResult boxResult = MessageBox.Show(InDetail, "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
                     if (boxResult == MessageBoxResult.OK)
                     if (boxResult == MessageBoxResult.OK)
                     {
                     {
+                        //前置项测试结果json转化
+                        string actionJsonStr = ModelToJsonToStr(SelectInJudge, InSelectLogic, InDetail, InConList);
+                        //json字符串
+                        bizTestRecordDtlDto.ActionFinal = actionJsonStr;
                         bizTestRecordDtlDto.ActionResult = "合格";
                         bizTestRecordDtlDto.ActionResult = "合格";
                         StepIndex = 2;
                         StepIndex = 2;
                     }
                     }
+                    else
+                    {
+                        isActionResult = false;
+                    }
 
 
                     break;
                     break;
                 case "自动判定":
                 case "自动判定":
@@ -433,73 +613,27 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                     switch (InSelectLogic)
                     switch (InSelectLogic)
                     {
                     {
                         case "NULL":
                         case "NULL":
-                            break;
-                        case "AND":
-                        case "ONLY":
-                            int countCond = 0;
-                            foreach (var item in InConList)
-                            {
-                                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)
-                                            {
-                                                // bool writeResult = PLCCom.GetInstance().WritePlcObject(plcAddress, VarType.Bit, plcValue);
-                                                ///实时值记录
-                                                bool writeResult = true;
-                                                item.TestTime = DateTime.Now;
-                                                if (writeResult)
-                                                {
-                                                    ///单个测试项合格
-                                                    item.TestResult = "合格";
-                                                }
-                                                else
-                                                {
-                                                    item.TestResult = "不合格";
-                                                }
-                                            }
-
-                                        });
-
-
-
-
-                                        break;
-                                    case "word":
-                                        break;
-
-                                }
-
-                            }
-                            //测试记录存入数据库
-                            //前置项测试结果json转化
-                            string actionJsonStr = ModelToJsonToStr(SelectInJudge, InSelectLogic, InDetail, InConList);
-                            //json字符串
-                            bizTestRecordDtlDto.ActionFinal = actionJsonStr;
-                            //条件满足
-                            if ((countCond == InConList.Count) && (countCond != 0))
+                            //弹出确认的对话框
+                            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 = "合格";
                                 bizTestRecordDtlDto.ActionResult = "合格";
                                 StepIndex = 2;
                                 StepIndex = 2;
                             }
                             }
                             else
                             else
                             {
                             {
-                                bizTestRecordDtlDto.ActionResult = "不合格";
+                                isActionResult = false;
                             }
                             }
 
 
                             break;
                             break;
+                        case "AND":
+                        case "ONLY":
                         case "OR":
                         case "OR":
+                            isActionResult = SendActionToPLC(InSelectLogic);
                             break;
                             break;
 
 
                         case "ORDER":
                         case "ORDER":
@@ -508,10 +642,114 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                     break;
                     break;
             }
             }
             //更新测试记录
             //更新测试记录
-            UpdateTesDtltRecord();
+            //更新测试记录
+            AddOrEditTesDtltRecord(globalSchDetailId);
+            return isActionResult;
+        }
+        /// <summary>
+        /// 发送命令给PLC
+        /// </summary>
+        private bool SendActionToPLC(string strActionLogic)
+        {
+            bool isAction = true;
+            int countCond = 0;
+            foreach (var item in InConList)
+            {
+                string plcAddress = item.PlcAddress;
+                string plcAddType = item.PlcAddType;
+                string plcValue = item.PlcValue;
+
+                switch (plcAddType)
+                {
+                    case "bool":
+
+                        bool writeResult = PLCCom.GetInstance().WritePlcObject(plcAddress, VarType.Bit, plcValue);
+                        ///实时值记录
+                        item.RealValue = plcValue;
+                        item.TestTime = DateTime.Now;
+                        if (writeResult)
+                        {
+                            ///单个测试项合格
+                            item.TestResult = "合格";
+                            countCond++;
+                        }
+                        else
+                        {
+                            item.TestResult = "不合格";
+                        }
+                    
+                        break;
+                    case "word":
+                       
+                        bool writeWrordResult = PLCCom.GetInstance().WritePlcObject(plcAddress, VarType.Word, plcValue);
+                        ///实时值记录
+                        item.RealValue = plcValue;
+                        item.TestTime = DateTime.Now;
+                        if (writeWrordResult)
+                        {
+                            ///单个测试项合格
+                            item.TestResult = "合格";
+                            countCond++;
+                        }
+                        else
+                        {
+                            item.TestResult = "不合格";
+                        }
+                      
+                    
+                        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;
         }
         }
-        private void TestJudgementMethod()
+        /// <summary>
+        /// 结果项判定
+        /// </summary>
+        private async Task<bool> TestJudgementMethod()
         {
         {
+            bool isJudge = true;
             switch (SelectOutJudge)
             switch (SelectOutJudge)
             {
             {
                 case "人工判定":
                 case "人工判定":
@@ -522,6 +760,10 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                         bizTestRecordDtlDto.JudgementResult = "合格";
                         bizTestRecordDtlDto.JudgementResult = "合格";
                         StepIndex = 3;
                         StepIndex = 3;
                     }
                     }
+                    else
+                    {
+                        isJudge = false;
+                    }
 
 
                     break;
                     break;
                 case "自动判定":
                 case "自动判定":
@@ -529,69 +771,124 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                     switch (OutSelectLogic)
                     switch (OutSelectLogic)
                     {
                     {
                         case "NULL":
                         case "NULL":
+                            bizTestRecordDtlDto.JudgementResult = "合格";
+                            StepIndex = 3;
                             break;
                             break;
                         case "AND":
                         case "AND":
                         case "ONLY":
                         case "ONLY":
-                            int countCond = 0;
-                            foreach (var item in OutConList)
-                            {
-                                string plcAddress = item.PlcAddress;
-                                string plcAddType = item.PlcAddType;
-                                string plcValue = item.PlcValue;
-
-                                switch (plcAddType)
-                                {
+                        case "OR":
+                            await ReadJudge(OutSelectLogic);
+                            break;
+                        case "ORDER":
+                            break;
+                    }
+                    break;
+            }
+            //更新测试记录
+            //更新测试记录
+            AddOrEditTesDtltRecord(globalSchDetailId);
 
 
-                                    case "bool":
-                                        //string readResult = PLCCom.GetInstance().ReadPlcObject(plcAddress, VarType.Bit);
-                                        string readResult = "1";
-                                        ///实时值记录
-                                        item.RealValue = readResult;
-                                        item.TestTime = DateTime.Now;
-                                        if (readResult.Trim() == plcValue.Trim())
-                                        {
-                                            item.TestResult = "合格";
-                                            countCond++;
-                                        }
-                                        else
-                                        {
-                                            item.TestResult = "不合格";
-                                        }
-
-                                        break;
-                                    case "word":
-                                        break;
+            //判定是否为最后一项
+            long maxDtlId = _basicPlcTestSchemeDtlService.FindAllBySchId(schId).Select(x => x.scheme_dtl_id).Max();
+            if (globalSchDetailId == maxDtlId)
+            {
+                MessageBox.Show("已是此测试方案最后一个测试项!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
+            }
+            return isJudge;
+        }
+        /// <summary>
+        /// 读取结果
+        /// </summary>
+        private async Task ReadJudge(String strLogic)
+        {
+            int countCond = 0;
+            foreach (var item in OutConList)
+            {
+                string plcAddress = item.PlcAddress;
+                string plcAddType = item.PlcAddType;
+                string plcValue = item.PlcValue;
 
 
-                                }
+                switch (plcAddType)
+                {
 
 
-                            }
-                            //测试记录存入数据库
-                            //前置项测试结果json转化
-                            string prefixJsonStr = ModelToJsonToStr(BeforeSelectJudge, SelectLogic, BeforeDetail, BeforeConList);
-                            //json字符串
-                            bizTestRecordDtlDto.JudgementResultFinal = prefixJsonStr;
-                            //条件满足
-                            if ((countCond == OutConList.Count) && (countCond != 0))
+                    case "bool":
+                        DateTime entryTime = DateTime.Now;
+                        string readResult = string.Empty;
+                        //一直读
+                        await Task.Run(async () =>
+                        {
+                            while (entryTime.AddMilliseconds(10 * 1000) > DateTime.Now)
                             {
                             {
-                                bizTestRecordDtlDto.JudgementResult = "合格";
-                                StepIndex = 3;
-                            }
-                            else
-                            {
-                                bizTestRecordDtlDto.JudgementResult = "不合格";
+                                //显示进度条
+                                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);
                             }
                             }
+                        });
+
+                        ProVisibility = Visibility.Hidden;
+                        ///实时值记录
+                        item.RealValue = readResult;
+                        item.TestTime = DateTime.Now;
+                        if (readResult.Trim() == plcValue?.Trim())
+                        {
+                            item.TestResult = "合格";
+                            countCond++;
+                        }
+                        else
+                        {
+                            item.TestResult = "不合格";
+                        }
+
+                        break;
+                    case "word":
+                        break;
 
 
-                            break;
-                        case "OR":
-                            break;
+                }
 
 
-                        case "ORDER":
-                            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;
                     break;
             }
             }
-            //更新测试记录
-            UpdateTesDtltRecord();
+
+            StepIndex = 3;
         }
         }
         /// <summary>
         /// <summary>
         /// 获取配置
         /// 获取配置
@@ -685,12 +982,10 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         #region 命令绑定
         #region 命令绑定
         public DelegateCommand CloseCommand { set; get; }
         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 StartCommand { set; get; }
+        public DelegateCommand<object> StopOrContinueCommand { set; get; }
 
 
-        public DelegateCommand<object> DoneCommand { set; get; }
+     
 
 
 
 
         #endregion
         #endregion
@@ -877,6 +1172,20 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
             get { return stepIndex; }
             get { return stepIndex; }
             set { stepIndex = value; RaisePropertyChanged(); }
             set { stepIndex = value; RaisePropertyChanged(); }
         }
         }
+
+        private Visibility proVisibility = Visibility.Hidden;
+        public Visibility ProVisibility
+        {
+            get { return proVisibility; }
+            set { proVisibility = value; RaisePropertyChanged(); }
+        }
+        private string stopOrContinueCont ="暂停";
+        public string StopOrContinueCont
+        {
+            get { return stopOrContinueCont; }
+            set { stopOrContinueCont = value; RaisePropertyChanged(); }
+        }
+        
         #endregion
         #endregion
 
 
     }
     }

+ 82 - 22
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/ManualTestViewModel.cs

@@ -277,7 +277,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
          
          
             foreach(var item in BeforeConList)
             foreach(var item in BeforeConList)
             {
             {
-                if (item.TestResult == "不合格")
+                if (item.TestResult == "不合格"||string.IsNullOrEmpty(item.TestResult))
                 {
                 {
                    
                    
                     return 0;
                     return 0;
@@ -286,7 +286,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
             }
             }
             foreach(var item in InConList)
             foreach(var item in InConList)
             {
             {
-                if(item.TestResult=="不合格")
+                if(item.TestResult=="不合格" || string.IsNullOrEmpty(item.TestResult))
                 {
                 {
                    
                    
                     return 0;    
                     return 0;    
@@ -294,7 +294,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
             }
             }
             foreach (var item in OutConList)
             foreach (var item in OutConList)
             {
             {
-                if (item.TestResult == "不合格")
+                if (item.TestResult == "不合格" || string.IsNullOrEmpty(item.TestResult))
                 {
                 {
                     return 0;
                     return 0;
                 }
                 }
@@ -318,6 +318,8 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         private void Done(object obj)
         private void Done(object obj)
         {
         {
             endTime = DateTime.Now;
             endTime = DateTime.Now;
+            RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
+      
         }
         }
 
 
         private void Next(object obj)
         private void Next(object obj)
@@ -339,7 +341,11 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                
                
                     break;
                     break;
                 }
                 }
-          
+                long maxDtlId = basicSchDtls.Select(x => x.scheme_dtl_id).Max();
+                if (globalSchDetailId == maxDtlId)
+                {
+                    MessageBox.Show("已是此测试方案最后一个测试项!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
+                }
 
 
             }
             }
         }
         }
@@ -363,8 +369,12 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                    
                    
                     break;
                     break;
                 }
                 }
-
-
+     
+            }
+            long maxDtlId = basicSchDtls.Select(x => x.scheme_dtl_id).Min();
+            if (globalSchDetailId == maxDtlId)
+            {
+                MessageBox.Show("已是此测试方案的第一个测试项!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
             }
             }
         }
         }
         /// <summary>
         /// <summary>
@@ -438,6 +448,21 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                     switch (SelectLogic)
                     switch (SelectLogic)
                     {
                     {
                         case "NULL":
                         case "NULL":
+                            //弹出确认的对话框
+                            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;
                             break;
                         case "AND":
                         case "AND":
                         case "ONLY":
                         case "ONLY":
@@ -445,7 +470,6 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                             ReadPredice(SelectLogic);
                             ReadPredice(SelectLogic);
                             break;
                             break;
                    
                    
-                           
                         case "ORDER":
                         case "ORDER":
                             break;
                             break;
                     }
                     }
@@ -557,13 +581,27 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                     switch (InSelectLogic)
                     switch (InSelectLogic)
                     {
                     {
                         case "NULL":
                         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;
                             break;
                         case "AND":
                         case "AND":
                         case "ONLY":
                         case "ONLY":
-
-                            isActionResult=SendActionToPLC();
-                            break;
                         case "OR":
                         case "OR":
+                            isActionResult =SendActionToPLC(InSelectLogic);
                             break;
                             break;
 
 
                         case "ORDER":
                         case "ORDER":
@@ -579,7 +617,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         /// <summary>
         /// <summary>
         /// 发送命令给PLC
         /// 发送命令给PLC
         /// </summary>
         /// </summary>
-        private bool SendActionToPLC()
+        private bool SendActionToPLC(string strActionLogic)
         {
         {
             bool isAction = true;
             bool isAction = true;
             int countCond = 0;
             int countCond = 0;
@@ -601,9 +639,10 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                         {
                         {
                             if (callback.Result == ButtonResult.OK)
                             if (callback.Result == ButtonResult.OK)
                             {
                             {
-                                bool writeResult = PLCCom.GetInstance().WritePlcObject(plcAddress, VarType.Bit, plcValue);
+                                string plcRealValue = callback.Parameters.GetValue<string>("ReturnValue");
+                                bool writeResult = PLCCom.GetInstance().WritePlcObject(plcAddress, VarType.Bit, plcRealValue);
                                 ///实时值记录
                                 ///实时值记录
-                                item.RealValue = plcValue;
+                                item.RealValue = plcRealValue;
                                 item.TestTime = DateTime.Now;
                                 item.TestTime = DateTime.Now;
                                 if (writeResult)
                                 if (writeResult)
                                 {
                                 {
@@ -632,9 +671,10 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                         {
                         {
                             if (callback.Result == ButtonResult.OK)
                             if (callback.Result == ButtonResult.OK)
                             {
                             {
-                                bool writeResult = PLCCom.GetInstance().WritePlcObject(plcAddress, VarType.Word, plcValue);
+                                string plcRealValue = callback.Parameters.GetValue<string>("ReturnValue");
+                                bool writeResult = PLCCom.GetInstance().WritePlcObject(plcAddress, VarType.Word, plcRealValue);
                                 ///实时值记录
                                 ///实时值记录
-                                item.RealValue = plcValue;
+                                item.RealValue = plcRealValue;
                                 item.TestTime = DateTime.Now;
                                 item.TestTime = DateTime.Now;
                                 if (writeResult)
                                 if (writeResult)
                                 {
                                 {
@@ -668,15 +708,35 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
             //json字符串
             //json字符串
             bizTestRecordDtlDto.ActionFinal = actionJsonStr;
             bizTestRecordDtlDto.ActionFinal = actionJsonStr;
             //条件满足
             //条件满足
-            if ((countCond == InConList.Count) && (countCond != 0))
-            {
-                bizTestRecordDtlDto.ActionResult = "合格";
-                
-            }
-            else
+
+            //条件满足
+            switch (strActionLogic)
             {
             {
-                bizTestRecordDtlDto.ActionResult = "不合格";
+                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;
             StepIndex = 2;
             return isAction;
             return isAction;
         }
         }

+ 12 - 2
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/WritePLCViewModel.cs

@@ -1,4 +1,5 @@
-using Prism.Commands;
+using Model.Dto;
+using Prism.Commands;
 using Prism.Mvvm;
 using Prism.Mvvm;
 using Prism.Services.Dialogs;
 using Prism.Services.Dialogs;
 using System;
 using System;
@@ -6,6 +7,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Linq;
 using System.Text;
 using System.Text;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
+using System.Windows;
 
 
 namespace PLCTool.ViewModels.BusinessManageViewModel
 namespace PLCTool.ViewModels.BusinessManageViewModel
 {
 {
@@ -24,7 +26,15 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
 
 
         private void Sure(object obj)
         private void Sure(object obj)
         {
         {
-            RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
+            if(string.IsNullOrEmpty(PLCAddr)|| string.IsNullOrEmpty(PLCValue))
+            {
+                MessageBox.Show("请填写PLC地址和数值", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
+                return;
+            }
+            DialogParameters parm = new DialogParameters();
+            parm.Add("ReturnValue", PLCValue);
+            RequestClose?.Invoke(new DialogResult(ButtonResult.OK, parm));
+        
         }
         }
 
 
         public string Title { set; get; } = "PLC写入";
         public string Title { set; get; } = "PLC写入";

+ 12 - 3
BlankApp1/BlankApp1/Views/BusinessManageView/AutoTestView.xaml

@@ -301,15 +301,24 @@
         <Border Grid.Row="3"  BorderBrush="#CBCBCB" BorderThickness="0,1,0,0" />
         <Border Grid.Row="3"  BorderBrush="#CBCBCB" BorderThickness="0,1,0,0" />
         <Grid Grid.Row="4">
         <Grid Grid.Row="4">
             <hc:StepBar  StepIndex="{Binding StepIndex}" VerticalAlignment="Center" x:Name="ProSetpBar"  >
             <hc:StepBar  StepIndex="{Binding StepIndex}" VerticalAlignment="Center" x:Name="ProSetpBar"  >
+                <hc:StepBarItem Content="开始"/>
                 <hc:StepBarItem Content="前置条件满足"/>
                 <hc:StepBarItem Content="前置条件满足"/>
                 <hc:StepBarItem Content="输入明细完成"/>
                 <hc:StepBarItem Content="输入明细完成"/>
                 <hc:StepBarItem Content="结果判定完成"/>
                 <hc:StepBarItem Content="结果判定完成"/>
-                
-
             </hc:StepBar>
             </hc:StepBar>
         </Grid>
         </Grid>
         <Grid Grid.Row="5">
         <Grid Grid.Row="5">
-            <Button  Content="开始检测" Width="80"    Command="{Binding StartCommand}" Style="{StaticResource NormalButtonStyle}" />
+            <StackPanel Orientation="Horizontal"  HorizontalAlignment="Center">
+                <Button  Content="开始检测" Width="80"    Command="{Binding StartCommand}" Style="{StaticResource NormalButtonStyle}" />
+                <Button  Content="{Binding StopOrContinueCont}" Width="80"    Command="{Binding StopOrContinueCommand}" Style="{StaticResource NormalButtonStyle}" Margin="10,0,0,0" />
+                <Button  Content="停止" Width="80"    Command="{Binding StopCommand}" Style="{StaticResource NormalButtonStyle}" Margin="10,0,0,0" />
+            </StackPanel>
+          
+        </Grid>
+        <Grid Grid.Row="2">
+            <hc:CircleProgressBar IsIndeterminate="True" Visibility="{Binding ProVisibility }" Value="50"  Margin="16,0,0,0" Width="100" Height="100" ArcThickness="10" Style="{StaticResource ProgressBarInfoCircle}">
+
+            </hc:CircleProgressBar>
         </Grid>
         </Grid>
     </Grid>
     </Grid>
 </UserControl>
 </UserControl>