|
@@ -0,0 +1,100 @@
|
|
|
+using DontHarmDesktop.Models;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.ComponentModel;
|
|
|
+using System.Globalization;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+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 DontHarmDesktop.Pages
|
|
|
+{
|
|
|
+ /// <summary>
|
|
|
+ /// Логика взаимодействия для LogOnHistory.xaml
|
|
|
+ /// </summary>
|
|
|
+ public partial class LogOnHistory : Page
|
|
|
+ {
|
|
|
+ /// <summary>
|
|
|
+ /// Направление сортировки колонки даты
|
|
|
+ /// </summary>
|
|
|
+ private ListSortDirection date_sort = ListSortDirection.Descending;
|
|
|
+
|
|
|
+ public LogOnHistory()
|
|
|
+ {
|
|
|
+ InitializeComponent();
|
|
|
+
|
|
|
+ // Привязка записей из БД к ListView
|
|
|
+ List<login_attempts> history = App.Context.login_attempts.ToList();
|
|
|
+ HistoryRecordsListView.ItemsSource = history;
|
|
|
+
|
|
|
+ // Привязка фильтра
|
|
|
+ CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(HistoryRecordsListView.ItemsSource);
|
|
|
+ view.Filter = LoginFilter;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Обработчик события нажатия на заголовок колонки даты входа
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="sender"></param>
|
|
|
+ /// <param name="e"></param>
|
|
|
+ private void GridViewColumnHeader_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ 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));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <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)
|
|
|
+ {
|
|
|
+ string filterText = FilterTextBox.Text;
|
|
|
+ if (string.IsNullOrEmpty(filterText))
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ } else
|
|
|
+ {
|
|
|
+ return (item as login_attempts).login.IndexOf(filterText, StringComparison.OrdinalIgnoreCase) >= 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|