|
@@ -1,6 +1,7 @@
|
|
|
using DontHarmDesktop.Models;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Collections.ObjectModel;
|
|
|
using System.ComponentModel;
|
|
|
using System.Globalization;
|
|
|
using System.Linq;
|
|
@@ -24,77 +25,42 @@ namespace DontHarmDesktop.Pages
|
|
|
public partial class LogOnHistory : Page
|
|
|
{
|
|
|
/// <summary>
|
|
|
- /// Направление сортировки колонки даты
|
|
|
+ /// Представление списка попыток входа
|
|
|
/// </summary>
|
|
|
- private ListSortDirection date_sort = ListSortDirection.Descending;
|
|
|
-
|
|
|
+ ICollectionView loginAttemptsView;
|
|
|
+
|
|
|
public LogOnHistory()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
|
|
|
- // Привязка записей из БД к ListView
|
|
|
- List<login_attempts> history = App.Context.login_attempts.ToList();
|
|
|
- HistoryRecordsListView.ItemsSource = history;
|
|
|
+ // Сбор записей и привязка callback-фильтра
|
|
|
+ var loginAttempts = App.Context.login_attempts.ToList();
|
|
|
+ loginAttemptsView = CollectionViewSource.GetDefaultView(loginAttempts);
|
|
|
+ loginAttemptsView.Filter = FilterByLogin;
|
|
|
|
|
|
- // Привязка фильтра
|
|
|
- CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(HistoryRecordsListView.ItemsSource);
|
|
|
- view.Filter = LoginFilter;
|
|
|
+ // Привязка представления к контролу
|
|
|
+ dgLoginHistory.ItemsSource = loginAttempts;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Обработчик события нажатия на заголовок колонки даты входа
|
|
|
+ /// Callback-метод для фильтрации записей по логину
|
|
|
/// </summary>
|
|
|
- /// <param name="sender"></param>
|
|
|
- /// <param name="e"></param>
|
|
|
- private void GridViewColumnHeader_Click(object sender, RoutedEventArgs e)
|
|
|
+ /// <param name="item"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private bool FilterByLogin(object item)
|
|
|
{
|
|
|
- if (date_sort == ListSortDirection.Ascending)
|
|
|
- {
|
|
|
- date_sort = ListSortDirection.Descending;
|
|
|
- } else
|
|
|
- {
|
|
|
- date_sort = ListSortDirection.Ascending;
|
|
|
- }
|
|
|
-
|
|
|
- var columnHeader = (sender as GridViewColumnHeader);
|
|
|
- if (date_sort == ListSortDirection.Descending)
|
|
|
- {
|
|
|
- columnHeader.Content = "Дата (по убыванию)";
|
|
|
- } else
|
|
|
- {
|
|
|
- columnHeader.Content = "Дата (по возрастанию)";
|
|
|
- }
|
|
|
-
|
|
|
- HistoryRecordsListView.Items.SortDescriptions.Clear();
|
|
|
- HistoryRecordsListView.Items.SortDescriptions.Add(new SortDescription("created_at", date_sort));
|
|
|
-
|
|
|
+ login_attempts Attempt = item as login_attempts;
|
|
|
+ return Attempt.login.Contains(tbFilter.Text);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Событие изменения текста в поле ввода фильтра
|
|
|
+ /// Событие изменения текста в поле фильтрации
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
- private void FilterTextBox_TextChanged(object sender, TextChangedEventArgs e)
|
|
|
- {
|
|
|
- CollectionViewSource.GetDefaultView(HistoryRecordsListView.ItemsSource).Refresh();
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Фильтр логинов
|
|
|
- /// </summary>
|
|
|
- /// <param name="item"></param>
|
|
|
- /// <returns></returns>
|
|
|
- private bool LoginFilter(object item)
|
|
|
+ private void tbFilter_TextChanged(object sender, TextChangedEventArgs e)
|
|
|
{
|
|
|
- string filterText = FilterTextBox.Text;
|
|
|
- if (string.IsNullOrEmpty(filterText))
|
|
|
- {
|
|
|
- return true;
|
|
|
- } else
|
|
|
- {
|
|
|
- return (item as login_attempts).login.IndexOf(filterText, StringComparison.OrdinalIgnoreCase) >= 0;
|
|
|
- }
|
|
|
+ loginAttemptsView.Refresh();
|
|
|
}
|
|
|
}
|
|
|
}
|