Files
CapMachine/CapMachine.Wpf/ViewModels/CANConfigViewModel.cs
2024-12-18 15:50:21 +08:00

986 lines
34 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using AutoMapper;
using CapMachine.Core;
using CapMachine.Model;
using CapMachine.Model.CANLIN;
using CapMachine.Wpf.CanDrive;
using CapMachine.Wpf.Dtos;
using CapMachine.Wpf.PrismEvent;
using CapMachine.Wpf.Services;
using Ganss.Excel;
using Microsoft.Win32;
using NPOI.SS.UserModel.Charts;
using Prism.Commands;
using Prism.Events;
using Prism.Regions;
using Prism.Services.Dialogs;
using Syncfusion.Windows.Tools.Controls;
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.Controls;
using System.Windows.Input;
namespace CapMachine.Wpf.ViewModels
{
/// <summary>
/// CAN配置ViewModel
/// </summary>
public class CANConfigViewModel : NavigationViewModel
{
public CANConfigViewModel(IDialogService dialogService, IFreeSql freeSql,
IEventAggregator eventAggregator, IRegionManager regionManager, SysRunService sysRunService,
ConfigService configService, CanDriveService canDriveService,
IMapper mapper, MachineRtDataService machineRtDataService)
{
//LogService = logService;
FreeSql = freeSql;
EventAggregator = eventAggregator;
RegionManager = regionManager;
SysRunService = sysRunService;
ConfigService = configService;
CanDriveService = canDriveService;
Mapper = mapper;
this.MachineRtDataService = machineRtDataService;
//MachineDataService = machineDataService;
DialogService = dialogService;
InitLoadCanConfigPro();
}
/// <summary>
/// FreeSQL 实例函数
/// </summary>
public IFreeSql FreeSql { get; }
public IEventAggregator EventAggregator { get; }
public IRegionManager RegionManager { get; }
public SysRunService SysRunService { get; }
public ConfigService ConfigService { get; }
public CanDriveService CanDriveService { get; }
public IMapper Mapper { get; }
private MachineRtDataService MachineRtDataService { get; }
/// <summary>
/// 弹窗服务
/// </summary>
public IDialogService DialogService { get; }
#region CanConfigPro
/// <summary>
/// 初始化j加载执行方法
/// </summary>
private void InitLoadCanConfigPro()
{
//CAN配置集合数据
canLinConfigPros = FreeSql.Select<CanLinConfigPro>().Where(a => a.CANLINInfo == CANLIN.CAN)
.Include(a => a.CANConfigExd)
.IncludeMany(a => a.CanLinConfigContents)
.ToList();
ListCanLinConfigPro = new ObservableCollection<CanLinConfigPro>(canLinConfigPros);
if (SelectCanLinConfigPro != null)
{
SelectCanLinConfigPro = canLinConfigPros.Where(a => a.Id == SelectCanLinConfigPro.Id).FirstOrDefault()!;
SelectedCANConfigExdDto = Mapper.Map<CANConfigExdDto>(SelectCanLinConfigPro!.CANConfigExd);
var WirteData = SelectCanLinConfigPro.CanLinConfigContents!.Where(a => a.RWInfo == RW.Write).ToList();
if (WirteData != null && WirteData.Count > 0)
{
ListWriteCanLinRWConfigDto = new ObservableCollection<CanLinRWConfigDto>(Mapper.Map<List<CanLinRWConfigDto>>(WirteData));
}
var ReadData = SelectCanLinConfigPro.CanLinConfigContents!.Where(a => a.RWInfo == RW.Read).ToList();
if (ReadData != null && ReadData.Count > 0)
{
ListReadCanLinRWConfigDto = new ObservableCollection<CanLinRWConfigDto>(Mapper.Map<List<CanLinRWConfigDto>>(ReadData));
}
}
}
private bool _IsCanConfigProActive = true;
/// <summary>
/// CAN 配置是否被激活
/// </summary>
public bool IsCanConfigProActive
{
get { return _IsCanConfigProActive; }
set { _IsCanConfigProActive = value; RaisePropertyChanged(); }
}
//CanLinConfigPromdCmd
private DelegateCommand<string> _CanLinConfigPromdCmd;
/// <summary>
/// CanConfigPro操作的指令
/// </summary>
public DelegateCommand<string> CanLinConfigPromdCmd
{
set
{
_CanLinConfigPromdCmd = value;
}
get
{
if (_CanLinConfigPromdCmd == null)
{
_CanLinConfigPromdCmd = new DelegateCommand<string>((Par) => CanLinConfigPromdCmdMethod(Par));
}
return _CanLinConfigPromdCmd;
}
}
/// <summary>
/// CanConfigPro操作的指令方法
/// </summary>
/// <exception cref="NotImplementedException"></exception>
private void CanLinConfigPromdCmdMethod(string Par)
{
switch (Par)
{
case "Add":
//弹窗
DialogService.ShowDialog("DialogCanLinConfigCreateView", new DialogParameters() { { "Name", "" } }, (par) =>
{
if (par.Result == ButtonResult.OK)
{
//程序名称
var ReturnValue = par.Parameters.GetValue<string>("Name");
//加载默认的数据 CANConfigExd
var InsertCANConfigExd = FreeSql.Insert<CANConfigExd>(new CANConfigExd()
{
BaudRate = 250,
DbcPath = "请配置DBC路径",
Cycle = 100,
}).ExecuteInserted();
//返回数据刷新Chart
var InsertData = FreeSql.Insert<CanLinConfigPro>(new CanLinConfigPro()
{
ConfigName = ReturnValue,
CANLINInfo = CANLIN.CAN,
CANConfigExdId = InsertCANConfigExd.FirstOrDefault()!.Id
}).ExecuteInserted();
if (InsertData != null)
{
//加载默认的数据 CanLinRWConfig
FreeSql.Insert<CanLinRWConfig>(new CanLinRWConfig()
{
Content = "Speed",
DefautValue = "0",
Name = "转速",
RWInfo = RW.Write,
CanLinConfigProId = InsertData.FirstOrDefault().Id
}).ExecuteInserted();
FreeSql.Insert<CanLinRWConfig>(new CanLinRWConfig()
{
Content = "Vol",
DefautValue = "0",
Name = "电压",
RWInfo = RW.Read,
CanLinConfigProId = InsertData.FirstOrDefault().Id
}).ExecuteInserted();
}
InitLoadCanConfigPro();
SelectCanLinConfigPro = canLinConfigPros!.Find(a => a.Id == InsertData.FirstOrDefault()!.Id);
}
else if (par.Result == ButtonResult.Cancel)
{
//取消
}
});
break;
case "Edit":
if (SelectCanLinConfigPro != null)
{
//弹窗
DialogService.ShowDialog("DialogCanLinConfigCreateView", new DialogParameters() { { "Name", SelectCanLinConfigPro.ConfigName } }, (par) =>
{
if (par.Result == ButtonResult.OK)
{
//程序名称
var ReturnValue = par.Parameters.GetValue<string>("Name");
FreeSql.Update<CanLinConfigPro>()
.Set(a => a.ConfigName, ReturnValue)
.Where(a => a.Id == SelectCanLinConfigPro.Id)
.ExecuteAffrows();
InitLoadCanConfigPro();
SelectCanLinConfigPro = null;
}
else if (par.Result == ButtonResult.Cancel)
{
//取消
}
});
}
else
{
MessageBox.Show("选中后再操作", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
}
break;
case "Save":
case "Delete":
if (SelectCanLinConfigPro != null)
{
var repo = FreeSql.GetRepository<CanLinConfigPro>();
repo.DbContextOptions.EnableCascadeSave = true; //关键设置
var DeleteData = repo.Select
.Include(a => a.CANConfigExd)
.IncludeMany(a => a.CanLinConfigContents)
.Where(a => a.Id == SelectCanLinConfigPro.Id)
.ToList();
repo.Delete(DeleteData);
foreach (var item in DeleteData)
{
FreeSql.Delete<CANConfigExd>(item.CANConfigExdId).ExecuteAffrows();
}
InitLoadCanConfigPro();
}
else
{
MessageBox.Show("选中后再操作", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
}
break;
case "Active":
if (SelectCanLinConfigPro != null)
{
IsCanConfigProActive = !IsCanConfigProActive;
}
else
{
MessageBox.Show("选中后再操作", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
}
break;
default:
break;
}
}
/// <summary>
/// CAN List集合信息
/// </summary>
private List<CanLinConfigPro> canLinConfigPros = new List<CanLinConfigPro>();
private ObservableCollection<CanLinConfigPro> _ListCanLinConfigPro;
/// <summary>
/// CAN 配置程序集合 ObservableCollection
/// </summary>
public ObservableCollection<CanLinConfigPro> ListCanLinConfigPro
{
get { return _ListCanLinConfigPro; }
set { _ListCanLinConfigPro = value; RaisePropertyChanged(); }
}
/// <summary>
/// 选中的CanLinConfigPro
/// </summary>
public CanLinConfigPro SelectCanLinConfigPro { get; set; }
private DelegateCommand<object> _CanConfigProGridSelectionChangedCmd;
/// <summary>
/// CAN 配置程序 选中行数据命令
/// </summary>
public DelegateCommand<object> CanConfigProGridSelectionChangedCmd
{
set
{
_CanConfigProGridSelectionChangedCmd = value;
}
get
{
if (_CanConfigProGridSelectionChangedCmd == null)
{
_CanConfigProGridSelectionChangedCmd = new DelegateCommand<object>((par) => CanConfigProGridSelectionChangedCmdMethod(par));
}
return _CanConfigProGridSelectionChangedCmd;
}
}
private void CanConfigProGridSelectionChangedCmdMethod(object par)
{
if (par == null)
{
return;
}
if (par is SelectionChangedEventArgs)
{
return;
}
if (par is CanLinConfigPro)
{
SelectCanLinConfigPro = par as CanLinConfigPro;
//CANConfigExdDto 数据
SelectedCANConfigExdDto = Mapper.Map<CANConfigExdDto>(SelectCanLinConfigPro!.CANConfigExd);
var WirteData = SelectCanLinConfigPro.CanLinConfigContents!.Where(a => a.RWInfo == RW.Write).ToList();
if (WirteData != null && WirteData.Count > 0)
{
ListWriteCanLinRWConfigDto = new ObservableCollection<CanLinRWConfigDto>(Mapper.Map<List<CanLinRWConfigDto>>(WirteData));
}
var ReadData = SelectCanLinConfigPro.CanLinConfigContents!.Where(a => a.RWInfo == RW.Read).ToList();
if (ReadData != null && ReadData.Count > 0)
{
ListReadCanLinRWConfigDto = new ObservableCollection<CanLinRWConfigDto>(Mapper.Map<List<CanLinRWConfigDto>>(ReadData));
}
return;
}
//先判断是否是正确的集合数据防止DataGrid的数据源刷新导致的触发事件
var Selecteddata = (par as SelectionChangedEventArgs)!.AddedItems[0] as CanLinConfigPro;
if (Selecteddata != null)
{
SelectCanLinConfigPro = Selecteddata;
}
}
#endregion
#region Dbc操作
private ObservableCollection<CanDbcModel> _ListCanDbcModel;
/// <summary>
/// Dbc消息集合
/// </summary>
public ObservableCollection<CanDbcModel> ListCanDbcModel
{
get { return _ListCanDbcModel; }
set { _ListCanDbcModel = value; RaisePropertyChanged(); }
}
//private string _DbcFilePath;
///// <summary>
///// Dbc文件路径
///// </summary>
//public string DbcFilePath
//{
// get { return _DbcFilePath; }
// set { _DbcFilePath = value; RaisePropertyChanged(); }
//}
private DelegateCommand _LoadDbcCmd;
/// <summary>
/// 下载Dbc文件指令
/// </summary>
public DelegateCommand LoadDbcCmd
{
set
{
_LoadDbcCmd = value;
}
get
{
if (_LoadDbcCmd == null)
{
_LoadDbcCmd = new DelegateCommand(() => LoadDbcCmdMethod());
}
return _LoadDbcCmd;
}
}
/// <summary>
/// 加载Dbc文件信息
/// </summary>
private void LoadDbcCmdMethod()
{
//DbcFilePath
try
{
//var dd = ListQuickMeterStepDto;
if (SelectCanLinConfigPro != null && SelectedCANConfigExdDto != null)
{
OpenFileDialog OpenFileDialogInfo = new OpenFileDialog(); //new一个方法
OpenFileDialogInfo.Filter = "(*.dbc;*.dbc)|*.dbc;*.dbc|all|*.*"; //删选、设定文件显示类型
OpenFileDialogInfo.CheckFileExists = true;
OpenFileDialogInfo.CheckPathExists = true;
OpenFileDialogInfo.ShowDialog(); //显示打开文件的窗口
string fileName = OpenFileDialogInfo.FileName; //获得选择的文件路径
SelectedCANConfigExdDto.DbcPath = fileName;
}
else
{
MessageBox.Show("新建CAN配置名称后再操作", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
}
//System.Diagnostics.Process.Start(fileName);//打开指定路径下的文件
}
catch (Exception ex)
{
MessageBox.Show("可能未选择信息", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand);
}
}
/// <summary>
/// 选中的CanDbcModel
/// </summary>
public CanDbcModel SelectedCanDbcModel { get; set; }
private DelegateCommand<object> _DbcGridSelectionChangedCmd;
/// <summary>
/// Dbc选中行数据命令
/// </summary>
public DelegateCommand<object> DbcGridSelectionChangedCmd
{
set
{
_DbcGridSelectionChangedCmd = value;
}
get
{
if (_DbcGridSelectionChangedCmd == null)
{
_DbcGridSelectionChangedCmd = new DelegateCommand<object>((par) => DbcGridSelectionChangedCmdMethod(par));
}
return _DbcGridSelectionChangedCmd;
}
}
private void DbcGridSelectionChangedCmdMethod(object par)
{
if (par == null)
{
return;
}
if (par is CanDbcModel)
{
SelectedCanDbcModel = par as CanDbcModel;
return;
}
//先判断是否是正确的集合数据防止DataGrid的数据源刷新导致的触发事件
var Selecteddata = (par as SelectionChangedEventArgs)!.AddedItems[0] as CanDbcModel;
if (Selecteddata != null)
{
SelectedCanDbcModel = Selecteddata;
}
}
private DelegateCommand<string> _DataGridMenuCmd;
/// <summary>
/// DataGridMenu 操作的指令
/// </summary>
public DelegateCommand<string> DataGridMenuCmd
{
set
{
_DataGridMenuCmd = value;
}
get
{
if (_DataGridMenuCmd == null)
{
_DataGridMenuCmd = new DelegateCommand<string>((Par) => DataGridMenuCmdMethod(Par));
}
return _DataGridMenuCmd;
}
}
/// <summary>
/// DataGridMenu 操作的指令
/// </summary>
/// <exception cref="NotImplementedException"></exception>
private void DataGridMenuCmdMethod(string Par)
{
switch (Par)
{
case "Write":
if (SelectedCanDbcModel != null && SelectCanLinConfigPro != null)
{
FreeSql.Insert<CanLinRWConfig>(new CanLinRWConfig()
{
Name = "",
Content = SelectedCanDbcModel.SignalName,
CanLinConfigProId = SelectCanLinConfigPro.Id,
DefautValue = "",
RWInfo = RW.Write,
}).ExecuteInserted();
InitLoadCanConfigPro();
}
break;
case "Read":
if (SelectedCanDbcModel != null && SelectCanLinConfigPro != null)
{
FreeSql.Insert<CanLinRWConfig>(new CanLinRWConfig()
{
Name = "",
Content = SelectedCanDbcModel.SignalName,
CanLinConfigProId = SelectCanLinConfigPro.Id,
DefautValue = "",
RWInfo = RW.Read,
}).ExecuteInserted();
InitLoadCanConfigPro();
}
break;
default:
break;
}
}
#endregion
#region CAN操作
private CANConfigExdDto _SelectedCANConfigExdDto;
/// <summary>
/// 选中的CAN操作
/// </summary>
public CANConfigExdDto SelectedCANConfigExdDto
{
get { return _SelectedCANConfigExdDto; }
set { _SelectedCANConfigExdDto = value; RaisePropertyChanged(); }
}
private DelegateCommand<string> _CanOpCmd;
/// <summary>
/// CAN操作的指令
/// </summary>
public DelegateCommand<string> CanOpCmd
{
set
{
_CanOpCmd = value;
}
get
{
if (_CanOpCmd == null)
{
_CanOpCmd = new DelegateCommand<string>((Par) => CanOpCmdMethod(Par));
}
return _CanOpCmd;
}
}
/// <summary>
/// CAN操作的指令方法
/// </summary>
/// <exception cref="NotImplementedException"></exception>
private void CanOpCmdMethod(string Par)
{
switch (Par)
{
case "Open":
if (SelectCanLinConfigPro != null && SelectedCANConfigExdDto != null)
{
CanDriveService.ToomossCanDrive.StartCanDrive();
}
else
{
MessageBox.Show("新建CAN配置名称后再操作", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
}
break;
case "Close":
if (SelectCanLinConfigPro != null && SelectedCANConfigExdDto != null)
{
CanDriveService.ToomossCanDrive.CloseDevice();
}
else
{
MessageBox.Show("新建CAN配置名称后再操作", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
}
break;
case "Save":
if (SelectCanLinConfigPro != null && SelectedCANConfigExdDto != null)
{
//保存Can 配置
if (!string.IsNullOrEmpty(SelectedCANConfigExdDto.DbcPath))
{
var Update = FreeSql.Update<CANConfigExd>()
.Set(a => a.DbcPath, SelectedCANConfigExdDto.DbcPath)
.Set(a => a.Cycle, SelectedCANConfigExdDto.Cycle)
.Set(a => a.BaudRate, SelectedCANConfigExdDto.BaudRate)
.Where(a => a.Id == SelectedCANConfigExdDto.Id)
.ExecuteUpdated();
}
InitLoadCanConfigPro();
}
else
{
MessageBox.Show("新建CAN配置名称后再操作", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
}
break;
case "Parse":
if (SelectCanLinConfigPro != null && SelectedCANConfigExdDto != null)
{
// ListCanDbcModel = new ObservableCollection<CanDbcModel>()
//{
// new CanDbcModel(){ MsgName="DSDF1",SignalName="FASDFA11",Publisher="DFAD1",SignalDesc="ASDFASD1"},
// new CanDbcModel(){ MsgName="DSDF2",SignalName="FASDFA22",Publisher="DFAD2",SignalDesc="ASDFASD2"},
// new CanDbcModel(){ MsgName="DSDF3",SignalName="FASDFA33",Publisher="DFAD3",SignalDesc="ASDFASD3"},
// new CanDbcModel(){ MsgName="DSDF4",SignalName="FASDFA44",Publisher="DFAD4",SignalDesc="ASDFASD4"},
// new CanDbcModel(){ MsgName="DSDF5",SignalName="FASDFA55",Publisher="DFAD5",SignalDesc="ASDFASD5"},
//};
// return;
if (!string.IsNullOrEmpty(SelectedCANConfigExdDto.DbcPath))
{
CanDriveService.ToomossCanDrive.StartDbc(SelectedCANConfigExdDto.DbcPath);
ListCanDbcModel = CanDriveService.ToomossCanDrive.ListCanDbcModel;
}
else
{
MessageBox.Show("请选择DBC文件后再操作", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Hand);
}
}
else
{
MessageBox.Show("新建CAN配置名称后再操作", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
}
break;
case "SendTest1":
CanDriveService.ToomossCanDrive.SendCanMsg(new List<CanCmdData>()
{
new CanCmdData(){ MsgName="TX1",SignalName="COM_current_Power",SignalCmdValue=12},
new CanCmdData(){ MsgName="TX1",SignalName="COM_Curr_dc",SignalCmdValue=12},
});
break;
case "SendTest2":
CanDriveService.ToomossCanDrive.IsCycleRevice = true;
CanDriveService.ToomossCanDrive.StartCycleReviceCanMsg();
break;
default:
break;
}
}
#endregion
#region
private ObservableCollection<CanLinRWConfigDto> _ListWriteCanLinRWConfigDto;
/// <summary>
/// CAN写入集合数据
/// </summary>
public ObservableCollection<CanLinRWConfigDto> ListWriteCanLinRWConfigDto
{
get { return _ListWriteCanLinRWConfigDto; }
set { _ListWriteCanLinRWConfigDto = value; RaisePropertyChanged(); }
}
/// <summary>
/// 选中的CanLinRWConfigDto行 Write
/// </summary>
private CanLinRWConfigDto SelectedWriteCanLinRWConfigDto { get; set; }
private DelegateCommand<object> _WriteGridSelectionChangedCmd;
/// <summary>
/// 写入CAN的选中行的命令
/// </summary>
public DelegateCommand<object> WriteGridSelectionChangedCmd
{
set
{
_WriteGridSelectionChangedCmd = value;
}
get
{
if (_WriteGridSelectionChangedCmd == null)
{
_WriteGridSelectionChangedCmd = new DelegateCommand<object>((Par) => WriteGridSelectionChangedCmdMethod(Par));
}
return _WriteGridSelectionChangedCmd;
}
}
/// <summary>
/// 写入CAN的选中行执行方法
/// </summary>
/// <param name="par"></param>
/// <exception cref="NotImplementedException"></exception>
private void WriteGridSelectionChangedCmdMethod(object par)
{
if (par is CanLinRWConfigDto)
{
SelectedWriteCanLinRWConfigDto = par as CanLinRWConfigDto;
}
}
private DelegateCommand<string> _WriteCmd;
/// <summary>
/// 写入操作的指令
/// </summary>
public DelegateCommand<string> WriteCmd
{
set
{
_WriteCmd = value;
}
get
{
if (_WriteCmd == null)
{
_WriteCmd = new DelegateCommand<string>((Par) => WriteCmdMethod(Par));
}
return _WriteCmd;
}
}
/// <summary>
/// 写入操作的指令方法
/// </summary>
/// <exception cref="NotImplementedException"></exception>
private void WriteCmdMethod(string Par)
{
if (SelectCanLinConfigPro == null)
{
MessageBox.Show("新建CAN配置名称后再操作", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
return;
}
switch (Par)
{
case "Add":
//由右侧的右键DBC目录增加
break;
case "Edit":
if (ListWriteCanLinRWConfigDto != null && ListWriteCanLinRWConfigDto.Count() > 0)
{
foreach (var item in ListWriteCanLinRWConfigDto)
{
//直接修改
FreeSql.Update<CanLinRWConfig>(item.Id)
.Set(a => a.Name, item.Name)
.Set(a => a.DefautValue, item.DefautValue)
.ExecuteAffrows();
//ListWriteCanLinRWConfigDto.Remove(SelectedWriteCanLinRWConfigDto);
//SelectedWriteCanLinRWConfigDto = null;
}
InitLoadCanConfigPro();
}
break;
case "Delete":
if (SelectedWriteCanLinRWConfigDto != null)
{
//直接删除掉
FreeSql.Delete<CanLinRWConfig>(SelectedWriteCanLinRWConfigDto.Id).ExecuteAffrows();
ListWriteCanLinRWConfigDto.Remove(SelectedWriteCanLinRWConfigDto);
SelectedWriteCanLinRWConfigDto = null;
InitLoadCanConfigPro();
}
else
{
MessageBox.Show("请选中后再进行【删除】操作?", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
}
break;
default:
break;
}
}
private ObservableCollection<CanLinRWConfigDto> _ListReadCanLinRWConfigDto;
/// <summary>
/// CAN读取集合数据
/// </summary>
public ObservableCollection<CanLinRWConfigDto> ListReadCanLinRWConfigDto
{
get { return _ListReadCanLinRWConfigDto; }
set { _ListReadCanLinRWConfigDto = value; RaisePropertyChanged(); }
}
/// <summary>
/// 选中的CanLinRWConfigDto行 Read
/// </summary>
private CanLinRWConfigDto SelectedReadCanLinRWConfigDto { get; set; }
private DelegateCommand<object> _ReadGridSelectionChangedCmd;
/// <summary>
/// 写入CAN的选中行的命令
/// </summary>
public DelegateCommand<object> ReadGridSelectionChangedCmd
{
set
{
_ReadGridSelectionChangedCmd = value;
}
get
{
if (_ReadGridSelectionChangedCmd == null)
{
_ReadGridSelectionChangedCmd = new DelegateCommand<object>((Par) => ReadGridSelectionChangedCmdMethod(Par));
}
return _ReadGridSelectionChangedCmd;
}
}
/// <summary>
/// 读取CAN的选中行执行方法
/// </summary>
/// <param name="par"></param>
/// <exception cref="NotImplementedException"></exception>
private void ReadGridSelectionChangedCmdMethod(object par)
{
if (par is CanLinRWConfigDto)
{
SelectedReadCanLinRWConfigDto = par as CanLinRWConfigDto;
}
}
private DelegateCommand<string> _ReadCmd;
/// <summary>
/// 读取操作的指令
/// </summary>
public DelegateCommand<string> ReadCmd
{
set
{
_ReadCmd = value;
}
get
{
if (_ReadCmd == null)
{
_ReadCmd = new DelegateCommand<string>((Par) => ReadCmdMethod(Par));
}
return _ReadCmd;
}
}
/// <summary>
/// 读取操作的指令方法
/// </summary>
/// <exception cref="NotImplementedException"></exception>
private void ReadCmdMethod(string Par)
{
if (SelectCanLinConfigPro == null)
{
MessageBox.Show("新建CAN配置名称后再操作", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
return;
}
switch (Par)
{
case "Add":
//由右侧的右键DBC目录增加
break;
case "Edit":
if (ListReadCanLinRWConfigDto != null && ListReadCanLinRWConfigDto.Count() > 0)
{
foreach (var item in ListReadCanLinRWConfigDto)
{
//直接修改
FreeSql.Update<CanLinRWConfig>(item.Id)
.Set(a => a.Name, item.Name)
.Set(a => a.DefautValue, item.DefautValue)
.ExecuteAffrows();
//ListReadCanLinRWConfigDto.Remove(SelectedReadCanLinRWConfigDto);
//SelectedReadCanLinRWConfigDto = null;
}
InitLoadCanConfigPro();
}
break;
case "Delete":
if (SelectedReadCanLinRWConfigDto != null)
{
//直接删除掉
FreeSql.Delete<CanLinRWConfig>(SelectedReadCanLinRWConfigDto.Id).ExecuteAffrows();
ListReadCanLinRWConfigDto.Remove(SelectedReadCanLinRWConfigDto);
SelectedReadCanLinRWConfigDto = null;
InitLoadCanConfigPro();
}
else
{
MessageBox.Show("请选中后再进行【删除】操作?", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
}
break;
default:
break;
}
}
#endregion
}
}