Ver Fonte

修改手动测试

user_lt há 1 ano atrás
pai
commit
bbbf42ae10

+ 2 - 2
BlankApp1/BlankApp1/App.config

@@ -3,8 +3,8 @@
 	<appSettings>
 		<!--连接字符串 SQL Server-->
 		<add key="MySql" value="Data Source=localhost;Database=plc_point_db;User Id='root';Password='Lt,100186';port=3306;charset=utf8mb4;"/>
-		<add key="PLCIp" value="192.168.0.1"/>
-		<add key="PLCPort" value="5000"/>
+		<add key="PLCIp" value="192.168.0.20"/>
+		<add key="PLCPort" value="9600"/>
 
 	</appSettings>
 </configuration>

+ 2 - 2
BlankApp1/BlankApp1/Common/PLCCom.cs

@@ -39,12 +39,12 @@ namespace PLCTool.Common
             short re = ENT.Link(plcIp, short.Parse(plcPort), 500);
             if (re == 0)
             {
-                //_logger.Info("PLC连接成功!");
+                isConnect = true;
                 return true;
             }
             else
             {
-                //_logger.Info("PLC连接失败!");
+                isConnect = false;
                 return false;
             }
 

+ 158 - 15
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/ManualTestViewModel.cs

@@ -239,6 +239,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
             }
             testStatus = 99;//测试状态赋值为99
                             //状态status 没有赋值
+          
 
             bizTestRecordDtlDto.RecordId = recordId;
             bizTestRecordDtlDto.SchemeDtlId = schDetailId;
@@ -246,7 +247,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
             bizTestRecordDtlDto.FinishTestTime = endTime;
             bizTestRecordDtlDto.TestMode = TestMode;
             bizTestRecordDtlDto.Status = testStatus;
-            bizTestRecordDtlDto.TestResult = testResult;
+            bizTestRecordDtlDto.TestResult = GetTestResult();
             bizTestRecordDtlDto.CreateBy = Appsession.UserName;
             bizTestRecordDtlDto.CreateTime = DateTime.Now;
             bizTestRecordDtlDto.UpdateBy = Appsession.UserName;
@@ -271,7 +272,39 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
            
         }
 
+        private int GetTestResult()
+        {
+         
+            foreach(var item in BeforeConList)
+            {
+                if (item.TestResult == "不合格")
+                {
+                   
+                    return 0;
+                }
+
+            }
+            foreach(var item in InConList)
+            {
+                if(item.TestResult=="不合格")
+                {
+                   
+                    return 0;    
+                }
+            }
+            foreach (var item in OutConList)
+            {
+                if (item.TestResult == "不合格")
+                {
+                    return 0;
+                }
+            }
 
+            return 1;
+        }
+        /// <summary>
+        /// 更新测试记录
+        /// </summary>
         private void UpdateTesDtltRecord()
         {
 
@@ -312,8 +345,6 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                        
                     }
                     break;
-
-
                 }
           
 
@@ -322,7 +353,33 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
 
         private void Previous(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);
+                    //界面显示
+                    GetDetailInfo(id);
+                    //记录记录明细表中是否有这个方案明细ID的记录,没有则添加,有则更新记录状态
+                    var findRecordDetail = _iBizTestRecordDtlService.FindRecordDetailBySchDtlID(schDetailId);
+                    if (findRecordDetail == null)
+                    {
 
+                        //增加测试记录明细
+                        AddTesDtltRecord(globalSchDetailId);
+
+                    }
+                    break;
+                }
+
+
+            }
         }
         /// <summary>
         /// 开始检测
@@ -334,19 +391,29 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
             startTime = DateTime.Now;
             //增加测试记录主表
             AddTestRecord();
-            //增加测试记录明细表
-            AddTesDtltRecord(globalSchDetailId);
+          
             //前置项
             TestPreceditionMethod();
-            MessageBox.Show("前置项测试完成!", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
+            //MessageBox.Show("前置项测试完成!", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
             //输入项
             TestActionMethod();
-            MessageBox.Show("输入项测试完成!", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
+            //MessageBox.Show("输入项测试完成!", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
             //输出项
             TestJudgementMethod();
-            MessageBox.Show("输出项测试完成!", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
+            //MessageBox.Show("输出项测试完成!", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
+            //增加测试记录明细表
+            AddTesDtltRecord(globalSchDetailId);
         }
+        /// <summary>
+        /// 更新测试结果
+        /// </summary>
+        private void UpdateTestRecord()
+        {
 
+        }
+        /// <summary>
+        /// 测试前置项目
+        /// </summary>
         private   void  TestPreceditionMethod()
         {
             switch (BeforeSelectJudge)
@@ -379,9 +446,9 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                                 switch (plcAddType)
                                 {
                                     case "bool":
-                                        // string readResult = PLCCom.GetInstance().ReadPlcObject(plcAddress, VarType.Bit);
+                                         string readResult = PLCCom.GetInstance().ReadPlcObject(plcAddress, VarType.Bit);
                                         ///实时值记录
-                                        string readResult = "1";
+                                       
                                         item.RealValue = readResult;
                                         item.TestTime = DateTime.Now;
                                         if (readResult.Trim() == plcValue.Trim())
@@ -419,7 +486,56 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                           
                             break;
                         case "OR":
+                            int countCond2 = 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 = "合格";
+                                            countCond2++;
+                                        }
+                                        else
+                                        {
+                                            item.TestResult = "不合格";
+                                        }
+
+                                        break;
+                                    case "word":
+                                        break;
+
+                                }
+
+                            }
+                            //测试记录存入数据库
+                            //前置项测试结果json转化
+                            string prefixJsonStr2 = ModelToJsonToStr(BeforeSelectJudge, SelectLogic, BeforeDetail, BeforeConList);
+                            //json字符串
+                            bizTestRecordDtlDto.PreconditionFinal = prefixJsonStr2;
+                            //条件满足
+                            if (countCond2 !=0)
+                            {
+                                bizTestRecordDtlDto.PreconditionResult = "合格";
+                                StepIndex = 1;
+                            }
+                            else
+                            {
+                                bizTestRecordDtlDto.PreconditionResult = "不合格";
+                            }
+
                             break;
+                            
 
                         case "ORDER":
                             break;
@@ -470,9 +586,9 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                                         {
                                             if (callback.Result == ButtonResult.OK)
                                             {
-                                                // bool writeResult = PLCCom.GetInstance().WritePlcObject(plcAddress, VarType.Bit, plcValue);
+                                                 bool writeResult = PLCCom.GetInstance().WritePlcObject(plcAddress, VarType.Bit, plcValue);
                                                 ///实时值记录
-                                                bool writeResult = true;
+                                              
                                                 item.TestTime = DateTime.Now;
                                                 if (writeResult)
                                                 {
@@ -493,6 +609,34 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
 
                                         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)
+                                            {
+                                                bool writeResult = PLCCom.GetInstance().WritePlcObject(plcAddress, VarType.Word, plcValue);
+                                                ///实时值记录
+
+                                                item.TestTime = DateTime.Now;
+                                                if (writeResult)
+                                                {
+                                                    ///单个测试项合格
+                                                    item.TestResult = "合格";
+                                                    countCond++;
+                                                }
+                                                else
+                                                {
+                                                    item.TestResult = "不合格";
+                                                }
+                                            }
+
+                                        });
+
+
+
                                         break;
 
                                 }
@@ -559,12 +703,11 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                                 {
                                  
                                     case "bool":
-                                        //string readResult = PLCCom.GetInstance().ReadPlcObject(plcAddress, VarType.Bit);
-                                        string readResult = "1";
+                                        string readResult = PLCCom.GetInstance().ReadPlcObject(plcAddress, VarType.Bit);
                                         ///实时值记录
                                         item.RealValue = readResult;
                                         item.TestTime = DateTime.Now;
-                                        if (readResult.Trim() == plcValue.Trim())
+                                        if (readResult.Trim() == plcValue?.Trim())
                                         {
                                             item.TestResult = "合格";
                                             countCond++;

+ 40 - 0
BlankApp1/BlankApp1/ViewModels/MonitorManageViewModel/PLCReadViewModel.cs

@@ -2,6 +2,7 @@
 using BizService;
 using Model.Dto;
 using Model.Entities;
+using PLCTool.Common;
 using Prism.Mvvm;
 using System;
 using System.CodeDom;
@@ -11,6 +12,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows;
+using System.Windows.Media.Animation;
 
 namespace PLCTool.ViewModels.MonitorManageViewModel
 {
@@ -26,6 +28,7 @@ namespace PLCTool.ViewModels.MonitorManageViewModel
             _iBasPlcItemConfigService = iBasPlcItemConfigService;
             _mapper = mapper;
             GetPLCConfig();
+            ReadPLCRealValue();
         }
         #region 私有方法
         /// <summary>
@@ -49,6 +52,43 @@ namespace PLCTool.ViewModels.MonitorManageViewModel
             get { return plcItemList; }
             set { plcItemList = value; RaisePropertyChanged(); }
         }
+        private void ReadPLCRealValue()
+        {
+                Task.Run(async () =>
+                {
+                    while(true)
+                    { 
+                        //更新界面上的值
+                        Application.Current.Dispatcher.Invoke(() =>
+                        {
+                            foreach (var item in PLCItemList)
+                            {
+                                string plcAddr = item.PlcAddress;
+                                string plcAddType = item.PlcAddType;
+                                switch (plcAddType)
+                                {
+                                    case "bool":
+                                        item.RealValue = PLCCom.GetInstance().ReadPlcObject(plcAddr, VarType.Bit);
+                                        break;
+                                    case "word":
+                                        item.RealValue = PLCCom.GetInstance().ReadPlcObject(plcAddr, VarType.Word);
+                                        break;
+                                    case "dword":
+                                        item.RealValue = PLCCom.GetInstance().ReadPlcObject(plcAddr, VarType.DWord);
+                                        break;
+                                    case "real":
+                                        item.RealValue = PLCCom.GetInstance().ReadPlcObject(plcAddr, VarType.Real);
+                                        break;
+                                }
+
+                            }
+                        });
+                     
+                        await Task.Delay(5000);
+                    }
+
+                });
+        }
         #endregion
   
     }

+ 47 - 18
BlankApp1/BlankApp1/ViewModels/MonitorManageViewModel/PLCWriteViewModel.cs

@@ -2,6 +2,8 @@
 using BizService;
 using Model.Dto;
 using Model.Entities;
+using PLCTool.Common;
+using Prism.Commands;
 using Prism.Mvvm;
 using System;
 using System.Collections.Generic;
@@ -24,9 +26,37 @@ namespace PLCTool.ViewModels.MonitorManageViewModel
 
             _iBasPlcItemConfigService = iBasPlcItemConfigService;
             _mapper = mapper;
+            WriteCommand = new DelegateCommand<object>(WriteToPlc);
             GetPLCConfig();
         }
+
+
         #region 私有方法
+
+        private void WriteToPlc(object obj)
+        {
+            foreach (var item in PLCItemList)
+            {
+                string plcAddr = item.PlcAddress;
+                string plcAddType = item.PlcAddType;
+                switch (plcAddType)
+                {
+                    case "bool":
+                        bool isResult=PLCCom.GetInstance().WritePlcObject(plcAddr, VarType.Bit, WritePLCValue);
+                        break;
+                    case "word":
+                        bool isResult2 = PLCCom.GetInstance().WritePlcObject(plcAddr, VarType.Word, WritePLCValue);
+                        break;
+                    case "dword":
+                        bool isResult3 = PLCCom.GetInstance().WritePlcObject(plcAddr, VarType.DWord, WritePLCValue);
+                        break;
+                    case "real":
+                        bool isResult4 = PLCCom.GetInstance().WritePlcObject(plcAddr, VarType.Real, WritePLCValue);
+                        break;
+                }
+
+            }
+        }
         /// <summary>
         /// 获取PLC配置
         /// </summary>
@@ -40,31 +70,30 @@ namespace PLCTool.ViewModels.MonitorManageViewModel
             }
         }
 
-        private void ReadPLCValue()
-        {
-            Task.Run(async () =>
-            {
-                while (true)
-                {
-                    //更新界面上的值
-                    Application.Current.Dispatcher.Invoke(() =>
-                    {
-
-                    });
-                    await Task.Delay(5000);
-                }
-
-            });
-
-        }
+    
         #endregion
-        #region 命令绑定
+        #region 数据绑定
         private ObservableCollection<BasPlcItemConfigDto> plcItemList = new ObservableCollection<BasPlcItemConfigDto>();
         public ObservableCollection<BasPlcItemConfigDto> PLCItemList
         {
             get { return plcItemList; }
             set { plcItemList = value; RaisePropertyChanged(); }
         }
+
+        /// <summary>
+        /// 写入值
+        /// </summary>
+        private string writePLCValue;
+        public string WritePLCValue
+        {
+            get { return writePLCValue; }
+            set { writePLCValue = value; RaisePropertyChanged(); }
+        }
+        #endregion
+
+        #region 命令绑定
+
+        public DelegateCommand<object> WriteCommand { set; get; }
         #endregion
     }
 }

+ 1 - 1
BlankApp1/BlankApp1/Views/BusinessManageView/ManualTestView.xaml

@@ -271,7 +271,7 @@
         </Grid>
         <UniformGrid  Grid.Row="5" Columns="4">
             <Button  Content="开始检测" Width="80"    Command="{Binding StartCommand}" Style="{StaticResource NormalButtonStyle}" />
-            <Button  Content="上一步" Width="80"    Command="{Binding PriviousCommand}" Style="{StaticResource NormalButtonStyle}" />
+            <Button  Content="上一步" Width="80"    Command="{Binding PreviousCommand}" Style="{StaticResource NormalButtonStyle}" />
             <Button  Content="下一步" Width="80"    Command="{Binding NextCommand}" Style="{StaticResource NormalButtonStyle}" />
             <Button  Content="完成" Width="80"    Command="{Binding DoneCommand}" Style="{StaticResource NormalButtonStyle}" />
         </UniformGrid>

+ 2 - 2
BlankApp1/BlankApp1/Views/MonitorManageView/PLCWriteView.xaml

@@ -21,11 +21,11 @@
                     <DataGridTemplateColumn.CellTemplate>
                         <DataTemplate>
                             <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
-                                <TextBox  Width="60"  HorizontalContentAlignment ="Left" Foreground="Black" Height="5" 
+                                <TextBox  Width="60" Text="{Binding WritePLCValue}"  HorizontalContentAlignment ="Left" Foreground="Black" Height="5" 
                                         Cursor="Hand" Margin="0,0,2,0" >
                                 </TextBox>
                                 <Button  Width="auto" Background="Transparent" HorizontalContentAlignment ="Left" Foreground="Black" Height="25" BorderThickness="0"
-                                    Command="{Binding DataContext.DeleteCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}"  Cursor="Hand" >
+                                    Command="{Binding DataContext.WriteCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}"  Cursor="Hand" >
                                     <StackPanel Orientation="Horizontal">
                                         <TextBlock  Text="写入" VerticalAlignment="Center" Foreground="Blue"/>
                                     </StackPanel>