Сделано удаление и почти редактирование

This commit is contained in:
maksim 2024-12-01 17:32:41 +04:00
parent 41e4e00fd2
commit 1c04d20d13
10 changed files with 465 additions and 37 deletions

View File

@ -1,12 +1,51 @@
<Window x:Class="EmployeeManagmentView.Employee.Salary.DeleteSalaryWindow"
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.Salary"
mc:Ignorable="d"
Title="DeleteSalaryWindow" Height="450" Width="800">
<Grid>
Title="Управление зарплатами"
Height="600" 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="SalariesDataGrid"
Margin="20,100,20,80"
AutoGenerateColumns="False"
Style="{StaticResource RoundedDataGridStyle}">
<DataGrid.Columns>
<DataGridTextColumn Header="Часы работы" Binding="{Binding CountHours}" Width="*" />
<DataGridTextColumn Header="Цена за час" Binding="{Binding PriceHour, StringFormat={}{0:F2}}" Width="*" />
<DataGridTextColumn Header="Премия" Binding="{Binding Premium, StringFormat={}{0:F2}}" Width="*" />
<DataGridTextColumn Header="Дата" Binding="{Binding Date, StringFormat=dd.MM.yyyy}" Width="*" />
<DataGridTextColumn Header="Сотрудник" Binding="{Binding EmployeeName}" Width="*" />
</DataGrid.Columns>
</DataGrid>
<!-- Кнопка добавления/редактирования -->
<Button Content="Удалить"
HorizontalAlignment="Center" VerticalAlignment="Bottom"
Width="150" Height="40"
Margin="0,0,0,20"
Background="#004890"
Foreground="White"
Style="{StaticResource RoundedButtonStyle}"
Click="DeleteButton_Click" />
</Grid>
</Window>

View File

@ -1,4 +1,5 @@
using EmployeeManagmentContracts.BusinessLogicContracts;
using EmployeeManagmentContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
@ -22,11 +23,59 @@ namespace EmployeeManagmentView.Employee.Salary
{
private readonly ISalaryLogic _salaryLogic;
private IEnumerable<SalaryViewModel> _allSalaries;
public DeleteSalaryWindow(ISalaryLogic salaryLogic)
{
_salaryLogic = salaryLogic;
InitializeComponent();
LoadSalaries();
}
private void LoadSalaries()
{
_allSalaries = _salaryLogic.GetFullList(); // Загрузка всех данных
SalariesDataGrid.ItemsSource = _allSalaries;
}
private void DeleteButton_Click(object sender, RoutedEventArgs e)
{
if (SalariesDataGrid.SelectedItem is SalaryViewModel selectedSalary)
{
// Удаление зарплаты
_salaryLogic.Delete(selectedSalary.Id);
MessageBox.Show("Зарплата успешно удалена!");
LoadSalaries(); // Перезагрузка данных после удаления
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))
{
// Отображаем все записи
SalariesDataGrid.ItemsSource = _allSalaries;
}
else
{
// Фильтрация по всем полям сущности
var filteredList = _allSalaries.Where(sal =>
(sal.EmployeeName?.ToLower().Contains(query) ?? false) ||
sal.CountHours.ToString().Contains(query) ||
sal.PriceHour.ToString().Contains(query) ||
(sal.Premium.HasValue && sal.Premium.Value.ToString().Contains(query)) ||
(sal.Date.HasValue && sal.Date.Value.ToString("dd.MM.yyyy").Contains(query))
).ToList();
SalariesDataGrid.ItemsSource = filteredList;
}
}
}
}

View File

@ -1,12 +1,99 @@
<Window x:Class="EmployeeManagmentView.Employee.Salary.EditSalaryWindow"
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.Salary"
mc:Ignorable="d"
Title="EditSalaryWindow" Height="450" Width="800">
<Grid>
Title="Редактирование зарплаты"
Height="600" Width="600"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"
Background="#0D2D4F">
<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="Auto" />
<!-- Поля редактирования зарплаты -->
<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"/>
<ComboBox x:Name="EmployeeComboBox" Grid.Row="0" 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="CountHoursTextBox" Width="250" Height="40"
Style="{StaticResource RoundedTextBoxStyle}" ToolTip="Введите количество часов" />
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" Margin="10">
<Label Content="Цена за час" Foreground="White" HorizontalAlignment="Center"/>
<TextBox x:Name="PriceHourTextBox" Width="250" Height="40"
Style="{StaticResource RoundedTextBoxStyle}" ToolTip="Введите цену за час" />
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="0" Margin="10">
<Label Content="Премия" Foreground="White" HorizontalAlignment="Center"/>
<TextBox x:Name="PremiumTextBox" Width="250" Height="40"
Style="{StaticResource RoundedTextBoxStyle}" ToolTip="Введите премию" />
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="1" Margin="10">
<Label Content="Дата" Foreground="White" HorizontalAlignment="Center"/>
<DatePicker x:Name="DatePicker" Width="250" Height="40"
ToolTip="Выберите дату" />
</StackPanel>
<StackPanel Grid.Row="2" Grid.Column="0" Margin="10">
<Label Content="Выплачено?" Foreground="White" HorizontalAlignment="Center"/>
<CheckBox x:Name="PassedCheckBox" />
</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>
</Window>

View File

@ -1,4 +1,5 @@
using EmployeeManagmentContracts.BusinessLogicContracts;
using EmployeeManagmentContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
@ -22,11 +23,58 @@ namespace EmployeeManagmentView.Employee.Salary
{
private readonly ISalaryLogic _salaryLogic;
private readonly IEmployeeLogic _employeeLogic;
private List<EmployeeViewModel> _employees;
public EditSalaryWindow(ISalaryLogic salaryLogic)
public EditSalaryWindow(ISalaryLogic salaryLogic, IEmployeeLogic employeeLogic)
{
_salaryLogic = salaryLogic;
_employeeLogic = employeeLogic;
InitializeComponent();
LoadEmployees();
}
private void LoadEmployees()
{
_employees = _employeeLogic.GetFullList();
EmployeeComboBox.ItemsSource = _employees;
EmployeeComboBox.DisplayMemberPath = "NameJob";
EmployeeComboBox.SelectedValuePath = "Id";
}
private void EmployeeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
if (EmployeeComboBox.SelectedValue is int selectedEmployeeId)
{
try
{
var newSalary = new SalaryViewModel
{
CountHours = int.Parse(CountHoursTextBox.Text),
PriceHour = float.Parse(PriceHourTextBox.Text),
Premium = string.IsNullOrEmpty(PremiumTextBox.Text) ? (float?)null : float.Parse(PremiumTextBox.Text),
Date = DatePicker.SelectedDate,
Passed = PassedCheckBox.IsChecked ?? false,
EmployeeId = selectedEmployeeId
};
_salaryLogic.Insert(newSalary);
MessageBox.Show("Зарплата успешно добавлена!");
this.Close();
}
catch (Exception ex)
{
MessageBox.Show($"Ошибка: {ex.Message}");
}
}
else
{
MessageBox.Show("Выберите сотрудника перед сохранением!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Warning);
}
}
}
}

View File

@ -77,7 +77,7 @@ namespace EmployeeManagmentView.Employee.Salary
}
}
var editWindow = new EditSalaryWindow(_salaryLogic);
var editWindow = new EditSalaryWindow(_salaryLogic, _employeeLogic);
editWindow.Show();
}

View File

@ -1,12 +1,49 @@
<Window x:Class="EmployeeManagmentView.Employee.Vacation.DeleteVacationWindow"
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.Vacation"
mc:Ignorable="d"
Title="DeleteVacationWindow" Height="450" Width="800">
<Grid>
Title="Управление отпусками"
Height="600" 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="VacationsDataGrid"
Margin="20,100,20,80"
AutoGenerateColumns="False"
Style="{StaticResource RoundedDataGridStyle}">
<DataGrid.Columns>
<DataGridTextColumn Header="Дата начала" Binding="{Binding StartData, StringFormat=dd.MM.yyyy}" Width="*" />
<DataGridTextColumn Header="Дата окончания" Binding="{Binding EndData, StringFormat=dd.MM.yyyy}" Width="*" />
<DataGridTextColumn Header="Сотрудник" Binding="{Binding EmployeeName}" Width="*" />
</DataGrid.Columns>
</DataGrid>
<!-- Удалить -->
<Button Content="Удалить"
HorizontalAlignment="Center" VerticalAlignment="Bottom"
Width="150" Height="40"
Margin="0,0,0,20"
Background="#004890"
Foreground="White"
Style="{StaticResource RoundedButtonStyle}"
Click="DeleteButton_Click" />
</Grid>
</Window>

View File

@ -1,4 +1,5 @@
using EmployeeManagmentContracts.BusinessLogicContracts;
using EmployeeManagmentContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
@ -20,13 +21,58 @@ namespace EmployeeManagmentView.Employee.Vacation
/// </summary>
public partial class DeleteVacationWindow : Window
{
private readonly IVacationLogic _vacationLogic;
private IEnumerable<VacationViewModel> _allVacations;
public DeleteVacationWindow(IVacationLogic vacationLogic)
{
_vacationLogic = vacationLogic;
InitializeComponent();
LoadVacations();
}
private void LoadVacations()
{
_allVacations = _vacationLogic.GetFullList(); // Загрузка всех данных
VacationsDataGrid.ItemsSource = _allVacations;
}
private void DeleteButton_Click(object sender, RoutedEventArgs e)
{
if (VacationsDataGrid.SelectedItem is VacationViewModel selectedVacation)
{
// Удаление отпуска
_vacationLogic.Delete(selectedVacation.Id);
MessageBox.Show("Отпуск успешно удален!");
LoadVacations(); // Перезагрузка данных после удаления
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))
{
// Отображаем все записи
VacationsDataGrid.ItemsSource = _allVacations;
}
else
{
// Фильтрация по всем полям сущности
var filteredList = _allVacations.Where(vac =>
(vac.EmployeeName?.ToLower().Contains(query) ?? false) ||
(vac.StartData.ToString("dd.MM.yyyy").Contains(query)) ||
(vac.EndData.ToString("dd.MM.yyyy").Contains(query))
).ToList();
VacationsDataGrid.ItemsSource = filteredList;
}
}
}
}

View File

@ -1,12 +1,87 @@
<Window x:Class="EmployeeManagmentView.Employee.Vacation.EditVacationWindow"
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.Vacation"
mc:Ignorable="d"
Title="EditVacationWindow" Height="450" Width="800">
<Grid>
Title="Редактирование отпуска"
Height="600" Width="600"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"
Background="#0D2D4F">
<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="Auto" />
<!-- Поля редактирования отпуска -->
<RowDefinition Height="5*" />
<!-- Кнопка сохранения -->
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- Блок выбора сотрудника -->
<Grid Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,10">
<Grid.RowDefinitions>
<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"/>
<ComboBox x:Name="EmployeeComboBox" Grid.Row="0" 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" />
</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"/>
<DatePicker x:Name="StartDatePicker" Width="250" Height="40"
ToolTip="Выберите дату начала" />
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" Margin="10">
<Label Content="Дата окончания" Foreground="White" HorizontalAlignment="Center"/>
<DatePicker x:Name="EndDatePicker" Width="250" Height="40"
ToolTip="Выберите дату окончания" />
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="0" Margin="10">
<Label Content="Выплачено?" Foreground="White" HorizontalAlignment="Center"/>
<CheckBox x:Name="PassedCheckBox" />
</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>
</Window>

View File

@ -1,4 +1,5 @@
using EmployeeManagmentContracts.BusinessLogicContracts;
using EmployeeManagmentContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
@ -22,11 +23,57 @@ namespace EmployeeManagmentView.Employee.Vacation
{
private readonly IVacationLogic _vacationLogic;
private readonly IEmployeeLogic _employeeLogic;
private List<EmployeeViewModel> _employees;
public EditVacationWindow(IVacationLogic vacationLogic)
public EditVacationWindow(IVacationLogic vacationLogic, IEmployeeLogic employeeLogic)
{
_vacationLogic = vacationLogic;
_employeeLogic = employeeLogic;
InitializeComponent();
LoadEmployees();
}
private void LoadEmployees()
{
_employees = _employeeLogic.GetFullList();
EmployeeComboBox.ItemsSource = _employees;
EmployeeComboBox.DisplayMemberPath = "NameJob";
EmployeeComboBox.SelectedValuePath = "Id";
}
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
if (EmployeeComboBox.SelectedValue is int selectedEmployeeId)
{
try
{
var newVacation = new VacationViewModel
{
StartData = StartDatePicker.SelectedDate ?? DateTime.MinValue,
EndData = EndDatePicker.SelectedDate ?? DateTime.MinValue,
Passed = PassedCheckBox.IsChecked ?? false,
EmployeeId = selectedEmployeeId
};
_vacationLogic.Insert(newVacation);
MessageBox.Show("Отпуск успешно добавлен!");
this.Close();
}
catch (Exception ex)
{
MessageBox.Show($"Ошибка: {ex.Message}");
}
}
else
{
MessageBox.Show("Выберите сотрудника перед сохранением!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Warning);
}
}
private void EmployeeComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
}
}

View File

@ -75,7 +75,7 @@ namespace EmployeeManagmentView.Employee.Vacation
}
}
var editWindow = new EditVacationWindow(_vacationLogic);
var editWindow = new EditVacationWindow(_vacationLogic, _employeeLogic);
editWindow.Show();
}