Files
DMS/DMS.WPF/ViewModels/Dialogs/ImportExcelDialogViewModel.cs

68 lines
1.5 KiB
C#
Raw Normal View History

2025-08-22 20:46:23 +08:00
using System.Collections;
2025-07-04 13:41:50 +08:00
using System.Collections.ObjectModel;
2025-08-22 20:46:23 +08:00
using System.Linq;
2025-08-22 20:24:09 +08:00
using AutoMapper;
2025-07-04 13:41:50 +08:00
using CommunityToolkit.Mvvm.ComponentModel;
2025-08-22 20:24:09 +08:00
using CommunityToolkit.Mvvm.Input;
using DMS.Core.Interfaces;
using DMS.Core.Models;
using DMS.Helper;
using DMS.WPF.ViewModels.Items;
2025-07-04 13:41:50 +08:00
2025-07-19 11:11:01 +08:00
namespace DMS.WPF.ViewModels.Dialogs;
2025-07-04 13:41:50 +08:00
2025-08-22 20:24:09 +08:00
public partial class ImportExcelDialogViewModel : DialogViewModelBase<List<Variable>>
2025-07-04 13:41:50 +08:00
{
2025-08-22 20:24:09 +08:00
private readonly IExcelService _excelService;
2025-07-04 13:41:50 +08:00
[ObservableProperty]
private string? _filePath;
[ObservableProperty]
2025-08-22 20:24:09 +08:00
private List<Variable> _variables = new();
2025-08-22 20:46:23 +08:00
[ObservableProperty]
private IList _selectedVariables = new ArrayList();
2025-08-22 20:24:09 +08:00
2025-08-22 20:46:23 +08:00
public ImportExcelDialogViewModel(IExcelService excelService)
2025-08-22 20:24:09 +08:00
{
_excelService = excelService;
}
2025-07-04 13:41:50 +08:00
partial void OnFilePathChanged(string? value)
{
2025-08-22 20:24:09 +08:00
if (string.IsNullOrEmpty(value))
{
return;
}
try
{
Variables = _excelService.ImprotFromTiaVariableTable(value);
}
catch (System.Exception ex)
{
NotificationHelper.ShowError($"从Excel文件中读取变量时发生了错误:{ex.Message}",ex);
}
}
2025-08-22 20:46:23 +08:00
2025-08-22 20:24:09 +08:00
[RelayCommand]
2025-08-22 20:46:23 +08:00
private void ImportAll()
2025-08-22 20:24:09 +08:00
{
2025-08-22 20:46:23 +08:00
Close(Variables);
2025-08-22 20:24:09 +08:00
}
2025-08-22 20:46:23 +08:00
2025-08-22 20:24:09 +08:00
[RelayCommand]
2025-08-22 20:46:23 +08:00
private void ImportSelected()
2025-08-22 20:24:09 +08:00
{
2025-08-22 20:46:23 +08:00
var selected = SelectedVariables.Cast<Variable>().ToList();
Close(selected);
2025-08-22 20:24:09 +08:00
}
2025-08-22 20:46:23 +08:00
2025-08-22 20:24:09 +08:00
[RelayCommand]
private void CancleButton()
{
Close(null);
2025-07-04 13:41:50 +08:00
}
2025-08-22 20:46:23 +08:00
}