Переглянути джерело

Реализован просмотр истории входов

Вадим Королёв 1 рік тому
батько
коміт
00e9f4631e

+ 4 - 1
src/DontHarmDesktop/App.xaml.cs

@@ -95,7 +95,10 @@ namespace DontHarmDesktop
             LogOffTime = LogOnTime + TimeSpan.FromMinutes(2);
 
             // Запуск таймера
-            (Current.MainWindow as MainWindow).StartLogoffTimer();
+            if (CurrentUser.role == 3 || CurrentUser.role == 4)
+            {
+                (Current.MainWindow as MainWindow).StartLogoffTimer();
+            }
 
             AddLogOnRecord(login, true);
             return true;

+ 7 - 0
src/DontHarmDesktop/DontHarmDesktop.csproj

@@ -96,6 +96,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="Pages\LogOnHistory.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="Pages\UserInfoPage.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
@@ -163,6 +167,9 @@
     <Compile Include="Pages\HeaderPage.xaml.cs">
       <DependentUpon>HeaderPage.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Pages\LogOnHistory.xaml.cs">
+      <DependentUpon>LogOnHistory.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Pages\UserInfoPage.xaml.cs">
       <DependentUpon>UserInfoPage.xaml</DependentUpon>
     </Compile>

+ 28 - 0
src/DontHarmDesktop/Pages/LogOnHistory.xaml

@@ -0,0 +1,28 @@
+<Page x:Class="DontHarmDesktop.Pages.LogOnHistory"
+      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+      xmlns:local="clr-namespace:DontHarmDesktop.Pages"
+      mc:Ignorable="d" 
+      d:DesignHeight="450" d:DesignWidth="800"
+      Title="LogOnHistory">
+
+    <StackPanel>
+        <TextBox x:Name="FilterTextBox" ToolTip="Фильтр логинов" TextChanged="FilterTextBox_TextChanged"></TextBox>
+        <ListView x:Name="HistoryRecordsListView">
+            <ListView.View>
+                <GridView>
+                    <GridViewColumn Width="Auto" Header="Login" DisplayMemberBinding="{Binding login}"/>
+                    <GridViewColumn Width="Auto" Header="IP" DisplayMemberBinding="{Binding ip_address}"/>
+                    <GridViewColumn Width="Auto" Header="Удачно" DisplayMemberBinding="{Binding successfull}"/>
+                    <GridViewColumn Width="Auto" DisplayMemberBinding="{Binding created_at}">
+                        <GridViewColumn.Header>
+                            <GridViewColumnHeader Content="Дата" Click="GridViewColumnHeader_Click"/>
+                        </GridViewColumn.Header>
+                    </GridViewColumn>
+                </GridView>
+            </ListView.View>
+        </ListView>
+    </StackPanel>
+</Page>

+ 100 - 0
src/DontHarmDesktop/Pages/LogOnHistory.xaml.cs

@@ -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;
+            }
+        }
+    }
+}

+ 1 - 1
src/DontHarmDesktop/Pages/WelcomePage.xaml

@@ -26,7 +26,7 @@
             <Label Visibility="{Binding Path=UtilizerVisibility}" Name="UtilizerLabel" Grid.Row="2"><Hyperlink>Работа с утилизатором</Hyperlink></Label>
             <Label Visibility="{Binding Path=ViewReportsVisibility}" Name="ViewReportsLabel" Grid.Row="3"><Hyperlink>Просмотреть отчёты</Hyperlink></Label>
             <Label Visibility="{Binding Path=MakeInvoiceVisibility}" Name="MakeInvoiceLabel" Grid.Row="4"><Hyperlink>Сформировать счёт предприятию</Hyperlink></Label>
-            <Label Visibility="{Binding Path=LoginHistoryVisibility}" Name="LoginHistoryLabel" Grid.Row="5"><Hyperlink>Просмотр истории входа</Hyperlink></Label>
+            <Label Visibility="{Binding Path=LoginHistoryVisibility}" Name="LoginHistoryLabel" Grid.Row="5"><Hyperlink NavigateUri="/Pages/LogOnHistory.xaml">Просмотр истории входа</Hyperlink></Label>
             <Label Visibility="{Binding Path=UsageVisibility}" Name="UsageLabel" Grid.Row="6"><Hyperlink>Просмотр расходов</Hyperlink></Label>
         </Grid>
         <Button Click="LogoffButton_Click" Name="LogoffButton">Выход</Button>