增加CAN FD和规则的功能

This commit is contained in:
2025-07-11 23:26:21 +08:00
parent 010497604d
commit a373265201
33 changed files with 5744 additions and 516 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,252 @@
using AutoMapper;
using CapMachine.Core;
using CapMachine.Model;
using CapMachine.Wpf.Dtos;
using CapMachine.Wpf.Services;
using Masuit.Tools;
using Prism.Commands;
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 CapMachine.Wpf.ViewModels
{
/// <summary>
/// 逻辑规则配置的弹窗
/// </summary>
public class DialogLogicRuleViewModel : DialogViewModel
{
public DialogLogicRuleViewModel(IFreeSql freeSql, IMapper mapper, LogicRuleService logicRuleService)
{
Title = "逻辑规则创建";
FreeSql = freeSql;
Mapper = mapper;
LogicRuleService = logicRuleService;
//var Data = Mapper.Map<List<LogicRuleDto>>(LogicRuleService.LogicRuleDtos);
ListLogicRuleDto = LogicRuleService.LogicRuleDtos;
}
public IFreeSql FreeSql { get; }
public IMapper Mapper { get; }
public LogicRuleService LogicRuleService { get; }
private ObservableCollection<LogicRuleDto> _ListLogicRuleDto;
/// <summary>
/// 数据集合
/// </summary>
public ObservableCollection<LogicRuleDto> ListLogicRuleDto
{
get { return _ListLogicRuleDto; }
set { _ListLogicRuleDto = value; RaisePropertyChanged(); }
}
private LogicRuleDto _selectedRule = new LogicRuleDto();
/// <summary>
/// 当前选中的规则
/// </summary>
public LogicRuleDto SelectedRule
{
get { return _selectedRule; }
set { _selectedRule = value; RaisePropertyChanged(); }
}
/// <summary>
/// 选中更改之前的LogicRuleDto
/// </summary>
public LogicRuleDto SelectedRuleOld { get; set; }
private DelegateCommand<object> _GridSelectionChangedCmd;
/// <summary>
/// 选中行数据命令
/// </summary>
public DelegateCommand<object> GridSelectionChangedCmd
{
set
{
_GridSelectionChangedCmd = value;
}
get
{
if (_GridSelectionChangedCmd == null)
{
_GridSelectionChangedCmd = new DelegateCommand<object>((par) => GridSelectionChangedCmdMethod(par));
}
return _GridSelectionChangedCmd;
}
}
private void GridSelectionChangedCmdMethod(object par)
{
var selectedItem = par as LogicRuleDto;
if (selectedItem != null)
{
//防止需要未更改之前的数据
SelectedRuleOld = selectedItem;
//先判断是否是正确的集合数据防止DataGrid的数据源刷新导致的触发事件
SelectedRule = selectedItem.DeepClone();
}
////选中的行数据
}
/// <summary>
/// 是否编辑
/// </summary>
private bool IsRuleEdit { get; set; } = false;
private DelegateCommand<string> _RuleCmd;
/// <summary>
/// 选中行数据命令
/// </summary>
public DelegateCommand<string> RuleCmd
{
set
{
_RuleCmd = value;
}
get
{
if (_RuleCmd == null)
{
_RuleCmd = new DelegateCommand<string>((par) => RuleCmdMethod(par));
}
return _RuleCmd;
}
}
private void RuleCmdMethod(string par)
{
IsRuleEdit = true;
//先判断是否是正确的集合数据防止DataGrid的数据源刷新导致的触发事件
switch (par)
{
case "Create":
//SelectedRule
LogicRuleService.AddRule(Mapper.Map<LogicRule>(SelectedRule));
break;
case "Update":
if (SelectedRule == null)
{
MessageBox.Show("选中后再操作数据");
return;
}
LogicRuleService.UpdateRule(Mapper.Map<LogicRule>(SelectedRuleOld), Mapper.Map<LogicRule>(SelectedRule));
break;
case "Delete":
if (SelectedRule == null)
{
MessageBox.Show("选中后再操作数据");
return;
}
LogicRuleService.DeleteRule(SelectedRule.Name);
break;
default:
break;
}
////选中的行数据
}
#region
private string name;
/// <summary>
/// 名称
/// </summary>
public string Name
{
get { return name; }
set { name = value; RaisePropertyChanged(); }
}
private DelegateCommand saveCmd;
/// <summary>
/// 保存命令
/// </summary>
public DelegateCommand SaveCmd
{
set
{
saveCmd = value;
}
get
{
if (saveCmd == null)
{
saveCmd = new DelegateCommand(() => SaveCmdMethod());
}
return saveCmd;
}
}
/// <summary>
/// 保存命令方法
/// </summary>
/// <exception cref="NotImplementedException"></exception>
private void SaveCmdMethod()
{
DialogParameters pars = new DialogParameters
{
{ "IsRuleEdit", IsRuleEdit }
};
RaiseRequestClose(new DialogResult(ButtonResult.OK, pars));
}
private DelegateCommand cancelCmd;
/// <summary>
/// 保存命令
/// </summary>
public DelegateCommand CancelCmd
{
set
{
cancelCmd = value;
}
get
{
if (cancelCmd == null)
{
cancelCmd = new DelegateCommand(() => CancelCmdMethod());
}
return cancelCmd;
}
}
/// <summary>
/// 取消命令方法
/// </summary>
/// <exception cref="NotImplementedException"></exception>
private void CancelCmdMethod()
{
RaiseRequestClose(new DialogResult(ButtonResult.Cancel));
}
/// <summary>
/// 窗口打开时的传递的参数
/// </summary>
/// <param name="parameters"></param>
public override void OnDialogOpened(IDialogParameters parameters)
{
Name = parameters.GetValue<string>("Name");
IsRuleEdit = false;
}
#endregion
}
}

View File

@@ -27,7 +27,7 @@ namespace CapMachine.Wpf.ViewModels
/// <param name="machineRtDataService"></param>
/// <param name="dialogService"></param>
public MonitorViewModel(ConfigService configService, IEventAggregator eventAggregator,
DataRecordService dataRecordService, SysRunService sysRunService, AlarmService alarmService, PPCService pPCService,CanDriveService canDriveService,LinDriveService linDriveService,
DataRecordService dataRecordService, CanFdDriveService canFdDriveService, SysRunService sysRunService, AlarmService alarmService, PPCService pPCService,CanDriveService canDriveService,LinDriveService linDriveService,
MachineRtDataService machineRtDataService, IDialogService dialogService)
{
ConfigService = configService;
@@ -38,6 +38,7 @@ namespace CapMachine.Wpf.ViewModels
AlarmService = alarmService;
PPCService = pPCService;
CanDriveService = canDriveService;
CanFdDriveService = canFdDriveService;
LinDriveService = linDriveService;
MachineRtDataService = machineRtDataService;
DialogService = dialogService;
@@ -75,6 +76,7 @@ namespace CapMachine.Wpf.ViewModels
public AlarmService AlarmService { get; }
public PPCService PPCService { get; }
public CanDriveService CanDriveService { get; }
public CanFdDriveService CanFdDriveService { get; }
public LinDriveService LinDriveService { get; }
public MachineRtDataService MachineRtDataService { get; }
public IDialogService DialogService { get; }
@@ -244,6 +246,11 @@ namespace CapMachine.Wpf.ViewModels
CanDriveService.UpdateSpeedCmdData(0);
//itemTag.Value.EngPvValue = 0;
break;
case CanLinEnum.CANFD:
//获取PLC的SV数据 更新SV的速度值到压缩机
CanFdDriveService.UpdateSpeedCmdData(0);
//itemTag.Value.EngPvValue = 0;
break;
case CanLinEnum.Lin:
//获取PLC的SV数据 更新SV的速度值到压缩机
LinDriveService.UpdateSpeedCmdData(0);
@@ -269,6 +276,11 @@ namespace CapMachine.Wpf.ViewModels
CanDriveService.UpdateSpeedCmdData(0);
//itemTag.Value.EngPvValue = 0;
break;
case CanLinEnum.CANFD:
//获取PLC的SV数据 更新SV的速度值到压缩机
CanFdDriveService.UpdateSpeedCmdData(0);
//itemTag.Value.EngPvValue = 0;
break;
case CanLinEnum.Lin:
//获取PLC的SV数据 更新SV的速度值到压缩机
LinDriveService.UpdateSpeedCmdData(0);