Добавьте файлы проекта.

This commit is contained in:
Курнат Андрей
2026-04-04 10:52:30 +03:00
parent 9b34a92f15
commit 5a55bc5f4c
30 changed files with 3446 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
using System.Collections.ObjectModel;
using System.Linq;
using CRAWLER.Infrastructure;
using CRAWLER.Models;
namespace CRAWLER.ViewModels;
internal sealed class EditInstrumentWindowViewModel : ObservableObject
{
private readonly InstrumentRecord _draft;
private PendingPdfFile _selectedPendingPdf;
public EditInstrumentWindowViewModel(InstrumentRecord draft, bool isNewRecord)
{
_draft = draft ?? new InstrumentRecord();
PendingPdfFiles = new ObservableCollection<PendingPdfFile>();
ExistingAttachments = new ObservableCollection<PdfAttachment>(_draft.Attachments ?? Enumerable.Empty<PdfAttachment>());
WindowTitle = isNewRecord ? "Новая запись" : $"Редактирование: {(_draft.RegistryNumber ?? _draft.Name)}";
}
public string WindowTitle { get; }
public ObservableCollection<PendingPdfFile> PendingPdfFiles { get; }
public ObservableCollection<PdfAttachment> ExistingAttachments { get; }
public PendingPdfFile SelectedPendingPdf
{
get { return _selectedPendingPdf; }
set { SetProperty(ref _selectedPendingPdf, value); }
}
public InstrumentRecord Draft
{
get { return _draft; }
}
public void AddPendingFiles(IReadOnlyList<string> paths)
{
foreach (var path in paths.Where(path => !string.IsNullOrWhiteSpace(path)))
{
if (PendingPdfFiles.Any(item => string.Equals(item.SourcePath, path, StringComparison.OrdinalIgnoreCase)))
{
continue;
}
PendingPdfFiles.Add(new PendingPdfFile
{
SourcePath = path,
DisplayName = System.IO.Path.GetFileName(path)
});
}
}
public void RemovePendingSelected()
{
if (SelectedPendingPdf != null)
{
PendingPdfFiles.Remove(SelectedPendingPdf);
}
}
public string[] GetPendingPaths()
{
return PendingPdfFiles.Select(item => item.SourcePath).ToArray();
}
public bool Validate(out string errorMessage)
{
if (string.IsNullOrWhiteSpace(Draft.Name))
{
errorMessage = "Укажите наименование средства измерения.";
return false;
}
errorMessage = null;
return true;
}
}