Files
laatzen/Common/Ui/Common.UI/ViewModels/EregisterHistoryVM.cs
T
2025-04-14 14:10:58 +02:00

98 lines
2.6 KiB
C#

namespace Common.UI.ViewModels
{
using Common.Hardware.SIRT;
using Common.UI.Infrastructure;
using LaaPackages.SqlClient;
using System.Collections.ObjectModel;
using System.Windows.Input;
public class EregisterHistoryVM : VM<EregisterHistoryVM>
{
private readonly SqlConnection sqlConnection;
public EregisterHistoryVM()
{
var connectionString = Appsettings.GetSetting("ConnectionString");
this.sqlConnection = SqlConnection.CreateSqlConnection(connectionString);
this.Addresses = new ObservableCollection<AddressVM>();
AppHost.SIRTHub.MessageProcessed += SIRTHub_MessageProcessed;
}
public ObservableCollection<AddressVM> Addresses { get; }
private void SIRTHub_MessageProcessed(SIRTMessage message)
{
var address = message.Address;
if (address > 0)
{
this.InvokeAsync(() =>
{
var inserted = false;
var addressesCount = this.Addresses.Count;
for (var addressIX = 0; addressIX < addressesCount; addressIX++)
{
var vm = this.Addresses[addressIX];
if (vm.Address == address)
{
inserted = true;
break;
}
else if (vm.Address > address)
{
this.Addresses.Insert(addressIX, address);
inserted = true;
break;
}
}
if (!inserted)
{
this.Addresses.Add(address);
}
});
}
}
}
public class AddressVM : VM<AddressVM>
{
public AddressVM()
=> this.CheckedCommand = new Command(this.CheckedCommandHandler);
private uint address;
public uint Address
{
get => this.address;
set => this.SetValue(vm => vm.address = value);
}
private bool isChecked;
public bool IsChecked
{
get => this.isChecked;
set => this.SetValue(vm => vm.isChecked = value);
}
public ICommand CheckedCommand { get; }
private void CheckedCommandHandler()
{
}
public static implicit operator AddressVM(uint address) => new AddressVM
{
Address = address
};
}
}