first edit
This commit is contained in:
183
XLIMS.TPRZ/ViewModels/MainViewModel.cs
Normal file
183
XLIMS.TPRZ/ViewModels/MainViewModel.cs
Normal file
@@ -0,0 +1,183 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text;
|
||||
using System.Windows.Input;
|
||||
using XLIMS.CONTRACT;
|
||||
using XLIMS.DATA.Models;
|
||||
using XLIMS.MVVM.Base;
|
||||
using XLIMS.TPRZ.Views;
|
||||
|
||||
namespace XLIMS.TPRZ.ViewModels
|
||||
{
|
||||
public class MainViewModel : ViewModelBase,IActivityViewModel
|
||||
{
|
||||
#region Constructor
|
||||
public MainViewModel(ILimsService limsService, IDialogService dialogService)
|
||||
{
|
||||
_limsService = limsService;
|
||||
_dialogService = dialogService;
|
||||
_limsService.Spois.SetChanged += OnSpoisChanged;
|
||||
_limsService.Tips.SetChanged += OnTipsChanged;
|
||||
_limsService.Tprzs.SetChanged += OnTprzsChanged;
|
||||
LoadSpoiAsync();
|
||||
}
|
||||
#endregion //Constructor
|
||||
|
||||
#region Events
|
||||
private async void OnSpoisChanged()
|
||||
{
|
||||
await LoadSpoiAsync();
|
||||
}
|
||||
private async void OnTipsChanged()
|
||||
{
|
||||
await LoadTipAsync();
|
||||
}
|
||||
private async void OnTprzsChanged()
|
||||
{
|
||||
await LoadTprzAsync();
|
||||
}
|
||||
#endregion //Events
|
||||
|
||||
#region Fields
|
||||
private readonly IDialogService _dialogService;
|
||||
private readonly ILimsService _limsService;
|
||||
private bool _isLoading;
|
||||
private TipViewModel _currentTip;
|
||||
private TprzViewModel _currentTprz;
|
||||
private Spoi _currentSpoi;
|
||||
#endregion //Fields
|
||||
|
||||
#region Properties
|
||||
public string Title => "ТПРМ";
|
||||
|
||||
public object View => new MainView();
|
||||
public ObservableCollection<Spoi> AllSpois { get; set; } = new();
|
||||
public ObservableCollection<TipViewModel> AllTips { get; set; } = new();
|
||||
public ObservableCollection<TprzViewModel> AllTprzs { get; set; } = new();
|
||||
public Spoi CurrentSpoi
|
||||
{
|
||||
get => _currentSpoi;
|
||||
set
|
||||
{
|
||||
_currentSpoi = value;
|
||||
if (_currentSpoi != null) LoadTipAsync();
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
public TipViewModel CurrentTip
|
||||
{
|
||||
get => _currentTip;
|
||||
set
|
||||
{
|
||||
_currentTip = value;
|
||||
if (_currentTip != null) LoadTprzAsync();
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
public TprzViewModel CurrentTprz
|
||||
{
|
||||
get => _currentTprz;
|
||||
set { _currentTprz = value; OnPropertyChanged(); }
|
||||
}
|
||||
public bool IsLoading
|
||||
{
|
||||
get => _isLoading;
|
||||
set { _isLoading = value; OnPropertyChanged(); }
|
||||
}
|
||||
#endregion //Properties
|
||||
|
||||
#region Methods
|
||||
public async Task LoadSpoiAsync()
|
||||
{
|
||||
IsLoading = true;
|
||||
|
||||
try
|
||||
{
|
||||
// Параллельная загрузка данных из разных доменов через подсервисы
|
||||
var spoisTask = await _limsService.Spois.GetAllAsync();
|
||||
|
||||
AllSpois = new ObservableCollection<Spoi>(spoisTask);
|
||||
OnPropertyChanged(nameof(AllSpois));
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsLoading = false;
|
||||
}
|
||||
}
|
||||
public async Task LoadTipAsync()
|
||||
{
|
||||
IsLoading = true;
|
||||
|
||||
try
|
||||
{
|
||||
// Параллельная загрузка данных из разных доменов через подсервисы
|
||||
var tipsTask = await _limsService.Tips.GetAllAsync();
|
||||
|
||||
AllTips = new ObservableCollection<TipViewModel>(tipsTask.Where(e=>e.Idspoi==CurrentSpoi.Id).Select(s=>new TipViewModel(_limsService,null,s)));
|
||||
OnPropertyChanged(nameof(AllTips));
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsLoading = false;
|
||||
}
|
||||
}
|
||||
public async Task LoadTprzAsync()
|
||||
{
|
||||
IsLoading = true;
|
||||
|
||||
try
|
||||
{
|
||||
// Параллельная загрузка данных из разных доменов через подсервисы
|
||||
var tprzsTask = await _limsService.Tprzs.GetAllAsync();
|
||||
|
||||
AllTprzs = new ObservableCollection<TprzViewModel>(tprzsTask.Where(e=>e.Idtip==CurrentTip.Id).Select(s => new TprzViewModel(_limsService,0,s)));
|
||||
OnPropertyChanged(nameof(AllTprzs));
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsLoading = false;
|
||||
}
|
||||
}
|
||||
private void AddTip()
|
||||
{
|
||||
_dialogService.ShowDialog(new TipViewModel(_limsService,CurrentSpoi));
|
||||
}
|
||||
private void EditTip()
|
||||
{
|
||||
_dialogService.ShowDialog(CurrentTip);
|
||||
}
|
||||
private async Task DelTipAsync()
|
||||
{
|
||||
await CurrentTip.Remove();
|
||||
AllTips.Remove(CurrentTip);
|
||||
OnPropertyChanged(nameof(AllTips));
|
||||
}
|
||||
private void AddTprz()
|
||||
{
|
||||
_dialogService.ShowDialog(new TprzViewModel(_limsService,CurrentTip.Id));
|
||||
}
|
||||
private void EditTprz()
|
||||
{
|
||||
_dialogService.ShowDialog(CurrentTprz);
|
||||
}
|
||||
private async Task DelTprzAsync()
|
||||
{
|
||||
await CurrentTprz.Remove();
|
||||
AllTprzs.Remove(CurrentTprz);
|
||||
OnPropertyChanged(nameof(AllTprzs));
|
||||
}
|
||||
#endregion //Methods
|
||||
|
||||
#region Commands
|
||||
public ICommand AddTipCommand => new RelayCommand(p => AddTip(),p=>CurrentSpoi!=null);
|
||||
public ICommand EditTipCommand => new RelayCommand(p => EditTip(), p => CurrentTip != null);
|
||||
public ICommand DelTipCommand => new AsyncRelayCommand(DelTipAsync, () => CurrentTip != null);
|
||||
public ICommand AddTprzCommand => new RelayCommand(p => AddTprz(),p=>CurrentTip!=null);
|
||||
public ICommand EditTprzCommand => new RelayCommand(p => EditTprz(), p => CurrentTprz != null);
|
||||
public ICommand DelTprzCommand => new AsyncRelayCommand(DelTprzAsync, () => CurrentTprz != null);
|
||||
|
||||
|
||||
#endregion //Commands
|
||||
}
|
||||
}
|
||||
84
XLIMS.TPRZ/ViewModels/TipViewModel.cs
Normal file
84
XLIMS.TPRZ/ViewModels/TipViewModel.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text;
|
||||
using System.Windows.Input;
|
||||
using XLIMS.CONTRACT;
|
||||
using XLIMS.DATA.Models;
|
||||
using XLIMS.MVVM.Base;
|
||||
|
||||
namespace XLIMS.TPRZ.ViewModels
|
||||
{
|
||||
public class TipViewModel : ViewModelBase
|
||||
{
|
||||
#region Constructor
|
||||
public TipViewModel(ILimsService limsService,Spoi spoi, Tip tip = null)
|
||||
{
|
||||
_limsService = limsService;
|
||||
if (tip != null) _tip = tip;
|
||||
else _tip = new Tip() {IdspoiNavigation=spoi };
|
||||
LoadSpnmtpAsync();
|
||||
}
|
||||
#endregion //Constructor
|
||||
|
||||
#region Events
|
||||
#endregion //Events
|
||||
|
||||
#region Fields
|
||||
private readonly ILimsService _limsService;
|
||||
private readonly Tip _tip;
|
||||
private Spnmtp _currentSpnmtp;
|
||||
#endregion //Fields
|
||||
|
||||
#region Properties
|
||||
public ObservableCollection<Spnmtp> AllSpnmtps { get; set; } = new();
|
||||
public Spnmtp CurrentSpnmtp
|
||||
{
|
||||
get=> _currentSpnmtp;
|
||||
set
|
||||
{
|
||||
_currentSpnmtp = value;
|
||||
if (_currentSpnmtp != null) _tip.IdspnmtpNavigation = _currentSpnmtp;
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
public string? Tp
|
||||
{
|
||||
get => _tip.Tp;
|
||||
set { _tip.Tp = value; OnPropertyChanged(); }
|
||||
}
|
||||
public int Id => _tip.Id;
|
||||
#endregion //Properties
|
||||
|
||||
#region Methods
|
||||
public async Task LoadSpnmtpAsync()
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
// Параллельная загрузка данных из разных доменов через подсервисы
|
||||
var spnmtpsTask = await _limsService.Spnmtps.GetAllAsync();
|
||||
|
||||
AllSpnmtps = new ObservableCollection<Spnmtp>(spnmtpsTask);
|
||||
OnPropertyChanged(nameof(AllSpnmtps));
|
||||
}
|
||||
finally
|
||||
{
|
||||
}
|
||||
}
|
||||
private async Task SaveAsync()
|
||||
{
|
||||
if (_tip.Id == 0) await _limsService.Tips.AddAsync(_tip);
|
||||
else await _limsService.Tips.UpdateAsync(_tip);
|
||||
}
|
||||
public async Task Remove()
|
||||
{
|
||||
await _limsService.Tips.RemoveAsync(_tip);
|
||||
}
|
||||
#endregion //Methods
|
||||
|
||||
#region Commands
|
||||
public ICommand SaveCommand => new AsyncRelayCommand(SaveAsync);
|
||||
#endregion //Commands
|
||||
}
|
||||
}
|
||||
61
XLIMS.TPRZ/ViewModels/TprzViewModel.cs
Normal file
61
XLIMS.TPRZ/ViewModels/TprzViewModel.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text;
|
||||
using System.Windows.Input;
|
||||
using XLIMS.CONTRACT;
|
||||
using XLIMS.DATA.Models;
|
||||
using XLIMS.MVVM.Base;
|
||||
|
||||
namespace XLIMS.TPRZ.ViewModels
|
||||
{
|
||||
public class TprzViewModel : ViewModelBase
|
||||
{
|
||||
#region Constructor
|
||||
public TprzViewModel(ILimsService limsService, int idtip, Tprz tprz = null)
|
||||
{
|
||||
_limsService = limsService;
|
||||
if (tprz != null) _tprz = tprz;
|
||||
else _tprz = new Tprz() { Idtip = idtip };
|
||||
}
|
||||
#endregion //Constructor
|
||||
|
||||
#region Events
|
||||
#endregion //Events
|
||||
|
||||
#region Fields
|
||||
private readonly ILimsService _limsService;
|
||||
private readonly Tprz _tprz;
|
||||
private Spnmtp _currentSpnmtp;
|
||||
#endregion //Fields
|
||||
|
||||
#region Properties
|
||||
public string? Dpzn
|
||||
{
|
||||
get => _tprz.Dpzn;
|
||||
set { _tprz.Dpzn = value; OnPropertyChanged(); }
|
||||
}
|
||||
public string? Hrtc
|
||||
{
|
||||
get => _tprz.Hrtc;
|
||||
set { _tprz.Hrtc = value; OnPropertyChanged(); }
|
||||
}
|
||||
#endregion //Properties
|
||||
|
||||
#region Methods
|
||||
private async Task SaveAsync()
|
||||
{
|
||||
if (_tprz.Id == 0) await _limsService.Tprzs.AddAsync(_tprz);
|
||||
else await _limsService.Tprzs.UpdateAsync(_tprz);
|
||||
}
|
||||
public async Task Remove()
|
||||
{
|
||||
await _limsService.Tprzs.RemoveAsync(_tprz);
|
||||
}
|
||||
#endregion //Methods
|
||||
|
||||
#region Commands
|
||||
public ICommand SaveCommand => new AsyncRelayCommand(SaveAsync);
|
||||
#endregion //Commands
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user