Browse Source

почти правильно работающие сортировки/фильтры

fly9024 1 năm trước cách đây
mục cha
commit
d4480b8b37
2 tập tin đã thay đổi với 34 bổ sung5 xóa
  1. 13 4
      MyWpfApp/Pages/PageUserList.xaml
  2. 21 1
      MyWpfApp/Pages/PageUserList.xaml.cs

+ 13 - 4
MyWpfApp/Pages/PageUserList.xaml

@@ -21,7 +21,7 @@
                 <GroupBox Header="Логин">
                     <TextBlock Text="{Binding LoginedTable.Login}"/>
                 </GroupBox>
-                <GroupBox Header="Логин">
+                <GroupBox Header="Роль в системе">
                     <TextBlock Text="{Binding LoginedTable.Roles.Role}"/>
                 </GroupBox>
                 <Button Content="Редактировать" Click="Button_Click" Uid="{Binding ID}"/>
@@ -31,10 +31,19 @@
     
     
     <StackPanel>
+        <GroupBox Header="Всякие разные фильтры">
+            <StackPanel Orientation="Horizontal">
+                <GroupBox Header="Поиск по фамилии">
+                    <TextBox x:Name="txtSurnameFind" TextChanged="txtSurnameFind_TextChanged"/>
+                </GroupBox>
+                <GroupBox Header="Фильтр по роли">
+                    <ComboBox x:Name="cbRoleFind" SelectionChanged="cbRoleFind_SelectionChanged"/>
+                </GroupBox>
+                <Button Content="Сбросить все фильтры" Name="btnResetFilters" Click="btnResetFilters_Click"/>
+            </StackPanel>
+        </GroupBox>
         
-        <ListBox x:Name="LB1" ItemTemplate="{StaticResource DT1}">
-            
-        </ListBox>
+        <ListBox x:Name="LB1" ItemTemplate="{StaticResource DT1}"/>
         <Button Content="Добавить нового пользователя" Name="BtnAddUser" Click="BtnAddUser_Click"/>
     </StackPanel>
 </Page>

+ 21 - 1
MyWpfApp/Pages/PageUserList.xaml.cs

@@ -21,10 +21,15 @@ namespace MyWpfApp.Pages
     /// </summary>
     public partial class PageUserList : Page
     {
+        List<UserTable> users = Globals.MyGlobalConnection.UserTable.ToList();
         public PageUserList()
         {
             InitializeComponent();
-            LB1.ItemsSource = Globals.MyGlobalConnection.UserTable.ToList();
+            LB1.ItemsSource = users;
+            cbRoleFind.ItemsSource = Globals.MyGlobalConnection.Roles.ToList();
+            cbRoleFind.SelectedValuePath = "ID";
+            cbRoleFind.DisplayMemberPath = "Role";
+
         }
 
        
@@ -44,5 +49,20 @@ namespace MyWpfApp.Pages
         {
             Globals.MyGlobalFrame.Navigate(new PageUserInfo());
         }
+
+        private void txtSurnameFind_TextChanged(object sender, TextChangedEventArgs e)
+        {
+            LB1.ItemsSource = users.Where(x=>x.Surname.StartsWith(txtSurnameFind.Text)).ToList();    
+        }
+
+        private void cbRoleFind_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            LB1.ItemsSource = users.Where(x=>x.LoginedTable.IDRole == (int)cbRoleFind.SelectedValue).ToList();
+        }
+
+        private void btnResetFilters_Click(object sender, RoutedEventArgs e)
+        {
+            LB1.ItemsSource = users;
+        }
     }
 }