PIbd-42_Kashin_M.I_CPO_Cour.../EmployeeManagmentView/Employee/ViewEmployeeWindow.xaml.cs

68 lines
2.4 KiB
C#
Raw Normal View History

using EmployeeManagmentContracts.BusinessLogicContracts;
using EmployeeManagmentContracts.ViewModels;
using System;
using System.Collections.Generic;
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.Shapes;
namespace EmployeeManagmentView.Employee
{
/// <summary>
/// Логика взаимодействия для ViewEmployeeWindow.xaml
/// </summary>
public partial class ViewEmployeeWindow : Window
{
private readonly IEmployeeLogic _employeeLogic;
private IEnumerable<EmployeeViewModel> _allEmployees; // Список сотрудников для фильтрации
public ViewEmployeeWindow(IEmployeeLogic employeeLogic)
{
_employeeLogic = employeeLogic;
InitializeComponent();
LoadEmployees();
}
private void LoadEmployees()
{
_allEmployees = _employeeLogic.GetFullList(); // Загрузка всех данных
EmployeesDataGrid.ItemsSource = _allEmployees;
}
private void SearchTextBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
string query = SearchTextBox.Text.ToLower();
if (string.IsNullOrWhiteSpace(query))
{
// Отображаем все записи
EmployeesDataGrid.ItemsSource = _allEmployees;
}
else
{
// Фильтрация по всем полям сущности
var filteredList = _allEmployees.Where(emp =>
(emp.NameJob?.ToLower().Contains(query) ?? false) ||
(emp.PartTimeJob?.ToLower().Contains(query) ?? false) ||
(emp.PhysicalPersonName?.ToLower().Contains(query) ?? false) ||
(emp.StartJob.HasValue && emp.StartJob.Value.ToString("dd.MM.yyyy").Contains(query)) ||
(emp.EndJob.HasValue && emp.EndJob.Value.ToString("dd.MM.yyyy").Contains(query)) ||
emp.Bid.ToString().Contains(query)
).ToList();
EmployeesDataGrid.ItemsSource = filteredList;
}
}
}
}