将设备列表,变量表列表,变量列表从ObservableCollection更换为字典类型的ObservableDictionary
This commit is contained in:
@@ -159,8 +159,7 @@ public partial class DeviceDetailViewModel : ViewModelBase, INavigatable
|
||||
|
||||
public async Task OnNavigatedToAsync(MenuItemViewModel menu)
|
||||
{
|
||||
var device = _dataStorageService.Devices.FirstOrDefault(d => d.Id == menu.TargetId);
|
||||
if (device != null)
|
||||
if (_dataStorageService.Devices.TryGetValue(menu.TargetId,out var device))
|
||||
{
|
||||
CurrentDevice = device;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ using DMS.WPF.Services;
|
||||
using DMS.WPF.ViewModels.Dialogs;
|
||||
using DMS.WPF.ViewModels.Items;
|
||||
using iNKORE.UI.WPF.Modern.Common.IconKeys;
|
||||
using ObservableCollections;
|
||||
|
||||
namespace DMS.WPF.ViewModels;
|
||||
|
||||
@@ -31,7 +32,7 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable
|
||||
/// 设备列表。
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<DeviceItemViewModel> _devices;
|
||||
private INotifyCollectionChangedSynchronizedViewList<DeviceItemViewModel> _devices;
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -52,7 +53,7 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable
|
||||
/// <param name="wpfDataService">主数据服务。</param>
|
||||
/// <param name="deviceAppService">设备应用服务。</param>
|
||||
/// <param name="notificationService">通知服务。</param>
|
||||
public DevicesViewModel(IMapper mapper,IDataStorageService dataStorageService,
|
||||
public DevicesViewModel(IMapper mapper, IDataStorageService dataStorageService,
|
||||
IDialogService dialogService, INavigationService navigationService,
|
||||
IWPFDataService wpfDataService, IDeviceAppService deviceAppService,
|
||||
INotificationService notificationService)
|
||||
@@ -64,7 +65,7 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable
|
||||
_wpfDataService = wpfDataService;
|
||||
_deviceAppService = deviceAppService;
|
||||
_notificationService = notificationService;
|
||||
Devices = _dataStorageService.Devices;
|
||||
Devices = _dataStorageService.Devices.ToNotifyCollectionChanged(x => x.Value);
|
||||
}
|
||||
|
||||
|
||||
@@ -131,7 +132,7 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable
|
||||
if (_wpfDataService != null && _wpfDataService.DeviceDataService != null)
|
||||
{
|
||||
var addDto = await _wpfDataService.DeviceDataService.AddDevice(dto);
|
||||
|
||||
|
||||
// 添加null检查
|
||||
if (addDto != null && addDto.Device != null && _notificationService != null)
|
||||
{
|
||||
@@ -239,15 +240,12 @@ public partial class DevicesViewModel : ViewModelBase, INavigatable
|
||||
|
||||
public async Task OnNavigatedToAsync(MenuItemViewModel menu)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void OnDeviceIsActiveChanged(object? sender, bool isActive)
|
||||
{
|
||||
if (sender is DeviceItemViewModel deviceItemViewModel)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,7 +83,7 @@ public partial class VariableDialogViewModel : DialogViewModelBase<VariableItemV
|
||||
return false;
|
||||
}
|
||||
//检查变量是否存在
|
||||
var existVariables = _dataStorageService.Variables.Where(v => v.Name == Variable.Name || (v.Protocol == ProtocolType.S7 && v.S7Address == Variable.S7Address) || (v.Protocol == ProtocolType.OpcUa && v.OpcUaNodeId == Variable.OpcUaNodeId)).ToList();
|
||||
var existVariables = _dataStorageService.Variables.Where(v => v.Value.Name == Variable.Name || (v.Value.Protocol == ProtocolType.S7 && v.Value.S7Address == Variable.S7Address) || (v.Value.Protocol == ProtocolType.OpcUa && v.Value.OpcUaNodeId == Variable.OpcUaNodeId)).Select(v=>v.Value).ToList();
|
||||
VariableItemViewModel existVariable = null;
|
||||
if (IsAddModel)
|
||||
{
|
||||
@@ -92,6 +92,7 @@ public partial class VariableDialogViewModel : DialogViewModelBase<VariableItemV
|
||||
else
|
||||
{
|
||||
existVariable = existVariables.FirstOrDefault(v => v.Id != Variable.Id);
|
||||
|
||||
}
|
||||
|
||||
if (existVariable != null)
|
||||
|
||||
@@ -138,20 +138,20 @@ partial class VariableHistoryViewModel : ViewModelBase, INavigatable
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(SearchText))
|
||||
{
|
||||
// 根据搜索文本过滤建议列表
|
||||
var filteredVariables = _dataStorageService.Variables
|
||||
.Where(v =>
|
||||
v.Name?.Contains(
|
||||
SearchText, StringComparison.OrdinalIgnoreCase) ==
|
||||
true)
|
||||
.Select(v => v.Name)
|
||||
.Take(10)
|
||||
.ToList();
|
||||
|
||||
foreach (var variable in filteredVariables)
|
||||
{
|
||||
_suggestedVariables.Add(variable);
|
||||
}
|
||||
// // 根据搜索文本过滤建议列表
|
||||
// var filteredVariables = _dataStorageService.Variables
|
||||
// .Where(v =>
|
||||
// v.Name?.Contains(
|
||||
// SearchText, StringComparison.OrdinalIgnoreCase) ==
|
||||
// true)
|
||||
// .Select(v => v.Name)
|
||||
// .Take(10)
|
||||
// .ToList();
|
||||
//
|
||||
// foreach (var variable in filteredVariables)
|
||||
// {
|
||||
// _suggestedVariables.Add(variable);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -806,9 +806,7 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
|
||||
|
||||
public async Task OnNavigatedToAsync(MenuItemViewModel menu)
|
||||
{
|
||||
var varTable =_dataStorageService.VariableTables.FirstOrDefault(v => v.Id == menu.TargetId);
|
||||
|
||||
if (varTable != null)
|
||||
if (_dataStorageService.VariableTables.TryGetValue(menu.TargetId,out var varTable))
|
||||
{
|
||||
CurrentVariableTable = varTable;
|
||||
// 根据变量表的协议类型设置对应的布尔属性
|
||||
|
||||
Reference in New Issue
Block a user