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,141 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.ComponentModel;
using System.Xml.Linq;
using Microsoft.Win32;
using System.IO;
using XLIMS.MVVM.Base;
using XLIMS.CONTRACT;
using XLIMS.DATA.Models;
namespace XLIMS.PSV.ViewModels
{
public class BadViewModel : ViewModelBase
{
#region Constructor
public BadViewModel(ILimsService limsService, DataSet data)
{
_limsService = limsService;
_currentData = data;
if (_currentData.Gdn == null)
{
_povDoc = new DocumentSet() { Division = _currentData.Device.Division,Name="Извещение" };
_currentData.DocumentPov = _povDoc;
}
else if (_currentData.DocumentPov != null) _povDoc = _currentData.DocumentPov;
LoadDataAsync();
}
#endregion //Constructor
#region Fields
private readonly ILimsService _limsService;
private DataSet _currentData;
private bool _isValid;
private PersonalSet _currentPersonal;
private DocumentSet _povDoc;
private BookSet _currentBook;
#endregion //Fields
#region Properties
public string Title => $"{_currentData.Device.Tip} №{_currentData.Device.Serial} {_currentData.Device.Name}";
public ObservableCollection<PersonalSet> AllPersonals { get; set; }
public ObservableCollection<BookSet> AllBooks { get; set; }
public BookSet CurrentBook
{
get => _currentBook;
set { _currentBook = value; OnPropertyChanged(); }
}
public PersonalSet CurrentPersonal
{
get => _currentPersonal;
set
{
_currentPersonal = value;
if (_currentPersonal != null) { _currentData.Person = _currentPersonal.Person; }
OnPropertyChanged();
}
}
public DateTime? PovDate
{
get => _currentData.Date;
set
{
_currentData.Date = value;
OnPropertyChanged();
}
}
public string Reason
{
get => _currentData.Reason;
set
{
_currentData.Reason = value;
OnPropertyChanged();
}
}
public string Number
{
get => _povDoc.Number;
set
{
_povDoc.Number = value;
OnPropertyChanged();
}
}
public DateTime? DocDate
{
get => _povDoc.DocDate;
set
{
_povDoc.DocDate = value;
OnPropertyChanged();
}
}
private async Task LoadDataAsync()
{
var personalTask = await _limsService.Personals.GetAllAsync();
var bookTask=await _limsService.Books.GetAllAsync();
AllPersonals=new ObservableCollection<PersonalSet>(personalTask);
AllBooks=new ObservableCollection<BookSet>(bookTask);
OnPropertyChanged(nameof(AllPersonals));
OnPropertyChanged(nameof(AllBooks));
}
private async Task SaveAsync()
{
if (_currentData.Gdn == null)
{
_currentData.Gdn = false;
await _limsService.Datas.UpdateAsync(_currentData);
var result = MessageBox.Show("Распечатать извещение?", "Внимание!", MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
try
{
//await Task.Run(() => new Izv(_newDMS, _repository).Print());
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
}
else { await _limsService.Datas.UpdateAsync(_currentData); }
}
#endregion //properties
#region Commands
public ICommand SaveCommand => new AsyncRelayCommand(SaveAsync, () => CurrentPersonal != null && !string.IsNullOrEmpty(Number));
#endregion //Commands
#region IDataErrorInfo
#endregion
}
}

View File

@@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Input;
using XLIMS.CONTRACT;
using XLIMS.DATA.Models;
using XLIMS.MVVM.Base;
namespace XLIMS.PSV.ViewModels
{
public class BrowseSerialViewModel : ViewModelBase, IDisposable
{
private readonly ILimsService _limsService;
private int _divisionId;
private DeviceSet _currentSerial = null;
private string _search = string.Empty;
private CancellationTokenSource? _searchCts = null;
private bool _disposed = false;
public ObservableCollection<DeviceSet> AllSerial { get; } = new();
public ICollectionView SerialView { get; }
public DeviceSet? CurrentSerial
{
get => _currentSerial;
set
{
_currentSerial = value;
OnPropertyChanged();
}
}
public string Search
{
get => _search;
set
{
_search = value;
DebounceSearch();
OnPropertyChanged();
}
}
public BrowseSerialViewModel(ILimsService limsService, int divisionId)
{
_limsService = limsService;
_divisionId = divisionId;
SerialView = CollectionViewSource.GetDefaultView(AllSerial);
SerialView.Filter = SerialFilter;
LoadSerialsAsync();
}
private async Task LoadSerialsAsync()
{
AllSerial.Clear();
var devList = await _limsService.Devices.GetAllAsync();
foreach (var dev in devList.Where(e=>e.DivisionId==_divisionId))
{
AllSerial.Add(dev);
}
SerialView.Refresh();
}
private bool SerialFilter(object item)
{
if (item is not DeviceSet dev) return false;
if (string.IsNullOrWhiteSpace(Search)) return true;
var search = Search.Trim();
return (dev.Serial?.Contains(search, StringComparison.OrdinalIgnoreCase) == true)
|| (dev.Dpzn?.Contains(search, StringComparison.OrdinalIgnoreCase) == true)
|| (dev.Tip?.Contains(search, StringComparison.OrdinalIgnoreCase) == true)
|| (dev.Name?.Contains(search, StringComparison.OrdinalIgnoreCase) == true);
}
private ICommand? _saveCommand = null;
public ICommand SaveCommand => _saveCommand ??= new RelayCommand(_ => Save(), _ => CurrentSerial != null);
private void Save()
{
}
private async void DebounceSearch()
{
_searchCts?.Cancel();
_searchCts = new CancellationTokenSource();
try
{
await Task.Delay(300, _searchCts.Token);
SerialView.Refresh();
}
catch (TaskCanceledException) { }
}
public void Dispose()
{
if (_disposed) return;
_disposed = true;
GC.SuppressFinalize(this);
}
}
}

View File

@@ -0,0 +1,179 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Input;
using System.Runtime.CompilerServices;
using System.Threading;
using XLIMS.MVVM.Base;
using XLIMS.DATA.Models;
using XLIMS.CONTRACT;
namespace XLIMS.PSV.ViewModels
{
public class BrowseTprzViewModel : ViewModelBase, IDataErrorInfo, IDisposable
{
private readonly ILimsService _limsService;
private readonly ObservableCollection<Tprz> _allTprz = new();
private Tprz? _currentTprz = null;
private string _search = string.Empty;
private string _serial = string.Empty;
private bool _isValid;
private CancellationTokenSource? _searchCts;
private CancellationTokenSource? _loadCts;
private string _lastFilter = string.Empty;
public BrowseTprzViewModel(ILimsService limsService)
{
_limsService = limsService;
AllTPRZView = CollectionViewSource.GetDefaultView(_allTprz);
AllTPRZView.Filter = TprzFilter;
LoadTPRZAsync();
}
private async Task LoadTPRZAsync()
{
_loadCts?.Cancel();
_loadCts = new CancellationTokenSource();
try
{
_allTprz.Clear();
var items = await _limsService.Tprzs.GetAllAsync();
foreach (var item in items)
_allTprz.Add(item);
AllTPRZView.Refresh();
}
catch (OperationCanceledException) { }
catch (Exception)
{
// Логирование или отображение ошибки пользователю
}
}
public ICollectionView AllTPRZView { get; }
public Tprz? CurrentTPRZ
{
get => _currentTprz;
set
{
_currentTprz = value;
OnPropertyChanged();
}
}
public string Search
{
get => _search;
set
{
_search = value ?? string.Empty;
DebouncedRefresh();
OnPropertyChanged();
}
}
private async void DebouncedRefresh()
{
_searchCts?.Cancel();
_searchCts = new CancellationTokenSource();
try
{
await Task.Delay(300, _searchCts.Token);
AllTPRZView.Refresh();
}
catch (TaskCanceledException) { }
}
public string Serial
{
get => _serial;
set
{
_serial = value?.Trim() ?? string.Empty;
OnPropertyChanged();
}
}
private bool TprzFilter(object obj)
{
if (obj is not Tprz tprz) return false;
var filter = Search?.Trim() ?? string.Empty;
if (_lastFilter != filter)
_lastFilter = filter;
if (string.IsNullOrWhiteSpace(_lastFilter)) return true;
return (tprz.Dpzn?.Contains(_lastFilter, StringComparison.OrdinalIgnoreCase) == true)
|| (tprz.IdtipNavigation.Tp?.Contains(_lastFilter, StringComparison.OrdinalIgnoreCase) == true)
|| (tprz.IdtipNavigation?.IdspnmtpNavigation?.Nmtp?.Contains(_lastFilter, StringComparison.OrdinalIgnoreCase) == true);
}
private RelayCommand? _saveCommand;
public ICommand SaveCommand => _saveCommand ??= new RelayCommand(_ => Save(), _ => _isValid && CurrentTPRZ != null);
private void Save()
{
}
private new void OnPropertyChanged([CallerMemberName] string propertyName = "")
{
base.OnPropertyChanged(propertyName);
if (propertyName == nameof(Serial) || propertyName == nameof(CurrentTPRZ))
CommandManager.InvalidateRequerySuggested();
}
#region IDataErrorInfo
public string Error => string.Empty;
private void ValidateAll()
{
_isValid = Validate();
CommandManager.InvalidateRequerySuggested();
}
public string this[string columnName]
{
get
{
string msg = string.Empty;
switch (columnName)
{
case nameof(Serial):
if (string.IsNullOrWhiteSpace(Serial))
msg = "Поле не может быть пустым!";
break;
}
ValidateAll();
return msg;
}
}
private bool Validate()
{
// Добавьте комплексную валидацию всех нужных полей
return !string.IsNullOrWhiteSpace(Serial);
}
#endregion
private bool _disposed = false;
public void Dispose()
{
if (_disposed) return;
_disposed = true;
_searchCts?.Dispose();
_loadCts?.Dispose();
}
}
}

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Text;
using XLIMS.MVVM.Base;
namespace XLIMS.PSV.ViewModels
{
public class DocPovViewModel:ViewModelBase
{
#region Constructor
#endregion //Constructor
#region Events
#endregion //Events
#region Fields
#endregion //Fields
#region Properties
#endregion //Properties
#region Methods
#endregion //Methods
#region Commands
#endregion //Commands
}
}

View File

@@ -0,0 +1,192 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Xml.Linq;
using XLIMS.CONTRACT;
using XLIMS.DATA.Models;
using XLIMS.MVVM.Base;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace XLIMS.PSV.ViewModels
{
public class GoodViewModel:ViewModelBase
{
#region Constructor
public GoodViewModel(ILimsService limsService, DataSet data)
{
_limsService = limsService;
_currentData = data;
if (_currentData.Gdn == null) _povDoc = new DocumentSet() { Division = _currentData.Device.Division };
else if (_currentData.DocumentPov != null) _povDoc = _currentData.DocumentPov;
LoadDataAsync();
}
#endregion //Constructor
#region Events
#endregion //Events
#region Fields
private readonly ILimsService _limsService;
private DataSet _currentData;
private PersonalSet _currentPersonal;
private DocumentSet _povDoc;
private BookSet _currentBook;
#endregion //Fields
#region Properties
public string Title => $"{_currentData.Device.Tip} №{_currentData.Device.Serial} {_currentData.Device.Name}";
public ObservableCollection<PersonalSet> AllPersonals { get; set; } = new();
public ObservableCollection<BookSet> AllBooks { get; set; } = new();
public BookSet CurrentBook
{
get => _currentBook;
set { _currentBook = value; OnPropertyChanged(); }
}
public PersonalSet CurrentPersonal
{
get => _currentPersonal;
set
{
_currentPersonal = value;
if (_currentPersonal != null) { _currentData.Person = _currentPersonal.Person; }
OnPropertyChanged();
}
}
public DateTime? PovDate
{
get => _currentData.Date;
set
{
_currentData.Date = value;
OnPropertyChanged();
}
}
public int? Nkl
{
get { return _currentData.Nkl; }
set
{
_currentData.Nkl = value;
OnPropertyChanged();
}
}
public string Number
{
get => _povDoc.Number;
set
{
_povDoc.Number = value;
OnPropertyChanged();
}
}
public DateTime? DocDate
{
get => _povDoc.DocDate;
set
{
_povDoc.DocDate = value;
OnPropertyChanged();
}
}
#endregion //Properties
#region Methods
private async Task LoadDataAsync()
{
var personalTask = await _limsService.Personals.GetAllAsync();
var bookTask = await _limsService.Books.GetAllAsync();
AllPersonals = new ObservableCollection<PersonalSet>(personalTask);
AllBooks = new ObservableCollection<BookSet>(bookTask);
OnPropertyChanged(nameof(PersonalSet));
OnPropertyChanged(nameof(BookSet));
}
private async Task SaveAsync()
{
if (_currentData.Gdn == null)
{
_currentData.Gdn = true;
await _limsService.Datas.AddAsync(_currentData);
}
else { await _limsService.Datas.UpdateAsync(_currentData); }
if (!string.IsNullOrEmpty(Number))
{
await _limsService.Documents.AddAsync(_povDoc);
if (MessageBox.Show("Распечатать свидетельство?", "Внимание!", MessageBoxButton.OKCancel).ToString() == "OK")
{
try
{
// await Task.Run(() => new Svid(_newDMS, _repository).Print());
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
}
}
#endregion //Methods
#region Commands
public ICommand SaveCommand => new AsyncRelayCommand(SaveAsync,() => CurrentPersonal != null);
#endregion //Commands
#region IDEI
//public string Error => string.Join(Environment.NewLine, GetValidationErrors());
//public string this[string columnName]
//{
// get
// {
// string msg = null;
// if (columnName == nameof(NND))
// {
// if (_repository.Dms.Any(a => a.Nnd ==CurrentBook+NND))
// {
// msg = "Документ с таким номером уже есть в базе!";
// }
// }
// if (columnName == "DTMKFK")
// {
// if (DTMKFK < _currentEKZMK.DTPRM)
// {
// msg = "Дата поверки не может быть раньше даты приемки!";
// }
// }
// if (columnName == nameof(Temp))
// {
// if (Temp == 0)
// {
// msg = "Данные о теммпературе не могут быть равны нулю!";
// }
// }
// if (columnName == nameof(Hum))
// {
// if (Hum == 0)
// {
// msg = "Данные о влажности не могут быть равны нулю!";
// }
// }
// if (columnName == nameof(Press))
// {
// if (Press == 0)
// {
// msg = "Данные о давлении не могут быть равны нулю!";
// }
// }
// return msg;
// }
//}
#endregion //IDEI
}
}

View File

@@ -0,0 +1,158 @@
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
}
}

View File

@@ -0,0 +1,239 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Windows;
using System.Windows.Input;
using XLIMS.PSV.Windows;
using XLIMS.DATA.Models;
using XLIMS.MVVM.Base;
using XLIMS.CONTRACT;
namespace XLIMS.PSV.ViewModels
{
public class PsvViewModel : ViewModelBase
{
#region Constructor
public PsvViewModel(ILimsService limsService, IDialogService dialogService, DocumentSet document=null)
{
_limsService = limsService;
_dialogService = dialogService;
if (document != null)
{
_document = document;
}
else
{
_document = new DocumentSet() {Name="ПСВ"};
}
LoadDataAsync();
}
#endregion //Constructor
#region Events
#endregion //Events
#region Fields
private DocumentSet _document;
private readonly ILimsService _limsService;
private readonly IDialogService _dialogService;
private int _devicesCount;
private DivisionSet _currentDivision;
private Tprz _currentTprz;
private DeviceSet _currentDevice;
private IGrouping<string, DataSet> _currentGroupedPov;
private DataSet _currentPov;
private PersonalSet _currentPersonal;
#endregion //Fields
#region Properties
public ObservableCollection<IGrouping<string, DataSet>> GroupedPovs { get; set; } = new();
public int ID => _document.Id;
public ObservableCollection<DivisionSet> AllDivisions { get; set; } = new();
public ObservableCollection<PersonalSet> AllPersonals { get; set; } = new();
public ObservableCollection<DataSet> AllPovs { get; set; } = new();
public DivisionSet CurrentDivision
{
get => _document.Division;
set
{
_document.Division = value;
OnPropertyChanged();
}
}
public PersonalSet CurrentPersonal
{
get
{
return _currentPersonal;
}
set
{
_currentPersonal = value;
if(_currentPersonal!=null) { _document.InPerson = _currentPersonal.Person; }
OnPropertyChanged();
}
}
public IGrouping<string, DataSet> CurrentGroupedPov
{
get => _currentGroupedPov;
set
{
_currentGroupedPov = value; OnPropertyChanged();
}
}
public DataSet CurrentPov
{
get => _currentPov;
set
{
_currentPov = value;
OnPropertyChanged();
}
}
public string? Number
{
get=>_document.Number;
set { _document.Number = value; OnPropertyChanged(); }
}
public DateTime? Date
{
get => _document.DocDate;
set { _document.DocDate = value; OnPropertyChanged(); }
}
#endregion //Properties
#region Methods
private async Task BrowseTprz()
{
var vm = new BrowseTprzViewModel(_limsService);
if (_dialogService.ShowDialog(vm, out _) != true || vm.CurrentTPRZ == null)
return;
var tprz = vm.CurrentTPRZ;
var serial = vm.Serial;
bool ExistsInList() => AllPovs.Any(p =>
p.Device.Serial == serial &&
p.Device.Dpzn == tprz.Dpzn &&
p.Device.Gsrs == tprz.Gsrs &&
p.Device.Hrtc == tprz.Hrtc);
if (ExistsInList())
{
MessageBox.Show("Документ уже содержит выбранный экземпляр!",
"Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
var dataSets = await _limsService.Datas.GetAllAsync();
if (dataSets.Any(d =>
d.Device.Serial == serial &&
d.Device.Dpzn == tprz.Dpzn &&
d.Device.Gsrs == tprz.Gsrs &&
d.Device.Hrtc == tprz.Hrtc &&
d.Device.Division == CurrentDivision &&
d.Gdn == null))
{
MessageBox.Show($"Прибор с номером №{serial} уже находится в поверке!",
"Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
var devices = await _limsService.Devices.GetAllAsync();
var dev = devices.FirstOrDefault(d =>
d.Serial == serial &&
d.Dpzn == tprz.Dpzn &&
d.Gsrs == tprz.Gsrs &&
d.Hrtc == tprz.Hrtc &&
d.Division == CurrentDivision)
?? new DeviceSet
{
Oi = tprz.IdtipNavigation.IdspoiNavigation.Nmoi,
Name = tprz.IdtipNavigation.IdspnmtpNavigation.Nmtp,
Tip = tprz.IdtipNavigation.Tp,
Serial = serial,
Dpzn = tprz.Dpzn,
Hrtc = tprz.Hrtc,
Division = CurrentDivision
};
AllPovs.Add(new DataSet() {Device=dev,Document=_document });
GroupedPovs = new ObservableCollection<IGrouping<string, DataSet>>(AllPovs.GroupBy(e => e.Device.Dpzn + e.Device.Hrtc + e.Device.Gsrs));
CurrentGroupedPov = GroupedPovs.FirstOrDefault();
OnPropertyChanged(nameof(GroupedPovs));
OnPropertyChanged(nameof(CurrentGroupedPov));
}
private async Task BrowseSerial()
{
var vm = new BrowseSerialViewModel(_limsService,CurrentDivision.Id);
if (_dialogService.ShowDialog(vm, out _) != true || vm.CurrentSerial == null)
return;
// Проверка на дублирование в текущем документе
bool alreadyExists = AllPovs.Any(e => e.Device == vm.CurrentSerial);
if (alreadyExists)
{
MessageBox.Show("Документ уже содержит выбранный экземпляр!",
"Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
var dataSets = await _limsService.Datas.GetAllAsync();
if (vm.CurrentSerial.DataSets.Any(d =>d.Gdn == null))
{
MessageBox.Show($"Прибор с номером №{vm.CurrentSerial.Serial} уже находится в поверке!",
"Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
AllPovs.Add(new DataSet() { Device = vm.CurrentSerial, Document = _document });
GroupedPovs = new ObservableCollection<IGrouping<string, DataSet>>(AllPovs.GroupBy(e => e.Device.Dpzn + e.Device.Hrtc + e.Device.Gsrs));
CurrentGroupedPov = GroupedPovs.FirstOrDefault();
OnPropertyChanged(nameof(GroupedPovs));
OnPropertyChanged(nameof(CurrentGroupedPov));
}
private async Task LoadDataAsync()
{
var povsTask = await Task.Run<IEnumerable<DataSet>>(() => _document.DataSetDocuments.ToList());
AllPersonals = new ObservableCollection<PersonalSet>(await _limsService.Personals.GetAllAsync());
AllDivisions = new ObservableCollection<DivisionSet>(await _limsService.Divisions.GetAllAsync());
AllPovs=new ObservableCollection<DataSet>(povsTask);
GroupedPovs = new ObservableCollection<IGrouping<string, DataSet>>(AllPovs.GroupBy(e => e.Device.Dpzn + e.Device.Hrtc + e.Device.Gsrs));
CurrentPersonal = AllPersonals.FirstOrDefault(f => f.Person == _document.InPerson);
OnPropertyChanged(nameof(AllDivisions));
OnPropertyChanged(nameof(AllPersonals));
OnPropertyChanged(nameof(GroupedPovs));
OnPropertyChanged(nameof(CurrentPersonal));
}
private async Task Save()
{
foreach (var pov in AllPovs)
{
if(pov.Id==0) await _limsService.Datas.AddAsync(pov);
else await _limsService.Datas.UpdateAsync(pov);
}
if(_document.Id== 0) {await _limsService.Documents.AddAsync(_document); }
else await _limsService.Documents.UpdateAsync(_document);
}
private async Task DelPov()
{
if(CurrentPov.Id!=0)
{
await _limsService.Datas.RemoveAsync(CurrentPov);
AllPovs.Remove(CurrentPov);
}
}
#endregion //Methods
#region Commands
public ICommand BrowseTprzCommand => new AsyncRelayCommand(BrowseTprz, ()=>CurrentDivision != null);
public ICommand BrowseSerialCommand => new AsyncRelayCommand(BrowseSerial,()=>CurrentDivision!=null);
public ICommand SaveCommand => new AsyncRelayCommand(Save);
#endregion //Commands
}
}

View File

@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Text;
using XLIMS.MVVM.Base;
namespace XLIMS.PSV.ViewModels
{
public class SideItemViewModel:ViewModelBase
{
#region Constructor
public SideItemViewModel(int index,string title)
{
_index = index;
_title = title;
}
#endregion //Constructor
#region Events
#endregion //Events
#region Fields
private int _index;
private string _title;
#endregion //Fields
#region Properties
public string Title
{
get => _title;
set { _title = value; OnPropertyChanged(); }
}
public int Index
{
get => _index;
set { _index = value; OnPropertyChanged(); }
}
#endregion //Properties
#region Methods
#endregion //Methods
#region Commands
#endregion //Commands
}
}