AnnaBezaeva 1 неделя назад
Родитель
Сommit
281a63ab12

+ 9 - 0
AvaloniaApplication5/Models/Teache.cs

@@ -4,6 +4,7 @@ using System.ComponentModel.DataAnnotations;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using System.Xml.Linq;
 using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal;
 namespace AvaloniaApplication5.Models
 {
@@ -35,5 +36,13 @@ namespace AvaloniaApplication5.Models
 
 
         }
+        public string FIO
+        {
+            get
+            {
+                return LastName + " " + FirstName + " " + PatronymicName;
+            }
+        }
+
     }
 }

+ 154 - 3
AvaloniaApplication5/ViewModels/ShowViewModel.cs

@@ -12,11 +12,15 @@ namespace AvaloniaApplication5.ViewModels
 {
     internal class ShowViewModel : ViewModelBase
     {
-        public List<Teacher> TeacherList => MainWindowViewModel.myConnection.Teachers.
+        List<Teacher> _teacherList;
+        public List<Teacher> TeacherList { get => _teacherList; set=> this.RaiseAndSetIfChanged(ref _teacherList, value); } 
+        public ShowViewModel()
+        {
+            TeacherList = MainWindowViewModel.myConnection.Teachers.
                                                                        Include(x => x.Gender).
                                                                        Include(x => x.TeacherDisciplines).ThenInclude(x => x.Discipline).
-                                                                      Include(x => x.TeacherCourses).ThenInclude(x => x.Course).
-            ToList();
+                                                                      Include(x => x.TeacherCourses).ThenInclude(x => x.Course).ToList();
+        }
         public void ToAddPage()
         {
             MainWindowViewModel.Instance.PageContent = new AddPage();
@@ -56,5 +60,152 @@ namespace AvaloniaApplication5.ViewModels
         {
             MainWindowViewModel.Instance.PageContent = new AddPage(idt);
         }
+        public bool _genderm = false;
+        public bool Genderm
+        {
+            get => _genderm;
+            set
+            {
+                _genderm = value;
+                AllFilters();
+            }
+        }
+
+        public bool _genderg = false;
+        public bool Genderg
+        {
+            get => _genderg;
+            set
+            {
+                _genderg = value;
+                AllFilters();
+            }
+        }
+        string _searchTeacher;
+        public string SearchTeacher
+        {
+            get => _searchTeacher;
+            set
+            {
+                _searchTeacher = value;
+                   AllFilters();
+            }
+            
+        }
+        bool _checkTeacher = false;
+        public bool CheckTeacher
+        {
+            get => _checkTeacher;
+            set
+            {
+                _checkTeacher = value;
+                AllFilters();
+            }
+        }
+
+        bool _phone = false;
+        public bool Phone
+        {
+            get => _phone;
+            set
+            {
+                _phone = value;
+                AllFilters();
+            }
+        }
+        List<Discipline> _disciplinesfilter = [new Discipline() { Id = 0, Name = "Âñå äèñöèïëèíû" }, .. MainWindowViewModel.myConnection.Disciplines.ToList()];
+        public List<Discipline> DisciplinesFilter { get => _disciplinesfilter; }
+        Discipline _selecteddiscipline = null;
+        public Discipline SelectedDiscipline
+        {
+            get
+            {
+                if (_selecteddiscipline == null) return _disciplinesfilter[0];
+                else { return _selecteddiscipline; }
+            }
+            set
+            {
+                _selecteddiscipline = value;
+                AllFilters();
+            }
+        }
+
+        int _selectedSort = 0;
+        bool _Visible = false;
+        bool _Up = true;
+        bool _Down = true;
+
+        public int SelectedSort { get => _selectedSort; set { _selectedSort = value; AllFilters(); } }
+        public bool Visible { get => _Visible; set => this.RaiseAndSetIfChanged(ref _Visible, value); }
+        public bool Up { get => _Up; set { this.RaiseAndSetIfChanged(ref _Up, value); AllFilters(); } }
+        public bool Down { get => _Down; set { this.RaiseAndSetIfChanged(ref _Down, value); AllFilters(); } }
+        void AllFilters()
+       {
+            TeacherList = MainWindowViewModel.myConnection.Teachers.
+                                                                       Include(x => x.Gender).
+                                                                       Include(x => x.TeacherDisciplines).ThenInclude(x => x.Discipline).
+                                                                      Include(x => x.TeacherCourses).ThenInclude(x => x.Course).
+            ToList();
+            if (!string.IsNullOrEmpty(_searchTeacher)) {
+                TeacherList = TeacherList.Where(x => x.FIO.ToLower().Contains(_searchTeacher.ToLower())).ToList();
+            }
+
+            if (_genderm || _genderg)
+            {
+                TeacherList = TeacherList.Where(x => (_genderm && x.GenderId ==1)|| (_genderg && x.GenderId == 2)).ToList();
+
+            } 
+            if (_phone)
+            {
+                TeacherList = TeacherList.Where(x => x.Phone == "").ToList();
+
+            }
+            if (_selecteddiscipline != null && _selecteddiscipline.Id != 0)
+            {
+                TeacherList = TeacherList.Where(x => x.TeacherDisciplines.Any(y => y.Discipline.Id == _selecteddiscipline.Id)).ToList();
+            }
+            switch (_selectedSort)
+            {
+                case 0:
+                    Visible = false;
+                    break;
+                case 1:
+                    Visible = true;
+                    if (_Down)
+                    {
+                        TeacherList = TeacherList.OrderByDescending(x => x.Experience).ToList();
+                    }
+                    else
+                    {
+                        TeacherList = TeacherList.OrderBy(x => x.Experience).ToList();
+                    }
+                    break;
+                case 2:
+                    Visible = true;
+                    if (_Down)
+                    {
+                        
+                        TeacherList = TeacherList.OrderByDescending(x => x.LastName).ToList();
+                    }
+                    else
+                    {
+                        TeacherList = TeacherList.OrderBy(x => x.LastName).ToList();
+                    }
+                    break;
+                case 3:
+                    Visible = true;
+                    if (_Down)
+                    {
+                        TeacherList = TeacherList.OrderByDescending(x => x.summa).ToList();
+                    }
+                    else
+                    {
+                        TeacherList = TeacherList.OrderBy(x => x.summa).ToList();
+                    }
+                    break;
+
+            }
+        }
+    
     }  
 }

+ 30 - 1
AvaloniaApplication5/Views/Show.axaml

@@ -12,7 +12,36 @@
 			<RowDefinition></RowDefinition>
 			<RowDefinition Height="8*"></RowDefinition>
 		</Grid.RowDefinitions>
-		<Button Command="{Binding ToAddPage}">Добавить преподавателя</Button>
+		<StackPanel Margin="10 0 0 0" Orientation="Horizontal" VerticalAlignment="Center">
+		<Button Command="{Binding ToAddPage}">Добавить преподавателя</Button>	
+			<TextBox Text="{Binding SearchTeacher}" Width="250"  Watermark="Поиск ФИО" HorizontalAlignment="Center" VerticalAlignment="Center"></TextBox>
+			<StackPanel Orientation="Vertical" Margin="10 0 0 0">
+
+				<CheckBox IsChecked="{Binding Genderm}">Мужской</CheckBox>
+				<CheckBox IsChecked="{Binding Genderg}">Женский</CheckBox>
+			</StackPanel>
+			<CheckBox IsChecked="{Binding Phone}">Наличие телефона</CheckBox>
+			<StackPanel Orientation="Vertical">
+				<ComboBox ItemsSource="{Binding DisciplinesFilter}" SelectedItem="{Binding SelectedDiscipline}" Width="200">
+					<ComboBox.ItemTemplate>
+						<DataTemplate>
+							<TextBlock Text="{Binding Name}"></TextBlock>
+						</DataTemplate>
+					</ComboBox.ItemTemplate>
+				</ComboBox>
+				<ComboBox SelectedIndex="{Binding SelectedSort}" Width="200">
+					<ComboBoxItem>Без сортировки</ComboBoxItem>
+					<ComboBoxItem>Стаж</ComboBoxItem>
+					<ComboBoxItem>По фамилии</ComboBoxItem>
+					<ComboBoxItem>По сумме часов пройденных курсов</ComboBoxItem>
+				</ComboBox>
+			</StackPanel>
+			<StackPanel Orientation="Vertical" IsVisible="{Binding Visible}">
+				<RadioButton  Content="По возрастанию" IsChecked="{Binding Up}"/>
+				<RadioButton  Content="По убыванию" IsChecked="{Binding Down}"/>
+			</StackPanel>
+		</StackPanel>
+		
 		<ListBox ItemsSource="{Binding TeacherList}" Grid.Row="1" SelectionMode="Multiple">
 			<ListBox.ItemTemplate>
 				<DataTemplate>