Весь CRUD добавлен для сотрудника добавлен.
This commit is contained in:
parent
bdf3269ea7
commit
c228db433f
@ -1,12 +1,118 @@
|
|||||||
<Window x:Class="EmployeeManagmentView.Employee.EditEmployeeWindow"
|
<Window x:Class="EmployeeManagmentView.Employee.EditEmployeeWindow"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
Title="Редактирование сотрудника"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
Height="704" Width="600"
|
||||||
xmlns:local="clr-namespace:EmployeeManagmentView.Employee"
|
ResizeMode="NoResize"
|
||||||
mc:Ignorable="d"
|
WindowStartupLocation="CenterScreen"
|
||||||
Title="EditEmployeeWindow" Height="450" Width="800">
|
Background="#0D2D4F">
|
||||||
<Grid>
|
|
||||||
|
<Grid Margin="0,0,0,-6">
|
||||||
|
<!-- Заголовок окна -->
|
||||||
|
<TextBlock Text="Редактирование сотрудника"
|
||||||
|
HorizontalAlignment="Center" VerticalAlignment="Top"
|
||||||
|
FontSize="18" FontWeight="Bold"
|
||||||
|
Foreground="#FFFFFF"
|
||||||
|
Margin="0,20,0,0" />
|
||||||
|
|
||||||
|
<!-- Основная сетка -->
|
||||||
|
<Grid Margin="0,70,0,60">
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<!-- Поиск -->
|
||||||
|
<RowDefinition Height="2*" />
|
||||||
|
<!-- Редактирование -->
|
||||||
|
<RowDefinition Height="5*" />
|
||||||
|
<!-- Кнопка сохранения -->
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
<!-- Блок поиска -->
|
||||||
|
<Grid Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,10">
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="Auto" />
|
||||||
|
<ColumnDefinition Width="Auto" />
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
|
<!-- Поле для поиска сотрудников -->
|
||||||
|
<Label Grid.Row="0" Grid.Column="0"
|
||||||
|
Content="Поиск сотрудника" Foreground="White" HorizontalAlignment="Right" Margin="0,0,10,0" VerticalContentAlignment="Center"/>
|
||||||
|
<TextBox x:Name="SearchTextBox" Grid.Row="0" Grid.Column="1"
|
||||||
|
Width="250" Height="30"
|
||||||
|
Style="{StaticResource RoundedTextBoxStyle}"
|
||||||
|
Margin="0,5,0,5"
|
||||||
|
VerticalContentAlignment="Center"
|
||||||
|
ToolTip="Введите для поиска"
|
||||||
|
TextChanged="SearchTextBox_TextChanged"/>
|
||||||
|
|
||||||
|
<!-- Поле для выбора сотрудника -->
|
||||||
|
<Label Grid.Row="1" Grid.Column="0"
|
||||||
|
Content="Выберите сотрудника" Foreground="White" HorizontalAlignment="Right" Margin="0,0,10,0" VerticalContentAlignment="Center"/>
|
||||||
|
<ComboBox x:Name="EmployeeComboBox" Grid.Row="1" Grid.Column="1"
|
||||||
|
Width="400" Height="30"
|
||||||
|
VerticalAlignment="Top"
|
||||||
|
ToolTip="Выберите сотрудника"
|
||||||
|
SelectionChanged="EmployeeComboBox_SelectionChanged" />
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<!-- Блок редактирования -->
|
||||||
|
<Grid Grid.Row="1" Margin="0,0,0,0">
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="*" />
|
||||||
|
<ColumnDefinition Width="*" />
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
|
<!-- Поля редактирования -->
|
||||||
|
<StackPanel Grid.Row="0" Grid.Column="0" Margin="10">
|
||||||
|
<Label Content="Название работы" Foreground="White" HorizontalAlignment="Center"/>
|
||||||
|
<TextBox x:Name="JobNameTextBox" Width="250" Height="40"
|
||||||
|
Style="{StaticResource RoundedTextBoxStyle}" ToolTip="Введите название работы" />
|
||||||
|
</StackPanel>
|
||||||
|
<StackPanel Grid.Row="0" Grid.Column="1" Margin="10">
|
||||||
|
<Label Content="Дата начала работы" Foreground="White" HorizontalAlignment="Center"/>
|
||||||
|
<DatePicker x:Name="StartJobPicker" Width="250" Height="40"
|
||||||
|
ToolTip="Выберите дату начала" />
|
||||||
|
</StackPanel>
|
||||||
|
<StackPanel Grid.Row="1" Grid.Column="0" Margin="10">
|
||||||
|
<Label Content="Дата окончания работы" Foreground="White" HorizontalAlignment="Center"/>
|
||||||
|
<DatePicker x:Name="EndJobPicker" Width="250" Height="40"
|
||||||
|
ToolTip="Выберите дату окончания" />
|
||||||
|
</StackPanel>
|
||||||
|
<StackPanel Grid.Row="1" Grid.Column="1" Margin="10">
|
||||||
|
<Label Content="Частичная занятость" Foreground="White" HorizontalAlignment="Center"/>
|
||||||
|
<TextBox x:Name="PartTimeTextBox" Width="250" Height="40"
|
||||||
|
Style="{StaticResource RoundedTextBoxStyle}" ToolTip="Укажите частичную занятость" />
|
||||||
|
</StackPanel>
|
||||||
|
<StackPanel Grid.Row="2" Grid.Column="0" Margin="10">
|
||||||
|
<Label Content="Ставка" Foreground="White" HorizontalAlignment="Center"/>
|
||||||
|
<TextBox x:Name="BidTextBox" Width="250" Height="40"
|
||||||
|
Style="{StaticResource RoundedTextBoxStyle}" ToolTip="Введите ставку" />
|
||||||
|
</StackPanel>
|
||||||
|
<StackPanel Grid.Row="2" Grid.Column="1" Margin="10">
|
||||||
|
<Label Content="Физическое лицо" Foreground="White" HorizontalAlignment="Center"/>
|
||||||
|
<ComboBox x:Name="PhysicalPersonComboBox" Width="250" Height="40"
|
||||||
|
ToolTip="Выберите физическое лицо" />
|
||||||
|
</StackPanel>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<!-- Кнопка сохранения -->
|
||||||
|
<Button Grid.Row="2" Content="Сохранить изменения"
|
||||||
|
Width="250" Height="40"
|
||||||
|
VerticalAlignment="Bottom"
|
||||||
|
Style="{StaticResource RoundedButtonStyle}"
|
||||||
|
Background="#004890" Foreground="#FFFFFF"
|
||||||
|
Click="SaveButton_Click"
|
||||||
|
HorizontalAlignment="Center" Margin="0,10,0,0"/>
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
@ -1,4 +1,5 @@
|
|||||||
using EmployeeManagmentContracts.BusinessLogicContracts;
|
using EmployeeManagmentContracts.BusinessLogicContracts;
|
||||||
|
using EmployeeManagmentContracts.ViewModels;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -22,11 +23,97 @@ namespace EmployeeManagmentView.Employee
|
|||||||
{
|
{
|
||||||
|
|
||||||
private readonly IEmployeeLogic _employeeLogic;
|
private readonly IEmployeeLogic _employeeLogic;
|
||||||
|
private readonly IPhisicalPersonLogic _physicalPersonLogic;
|
||||||
|
private List<EmployeeViewModel> _employees;
|
||||||
|
|
||||||
public EditEmployeeWindow(IEmployeeLogic employeeLogic)
|
public EditEmployeeWindow(IEmployeeLogic employeeLogic, IPhisicalPersonLogic physicalPersonLogic)
|
||||||
{
|
{
|
||||||
_employeeLogic = employeeLogic;
|
_employeeLogic = employeeLogic;
|
||||||
|
_physicalPersonLogic = physicalPersonLogic;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
LoadEmployees();
|
||||||
|
LoadPhysicalPersons();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadEmployees()
|
||||||
|
{
|
||||||
|
_employees = _employeeLogic.GetFullList();
|
||||||
|
EmployeeComboBox.ItemsSource = _employees;
|
||||||
|
EmployeeComboBox.DisplayMemberPath = "NameJob";
|
||||||
|
EmployeeComboBox.SelectedValuePath = "Id";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadPhysicalPersons()
|
||||||
|
{
|
||||||
|
var physicalPersons = _physicalPersonLogic.GetFullList();
|
||||||
|
PhysicalPersonComboBox.ItemsSource = physicalPersons;
|
||||||
|
PhysicalPersonComboBox.DisplayMemberPath = "FullNameWithBirthday";
|
||||||
|
PhysicalPersonComboBox.SelectedValuePath = "Id";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void EmployeeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (EmployeeComboBox.SelectedValue is int selectedEmployeeId)
|
||||||
|
{
|
||||||
|
LoadEmployee(selectedEmployeeId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadEmployee(int employeeId)
|
||||||
|
{
|
||||||
|
var employee = _employeeLogic.GetElement(employeeId);
|
||||||
|
if (employee != null)
|
||||||
|
{
|
||||||
|
JobNameTextBox.Text = employee.NameJob;
|
||||||
|
StartJobPicker.SelectedDate = employee.StartJob;
|
||||||
|
EndJobPicker.SelectedDate = employee.EndJob;
|
||||||
|
PartTimeTextBox.Text = employee.PartTimeJob;
|
||||||
|
BidTextBox.Text = employee.Bid.ToString();
|
||||||
|
PhysicalPersonComboBox.SelectedValue = employee.PhysicalPersonsId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SearchTextBox_TextChanged(object sender, TextChangedEventArgs e)
|
||||||
|
{
|
||||||
|
var searchText = SearchTextBox.Text.ToLower();
|
||||||
|
var filteredEmployees = _employees
|
||||||
|
.Where(emp => emp.NameJob.ToLower().Contains(searchText) ||
|
||||||
|
emp.PhysicalPersonName?.ToLower().Contains(searchText) == true)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
EmployeeComboBox.ItemsSource = filteredEmployees;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SaveButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (EmployeeComboBox.SelectedValue is int selectedEmployeeId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var updatedEmployee = new EmployeeViewModel
|
||||||
|
{
|
||||||
|
Id = selectedEmployeeId,
|
||||||
|
NameJob = JobNameTextBox.Text,
|
||||||
|
StartJob = StartJobPicker.SelectedDate,
|
||||||
|
EndJob = EndJobPicker.SelectedDate,
|
||||||
|
PartTimeJob = PartTimeTextBox.Text,
|
||||||
|
Bid = float.Parse(BidTextBox.Text),
|
||||||
|
PhysicalPersonsId = PhysicalPersonComboBox.SelectedValue as int?
|
||||||
|
};
|
||||||
|
|
||||||
|
_employeeLogic.Update(updatedEmployee);
|
||||||
|
MessageBox.Show("Данные успешно обновлены!");
|
||||||
|
this.Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"Ошибка: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите сотрудника перед сохранением!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -74,7 +74,7 @@ namespace EmployeeManagmentView.Employee
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var editWindow = new EditEmployeeWindow(_employeeLogic);
|
var editWindow = new EditEmployeeWindow(_employeeLogic, _phisicalPersonLogic);
|
||||||
editWindow.Show();
|
editWindow.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,43 @@
|
|||||||
<Window x:Class="EmployeeManagmentView.Employee.ViewEmployeeWindow"
|
<Window x:Class="EmployeeManagmentView.Employee.ViewEmployeeWindow"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
Title="Удаление сотрудников"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
Height="500" Width="800"
|
||||||
xmlns:local="clr-namespace:EmployeeManagmentView.Employee"
|
ResizeMode="NoResize"
|
||||||
mc:Ignorable="d"
|
WindowStartupLocation="CenterScreen"
|
||||||
Title="ViewEmployeeWindow" Height="450" Width="800">
|
Background="#0D2D4F">
|
||||||
|
|
||||||
<Grid>
|
<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,30"
|
||||||
|
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>
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
@ -1,4 +1,5 @@
|
|||||||
using EmployeeManagmentContracts.BusinessLogicContracts;
|
using EmployeeManagmentContracts.BusinessLogicContracts;
|
||||||
|
using EmployeeManagmentContracts.ViewModels;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -22,11 +23,45 @@ namespace EmployeeManagmentView.Employee
|
|||||||
{
|
{
|
||||||
|
|
||||||
private readonly IEmployeeLogic _employeeLogic;
|
private readonly IEmployeeLogic _employeeLogic;
|
||||||
|
private IEnumerable<EmployeeViewModel> _allEmployees; // Список сотрудников для фильтрации
|
||||||
|
|
||||||
public ViewEmployeeWindow(IEmployeeLogic employeeLogic)
|
public ViewEmployeeWindow(IEmployeeLogic employeeLogic)
|
||||||
{
|
{
|
||||||
_employeeLogic = employeeLogic;
|
_employeeLogic = employeeLogic;
|
||||||
InitializeComponent();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user