|
@@ -1,5 +1,7 @@
|
|
|
using AutoMapper;
|
|
|
using BizService;
|
|
|
+using BlankApp1.Events;
|
|
|
+using DryIoc;
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
using Model.Dto;
|
|
|
using Model.Entities;
|
|
@@ -9,6 +11,7 @@ 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;
|
|
@@ -21,10 +24,11 @@ using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
|
|
|
|
|
|
namespace PLCTool.ViewModels.BasicConfigViewModel
|
|
|
{
|
|
|
- public class AddOrEditSchViewModel : BindableBase, IDialogAware
|
|
|
+ public class AddOrEditSchViewModel : 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;
|
|
@@ -34,10 +38,12 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
|
|
|
private List<OptionConfigDto> _optionConfigs;
|
|
|
private bas_plc_test_scheme bas_Plc_Test_Scheme;//测试方案
|
|
|
private int schDtlMainId = 0;//测试方案明细主键id
|
|
|
- public AddOrEditSchViewModel(IDialogService dialog, IEventAggregator aggregator, IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService, IBasicDeviceKindService iBasicDeviceKindService, IMapper mapper,ILogger logger)
|
|
|
+ public event Action<NavigationResult> RequestClose;
|
|
|
+ public AddOrEditSchViewModel(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;
|
|
@@ -61,86 +67,64 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
|
|
|
DownCommand = new DelegateCommand<object>(DataDown);
|
|
|
SaveAllSchCommand = new DelegateCommand<object>(SaveAllSch);
|
|
|
// EditDetailCommand = new DelegateCommand<object>(DataGridSelectChange);
|
|
|
-
|
|
|
DgSelectChangeCommand = new DelegateCommand<object>(DataGridSelectChange);
|
|
|
- DisAnoCommand = new DelegateCommand<object>(DisAnomation);
|
|
|
-
|
|
|
- BeforeConList = new ObservableCollection<BasPlcItemConfigDto>();
|
|
|
+ CancelCommand= new DelegateCommand<object>(Cancel);
|
|
|
+ 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;
|
|
|
|
|
|
- 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)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
+ #endregion
|
|
|
|
|
|
- Title = "编辑方案";
|
|
|
- ScheduleName= item.ToString();
|
|
|
- //获取已经有的测试项
|
|
|
- GetExistSchs();
|
|
|
- //展示第一个测试项详情
|
|
|
- var findSch=_basicPlcTestSchemeService.FindByNameAndType(ScheduleName, DeviceKindName);
|
|
|
- if(findSch != null)
|
|
|
- {
|
|
|
- long schID = findSch.scheme_id;
|
|
|
- int schDtlId=(int)_basicPlcTestSchemeDtlService.FindAllBySchId(schID)?.OrderBy(x => x.scheme_dtl_id)?.First()?.scheme_dtl_id;
|
|
|
-
|
|
|
- schDtlMainId = schDtlId;//全局变量赋值,测试方案明细id
|
|
|
- GetDetaiMsg(schDtlId);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- _logger.LogError(ex.ToString());
|
|
|
- }
|
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
- }
|
|
|
|
|
|
- var getMsg2 = parameters.GetValues<string>("Key2");
|
|
|
- if(getMsg2 != null )
|
|
|
- {
|
|
|
- foreach (var item in getMsg2)
|
|
|
- {
|
|
|
- DeviceKindName = item;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
+ #region 私有方法
|
|
|
+ /// <summary>
|
|
|
+ /// 取消返回列表界面
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="obj"></param>
|
|
|
+ private void Cancel(object obj)
|
|
|
+ {
|
|
|
+ _regionManager.Regions["ContentRegion"].RequestNavigate("BaseConfigView");
|
|
|
+ }
|
|
|
/// <summary>
|
|
|
/// 测试方案明细主键ID 查找测试方案id 及方案名
|
|
|
/// </summary>
|
|
@@ -232,9 +216,6 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
|
|
|
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- #endregion
|
|
|
- #region 私有方法
|
|
|
/// <summary>
|
|
|
/// 选中datadagridView某一行
|
|
|
/// </summary>
|
|
@@ -242,19 +223,16 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
|
|
|
private void DataGridSelectChange(object obj)
|
|
|
{
|
|
|
SelectItemModel selectItemModel = (SelectItemModel)obj;
|
|
|
- int schDtlId = Convert.ToInt32(selectItemModel.SchDtlId);
|
|
|
- schDtlMainId = schDtlId;//全局变量赋值,测试方案明细id
|
|
|
- GetDetaiMsg(schDtlId);
|
|
|
- }
|
|
|
- /// <summary>
|
|
|
- /// 显示侧边栏
|
|
|
- /// </summary>
|
|
|
- /// <param name="obj"></param>
|
|
|
- /// <exception cref="NotImplementedException"></exception>
|
|
|
- private void DisAnomation(object obj)
|
|
|
- {
|
|
|
+ if(selectItemModel!=null)
|
|
|
+ {
|
|
|
+ int schDtlId = Convert.ToInt32(selectItemModel.SchDtlId);
|
|
|
+ schDtlMainId = schDtlId;//全局变量赋值,测试方案明细id
|
|
|
+ GetDetaiMsg(schDtlId);
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
+
|
|
|
|
|
|
/// <summary>
|
|
|
/// 保存所有测试项
|
|
@@ -263,6 +241,8 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
|
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
|
private void SaveAllSch(object obj)
|
|
|
{
|
|
|
+ //先保存一下当前测试项
|
|
|
+ Sure(string.Empty);
|
|
|
//可能调整了测试项的顺序,所以先删除所有测试项
|
|
|
var findSche = _basicPlcTestSchemeService.FindByName(ScheduleName);
|
|
|
if (findSche != null)
|
|
@@ -296,7 +276,9 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
|
|
|
|
|
|
}
|
|
|
MessageBox.Show("保存成功!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
- RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
|
|
|
+ //发布消息
|
|
|
+ _aggregator.GetEvent<ChangeEvent>().Publish("Change");
|
|
|
+ _regionManager.Regions["ContentRegion"].RequestNavigate("BaseConfigView");
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
@@ -371,7 +353,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
|
|
|
SchDtlId = unit.scheme_dtl_id,
|
|
|
ItemName = unit.item_name,
|
|
|
ItemType = itemType,
|
|
|
- }); ;
|
|
|
+ });
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -609,7 +591,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
|
|
|
/// </summary>
|
|
|
private void Close()
|
|
|
{
|
|
|
- RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
|
|
|
+ //RequestClose?.Invoke(new NavigationResult(new NavigationContext(),true);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 确认
|
|
@@ -738,10 +720,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
|
|
|
//更新已有的测试项
|
|
|
GetExistSchs();
|
|
|
//清空已填写的内容
|
|
|
-
|
|
|
-
|
|
|
- TestName = string.Empty;
|
|
|
-
|
|
|
+
|
|
|
BeforeConList =new ObservableCollection<BasPlcItemConfigDto>();
|
|
|
InConList = new ObservableCollection<BasPlcItemConfigDto>();
|
|
|
OutConList = new ObservableCollection<BasPlcItemConfigDto>();
|
|
@@ -818,11 +797,11 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
|
|
|
if (isSucc)
|
|
|
{
|
|
|
_logger.LogInformation($"更新方案成功。方案名{ScheduleName},测试项{TestName}");
|
|
|
- MessageBoxResult boxResult = MessageBox.Show("更新成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ MessageBoxResult boxResult = MessageBox.Show("保存成功", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- MessageBoxResult boxResult = MessageBox.Show("更新失败", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
+ MessageBoxResult boxResult = MessageBox.Show("保存失败", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -902,6 +881,65 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
|
|
|
DeviceKindName = string.Empty;
|
|
|
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();
|
|
|
+ //展示第一个测试项详情
|
|
|
+ var findSch = _basicPlcTestSchemeService.FindByNameAndType(ScheduleName, DeviceKindName);
|
|
|
+ if (findSch != null)
|
|
|
+ {
|
|
|
+ long schID = findSch.scheme_id;
|
|
|
+ int schDtlId = (int)_basicPlcTestSchemeDtlService.FindAllBySchId(schID)?.OrderBy(x => x.scheme_dtl_id)?.First()?.scheme_dtl_id;
|
|
|
+
|
|
|
+ schDtlMainId = schDtlId;//全局变量赋值,测试方案明细id
|
|
|
+ GetDetaiMsg(schDtlId);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ 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
|
|
|
|
|
|
|
|
@@ -946,7 +984,11 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
|
|
|
public DelegateCommand<object> EditDetailCommand { set; get; }
|
|
|
public DelegateCommand<object> DgSelectChangeCommand { 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>
|