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

113 lines
4.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using EmployeeManagmentBusinessLogic.BusinessLogic;
using EmployeeManagmentContracts.BusinessLogicContracts;
using EmployeeManagmentContracts.ViewModels;
using EmployeeManagmentView.Employee.Salary;
using EmployeeManagmentView.Employee.Vacation;
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 readonly ISalaryLogic _salaryLogic;
private readonly IVacationLogic _vacationLogic;
private IEnumerable<EmployeeViewModel> _allEmployees; // Список сотрудников для фильтрации
public ViewEmployeeWindow(IEmployeeLogic employeeLogic, ISalaryLogic salaryLogic, IVacationLogic vacationLogic)
{
_employeeLogic = employeeLogic;
_salaryLogic = salaryLogic;
_vacationLogic = vacationLogic;
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;
}
}
private void OpenSalaryManagementWindow(object sender, RoutedEventArgs e)
{
foreach (Window window in Application.Current.Windows)
{
if (window is SalaryManagementWindow)
{
// Если окно уже открыто, активируем его и ставим на передний план
window.Activate();
window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
window.Topmost = true; // Ставим окно на передний план
window.Topmost = false; // Сразу снимаем флаг, чтобы окно не оставалось всегда наверху
return;
}
}
var salaryWindow = new SalaryManagementWindow(_salaryLogic, _employeeLogic);
salaryWindow.Show();
}
private void OpenVacationManagementWindow(object sender, RoutedEventArgs e)
{
foreach (Window window in Application.Current.Windows)
{
if (window is VacationManagementWindow)
{
// Если окно уже открыто, активируем его и ставим на передний план
window.Activate();
window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
window.Topmost = true; // Ставим окно на передний план
window.Topmost = false; // Сразу снимаем флаг, чтобы окно не оставалось всегда наверху
return;
}
}
var vacationWindow = new VacationManagementWindow(_vacationLogic, _employeeLogic);
vacationWindow.Show();
}
}
}