123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using ReactiveUI;
- using System.Linq;
- using AvaloniaApplication5.Models;
- using Microsoft.EntityFrameworkCore;
- using MsBox.Avalonia.Enums;
- using MsBox.Avalonia;
- namespace AvaloniaApplication5.ViewModels
- {
- internal class ShowViewModel : ViewModelBase
- {
- 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();
- }
- public void ToAddPage()
- {
- MainWindowViewModel.Instance.PageContent = new AddPage();
- }
- public async void DeleteTeacher(int idt)
- {
- // Çàïðàøèâàåì ïîäòâåðæäåíèå óäàëåíèÿ
- ButtonResult result = await MessageBoxManager.GetMessageBoxStandard("Ïîäòâåðæäåíèå óäàëåíèÿ",
- "Ïîäòâåðäèòü óäàëåíèå ó÷èòåëÿ?", ButtonEnum.YesNo).ShowAsync();
- if (result == ButtonResult.Yes)
- {
- // Åñëè ïîëüçîâàòåëü ïîäòâåðäèë, óäàëÿåì ó÷èòåëÿ
- Teacher deleteTeacher = MainWindowViewModel.myConnection.Teachers.First(x => x.Id == idt);
- MainWindowViewModel.myConnection.Teachers.Remove(deleteTeacher);
- MainWindowViewModel.myConnection.SaveChanges();
- await MessageBoxManager.GetMessageBoxStandard("Ñîîáùåíèå", "Ó÷èòåëü óäàëåí", ButtonEnum.Ok).ShowAsync();
- MainWindowViewModel.Instance.PageContent = new Show();
- }
- else
- {
- // Åñëè ïîëüçîâàòåëü îòìåíèë, ìîæíî, íàïðèìåð, ïîêàçàòü ñîîáùåíèå
- await MessageBoxManager.GetMessageBoxStandard("Îòìåíà", "Óäàëåíèå îòìåíåíî.", ButtonEnum.Ok).ShowAsync();
- }
- }
- string _message = "";
- public string Message
- {
- get => _message;
- set => this.RaiseAndSetIfChanged(ref _message, value);
- }
- public void UpdateTeacher(int idt)
- {
- 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;
- }
- }
-
- }
- }
|