first edit

This commit is contained in:
Курнат Андрей
2026-01-31 16:11:36 +03:00
commit f0e11d6379
148 changed files with 6986 additions and 0 deletions

View File

@@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Windows.Input;
using XLIMS.CONTRACT;
using XLIMS.MVVM.Base;
namespace XLIMS.SP.ViewModels
{
public class DivisionsViewModel : ViewModelBase
{
#region Constructor
public DivisionsViewModel(ILimsService limsService, IDialogService dialogService)
{
_limsService = limsService;
_dialogService = dialogService;
_limsService.Divisions.SetChanged += OnDivisionsChanged;
LoadDataAsync();
}
#endregion //Constructor
#region Events
private async void OnDivisionsChanged()
{
await LoadDataAsync();
}
#endregion //Events
#region Fields
private readonly IDialogService _dialogService;
private readonly ILimsService _limsService;
private bool _isLoading;
private DivisionViewModel _currentDivision;
#endregion //Fields
#region Properties
public ObservableCollection<DivisionViewModel> AllDivisions { get; set; } = new();
public DivisionViewModel CurrentDivision
{
get => _currentDivision;
set { _currentDivision = value; OnPropertyChanged(); }
}
public bool IsLoading
{
get => _isLoading;
set { _isLoading = value; OnPropertyChanged(); }
}
#endregion //Properties
#region Methods
public async Task LoadDataAsync()
{
IsLoading = true;
try
{
// Параллельная загрузка данных из разных доменов через подсервисы
var divisionsTask = await _limsService.Divisions.GetAllAsync();
AllDivisions = new ObservableCollection<DivisionViewModel>(divisionsTask.Select(s => new DivisionViewModel(_limsService, s)));
OnPropertyChanged(nameof(AllDivisions));
}
finally
{
IsLoading = false;
}
}
private void Add()
{
_dialogService.ShowDialog(new DivisionViewModel(_limsService));
}
private void Edit()
{
_dialogService.ShowDialog(CurrentDivision);
}
private async Task DelAsync()
{
await CurrentDivision.Remove();
AllDivisions.Remove(CurrentDivision);
OnPropertyChanged(nameof(AllDivisions));
}
#endregion //Methods
#region Commands
public ICommand AddCommand => new RelayCommand(p => Add());
public ICommand EditCommand => new RelayCommand(p => Edit(), p => CurrentDivision != null);
public ICommand DelCommand => new AsyncRelayCommand(DelAsync, () => CurrentDivision != null);
#endregion //Commands
}
}