50 lines
1.9 KiB
C#
50 lines
1.9 KiB
C#
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using HikvisionAttendanceManager.App.Models;
|
|
using HikvisionAttendanceManager.App.Services;
|
|
|
|
namespace HikvisionAttendanceManager.App;
|
|
|
|
public partial class DeviceToDbView : UserControl
|
|
{
|
|
private readonly DeviceService _devices = new();
|
|
private readonly TemplateSyncService _service;
|
|
private bool _initialized;
|
|
|
|
public DeviceToDbView()
|
|
{
|
|
InitializeComponent();
|
|
_service = new TemplateSyncService(new HikvisionIsapiClient(), new AttendanceMachineUserRepository(), new AttendanceMachineFaceTemplateRepository(), new OperationHistoryService());
|
|
}
|
|
|
|
public async Task InitializeAsync()
|
|
{
|
|
if (_initialized) return;
|
|
_initialized = true;
|
|
DeviceCombo.ItemsSource = await _devices.LoadUnifiedAsync();
|
|
}
|
|
|
|
private async void StartSync_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
if (DeviceCombo.SelectedItem is not Device device) { MessageBox.Show("Select a device."); return; }
|
|
ProgressCard.Visibility = Visibility.Visible;
|
|
var progress = new Progress<UserSyncProgress>(p =>
|
|
{
|
|
ProgressBar.Maximum = Math.Max(1, p.Total);
|
|
ProgressBar.Value = p.Completed;
|
|
ProgressText.Text = $"{p.Completed}/{p.Total} · {p.CurrentEmployee} · {p.CurrentOperation}";
|
|
CounterText.Text = $"Saved: {p.Created} · Skipped: {p.Skipped} · Failed: {p.Failed}";
|
|
});
|
|
try
|
|
{
|
|
var entry = await _service.DeviceToDbAsync(device, progress, CancellationToken.None);
|
|
ProgressText.Text = $"Completed — {entry.Status}";
|
|
CounterText.Text = $"Total: {entry.Total} · Success: {entry.Success} · Skipped: {entry.Skipped} · Failed: {entry.Failed}";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "Device → DB", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
}
|