完成从Excel导入变量的对话框
This commit is contained in:
@@ -22,6 +22,7 @@ using Microsoft.Extensions.Hosting;
|
||||
using DMS.WPF.Helper;
|
||||
using DMS.WPF.Services;
|
||||
using DMS.WPF.Services.Processors;
|
||||
using DMS.WPF.ViewModels.Dialogs;
|
||||
using DataProcessingService = DMS.Services.DataProcessingService;
|
||||
using IDataProcessingService = DMS.Services.IDataProcessingService;
|
||||
using LogLevel = Microsoft.Extensions.Logging.LogLevel;
|
||||
@@ -179,6 +180,8 @@ public partial class App : System.Windows.Application
|
||||
//services.AddScoped<MqttServerDetailViewModel>();
|
||||
services.AddSingleton<DeviceDetailViewModel>();
|
||||
services.AddSingleton<MqttsViewModel>();
|
||||
// 注册对话框模型
|
||||
services.AddTransient<ImportExcelDialogViewModel>();
|
||||
// 注册对话框
|
||||
services.AddSingleton<DevicesView>();
|
||||
//注册View视图
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System.Collections;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using AutoMapper;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
@@ -11,7 +13,6 @@ namespace DMS.WPF.ViewModels.Dialogs;
|
||||
|
||||
public partial class ImportExcelDialogViewModel : DialogViewModelBase<List<Variable>>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IExcelService _excelService;
|
||||
|
||||
[ObservableProperty]
|
||||
@@ -20,11 +21,11 @@ public partial class ImportExcelDialogViewModel : DialogViewModelBase<List<Varia
|
||||
[ObservableProperty]
|
||||
private List<Variable> _variables = new();
|
||||
|
||||
[ObservableProperty]
|
||||
private IList _selectedVariables = new ArrayList();
|
||||
|
||||
|
||||
public ImportExcelDialogViewModel(IMapper mapper,IExcelService excelService)
|
||||
public ImportExcelDialogViewModel(IExcelService excelService)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_excelService = excelService;
|
||||
}
|
||||
|
||||
@@ -44,17 +45,20 @@ public partial class ImportExcelDialogViewModel : DialogViewModelBase<List<Varia
|
||||
NotificationHelper.ShowError($"从Excel文件中读取变量时发生了错误:{ex.Message}",ex);
|
||||
}
|
||||
}
|
||||
[RelayCommand]
|
||||
public void SecondaryButton()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void PrimaryButton()
|
||||
private void ImportAll()
|
||||
{
|
||||
Close(Variables);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void ImportSelected()
|
||||
{
|
||||
var selected = SelectedVariables.Cast<Variable>().ToList();
|
||||
Close(selected);
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void CancleButton()
|
||||
{
|
||||
|
||||
@@ -10,6 +10,7 @@ using DMS.WPF.ViewModels.Items;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Data;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace DMS.WPF.ViewModels;
|
||||
|
||||
@@ -17,7 +18,6 @@ namespace DMS.WPF.ViewModels;
|
||||
partial class VariableTableViewModel : ViewModelBase, INavigatable
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IExcelService _excelService;
|
||||
|
||||
/// <summary>
|
||||
/// 对话服务接口,用于显示各种对话框(如确认、编辑、导入等)。
|
||||
@@ -91,10 +91,9 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
|
||||
/// <param name="dialogService">对话服务接口的实例。</param>
|
||||
private readonly DataServices _dataServices;
|
||||
|
||||
public VariableTableViewModel(IMapper mapper, IExcelService excelService, IDialogService dialogService, DataServices dataServices)
|
||||
public VariableTableViewModel(IMapper mapper, IDialogService dialogService, DataServices dataServices)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_excelService = excelService;
|
||||
_dialogService = dialogService;
|
||||
_dataServices = dataServices;
|
||||
IsLoadCompletion = false; // 初始设置为 false,表示未完成加载
|
||||
@@ -295,10 +294,10 @@ partial class VariableTableViewModel : ViewModelBase, INavigatable
|
||||
[RelayCommand]
|
||||
private async void ImprotFromTiaVarTable()
|
||||
{
|
||||
ImportExcelDialogViewModel viewModel = new ImportExcelDialogViewModel(_mapper, _excelService);
|
||||
|
||||
ImportExcelDialogViewModel viewModel = App.Current.Services.GetRequiredService<ImportExcelDialogViewModel>();
|
||||
List<Variable> improtVariable = await _dialogService.ShowDialogAsync(viewModel);
|
||||
if (improtVariable == null) return;
|
||||
|
||||
if (improtVariable == null || improtVariable.Count==0) return;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
|
||||
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||
xmlns:vmd="clr-namespace:DMS.WPF.ViewModels.Dialogs"
|
||||
xmlns:helper="clr-namespace:DMS.WPF.Helper"
|
||||
Title="从Excel导入"
|
||||
CloseButtonText="取消"
|
||||
DefaultButton="Primary"
|
||||
PrimaryButtonText="导入全部"
|
||||
SecondaryButtonText="导入选择"
|
||||
|
||||
d:DataContext="{d:DesignInstance vmd:ImportExcelDialogViewModel}"
|
||||
mc:Ignorable="d"
|
||||
AllowDrop="True"
|
||||
@@ -20,10 +20,10 @@
|
||||
|
||||
<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="PrimaryButtonClick">
|
||||
<i:InvokeCommandAction Command="{Binding PrimaryButtonCommand}" />
|
||||
<i:InvokeCommandAction Command="{Binding ImportAllCommand}" />
|
||||
</i:EventTrigger>
|
||||
<i:EventTrigger EventName="SecondaryButtonClick">
|
||||
<i:InvokeCommandAction Command="{Binding SecondaryButtonCommand}" />
|
||||
<i:InvokeCommandAction Command="{Binding ImportSelectedCommand}" />
|
||||
</i:EventTrigger>
|
||||
<i:EventTrigger EventName="CloseButtonClick">
|
||||
<i:InvokeCommandAction Command="{Binding CancleButtonCommand}" />
|
||||
@@ -59,6 +59,9 @@
|
||||
ItemsSource="{Binding Variables}"
|
||||
AutoGenerateColumns="False"
|
||||
CanUserAddRows="False">
|
||||
<i:Interaction.Behaviors>
|
||||
<helper:SelectedItemsBehavior SelectedItems="{Binding SelectedVariables}" />
|
||||
</i:Interaction.Behaviors>
|
||||
<DataGrid.Style>
|
||||
<Style BasedOn="{StaticResource {x:Type DataGrid}}"
|
||||
TargetType="DataGrid">
|
||||
@@ -75,7 +78,7 @@
|
||||
<DataGridTextColumn Header="名称"
|
||||
Binding="{Binding Name}" />
|
||||
<DataGridTextColumn Header="数据类型"
|
||||
Binding="{Binding SignalType}" />
|
||||
Binding="{Binding CSharpDataType}" />
|
||||
<DataGridTextColumn Header="S7地址"
|
||||
Binding="{Binding S7Address}" />
|
||||
</DataGrid.Columns>
|
||||
|
||||
Reference in New Issue
Block a user