Files
XLIMS/XLIMS.PSV/ViewModels/GoodViewModel.cs
Курнат Андрей f0e11d6379 first edit
2026-01-31 16:11:36 +03:00

193 lines
6.2 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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
}
}