Forráskód Böngészése

添加异常捕获

ltwork 1 éve
szülő
commit
c640023fde

+ 36 - 36
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/AddDetailViewModel.cs

@@ -43,41 +43,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
 
         }
 
-        private void LostFocusPLCValue()
-        {
-            if(string.IsNullOrEmpty(PLCValue))
-            {
-                return;
-            }
-            if (!IsInteger(PLCValue))
-            {
-                MessageBox.Show("请填写正整数!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
-                return;
-            }
-        }
-        /// <summary>
-        /// 判断输入的数据
-        /// </summary>
-        /// <param name="input"></param>
-        /// <returns></returns>
-        private bool IsInteger(string input)
-        {
-            Regex regex = new Regex(@"^[0-9]\d*$");
-            return regex.IsMatch(input);
-        }
-        private void LostFocus()
-        {
-            var findResult = plcConfigs?.FirstOrDefault(x => x.PlcAddress == PLCAddress);
-            if(findResult != null) 
-            {
-                id = findResult.Id;
-                PLCItem = findResult.PlcItem;
-                SelectPLCType = findResult.PlcAddType;
-                PLCValue = findResult.PlcValue;
-                PLCDescribe = findResult.Remark;
-            }
-            
-        }
+     
 
 
 
@@ -124,7 +90,41 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
         #endregion
         #region 私有方法
 
-     
+        private void LostFocusPLCValue()
+        {
+            if (string.IsNullOrEmpty(PLCValue))
+            {
+                return;
+            }
+            if (!IsInteger(PLCValue))
+            {
+                MessageBox.Show("请填写正整数!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+        }
+        /// <summary>
+        /// 判断输入的数据
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        private bool IsInteger(string input)
+        {
+            Regex regex = new Regex(@"^[0-9]\d*$");
+            return regex.IsMatch(input);
+        }
+        private void LostFocus()
+        {
+            var findResult = plcConfigs?.FirstOrDefault(x => x.PlcAddress == PLCAddress);
+            if (findResult != null)
+            {
+                id = findResult.Id;
+                PLCItem = findResult.PlcItem;
+                SelectPLCType = findResult.PlcAddType;
+                PLCValue = findResult.PlcValue;
+                PLCDescribe = findResult.Remark;
+            }
+
+        }
         private void Close()
         {
             RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));

+ 36 - 25
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/AddSchViewModel.cs

@@ -78,28 +78,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             GetConfigOption();
         }
 
-        private void Delete(object obj)
-        {
-            int id = Convert.ToInt32(obj);
-            bool isResult=_basicPlcTestSchemeDtlService.Delete(id);
-            if(isResult)
-            {
-                MessageBox.Show("删除成功!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
-                //更新已有的测试项
-                GetExistSchs();
-            }
-           
-        }
-
-        private void CheckDetail(object obj)
-        {
-     
-        }
-
-
-
-
-
+ 
 
         #region idialog接口实现
         public string Title { set; get; } = "新增方案";
@@ -124,7 +103,26 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
         {
             _regionManager.Regions["ContentRegion"].RequestNavigate("BaseConfigView");
         }
- 
+        private void Delete(object obj)
+        {
+            int id = Convert.ToInt32(obj);
+            bool isResult = _basicPlcTestSchemeDtlService.Delete(id);
+            if (isResult)
+            {
+                MessageBox.Show("删除成功!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
+                _logger.LogInformation($"删除测试项,ID为{id}");
+                //更新已有的测试项
+                GetExistSchs();
+            }
+
+        }
+
+        private void CheckDetail(object obj)
+        {
+
+        }
+
+
         /// <summary>
         /// 保存所有测试项
         /// </summary>
@@ -174,6 +172,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
                 //发布消息
                 _aggregator.GetEvent<ChangeEvent>().Publish("Change");
                 _regionManager.Regions["ContentRegion"].RequestNavigate("BaseConfigView");
+                _logger.LogInformation($"保存测试方案,方案名{ScheduleName}");
             }
         }
         /// <summary>
@@ -315,6 +314,11 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             //清空测试项的内容
             CleanContent();
         }
+        /// <summary>
+        /// 新增PLC详情
+        /// </summary>
+        /// <param name="obj"></param>
+        /// <param name="conList"></param>
         private void OpenEditDialog(Object obj, ObservableCollection<BasPlcItemConfigDto> conList)
         {
             int id = Convert.ToInt32(obj);
@@ -358,12 +362,18 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
 
 
         }
-
+        /// <summary>
+        /// 输出项编辑
+        /// </summary>
+        /// <param name="obj"></param>
         private void EditOut(object obj)
         {
             OpenEditDialog(obj, OutConList);
         }
-
+        /// <summary>
+        /// 输入项编辑
+        /// </summary>
+        /// <param name="obj"></param>
         private void EditIn(object obj)
         {
             OpenEditDialog(obj, InConList);
@@ -632,6 +642,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
                 GetExistSchs();
                 //清空上次的内容
                 CleanContent();
+                _logger.LogInformation($"新增测试项{TestName},方案名称为{ScheduleName}");
             }
             catch (Exception ex)
             {

+ 16 - 9
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/BaseConfigViewModel.cs

@@ -155,16 +155,23 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
                 }
 
             }
-       
 
-            conditionConfig = (from a in allConfigList
-                                      where (EndTime == string.Empty ? true : (a.CreateTime < Convert.ToDateTime(EndTime)) && (Convert.ToDateTime(StartTime) < a.CreateTime))
-                                       && (string.IsNullOrEmpty(ScheduleName) ? true : (a.SchemeName == ScheduleName))
-                                         && (DeviceKindName == "---") ? true : (a.DeviceKindName == DeviceKindName)
-                               select a).ToList();
-            //默认显示的第一页
-            conditionConfig = conditionConfig.OrderBy(x => x.SchemeName).ThenBy(x => x.SchemeId).ToList();
-            Getpage();
+            try
+            {
+                conditionConfig = (from a in allConfigList
+                                   where (EndTime == string.Empty ? true : (a.CreateTime < Convert.ToDateTime(EndTime)) && (Convert.ToDateTime(StartTime) < a.CreateTime))
+                                    && (string.IsNullOrEmpty(ScheduleName) ? true : (a.SchemeName == ScheduleName))
+                                      && (DeviceKindName == "---") ? true : (a.DeviceKindName == DeviceKindName)
+                                   select a).ToList();
+                //默认显示的第一页
+                conditionConfig = conditionConfig.OrderBy(x => x.SchemeName).ThenBy(x => x.SchemeId).ToList();
+                Getpage();
+            }
+            catch(Exception ex)
+            {
+                _logger.LogError(ex.ToString());
+            }
+
             //BaseConfigList = new ObservableCollection<BasicPlcTestSchemeDto>(conditionConfig);
         }
         /// <summary>

+ 17 - 10
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/ProjectViewModel.cs

@@ -155,16 +155,23 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
                 }
               
             }
-           
-            conditionProject = (from a in allProjectList
-                               where (string.IsNullOrEmpty(ProjectNo) ? true : (a.ProjectNo == ProjectNo))
-                               && (string.IsNullOrEmpty(ProjectName) ? true : (a.ProjectName == ProjectName))
-                                 && (string.IsNullOrEmpty(ProjectLeader) ? true : (a.ProjectLeader == ProjectLeader))
-                                 && (EndTime == string.Empty ? true : (a.CreateTime < Convert.ToDateTime(EndTime)) && (Convert.ToDateTime(StartTime) < a.CreateTime))
-                                select a).ToList();
-            //默认显示的第一页
-            conditionProject = conditionProject.OrderBy(x => x.ProjectId).ToList();
-            Getpage();
+            try
+            {
+                conditionProject = (from a in allProjectList
+                                    where (string.IsNullOrEmpty(ProjectNo) ? true : (a.ProjectNo == ProjectNo))
+                                    && (string.IsNullOrEmpty(ProjectName) ? true : (a.ProjectName == ProjectName))
+                                      && (string.IsNullOrEmpty(ProjectLeader) ? true : (a.ProjectLeader == ProjectLeader))
+                                      && (EndTime == string.Empty ? true : (a.CreateTime < Convert.ToDateTime(EndTime)) && (Convert.ToDateTime(StartTime) < a.CreateTime))
+                                    select a).ToList();
+                //默认显示的第一页
+                conditionProject = conditionProject.OrderBy(x => x.ProjectId).ToList();
+                Getpage();
+            }
+            catch(Exception ex)
+            {
+                _logger.LogError(ex.ToString());
+            }
+          
         }
 
         private void Export(string obj)

+ 6 - 3
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/DeviceResultCardViewModel.cs

@@ -8,15 +8,18 @@ using System.Text;
 using System.Threading.Tasks;
 using System.Windows.Controls;
 using System.Windows;
+using Microsoft.Extensions.Logging;
 
 namespace PLCTool.ViewModels.BusinessManageViewModel
 {
     public class DeviceResultCardViewModel : BindableBase
     {
         private readonly IRegionManager _regionManager;
-        public DeviceResultCardViewModel(IRegionManager regionManager)
+        private readonly ILogger _logger;
+        public DeviceResultCardViewModel(IRegionManager regionManager, ILogger logger)
         {
             this._regionManager = regionManager;
+            this._logger = logger;
             DoubleClickCommand = new DelegateCommand<object>(DoubleClickCard);
         }
 
@@ -44,9 +47,9 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
 
                 }, parm);
             }
-            catch
+            catch (Exception ex)
             {
-
+                _logger.LogError(ex.ToString());
             }
         }
         #region 命令绑定

+ 93 - 79
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/DeviceTestViewModel.cs

@@ -217,16 +217,24 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                 }
 
             }
-            conditionDevices = (from a in allDeviceList
-                                where (string.IsNullOrEmpty(DeviceName) ? true : (a.DeviceName == DeviceName))
-                                && (string.IsNullOrEmpty(DeviceNo) ? true : (a.DeviceNo == DeviceNo))
-                                 && ((DeviceKindName == "---") ? true : (a.DeviceKindName == DeviceKindName))
-                                   && ((ProjectName == "---") ? true : (a.ProjectName == ProjectName))
-                                     && (EndTime == string.Empty ? true : (a.CreateTime < Convert.ToDateTime(EndTime)) && (Convert.ToDateTime(StartTime) < a.CreateTime))
-                                select a).ToList();
-            //默认显示的第一页
-            conditionDevices = conditionDevices.OrderBy(x => x.DeviceId).ToList();
-            Getpage();
+            try
+            {
+                conditionDevices = (from a in allDeviceList
+                                    where (string.IsNullOrEmpty(DeviceName) ? true : (a.DeviceName == DeviceName))
+                                    && (string.IsNullOrEmpty(DeviceNo) ? true : (a.DeviceNo == DeviceNo))
+                                     && ((DeviceKindName == "---") ? true : (a.DeviceKindName == DeviceKindName))
+                                       && ((ProjectName == "---") ? true : (a.ProjectName == ProjectName))
+                                         && (EndTime == string.Empty ? true : (a.CreateTime < Convert.ToDateTime(EndTime)) && (Convert.ToDateTime(StartTime) < a.CreateTime))
+                                    select a).ToList();
+                //默认显示的第一页
+                conditionDevices = conditionDevices.OrderBy(x => x.DeviceId).ToList();
+                Getpage();
+            }
+            catch (Exception ex)
+            {
+                _logger.LogError(ex.ToString());
+            }
+           
         }
 
         private void Export(string obj)
@@ -283,85 +291,91 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
             //所有测试方案
             var schlist = _basicPlcTestSchemeService.QueryList();
             var schDtoList = _mapper.Map<List<bas_plc_test_scheme>, List<BasicPlcTestSchemeDto>>(schlist);
-            
-
-            foreach (var item in allDeviceKinds)
+            try
             {
-             
 
-                string projectName = _iBasicProjectService.Find((int)item.ProjectId)?.project_name;
-                string deviceKindName = _iBasicDeviceKindService.Find((int)item.DeviceKindId)?.devicekind_name;
+                foreach (var item in allDeviceKinds)
+                {
 
 
-                string deviceKind = _iBasicDeviceKindService.Find((int)item.DeviceKindId)?.devicekind_name;
-                //在测试方案中查找此设备类型的所有方案
-                var schs = schDtoList.FindAll(x => x.DeviceKindName == deviceKind);
-                //设备方案
-                foreach (var sch in schs)
-                {
-                    //测试方案是否测试
-                    string testStu = "未测试";
-                    var testStatusResult = _iBizTestRecordService.FindRecorddByDeviceIdAndSchname(item.DeviceId, sch.SchemeName);
-                    if (testStatusResult != null)
-                    {
-                        testStu = "已测试";
-                    }
+                    string projectName = _iBasicProjectService.Find((int)item.ProjectId)?.project_name;
+                    string deviceKindName = _iBasicDeviceKindService.Find((int)item.DeviceKindId)?.devicekind_name;
+
 
-                    allDeviceAndSchList.Add(new BasDeviceWithSchModel()
+                    string deviceKind = _iBasicDeviceKindService.Find((int)item.DeviceKindId)?.devicekind_name;
+                    //在测试方案中查找此设备类型的所有方案
+                    var schs = schDtoList.FindAll(x => x.DeviceKindName == deviceKind);
+                    //设备方案
+                    foreach (var sch in schs)
                     {
-                        DeviceId = item.DeviceId,
-                        DeviceNo = item.DeviceNo,
-                        DeviceName = item.DeviceName,
-                        DeviceKindName = deviceKindName,
-                        ProjectName = projectName,
-                        SchemeName = sch.SchemeName,
-                        SchemeId = sch.SchemeId,
-                        TestStatus=testStu,
-                        CreateBy=sch.CreateBy,
-                        CreateTime = item.CreateTime,
-                    });
-                 
-                }
-                //查看测试记录中是否有测试
-                string totalTestStu = "未测试";
-                var resultTest=_iBizTestRecordService.FindRecordByDeviceId(item.DeviceId);
-                if(resultTest.Count!=0)
-                {
-                    totalTestStu = "已测试";
-                }
-                //只添加选择的项目
-                if (projectName == selectProjectName)
-                {
-                    allDeviceList.Add(new BasDeviceWithSchModel()
+                        //测试方案是否测试
+                        string testStu = "未测试";
+                        var testStatusResult = _iBizTestRecordService.FindRecorddByDeviceIdAndSchname(item.DeviceId, sch.SchemeName);
+                        if (testStatusResult != null)
+                        {
+                            testStu = "已测试";
+                        }
+
+                        allDeviceAndSchList.Add(new BasDeviceWithSchModel()
+                        {
+                            DeviceId = item.DeviceId,
+                            DeviceNo = item.DeviceNo,
+                            DeviceName = item.DeviceName,
+                            DeviceKindName = deviceKindName,
+                            ProjectName = projectName,
+                            SchemeName = sch.SchemeName,
+                            SchemeId = sch.SchemeId,
+                            TestStatus = testStu,
+                            CreateBy = sch.CreateBy,
+                            CreateTime = item.CreateTime,
+                        });
+
+                    }
+                    //查看测试记录中是否有测试
+                    string totalTestStu = "未测试";
+                    var resultTest = _iBizTestRecordService.FindRecordByDeviceId(item.DeviceId);
+                    if (resultTest.Count != 0)
                     {
-                        DeviceId = item.DeviceId,
-                        DeviceNo = item.DeviceNo,
-                        DeviceName = item.DeviceName,
-                        DeviceKindName = deviceKindName,
-                        ProjectName = projectName,
-                        TotalTestStatus = totalTestStu,
-                        CreateBy = item.CreateBy,
-                        CreateTime = item.CreateTime,
-                     
-                    });
-                    conditionDevices.Add(new BasDeviceWithSchModel()
+                        totalTestStu = "已测试";
+                    }
+                    //只添加选择的项目
+                    if (projectName == selectProjectName)
                     {
-                        DeviceId = item.DeviceId,
-                        DeviceNo = item.DeviceNo,
-                        DeviceName = item.DeviceName,
-                        DeviceKindName = deviceKindName,
-                        ProjectName = projectName,
-                        TotalTestStatus = totalTestStu,
-                        CreateBy = item.CreateBy,
-                        CreateTime = item.CreateTime,
-
-                    });
-                }
+                        allDeviceList.Add(new BasDeviceWithSchModel()
+                        {
+                            DeviceId = item.DeviceId,
+                            DeviceNo = item.DeviceNo,
+                            DeviceName = item.DeviceName,
+                            DeviceKindName = deviceKindName,
+                            ProjectName = projectName,
+                            TotalTestStatus = totalTestStu,
+                            CreateBy = item.CreateBy,
+                            CreateTime = item.CreateTime,
+
+                        });
+                        conditionDevices.Add(new BasDeviceWithSchModel()
+                        {
+                            DeviceId = item.DeviceId,
+                            DeviceNo = item.DeviceNo,
+                            DeviceName = item.DeviceName,
+                            DeviceKindName = deviceKindName,
+                            ProjectName = projectName,
+                            TotalTestStatus = totalTestStu,
+                            CreateBy = item.CreateBy,
+                            CreateTime = item.CreateTime,
+
+                        });
+                    }
 
-          
+
+                }
+                conditionDevices = conditionDevices.OrderBy(x => x.DeviceId).ToList();
+                Getpage();
+            }
+            catch(Exception ex)
+            {
+                _logger.LogError(ex.ToString());
             }
-            conditionDevices = conditionDevices.OrderBy(x => x.DeviceId).ToList();
-            Getpage();
         }
         /// <summary>
         /// 获取页面

+ 132 - 119
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/ProjectTestResultViewModel.cs

@@ -67,13 +67,21 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
 
         private void Query(object obj)
         {
-            var conditions = (from a in allProjectResultPicList
-                              where (string.IsNullOrEmpty(ProjectNo) ? true : (a.txtProjectNo.Text == ProjectNo))
-                              && (string.IsNullOrEmpty(ProjectName) ? true : (a.txtName.Text == ProjectName))
-                                && (string.IsNullOrEmpty(ProjectLeader) ? true : (a.txtProjectLeader.Text == ProjectLeader))
-                                 && (EndTime == string.Empty ? true : (Convert.ToDateTime(a.txtCreateTime.Text) < Convert.ToDateTime(EndTime)) && (Convert.ToDateTime(StartTime) < Convert.ToDateTime(a.txtCreateTime.Text)))
-                              select a).ToList();
-            ProjectResultPicList = new ObservableCollection<DeviceResultCardView>(conditions);
+            try
+            {
+                var conditions = (from a in allProjectResultPicList
+                                  where (string.IsNullOrEmpty(ProjectNo) ? true : (a.txtProjectNo.Text == ProjectNo))
+                                  && (string.IsNullOrEmpty(ProjectName) ? true : (a.txtName.Text == ProjectName))
+                                    && (string.IsNullOrEmpty(ProjectLeader) ? true : (a.txtProjectLeader.Text == ProjectLeader))
+                                     && (EndTime == string.Empty ? true : (Convert.ToDateTime(a.txtCreateTime.Text) < Convert.ToDateTime(EndTime)) && (Convert.ToDateTime(StartTime) < Convert.ToDateTime(a.txtCreateTime.Text)))
+                                  select a).ToList();
+                ProjectResultPicList = new ObservableCollection<DeviceResultCardView>(conditions);
+            }
+            catch (Exception ex)
+            {
+                _logger.LogError(ex.ToString());
+            }
+          
         }
 
         private void OnLoad()
@@ -97,139 +105,144 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
             //所有测试方案
             var schlist = _basicPlcTestSchemeService.QueryList();
             var schDtoList = _mapper.Map<List<bas_plc_test_scheme>, List<BasicPlcTestSchemeDto>>(schlist);
-            //测试记录中的所有设备
-            var deviceIds = _iBizTestRecordService.QueryList().Select(X => X.device_id).Distinct();
-            foreach (var deviceId in deviceIds)
+            try
             {
-                List<DateTime> startDateTimes = new List<DateTime>();
-                var deviceMsg = _iBasicDeviceService.Find(((int)deviceId));
-                if (deviceMsg != null)
+                //测试记录中的所有设备
+                var deviceIds = _iBizTestRecordService.QueryList().Select(X => X.device_id).Distinct();
+                foreach (var deviceId in deviceIds)
                 {
-                    string deviceKind = _iBasicDeviceKindService.Find((int)deviceMsg.device_kind_id)?.devicekind_name;
-                    string projectName = _iBasicProjectService.Find((int)deviceMsg.project_id)?.project_name;
-                    //记录设备下的方案通过个数
-                    int deviceCountResult = 0;
-                    string deviceTestResult = string.Empty;
-                    //查找哦记录有的方案
-
-                    var recordMsgs = _iBizTestRecordService.FindRecordByDeviceId(deviceId);
-                    foreach (var sch in recordMsgs)
+                    List<DateTime> startDateTimes = new List<DateTime>();
+                    var deviceMsg = _iBasicDeviceService.Find(((int)deviceId));
+                    if (deviceMsg != null)
                     {
+                        string deviceKind = _iBasicDeviceKindService.Find((int)deviceMsg.device_kind_id)?.devicekind_name;
+                        string projectName = _iBasicProjectService.Find((int)deviceMsg.project_id)?.project_name;
+                        //记录设备下的方案通过个数
+                        int deviceCountResult = 0;
+                        string deviceTestResult = string.Empty;
+                        //查找哦记录有的方案
 
-                        long schId = (long)_basicPlcTestSchemeService.FindByNameAndType(sch.scheme_name, deviceKind)?.scheme_id;
-                        //计算测试结果
-                        string testResult = string.Empty;
-                        int countResult = 0;
-                        var records = _iBizTestRecordDtlService.FindRecordDetailByRecordID(sch.record_id);
-                        //
-                        var schDtls = _iBasicPlcTestSchemeDtlService.FindAllBySchId(schId);
-                        //循环所有测试项,有一个不合格,则整个测试方案不合格
-                        foreach (var dtl in schDtls)
+                        var recordMsgs = _iBizTestRecordService.FindRecordByDeviceId(deviceId);
+                        foreach (var sch in recordMsgs)
                         {
-                            //选取开始时间最大的一个数据,查看测试结果
-                            long schDtId = dtl.scheme_dtl_id;
-                            var findRecords = records.FindAll(x => x.scheme_dtl_id == schDtId).OrderByDescending(x => x.start_test_time).ToArray();
-                            if (findRecords.Length > 0)
+
+                            long schId = (long)_basicPlcTestSchemeService.FindByNameAndType(sch.scheme_name, deviceKind)?.scheme_id;
+                            //计算测试结果
+                            string testResult = string.Empty;
+                            int countResult = 0;
+                            var records = _iBizTestRecordDtlService.FindRecordDetailByRecordID(sch.record_id);
+                            //
+                            var schDtls = _iBasicPlcTestSchemeDtlService.FindAllBySchId(schId);
+                            //循环所有测试项,有一个不合格,则整个测试方案不合格
+                            foreach (var dtl in schDtls)
                             {
-                                int result = (int)findRecords[0]?.test_result.Value;
-                                if (result == 0)
+                                //选取开始时间最大的一个数据,查看测试结果
+                                long schDtId = dtl.scheme_dtl_id;
+                                var findRecords = records.FindAll(x => x.scheme_dtl_id == schDtId).OrderByDescending(x => x.start_test_time).ToArray();
+                                if (findRecords.Length > 0)
                                 {
-                                    testResult = "不通过";
-                                    break;
-                                }
-                                else
-                                {
-                                    countResult++;
+                                    int result = (int)findRecords[0]?.test_result.Value;
+                                    if (result == 0)
+                                    {
+                                        testResult = "不通过";
+                                        break;
+                                    }
+                                    else
+                                    {
+                                        countResult++;
+                                    }
                                 }
                             }
+                            //测试结果
+                            if (countResult == schDtls.Count)
+                            {
+                                testResult = "通过";
+                            }
+
+                            //计算这个设备是否通过
+                            if (testResult == "通过")
+                            {
+                                deviceCountResult++;
+                            }
+                            //加入时间集合
+                            startDateTimes.Add(sch.start_test_time.Value);
                         }
-                        //测试结果
-                        if (countResult == schDtls.Count)
+                        //计算这个设备是否所有的方案都通过
+                        if ((deviceCountResult != 0) && (deviceCountResult == recordMsgs.Count))
                         {
-                            testResult = "通过";
+                            deviceTestResult = "通过";
                         }
-
-                        //计算这个设备是否通过
-                        if (testResult == "通过")
+                        else
                         {
-                            deviceCountResult++;
+                            deviceTestResult = "不通过";
                         }
-                        //加入时间集合
-                        startDateTimes.Add(sch.start_test_time.Value);
-                    }
-                    //计算这个设备是否所有的方案都通过
-                    if ((deviceCountResult != 0) && (deviceCountResult == recordMsgs.Count))
-                    {
-                        deviceTestResult = "通过";
-                    }
-                    else
-                    {
-                        deviceTestResult = "不通过";
+                        //这里不添加方案名称
+                        allDeviceList.Add(new DeviceDtlWithResultModel()
+                        {
+                            ProjectId = deviceMsg.project_id,
+                            DeviceId = deviceMsg.device_id,
+                            DeviceNo = deviceMsg.device_no,
+                            DeviceName = deviceMsg.device_name,
+                            DeviceKindName = deviceKind,
+                            ProjectName = projectName,
+                            StartTestTime = startDateTimes.Min(),//取最小时间
+                            TestResult = deviceTestResult
+                        });
+
                     }
-                    //这里不添加方案名称
-                    allDeviceList.Add(new DeviceDtlWithResultModel()
-                    {
-                        ProjectId= deviceMsg.project_id,
-                        DeviceId = deviceMsg.device_id,
-                        DeviceNo = deviceMsg.device_no,
-                        DeviceName = deviceMsg.device_name,
-                        DeviceKindName = deviceKind,
-                        ProjectName = projectName,
-                        StartTestTime = startDateTimes.Min(),//取最小时间
-                        TestResult = deviceTestResult
-                    }); 
-            
-                }
 
-            }
+                }
 
-            //所有新项目
-            List<string> projectNames = allDeviceList.Select(x => x.ProjectName).Distinct().ToList();
-            foreach (var project in projectNames)
-            {
-                int projectId =(int) allDeviceList?.FirstOrDefault(x => x.ProjectName == project)?.ProjectId;
-                //总设备
-                int totalDevice=(int)_iBasicDeviceService.QueryList()?.FindAll(x=>x.project_id== projectId).Count();
-                //已测试设备数
-                int deviceTestCount =(int)allDeviceList?.FindAll(x => x.ProjectName == project)?.Select(x => x.DeviceId)?.Distinct().Count();
+                //所有新项目
+                List<string> projectNames = allDeviceList.Select(x => x.ProjectName).Distinct().ToList();
+                foreach (var project in projectNames)
+                {
+                    int projectId = (int)allDeviceList?.FirstOrDefault(x => x.ProjectName == project)?.ProjectId;
+                    //总设备
+                    int totalDevice = (int)_iBasicDeviceService.QueryList()?.FindAll(x => x.project_id == projectId).Count();
+                    //已测试设备数
+                    int deviceTestCount = (int)allDeviceList?.FindAll(x => x.ProjectName == project)?.Select(x => x.DeviceId)?.Distinct().Count();
 
-                int passCount=(int)allDeviceList?.FindAll(x => (x.ProjectName == project)&&(x.TestResult=="通过")).Count;
-                int noPassCount = (int)allDeviceList?.FindAll(x => (x.ProjectName == project) && (x.TestResult == "不通过")).Count;
-                //添加卡片
-                DeviceResultCardView deviceCard = new DeviceResultCardView();
-                //创建时间
-                deviceCard.txtCreateTime.Text = _iBasicProjectService.FindByProjectName(project)?.create_time.ToString();
-                deviceCard.txtName.Text = project;
-                deviceCard.txtProjectNo.Text = _iBasicProjectService.FindByProjectName(project)?.project_no;
-                deviceCard.txtProjectLeader.Text = _iBasicProjectService.FindByProjectName(project)?.project_leader;
-                //总设备数量
-                deviceCard.txtDeviceCount.Text = totalDevice.ToString()+" 台";
-                deviceCard.txtTestCount.Text = deviceTestCount.ToString()+" 台";
-                deviceCard.txtPassCount.Text = passCount.ToString()+" 台";
-                deviceCard.txtNoPassCount.Text = noPassCount.ToString() + " 台";
-                //赋值
-                allProjectResultPicList.Add(deviceCard);
-            }
-            foreach (var item in allProjectResultPicList)
-            {
-                ProjectResultPicList.Add(item);
-            }
-            //计算行数
-            if (projectNames.Count % eachColumNum == 0)
-            {
-                RowsCount = projectNames.Count / eachColumNum;
-            }
-            else
-            {
-                RowsCount = projectNames.Count / eachColumNum + 1;
+                    int passCount = (int)allDeviceList?.FindAll(x => (x.ProjectName == project) && (x.TestResult == "通过")).Count;
+                    int noPassCount = (int)allDeviceList?.FindAll(x => (x.ProjectName == project) && (x.TestResult == "不通过")).Count;
+                    //添加卡片
+                    DeviceResultCardView deviceCard = new DeviceResultCardView();
+                    //创建时间
+                    deviceCard.txtCreateTime.Text = _iBasicProjectService.FindByProjectName(project)?.create_time.ToString();
+                    deviceCard.txtName.Text = project;
+                    deviceCard.txtProjectNo.Text = _iBasicProjectService.FindByProjectName(project)?.project_no;
+                    deviceCard.txtProjectLeader.Text = _iBasicProjectService.FindByProjectName(project)?.project_leader;
+                    //总设备数量
+                    deviceCard.txtDeviceCount.Text = totalDevice.ToString() + " 台";
+                    deviceCard.txtTestCount.Text = deviceTestCount.ToString() + " 台";
+                    deviceCard.txtPassCount.Text = passCount.ToString() + " 台";
+                    deviceCard.txtNoPassCount.Text = noPassCount.ToString() + " 台";
+                    //赋值
+                    allProjectResultPicList.Add(deviceCard);
+                }
+                foreach (var item in allProjectResultPicList)
+                {
+                    ProjectResultPicList.Add(item);
+                }
+                //计算行数
+                if (projectNames.Count % eachColumNum == 0)
+                {
+                    RowsCount = projectNames.Count / eachColumNum;
+                }
+                else
+                {
+                    RowsCount = projectNames.Count / eachColumNum + 1;
+                }
+                if (RowsCount < 2)
+                {
+                    RowsCount = 2;
+                }
             }
-            if (RowsCount < 2)
+            catch (Exception ex)
             {
-                RowsCount = 2;
+                _logger.LogError(ex.ToString());
             }
-
-
-
+  
         }
         #endregion
 

+ 79 - 67
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/ProjectTestViewModel.cs

@@ -63,13 +63,21 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
 
         private void Query(object obj)
         {
-            var conditions = (from a in allProjectePicList
-                              where (string.IsNullOrEmpty(ProjectNo) ? true : (a.txtProjectNo.Text == ProjectNo))
-                              && (string.IsNullOrEmpty(ProjectName) ? true : (a.txtName.Text == ProjectName))
-                                && (string.IsNullOrEmpty(ProjectLeader) ? true : (a.txtPProjectLeader.Text == ProjectLeader))
-                                && (EndTime == string.Empty ? true : (Convert.ToDateTime(a.txtCreateTime.Text) < Convert.ToDateTime(EndTime)) && (Convert.ToDateTime(StartTime) < Convert.ToDateTime(a.txtCreateTime.Text)))
-                              select a).ToList();
-            ProjectePicList = new ObservableCollection<DeviceTestCardView>(conditions);
+            try
+            {
+                var conditions = (from a in allProjectePicList
+                                  where (string.IsNullOrEmpty(ProjectNo) ? true : (a.txtProjectNo.Text == ProjectNo))
+                                  && (string.IsNullOrEmpty(ProjectName) ? true : (a.txtName.Text == ProjectName))
+                                    && (string.IsNullOrEmpty(ProjectLeader) ? true : (a.txtPProjectLeader.Text == ProjectLeader))
+                                    && (EndTime == string.Empty ? true : (Convert.ToDateTime(a.txtCreateTime.Text) < Convert.ToDateTime(EndTime)) && (Convert.ToDateTime(StartTime) < Convert.ToDateTime(a.txtCreateTime.Text)))
+                                  select a).ToList();
+                ProjectePicList = new ObservableCollection<DeviceTestCardView>(conditions);
+            }
+            catch (Exception ex)
+            {
+                _logger.LogError(ex.ToString());
+            }
+           
         }
 
         private void OnLoad()
@@ -93,78 +101,82 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
             List<BasDeviceWithSchModel> allDeviceList = new List<BasDeviceWithSchModel>();//所有方案
             var devicelist = _iBasicDeviceService.QueryList();
             var allDeviceKinds = _mapper.Map<List<bas_device>, List<BasDeviceDto>>(devicelist);
-           
-            //遍历设备类型
-            foreach (var item in allDeviceKinds)
+            try
             {
-                string deviceKind = _iBasicDeviceKindService.Find((int)item.DeviceKindId)?.devicekind_name;
-                allDeviceList.Add(new BasDeviceWithSchModel()
+                //遍历设备类型
+                foreach (var item in allDeviceKinds)
                 {
-                    ProjectId = item.ProjectId,
-                    DeviceId = item.DeviceId,
-                    DeviceNo = item.DeviceNo,
-                    DeviceName = item.DeviceName,
-                    DeviceKindName = _iBasicDeviceKindService.Find((int)item.DeviceKindId)?.devicekind_name,
-                    ProjectName = _iBasicProjectService.Find((int)item.ProjectId)?.project_name,
-                
-                });
-               
+                    string deviceKind = _iBasicDeviceKindService.Find((int)item.DeviceKindId)?.devicekind_name;
+                    allDeviceList.Add(new BasDeviceWithSchModel()
+                    {
+                        ProjectId = item.ProjectId,
+                        DeviceId = item.DeviceId,
+                        DeviceNo = item.DeviceNo,
+                        DeviceName = item.DeviceName,
+                        DeviceKindName = _iBasicDeviceKindService.Find((int)item.DeviceKindId)?.devicekind_name,
+                        ProjectName = _iBasicProjectService.Find((int)item.ProjectId)?.project_name,
 
-            }
-            //所有的项目
-            List<string> projectNames = allDeviceList.Select(x => x.ProjectName).Distinct().ToList();
-            foreach (var project in projectNames)
-            {
-                int noTestCount = 0;
-             
-                var devices=allDeviceList?.FindAll(x => x.ProjectName == project)?.Select(x => x.DeviceId)?.Distinct();
-                //计算未测试的数量
-                foreach (var deviceid in devices)
+                    });
+
+
+                }
+                //所有的项目
+                List<string> projectNames = allDeviceList.Select(x => x.ProjectName).Distinct().ToList();
+                foreach (var project in projectNames)
                 {
-                    var findResult = _iBizTestRecordService.FindRecordByDeviceId(deviceid);
-                    if(findResult.Count==0)
+                    int noTestCount = 0;
+
+                    var devices = allDeviceList?.FindAll(x => x.ProjectName == project)?.Select(x => x.DeviceId)?.Distinct();
+                    //计算未测试的数量
+                    foreach (var deviceid in devices)
                     {
-                        noTestCount++;
+                        var findResult = _iBizTestRecordService.FindRecordByDeviceId(deviceid);
+                        if (findResult.Count == 0)
+                        {
+                            noTestCount++;
+                        }
                     }
+                    int deviceCount = devices.Count();
+                    //添加卡片
+                    DeviceTestCardView deviceCard = new DeviceTestCardView();
+                    //创建时间
+                    deviceCard.txtCreateTime.Text = _iBasicProjectService.FindByProjectName(project)?.create_time.ToString();
+                    deviceCard.txtName.Text = project;
+                    deviceCard.txtProjectNo.Text = _iBasicProjectService.FindByProjectName(project)?.project_no;
+                    deviceCard.txtPProjectLeader.Text = _iBasicProjectService.FindByProjectName(project)?.project_leader;
+                    deviceCard.txtDeviceCount.Text = deviceCount.ToString() + " 台"; ;
+                    deviceCard.txtNoTestCount.Text = noTestCount.ToString() + " 台";
+                    //赋值
+                    allProjectePicList.Add(deviceCard);
                 }
-                int deviceCount = devices.Count();
-                //添加卡片
-                DeviceTestCardView deviceCard = new DeviceTestCardView();
-                //创建时间
-                deviceCard.txtCreateTime.Text = _iBasicProjectService.FindByProjectName(project)?.create_time.ToString();
-                deviceCard.txtName.Text = project;
-                deviceCard.txtProjectNo.Text = _iBasicProjectService.FindByProjectName(project)?.project_no;
-                deviceCard.txtPProjectLeader.Text = _iBasicProjectService.FindByProjectName(project)?.project_leader;
-                deviceCard.txtDeviceCount.Text = deviceCount.ToString() + " 台"; ;
-                deviceCard.txtNoTestCount.Text = noTestCount.ToString() + " 台";
-                //赋值
-                allProjectePicList.Add(deviceCard);
-            }
-            
-            foreach (var item in allProjectePicList)
-             {
 
-                    
-                   ProjectePicList.Add(item);
-                    
+                foreach (var item in allProjectePicList)
+                {
+
+                    ProjectePicList.Add(item);
+
+                }
+
+                //计算行数
+                if (ProjectePicList.Count % eachColumNum == 0)
+                {
+                    RowsCount = ProjectePicList.Count / eachColumNum;
+                }
+                else
+                {
+                    RowsCount = ProjectePicList.Count / eachColumNum + 1;
+                }
+                if (RowsCount < 2)
+                {
+                    RowsCount = 2;
+                }
 
             }
-     
-            //计算行数
-            if (ProjectePicList.Count % eachColumNum == 0)
-            {
-                RowsCount = ProjectePicList.Count / eachColumNum;
-            }
-            else
-            {
-                RowsCount = ProjectePicList.Count / eachColumNum + 1;
-            }
-            if (RowsCount < 2)
+            catch (Exception ex)
             {
-                RowsCount = 2;
+                _logger.LogError(ex.ToString());
             }
-
-
+        
 
         }
         #endregion