ltwork 1 gadu atpakaļ
vecāks
revīzija
1b14017e64

+ 5 - 0
BlankApp1/BizService/BasicDeviceKindService.cs

@@ -13,5 +13,10 @@ namespace BizService
         {
             return base.GetList().Select(x=>x.devicekind_name).ToList();
         }
+
+        public bas_device_kind FindByDeviceKindName(string deviceKindName)
+        {
+            return base.GetFirst(x => x.devicekind_name == deviceKindName);
+        }
     }
 }

+ 5 - 0
BlankApp1/BizService/BasicProjectService.cs

@@ -14,5 +14,10 @@ namespace BizService
         {
             return base.GetList().Select(x => x.project_name).ToList();
         }
+
+        public bas_project FindByProjectName(string projectName)
+        {
+            return base.GetFirst(x => x.project_name == projectName);
+        }
     }
 }

+ 4 - 2
BlankApp1/BizService/BizTestRecordService.cs

@@ -9,9 +9,11 @@ namespace BizService
 {
     public class BizTestRecordService : BaseService<biz_test_record>, IBizTestRecordService
     {
-        public biz_test_record FindRecorddBySchname(string schName)
+        public biz_test_record FindRecorddByDeviceIdAndSchname(long deviceId, string schName)
         {
-            return base.GetFirst(x => x.scheme_name == schName);
+            return base.GetFirst(x => ((x.device_id == deviceId) &&(x.scheme_name == schName)));
         }
+
+     
     }
 }

+ 2 - 0
BlankApp1/BizService/IBasicDeviceKindService.cs

@@ -11,5 +11,7 @@ namespace BizService
     public interface IBasicDeviceKindService : IBaseService<bas_device_kind>
     {
         public List<string> FindAllDeviceKind();
+
+        public bas_device_kind FindByDeviceKindName(string deviceKindName);
     }
 }

+ 2 - 0
BlankApp1/BizService/IBasicProjectService.cs

@@ -11,5 +11,7 @@ namespace BizService
     public interface IBasicProjectService : IBaseService<bas_project>
     {
         public List<string> FindAllProject();
+        public bas_project FindByProjectName(string projectName);
+        
     }
 }

+ 2 - 2
BlankApp1/BizService/IBizTestRecordService.cs

@@ -9,10 +9,10 @@ namespace BizService
 {
     public interface IBizTestRecordService : IBaseService<biz_test_record>
     {   /// <summary>
-        /// 根据 方案名查找是 记录主表中是否有这个方案的记录
+        /// 根据 设备id和方案名查找是 记录主表中是否有这个方案的记录
         /// </summary>
         /// <param name="schemeId"></param>
         /// <returns></returns>
-        public biz_test_record FindRecorddBySchname(string schName);
+        public biz_test_record FindRecorddByDeviceIdAndSchname(long deviceId,string schName);
     }
 }

+ 3 - 2
BlankApp1/BlankApp1/Common/AutoMapper/AutoMapProfile.cs

@@ -56,6 +56,7 @@ namespace BlankApp1.Common.AutoMapper
             CreateMap<biz_test_record, BizTestRecordDto>()
                  .ForMember(dest => dest.RecordId, opt => opt.MapFrom(src => src.record_id))
                   .ForMember(dest => dest.RecordName, opt => opt.MapFrom(src => src.record_name))
+                   .ForMember(dest => dest.DeviceId, opt => opt.MapFrom(src => src.device_id))
                    .ForMember(dest => dest.SchemeName, opt => opt.MapFrom(src => src.scheme_name))
                     .ForMember(dest => dest.Tester, opt => opt.MapFrom(src => src.tester))
                      .ForMember(dest => dest.StartTestTime, opt => opt.MapFrom(src => src.start_test_time))
@@ -92,8 +93,8 @@ namespace BlankApp1.Common.AutoMapper
                  .ForMember(dest => dest.DeviceNo, opt => opt.MapFrom(src => src.device_no))
                .ForMember(dest => dest.DeviceNo, opt => opt.MapFrom(src => src.device_no))
                 .ForMember(dest => dest.DeviceName, opt => opt.MapFrom(src => src.device_name))
-                 .ForMember(dest => dest.ProjectName, opt => opt.MapFrom(src => src.project_id))
-                  .ForMember(dest => dest.DeviceKindName, opt => opt.MapFrom(src => src.device_kind_id))
+                 .ForMember(dest => dest.ProjectId, opt => opt.MapFrom(src => src.project_id))
+                  .ForMember(dest => dest.DeviceKindId, opt => opt.MapFrom(src => src.device_kind_id))
                       .ForMember(dest => dest.CreateBy, opt => opt.MapFrom(src => src.create_by))
                        .ForMember(dest => dest.CreateTime, opt => opt.MapFrom(src => src.create_time))
                         .ForMember(dest => dest.UpdateTime, opt => opt.MapFrom(src => src.update_time))

+ 32 - 0
BlankApp1/BlankApp1/Controls/Convert/TwoParConverter.cs

@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Data;
+
+namespace PLCTool.Controls.Convert
+{
+    class TwoParConverter : IMultiValueConverter
+    {
+        #region IMultiValueConverter Members
+
+        public static object ConverterObject;
+
+        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
+        {
+
+            return values.ToArray();
+        }
+
+        public object[] ConvertBack(object value, Type[] targetTypes,
+          object parameter, System.Globalization.CultureInfo culture)
+        {
+            throw new NotImplementedException();
+        }
+
+        #endregion
+    }
+
+
+}

+ 10 - 7
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/AddOrEditDeviceViewModel.cs

@@ -20,7 +20,8 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
     {
         private readonly IEventAggregator _aggregator;
         private readonly IBasicDeviceService _iBasicDeviceService;
-
+        private readonly IBasicDeviceKindService _iBasicDeviceKindService;
+          private readonly IBasicProjectService _iBasicProjectService;
         private readonly IMapper _mapper;
 
         private long id = 0;
@@ -28,12 +29,14 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
         {
             _aggregator = aggregator;
             _iBasicDeviceService = iBasicDeviceService;
+            _iBasicDeviceKindService = iBasicDeviceKindService;
+            _iBasicProjectService= iBasicProjectService;
             _mapper = mapper;
             CloseCommand = new DelegateCommand(Close);
             SureCommand = new DelegateCommand<string>(Sure);
             CancelCommand = new DelegateCommand(Close);
-            DeviceKindNameList= iBasicDeviceKindService.FindAllDeviceKind();
-            ProjectNameList = iBasicProjectService.FindAllProject();
+            DeviceKindNameList= _iBasicDeviceKindService.FindAllDeviceKind();
+            ProjectNameList = _iBasicProjectService.FindAllProject();
         }
 
 
@@ -70,8 +73,8 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
 
                         DeviceName = item.DeviceName;
                         DeviceNo = item.DeviceNo;
-                        ProjectName = item.ProjectName;
-                        DeviceKindName= item.DeviceKindName;
+                        ProjectName = _iBasicProjectService.Find((int)item.ProjectId)?.project_name;
+                        DeviceKindName = _iBasicDeviceKindService.Find((int)item.DeviceKindId)?.devicekind_name;
                         Remark = item.Remark;
 
                     }
@@ -118,8 +121,8 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             BasDeviceDto basDevice = new BasDeviceDto();
             basDevice.DeviceName = DeviceName;
             basDevice.DeviceNo = DeviceNo;
-            basDevice.ProjectName= ProjectName;
-            basDevice.DeviceKindName= DeviceKindName;
+            basDevice.ProjectId= (long)(_iBasicProjectService.FindByProjectName(ProjectName)?.project_id);
+            basDevice.DeviceKindId= (long)(_iBasicDeviceKindService.FindByDeviceKindName(DeviceKindName)?.devicekind_id);
             basDevice.Remark = Remark;
             DialogParameters parm = new DialogParameters();
             parm.Add("ReturnValue", basDevice);

+ 8 - 4
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/DeviceViewModel.cs

@@ -146,7 +146,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             conditionDevices = (from a in allDeviceList
                                    where (string.IsNullOrEmpty(DeviceName) ? true : (a.DeviceName == DeviceName))
                                    && (string.IsNullOrEmpty(DeviceNo) ? true : (a.DeviceNo == DeviceNo))
-                                   && (string.IsNullOrEmpty(DeviceKindName) ? true : (a.DeviceKindName == DeviceKindName))
+                               
                                 select a).ToList();
             //默认显示的第一页
             conditionDevices = conditionDevices.OrderBy(x => x.DeviceId).ToList();
@@ -242,10 +242,14 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             conditionDevices.Clear();
             var projectlist = _iBasicDeviceService.QueryList();
             var allDeviceKinds = _mapper.Map<List<bas_device>, List<BasDeviceDto>>(projectlist);
-            foreach (var plc in allDeviceKinds)
+            foreach (var kind in allDeviceKinds)
             {
-                allDeviceList.Add(plc);
-                conditionDevices.Add(plc);
+                //获取项目名和设备类型
+                kind.DeviceKindName = _iBasicDeviceKindService.Find((int)kind.DeviceKindId)?.devicekind_name;
+                kind.ProjectName = _iBasicProjectService.Find((int)kind.ProjectId)?.project_name;
+
+                allDeviceList.Add(kind);
+                conditionDevices.Add(kind);
             }
             conditionDevices = conditionDevices.OrderBy(x => x.DeviceId).ToList();
             Getpage();

+ 15 - 2
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/AutoTestViewModel.cs

@@ -44,6 +44,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         private int testResult = 0; //测试结果
         private long schId = 0; //方案ID
         private long globalSchDetailId = 0; //测试方案明细ID
+        private long globalDeviceId = 0; //设备ID
         private long selctStartDetailId = 0; //当前选择的第一个方案明细id
         private BizTestRecordDtlDto bizTestRecordDtlDto = new BizTestRecordDtlDto(); //测试方案明细表
         private const string TestMode = "自动测试";
@@ -174,6 +175,16 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                 }
 
             }
+
+            //获取设备id
+            var getDes = parameters.GetValues<long>("Key2");
+            if (getDes != null)
+            {
+                foreach (var item in getDes)
+                {
+                    globalDeviceId = item;
+                }
+            }
         }
 
         /// <summary>
@@ -278,13 +289,14 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         {
 
             //记录记录主表中是否有这个方案的记录,没有则添加
-            var findRecord = _iBizTestRecordService.FindRecorddBySchname(ScheduleName);
+            var findRecord = _iBizTestRecordService.FindRecorddByDeviceIdAndSchname(globalDeviceId,ScheduleName);
             if (findRecord == null)
             {
                 //状态status 没有赋值
                 BizTestRecordDto bizTestRecordDto = new BizTestRecordDto();
                 bizTestRecordDto.RecordName = ScheduleName + "_Record";
                 bizTestRecordDto.SchemeName = ScheduleName;
+                bizTestRecordDto.DeviceId = globalDeviceId;
                 bizTestRecordDto.Tester = Appsession.UserName;
                 bizTestRecordDto.StartTestTime = startTime;
                 bizTestRecordDto.FinishTestTime = endTime;
@@ -300,11 +312,12 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         /// <summary>
         /// 增加测试记录明细
         /// </summary>
+
         private void AddOrEditTesDtltRecord(long schDetailId)
         {
             //查找record ID
             long recordId = 0;
-            var findRecordID = _iBizTestRecordService.FindRecorddBySchname(ScheduleName);
+            var findRecordID =_iBizTestRecordService.FindRecorddByDeviceIdAndSchname(globalDeviceId, ScheduleName);
             if (findRecordID != null)
             {
                 recordId = findRecordID.record_id;

+ 27 - 131
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/DeviceTestViewModel.cs

@@ -15,6 +15,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows;
+using System.Windows.Controls;
 
 namespace PLCTool.ViewModels.BusinessManageViewModel
 {
@@ -41,16 +42,15 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
             _dialog = dialog;
             _logger = logger;
             QueryCommand = new DelegateCommand<object>(Query);
-            AddCommand = new DelegateCommand<object>(Add);
+          
             ExportCommand = new DelegateCommand<string>(Export);
-            EditCommand = new DelegateCommand<object>(Edit);
-            DeleteCommand = new DelegateCommand<object>(Delete);
+;
             ResetCommand = new DelegateCommand<object>(Reset);
             OnLoadCommand = new DelegateCommand(OnLoad);
             //手动  自动测试
             AutoTestCommand = new DelegateCommand<object>(AutoDest);
             ManualTestCommand = new DelegateCommand<object>(ManualTest);
-            GetPprojectConfig();
+         
         }
 
 
@@ -68,6 +68,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         {
             DeviceKindNameList = _iBasicDeviceKindService.FindAllDeviceKind();
             ProjectNameList = _iBasicProjectService.FindAllProject();
+            GetPprojectConfig();
         }
         private void Reset(object obj)
         {
@@ -83,10 +84,14 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         /// <param name="obj"></param>
         private void AutoDest(object obj)
         {
+            object[] multiObj = obj as object[];
+           
             //测试方案明细主键ID
-            long id = Convert.ToInt64(obj);
+            long id =(long) multiObj[0];
+            long deviceId= (long)multiObj[1];
             DialogParameters parm = new DialogParameters();
             parm.Add("Key", id);
+            parm.Add("Key2", deviceId);
             //弹出详情对话框
             //弹出详情对话框
             _dialog.ShowDialog("AutoTestView", parm, async callback =>
@@ -102,10 +107,14 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
 
         private void ManualTest(object obj)
         {
-            //测试方案主键ID
-            long id = Convert.ToInt64(obj);
+            object[] multiObj = obj as object[];
+
+            //测试方案明细主键ID
+            long id = (long)multiObj[0];
+            long deviceId = (long)multiObj[1];
             DialogParameters parm = new DialogParameters();
             parm.Add("Key", id);
+            parm.Add("Key2", deviceId);
             //弹出详情对话框
             //弹出详情对话框
             _dialog.ShowDialog("ManualTestView", parm, async callback =>
@@ -118,74 +127,6 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
 
             });
         }
-        /// <summary>
-        /// 修改
-        /// </summary>
-        /// <param name="obj"></param>
-        private void Edit(object obj)
-        {
-            int id = Convert.ToInt32(obj);
-            var findDevice = allDeviceList.FirstOrDefault(x => (x.DeviceId == id));
-            DialogParameters parm = new DialogParameters();
-            parm.Add("Key", findDevice);
-            //弹出详情对话框
-            _dialog.ShowDialog("AddOrEditDeviceView", parm, async callback =>
-            {
-                if (callback.Result == ButtonResult.OK)
-                {
-                    BasDeviceDto returnValue = callback.Parameters.GetValue<BasDeviceDto>("ReturnValue");
-
-                    if (returnValue != null)
-                    {
-                        //更新时间
-                        returnValue.UpdateTime = DateTime.Now;
-                        returnValue.UpdateBy = Appsession.UserName;
-                        //创建时间
-                        returnValue.CreateTime = findDevice.CreateTime;
-                        returnValue.CreateBy = findDevice?.CreateBy;
-
-                        var deviceKindCon = _mapper.Map<BasDeviceDto, bas_device>(returnValue);
-                        var findPlcs = allDeviceList.FindAll(x => (x.DeviceName == returnValue.DeviceName) || (x.DeviceNo == returnValue.DeviceNo));
-                        foreach (var item in findPlcs)
-                        {
-                            if (item.DeviceId != id)
-                            {
-                                MessageBox.Show("已有此设备编号,请更改名称!", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
-                                return;
-                            }
-                        }
-
-                        //修改
-                        deviceKindCon.device_id = id;
-                        bool isSucc = _iBasicDeviceService.Edit(deviceKindCon);
-                        if (isSucc)
-                        {
-                            //重新读取PLC
-                            GetPprojectConfig();
-                            _logger.LogInformation($"修改项目成功");
-                            MessageBox.Show("修改项目成功", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
-                        }
-                    }
-                }
-
-            });
-        }
-
-        private void Delete(object obj)
-        {
-            int id = Convert.ToInt32(obj);
-            MessageBoxResult boxResult = MessageBox.Show("确认删除此条数据?", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Question);
-            if (boxResult == MessageBoxResult.OK)
-            {
-                var del = _iBasicDeviceService.Delete(id);
-                if (del)
-                {
-                    MessageBox.Show("删除成功!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
-                    GetPprojectConfig();
-                }
-
-            }
-        }
 
         /// <summary>
         /// 查询
@@ -196,7 +137,8 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
             conditionDevices = (from a in allDeviceList
                                 where (string.IsNullOrEmpty(DeviceName) ? true : (a.DeviceName == DeviceName))
                                 && (string.IsNullOrEmpty(DeviceNo) ? true : (a.DeviceNo == DeviceNo))
-                                && (string.IsNullOrEmpty(DeviceKindName) ? true : (a.DeviceKindName == DeviceKindName))
+                                //&& (string.IsNullOrEmpty(DeviceKindName) ? true : (a.DeviceKindId == DeviceKindName))
+                                // && (string.IsNullOrEmpty(ProjectName) ? true : (a.ProjectId == ProjectName))
                                 select a).ToList();
             //默认显示的第一页
             conditionDevices = conditionDevices.OrderBy(x => x.DeviceId).ToList();
@@ -243,46 +185,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
 
             }
         }
-        /// <summary>
-        /// 添加PLC变量
-        /// </summary>
-        /// <param name="obj"></param>
-        /// <exception cref="NotImplementedException"></exception>
-        private void Add(object obj)
-        {
 
-            //弹出详情对话框
-            _dialog.ShowDialog("AddOrEditDeviceView", async callback =>
-            {
-                if (callback.Result == ButtonResult.OK)
-                {
-                    BasDeviceDto returnValue = callback.Parameters.GetValue<BasDeviceDto>("ReturnValue");
-                    if (returnValue != null)
-                    {
-                        returnValue.CreateTime = DateTime.Now;
-                        returnValue.CreateBy = Appsession.UserName;
-                        returnValue.UpdateTime = DateTime.Now;
-                        returnValue.UpdateBy = Appsession.UserName;
-                        var deviceCon = _mapper.Map<BasDeviceDto, bas_device>(returnValue);
-                        var findPlc = allDeviceList.FirstOrDefault(x => (x.DeviceName == returnValue.DeviceName) || (x.DeviceNo == returnValue.DeviceNo));
-                        if (findPlc != null)
-                        {
-                            MessageBox.Show("已有此项目名称或编号,请更改!", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
-                            return;
-                        }
-                        bool isSucc = _iBasicDeviceService.Add(deviceCon);
-                        if (isSucc)
-                        {
-                            //重新读取PLC
-                            GetPprojectConfig();
-                            _logger.LogInformation($"添加项目成功");
-                            MessageBox.Show("添加项目成功!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
-                        }
-                    }
-                }
-
-            });
-        }
         /// <summary>
         /// 获取所有项目
         /// </summary>
@@ -290,8 +193,8 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         {
             allDeviceList.Clear();
             conditionDevices.Clear();
-            var projectlist = _iBasicDeviceService.QueryList();
-            var allDeviceKinds = _mapper.Map<List<bas_device>, List<BasDeviceDto>>(projectlist);
+            var devicelist = _iBasicDeviceService.QueryList();
+            var allDeviceKinds = _mapper.Map<List<bas_device>, List<BasDeviceDto>>(devicelist);
             //所有测试方案
             var schlist = _basicPlcTestSchemeService.QueryList();
             var schDtoList = _mapper.Map<List<bas_plc_test_scheme>, List<BasicPlcTestSchemeDto>>(schlist);
@@ -299,7 +202,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
 
             foreach (var item in allDeviceKinds)
             {
-                string deviceKind = item.DeviceKindName;
+                string deviceKind =_iBasicDeviceKindService.Find((int)item.DeviceKindId)?.devicekind_name;
                 //在测试方案中查找此设备类型的所有方案
                 var schs= schDtoList.FindAll(x => x.DeviceKindName == deviceKind);
                 //设备方案
@@ -310,8 +213,8 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                         DeviceId = item.DeviceId,
                         DeviceNo = item.DeviceNo,
                         DeviceName = item.DeviceName,
-                        DeviceKindName = item.DeviceKindName,
-                        ProjectName = item.ProjectName,
+                        DeviceKindId = item.DeviceKindId,
+                        ProjectId = item.ProjectId,
                         SchemeName = sch.SchemeName,
                         SchemeId=sch.SchemeId,
                     }) ;
@@ -320,8 +223,8 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                         DeviceId = item.DeviceId,
                         DeviceNo = item.DeviceNo,
                         DeviceName = item.DeviceName,
-                        DeviceKindName = item.DeviceKindName,
-                        ProjectName = item.ProjectName,
+                        DeviceKindId = item.DeviceKindId,
+                        ProjectId = item.ProjectId,
                         SchemeName = sch.SchemeName,
                         SchemeId = sch.SchemeId,
                     });
@@ -360,17 +263,10 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         #region 命令绑定
 
         public DelegateCommand<object> QueryCommand { set; get; }
-        public DelegateCommand<object> AddCommand { set; get; }
+
         public DelegateCommand<string> ExportCommand { set; get; }
 
-        /// <summary>
-        /// 表格删除
-        /// </summary>
-        public DelegateCommand<Object> DeleteCommand { set; get; }
-        /// <summary>
-        /// 表格编辑按钮
-        /// </summary>
-        public DelegateCommand<Object> EditCommand { set; get; }
+  
         public DelegateCommand<object> ResetCommand { set; get; }
 
         public DelegateCommand OnLoadCommand { set; get; }

+ 35 - 26
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/ManualTestViewModel.cs

@@ -16,6 +16,7 @@ using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Configuration;
 using System.Linq;
+using System.Linq.Expressions;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows;
@@ -45,6 +46,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         private int testResult = 0; //测试结果
         private long schId = 0; //方案ID
         private long globalSchDetailId = 0; //测试方案明细ID
+        private long globalDeviceId = 0; //设备ID
         private BizTestRecordDtlDto bizTestRecordDtlDto = new BizTestRecordDtlDto(); //测试方案明细表
         private const string TestMode = "手动测试";
         private int delayTime = 20;
@@ -140,6 +142,15 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                 }
 
             }
+            //获取设备id
+            var getDes = parameters.GetValues<long>("Key2");
+            if(getDes != null)
+            {
+                foreach(var item in getDes)
+                {
+                    globalDeviceId = item;
+                }
+            }
         }
 
         /// <summary>
@@ -244,13 +255,14 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         {
         
             //记录记录主表中是否有这个方案的记录,没有则添加
-            var findRecord = _iBizTestRecordService.FindRecorddBySchname(ScheduleName);
+            var findRecord = _iBizTestRecordService.FindRecorddByDeviceIdAndSchname(globalDeviceId,ScheduleName);
             if (findRecord == null)
             {
                 //状态status 没有赋值
                 BizTestRecordDto bizTestRecordDto = new BizTestRecordDto();
                 bizTestRecordDto.RecordName = ScheduleName + "_Record";
                 bizTestRecordDto.SchemeName = ScheduleName;
+                bizTestRecordDto.DeviceId = globalDeviceId;
                 bizTestRecordDto.Tester = Appsession.UserName;
                 bizTestRecordDto.StartTestTime = startTime;
                 bizTestRecordDto.FinishTestTime = endTime;
@@ -270,7 +282,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         {
             //查找record ID
             long recordId = 0;
-            var findRecordID = _iBizTestRecordService.FindRecorddBySchname(ScheduleName);
+            var findRecordID = _iBizTestRecordService.FindRecorddByDeviceIdAndSchname(globalDeviceId, ScheduleName);
             if (findRecordID != null)
             {
                 recordId = findRecordID.record_id;
@@ -279,10 +291,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                             //状态status 没有赋值
 
             
-            //记录记录明细表中是否有这个方案明细ID的记录,没有则添加,有则更新记录状态
-            var findRecordDetail = _iBizTestRecordDtlService.FindRecordDetailBySchDtlID(schDetailId);
-            if (findRecordDetail == null)
-            {
+            //无论第几次测试都添加
                 BizTestRecordDtlDto newBizTestEwDetail=new BizTestRecordDtlDto();
                 newBizTestEwDetail.RecordId = recordId;
                 newBizTestEwDetail.SchemeDtlId = schDetailId;
@@ -297,26 +306,26 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                 newBizTestEwDetail.UpdateTime = DateTime.Now;
                 var testRecordDtl = _mapper.Map<BizTestRecordDtlDto, biz_test_record_dtl>(newBizTestEwDetail);
                 _iBizTestRecordDtlService.Add(testRecordDtl);
-            }
-            else
-            {
-                bizTestRecordDtlDto.RecordDtlId = findRecordDetail.record_dtl_id;
-                bizTestRecordDtlDto.RecordId = recordId;
-                bizTestRecordDtlDto.SchemeDtlId = schDetailId;
-                bizTestRecordDtlDto.StartTestTime = startTime;
-                bizTestRecordDtlDto.FinishTestTime = endTime;
-                bizTestRecordDtlDto.TestMode = TestMode;
-                bizTestRecordDtlDto.Status = testStatus;
-                bizTestRecordDtlDto.TestResult = GetTestResult();
-                bizTestRecordDtlDto.CreateBy = Appsession.UserName;
-                bizTestRecordDtlDto.CreateTime = startTime;
-                bizTestRecordDtlDto.UpdateBy = Appsession.UserName;
-                bizTestRecordDtlDto.UpdateTime = DateTime.Now;
-                //更新时间
-                bizTestRecordDtlDto.UpdateBy = Appsession.UserName;
-                bizTestRecordDtlDto.UpdateTime = DateTime.Now;
-                UpdateTesDtltRecord();
-            }
+            
+            //else
+            //{
+            //    bizTestRecordDtlDto.RecordDtlId = findRecordDetail.record_dtl_id;
+            //    bizTestRecordDtlDto.RecordId = recordId;
+            //    bizTestRecordDtlDto.SchemeDtlId = schDetailId;
+            //    bizTestRecordDtlDto.StartTestTime = startTime;
+            //    bizTestRecordDtlDto.FinishTestTime = endTime;
+            //    bizTestRecordDtlDto.TestMode = TestMode;
+            //    bizTestRecordDtlDto.Status = testStatus;
+            //    bizTestRecordDtlDto.TestResult = GetTestResult();
+            //    bizTestRecordDtlDto.CreateBy = Appsession.UserName;
+            //    bizTestRecordDtlDto.CreateTime = startTime;
+            //    bizTestRecordDtlDto.UpdateBy = Appsession.UserName;
+            //    bizTestRecordDtlDto.UpdateTime = DateTime.Now;
+            //    //更新时间
+            //    bizTestRecordDtlDto.UpdateBy = Appsession.UserName;
+            //    bizTestRecordDtlDto.UpdateTime = DateTime.Now;
+            //    UpdateTesDtltRecord();
+            //}
             
 
 

+ 5 - 2
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/QueryViewModel.cs

@@ -36,6 +36,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         private readonly IBasicPlcTestSchemeService _basicPlcTestSchemeService;
         private readonly IBasicPlcTestSchemeDtlService _basicPlcTestSchemeDtlService;
         private readonly IBizTestRecordDtlService _iBizTestRecordDtlService;
+        private readonly IBasicDeviceService _iBasicDeviceService;
         private readonly ILogger _logger;
         private readonly IMapper _mapper;
         private readonly IMenuService _menuService;
@@ -44,13 +45,14 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         private List<SchDtlWithResultModel> conditionConfig = new List<SchDtlWithResultModel>();//符合条件的方案
 
         private const int PageCount = 1; //每一页显示个数
-        public QueryViewModel(IDialogService dialog, IMenuService menuService, IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService, IBizTestRecordDtlService iBizTestRecordDtlService,IMapper mapper, ILogger logger)
+        public QueryViewModel(IDialogService dialog, IMenuService menuService, IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService, IBizTestRecordDtlService iBizTestRecordDtlService, IBasicDeviceService iBasicDeviceService,IMapper mapper, ILogger logger)
         {
             _dialog = dialog;
             _optionConfigService = optionConfigService;
             _basicPlcTestSchemeService = basicPlcTestSchemeService;
             _basicPlcTestSchemeDtlService = basicPlcTestSchemeDtlService;
             _iBizTestRecordDtlService = iBizTestRecordDtlService;
+            _iBasicDeviceService = iBasicDeviceService;
             _logger = logger;
             _mapper = mapper;
             _menuService = menuService;
@@ -494,10 +496,11 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                 BaseConfigList.Add(i);
             }
         }
+
         #endregion
         #region 命令绑定
 
- 
+
         public DelegateCommand<object> QueryCommand { set; get; }
         public DelegateCommand<object> ResetCommand { set; get; }
     

+ 18 - 2
BlankApp1/BlankApp1/Views/BusinessManageView/DeviceTestView.xaml

@@ -8,8 +8,12 @@
              xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
              xmlns:myContr="clr-namespace:BlankApp1.Controls"
              xmlns:wpfdev="https://github.com/WPFDevelopersOrg/WPFDevelopers"
+             xmlns:cvt="clr-namespace:PLCTool.Controls.Convert"
              mc:Ignorable="d" 
              d:DesignHeight="450" d:DesignWidth="800">
+    <UserControl.Resources>
+        <cvt:TwoParConverter x:Key="TwoParConverter"/>
+    </UserControl.Resources>
     <Grid >
         <b:Interaction.Triggers>
             <b:EventTrigger EventName="Loaded">
@@ -86,18 +90,30 @@
                         <DataTemplate>
                             <StackPanel Orientation="Horizontal">
                                 <Button  Width="auto" Background="Transparent" HorizontalContentAlignment ="Left" Foreground="Black" Height="25" BorderThickness="0"
-                                        Command="{Binding DataContext.ManualTestCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding SchemeId}" Cursor="Hand" Margin="0,0,10,0" >
+                                        Command="{Binding DataContext.ManualTestCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" Cursor="Hand" Margin="0,0,10,0" >
 
                                     <StackPanel Orientation="Horizontal">
                                         <TextBlock  Text="手动测试" VerticalAlignment="Center" Foreground="Blue"/>
                                     </StackPanel>
+                                    <Button.CommandParameter>
+                                        <MultiBinding Converter="{ StaticResource ResourceKey=TwoParConverter}">
+                                            <Binding Path="SchemeId"  ></Binding>
+                                            <Binding Path="DeviceId"></Binding>
+                                        </MultiBinding>
+                                    </Button.CommandParameter>
                                 </Button>
                                 <Button  Width="auto" Background="Transparent" HorizontalContentAlignment ="Left" Foreground="Black" Height="25" BorderThickness="0"
-                                        Command="{Binding DataContext.AutoTestCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding SchemeId}" Cursor="Hand" Margin="0,0,10,0">
+                                        Command="{Binding DataContext.AutoTestCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}"  Cursor="Hand" Margin="0,0,10,0">
 
                                     <StackPanel Orientation="Horizontal">
                                         <TextBlock  Text="自动测试" VerticalAlignment="Center" Foreground="Blue"/>
                                     </StackPanel>
+                                    <Button.CommandParameter>
+                                        <MultiBinding Converter="{ StaticResource ResourceKey=TwoParConverter}">
+                                            <Binding Path="SchemeId"  ></Binding>
+                                            <Binding Path="DeviceId"></Binding>
+                                        </MultiBinding>
+                                    </Button.CommandParameter>
                                 </Button>
 
                             </StackPanel>

+ 54 - 1
BlankApp1/BlankApp1/Views/BusinessManageView/QueryView.xaml

@@ -21,7 +21,8 @@
             <RowDefinition Height="40"/>
             <RowDefinition/>
             <RowDefinition Height="40"/>
-
+            <RowDefinition/>
+            <RowDefinition Height="40"/>
         </Grid.RowDefinitions>
         <UniformGrid Grid.Row="0" Columns="4">
             <StackPanel Orientation="Horizontal">
@@ -112,6 +113,58 @@
 
         </Grid>
 
+        <DataGrid  Grid.Row="4"  ColumnWidth="*" AutoGenerateColumns="False" HeadersVisibility="All" CanUserAddRows="False"  SelectionUnit="FullRow" SelectionMode="Single"   RowHeaderWidth="0"
+            ColumnHeaderStyle="{StaticResource ColumnHeaderStyle}"  RowHeaderStyle="{StaticResource RowHeaderStyle}" RowStyle="{StaticResource DataGridRowtyle}"  AlternationCount="2"
+           ItemsSource="{Binding DeviceItemList}" IsReadOnly="True" Padding="0"  >
+            <DataGrid.Columns >
+                <DataGridTextColumn Header="序号" Width="50" Binding="{Binding DeviceId}" CellStyle="{StaticResource MyDataGridCellStyle}" />
+                <DataGridTextColumn Header="设备编号" Binding="{Binding DeviceNo}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                <DataGridTextColumn Header="设备名称" Binding="{Binding DeviceName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                <DataGridTextColumn Header="项目名称" Binding="{Binding ProjectName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                <DataGridTextColumn Header="设备类型" Binding="{Binding DeviceKindName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                <DataGridTextColumn Header="测试方案名称" Binding="{Binding SchemeName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                <DataGridTextColumn Header="测试时间" Binding="{Binding StartTestTime}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                <DataGridTextColumn Header="测试结果" Binding="{Binding TestResult}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                <!--<DataGridTextColumn Header="创建者" Binding="{Binding CreateBy}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+          <DataGridTextColumn Header="创建时间" Binding="{Binding CreateTime,StringFormat={}{0:yyyy-MM-dd HH:mm:ss}}" CellStyle="{StaticResource MyDataGridCellStyle}"/>-->
+                <DataGridTemplateColumn Header="操作" Width="180"  CellStyle="{StaticResource MyDataGridCellStyle}">
+                    <DataGridTemplateColumn.CellTemplate>
+                        <DataTemplate>
+                            <UniformGrid Columns="2">
+                                <Button  Width="auto" Background="Transparent" HorizontalContentAlignment ="Left" Foreground="Black" Height="25" BorderThickness="0"
+                            Command="{Binding DataContext.CheckDetailCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding SchemeId}" Cursor="Hand" Margin="0,0,5,0" >
+
+                                    <StackPanel Orientation="Horizontal">
+                                        <TextBlock  Text="查看详情" VerticalAlignment="Center" Foreground="Blue"/>
+                                    </StackPanel>
+                                </Button>
+                                <Button  Width="auto" Background="Transparent" HorizontalContentAlignment ="Left" Foreground="Black" Height="25" BorderThickness="0"
+     Command="{Binding DataContext.PdfReportCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding SchemeId}" Cursor="Hand" >
+
+                                    <StackPanel Orientation="Horizontal">
+                                        <TextBlock  Text="生成pdf报表" VerticalAlignment="Center" Foreground="Blue"/>
+                                    </StackPanel>
+                                </Button>
+
+                            </UniformGrid>
+                        </DataTemplate>
+                    </DataGridTemplateColumn.CellTemplate>
+                </DataGridTemplateColumn>
+            </DataGrid.Columns>
 
+        </DataGrid>
+        <Grid Grid.Row="5" HorizontalAlignment="Center" VerticalAlignment="Center">
+            <wpfdev:Pagination IsLite="False"    Margin="0"  Width="auto" Height="30" HorizontalAlignment="Center"  
+                 Count="{Binding TotalCount,Mode=TwoWay}" 
+                 CountPerPage="{Binding CountPerPage,Mode=TwoWay}"
+                 Current="{Binding CurrentPage,Mode=TwoWay}"/>
+            <!--<hc:Pagination MaxPageCount="10" PageIndex="{Binding PageIndex}" IsJumpEnabled="True">
+          <hc:Interaction.Triggers>
+              <hc:EventTrigger EventName="PageUpdated">
+                  <hc:EventToCommand Command="{Binding PageUpdatedCmd}" PassEventArgsToCommand="True" />
+              </hc:EventTrigger>
+          </hc:Interaction.Triggers>
+      </hc:Pagination>-->
+        </Grid>
     </Grid>
 </UserControl>

+ 18 - 5
BlankApp1/Model/Dto/BasDeviceDto.cs

@@ -48,24 +48,37 @@ namespace Model.Dto
         /// Default:
         /// Nullable:True
         /// </summary>           
-        private string projectName { get; set; }
-        public string ProjectName
+        private long projectId{ get; set; }
+        public long ProjectId
         {
-            get { return projectName; }
-            set { projectName = value; OnPropertyChanged(); }
+            get { return projectId; }
+            set { projectId = value; OnPropertyChanged(); }
         }
         /// <summary>
         /// Desc:所属设备类型编号
         /// Default:
         /// Nullable:False
         /// </summary>           
+        private long deviceKindId { get; set; }
+        public long DeviceKindId
+        {
+            get { return deviceKindId; }
+            set { deviceKindId = value; OnPropertyChanged(); }
+        }
+
+
+        private string projectName { get; set; }
+        public string ProjectName
+        {
+            get { return projectName; }
+            set { projectName = value; OnPropertyChanged(); }
+        }
         private string deviceKindName { get; set; }
         public string DeviceKindName
         {
             get { return deviceKindName; }
             set { deviceKindName = value; OnPropertyChanged(); }
         }
-       
         /// <summary>
         /// Desc:创建者
         /// Default:

+ 4 - 1
BlankApp1/Model/Dto/BizTestRecordDto.cs

@@ -22,7 +22,10 @@ namespace Model.Dto
         /// Nullable:False
         /// </summary>           
         public string RecordName { get; set; }
-
+        /// <summary>
+        /// 设备方案id
+        /// </summary>
+        public long DeviceId { get; set; }
         /// <summary>
         /// Desc:测试方案名称
         /// Default:

+ 2 - 2
BlankApp1/Model/Entities/bas_device.cs

@@ -42,14 +42,14 @@ namespace Model.Entities
            /// Default:
            /// Nullable:True
            /// </summary>           
-           public string project_id {get;set;}
+           public long project_id {get;set;}
 
            /// <summary>
            /// Desc:所属设备类型编号
            /// Default:
            /// Nullable:False
            /// </summary>           
-           public string device_kind_id {get;set;}
+           public long device_kind_id {get;set;}
 
       
 

+ 10 - 6
BlankApp1/Model/Entities/biz_test_record.cs

@@ -30,12 +30,16 @@ namespace Model.Entities
            /// </summary>           
            public string record_name {get;set;}
 
-           /// <summary>
-           /// Desc:测试方案名称
-           /// Default:
-           /// Nullable:False
-           /// </summary>           
-           public string scheme_name {get;set;}
+        /// <summary>
+        /// 设备方案id
+        /// </summary>
+        public long device_id { get; set; }
+        /// <summary>
+        /// Desc:测试方案名称
+        /// Default:
+        /// Nullable:False
+        /// </summary>           
+        public string scheme_name {get;set;}
 
            /// <summary>
            /// Desc:测试人员