1305 lines
49 KiB
C#
1305 lines
49 KiB
C#
using AutoMapper;
|
||
using CapMachine.Core;
|
||
using CapMachine.Model.CANLIN;
|
||
using CapMachine.Wpf.CanDrive;
|
||
using CapMachine.Wpf.Dtos;
|
||
using CapMachine.Wpf.LinDrive;
|
||
using CapMachine.Wpf.Services;
|
||
using Prism.Commands;
|
||
using Prism.Events;
|
||
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.Controls;
|
||
using Microsoft.Win32;
|
||
using static CapMachine.Wpf.Models.ComEnum;
|
||
using ImTools;
|
||
|
||
namespace CapMachine.Wpf.ViewModels
|
||
{
|
||
public class LinConfigViewModel : NavigationViewModel
|
||
{
|
||
/// <summary>
|
||
/// 实例化函数
|
||
/// </summary>
|
||
/// <param name="dialogService"></param>
|
||
/// <param name="freeSql"></param>
|
||
/// <param name="eventAggregator"></param>
|
||
/// <param name="regionManager"></param>
|
||
/// <param name="sysRunService"></param>
|
||
/// <param name="configService"></param>
|
||
/// <param name="linDriveService"></param>
|
||
/// <param name="mapper"></param>
|
||
/// <param name="machineRtDataService"></param>
|
||
public LinConfigViewModel(IDialogService dialogService, IFreeSql freeSql,
|
||
IEventAggregator eventAggregator, IRegionManager regionManager, SysRunService sysRunService,
|
||
ConfigService configService, LinDriveService linDriveService, ComActionService comActionService,
|
||
IMapper mapper, MachineRtDataService machineRtDataService)
|
||
{
|
||
//LogService = logService;
|
||
FreeSql = freeSql;
|
||
EventAggregator = eventAggregator;
|
||
RegionManager = regionManager;
|
||
SysRunService = sysRunService;
|
||
ConfigService = configService;
|
||
LinDriveService = linDriveService;
|
||
ComActionService = comActionService;
|
||
Mapper = mapper;
|
||
this.MachineRtDataService = machineRtDataService;
|
||
|
||
//MachineDataService = machineDataService;
|
||
DialogService = dialogService;
|
||
|
||
//数据波特率
|
||
DataBaudRateCbxItems = new ObservableCollection<CbxItems>()
|
||
{
|
||
new CbxItems(){ Key="38400",Text="38400"},
|
||
new CbxItems(){ Key="19200",Text="19200"},
|
||
new CbxItems(){ Key="14400",Text="14400"},
|
||
new CbxItems(){ Key="9600",Text="9600"},
|
||
new CbxItems(){ Key="4800",Text="4800"},
|
||
new CbxItems(){ Key="2400",Text="2400"},
|
||
};
|
||
|
||
|
||
WriteNameCbxItems = new ObservableCollection<CbxItems>()
|
||
{
|
||
new CbxItems(){ Key="转速",Text="转速"},
|
||
new CbxItems(){ Key="功率限制",Text="功率限制"},
|
||
new CbxItems(){ Key="使能",Text="使能"},
|
||
new CbxItems(){ Key="Anti_Sleep",Text="Anti_Sleep"},
|
||
};
|
||
|
||
ReadNameCbxItems = new ObservableCollection<CbxItems>()
|
||
{
|
||
new CbxItems(){ Key="通讯转速",Text="通讯转速"},
|
||
new CbxItems(){ Key="通讯母线电压",Text="通讯母线电压"},
|
||
new CbxItems(){ Key="通讯母线电流",Text="通讯母线电流"},
|
||
new CbxItems(){ Key="通讯相电流",Text="通讯相电流"},
|
||
new CbxItems(){ Key="通讯功率",Text="通讯功率"},
|
||
new CbxItems(){ Key="通讯逆变器温度",Text="通讯逆变器温度"},
|
||
new CbxItems(){ Key="通讯芯片温度",Text="通讯芯片温度"},
|
||
};
|
||
InitLoadLinConfigPro();
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// FreeSQL 实例函数
|
||
/// </summary>
|
||
public IFreeSql FreeSql { get; }
|
||
public IEventAggregator EventAggregator { get; }
|
||
public IRegionManager RegionManager { get; }
|
||
public SysRunService SysRunService { get; }
|
||
public ConfigService ConfigService { get; }
|
||
public LinDriveService LinDriveService { get; }
|
||
public ComActionService ComActionService { get; }
|
||
public IMapper Mapper { get; }
|
||
private MachineRtDataService MachineRtDataService { get; }
|
||
|
||
/// <summary>
|
||
/// 弹窗服务
|
||
/// </summary>
|
||
public IDialogService DialogService { get; }
|
||
|
||
|
||
|
||
#region LinConfigPro
|
||
|
||
/// <summary>
|
||
/// 初始化j加载执行方法
|
||
/// </summary>
|
||
private void InitLoadLinConfigPro()
|
||
{
|
||
//LIN配置集合数据
|
||
canLinConfigPros = FreeSql.Select<CanLinConfigPro>().Where(a => a.CANLINInfo == CANLIN.LIN)
|
||
.Include(a => a.LINConfigExd)
|
||
.IncludeMany(a => a.CanLinConfigContents)
|
||
.ToList();
|
||
|
||
ListCanLinConfigPro = new ObservableCollection<CanLinConfigPro>(canLinConfigPros);
|
||
if (SelectCanLinConfigPro != null)
|
||
{
|
||
SelectCanLinConfigPro = canLinConfigPros.Where(a => a.Id == SelectCanLinConfigPro.Id).FirstOrDefault()!;
|
||
//无数据就返回
|
||
if (SelectCanLinConfigPro == null) return;
|
||
|
||
SelectedLINConfigExdDto = Mapper.Map<LINConfigExdDto>(SelectCanLinConfigPro!.LINConfigExd);
|
||
|
||
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));
|
||
|
||
//加载把当前的配置信息给指令
|
||
LinDriveService.CmdData.Clear();
|
||
foreach (var item in WirteData)
|
||
{
|
||
LinDriveService.AddCmdData(new LinCmdData()
|
||
{
|
||
ConfigName = item.Name,
|
||
MsgName = item.MsgFrameName,
|
||
SignalName = item.SignalName,
|
||
SignalCmdValue = double.TryParse(item.DefautValue, out double result) == true ? result : 0,
|
||
});
|
||
//LinDriveService.CmdData.Add(new LinCmdData()
|
||
//{
|
||
// ConfigName = item.Name,
|
||
// MsgName = item.MsgFrameName,
|
||
// SignalName = item.SignalName,
|
||
// SignalCmdValue = double.TryParse(item.DefautValue, out double result) == true ? result : 0,
|
||
//});
|
||
}
|
||
|
||
}
|
||
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));
|
||
}
|
||
|
||
//匹配选中的SelectCanLinConfigPro.CanLinConfigContents和ListLinLdfModel
|
||
MatchSeletedAndLinLdfModel();
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 匹配选中的SelectCanLinConfigPro.CanLinConfigContents和LinLdfModel
|
||
/// 为了标注和着色使用
|
||
/// </summary>
|
||
private void MatchSeletedAndLinLdfModel()
|
||
{
|
||
//通过CanLinConfigContents标注ListLinLdfModel的选中状态属性,方便着色
|
||
if (ListLinLdfModel != null && ListLinLdfModel!.Count() > 0 && SelectCanLinConfigPro.CanLinConfigContents != null && SelectCanLinConfigPro.CanLinConfigContents.Count() > 0)
|
||
{
|
||
foreach (var itemLinLdfModel in ListLinLdfModel)
|
||
{
|
||
var FindData = SelectCanLinConfigPro.CanLinConfigContents.FindFirst(a => a.SignalName == itemLinLdfModel.SignalName);
|
||
if (FindData != null)//找到了就标注
|
||
{
|
||
switch (FindData.RWInfo)
|
||
{
|
||
case RW.Write:
|
||
itemLinLdfModel.IsSeletedInfo = 1;
|
||
break;
|
||
case RW.Read:
|
||
itemLinLdfModel.IsSeletedInfo = 2;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//没有找到了就标注为0
|
||
itemLinLdfModel.IsSeletedInfo = 0;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private bool _IsLinConfigProActive = false;
|
||
/// <summary>
|
||
/// LIN 配置是否被激活
|
||
/// </summary>
|
||
public bool IsLinConfigProActive
|
||
{
|
||
get { return _IsLinConfigProActive; }
|
||
set { _IsLinConfigProActive = value; RaisePropertyChanged(); }
|
||
}
|
||
|
||
private bool _IsLINConfigDatagridActive = true;
|
||
/// <summary>
|
||
/// LINConfigDatagrid是否被触控
|
||
/// 关联IsLinConfigProActive 取反
|
||
/// </summary>
|
||
public bool IsLINConfigDatagridActive
|
||
{
|
||
get { return _IsLINConfigDatagridActive; }
|
||
set { _IsLINConfigDatagridActive = value; RaisePropertyChanged(); }
|
||
}
|
||
|
||
private string _SelectCanLinConfigProConfigName;
|
||
/// <summary>
|
||
/// 选中的 CanLinConfigPro 名称
|
||
/// </summary>
|
||
public string SelectCanLinConfigProConfigName
|
||
{
|
||
get { return _SelectCanLinConfigProConfigName; }
|
||
set { _SelectCanLinConfigProConfigName = value; RaisePropertyChanged(); }
|
||
}
|
||
|
||
|
||
private DelegateCommand<string> _CanLinConfigPromdCmd;
|
||
/// <summary>
|
||
/// LINConfigPro操作的指令
|
||
/// </summary>
|
||
public DelegateCommand<string> CanLinConfigPromdCmd
|
||
{
|
||
set
|
||
{
|
||
_CanLinConfigPromdCmd = value;
|
||
}
|
||
get
|
||
{
|
||
if (_CanLinConfigPromdCmd == null)
|
||
{
|
||
_CanLinConfigPromdCmd = new DelegateCommand<string>((Par) => CanLinConfigPromdCmdMethod(Par));
|
||
}
|
||
return _CanLinConfigPromdCmd;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// LinConfigPro操作的指令方法
|
||
/// </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");
|
||
|
||
//加载默认的数据 LINConfigExd
|
||
var InsertLINConfigExd = FreeSql.Insert<LINConfigExd>(new LINConfigExd()
|
||
{
|
||
BaudRate = 250,
|
||
LdfPath = "请配置LDF路径",
|
||
Cycle = 100,
|
||
}).ExecuteInserted();
|
||
|
||
//返回数据,刷新Chart
|
||
var InsertData = FreeSql.Insert<CanLinConfigPro>(new CanLinConfigPro()
|
||
{
|
||
ConfigName = ReturnValue,
|
||
CANLINInfo = CANLIN.LIN,
|
||
LINConfigExdId = InsertLINConfigExd.FirstOrDefault()!.Id
|
||
}).ExecuteInserted();
|
||
if (InsertData != null)
|
||
{
|
||
//加载默认的数据 CanLinRWConfig
|
||
FreeSql.Insert<CanLinRWConfig>(new CanLinRWConfig()
|
||
{
|
||
SignalName = "Speed",
|
||
DefautValue = "0",
|
||
Name = "转速",
|
||
RWInfo = RW.Write,
|
||
CanLinConfigProId = InsertData.FirstOrDefault().Id
|
||
}).ExecuteInserted();
|
||
|
||
FreeSql.Insert<CanLinRWConfig>(new CanLinRWConfig()
|
||
{
|
||
SignalName = "Vol",
|
||
DefautValue = "0",
|
||
Name = "电压",
|
||
RWInfo = RW.Read,
|
||
CanLinConfigProId = InsertData.FirstOrDefault().Id
|
||
|
||
}).ExecuteInserted();
|
||
}
|
||
|
||
InitLoadLinConfigPro();
|
||
|
||
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();
|
||
|
||
InitLoadLinConfigPro();
|
||
|
||
SelectCanLinConfigPro = null;
|
||
}
|
||
else if (par.Result == ButtonResult.Cancel)
|
||
{
|
||
//取消
|
||
|
||
}
|
||
|
||
});
|
||
}
|
||
else
|
||
{
|
||
System.Windows.MessageBox.Show("选中后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.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.LINConfigExd)
|
||
.IncludeMany(a => a.CanLinConfigContents)
|
||
.Where(a => a.Id == SelectCanLinConfigPro.Id)
|
||
.ToList();
|
||
|
||
repo.Delete(DeleteData);
|
||
foreach (var item in DeleteData)
|
||
{
|
||
FreeSql.Delete<LINConfigExd>(item.LINConfigExdId).ExecuteAffrows();
|
||
}
|
||
InitLoadLinConfigPro();
|
||
}
|
||
else
|
||
{
|
||
System.Windows.MessageBox.Show("选中后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
|
||
}
|
||
break;
|
||
case "Active":
|
||
|
||
//激活到取消的状态的判断
|
||
if (IsLinConfigProActive == true)
|
||
{
|
||
//控件的激活
|
||
IsLinConfigProActive = !IsLinConfigProActive;
|
||
//控件的激活配置信息
|
||
IsLINConfigDatagridActive = !IsLinConfigProActive;
|
||
|
||
return;
|
||
}
|
||
|
||
if (LinDriveService.ToomossLinDrive.OpenState == true && LinDriveService.ToomossLinDrive.LdfParserState == true)
|
||
{
|
||
if (SelectCanLinConfigPro != null)
|
||
{
|
||
//控件的激活
|
||
IsLinConfigProActive = !IsLinConfigProActive;
|
||
//控件的激活配置信息
|
||
IsLINConfigDatagridActive = !IsLinConfigProActive;
|
||
|
||
//当前使用的LIN配置信息
|
||
LinDriveService.InitLinConfig(SelectCanLinConfigPro);
|
||
|
||
InitLoadLinConfigPro();
|
||
}
|
||
else
|
||
{
|
||
System.Windows.MessageBox.Show("选中后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
System.Windows.MessageBox.Show("请确保LIN连接打开和LDF解析成功后再激活", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// LIN List集合信息
|
||
/// </summary>
|
||
private List<CanLinConfigPro> canLinConfigPros = new List<CanLinConfigPro>();
|
||
|
||
private ObservableCollection<CanLinConfigPro> _ListCanLinConfigPro;
|
||
/// <summary>
|
||
/// LIN 配置程序集合 ObservableCollection
|
||
/// </summary>
|
||
public ObservableCollection<CanLinConfigPro> ListCanLinConfigPro
|
||
{
|
||
get { return _ListCanLinConfigPro; }
|
||
set { _ListCanLinConfigPro = value; RaisePropertyChanged(); }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 选中的CanLinConfigPro
|
||
/// </summary>
|
||
public CanLinConfigPro SelectCanLinConfigPro { get; set; }
|
||
|
||
private DelegateCommand<object> _LinConfigProGridSelectionChangedCmd;
|
||
/// <summary>
|
||
/// LIN 配置程序 选中行数据命令
|
||
/// </summary>
|
||
public DelegateCommand<object> LinConfigProGridSelectionChangedCmd
|
||
{
|
||
set
|
||
{
|
||
_LinConfigProGridSelectionChangedCmd = value;
|
||
}
|
||
get
|
||
{
|
||
if (_LinConfigProGridSelectionChangedCmd == null)
|
||
{
|
||
_LinConfigProGridSelectionChangedCmd = new DelegateCommand<object>((par) => LinConfigProGridSelectionChangedCmdMethod(par));
|
||
}
|
||
return _LinConfigProGridSelectionChangedCmd;
|
||
}
|
||
}
|
||
private void LinConfigProGridSelectionChangedCmdMethod(object par)
|
||
{
|
||
if (par == null)
|
||
{
|
||
return;
|
||
}
|
||
if (par is SelectionChangedEventArgs)
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (par is CanLinConfigPro)
|
||
{
|
||
SelectCanLinConfigPro = par as CanLinConfigPro;
|
||
|
||
//LINConfigExdDto 数据
|
||
SelectedLINConfigExdDto = Mapper.Map<LINConfigExdDto>(SelectCanLinConfigPro!.LINConfigExd);
|
||
|
||
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));
|
||
|
||
//加载把当前的配置信息给指令
|
||
LinDriveService.CmdData.Clear();
|
||
foreach (var item in WirteData)
|
||
{
|
||
LinDriveService.AddCmdData(new LinCmdData()
|
||
{
|
||
ConfigName = item.Name,
|
||
MsgName = item.MsgFrameName,
|
||
SignalName = item.SignalName,
|
||
SignalCmdValue = double.TryParse(item.DefautValue, out double result) == true ? result : 0,
|
||
});
|
||
|
||
//LinDriveService.CmdData.Add(new LinCmdData()
|
||
//{
|
||
// ConfigName = item.Name,
|
||
// MsgName = item.MsgFrameName,
|
||
// SignalName = item.SignalName,
|
||
// SignalCmdValue = double.TryParse(item.DefautValue, out double result) == true ? result : 0,
|
||
//});
|
||
}
|
||
|
||
}
|
||
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));
|
||
}
|
||
|
||
SelectCanLinConfigProConfigName = SelectCanLinConfigPro.ConfigName;
|
||
return;
|
||
}
|
||
//先判断是否是正确的集合数据,防止DataGrid的数据源刷新导致的触发事件
|
||
var Selecteddata = (par as SelectionChangedEventArgs)!.AddedItems[0] as CanLinConfigPro;
|
||
|
||
if (Selecteddata != null)
|
||
{
|
||
SelectCanLinConfigPro = Selecteddata;
|
||
|
||
SelectCanLinConfigProConfigName = SelectCanLinConfigPro.ConfigName;
|
||
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
private DelegateCommand<object> _LinConfigProGridPreviewMouseLeftButtonDownCmd;
|
||
/// <summary>
|
||
/// LIN 配置程序 选中行之前的数据命令 Preview
|
||
/// 防止LIN 打开后没有关闭就开始切换LIN 配置程序信息
|
||
/// 要关闭后再切换
|
||
/// </summary>
|
||
public DelegateCommand<object> LinConfigProGridPreviewMouseLeftButtonDownCmd
|
||
{
|
||
set
|
||
{
|
||
_LinConfigProGridPreviewMouseLeftButtonDownCmd = value;
|
||
}
|
||
get
|
||
{
|
||
if (_LinConfigProGridPreviewMouseLeftButtonDownCmd == null)
|
||
{
|
||
_LinConfigProGridPreviewMouseLeftButtonDownCmd = new DelegateCommand<object>((par) => LinConfigProGridPreviewMouseLeftButtonDownCmdMethod(par));
|
||
}
|
||
return _LinConfigProGridPreviewMouseLeftButtonDownCmd;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 防止LIN 打开后没有关闭就开始切换LIN 配置程序信息
|
||
/// 要关闭后再切换
|
||
/// </summary>
|
||
/// <param name="par"></param>
|
||
private void LinConfigProGridPreviewMouseLeftButtonDownCmdMethod(object par)
|
||
{
|
||
if (par == null)
|
||
{
|
||
return;
|
||
}
|
||
if (par is System.Windows.Input.MouseButtonEventArgs)
|
||
{
|
||
var handler = par as System.Windows.Input.MouseButtonEventArgs;
|
||
|
||
if (!LinDriveService.ToomossLinDrive.OpenState)
|
||
{
|
||
// 防止默认的行选择行为发生
|
||
handler.Handled = false;
|
||
}
|
||
else
|
||
{
|
||
System.Windows.MessageBox.Show("关闭LIN连接后再点击切换LIN配置", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
|
||
handler.Handled = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
#endregion
|
||
|
||
#region Ldf操作
|
||
|
||
private ObservableCollection<LinLdfModel> _ListLinLdfModel;
|
||
/// <summary>
|
||
/// Ldf消息集合
|
||
/// </summary>
|
||
public ObservableCollection<LinLdfModel> ListLinLdfModel
|
||
{
|
||
get { return _ListLinLdfModel; }
|
||
set { _ListLinLdfModel = value; RaisePropertyChanged(); }
|
||
}
|
||
|
||
//private string _LdfFilePath;
|
||
///// <summary>
|
||
///// Ldf文件路径
|
||
///// </summary>
|
||
//public string LdfFilePath
|
||
//{
|
||
// get { return _LdfFilePath; }
|
||
// set { _LdfFilePath = value; RaisePropertyChanged(); }
|
||
//}
|
||
|
||
|
||
private DelegateCommand _LoadLdfCmd;
|
||
/// <summary>
|
||
/// 下载Ldf文件指令
|
||
/// </summary>
|
||
public DelegateCommand LoadLdfCmd
|
||
{
|
||
set
|
||
{
|
||
_LoadLdfCmd = value;
|
||
}
|
||
get
|
||
{
|
||
if (_LoadLdfCmd == null)
|
||
{
|
||
_LoadLdfCmd = new DelegateCommand(() => LoadLdfCmdMethod());
|
||
}
|
||
return _LoadLdfCmd;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 加载Ldf文件信息
|
||
/// </summary>
|
||
private void LoadLdfCmdMethod()
|
||
{
|
||
//LdfFilePath
|
||
try
|
||
{
|
||
//var dd = ListQuickMeterStepDto;
|
||
|
||
if (SelectCanLinConfigPro != null && SelectedLINConfigExdDto != null)
|
||
{
|
||
OpenFileDialog OpenFileDialogInfo = new OpenFileDialog(); //new一个方法
|
||
OpenFileDialogInfo.Filter = "(*.ldf;*.ldf)|*.ldf;*.ldf|all|*.*"; //删选、设定文件显示类型
|
||
OpenFileDialogInfo.CheckFileExists = true;
|
||
OpenFileDialogInfo.CheckPathExists = true;
|
||
|
||
OpenFileDialogInfo.ShowDialog(); //显示打开文件的窗口
|
||
string fileName = OpenFileDialogInfo.FileName; //获得选择的文件路径
|
||
|
||
SelectedLINConfigExdDto.LdfPath = fileName;
|
||
}
|
||
else
|
||
{
|
||
System.Windows.MessageBox.Show("选中LIN配置名称后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
|
||
}
|
||
|
||
//System.Diagnostics.Process.Start(fileName);//打开指定路径下的文件
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
System.Windows.MessageBox.Show("可能未选择信息", "提示", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Hand);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 选中的LinLdfModel
|
||
/// </summary>
|
||
public LinLdfModel SelectedLinLdfModel { get; set; }
|
||
|
||
private DelegateCommand<object> _LdfGridSelectionChangedCmd;
|
||
/// <summary>
|
||
/// Ldf选中行数据命令
|
||
/// </summary>
|
||
public DelegateCommand<object> LdfGridSelectionChangedCmd
|
||
{
|
||
set
|
||
{
|
||
_LdfGridSelectionChangedCmd = value;
|
||
}
|
||
get
|
||
{
|
||
if (_LdfGridSelectionChangedCmd == null)
|
||
{
|
||
_LdfGridSelectionChangedCmd = new DelegateCommand<object>((par) => LdfGridSelectionChangedCmdMethod(par));
|
||
}
|
||
return _LdfGridSelectionChangedCmd;
|
||
}
|
||
}
|
||
private void LdfGridSelectionChangedCmdMethod(object par)
|
||
{
|
||
if (par == null)
|
||
{
|
||
return;
|
||
}
|
||
if (par is LinLdfModel)
|
||
{
|
||
SelectedLinLdfModel = par as LinLdfModel;
|
||
return;
|
||
}
|
||
|
||
if ((par as SelectionChangedEventArgs)!.AddedItems.Count == 0)
|
||
{
|
||
return;
|
||
}
|
||
//先判断是否是正确的集合数据,防止DataGrid的数据源刷新导致的触发事件
|
||
var Selecteddata = (par as SelectionChangedEventArgs)!.AddedItems[0] as LinLdfModel;
|
||
|
||
if (Selecteddata != null)
|
||
{
|
||
SelectedLinLdfModel = 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 (SelectedLinLdfModel != null && SelectCanLinConfigPro != null)
|
||
{
|
||
FreeSql.Insert<CanLinRWConfig>(new CanLinRWConfig()
|
||
{
|
||
Name = "",
|
||
SignalName = SelectedLinLdfModel.SignalName,
|
||
MsgFrameName = SelectedLinLdfModel.MsgName,
|
||
CanLinConfigProId = SelectCanLinConfigPro.Id,
|
||
DefautValue = "",
|
||
RWInfo = RW.Write,
|
||
}).ExecuteInserted();
|
||
|
||
InitLoadLinConfigPro();
|
||
}
|
||
break;
|
||
case "Read":
|
||
if (SelectedLinLdfModel != null && SelectCanLinConfigPro != null)
|
||
{
|
||
FreeSql.Insert<CanLinRWConfig>(new CanLinRWConfig()
|
||
{
|
||
Name = "",
|
||
SignalName = SelectedLinLdfModel.SignalName,
|
||
MsgFrameName = SelectedLinLdfModel.MsgName,
|
||
CanLinConfigProId = SelectCanLinConfigPro.Id,
|
||
DefautValue = "",
|
||
RWInfo = RW.Read,
|
||
}).ExecuteInserted();
|
||
|
||
InitLoadLinConfigPro();
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
#endregion
|
||
|
||
#region LIN操作
|
||
|
||
|
||
private ObservableCollection<CbxItems> _DataBaudRateCbxItems;
|
||
/// <summary>
|
||
/// CAN 数据波特率
|
||
/// </summary>
|
||
public ObservableCollection<CbxItems> DataBaudRateCbxItems
|
||
{
|
||
get { return _DataBaudRateCbxItems; }
|
||
set { _DataBaudRateCbxItems = value; RaisePropertyChanged(); }
|
||
}
|
||
|
||
|
||
private LINConfigExdDto _SelectedLINConfigExdDto;
|
||
/// <summary>
|
||
/// 选中的LIN操作
|
||
/// </summary>
|
||
public LINConfigExdDto SelectedLINConfigExdDto
|
||
{
|
||
get { return _SelectedLINConfigExdDto; }
|
||
set { _SelectedLINConfigExdDto = value; RaisePropertyChanged(); }
|
||
}
|
||
|
||
private DelegateCommand<string> _LinOpCmd;
|
||
/// <summary>
|
||
/// LIN操作的指令
|
||
/// </summary>
|
||
public DelegateCommand<string> LinOpCmd
|
||
{
|
||
set
|
||
{
|
||
_LinOpCmd = value;
|
||
}
|
||
get
|
||
{
|
||
if (_LinOpCmd == null)
|
||
{
|
||
_LinOpCmd = new DelegateCommand<string>((Par) => LinOpCmdMethod(Par));
|
||
}
|
||
return _LinOpCmd;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// LIN操作的指令方法
|
||
/// </summary>
|
||
/// <exception cref="NotImplementedException"></exception>
|
||
private void LinOpCmdMethod(string Par)
|
||
{
|
||
switch (Par)
|
||
{
|
||
case "Open":
|
||
if (ComActionService.IsLINToDoWork() == false)
|
||
{
|
||
System.Windows.MessageBox.Show("请关闭CAN连接后才能开启LIN,同一个时刻只能有一个通信驱动压缩机", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
|
||
return;
|
||
}
|
||
if (SelectCanLinConfigPro != null && SelectedLINConfigExdDto != null)
|
||
{
|
||
//打开连接
|
||
LinDriveService.ToomossLinDrive.StartLinDrive();
|
||
//成功后状态显示
|
||
if (LinDriveService.ToomossLinDrive.OpenState)
|
||
{
|
||
//系统使用了LIN
|
||
ConfigService.CanLinRunStateModel.CurSysSelectedCanLin = CanLinEnum.Lin;
|
||
}
|
||
|
||
//LIN LDF配置 有LDF配置的话,则直接加载LDF信息
|
||
if (!string.IsNullOrEmpty(SelectCanLinConfigPro.LINConfigExd.LdfPath))
|
||
{
|
||
var LdfData = LinDriveService.StartLdf(SelectedLINConfigExdDto.LdfPath);
|
||
ListLinLdfModel = LdfData;
|
||
|
||
//ListLinLdfModel有数据后就要看看是否有配置信息,有的话就要标注
|
||
//匹配选中的SelectCanLinConfigPro.CanLinConfigContents和ListLinLdfModel
|
||
MatchSeletedAndLinLdfModel();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
System.Windows.MessageBox.Show("选中LIN配置名称后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
|
||
}
|
||
|
||
break;
|
||
case "Close":
|
||
if (SelectCanLinConfigPro != null && SelectedLINConfigExdDto != null)
|
||
{
|
||
|
||
LinDriveService.ToomossLinDrive.CloseDevice();
|
||
//系统取消使用了CAN
|
||
ConfigService.CanLinRunStateModel.CurSysSelectedCanLin = CanLinEnum.No;
|
||
}
|
||
else
|
||
{
|
||
System.Windows.MessageBox.Show("选中LIN配置名称后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
|
||
}
|
||
|
||
break;
|
||
case "Save":
|
||
if (SelectCanLinConfigPro != null && SelectedLINConfigExdDto != null)
|
||
{
|
||
//保存LIN 配置
|
||
if (!string.IsNullOrEmpty(SelectedLINConfigExdDto.LdfPath))
|
||
{
|
||
var Update = FreeSql.Update<LINConfigExd>()
|
||
.Set(a => a.LdfPath, SelectedLINConfigExdDto.LdfPath)
|
||
.Set(a => a.Cycle, SelectedLINConfigExdDto.Cycle)
|
||
.Set(a => a.BaudRate, SelectedLINConfigExdDto.BaudRate)
|
||
.Where(a => a.Id == SelectedLINConfigExdDto.Id)
|
||
.ExecuteUpdated();
|
||
}
|
||
|
||
InitLoadLinConfigPro();
|
||
}
|
||
else
|
||
{
|
||
System.Windows.MessageBox.Show("选中LIN配置名称后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
|
||
}
|
||
|
||
break;
|
||
case "Parse":
|
||
if (SelectCanLinConfigPro != null && SelectedLINConfigExdDto != null)
|
||
{
|
||
//打开之后连接
|
||
if (LinDriveService.ToomossLinDrive.OpenState)
|
||
{
|
||
//LIN LDF配置 有LDF配置的话,则加载LDF信息
|
||
if (!string.IsNullOrEmpty(SelectedLINConfigExdDto.LdfPath))
|
||
{
|
||
var LdfData = LinDriveService.StartLdf(SelectedLINConfigExdDto.LdfPath);
|
||
|
||
ListLinLdfModel = LdfData;
|
||
}
|
||
else
|
||
{
|
||
System.Windows.MessageBox.Show("请选择LDF文件后再操作", "提示", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Hand);
|
||
}
|
||
}
|
||
// ListLinLdfModel = new ObservableCollection<LinLdfModel>()
|
||
//{
|
||
// new LinLdfModel(){ MsgName="DSDF1",SignalName="FASDFA11",Publisher="DFAD1",SignalDesc="ASDFASD1"},
|
||
// new LinLdfModel(){ MsgName="DSDF2",SignalName="FASDFA22",Publisher="DFAD2",SignalDesc="ASDFASD2"},
|
||
// new LinLdfModel(){ MsgName="DSDF3",SignalName="FASDFA33",Publisher="DFAD3",SignalDesc="ASDFASD3"},
|
||
// new LinLdfModel(){ MsgName="DSDF4",SignalName="FASDFA44",Publisher="DFAD4",SignalDesc="ASDFASD4"},
|
||
// new LinLdfModel(){ MsgName="DSDF5",SignalName="FASDFA55",Publisher="DFAD5",SignalDesc="ASDFASD5"},
|
||
//};
|
||
// return;
|
||
|
||
}
|
||
else
|
||
{
|
||
System.Windows.MessageBox.Show("选中LIN配置名称后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
|
||
}
|
||
|
||
break;
|
||
|
||
case "HandSend"://手动发送
|
||
|
||
//手动发送数据
|
||
LinDriveService.SendMsgToLinDrive(HandSpeed);
|
||
|
||
//LinDriveService.ToomossLinDrive.SendCanMsg(new List<LinCmdData>()
|
||
//{
|
||
// new LinCmdData(){ MsgName="TX1",SignalName="COM_current_Power",SignalCmdValue=12},
|
||
// new LinCmdData(){ MsgName="TX1",SignalName="COM_Curr_dc",SignalCmdValue=12},
|
||
//});
|
||
|
||
break;
|
||
case "CycleSend"://循环发送你
|
||
//循环发送数据
|
||
LinDriveService.CycleSendMsg();
|
||
|
||
//Listen
|
||
break;
|
||
case "CycleRecive":
|
||
LinDriveService.CycleReciveMsg();
|
||
|
||
//Listen
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
private double _HandSpeed;
|
||
/// <summary>
|
||
/// 手动转速数据
|
||
/// </summary>
|
||
public double HandSpeed
|
||
{
|
||
get { return _HandSpeed; }
|
||
set { _HandSpeed = value; RaisePropertyChanged(); }
|
||
}
|
||
|
||
|
||
#endregion
|
||
|
||
|
||
#region 写入和读取操作
|
||
|
||
private ObservableCollection<CbxItems> _WriteNameCbxItems;
|
||
/// <summary>
|
||
/// 写入的Name
|
||
/// </summary>
|
||
public ObservableCollection<CbxItems> WriteNameCbxItems
|
||
{
|
||
get { return _WriteNameCbxItems; }
|
||
set { _WriteNameCbxItems = value; RaisePropertyChanged(); }
|
||
}
|
||
|
||
|
||
private ObservableCollection<CbxItems> _ReadNameCbxItems;
|
||
/// <summary>
|
||
/// 写入的Name
|
||
/// </summary>
|
||
public ObservableCollection<CbxItems> ReadNameCbxItems
|
||
{
|
||
get { return _ReadNameCbxItems; }
|
||
set { _ReadNameCbxItems = value; RaisePropertyChanged(); }
|
||
}
|
||
|
||
|
||
//private string _SelectedWriteName;
|
||
///// <summary>
|
||
///// 选中的写入的Name
|
||
///// </summary>
|
||
//public string SelectedWriteName
|
||
//{
|
||
// get { return _SelectedWriteName; }
|
||
// set { _SelectedWriteName = value; RaisePropertyChanged(); }
|
||
//}
|
||
|
||
//private string _SelectedReadName;
|
||
///// <summary>
|
||
///// 选中的读取的Name
|
||
///// </summary>
|
||
//public string SelectedReadName
|
||
//{
|
||
// get { return _SelectedReadName; }
|
||
// set { _SelectedReadName = value; RaisePropertyChanged(); }
|
||
//}
|
||
|
||
|
||
private ObservableCollection<CanLinRWConfigDto> _ListWriteCanLinRWConfigDto;
|
||
/// <summary>
|
||
/// LIN写入集合数据
|
||
/// </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>
|
||
/// 写入LIN的选中行的命令
|
||
/// </summary>
|
||
public DelegateCommand<object> WriteGridSelectionChangedCmd
|
||
{
|
||
set
|
||
{
|
||
_WriteGridSelectionChangedCmd = value;
|
||
}
|
||
get
|
||
{
|
||
if (_WriteGridSelectionChangedCmd == null)
|
||
{
|
||
_WriteGridSelectionChangedCmd = new DelegateCommand<object>((Par) => WriteGridSelectionChangedCmdMethod(Par));
|
||
}
|
||
return _WriteGridSelectionChangedCmd;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 写入LIN的选中行执行方法
|
||
/// </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)
|
||
{
|
||
System.Windows.MessageBox.Show("选中LIN配置名称后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
|
||
return;
|
||
}
|
||
if (LinDriveService.ToomossLinDrive.IsCycleSend)
|
||
{
|
||
System.Windows.MessageBox.Show("正在循环发送中,此时编辑可能会出现错误,请关闭循环发送后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
|
||
return;
|
||
}
|
||
|
||
switch (Par)
|
||
{
|
||
case "Add":
|
||
//由右侧的右键LDF目录增加
|
||
|
||
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;
|
||
|
||
}
|
||
|
||
InitLoadLinConfigPro();
|
||
}
|
||
|
||
|
||
|
||
break;
|
||
case "Delete":
|
||
if (SelectedWriteCanLinRWConfigDto != null)
|
||
{
|
||
//直接删除掉
|
||
FreeSql.Delete<CanLinRWConfig>(SelectedWriteCanLinRWConfigDto.Id).ExecuteAffrows();
|
||
ListWriteCanLinRWConfigDto.Remove(SelectedWriteCanLinRWConfigDto);
|
||
|
||
SelectedWriteCanLinRWConfigDto = null;
|
||
|
||
InitLoadLinConfigPro();
|
||
}
|
||
else
|
||
{
|
||
System.Windows.MessageBox.Show("请选中后再进行【删除】操作?", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
|
||
}
|
||
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
private ObservableCollection<CanLinRWConfigDto> _ListReadCanLinRWConfigDto;
|
||
/// <summary>
|
||
/// LIN读取集合数据
|
||
/// </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>
|
||
/// 写入LIN的选中行的命令
|
||
/// </summary>
|
||
public DelegateCommand<object> ReadGridSelectionChangedCmd
|
||
{
|
||
set
|
||
{
|
||
_ReadGridSelectionChangedCmd = value;
|
||
}
|
||
get
|
||
{
|
||
if (_ReadGridSelectionChangedCmd == null)
|
||
{
|
||
_ReadGridSelectionChangedCmd = new DelegateCommand<object>((Par) => ReadGridSelectionChangedCmdMethod(Par));
|
||
}
|
||
return _ReadGridSelectionChangedCmd;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 读取LIN的选中行执行方法
|
||
/// </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)
|
||
{
|
||
System.Windows.MessageBox.Show("选中LIN配置名称后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
|
||
return;
|
||
}
|
||
if (LinDriveService.ToomossLinDrive.IsCycleRevice)
|
||
{
|
||
System.Windows.MessageBox.Show("正在循环接受中,此时编辑可能会出现错误,请关闭循环发送后再操作", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
|
||
return;
|
||
}
|
||
|
||
switch (Par)
|
||
{
|
||
case "Add":
|
||
//由右侧的右键LDF目录增加
|
||
|
||
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;
|
||
|
||
}
|
||
|
||
InitLoadLinConfigPro();
|
||
}
|
||
|
||
|
||
|
||
break;
|
||
case "Delete":
|
||
if (SelectedReadCanLinRWConfigDto != null)
|
||
{
|
||
//直接删除掉
|
||
FreeSql.Delete<CanLinRWConfig>(SelectedReadCanLinRWConfigDto.Id).ExecuteAffrows();
|
||
ListReadCanLinRWConfigDto.Remove(SelectedReadCanLinRWConfigDto);
|
||
|
||
SelectedReadCanLinRWConfigDto = null;
|
||
|
||
InitLoadLinConfigPro();
|
||
}
|
||
else
|
||
{
|
||
System.Windows.MessageBox.Show("请选中后再进行【删除】操作?", "提示", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Hand);
|
||
}
|
||
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
}
|
||
}
|