159 lines
5.3 KiB
C#
159 lines
5.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Text;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using XLIMS.CONTRACT;
|
|
using XLIMS.DATA.Models;
|
|
using XLIMS.MVVM.Base;
|
|
using XLIMS.PSV.Views;
|
|
|
|
namespace XLIMS.PSV.ViewModels
|
|
{
|
|
public class MainViewModel : ViewModelBase,IActivityViewModel
|
|
{
|
|
#region Constructor
|
|
public MainViewModel(ILimsService limsService, IDialogService dialogService)
|
|
{
|
|
_limsService = limsService;
|
|
_dialogService = dialogService;
|
|
LoadSide();
|
|
_limsService.Datas.SetChanged += Datas_SetChanged;
|
|
}
|
|
|
|
private void Datas_SetChanged()
|
|
{
|
|
|
|
}
|
|
#endregion //Constructor
|
|
|
|
#region Events
|
|
#endregion //Events
|
|
|
|
#region Fields
|
|
private readonly ILimsService _limsService;
|
|
private readonly IDialogService _dialogService;
|
|
private SideItemViewModel _currentSideItem;
|
|
private DocumentSet _currentPsv;
|
|
private IGrouping<string,DataSet> _currentGroupPov;
|
|
private DataSet _currentPov;
|
|
#endregion //Fields
|
|
|
|
#region Properties
|
|
public ObservableCollection<SideItemViewModel> SideItems { get; set; } = new();
|
|
public SideItemViewModel CurrentSideItem
|
|
{
|
|
get => _currentSideItem;
|
|
set
|
|
{
|
|
_currentSideItem = value;
|
|
if (_currentSideItem != null) { LoadPsvAsync(_currentSideItem.Index); }
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
public ObservableCollection<DocumentSet> AllPsvs { get; set; } = new();
|
|
public DocumentSet CurrentPsv
|
|
{
|
|
get => _currentPsv;
|
|
set
|
|
{
|
|
_currentPsv = value;
|
|
if (_currentPsv != null) { LoadDataAsync(_currentPsv); }
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
public ObservableCollection<IGrouping<string,DataSet>> GroupedPovs { get; set; }
|
|
public IGrouping<string, DataSet> CurrentGroupPov
|
|
{
|
|
get => _currentGroupPov;
|
|
set { _currentGroupPov = value; OnPropertyChanged(); }
|
|
}
|
|
public DataSet CurrentPov
|
|
{
|
|
get => _currentPov;
|
|
set { _currentPov = value; OnPropertyChanged(); }
|
|
}
|
|
public string Title => "ПСВ";
|
|
public object View => new MainView();
|
|
|
|
|
|
#endregion //Properties
|
|
|
|
#region Methods
|
|
public void LoadSide()
|
|
{
|
|
var side=new List<SideItemViewModel>();
|
|
side.Add(new SideItemViewModel(1,"Срочные"));
|
|
side.Add(new SideItemViewModel(2,"Открытые"));
|
|
side.Add(new SideItemViewModel(3,"Архив"));
|
|
SideItems = new ObservableCollection<SideItemViewModel>(side);
|
|
OnPropertyChanged(nameof(SideItems));
|
|
}
|
|
public async Task LoadPsvAsync(int index)
|
|
{
|
|
try
|
|
{
|
|
var psvsTask = await _limsService.Documents.GetAllAsync();
|
|
if (index == 1)
|
|
{
|
|
AllPsvs = new ObservableCollection<DocumentSet>(psvsTask.Where(e => e.Name == "ПСВ" && (DateTime.Today - e.DocDate).Value.TotalDays > 15));
|
|
}
|
|
if (index == 2)
|
|
{
|
|
AllPsvs = new ObservableCollection<DocumentSet>(psvsTask.Where(e => e.Name == "ПСВ"));
|
|
}
|
|
if (index == 3)
|
|
{
|
|
|
|
AllPsvs = new ObservableCollection<DocumentSet>(psvsTask.Where(e => e.Name == "ПСВ" && e.Status == "close"));
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
OnPropertyChanged(nameof(AllPsvs));
|
|
}
|
|
}
|
|
public async Task LoadDataAsync(DocumentSet psv)
|
|
{
|
|
try
|
|
{
|
|
var povsTask = await Task.Run<IEnumerable<DataSet>>(()=>psv.DataSetDocuments.ToList());
|
|
GroupedPovs = new ObservableCollection<IGrouping<string, DataSet>>(povsTask.GroupBy(e => e.Device.Dpzn + e.Device.Hrtc + e.Device.Gsrs));
|
|
}
|
|
finally
|
|
{
|
|
OnPropertyChanged(nameof(GroupedPovs));
|
|
}
|
|
}
|
|
private void AddPsv()
|
|
{
|
|
_dialogService.ShowDialog(new PsvViewModel(_limsService, _dialogService));
|
|
}
|
|
private void EditPsv()
|
|
{
|
|
_dialogService.ShowDialog(new PsvViewModel(_limsService, _dialogService,CurrentPsv));
|
|
}
|
|
private async Task DelPsvAsync()
|
|
{
|
|
await _limsService.Documents.RemoveAsync(CurrentPsv);
|
|
AllPsvs.Remove(CurrentPsv);
|
|
}
|
|
private void GoodPov() { }
|
|
private void BadPov()
|
|
{
|
|
_dialogService.ShowDialog(new BadViewModel(_limsService,CurrentPov));
|
|
}
|
|
#endregion //Methods
|
|
|
|
#region Commands
|
|
public ICommand AddPsvCommand => new RelayCommand(p => AddPsv());
|
|
public ICommand EditPsvCommand => new RelayCommand(p => EditPsv(),p=>CurrentPsv!=null);
|
|
public ICommand BadCommand => new RelayCommand(p => BadPov());
|
|
public ICommand DelPsvCommand => new AsyncRelayCommand(DelPsvAsync,()=>CurrentPsv!=null);
|
|
|
|
#endregion //Commands
|
|
}
|
|
}
|