修改了一些内容
This commit is contained in:
@@ -6,7 +6,6 @@ using DMS.Core.Enums;
|
||||
using DMS.Core.Interfaces;
|
||||
using DMS.Core.Interfaces.Repositories;
|
||||
using DMS.Helper;
|
||||
using DMS.Services;
|
||||
using DMS.Services.Processors;
|
||||
using DMS.WPF.ViewModels;
|
||||
using DMS.WPF.Views;
|
||||
@@ -18,10 +17,12 @@ using DMS.Extensions;
|
||||
using DMS.Infrastructure.Configurations;
|
||||
using DMS.Infrastructure.Data;
|
||||
using DMS.Infrastructure.Repositories;
|
||||
using DMS.Infrastructure.Services;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using DMS.WPF.Helper;
|
||||
using DMS.WPF.Services;
|
||||
using DMS.WPF.Services.Processors;
|
||||
using DataProcessingService = DMS.Services.DataProcessingService;
|
||||
using IDataProcessingService = DMS.Services.IDataProcessingService;
|
||||
using LogLevel = Microsoft.Extensions.Logging.LogLevel;
|
||||
|
||||
@@ -153,6 +154,7 @@ public partial class App : System.Windows.Application
|
||||
|
||||
services.AddSingleton<IInitializeRepository, InitializeRepository>();
|
||||
services.AddSingleton<IRepositoryManager, RepositoryManager>();
|
||||
services.AddSingleton<IExcelService, ExcelService>();
|
||||
|
||||
|
||||
// 注册App服务
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using AutoMapper;
|
||||
using DMS.Application.DTOs;
|
||||
using DMS.Core.Models;
|
||||
using DMS.WPF.ViewModels.Items;
|
||||
|
||||
namespace DMS.WPF.Profiles
|
||||
@@ -10,6 +11,8 @@ namespace DMS.WPF.Profiles
|
||||
{
|
||||
CreateMap<DeviceDto, DeviceItemViewModel>()
|
||||
.ReverseMap();
|
||||
CreateMap<Variable, VariableItemViewModel>()
|
||||
.ReverseMap();
|
||||
|
||||
CreateMap<MenuBeanDto, MenuItemViewModel>()
|
||||
.ForMember(dest => dest.Children, opt => opt.Ignore())
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace DMS.WPF.Services
|
||||
{ typeof(DeviceDialogViewModel), typeof(DeviceDialog) },
|
||||
{ typeof(ConfrimDialogViewModel), typeof(ConfirmDialog) },
|
||||
{ typeof(VariableTableDialogViewModel), typeof(VariableTableDialog) },
|
||||
{ typeof(ImportExcelDialogViewModel), typeof(ImportExcelDialog) },
|
||||
// { typeof(MqttDialogViewModel), typeof(MqttDialog) }, // Add other mappings here
|
||||
// ... other dialogs
|
||||
};
|
||||
|
||||
@@ -1,31 +1,63 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using AutoMapper;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using DMS.Core.Interfaces;
|
||||
using DMS.Core.Models;
|
||||
using DMS.Helper;
|
||||
using DMS.WPF.ViewModels.Items;
|
||||
|
||||
namespace DMS.WPF.ViewModels.Dialogs;
|
||||
|
||||
public partial class ImportExcelDialogViewModel : ObservableObject
|
||||
public partial class ImportExcelDialogViewModel : DialogViewModelBase<List<Variable>>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IExcelService _excelService;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? _filePath;
|
||||
|
||||
[ObservableProperty]
|
||||
private ObservableCollection<DMS.Core.Models.Variable> _variables = new();
|
||||
private List<Variable> _variables = new();
|
||||
|
||||
|
||||
|
||||
public ImportExcelDialogViewModel(IMapper mapper,IExcelService excelService)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_excelService = excelService;
|
||||
}
|
||||
|
||||
partial void OnFilePathChanged(string? value)
|
||||
{
|
||||
// if (string.IsNullOrEmpty(value))
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// try
|
||||
// {
|
||||
// var data = ExcelHelper.ImprotFromTiaVariableTable(value);
|
||||
// Variables = new ObservableCollection<DMS.Core.Models.Variable>(data);
|
||||
// }
|
||||
// catch (System.Exception ex)
|
||||
// {
|
||||
// // Handle exception
|
||||
// }
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Variables = _excelService.ImprotFromTiaVariableTable(value);
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
NotificationHelper.ShowError($"从Excel文件中读取变量时发生了错误:{ex.Message}",ex);
|
||||
}
|
||||
}
|
||||
[RelayCommand]
|
||||
public void SecondaryButton()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void PrimaryButton()
|
||||
{
|
||||
Close(Variables);
|
||||
}
|
||||
[RelayCommand]
|
||||
private void CancleButton()
|
||||
{
|
||||
Close(null);
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,23 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using AutoMapper;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using DMS.Core.Enums;
|
||||
using DMS.Core.Interfaces;
|
||||
using DMS.Core.Models;
|
||||
using DMS.Helper;
|
||||
using DMS.Services;
|
||||
using iNKORE.UI.WPF.Modern.Controls;
|
||||
using Newtonsoft.Json;
|
||||
using DMS.Extensions;
|
||||
using DMS.WPF.Services;
|
||||
using DMS.WPF.ViewModels.Dialogs;
|
||||
using DMS.WPF.ViewModels.Items;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace DMS.WPF.ViewModels;
|
||||
|
||||
|
||||
partial class VariableTableViewModel : ViewModelBase,INavigatable
|
||||
partial class VariableTableViewModel : ViewModelBase, INavigatable
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IExcelService _excelService;
|
||||
|
||||
/// <summary>
|
||||
/// 对话服务接口,用于显示各种对话框(如确认、编辑、导入等)。
|
||||
@@ -93,9 +91,10 @@ partial class VariableTableViewModel : ViewModelBase,INavigatable
|
||||
/// <param name="dialogService">对话服务接口的实例。</param>
|
||||
private readonly DataServices _dataServices;
|
||||
|
||||
public VariableTableViewModel(IMapper mapper, IDialogService dialogService, DataServices dataServices)
|
||||
public VariableTableViewModel(IMapper mapper, IExcelService excelService, IDialogService dialogService, DataServices dataServices)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_excelService = excelService;
|
||||
_dialogService = dialogService;
|
||||
_dataServices = dataServices;
|
||||
IsLoadCompletion = false; // 初始设置为 false,表示未完成加载
|
||||
@@ -296,6 +295,13 @@ partial class VariableTableViewModel : ViewModelBase,INavigatable
|
||||
[RelayCommand]
|
||||
private async void ImprotFromTiaVarTable()
|
||||
{
|
||||
ImportExcelDialogViewModel viewModel = new ImportExcelDialogViewModel(_mapper, _excelService);
|
||||
|
||||
List<Variable> improtVariable = await _dialogService.ShowDialogAsync(viewModel);
|
||||
if (improtVariable == null) return;
|
||||
|
||||
|
||||
|
||||
// ContentDialog processingDialog = null; // 用于显示处理中的对话框
|
||||
// try
|
||||
// {
|
||||
@@ -887,10 +893,20 @@ partial class VariableTableViewModel : ViewModelBase,INavigatable
|
||||
public async Task OnNavigatedToAsync(MenuItemViewModel menu)
|
||||
{
|
||||
var varTable = _dataServices.VariableTables.FirstOrDefault(v => v.Id == menu.TargetId);
|
||||
if (varTable!=null)
|
||||
if (varTable != null)
|
||||
{
|
||||
CurrentVariableTable=varTable;
|
||||
CurrentVariableTable = varTable;
|
||||
|
||||
if (CurrentVariableTable.Protocol == ProtocolType.S7)
|
||||
{
|
||||
IsS7ProtocolSelected = true;
|
||||
}
|
||||
else if (CurrentVariableTable.Protocol == ProtocolType.OpcUa)
|
||||
{
|
||||
IsOpcUaProtocolSelected = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -4,17 +4,32 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
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"
|
||||
Title="从Excel导入"
|
||||
CloseButtonText="取消"
|
||||
DefaultButton="Primary"
|
||||
PrimaryButtonText="导入"
|
||||
PrimaryButtonText="导入全部"
|
||||
SecondaryButtonText="导入选择"
|
||||
|
||||
d:DataContext="{d:DesignInstance vmd:ImportExcelDialogViewModel}"
|
||||
mc:Ignorable="d"
|
||||
AllowDrop="True"
|
||||
DragEnter="Dialog_DragEnter"
|
||||
Drop="Dialog_Drop">
|
||||
|
||||
<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="PrimaryButtonClick">
|
||||
<i:InvokeCommandAction Command="{Binding PrimaryButtonCommand}" />
|
||||
</i:EventTrigger>
|
||||
<i:EventTrigger EventName="SecondaryButtonClick">
|
||||
<i:InvokeCommandAction Command="{Binding SecondaryButtonCommand}" />
|
||||
</i:EventTrigger>
|
||||
<i:EventTrigger EventName="CloseButtonClick">
|
||||
<i:InvokeCommandAction Command="{Binding CancleButtonCommand}" />
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>
|
||||
|
||||
<Grid Margin="10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
|
||||
@@ -8,10 +8,9 @@ namespace DMS.WPF.Views.Dialogs;
|
||||
|
||||
public partial class ImportExcelDialog : ContentDialog
|
||||
{
|
||||
public ImportExcelDialog(ImportExcelDialogViewModel viewModel)
|
||||
public ImportExcelDialog()
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = viewModel;
|
||||
}
|
||||
|
||||
private void Dialog_DragEnter(object sender, DragEventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user