|
@@ -0,0 +1,183 @@
|
|
|
+using AutoMapper;
|
|
|
+using BizService;
|
|
|
+using Microsoft.Extensions.Logging;
|
|
|
+using Model.Dto;
|
|
|
+using Model.Entities;
|
|
|
+using PLCTool.Common;
|
|
|
+using PLCTool.Models;
|
|
|
+using Prism.Commands;
|
|
|
+using Prism.Events;
|
|
|
+using Prism.Mvvm;
|
|
|
+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;
|
|
|
+using System.Windows.Automation;
|
|
|
+using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
|
|
|
+
|
|
|
+namespace PLCTool.ViewModels.BasicConfigViewModel
|
|
|
+{
|
|
|
+ internal class CopySchViewModel : BindableBase, IDialogAware
|
|
|
+ {
|
|
|
+ private readonly IMapper _mapper;
|
|
|
+ private readonly ILogger _logger;
|
|
|
+ private readonly IBasicPlcTestSchemeService _basicPlcTestSchemeService;
|
|
|
+ private readonly IBasicPlcTestSchemeDtlService _basicPlcTestSchemeDtlService;
|
|
|
+ private string schNameAgo = String.Empty;
|
|
|
+ public CopySchViewModel(IDialogService dialog, IEventAggregator aggregator, IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService, IMapper mapper, ILogger logger)
|
|
|
+ {
|
|
|
+
|
|
|
+ _basicPlcTestSchemeService = basicPlcTestSchemeService;
|
|
|
+ _basicPlcTestSchemeDtlService = basicPlcTestSchemeDtlService;
|
|
|
+ _mapper = mapper;
|
|
|
+ _logger = logger;
|
|
|
+ SureCommand = new DelegateCommand<string>(Sure);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Sure(string obj)
|
|
|
+ {
|
|
|
+ //查找是否有这个测试方案
|
|
|
+ var findExist = _basicPlcTestSchemeService.FindByName(ScheduleName);
|
|
|
+ if (findExist != null)
|
|
|
+ {
|
|
|
+ MessageBoxResult boxResult = MessageBox.Show("已有次测试方案,请填写其他方案名!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //查找以前测试方案的信息
|
|
|
+ var finsSche = _basicPlcTestSchemeService.FindByName(schNameAgo);
|
|
|
+ if (finsSche != null)
|
|
|
+ {
|
|
|
+ //增加测试方案到数据库
|
|
|
+ bas_plc_test_scheme schDto = new bas_plc_test_scheme();
|
|
|
+ schDto.scheme_name = ScheduleName;
|
|
|
+ schDto.device_name = DeviceName;
|
|
|
+ schDto.create_by = Appsession.UserName;
|
|
|
+ schDto.create_time = DateTime.Now;
|
|
|
+ schDto.update_time = DateTime.Now;
|
|
|
+ schDto.update_by = Appsession.UserName;
|
|
|
+ _basicPlcTestSchemeService.Add(schDto);
|
|
|
+ //以前复制的schID
|
|
|
+ long schID = finsSche.scheme_id;
|
|
|
+ //查找此方案下的所有的测试项,并增加到测试项详细表中
|
|
|
+ long? schINewID = _basicPlcTestSchemeService.FindByName(ScheduleName)?.scheme_id;
|
|
|
+ var schDtls = _basicPlcTestSchemeDtlService.QueryList()?.FindAll(x => x.scheme_id == schID);
|
|
|
+ foreach (var unit in schDtls)
|
|
|
+ {
|
|
|
+ bas_plc_test_scheme_dtl schDtlDto = new bas_plc_test_scheme_dtl();
|
|
|
+ schDtlDto.scheme_id = schINewID;
|
|
|
+ schDtlDto.item_name = unit.item_name;
|
|
|
+
|
|
|
+ schDtlDto.item_type = unit.item_type;
|
|
|
+ schDtlDto.precondition = unit.precondition;
|
|
|
+ schDtlDto.precondition_describe = unit.precondition_describe;
|
|
|
+ schDtlDto.action = unit.action;
|
|
|
+ schDtlDto.action_describe = unit.action_describe;
|
|
|
+ schDtlDto.judgement_result = unit.judgement_result;
|
|
|
+ schDtlDto.judgement_result_describe = unit.judgement_result_describe;
|
|
|
+ schDtlDto.create_by = Appsession.UserName;
|
|
|
+ schDtlDto.create_time = DateTime.Now;
|
|
|
+ schDtlDto.update_time = DateTime.Now;
|
|
|
+ schDtlDto.update_by = Appsession.UserName;
|
|
|
+ bool isAddSucc = _basicPlcTestSchemeDtlService.Add(schDtlDto);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
|
|
|
+ }
|
|
|
+
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ schNameAgo = item.ToString();
|
|
|
+ ScheduleName = schNameAgo + "_copy";
|
|
|
+
|
|
|
+ var findSche = _basicPlcTestSchemeService.FindByName(schNameAgo);
|
|
|
+ if (findSche != null)
|
|
|
+ {
|
|
|
+ //显示设备名称
|
|
|
+ DeviceName= findSche.device_name;
|
|
|
+ long schID = findSche.scheme_id;
|
|
|
+ //查找此方案下的所有的测试项,并增加到表格
|
|
|
+ var schDtls = _basicPlcTestSchemeDtlService.QueryList()?.FindAll(x => x.scheme_id == schID);
|
|
|
+ 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
|
|
|
+ {
|
|
|
+ ItemName = unit.item_name,
|
|
|
+
|
|
|
+ ItemType= itemType,
|
|
|
+ }) ;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #region 命令绑定
|
|
|
+ public DelegateCommand<string> SureCommand { set; get; }
|
|
|
+ #endregion
|
|
|
+ #region 数据绑定
|
|
|
+ /// <summary>
|
|
|
+ /// 测试方案编码
|
|
|
+ /// </summary>
|
|
|
+ private string scheduleName;
|
|
|
+ public string ScheduleName
|
|
|
+ {
|
|
|
+ get { return scheduleName; }
|
|
|
+ set { scheduleName = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 设备名称
|
|
|
+ /// </summary>
|
|
|
+ private string deviceName;
|
|
|
+ public string DeviceName
|
|
|
+ {
|
|
|
+ get { return deviceName; }
|
|
|
+ set { deviceName = value; RaisePropertyChanged(); }
|
|
|
+ }
|
|
|
+ private ObservableCollection<SelectItemModel> schProjectList = new ObservableCollection<SelectItemModel>();
|
|
|
+ public ObservableCollection<SelectItemModel> SchProjectList
|
|
|
+ {
|
|
|
+ get { return schProjectList; }
|
|
|
+ set { SetProperty(ref schProjectList, value); }
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ }
|
|
|
+}
|