|
@@ -0,0 +1,851 @@
|
|
|
+using AutoMapper;
|
|
|
+using BizService;
|
|
|
+using BlankApp1.Events;
|
|
|
+using DryIoc;
|
|
|
+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 AddItemDetailViewModel : 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 AddItemDetailViewModel(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);
|
|
|
+ BeforeConList = new ObservableCollection<BasPlcItemConfigDto>();
|
|
|
+ InConList = new ObservableCollection<BasPlcItemConfigDto>();
|
|
|
+ OutConList = new ObservableCollection<BasPlcItemConfigDto>();
|
|
|
+
|
|
|
+ GetConfigOption();
|
|
|
+ }
|
|
|
+ #region IDIALOG实现
|
|
|
+ public string Title { set; get; } = "新增测试项";
|
|
|
+
|
|
|
+ public event Action<IDialogResult> RequestClose;
|
|
|
+
|
|
|
+ public bool CanCloseDialog()
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void OnDialogClosed()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void OnDialogOpened(IDialogParameters parameters)
|
|
|
+ {
|
|
|
+ var getMsg = parameters.GetValues<string>("Key");
|
|
|
+ ///值不为空,表示修改,为空表示新增
|
|
|
+ if (getMsg != null)
|
|
|
+ {
|
|
|
+ foreach (var item in getMsg)
|
|
|
+ {
|
|
|
+
|
|
|
+ DeviceKindName = item;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ var getMsg2 = parameters.GetValues<string>("Key2");
|
|
|
+
|
|
|
+ if (getMsg != null)
|
|
|
+ {
|
|
|
+ foreach (var item in getMsg2)
|
|
|
+ {
|
|
|
+
|
|
|
+ ScheduleName = item;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ #region 私有方法
|
|
|
+
|
|
|
+
|
|
|
+ private void OnLoad(object obj)
|
|
|
+ {
|
|
|
+ DeviceKindName = "---";
|
|
|
+ ScheduleName = string.Empty;
|
|
|
+
|
|
|
+ //清空测试项的内容
|
|
|
+ CleanContent();
|
|
|
+ }
|
|
|
+ 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 kinds = _iBasicDeviceKindService.FindAllDeviceKind();
|
|
|
+ DeviceKindNameList.Add("---");
|
|
|
+ foreach (var kind in kinds)
|
|
|
+ {
|
|
|
+ DeviceKindNameList.Add(kind);
|
|
|
+ }
|
|
|
+
|
|
|
+ //
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ //测试项类型
|
|
|
+ BeforeJudgeKinds.Add("---");
|
|
|
+ InJudgeKinds.Add("---");
|
|
|
+ OutJudgeKinds.Add("---");
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ //判定逻辑
|
|
|
+ JudgeLogicKinds.Add("---");
|
|
|
+ InJudgeLogicKinds.Add("---");
|
|
|
+ OutJudgeLogicKinds.Add("---");
|
|
|
+ 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
|
|
|
+ {
|
|
|
+
|
|
|
+ var finsSche = _basicPlcTestSchemeService.FindByName(ScheduleName);
|
|
|
+ //测试方案中已有这个名称
|
|
|
+ if (finsSche != null)
|
|
|
+ {
|
|
|
+ long schID = finsSche.scheme_id;
|
|
|
+ //在测试方案明细表中查找是否有这个测试方案和测试项
|
|
|
+ var schDtl = _basicPlcTestSchemeDtlService.FindSchDtlIdBySchIdAndItem(schID, TestName);
|
|
|
+ //在不为空,说明有这个测试方案和测试项了
|
|
|
+ if (schDtl != null)
|
|
|
+ {
|
|
|
+ MessageBoxResult boxResult = MessageBox.Show("此测试方案名称已存在此测试项,请填写其他测试项!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //增加测试方案到数据库
|
|
|
+ BasicPlcTestSchemeDto schDto = new BasicPlcTestSchemeDto();
|
|
|
+ schDto.SchemeName = ScheduleName;
|
|
|
+ schDto.DeviceKindName = DeviceKindName;
|
|
|
+ schDto.CreateBy = Appsession.UserName;
|
|
|
+ schDto.CreateTime = DateTime.Now;
|
|
|
+ schDto.UpdateTime = DateTime.Now;
|
|
|
+ schDto.UpdateBy = Appsession.UserName;
|
|
|
+ bas_plc_test_scheme schEntity = _mapper.Map<BasicPlcTestSchemeDto, bas_plc_test_scheme>(schDto);
|
|
|
+ _basicPlcTestSchemeService.Add(schEntity);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //查找测试方案id
|
|
|
+ var finsScheHave = _basicPlcTestSchemeService.FindByName(ScheduleName);
|
|
|
+ if (finsScheHave != null)
|
|
|
+ {
|
|
|
+ long id = finsScheHave.scheme_id;
|
|
|
+ //增加或修改方案明细表
|
|
|
+ AddOrEditDetailsToDb(id);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ _logger.LogError(ex.ToString());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 清空测试项内容内容
|
|
|
+ /// </summary>
|
|
|
+ private void CleanContent()
|
|
|
+ {
|
|
|
+ //清空已填写的内容
|
|
|
+ TestName = string.Empty;
|
|
|
+ SelectTest = "---";
|
|
|
+ BeforeSelectJudge = "---";
|
|
|
+ SelectLogic = "---";
|
|
|
+ BeforeDetail = string.Empty;
|
|
|
+ //输入项
|
|
|
+ SelectInJudge = "---";
|
|
|
+ InSelectLogic = "---";
|
|
|
+ InDetail = string.Empty;
|
|
|
+ //输出项
|
|
|
+ SelectOutJudge = "---";
|
|
|
+ OutSelectLogic = "---";
|
|
|
+ OutDetail = string.Empty;
|
|
|
+
|
|
|
+ BeforeConList = new ObservableCollection<BasPlcItemConfigDto>();
|
|
|
+ InConList = new ObservableCollection<BasPlcItemConfigDto>();
|
|
|
+ OutConList = new ObservableCollection<BasPlcItemConfigDto>();
|
|
|
+
|
|
|
+ }
|
|
|
+ /// <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
|
|
|
+ {
|
|
|
+
|
|
|
+ bool isAddSucc = _basicPlcTestSchemeDtlService.Add(schDtlEntity);
|
|
|
+ if (isAddSucc)
|
|
|
+ {
|
|
|
+ _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 void OnNavigatedTo(NavigationContext navigationContext)
|
|
|
+ {
|
|
|
+ ScheduleName = string.Empty;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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<string> OpenExistCommand { 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<object> EditDetailCommand { 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 ObservableCollection<string> beforeJudgeKinds = new ObservableCollection<string>();
|
|
|
+ public ObservableCollection<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 ObservableCollection<string> judgeLogicKinds = new ObservableCollection<string>();
|
|
|
+ public ObservableCollection<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 ObservableCollection<string> inJudgeKinds = new ObservableCollection<string>();
|
|
|
+ public ObservableCollection<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 ObservableCollection<string> inJudgeLogicKinds = new ObservableCollection<string>();
|
|
|
+ public ObservableCollection<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 ObservableCollection<string> outJudgeKinds = new ObservableCollection<string>();
|
|
|
+ public ObservableCollection<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 ObservableCollection<string> outJudgeLogicKinds = new ObservableCollection<string>();
|
|
|
+ public ObservableCollection<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 ObservableCollection<string> deviceKindNameList = new ObservableCollection<string>();
|
|
|
+ public ObservableCollection<string> DeviceKindNameList
|
|
|
+ {
|
|
|
+ get { return deviceKindNameList; }
|
|
|
+ set { deviceKindNameList = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ }
|
|
|
+}
|