1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048 |
- 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
- }
- }
|