Удаление готово
This commit is contained in:
parent
8b68e2c7ec
commit
bdf3269ea7
@ -70,10 +70,13 @@ namespace EmployeeManagmentDataBaseImplement.Implements
|
||||
PartTimeJob = entity.PartTimeJob,
|
||||
Bid = entity.Bid,
|
||||
PhysicalPersonsId = entity.PhisicalPersonsId,
|
||||
PhysicalPersonName = $"{entity.PhisicalPerson.Surname} {entity.PhisicalPerson.Name}"
|
||||
PhysicalPersonName = entity.PhisicalPerson != null
|
||||
? $"{entity.PhisicalPerson.Surname} {entity.PhisicalPerson.Name}"
|
||||
: "Не указано" // Обработка отсутствующего физического лица
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// Добавить нового сотрудника
|
||||
public void Insert(EmployeeViewModel model)
|
||||
{
|
||||
|
@ -1,12 +1,52 @@
|
||||
<Window x:Class="EmployeeManagmentView.Employee.DeleteEmployeeWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:EmployeeManagmentView.Employee"
|
||||
mc:Ignorable="d"
|
||||
Title="DeleteEmployeeWindow" Height="450" Width="800">
|
||||
Title="Удаление сотрудников"
|
||||
Height="500" Width="800"
|
||||
ResizeMode="NoResize"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
Background="#0D2D4F">
|
||||
|
||||
<Grid>
|
||||
|
||||
<!-- Заголовок окна -->
|
||||
<TextBlock Text="Список сотрудников для удаления"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Top"
|
||||
FontSize="18" FontWeight="Bold"
|
||||
Foreground="White"
|
||||
Margin="0,20,0,0" />
|
||||
|
||||
<!-- Поле поиска -->
|
||||
<TextBox x:Name="SearchTextBox"
|
||||
Width="560"
|
||||
VerticalAlignment="Top"
|
||||
Margin="0,60,0,0"
|
||||
HorizontalAlignment="Center"
|
||||
Style="{StaticResource RoundedTextBoxStyle}"
|
||||
TextChanged="SearchTextBox_TextChanged" />
|
||||
|
||||
<!-- Таблица сотрудников -->
|
||||
<DataGrid x:Name="EmployeesDataGrid"
|
||||
Margin="20,100,20,80"
|
||||
AutoGenerateColumns="False"
|
||||
Style="{StaticResource RoundedDataGridStyle}">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="Должность" Binding="{Binding NameJob}" Width="*" />
|
||||
<DataGridTextColumn Header="Дата начала" Binding="{Binding StartJob, StringFormat=dd.MM.yyyy}" Width="*" />
|
||||
<DataGridTextColumn Header="Дата окончания" Binding="{Binding EndJob, StringFormat=dd.MM.yyyy}" Width="*" />
|
||||
<DataGridTextColumn Header="Частичная занятость" Binding="{Binding PartTimeJob}" Width="*" />
|
||||
<DataGridTextColumn Header="Ставка" Binding="{Binding Bid}" Width="*" />
|
||||
<DataGridTextColumn Header="Физическое лицо" Binding="{Binding PhysicalPersonName}" Width="*" />
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
|
||||
<!-- Кнопка удаления -->
|
||||
<Button Content="Удалить"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Bottom"
|
||||
Width="100" Height="40"
|
||||
Margin="0,0,0,20"
|
||||
Background="#004890"
|
||||
Foreground="White"
|
||||
Style="{StaticResource RoundedButtonStyle}"
|
||||
Click="DeleteButton_Click" />
|
||||
</Grid>
|
||||
</Window>
|
||||
|
@ -1,32 +1,68 @@
|
||||
using EmployeeManagmentContracts.BusinessLogicContracts;
|
||||
using System;
|
||||
using EmployeeManagmentContracts.ViewModels;
|
||||
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>
|
||||
/// Логика взаимодействия для DeleteEmployeeWindow.xaml
|
||||
/// </summary>
|
||||
public partial class DeleteEmployeeWindow : Window
|
||||
{
|
||||
|
||||
private readonly IEmployeeLogic _employeeLogic;
|
||||
private IEnumerable<EmployeeViewModel> _allEmployees; // Список сотрудников для фильтрации
|
||||
|
||||
public DeleteEmployeeWindow(IEmployeeLogic employeeLogic)
|
||||
{
|
||||
_employeeLogic = employeeLogic;
|
||||
InitializeComponent();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user