ltwork преди 1 година
родител
ревизия
2dc276c0c6

+ 3 - 1
BlankApp1/BlankApp1/App.xaml.cs

@@ -71,7 +71,7 @@ namespace BlankApp1
             containerRegistry.RegisterForNavigation<ResultQueryView, ResultQueryViewModel>();
             containerRegistry.RegisterForNavigation<RetryTestView, RetryTestViewModel>();
             containerRegistry.RegisterForNavigation<AddSchView, AddSchViewModel>();
-
+            containerRegistry.RegisterForNavigation<EditSchView, EditSchViewModel>();
             containerRegistry.RegisterForNavigation<DeviceTestCardView, DeviceTestCardViewModel>();
             containerRegistry.RegisterForNavigation<ProjectTestView, ProjectTestViewModel>();
             containerRegistry.RegisterForNavigation<DeviceResultCardView, DeviceResultCardViewModel>();
@@ -85,6 +85,8 @@ namespace BlankApp1
             containerRegistry.RegisterDialog<AddOrEditProjectView, AddOrEditProjectViewModel>();
             containerRegistry.RegisterDialog<AddOrEditDeviceKindView, AddOrEditDeviceKindViewModel>();
             containerRegistry.RegisterDialog<AddOrEditDeviceView, AddOrEditDeviceViewModel>();
+            containerRegistry.RegisterDialog<EditItemDetailView, EditItemDetailViewModel>();
+            
         }
 
         private IMapper GetMapper(IContainerProvider container)

+ 1048 - 0
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/EditItemDetailViewModel.cs

@@ -0,0 +1,1048 @@
+using AutoMapper;
+using BizService;
+using BlankApp1.Events;
+using Microsoft.Extensions.Logging;
+using Model.Dto;
+using Model.Entities;
+using NetTaste;
+using Newtonsoft.Json;
+using PLCTool.Common;
+using PLCTool.Models;
+using Prism.Commands;
+using Prism.Events;
+using Prism.Mvvm;
+using Prism.Regions;
+using Prism.Services.Dialogs;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace PLCTool.ViewModels.BasicConfigViewModel
+{
+    
+    public class EditItemDetailViewModel : BindableBase, IDialogAware
+    {
+        private readonly IDialogService _dialog;
+        private readonly IEventAggregator _aggregator;
+        private readonly IRegionManager _regionManager;
+        private readonly IOptionConfigService _optionConfigService;
+        private readonly IBasicPlcTestSchemeService _basicPlcTestSchemeService;
+        private readonly IBasicPlcTestSchemeDtlService _basicPlcTestSchemeDtlService;
+        private readonly IBasicDeviceKindService _iBasicDeviceKindService;
+        private readonly IMapper _mapper;
+        private readonly ILogger _logger;
+        private List<OptionConfigDto> _optionConfigs;
+        private bas_plc_test_scheme bas_Plc_Test_Scheme;//测试方案
+        private int schDtlMainId = 0;//测试方案明细主键id
+        
+        public EditItemDetailViewModel(IDialogService dialog, IEventAggregator aggregator, IRegionManager regionManager, IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService, IBasicDeviceKindService iBasicDeviceKindService, IMapper mapper, ILogger logger)
+        {
+            _dialog = dialog;
+            _aggregator = aggregator;
+            _regionManager = regionManager;
+            _optionConfigService = optionConfigService;
+            _basicPlcTestSchemeService = basicPlcTestSchemeService;
+            _basicPlcTestSchemeDtlService = basicPlcTestSchemeDtlService;
+            _iBasicDeviceKindService = iBasicDeviceKindService;
+            _mapper = mapper;
+            _logger = logger;
+            CloseCommand = new DelegateCommand(Close);
+            SureCommand = new DelegateCommand<string>(Sure);
+            ResetCommand = new DelegateCommand<string>(ResetMethod);
+            AddDetailCommand = new DelegateCommand<string>(AddPLCDetail);
+            EditInCommand = new DelegateCommand<object>(EditIn);
+            EditOutCommand = new DelegateCommand<object>(EditOut);
+            EditBeforeCommand = new DelegateCommand<Object>(EditBefore);
+            DeleteBeforeCommand = new DelegateCommand<Object>(DeleteBefore);
+            DeleteInCommand = new DelegateCommand<object>(DeleteIn);
+            DeleteOutCommand = new DelegateCommand<object>(DeleteOut);
+            OnLoadCommand = new DelegateCommand<object>(OnLoad);
+            TxtLostFocusCommand = new DelegateCommand(GetExistSchs);
+            OpenExistCommand = new DelegateCommand<string>(OpenExist);
+            UpCommand = new DelegateCommand<object>(DataUp);
+            DownCommand = new DelegateCommand<object>(DataDown);
+            DetailCommand = new DelegateCommand<object>(CheckDetail);
+            DeleteCommand = new DelegateCommand<object>(Delete);
+            BeforeConList = new ObservableCollection<BasPlcItemConfigDto>();
+            InConList = new ObservableCollection<BasPlcItemConfigDto>();
+            OutConList = new ObservableCollection<BasPlcItemConfigDto>();
+            //获取设备类型
+            DeviceKindNameList = _iBasicDeviceKindService.FindAllDeviceKind();
+            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; } = "新增方案";
+
+        public event Action<IDialogResult> RequestClose;
+
+
+
+        #endregion
+
+
+
+
+
+
+        #region 私有方法
+
+        /// <summary>
+        ///  测试方案明细主键ID 查找测试方案id 及方案名
+        /// </summary>
+        /// <param name="schDtlId"></param>
+        private void GetDetaiMsg(int schDtlId)
+        {
+            //根据 测试方案明细主键ID 查找测试方案id 及方案名和设备名
+            var findEntity = _basicPlcTestSchemeDtlService.Find(schDtlId);
+            var findresult = _mapper.Map<bas_plc_test_scheme_dtl, BasicPlcTestSchemeDtlDto>(findEntity);
+            if (findresult != null)
+            {
+                //根据方案id 在方案表中查找方案名 设备名
+                int schID = Convert.ToInt32(findresult.SchemeId);
+                //测试方案
+                bas_Plc_Test_Scheme = _basicPlcTestSchemeService.Find(schID);
+                if (bas_Plc_Test_Scheme != null)
+                {
+                    ScheduleName = bas_Plc_Test_Scheme.scheme_name;
+                    DeviceKindName = bas_Plc_Test_Scheme.devicekind_name;
+
+                }
+                TestName = findresult.ItemName;
+                SelectTest = findresult.ItemType;
+                //前置项解析
+                string preconStr = findresult.Precondition.ToString();
+                if (!string.IsNullOrEmpty(preconStr))
+                {
+                    JsonModel preconditionModel = JsonConvert.DeserializeObject<JsonModel>(preconStr);
+                    BeforeSelectJudge = preconditionModel.ItemType;
+                    SelectLogic = preconditionModel.ItemLogical;
+                    BeforeDetail = preconditionModel.Description;
+                    BeforeConList.Clear();
+                    foreach (var detail in preconditionModel.DetailInfo)
+                    {
+                        BasPlcItemConfigDto basPlcItemConfigDto = new BasPlcItemConfigDto();
+                        basPlcItemConfigDto.Id = detail.Id;
+                        basPlcItemConfigDto.PlcItem = detail.PlcItem;
+                        basPlcItemConfigDto.PlcAddress = detail.PlcAddress;
+                        basPlcItemConfigDto.PlcAddType = detail.PlcAddType;
+                        basPlcItemConfigDto.PlcValue = detail.PlcValue;
+                        basPlcItemConfigDto.Remark = detail.Remark;
+                        BeforeConList.Add(basPlcItemConfigDto);
+                    }
+                }
+
+                //输入项解析
+                string inStr = findresult.Action.ToString();
+                if (!string.IsNullOrEmpty(inStr))
+                {
+                    JsonModel inModel = JsonConvert.DeserializeObject<JsonModel>(inStr);
+                    SelectInJudge = inModel.ItemType;
+                    InSelectLogic = inModel.ItemLogical;
+                    InDetail = inModel.Description;
+                    InConList.Clear();
+                    foreach (var detail in inModel.DetailInfo)
+                    {
+                        BasPlcItemConfigDto basPlcItemConfigDto = new BasPlcItemConfigDto();
+                        basPlcItemConfigDto.Id = detail.Id;
+                        basPlcItemConfigDto.PlcItem = detail.PlcItem;
+                        basPlcItemConfigDto.PlcAddress = detail.PlcAddress;
+                        basPlcItemConfigDto.PlcAddType = detail.PlcAddType;
+                        basPlcItemConfigDto.PlcValue = detail.PlcValue;
+                        basPlcItemConfigDto.Remark = detail.Remark;
+                        InConList.Add(basPlcItemConfigDto);
+                    }
+                }
+
+                //输出项解析
+                string outStr = findresult.JudgementResult.ToString();
+                if (!string.IsNullOrEmpty(outStr))
+                {
+                    JsonModel outModel = JsonConvert.DeserializeObject<JsonModel>(outStr);
+                    SelectOutJudge = outModel.ItemType;
+                    OutSelectLogic = outModel.ItemLogical;
+                    OutDetail = outModel.Description;
+                    OutConList.Clear();
+                    foreach (var detail in outModel.DetailInfo)
+                    {
+                        BasPlcItemConfigDto basPlcItemConfigDto = new BasPlcItemConfigDto();
+                        basPlcItemConfigDto.Id = detail.Id;
+                        basPlcItemConfigDto.PlcItem = detail.PlcItem;
+                        basPlcItemConfigDto.PlcAddress = detail.PlcAddress;
+                        basPlcItemConfigDto.PlcAddType = detail.PlcAddType;
+                        basPlcItemConfigDto.PlcValue = detail.PlcValue;
+                        basPlcItemConfigDto.Remark = detail.Remark;
+                        OutConList.Add(basPlcItemConfigDto);
+                    }
+                }
+
+            }
+        }
+
+       
+
+
+        
+        /// <summary>
+        /// 打开已有方案
+        /// </summary>
+        /// <param name="obj"></param>
+        /// <exception cref="NotImplementedException"></exception>
+        private void OpenExist(string str)
+        {
+            if (string.IsNullOrEmpty(DeviceKindName))
+            {
+                MessageBox.Show("请选择设备类型!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
+                return;
+            }
+
+            if (string.IsNullOrEmpty(ScheduleName))
+            {
+                MessageBox.Show("请填写方案名称!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
+                return;
+            }
+            //设备类型名称
+
+            DialogParameters parm = new DialogParameters();
+            parm.Add("Key", DeviceKindName);
+            parm.Add("Key2", ScheduleName);
+            //已有的测试项
+            parm.Add("Key3", SchProjectList);
+            //弹出详情对话框
+            _dialog.ShowDialog("CopySchView", parm, async callback =>
+            {
+                if (callback.Result == ButtonResult.OK)
+                {
+                    List<bas_plc_test_scheme_dtl> returnValue = callback.Parameters.GetValue<List<bas_plc_test_scheme_dtl>>("ReturnValue");
+                    //更新表格,重新获取
+                    GetExistSchs();
+                }
+
+            });
+        }
+        /// <summary>
+        /// 获取测试项
+        /// </summary>
+        private void GetExistSchs()
+        {
+            SchProjectList.Clear();
+            var findSche = _basicPlcTestSchemeService.FindByName(ScheduleName);
+            if (findSche != null)
+            {
+
+                //显示设备名称
+                DeviceKindName = findSche.devicekind_name;
+                long schID = findSche.scheme_id;
+                //查找此方案下的所有的测试项,并增加到表格
+                var schDtls = _basicPlcTestSchemeDtlService.QueryList()?.FindAll(x => x.scheme_id == schID)?.OrderBy(x => x.scheme_dtl_id);
+                foreach (var unit in schDtls)
+                {
+                    string itemType = string.Empty;
+                    switch (unit.item_type)
+                    {
+                        case 0:
+                            itemType = "前置项";
+                            break;
+                        case 1:
+                            itemType = "PLC点位测试项";
+                            break;
+                        case 2:
+                            itemType = "Robot动作测试";
+                            break;
+                    }
+                    SchProjectList.Add(new SelectItemModel
+                    {
+                        SchDtlId = unit.scheme_dtl_id,
+                        ItemName = unit.item_name,
+                        ItemType = itemType,
+                        BeforeDetail = unit.precondition_describe,
+                        InDetail = unit.action_describe,
+                        OutDetail = unit.judgement_result_describe
+                    });
+
+                }
+            }
+        }
+
+        /// <summary>
+        /// 下移
+        /// </summary>
+        /// <param name="obj"></param>
+        private void DataDown(object obj)
+        {
+            int id = Convert.ToInt32(obj);
+            var findScheExist = SchProjectList.FirstOrDefault(x => x.SchDtlId == id);
+            if (findScheExist != null)
+            {
+
+                int index = SchProjectList.IndexOf(findScheExist);
+                if (index != -1)
+                {
+                    if (index == SchProjectList.Count - 1)
+                        return;
+                    SchProjectList.RemoveAt(index);
+                    index = index + 1;
+                    SchProjectList.Insert(index, findScheExist);
+                }
+
+
+            }
+        }
+        /// <summary>
+        /// 上移
+        /// </summary>
+        /// <param name="obj"></param>
+        private void DataUp(object obj)
+        {
+            int id = Convert.ToInt32(obj);
+            var findScheExist = SchProjectList.FirstOrDefault(x => x.SchDtlId == id);
+            if (findScheExist != null)
+            {
+
+                int index = SchProjectList.IndexOf(findScheExist);
+                if (index != -1)
+                {
+                    if (index == 0)
+                        return;
+                    SchProjectList.RemoveAt(index);
+                    index = index - 1;
+                    SchProjectList.Insert(index, findScheExist);
+                }
+
+
+            }
+
+        }
+
+        private void OnLoad(object obj)
+        {
+
+        }
+        private void OpenEditDialog(Object obj, ObservableCollection<BasPlcItemConfigDto> conList)
+        {
+            int id = Convert.ToInt32(obj);
+            var edit = conList.FirstOrDefault(x => x.Id == id);
+            if (edit != null)
+            {
+                DialogParameters parm = new DialogParameters();
+                parm.Add("Key", edit);
+                //弹出详情对话框
+                _dialog.ShowDialog("AddDetailView", parm, async callback =>
+                {
+                    if (callback.Result == ButtonResult.OK)
+                    {
+                        BasPlcItemConfigDto returnValue = callback.Parameters.GetValue<BasPlcItemConfigDto>("ReturnValue");
+                        //更新
+                        var after = conList.FirstOrDefault(x => x.Id == id);
+                        if (after != null)
+                        {
+                            after.PlcItem = returnValue.PlcItem;
+                            after.PlcAddress = returnValue.PlcAddress;
+                            after.PlcAddType = returnValue.PlcAddType;
+                            after.PlcValue = returnValue.PlcValue;
+                            after.Remark = returnValue.Remark;
+
+                        }
+                    }
+
+                });
+            }
+        }
+
+        /// <summary>
+        /// 前置条件编辑
+        /// </summary>
+        /// <param name="obj"></param>
+        /// <exception cref="NotImplementedException"></exception>
+        private void EditBefore(Object obj)
+        {
+
+            OpenEditDialog(obj, BeforeConList);
+
+
+        }
+
+        private void EditOut(object obj)
+        {
+            OpenEditDialog(obj, OutConList);
+        }
+
+        private void EditIn(object obj)
+        {
+            OpenEditDialog(obj, InConList);
+        }
+        /// <summary>
+        /// 前置条件删除
+        /// </summary>
+        /// <param name="obj"></param>
+        /// <exception cref="NotImplementedException"></exception>
+        private void DeleteBefore(Object obj)
+        {
+            int id = Convert.ToInt32(obj);
+            MessageBoxResult boxResult = MessageBox.Show("确认删除此条数据?", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Question);
+            if (boxResult == MessageBoxResult.OK)
+            {
+                var del = BeforeConList.FirstOrDefault(x => x.Id == id);
+                if (del != null)
+                {
+                    BeforeConList.Remove(del);
+                }
+
+            }
+        }
+        private void DeleteOut(object obj)
+        {
+            int id = Convert.ToInt32(obj);
+            MessageBoxResult boxResult = MessageBox.Show("确认删除此条数据?", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Question);
+            if (boxResult == MessageBoxResult.OK)
+            {
+                var del = OutConList.FirstOrDefault(x => x.Id == id);
+                if (del != null)
+                {
+                    OutConList.Remove(del);
+                }
+
+            }
+        }
+
+        private void DeleteIn(object obj)
+        {
+            int id = Convert.ToInt32(obj);
+            MessageBoxResult boxResult = MessageBox.Show("确认删除此条数据?", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Question);
+            if (boxResult == MessageBoxResult.OK)
+            {
+                var del = InConList.FirstOrDefault(x => x.Id == id);
+                if (del != null)
+                {
+                    InConList.Remove(del);
+                }
+
+            }
+        }
+
+        /// <summary>
+        /// 获取配置
+        /// </summary>
+        private void GetConfigOption()
+        {
+            var configList = _optionConfigService.QueryList();
+            _optionConfigs = _mapper.Map<List<OptionConfig>, List<OptionConfigDto>>(configList);
+            var tests = _optionConfigs.FindAll(x => x.TypeID == 1);
+            TestKinds = new List<string>();
+            foreach (var test in tests)
+            {
+                TestKinds.Add(test.ContentOption);
+            }
+
+            //测试项类型
+            var judges = _optionConfigs.FindAll(x => x.TypeID == 2);
+            foreach (var judge in judges)
+            {
+                BeforeJudgeKinds.Add(judge.ContentOption);
+                InJudgeKinds.Add(judge.ContentOption);
+                OutJudgeKinds.Add(judge.ContentOption);
+            }
+
+            //判定逻辑
+            var logics = _optionConfigs.FindAll(x => x.TypeID == 3);
+            foreach (var logic in logics)
+            {
+                JudgeLogicKinds.Add(logic.ContentOption);
+                InJudgeLogicKinds.Add(logic.ContentOption);
+                OutJudgeLogicKinds.Add(logic.ContentOption);
+
+            }
+
+        }
+
+
+        /// <summary>
+        /// 新增
+        /// </summary>
+        /// <param name="str"></param>
+        private void AddPLCDetail(string str)
+        {
+            DialogParameters parm = new DialogParameters();
+            parm.Add("Key", "");
+            //弹出详情对话框
+            _dialog.ShowDialog("AddDetailView", parm, async callback =>
+            {
+                if (callback.Result == ButtonResult.OK)
+                {
+                    BasPlcItemConfigDto returnValue = callback.Parameters.GetValue<BasPlcItemConfigDto>("ReturnValue");
+                    switch (str)
+                    {
+                        case "Before":
+                            returnValue.Id = BeforeConList.Count + 1;
+                            BeforeConList.Add(returnValue); break;
+                        case "In":
+                            returnValue.Id = InConList.Count + 1;
+                            InConList.Add(returnValue); break;
+                        case "Out":
+                            returnValue.Id = OutConList.Count + 1;
+                            OutConList.Add(returnValue); break;
+                    }
+                }
+
+            });
+        }
+
+        /// <summary>
+        /// 初始化
+        /// </summary>
+
+        /// <summary>
+        /// 关闭按钮
+        /// </summary>
+        private void Close()
+        {
+            //RequestClose?.Invoke(new NavigationResult(new NavigationContext(),true);
+        }
+        /// <summary>
+        /// 确认
+        /// </summary>
+        /// <param name="obj"></param>
+        private void Sure(string obj)
+        {
+            if (string.IsNullOrEmpty(ScheduleName))
+            {
+                MessageBox.Show("请填写测试方案名称!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            if (string.IsNullOrEmpty(DeviceKindName))
+            {
+                MessageBox.Show("请填写设备类型名称!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            if (string.IsNullOrEmpty(SelectTest))
+            {
+                MessageBox.Show("请选择测试项类型!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            if (string.IsNullOrEmpty(TestName))
+            {
+                MessageBox.Show("请填写测试项名称!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            if (string.IsNullOrEmpty(BeforeSelectJudge))
+            {
+                MessageBox.Show("请填写前置项测试项测试类型!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            //前置项
+            if (string.IsNullOrEmpty(BeforeSelectJudge))
+            {
+                MessageBox.Show("请填写前置项测试项测试类型!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            if (string.IsNullOrEmpty(SelectLogic))
+            {
+                MessageBox.Show("请填写前置项判定逻辑!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            //输入项
+            if (string.IsNullOrEmpty(SelectInJudge))
+            {
+                MessageBox.Show("请填写输入项测试项测试类型!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            if (string.IsNullOrEmpty(InSelectLogic))
+            {
+                MessageBox.Show("请填写输入项判定逻辑!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            //输出项
+            if (string.IsNullOrEmpty(SelectOutJudge))
+            {
+                MessageBox.Show("请填写结果项测试项测试类型!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            if (string.IsNullOrEmpty(OutSelectLogic))
+            {
+                MessageBox.Show("请填写结果项判定逻辑!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                return;
+            }
+            try
+            {
+
+                //更新测试方案名称
+                if (bas_Plc_Test_Scheme != null)
+                {
+                    bas_Plc_Test_Scheme.scheme_name = ScheduleName;
+                    bas_Plc_Test_Scheme.devicekind_name = DeviceKindName;
+                    _basicPlcTestSchemeService.Edit(bas_Plc_Test_Scheme);
+                }
+
+                //查找测试方案id
+                var finsScheHave = _basicPlcTestSchemeService.FindByName(ScheduleName);
+                if (finsScheHave != null)
+                {
+                    long id = finsScheHave.scheme_id;
+                    //增加或修改方案明细表
+                    AddOrEditDetailsToDb(id);
+
+                }
+                //更新已有的测试项
+                GetExistSchs();
+                //清空已填写的内容
+
+                BeforeConList = new ObservableCollection<BasPlcItemConfigDto>();
+                InConList = new ObservableCollection<BasPlcItemConfigDto>();
+                OutConList = new ObservableCollection<BasPlcItemConfigDto>();
+            }
+            catch (Exception ex)
+            {
+                _logger.LogError(ex.ToString());
+            }
+
+
+
+        }
+
+        /// <summary>
+        /// 方案明细添加到数据库
+        /// </summary>
+        private void AddOrEditDetailsToDb(long scheduleId)
+        {
+            //前置项json转化
+            string prefixJsonStr = ModelToJsonToStr(BeforeSelectJudge, SelectLogic, BeforeDetail, BeforeConList);
+            //输入项json转化
+            string inJsonStr = ModelToJsonToStr(SelectInJudge, InSelectLogic, InDetail, InConList);
+            //输出项json转化
+            string outJsonStr = ModelToJsonToStr(SelectOutJudge, OutSelectLogic, OutDetail, OutConList);
+            //添加达到测试主表
+            //增加测试方案
+            BasicPlcTestSchemeDtlDto schDtlDto = new BasicPlcTestSchemeDtlDto();
+            schDtlDto.SchemeId = scheduleId;
+            schDtlDto.ItemName = TestName;
+
+            schDtlDto.ItemType = SelectTest;
+            schDtlDto.Precondition = prefixJsonStr;
+            schDtlDto.PreconditionDescribe = BeforeDetail;
+            schDtlDto.Action = inJsonStr;
+            schDtlDto.ActionDescribe = InDetail;
+            schDtlDto.JudgementResult = outJsonStr;
+            schDtlDto.JudgementResultDescribe = OutDetail;
+            schDtlDto.CreateBy = Appsession.UserName;
+            schDtlDto.CreateTime = DateTime.Now;
+            schDtlDto.UpdateTime = DateTime.Now;
+            schDtlDto.UpdateBy = Appsession.UserName;
+            bas_plc_test_scheme_dtl schDtlEntity = _mapper.Map<BasicPlcTestSchemeDtlDto, bas_plc_test_scheme_dtl>(schDtlDto);
+            schDtlEntity.item_type = StrToItemType(schDtlDto.ItemType);
+            try
+            {
+             
+                
+                   
+                    {
+                      
+                        {
+                            schDtlDto.SchemeDtlId = schDtlMainId;
+                            bas_plc_test_scheme_dtl schDtlEntityEdit = _mapper.Map<BasicPlcTestSchemeDtlDto, bas_plc_test_scheme_dtl>(schDtlDto);
+                            //ItemType 转化
+                            schDtlEntityEdit.item_type = StrToItemType(schDtlDto.ItemType);
+                            bool isSucc = _basicPlcTestSchemeDtlService.Edit(schDtlEntityEdit);
+                            if (isSucc)
+                            {
+                                _logger.LogInformation($"更新方案成功。方案名{ScheduleName},测试项{TestName}");
+                                MessageBoxResult boxResult = MessageBox.Show("保存成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
+                            }
+                            else
+                            {
+                                MessageBoxResult boxResult = MessageBox.Show("保存失败", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                                return;
+                            }
+
+                        }
+
+                    }
+                
+            }
+            catch (Exception ex)
+            {
+                _logger.LogError(ex.ToString());
+            }
+
+
+
+        }
+        /// <summary>
+        /// 转化
+        /// </summary>
+        /// <param name="typeStr"></param>
+        /// <returns></returns>
+        private int StrToItemType(string typeStr)
+        {
+            int itemInt = 0;
+            switch (typeStr)
+            {
+                case "前置项":
+                    itemInt = 0;
+                    break;
+                case "PLC点位测试项":
+                    itemInt = 1;
+                    break;
+                case "Robot动作测试":
+                    itemInt = 2;
+                    break;
+            }
+            return itemInt;
+        }
+        /// <summary>
+        /// mode转json
+        /// </summary>
+        /// <param name="itemType"></param>
+        /// <param name="itemLogical"></param>
+        /// <param name="description"></param>
+        /// <param name="conList"></param>
+        /// <returns></returns>
+
+        private string ModelToJsonToStr(string itemType, string itemLogical, string description, ObservableCollection<BasPlcItemConfigDto> conList)
+        {
+            JsonModel prefixJsonModel = new JsonModel();
+            prefixJsonModel.ItemType = itemType;
+            prefixJsonModel.ItemLogical = itemLogical;
+            prefixJsonModel.Description = description;
+            prefixJsonModel.DetailInfo = new List<DetailPLC>();
+            foreach (var item in conList)
+            {
+                DetailPLC plcItem = new DetailPLC();
+                plcItem.Id = item.Id;
+                plcItem.PlcItem = item.PlcItem;
+                plcItem.PlcAddress = item.PlcAddress;
+                plcItem.PlcAddType = item.PlcAddType;
+                plcItem.PlcValue = item.PlcValue;
+                plcItem.Remark = item.Remark;
+                prefixJsonModel.DetailInfo.Add(plcItem);
+
+            }
+            string prefixJsonStr = JsonConvert.SerializeObject(prefixJsonModel);
+            return prefixJsonStr;
+        }
+        /// <summary>
+        /// 重置
+        /// </summary>
+        /// <param name="obj"></param>
+        private void ResetMethod(string obj)
+        {
+            ScheduleName = string.Empty;
+            DeviceKindName = string.Empty;
+            TestName = string.Empty;
+        }
+
+      
+
+       
+
+        public bool CanCloseDialog()
+        {
+            return true;
+        }
+
+        public void OnDialogClosed()
+        {
+          
+        }
+
+        public void OnDialogOpened(IDialogParameters parameters)
+        {
+            //编辑
+            var getMsg = parameters.GetValues<long>("Key");
+            ///值不为空,表示修改,为空表示新增
+            if (getMsg != null)
+            {
+                foreach (var item in getMsg)
+                {
+                    int schDtlId = Convert.ToInt32(item);
+                    schDtlMainId = schDtlId;//全局变量赋值,测试方案明细id
+                    GetDetaiMsg(schDtlId);
+
+                }
+            }
+            
+        }
+
+
+        #endregion
+
+
+
+        #region 命令绑定
+        public DelegateCommand CloseCommand { set; get; }
+        public DelegateCommand<string> SureCommand { set; get; }
+        public DelegateCommand<string> ResetCommand { set; get; }
+        /// <summary>
+        /// 新增对话框按钮
+        /// </summary>
+        public DelegateCommand<string> AddDetailCommand { set; get; }
+        /// <summary>
+        /// 表格删除
+        /// </summary>
+        public DelegateCommand<Object> DeleteBeforeCommand { set; get; }
+        /// <summary>
+        /// 表格编辑按钮
+        /// </summary>
+        public DelegateCommand<Object> EditBeforeCommand { set; get; }
+
+        /// <summary>
+        /// 输入项
+        /// </summary>
+        public DelegateCommand<Object> DeleteInCommand { set; get; }
+
+        public DelegateCommand<Object> EditInCommand { set; get; }
+
+        /// <summary>
+        /// 输出项
+        /// </summary>
+        public DelegateCommand<Object> DeleteOutCommand { set; get; }
+
+        public DelegateCommand<Object> EditOutCommand { set; get; }
+
+        public DelegateCommand<Object> OnLoadCommand { set; get; }
+        public DelegateCommand TxtLostFocusCommand { set; get; }
+        public DelegateCommand<string> OpenExistCommand { set; get; }
+        public DelegateCommand<object> DownCommand { set; get; }
+        public DelegateCommand<object> UpCommand { set; get; }
+    
+        public DelegateCommand<object> EditDetailCommand { set; get; }
+   
+        public DelegateCommand<object> DisAnoCommand { set; get; }
+        public DelegateCommand<object> CancelCommand { set; get; }
+
+        public DelegateCommand<object> DetailCommand { set; get; }
+        public DelegateCommand<object> DeleteCommand { set; get; }
+
+        #endregion
+        #region 变量绑定
+        /// <summary>
+        /// 测试方案编码
+        /// </summary>
+        private string scheduleName;
+        public string ScheduleName
+        {
+            get { return scheduleName; }
+            set { scheduleName = value; RaisePropertyChanged(); }
+        }
+        /// <summary>
+        /// 设备类型
+        /// </summary>
+        private string deviceKindName;
+        public string DeviceKindName
+        {
+            get { return deviceKindName; }
+            set { deviceKindName = value; RaisePropertyChanged(); }
+        }
+        /// <summary>
+        /// 测试项名称
+        /// </summary>
+        private string testName;
+        public string TestName
+        {
+            get { return testName; }
+            set { testName = value; RaisePropertyChanged(); }
+        }
+        /// <summary>
+        /// 测试项类型
+        /// </summary>
+        private List<string> testKinds = new List<string>();
+        public List<string> TestKinds
+        {
+            get { return testKinds; }
+            set { testKinds = value; RaisePropertyChanged(); }
+        }
+        /// <summary>
+        /// 
+        /// </summary>
+        private string selectTest;
+        public string SelectTest
+        {
+            get { return selectTest; }
+            set { selectTest = value; RaisePropertyChanged(); }
+        }
+        /// <summary>
+        /// 判定类型(前置项)
+        /// </summary>
+        private List<string> beforeJudgeKinds = new List<string>();
+        public List<string> BeforeJudgeKinds
+        {
+            get { return beforeJudgeKinds; }
+            set { beforeJudgeKinds = value; RaisePropertyChanged(); }
+        }
+        private string beforeSelectJudge;
+        public string BeforeSelectJudge
+        {
+            get { return beforeSelectJudge; }
+            set { beforeSelectJudge = value; RaisePropertyChanged(); }
+        }
+        /// <summary>
+        /// 逻辑判断
+        /// </summary>
+        private List<string> judgeLogicKinds = new List<string>();
+        public List<string> JudgeLogicKinds
+        {
+            get { return judgeLogicKinds; }
+            set { judgeLogicKinds = value; RaisePropertyChanged(); }
+        }
+        private string selectLogic;
+        public string SelectLogic
+        {
+            get { return selectLogic; }
+            set { selectLogic = value; RaisePropertyChanged(); }
+        }
+        private string beforeDetail;
+        public string BeforeDetail
+        {
+            get { return beforeDetail; }
+            set { beforeDetail = value; RaisePropertyChanged(); }
+        }
+
+        private ObservableCollection<BasPlcItemConfigDto> beforeConList;
+        public ObservableCollection<BasPlcItemConfigDto> BeforeConList
+        {
+            get { return beforeConList; }
+            set { beforeConList = value; RaisePropertyChanged(); }
+        }
+
+        /// <summary>
+        /// 判定类型(输入项)
+        /// </summary>
+        private List<string> inJudgeKinds = new List<string>();
+        public List<string> InJudgeKinds
+        {
+            get { return inJudgeKinds; }
+            set { inJudgeKinds = value; RaisePropertyChanged(); }
+        }
+        private string selectInJudge;
+        public string SelectInJudge
+        {
+            get { return selectInJudge; }
+            set { selectInJudge = value; RaisePropertyChanged(); }
+        }
+        /// <summary>
+        /// 逻辑判断
+        /// </summary>
+        private List<string> inJudgeLogicKinds = new List<string>();
+        public List<string> InJudgeLogicKinds
+        {
+            get { return inJudgeLogicKinds; }
+            set { inJudgeLogicKinds = value; RaisePropertyChanged(); }
+        }
+        private string inSelectLogic;
+        public string InSelectLogic
+        {
+            get { return inSelectLogic; }
+            set { inSelectLogic = value; RaisePropertyChanged(); }
+        }
+        private string inDetail;
+        public string InDetail
+        {
+            get { return inDetail; }
+            set { inDetail = value; RaisePropertyChanged(); }
+        }
+
+        private ObservableCollection<BasPlcItemConfigDto> inConList;
+        public ObservableCollection<BasPlcItemConfigDto> InConList
+        {
+            get { return inConList; }
+            set { inConList = value; RaisePropertyChanged(); }
+        }
+        /// <summary>
+        /// 判定类型(结果项)
+        /// </summary>
+        private List<string> outJudgeKinds = new List<string>();
+        public List<string> OutJudgeKinds
+        {
+            get { return outJudgeKinds; }
+            set { outJudgeKinds = value; RaisePropertyChanged(); }
+        }
+        private string selectOutJudge;
+        public string SelectOutJudge
+        {
+            get { return selectOutJudge; }
+            set { selectOutJudge = value; RaisePropertyChanged(); }
+        }
+
+
+        /// <summary>
+        /// 逻辑判断
+        /// </summary>
+        private List<string> outJudgeLogicKinds = new List<string>();
+        public List<string> OutJudgeLogicKinds
+        {
+            get { return outJudgeLogicKinds; }
+            set { outJudgeLogicKinds = value; RaisePropertyChanged(); }
+        }
+        private string outSelectLogic;
+        public string OutSelectLogic
+        {
+            get { return outSelectLogic; }
+            set { outSelectLogic = value; RaisePropertyChanged(); }
+        }
+
+        private string outDetail;
+        public string OutDetail
+        {
+            get { return outDetail; }
+            set { outDetail = value; RaisePropertyChanged(); }
+        }
+        private ObservableCollection<BasPlcItemConfigDto> outConList;
+        public ObservableCollection<BasPlcItemConfigDto> OutConList
+        {
+            get { return outConList; }
+            set { outConList = value; RaisePropertyChanged(); }
+        }
+
+        /// <summary>
+        /// 设备类型
+        /// </summary>
+        private List<string> deviceKindNameList;
+        public List<string> DeviceKindNameList
+        {
+            get { return deviceKindNameList; }
+            set { deviceKindNameList = value; RaisePropertyChanged(); }
+        }
+
+        private ObservableCollection<SelectItemModel> schProjectList = new ObservableCollection<SelectItemModel>();
+        public ObservableCollection<SelectItemModel> SchProjectList
+        {
+            get { return schProjectList; }
+            set { SetProperty(ref schProjectList, value); }
+        }
+
+
+        #endregion
+
+    }
+}

+ 518 - 0
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/EditSchViewModel.cs

@@ -0,0 +1,518 @@
+using AutoMapper;
+using BizService;
+using BlankApp1.Events;
+using Microsoft.Extensions.Logging;
+using Model.Dto;
+using Model.Entities;
+using Newtonsoft.Json;
+using PLCTool.Common;
+using PLCTool.Models;
+using Prism.Commands;
+using Prism.Events;
+using Prism.Mvvm;
+using Prism.Regions;
+using Prism.Services.Dialogs;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace PLCTool.ViewModels.BasicConfigViewModel
+{
+  
+    public class EditSchViewModel : BindableBase, INavigationAware
+    {
+        private readonly IDialogService _dialog;
+        private readonly IEventAggregator _aggregator;
+        private readonly IRegionManager _regionManager;
+        private readonly IOptionConfigService _optionConfigService;
+        private readonly IBasicPlcTestSchemeService _basicPlcTestSchemeService;
+        private readonly IBasicPlcTestSchemeDtlService _basicPlcTestSchemeDtlService;
+        private readonly IBasicDeviceKindService _iBasicDeviceKindService;
+        private readonly IMapper _mapper;
+        private readonly ILogger _logger;
+        private List<OptionConfigDto> _optionConfigs;
+        private bas_plc_test_scheme bas_Plc_Test_Scheme;//测试方案
+        private int schDtlMainId = 0;//测试方案明细主键id
+        public event Action<NavigationResult> RequestClose;
+        public ObservableCollection<SelectItemModel> allSchProjectList = new ObservableCollection<SelectItemModel>(); //所有测试项
+        public EditSchViewModel(IDialogService dialog, IEventAggregator aggregator, IRegionManager regionManager, IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService, IBasicDeviceKindService iBasicDeviceKindService, IMapper mapper, ILogger logger)
+        {
+            _dialog = dialog;
+            _aggregator = aggregator;
+            _regionManager = regionManager;
+            _optionConfigService = optionConfigService;
+            _basicPlcTestSchemeService = basicPlcTestSchemeService;
+            _basicPlcTestSchemeDtlService = basicPlcTestSchemeDtlService;
+            _iBasicDeviceKindService = iBasicDeviceKindService;
+            _mapper = mapper;
+            _logger = logger;
+            CloseCommand = new DelegateCommand(Close);
+           
+            ResetCommand = new DelegateCommand<string>(ResetMethod);
+        
+            OnLoadCommand = new DelegateCommand<object>(OnLoad);
+            TxtLostFocusCommand = new DelegateCommand(GetExistSchs);
+          
+            UpCommand = new DelegateCommand<object>(DataUp);
+            DownCommand = new DelegateCommand<object>(DataDown);
+            SaveAllSchCommand = new DelegateCommand<object>(SaveAllSch);
+
+            CancelCommand = new DelegateCommand<object>(Cancel);
+            DetailCommand = new DelegateCommand<object>(CheckDetail);
+            DeleteCommand = new DelegateCommand<object>(Delete);
+            QueryCommand = new DelegateCommand<object>(Query);
+            EditCommand = new DelegateCommand<object>(EditSchDtl);
+              //获取设备类型
+            DeviceKindNameList = _iBasicDeviceKindService.FindAllDeviceKind();
+            
+        }
+
+        private void EditSchDtl(object obj)
+        {
+            long schDtlId = Convert.ToInt64(obj);
+            DialogParameters parm = new DialogParameters();
+            parm.Add("Key", schDtlId);
+            //弹出详情对话框
+            _dialog.ShowDialog("EditItemDetailView", parm, async callback =>
+            {
+                if (callback.Result == ButtonResult.OK)
+                {
+                    //获取已经有的测试项
+                    GetExistSchs();
+                }
+
+            });
+        }
+
+        private void Query(object obj)
+        {
+            var conditions = (from a in allSchProjectList
+                                 where ((SelectTest=="---") ? true : (a.ItemType == SelectTest))
+                                && (string.IsNullOrEmpty(TestName) ? true : (a.ItemName == TestName))
+                               select a).ToList();
+            SchProjectList = new ObservableCollection<SelectItemModel>(conditions);
+
+        }
+
+
+
+
+
+        #region idialog接口实现
+        public string Title { set; get; } = "新增方案";
+
+
+
+
+
+        #endregion
+
+
+
+
+        #region 私有方法
+        /// <summary>
+        /// 获取配置
+        /// </summary>
+        private void GetConfigOption()
+        {
+            var configList = _optionConfigService.QueryList();
+            _optionConfigs = _mapper.Map<List<OptionConfig>, List<OptionConfigDto>>(configList);
+            var tests = _optionConfigs.FindAll(x => x.TypeID == 1);
+            TestKinds.Add("---");
+            foreach (var test in tests)
+            {
+                TestKinds.Add(test.ContentOption);
+            }
+        }
+
+        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)
+        {
+
+        }
+
+
+        /// <summary>
+        /// 取消返回列表界面
+        /// </summary>
+        /// <param name="obj"></param>
+        private void Cancel(object obj)
+        {
+            _regionManager.Regions["ContentRegion"].RequestNavigate("BaseConfigView");
+        }
+    
+
+
+
+        /// <summary>
+        /// 保存所有测试项
+        /// </summary>
+        /// <param name="obj"></param>
+        /// <exception cref="NotImplementedException"></exception>
+        private void SaveAllSch(object obj)
+        {
+            //先保存一下当前测试项
+           
+            //可能调整了测试项的顺序,所以先删除所有测试项
+            var findSche = _basicPlcTestSchemeService.FindByName(ScheduleName);
+            if (findSche != null)
+            {
+
+                //显示设备名称
+                DeviceKindName = findSche.devicekind_name;
+                long schID = findSche.scheme_id;
+                //查找此方案下的所有的测试项,并
+                var schDtls = _basicPlcTestSchemeDtlService.QueryList()?.FindAll(x => x.scheme_id == schID);
+                //先删除
+                foreach (var unit in schDtls)
+                {
+                    int id = Convert.ToInt32(unit.scheme_dtl_id);
+                    _basicPlcTestSchemeDtlService.Delete(id);
+
+
+                }
+                //按照调整后的顺序添加
+                foreach (var item in SchProjectList)
+                {
+                    //测试项目名称
+                    string schItenName = item.ItemName;
+                    var dtl = schDtls.FirstOrDefault(x => x.item_name == schItenName);
+                    if (dtl != null)
+                    {
+                        //要将主键改为0,否则还是原来的主键
+                        dtl.scheme_dtl_id = 0;
+                        _basicPlcTestSchemeDtlService.Add(dtl);
+                    }
+
+                }
+                MessageBox.Show("保存成功!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
+                //发布消息
+                _aggregator.GetEvent<ChangeEvent>().Publish("Change");
+                _regionManager.Regions["ContentRegion"].RequestNavigate("BaseConfigView");
+            }
+        }
+      
+        /// <summary>
+        /// 获取测试项
+        /// </summary>
+        private void GetExistSchs()
+        {
+            allSchProjectList.Clear();
+            SchProjectList.Clear();
+            var findSche = _basicPlcTestSchemeService.FindByName(ScheduleName);
+            if (findSche != null)
+            {
+
+                //显示设备名称
+                DeviceKindName = findSche.devicekind_name;
+                long schID = findSche.scheme_id;
+                //查找此方案下的所有的测试项,并增加到表格
+                var schDtls = _basicPlcTestSchemeDtlService.QueryList()?.FindAll(x => x.scheme_id == schID)?.OrderBy(x => x.scheme_dtl_id);
+                foreach (var unit in schDtls)
+                {
+                    string itemType = string.Empty;
+                    switch (unit.item_type)
+                    {
+                        case 0:
+                            itemType = "前置项";
+                            break;
+                        case 1:
+                            itemType = "PLC点位测试项";
+                            break;
+                        case 2:
+                            itemType = "Robot动作测试";
+                            break;
+                    }
+
+                    allSchProjectList.Add(new SelectItemModel
+                    {
+                        SchDtlId = unit.scheme_dtl_id,
+                        ItemName = unit.item_name,
+                        ItemType = itemType,
+                        BeforeDetail = unit.precondition_describe,
+                        InDetail = unit.action_describe,
+                        OutDetail = unit.judgement_result_describe
+                    });
+
+                }
+                foreach (var item in allSchProjectList)
+                {
+                    SchProjectList.Add(item);
+                }
+            }
+        }
+
+        /// <summary>
+        /// 下移
+        /// </summary>
+        /// <param name="obj"></param>
+        private void DataDown(object obj)
+        {
+            int id = Convert.ToInt32(obj);
+            var findScheExist = SchProjectList.FirstOrDefault(x => x.SchDtlId == id);
+            if (findScheExist != null)
+            {
+
+                int index = SchProjectList.IndexOf(findScheExist);
+                if (index != -1)
+                {
+                    if (index == SchProjectList.Count - 1)
+                        return;
+                    SchProjectList.RemoveAt(index);
+                    index = index + 1;
+                    SchProjectList.Insert(index, findScheExist);
+                }
+
+
+            }
+        }
+        /// <summary>
+        /// 上移
+        /// </summary>
+        /// <param name="obj"></param>
+        private void DataUp(object obj)
+        {
+            int id = Convert.ToInt32(obj);
+            var findScheExist = SchProjectList.FirstOrDefault(x => x.SchDtlId == id);
+            if (findScheExist != null)
+            {
+
+                int index = SchProjectList.IndexOf(findScheExist);
+                if (index != -1)
+                {
+                    if (index == 0)
+                        return;
+                    SchProjectList.RemoveAt(index);
+                    index = index - 1;
+                    SchProjectList.Insert(index, findScheExist);
+                }
+
+
+            }
+
+        }
+
+        private void OnLoad(object obj)
+        {
+            GetConfigOption();
+        }
+       
+
+
+        /// <summary>
+        /// 关闭按钮
+        /// </summary>
+        private void Close()
+        {
+            //RequestClose?.Invoke(new NavigationResult(new NavigationContext(),true);
+        }
+        
+
+
+        /// <summary>
+        /// mode转json
+        /// </summary>
+        /// <param name="itemType"></param>
+        /// <param name="itemLogical"></param>
+        /// <param name="description"></param>
+        /// <param name="conList"></param>
+        /// <returns></returns>
+
+        private string ModelToJsonToStr(string itemType, string itemLogical, string description, ObservableCollection<BasPlcItemConfigDto> conList)
+        {
+            JsonModel prefixJsonModel = new JsonModel();
+            prefixJsonModel.ItemType = itemType;
+            prefixJsonModel.ItemLogical = itemLogical;
+            prefixJsonModel.Description = description;
+            prefixJsonModel.DetailInfo = new List<DetailPLC>();
+            foreach (var item in conList)
+            {
+                DetailPLC plcItem = new DetailPLC();
+                plcItem.Id = item.Id;
+                plcItem.PlcItem = item.PlcItem;
+                plcItem.PlcAddress = item.PlcAddress;
+                plcItem.PlcAddType = item.PlcAddType;
+                plcItem.PlcValue = item.PlcValue;
+                plcItem.Remark = item.Remark;
+                prefixJsonModel.DetailInfo.Add(plcItem);
+
+            }
+            string prefixJsonStr = JsonConvert.SerializeObject(prefixJsonModel);
+            return prefixJsonStr;
+        }
+        /// <summary>
+        /// 重置
+        /// </summary>
+        /// <param name="obj"></param>
+        private void ResetMethod(string obj)
+        {
+           
+            SelectTest = "---";
+            TestName = string.Empty;
+        }
+
+        public void OnNavigatedTo(NavigationContext navigationContext)
+        {
+            //编辑
+            var getMsg = navigationContext.Parameters.GetValues<string>("Key");
+            ///值不为空,表示修改,为空表示新增
+            if (getMsg != null)
+            {
+                foreach (var item in getMsg)
+                {
+                    try
+                    {
+
+                        Title = "编辑方案";
+                        ScheduleName = item.ToString();
+                        //获取已经有的测试项
+                        GetExistSchs();
+                     
+
+                    }
+                    catch (Exception ex)
+                    {
+                        _logger.LogError(ex.ToString());
+                    }
+
+
+                }
+            }
+
+            var getMsg2 = navigationContext.Parameters.GetValues<string>("Key2");
+            if (getMsg2 != null)
+            {
+                foreach (var item in getMsg2)
+                {
+                    DeviceKindName = item;
+                }
+            }
+        }
+
+        public bool IsNavigationTarget(NavigationContext navigationContext)
+        {
+            return true;
+        }
+
+        public void OnNavigatedFrom(NavigationContext navigationContext)
+        {
+
+        }
+
+
+        #endregion
+
+
+
+        #region 命令绑定
+        public DelegateCommand CloseCommand { set; get; }
+        public DelegateCommand<string> SureCommand { set; get; }
+        public DelegateCommand<string> ResetCommand { set; get; }
+      
+
+
+        public DelegateCommand<Object> OnLoadCommand { set; get; }
+        public DelegateCommand TxtLostFocusCommand { set; get; }
+        public DelegateCommand<string> OpenExistCommand { set; get; }
+        public DelegateCommand<object> DownCommand { set; get; }
+        public DelegateCommand<object> UpCommand { set; get; }
+    
+ 
+        public DelegateCommand<object> CancelCommand { set; get; }
+
+        public DelegateCommand<object> DetailCommand { set; get; }
+        public DelegateCommand<object> DeleteCommand { set; get; }
+        public DelegateCommand<object> SaveAllSchCommand { set; get; }
+
+        public DelegateCommand<object> QueryCommand { set; get; }
+        public DelegateCommand<object> EditCommand { set; get; }
+        
+        #endregion
+        #region 变量绑定
+        /// <summary>
+        /// 测试方案编码
+        /// </summary>
+        private string scheduleName;
+        public string ScheduleName
+        {
+            get { return scheduleName; }
+            set { scheduleName = value; RaisePropertyChanged(); }
+        }
+        /// <summary>
+        /// 设备类型
+        /// </summary>
+        private string deviceKindName;
+        public string DeviceKindName
+        {
+            get { return deviceKindName; }
+            set { deviceKindName = value; RaisePropertyChanged(); }
+        }
+        /// <summary>
+        /// 测试项名称
+        /// </summary>
+        private string testName;
+        public string TestName
+        {
+            get { return testName; }
+            set { testName = value; RaisePropertyChanged(); }
+        }
+     
+       
+        /// <summary>
+        /// 测试项类型
+        /// </summary>
+        private ObservableCollection<string> testKinds = new ObservableCollection<string>();
+        public ObservableCollection<string> TestKinds
+        {
+            get { return testKinds; }
+            set { testKinds = value; RaisePropertyChanged(); }
+        }
+        /// <summary>
+        /// 
+        /// </summary>
+        private string selectTest;
+        public string SelectTest
+        {
+            get { return selectTest; }
+            set { selectTest = value; RaisePropertyChanged(); }
+        }
+
+        /// <summary>
+        /// 设备类型
+        /// </summary>
+        private List<string> deviceKindNameList;
+        public List<string> DeviceKindNameList
+        {
+            get { return deviceKindNameList; }
+            set { deviceKindNameList = value; RaisePropertyChanged(); }
+        }
+
+        private ObservableCollection<SelectItemModel> schProjectList = new ObservableCollection<SelectItemModel>();
+        public ObservableCollection<SelectItemModel> SchProjectList
+        {
+            get { return schProjectList; }
+            set { SetProperty(ref schProjectList, value); }
+        }
+
+
+        #endregion
+
+    }
+}

+ 7 - 20
BlankApp1/BlankApp1/Views/BasicConfigView/AddSchView.xaml

@@ -8,15 +8,7 @@
              xmlns:prism="http://prismlibrary.com/" 
              BorderBrush="#CBCBCB" BorderThickness="1"
              Height="700" Width="1100" >
-    <!--<prism:Dialog.WindowStyle>
-        <Style TargetType="Window">
-            <Setter Property="SizeToContent" Value="WidthAndHeight" />
-            <Setter Property="ResizeMode" Value="NoResize" />
-            <Setter Property="prism:Dialog.WindowStartupLocation" Value="CenterScreen" />
-            <Setter Property="WindowStyle" Value="None" />
-        
-        </Style>
-    </prism:Dialog.WindowStyle>-->
+   
     <UserControl.Resources>
         <Style TargetType="TextBlock" x:Key="textBlockStyle">
             <Setter Property="Width" Value="80"/>
@@ -70,13 +62,7 @@
                     <StackPanel Orientation="Horizontal">
                         <TextBlock Text="测试方案名称:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
                         <TextBox  Height="28" Width="120" Text="{Binding ScheduleName}" >
-                            <b:Interaction.Triggers>
-                                <b:EventTrigger EventName="LostFocus">
-                                    <b:InvokeCommandAction Command="{Binding TxtLostFocusCommand}" CommandParameter="{Binding ElementName=TBSeriesDescription}"/>
-                                </b:EventTrigger>
-
-                            </b:Interaction.Triggers>
-
+              
                         </TextBox>
                     </StackPanel>
                     <Button  Content="取消" Width="80"  Margin="5,0"  Command="{Binding CancelCommand}" Style="{StaticResource NormalButtonStyle}" DockPanel.Dock="Right" />
@@ -105,14 +91,15 @@
                         </StackPanel>
                         <StackPanel Grid.Row="1" Orientation="Horizontal">
 
-                            <StackPanel Orientation="Horizontal" >
-                                <TextBlock Text="测试项类型:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
-                                <ComboBox  Height="28" Width="160" ItemsSource="{Binding TestKinds}" SelectedItem="{Binding SelectTest}" />
-                            </StackPanel>
                             <StackPanel Orientation="Horizontal">
                                 <TextBlock Text="测试项名称:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
                                 <TextBox  Height="28" Width="160"  Text="{Binding TestName}"/>
                             </StackPanel>
+
+                            <StackPanel Orientation="Horizontal" >
+                                <TextBlock Text="测试项类型:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
+                                <ComboBox  Height="28" Width="160" ItemsSource="{Binding TestKinds}" SelectedItem="{Binding SelectTest}" />
+                            </StackPanel>
                         </StackPanel>
 
                         <Border Grid.Row="1"  BorderBrush="#CBCBCB" BorderThickness="1" />

+ 381 - 0
BlankApp1/BlankApp1/Views/BasicConfigView/EditItemDetailView.xaml

@@ -0,0 +1,381 @@
+<UserControl x:Class="PLCTool.Views.BasicConfigView.EditItemDetailView"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+             xmlns:local="clr-namespace:PLCTool.Views.BasicConfigView"
+                         xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
+             xmlns:prism="http://prismlibrary.com/" 
+             BorderBrush="#CBCBCB" BorderThickness="1"
+             Height="700" Width="1100" >
+
+    <UserControl.Resources>
+        <Style TargetType="TextBlock" x:Key="textBlockStyle">
+            <Setter Property="Width" Value="80"/>
+            <Setter Property="FontSize" Value="12"/>
+            <Setter Property="VerticalAlignment" Value="Center"/>
+            <Setter Property="TextAlignment" Value="Right"/>
+            <Setter Property="Margin" Value="0,0,5,0"/>
+        </Style>
+
+        <Style x:Key="CenterAlignedGroupBoxStyle" TargetType="{x:Type GroupBox}">
+            <Setter Property="Template">
+                <Setter.Value>
+                    <ControlTemplate TargetType="GroupBox">
+                        <Grid>
+                            <Grid.RowDefinitions>
+                                <RowDefinition Height="Auto"/>
+                                <RowDefinition Height="*"/>
+                            </Grid.RowDefinitions>
+                            <Border Grid.Row="0" Background="BlueViolet" CornerRadius="5" Padding="5">
+                                <TextBlock Text="{TemplateBinding Header}" HorizontalAlignment="Right"/>
+                            </Border>
+                            <ContentControl Grid.Row="1" Content="{TemplateBinding Content}"/>
+                        </Grid>
+                    </ControlTemplate>
+                </Setter.Value>
+            </Setter>
+        </Style>
+    </UserControl.Resources>
+
+    <Grid>
+        <b:Interaction.Triggers>
+            <b:EventTrigger EventName="Loaded">
+                <b:InvokeCommandAction Command="{Binding OnLoadCommand}" CommandParameter="{Binding ElementName=tt}"/>
+            </b:EventTrigger>
+        </b:Interaction.Triggers>
+       
+            <Grid >
+
+                <Grid.RowDefinitions>
+                    <RowDefinition Height="50" />
+                    <RowDefinition  />
+             
+
+                </Grid.RowDefinitions>
+
+                <DockPanel  Grid.Row="0" Margin="10" LastChildFill="False">
+                    <StackPanel Orientation="Horizontal"  Grid.Row="4" HorizontalAlignment="Center">
+                        <TextBlock Text="设备类型:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"  Width="60"/>
+                        <ComboBox  Height="28" Width="120" ItemsSource="{Binding DeviceKindNameList}" SelectedItem="{Binding DeviceKindName}" />
+                    </StackPanel>
+                    <StackPanel Orientation="Horizontal">
+                        <TextBlock Text="测试方案名称:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
+                        <TextBox  Height="28" Width="120" Text="{Binding ScheduleName}" />
+                    </StackPanel>
+                <Button  DockPanel.Dock="Right" Content="保存测试项" Width="80"  Margin="15,0"  Command="{Binding SureCommand}" Style="{StaticResource NormalButtonStyle}" />
+
+
+
+            </DockPanel>
+                <Border Grid.Row="0"  BorderBrush="#CBCBCB" BorderThickness="0,1" />
+
+
+                <Border  Grid.Row="1" BorderBrush="#409EFF"  BorderThickness="1" Margin="5" >
+
+                    <Grid>
+                        <Grid.RowDefinitions>
+                            <RowDefinition Height="50"/>
+                            <RowDefinition Height="50"/>
+                            <RowDefinition/>
+                            <RowDefinition/>
+                            <RowDefinition/>
+                            <RowDefinition Height="50"/>
+                        </Grid.RowDefinitions>
+                        <StackPanel Grid.Row="0" Orientation="Horizontal">
+                            <StackPanel Orientation="Horizontal" >
+                                <TextBlock Text="▊"  TextAlignment="Center" VerticalAlignment="Center" Foreground="#409EFF" Margin="5,0,5,0"/>
+                                <TextBlock Text="测试方案明细"  Style="{StaticResource NormalTextBlockStyle}" Margin="0,0,5,0"/>
+                            </StackPanel>
+                       
+                    </StackPanel>
+                        <StackPanel Grid.Row="1" Orientation="Horizontal">
+
+                            <StackPanel Orientation="Horizontal">
+                                <TextBlock Text="测试项名称:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
+                                <TextBox  Height="28" Width="160"  Text="{Binding TestName}"/>
+                            </StackPanel>
+
+                            <StackPanel Orientation="Horizontal" >
+                                <TextBlock Text="测试项类型:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
+                                <ComboBox  Height="28" Width="160" ItemsSource="{Binding TestKinds}" SelectedItem="{Binding SelectTest}" />
+                            </StackPanel>
+                        </StackPanel>
+
+                        <Border Grid.Row="1"  BorderBrush="#CBCBCB" BorderThickness="1" />
+                        <ScrollViewer Grid.Row="2">
+                            <Grid >
+                                <Grid.ColumnDefinitions>
+                                    <ColumnDefinition Width="80"/>
+                                    <ColumnDefinition/>
+                                    <ColumnDefinition Width="1.3*"/>
+                                </Grid.ColumnDefinitions>
+                                <TextBlock Grid.Column="0" Text="前置项" Style="{StaticResource NormalTextBlockStyle}" TextAlignment="Center">
+                                </TextBlock>
+                                <Border Grid.Column="1"  BorderBrush="#CBCBCB" BorderThickness="1,0" />
+                                <Grid Grid.Column="1">
+                                    <Grid.RowDefinitions>
+                                        <RowDefinition/>
+                                        <RowDefinition/>
+                                        <RowDefinition Height="2*"/>
+                                    </Grid.RowDefinitions>
+                                    <Grid Grid.Row="0">
+                                        <StackPanel Orientation="Horizontal" >
+                                            <TextBlock Text="测试项类型:"  Style="{StaticResource textBlockStyle}"/>
+                                            <ComboBox  Height="28" Width="150" ItemsSource="{Binding BeforeJudgeKinds}" SelectedItem="{Binding BeforeSelectJudge}" />
+                                        </StackPanel>
+                                    </Grid>
+                                    <Grid Grid.Row="1"  >
+                                        <StackPanel Orientation="Horizontal" >
+                                            <TextBlock Text="明细判定逻辑:"  Style="{StaticResource textBlockStyle}"/>
+                                            <ComboBox  Height="28" Width="150" ItemsSource="{Binding JudgeLogicKinds}" SelectedItem="{Binding SelectLogic}"/>
+                                        </StackPanel>
+                                    </Grid>
+                                    <Grid Grid.Row="2">
+                                        <DockPanel LastChildFill="True" >
+                                            <TextBlock Text="前置项描述:"   Style="{StaticResource textBlockStyle}" />
+                                            <TextBox x:Name="txtBefore"  TextWrapping="Wrap"  Text="{Binding BeforeDetail }"  AcceptsReturn="True" KeyDown="txtBefore_KeyDown"/>
+
+                                        </DockPanel>
+                                    </Grid>
+                                </Grid>
+                                <Grid Grid.Column="2" >
+                                    <Grid.RowDefinitions>
+                                        <RowDefinition Height="30"/>
+                                        <RowDefinition/>
+                                    </Grid.RowDefinitions>
+                                    <DockPanel LastChildFill="False">
+                                        <TextBlock Text="前置项明细:"   Style="{StaticResource textBlockStyle}" />
+                                        <Button  Content="新增" Height="22" Width="60"  Margin="5,0"  Command="{Binding AddDetailCommand}" CommandParameter="Before" Style="{StaticResource NormalButtonStyle}" DockPanel.Dock="Right"  />
+                                    </DockPanel>
+                                    <DataGrid Grid.Row="1"  ColumnWidth="*" AutoGenerateColumns="False" HeadersVisibility="All" CanUserAddRows="False"  SelectionUnit="FullRow" SelectionMode="Single"   RowHeaderWidth="0" HorizontalScrollBarVisibility="Disabled"
+  ColumnHeaderStyle="{StaticResource ColumnHeaderStyle}" x:Name="DeviceDataGrid" RowHeaderStyle="{StaticResource RowHeaderStyle}" RowStyle="{StaticResource DataGridRowtyle}"  AlternationCount="2"
+    ItemsSource="{Binding BeforeConList}"  IsReadOnly="True" Padding="0" >
+                                        <DataGrid.Columns >
+                                            <DataGridTextColumn Header="序号" Width="40" Binding="{Binding Id}" CellStyle="{StaticResource MyDataGridCellStyle}" />
+                                            <DataGridTextColumn Header="PLC地址" Binding="{Binding PlcAddress}" CellStyle="{StaticResource MyDataGridCellStyle}" />
+                                            <DataGridTextColumn Header="PLC变量名" Binding="{Binding PlcItem}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                                            <DataGridTextColumn Header="判定值" Binding="{Binding PlcValue}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                                            <DataGridTemplateColumn Header="操作" Width="160"  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.EditBeforeCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding Id}" Cursor="Hand" Margin="0,0,10,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.DeleteBeforeCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding Id}"   Cursor="Hand" >
+
+                                                                <StackPanel Orientation="Horizontal">
+                                                                    <TextBlock  Text="删除" VerticalAlignment="Center" Foreground="Blue"/>
+                                                                </StackPanel>
+                                                            </Button>
+
+                                                        </UniformGrid>
+                                                    </DataTemplate>
+                                                </DataGridTemplateColumn.CellTemplate>
+                                            </DataGridTemplateColumn>
+
+                                        </DataGrid.Columns>
+
+                                    </DataGrid>
+
+                                </Grid>
+                            </Grid>
+                        </ScrollViewer>
+                        <ScrollViewer Grid.Row="3">
+                            <Grid >
+                                <Grid.ColumnDefinitions>
+                                    <ColumnDefinition Width="80"/>
+                                    <ColumnDefinition/>
+                                    <ColumnDefinition Width="1.3*"/>
+                                </Grid.ColumnDefinitions>
+                                <TextBlock Grid.Column="0" Text="输入项" Style="{StaticResource NormalTextBlockStyle}" TextAlignment="Center">
+                                </TextBlock>
+                                <Border Grid.Column="1"  BorderBrush="#CBCBCB" BorderThickness="1,0" />
+                                <Grid Grid.Column="1">
+                                    <Grid.RowDefinitions>
+                                        <RowDefinition/>
+                                        <RowDefinition/>
+                                        <RowDefinition Height="2*"/>
+                                    </Grid.RowDefinitions>
+                                    <Grid Grid.Row="0">
+                                        <StackPanel Orientation="Horizontal" >
+                                            <TextBlock Text="测试项类型:"  Style="{StaticResource textBlockStyle}"/>
+                                            <ComboBox  Height="28" Width="150" ItemsSource="{Binding InJudgeKinds}" SelectedItem="{Binding SelectInJudge}" />
+                                        </StackPanel>
+                                    </Grid>
+                                    <Grid Grid.Row="1"  >
+                                        <StackPanel Orientation="Horizontal" >
+                                            <TextBlock Text="明细判定逻辑:"  Style="{StaticResource textBlockStyle}"/>
+                                            <ComboBox  Height="28" Width="150" ItemsSource="{Binding InJudgeLogicKinds}" SelectedItem="{Binding InSelectLogic}"/>
+                                        </StackPanel>
+                                    </Grid>
+                                    <Grid Grid.Row="2">
+                                        <DockPanel LastChildFill="True" >
+                                            <TextBlock Text="输入项描述:"   Style="{StaticResource textBlockStyle}" />
+                                            <TextBox x:Name="txtIn"  TextWrapping="Wrap"  Text="{Binding InDetail,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"  AcceptsReturn="True" KeyDown="txtIn_KeyDown"/>
+
+                                        </DockPanel>
+                                    </Grid>
+                                </Grid>
+                                <Grid Grid.Column="2" >
+                                    <Grid.RowDefinitions>
+                                        <RowDefinition Height="30"/>
+                                        <RowDefinition/>
+                                    </Grid.RowDefinitions>
+                                    <DockPanel LastChildFill="False">
+                                        <TextBlock Text="输入项明细:"   Style="{StaticResource textBlockStyle}" />
+                                        <Button  Content="新增" Height="22" Width="60"  Margin="5,0"  Command="{Binding AddDetailCommand}" CommandParameter="In" Style="{StaticResource NormalButtonStyle}" DockPanel.Dock="Right"  />
+                                    </DockPanel>
+                                    <DataGrid Grid.Row="1"  ColumnWidth="*" AutoGenerateColumns="False" HeadersVisibility="All" CanUserAddRows="False"  SelectionUnit="FullRow" SelectionMode="Single"   RowHeaderWidth="0" HorizontalScrollBarVisibility="Disabled"
+  ColumnHeaderStyle="{StaticResource ColumnHeaderStyle}" RowHeaderStyle="{StaticResource RowHeaderStyle}" RowStyle="{StaticResource DataGridRowtyle}"  AlternationCount="2"
+    ItemsSource="{Binding InConList}"  IsReadOnly="True" Padding="0" >
+                                        <DataGrid.Columns >
+                                            <DataGridTextColumn Header="序号" Width="40" Binding="{Binding Id}" CellStyle="{StaticResource MyDataGridCellStyle}" />
+                                            <DataGridTextColumn Header="PLC地址" Binding="{Binding PlcAddress}" CellStyle="{StaticResource MyDataGridCellStyle}" />
+                                            <DataGridTextColumn Header="PLC变量名" Binding="{Binding PlcItem}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                                            <DataGridTextColumn Header="判定值" Binding="{Binding PlcValue}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                                            <DataGridTemplateColumn Header="操作" Width="160"  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.EditInCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding Id}" Cursor="Hand" Margin="0,0,10,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.DeleteInCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding Id}"   Cursor="Hand" >
+
+                                                                <StackPanel Orientation="Horizontal">
+                                                                    <TextBlock  Text="删除" VerticalAlignment="Center" Foreground="Blue"/>
+                                                                </StackPanel>
+                                                            </Button>
+
+                                                        </UniformGrid>
+                                                    </DataTemplate>
+                                                </DataGridTemplateColumn.CellTemplate>
+                                            </DataGridTemplateColumn>
+
+                                        </DataGrid.Columns>
+
+                                    </DataGrid>
+
+                                </Grid>
+                            </Grid>
+                        </ScrollViewer>
+
+                        <Border Grid.Row="3"  BorderBrush="#CBCBCB" BorderThickness="0,1,0,0" />
+
+                        <ScrollViewer Grid.Row="4">
+                            <Grid >
+                                <Grid.ColumnDefinitions>
+                                    <ColumnDefinition Width="80"/>
+                                    <ColumnDefinition/>
+                                    <ColumnDefinition Width="1.3*"/>
+                                </Grid.ColumnDefinitions>
+                                <TextBlock Grid.Column="0" Text="结果项" Style="{StaticResource NormalTextBlockStyle}" TextAlignment="Center">
+                                </TextBlock>
+                                <Border Grid.Column="1"  BorderBrush="#CBCBCB" BorderThickness="1,0" />
+                                <Grid Grid.Column="1">
+                                    <Grid.RowDefinitions>
+                                        <RowDefinition/>
+                                        <RowDefinition/>
+                                        <RowDefinition Height="2*"/>
+                                    </Grid.RowDefinitions>
+                                    <Grid Grid.Row="0">
+                                        <StackPanel Orientation="Horizontal" >
+                                            <TextBlock Text="测试项类型:"  Style="{StaticResource textBlockStyle}"/>
+                                            <ComboBox  Height="28" Width="150" ItemsSource="{Binding OutJudgeKinds}" SelectedItem="{Binding SelectOutJudge}" />
+                                        </StackPanel>
+                                    </Grid>
+                                    <Grid Grid.Row="1"  >
+                                        <StackPanel Orientation="Horizontal" >
+                                            <TextBlock Text="明细判定逻辑:"  Style="{StaticResource textBlockStyle}"/>
+                                            <ComboBox  Height="28" Width="150" ItemsSource="{Binding OutJudgeLogicKinds}" SelectedItem="{Binding OutSelectLogic}"/>
+                                        </StackPanel>
+                                    </Grid>
+                                    <Grid Grid.Row="2">
+                                        <DockPanel LastChildFill="True" >
+                                            <TextBlock Text="结果项描述:"   Style="{StaticResource textBlockStyle}" />
+
+                                            <TextBox x:Name="txtOut"  TextWrapping="Wrap"  Text="{Binding OutDetail,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"  AcceptsReturn="True" KeyDown="txtOut_KeyDown"/>
+
+                                        </DockPanel>
+                                    </Grid>
+                                </Grid>
+                                <Grid Grid.Column="2" >
+                                    <Grid.RowDefinitions>
+                                        <RowDefinition Height="30"/>
+                                        <RowDefinition/>
+                                    </Grid.RowDefinitions>
+                                    <DockPanel LastChildFill="False">
+                                        <TextBlock Text="结果项明细:"   Style="{StaticResource textBlockStyle}" />
+                                        <Button  Content="新增" Height="22" Width="60"  Margin="5,0"  Command="{Binding AddDetailCommand}" CommandParameter="Out" Style="{StaticResource NormalButtonStyle}" DockPanel.Dock="Right"  />
+                                    </DockPanel>
+                                    <DataGrid Grid.Row="1"  ColumnWidth="*" AutoGenerateColumns="False" HeadersVisibility="All" CanUserAddRows="False"  SelectionUnit="FullRow" SelectionMode="Single"   RowHeaderWidth="0" HorizontalScrollBarVisibility="Disabled"
+  ColumnHeaderStyle="{StaticResource ColumnHeaderStyle}"  RowHeaderStyle="{StaticResource RowHeaderStyle}" RowStyle="{StaticResource DataGridRowtyle}"  AlternationCount="2"
+    ItemsSource="{Binding OutConList}"  IsReadOnly="True" Padding="0" >
+                                        <DataGrid.Columns >
+                                            <DataGridTextColumn Header="序号" Width="40" Binding="{Binding Id}" CellStyle="{StaticResource MyDataGridCellStyle}" />
+                                            <DataGridTextColumn Header="PLC地址" Binding="{Binding PlcAddress}" CellStyle="{StaticResource MyDataGridCellStyle}" />
+                                            <DataGridTextColumn Header="PLC变量名" Binding="{Binding PlcItem}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                                            <DataGridTextColumn Header="判定值" Binding="{Binding PlcValue}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                                            <DataGridTemplateColumn Header="操作" Width="160"  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.EditOutCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding Id}" Cursor="Hand" Margin="0,0,10,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.DeleteOutCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding Id}"   Cursor="Hand" >
+
+                                                                <StackPanel Orientation="Horizontal">
+                                                                    <TextBlock  Text="删除" VerticalAlignment="Center" Foreground="Blue"/>
+                                                                </StackPanel>
+                                                            </Button>
+
+                                                        </UniformGrid>
+                                                    </DataTemplate>
+                                                </DataGridTemplateColumn.CellTemplate>
+                                            </DataGridTemplateColumn>
+
+                                        </DataGrid.Columns>
+
+                                    </DataGrid>
+
+                                </Grid>
+                            </Grid>
+                        </ScrollViewer>
+                        <Border Grid.Row="4"  BorderBrush="#CBCBCB" BorderThickness="0,1" />
+                        <StackPanel Grid.Row="5" Orientation="Horizontal" HorizontalAlignment="Right">
+
+                       
+                        </StackPanel>
+
+                    </Grid>
+
+                </Border>
+
+
+            </Grid>
+
+
+
+
+    </Grid>
+</UserControl>
+
+

+ 64 - 0
BlankApp1/BlankApp1/Views/BasicConfigView/EditItemDetailView.xaml.cs

@@ -0,0 +1,64 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace PLCTool.Views.BasicConfigView
+{
+    /// <summary>
+    /// EditItemDetailView.xaml 的交互逻辑
+    /// </summary>
+    public partial class EditItemDetailView : UserControl
+    {
+        public EditItemDetailView()
+        {
+            InitializeComponent();
+        }
+
+        private void txtBefore_KeyDown(object sender, KeyEventArgs e)
+        {
+            var textbox = sender as TextBox;
+            if (e.Key == Key.Enter &&
+                !(Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) &&
+                !(Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.LeftShift)))
+            {
+                textbox.Text = "";
+                e.Handled = true;
+            }
+        }
+
+        private void txtIn_KeyDown(object sender, KeyEventArgs e)
+        {
+            var textbox = sender as TextBox;
+            if (e.Key == Key.Enter &&
+                !(Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) &&
+                !(Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.LeftShift)))
+            {
+                textbox.Text = "";
+                e.Handled = true;
+            }
+        }
+
+        private void txtOut_KeyDown(object sender, KeyEventArgs e)
+        {
+            var textbox = sender as TextBox;
+            if (e.Key == Key.Enter &&
+                !(Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) &&
+                !(Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.LeftShift)))
+            {
+                textbox.Text = "";
+                e.Handled = true;
+            }
+        }
+    }
+}

+ 168 - 0
BlankApp1/BlankApp1/Views/BasicConfigView/EditSchView.xaml

@@ -0,0 +1,168 @@
+<UserControl x:Class="PLCTool.Views.BasicConfigView.EditSchView"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+             xmlns:local="clr-namespace:PLCTool.Views.BasicConfigView"
+             xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
+             xmlns:prism="http://prismlibrary.com/" 
+             BorderBrush="#CBCBCB" BorderThickness="1"
+             Height="700" Width="1100" >
+
+    <UserControl.Resources>
+        <Style TargetType="TextBlock" x:Key="textBlockStyle">
+            <Setter Property="Width" Value="80"/>
+            <Setter Property="FontSize" Value="12"/>
+            <Setter Property="VerticalAlignment" Value="Center"/>
+            <Setter Property="TextAlignment" Value="Right"/>
+            <Setter Property="Margin" Value="0,0,5,0"/>
+        </Style>
+
+        <Style x:Key="CenterAlignedGroupBoxStyle" TargetType="{x:Type GroupBox}">
+            <Setter Property="Template">
+                <Setter.Value>
+                    <ControlTemplate TargetType="GroupBox">
+                        <Grid>
+                            <Grid.RowDefinitions>
+                                <RowDefinition Height="Auto"/>
+                                <RowDefinition Height="*"/>
+                            </Grid.RowDefinitions>
+                            <Border Grid.Row="0" Background="BlueViolet" CornerRadius="5" Padding="5">
+                                <TextBlock Text="{TemplateBinding Header}" HorizontalAlignment="Right"/>
+                            </Border>
+                            <ContentControl Grid.Row="1" Content="{TemplateBinding Content}"/>
+                        </Grid>
+                    </ControlTemplate>
+                </Setter.Value>
+            </Setter>
+        </Style>
+    </UserControl.Resources>
+
+    <Grid>
+        <b:Interaction.Triggers>
+            <b:EventTrigger EventName="Loaded">
+                <b:InvokeCommandAction Command="{Binding OnLoadCommand}" CommandParameter="{Binding ElementName=tt}"/>
+            </b:EventTrigger>
+        </b:Interaction.Triggers>
+       
+            <Grid >
+
+                <Grid.RowDefinitions>
+                    <RowDefinition Height="50" />
+                    <RowDefinition  />
+                   
+
+                </Grid.RowDefinitions>
+
+                <DockPanel  Grid.Row="0" Margin="10" LastChildFill="False">
+                    <StackPanel Orientation="Horizontal"  Grid.Row="4" HorizontalAlignment="Center">
+                        <TextBlock Text="设备类型:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"  Width="60"/>
+                        <ComboBox  Height="28" Width="120" ItemsSource="{Binding DeviceKindNameList}" SelectedItem="{Binding DeviceKindName}" />
+                    </StackPanel>
+                    <StackPanel Orientation="Horizontal">
+                        <TextBlock Text="测试方案名称:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
+                        <TextBox  Height="28" Width="120" Text="{Binding ScheduleName}" >
+                        </TextBox>
+                    </StackPanel>
+                    <Button  Content="取消" Width="80"  Margin="5,0"  Command="{Binding CancelCommand}" Style="{StaticResource NormalButtonStyle}" DockPanel.Dock="Right" />
+                    <Button  Content="提交" Width="80"  Margin="5,0"  Command="{Binding SaveAllSchCommand}" Style="{StaticResource NormalButtonStyle}" DockPanel.Dock="Right" />
+
+                </DockPanel>
+                <Border Grid.Row="0"  BorderBrush="#CBCBCB" BorderThickness="0,1" />
+
+
+               
+                <Grid Grid.Row="1"  Margin="5">
+                    <StackPanel Orientation="Vertical">
+                        <StackPanel Orientation="Horizontal" >
+                            <TextBlock Text="▊"  TextAlignment="Center" VerticalAlignment="Center" Foreground="#409EFF" Margin="5,0,5,0"/>
+                            <TextBlock Text="测试项列表"  Style="{StaticResource NormalTextBlockStyle}" Margin="0,0,5,0"/>
+                        </StackPanel>
+                    <StackPanel Orientation="Horizontal" >
+             
+                        <StackPanel Orientation="Horizontal">
+                            <TextBlock Text="测试项名称:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
+                            <TextBox  Height="28" Width="160"  Text="{Binding TestName}"/>
+                        </StackPanel>
+                        <StackPanel Orientation="Horizontal" >
+                            <TextBlock Text="测试项类型:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
+                            <ComboBox  Height="28" Width="160" ItemsSource="{Binding TestKinds}" SelectedItem="{Binding SelectTest}" />
+                        </StackPanel>
+                        <Button  Content="查询" Width="80"  Margin="5,0"  Command="{Binding QueryCommand}" Style="{StaticResource NormalButtonStyle}" DockPanel.Dock="Right" />
+                        <Button  Content="重置" Width="80"  Margin="5,0"  Command="{Binding ResetCommand}" Style="{StaticResource NormalButtonStyle}" DockPanel.Dock="Right" />
+                    </StackPanel>
+                    <DataGrid    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 SchProjectList}" IsReadOnly="True" Margin="5" Padding="0" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible" >
+                            <b:Interaction.Triggers>
+                                <b:EventTrigger EventName="SelectionChanged">
+                                    <b:InvokeCommandAction Command="{Binding DgSelectChangeCommand}" 
+                                                   CommandParameter="{Binding Path=SelectedItem, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}"/>
+                                </b:EventTrigger>
+                            </b:Interaction.Triggers>
+                            <DataGrid.Columns >
+                                <DataGridTextColumn Header="测试项名称" Binding="{Binding ItemName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                                <DataGridTextColumn Header="测试项类型" Binding="{Binding ItemType}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                                <DataGridTextColumn Header="前置项描述" Binding="{Binding BeforeDetail}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                                <DataGridTextColumn Header="输入项描述" Binding="{Binding InDetail}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                                <DataGridTextColumn Header="输出项描述" Binding="{Binding OutDetail}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                                <DataGridTemplateColumn Header="操作" Width="240" CellStyle="{StaticResource MyDataGridCellStyle}">
+                                    <DataGridTemplateColumn.CellTemplate>
+                                        <DataTemplate>
+                                            <StackPanel Orientation="Horizontal">
+                                                <Button  Width="auto" Background="Transparent" HorizontalContentAlignment ="Left" Foreground="Black" Height="25" BorderThickness="0"
+        Command="{Binding DataContext.DetailCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding SchDtlId}" Cursor="Hand" Margin="0,0,10,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.EditCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding SchDtlId}" Cursor="Hand" Margin="0,0,10,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.DeleteCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding SchDtlId}" Cursor="Hand" Margin="0,0,10,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.UpCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding SchDtlId}" Cursor="Hand" Margin="0,0,10,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.DownCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding SchDtlId}" Cursor="Hand" Margin="0,0,10,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.EditDetailCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding SchDtlId}" Cursor="Hand" Margin="0,0,10,0">
+                                            <StackPanel Orientation="Horizontal">
+                                                <TextBlock  Text="编辑" VerticalAlignment="Center" Foreground="Blue"/>
+                                            </StackPanel>
+                                        </Button>-->
+                                            </StackPanel>
+                                        </DataTemplate>
+                                    </DataGridTemplateColumn.CellTemplate>
+                                </DataGridTemplateColumn>
+                            </DataGrid.Columns>
+
+                        </DataGrid>
+                    </StackPanel>
+
+                </Grid>
+
+            </Grid>
+     
+
+
+
+
+    </Grid>
+</UserControl>

+ 28 - 0
BlankApp1/BlankApp1/Views/BasicConfigView/EditSchView.xaml.cs

@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace PLCTool.Views.BasicConfigView
+{
+    /// <summary>
+    /// EditSchView.xaml 的交互逻辑
+    /// </summary>
+    public partial class EditSchView : UserControl
+    {
+        public EditSchView()
+        {
+            InitializeComponent();
+        }
+    }
+}