diff --git a/src/HikvisionAttendanceManager.App/DbToDeviceView.xaml b/src/HikvisionAttendanceManager.App/DbToDeviceView.xaml index 2c484f0..2b8d6ca 100644 --- a/src/HikvisionAttendanceManager.App/DbToDeviceView.xaml +++ b/src/HikvisionAttendanceManager.App/DbToDeviceView.xaml @@ -1,50 +1,289 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + - - - + + + diff --git a/src/HikvisionAttendanceManager.App/DbToDeviceView.xaml.cs b/src/HikvisionAttendanceManager.App/DbToDeviceView.xaml.cs index 247541a..f69474c 100644 --- a/src/HikvisionAttendanceManager.App/DbToDeviceView.xaml.cs +++ b/src/HikvisionAttendanceManager.App/DbToDeviceView.xaml.cs @@ -20,18 +20,50 @@ public partial class DbToDeviceView : UserControl InitializeComponent(); _service = new TemplateSyncService(new HikvisionIsapiClient(), _machineUsers, _faceTemplates, new OperationHistoryService()); UsersGrid.ItemsSource = _rows; + UpdateUsersEmptyState(); } public async Task InitializeAsync() { if (_initialized) return; _initialized = true; - var devices = await _devices.LoadUnifiedAsync(); - SourceCombo.ItemsSource = devices; - TargetCombo.ItemsSource = devices; + await RefreshAsync(); } - private void SourceChanged(object sender, SelectionChangedEventArgs e) => _rows.Clear(); + public async Task RefreshAsync() + { + var originalContent = RefreshButton.Content; + try + { + RefreshButton.IsEnabled = false; + RefreshButton.Content = "Refreshing..."; + SourceCombo.SelectedItem = null; + TargetCombo.SelectedItem = null; + _rows.Clear(); + UpdateUsersEmptyState(); + ProgressCard.Visibility = Visibility.Collapsed; + ProgressBar.Value = 0; + ProgressText.Text = ""; + CounterText.Text = ""; + UsersGrid.Items.Refresh(); + var devices = await _devices.LoadUnifiedAsync(); + SourceCombo.ItemsSource = devices; + TargetCombo.ItemsSource = devices; + } + finally + { + RefreshButton.IsEnabled = true; + RefreshButton.Content = originalContent; + } + } + + private async void Refresh_Click(object sender, RoutedEventArgs e) => await RefreshAsync(); + + private void SourceChanged(object sender, SelectionChangedEventArgs e) + { + _rows.Clear(); + UpdateUsersEmptyState(); + } private async void LoadUsers_Click(object sender, RoutedEventArgs e) { @@ -44,6 +76,8 @@ public partial class DbToDeviceView : UserControl var hasFace = template?.Template is { Length: > 0 } && HikvisionIsapiClient.IsUploadableFaceTemplate(template.Template); _rows.Add(new SelectableMachineUser(user.SerialNumber, user.EmployeeName, hasFace)); } + + UpdateUsersEmptyState(); } private void SelectAll_Click(object sender, RoutedEventArgs e) @@ -58,6 +92,11 @@ public partial class DbToDeviceView : UserControl UsersGrid.Items.Refresh(); } + private void UpdateUsersEmptyState() + { + UsersEmptyState.Visibility = _rows.Count == 0 ? Visibility.Visible : Visibility.Collapsed; + } + private async void Transfer_Click(object sender, RoutedEventArgs e) { if (SourceCombo.SelectedItem is not Device source || TargetCombo.SelectedItem is not Device target)