2024-12-01 15:14:20 +04:00
|
|
|
|
using EmployeeManagmentContracts.BusinessLogicContracts;
|
2024-12-01 15:27:38 +04:00
|
|
|
|
using EmployeeManagmentContracts.ViewModels;
|
2024-12-01 15:14:20 +04:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
|
|
|
|
namespace EmployeeManagmentView.Employee
|
|
|
|
|
{
|
|
|
|
|
public partial class DeleteEmployeeWindow : Window
|
|
|
|
|
{
|
|
|
|
|
private readonly IEmployeeLogic _employeeLogic;
|
2024-12-01 15:27:38 +04:00
|
|
|
|
private IEnumerable<EmployeeViewModel> _allEmployees; // Список сотрудников для фильтрации
|
2024-12-01 15:14:20 +04:00
|
|
|
|
|
|
|
|
|
public DeleteEmployeeWindow(IEmployeeLogic employeeLogic)
|
|
|
|
|
{
|
|
|
|
|
_employeeLogic = employeeLogic;
|
|
|
|
|
InitializeComponent();
|
2024-12-01 15:27:38 +04:00
|
|
|
|
LoadEmployees();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadEmployees()
|
|
|
|
|
{
|
|
|
|
|
_allEmployees = _employeeLogic.GetFullList(); // Загрузка всех данных
|
|
|
|
|
EmployeesDataGrid.ItemsSource = _allEmployees;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DeleteButton_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (EmployeesDataGrid.SelectedItem is EmployeeViewModel selectedEmployee)
|
|
|
|
|
{
|
|
|
|
|
// Удаление сотрудника
|
|
|
|
|
_employeeLogic.Delete(selectedEmployee.Id);
|
|
|
|
|
MessageBox.Show("Сотрудник успешно удален!");
|
|
|
|
|
LoadEmployees(); // Перезагрузка данных после удаления
|
|
|
|
|
SearchTextBox.Text = string.Empty; // Очистка поля поиска
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Пожалуйста, выберите сотрудника для удаления.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2024-12-01 15:14:20 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|