using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Module_HSI_Identifier
{
/// /// Interaction logic for MainWindow.xaml ///
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
LoadHSI();
IdDataGrid.ItemsSource = recordedIdList;
idCollectionView = CollectionViewSource.GetDefaultView(recordedIdList);
IdDataGrid.ItemsSource = idCollectionView;
}
private List hsiRes = new();
private HashSet recordedIds = new();
private ObservableCollection recordedIdList = new();
private ICollectionView idCollectionView; private void LoadHSI()
{
string hsiPath = @"x";
if (!File.Exists(hsiPath)) return;
hsiRes.Clear();
foreach (var line in File.ReadAllLines(hsiPath))
{
if (string.IsNullOrWhiteSpace(line))
continue;
var parts = line.Split('\t');
hsiRes.Add(new IdRecord { Id = parts[0].Trim(), Status = parts[1].Trim() });
}
}
private void IdInput_TextChanged(object sender, TextChangedEventArgs e)
{
string input = IdInput.Text.Trim();
if (input.Length == 16)
{
string inputId = input;
var match = hsiRes.FirstOrDefault(x => x.Id == inputId);
if (match != null)
{
if (recordedIds.Contains(inputId))
{
MessageBox.Show($"ID is already in the list: {inputId}");
IdInput.Clear();
return;
}
recordedIds.Add(inputId);
recordedIdList.Insert(0, match);
}
if (match == null)
{
MessageBox.Show($"No result for the ID: {inputId}");
IdInput.Clear();
return;
}
IdInput.Clear();
}
}
}
}