This commit is contained in:
Курнат Андрей
2026-03-19 23:31:41 +03:00
parent ce3a3f02d2
commit a47a7a5a3b
104 changed files with 21982 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;
namespace XLAB2
{
internal sealed class TpvdklEditWindowViewModel : ObservableObject
{
private readonly IReadOnlyList<TpvdklDirectoryItem> _existingItems;
private int _stampKindId;
private string _validationMessage;
private int _verificationTypeId;
public TpvdklEditWindowViewModel(TpvdklDirectoryItem seed, bool isNew, IReadOnlyList<TpvdklDirectoryItem> existingItems, TypeSizeDirectoryService service)
{
var source = seed ?? new TpvdklDirectoryItem();
_existingItems = existingItems ?? Array.Empty<TpvdklDirectoryItem>();
Id = source.Id;
TipsId = source.TipsId;
IsNew = isNew;
VerificationTypes = service.LoadSpvdmkReferences();
StampKinds = service.LoadSpvdklReferences();
VerificationTypeId = source.VerificationTypeId;
StampKindId = source.StampKindId;
ConfirmCommand = new RelayCommand(Confirm);
CancelCommand = new RelayCommand(Cancel);
}
public event EventHandler<bool?> CloseRequested;
public ICommand CancelCommand { get; private set; }
public ICommand ConfirmCommand { get; private set; }
public int Id { get; private set; }
public bool IsNew { get; private set; }
public IReadOnlyList<DirectoryLookupItem> VerificationTypes { get; private set; }
public IReadOnlyList<DirectoryLookupItem> StampKinds { get; private set; }
public int TipsId { get; private set; }
public int VerificationTypeId { get { return _verificationTypeId; } set { SetProperty(ref _verificationTypeId, value); } }
public int StampKindId { get { return _stampKindId; } set { SetProperty(ref _stampKindId, value); } }
public string Title { get { return IsNew ? "Новый вид клейма" : "Редактирование вида клейма"; } }
public string ValidationMessage { get { return _validationMessage; } private set { SetProperty(ref _validationMessage, value); } }
public TpvdklDirectoryItem ToResult()
{
return new TpvdklDirectoryItem { Id = Id, TipsId = TipsId, VerificationTypeId = VerificationTypeId, StampKindId = StampKindId };
}
private void Cancel(object parameter) { RaiseCloseRequested(false); }
private void Confirm(object parameter)
{
if (VerificationTypeId <= 0) { ValidationMessage = "Укажите вид МК."; return; }
if (StampKindId <= 0) { ValidationMessage = "Укажите вид клейма."; return; }
var duplicate = _existingItems.FirstOrDefault(delegate(TpvdklDirectoryItem item) { return item != null && item.Id != Id && item.VerificationTypeId == VerificationTypeId && item.StampKindId == StampKindId; });
if (duplicate != null) { ValidationMessage = "Такая комбинация вида МК и вида клейма уже существует."; return; }
ValidationMessage = string.Empty;
RaiseCloseRequested(true);
}
private void RaiseCloseRequested(bool? dialogResult)
{
var handler = CloseRequested;
if (handler != null) handler(this, dialogResult);
}
}
}