2024-12-01 16:34:36 +04:00
|
|
|
|
using EmployeeManagmentContracts.BusinessLogicContracts;
|
2024-12-01 17:32:41 +04:00
|
|
|
|
using EmployeeManagmentContracts.ViewModels;
|
2024-12-01 16:34:36 +04:00
|
|
|
|
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.Salary
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Логика взаимодействия для EditSalaryWindow.xaml
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class EditSalaryWindow : Window
|
|
|
|
|
{
|
2024-12-01 18:08:18 +04:00
|
|
|
|
private readonly ISalaryLogic _salaryLogic; // Логика для работы с зарплатами
|
|
|
|
|
private readonly IEmployeeLogic _employeeLogic; // Логика для работы с сотрудниками
|
|
|
|
|
private List<SalaryViewModel> _salaries;
|
|
|
|
|
private List<EmployeeViewModel> _employees; // Список сотрудников
|
2024-12-01 16:34:36 +04:00
|
|
|
|
|
2024-12-01 17:32:41 +04:00
|
|
|
|
public EditSalaryWindow(ISalaryLogic salaryLogic, IEmployeeLogic employeeLogic)
|
2024-12-01 16:34:36 +04:00
|
|
|
|
{
|
|
|
|
|
_salaryLogic = salaryLogic;
|
2024-12-01 17:32:41 +04:00
|
|
|
|
_employeeLogic = employeeLogic;
|
2024-12-01 16:34:36 +04:00
|
|
|
|
InitializeComponent();
|
2024-12-01 18:08:18 +04:00
|
|
|
|
LoadSalaries();
|
2024-12-01 17:32:41 +04:00
|
|
|
|
LoadEmployees();
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-01 18:08:18 +04:00
|
|
|
|
private void LoadSalaries()
|
|
|
|
|
{
|
|
|
|
|
_salaries = _salaryLogic.GetFullList();
|
|
|
|
|
SalaryComboBox.ItemsSource = _salaries;
|
|
|
|
|
SalaryComboBox.DisplayMemberPath = "EmployeeName";
|
|
|
|
|
SalaryComboBox.SelectedValuePath = "Id";
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-01 17:32:41 +04:00
|
|
|
|
private void LoadEmployees()
|
|
|
|
|
{
|
2024-12-01 18:08:18 +04:00
|
|
|
|
_employees = _employeeLogic.GetFullList(); // Получение списка всех сотрудников
|
2024-12-01 17:32:41 +04:00
|
|
|
|
EmployeeComboBox.ItemsSource = _employees;
|
2024-12-01 18:08:18 +04:00
|
|
|
|
EmployeeComboBox.DisplayMemberPath = "FullName"; // Предполагается, что у сотрудника есть свойство FullName
|
2024-12-01 17:32:41 +04:00
|
|
|
|
EmployeeComboBox.SelectedValuePath = "Id";
|
|
|
|
|
}
|
2024-12-01 18:08:18 +04:00
|
|
|
|
|
|
|
|
|
private void SalaryComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
2024-12-01 17:32:41 +04:00
|
|
|
|
{
|
2024-12-01 18:08:18 +04:00
|
|
|
|
if (SalaryComboBox.SelectedValue is int selectedSalaryId)
|
|
|
|
|
{
|
|
|
|
|
LoadSalary(selectedSalaryId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadSalary(int salaryId)
|
|
|
|
|
{
|
|
|
|
|
var salary = _salaryLogic.GetElement(salaryId);
|
|
|
|
|
if (salary != null)
|
|
|
|
|
{
|
|
|
|
|
CountHoursTextBox.Text = salary.CountHours.ToString();
|
|
|
|
|
PriceHourTextBox.Text = salary.PriceHour.ToString();
|
|
|
|
|
PremiumTextBox.Text = salary.Premium?.ToString() ?? string.Empty;
|
|
|
|
|
DatePicker.SelectedDate = salary.Date;
|
|
|
|
|
PassedCheckBox.IsChecked = salary.Passed;
|
2024-12-01 17:32:41 +04:00
|
|
|
|
|
2024-12-01 18:08:18 +04:00
|
|
|
|
// Устанавливаем выбранного сотрудника
|
|
|
|
|
EmployeeComboBox.SelectedValue = salary.EmployeeId;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Зарплата не найдена", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SearchTextBox_TextChanged(object sender, TextChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var searchText = SearchTextBox.Text.ToLower();
|
|
|
|
|
var filteredSalaries = _salaries
|
|
|
|
|
.Where(sal => sal.EmployeeName.ToLower().Contains(searchText))
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
SalaryComboBox.ItemsSource = filteredSalaries;
|
2024-12-01 17:32:41 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SaveButton_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2024-12-01 18:08:18 +04:00
|
|
|
|
try
|
2024-12-01 17:32:41 +04:00
|
|
|
|
{
|
2024-12-01 18:08:18 +04:00
|
|
|
|
if (SalaryComboBox.SelectedValue is int selectedSalaryId)
|
2024-12-01 17:32:41 +04:00
|
|
|
|
{
|
2024-12-01 18:08:18 +04:00
|
|
|
|
var updatedSalary = new SalaryViewModel
|
2024-12-01 17:32:41 +04:00
|
|
|
|
{
|
2024-12-01 18:08:18 +04:00
|
|
|
|
Id = selectedSalaryId,
|
2024-12-01 17:32:41 +04:00
|
|
|
|
CountHours = int.Parse(CountHoursTextBox.Text),
|
|
|
|
|
PriceHour = float.Parse(PriceHourTextBox.Text),
|
2024-12-01 18:08:18 +04:00
|
|
|
|
Premium = float.TryParse(PremiumTextBox.Text, out var premium) ? premium : (float?)null,
|
|
|
|
|
Date = DatePicker.SelectedDate.Value.ToUniversalTime(),
|
2024-12-01 17:32:41 +04:00
|
|
|
|
Passed = PassedCheckBox.IsChecked ?? false,
|
2024-12-01 18:08:18 +04:00
|
|
|
|
EmployeeId = (int?)EmployeeComboBox.SelectedValue // Устанавливаем выбранного сотрудника
|
2024-12-01 17:32:41 +04:00
|
|
|
|
};
|
|
|
|
|
|
2024-12-01 18:08:18 +04:00
|
|
|
|
_salaryLogic.Update(updatedSalary);
|
|
|
|
|
|
|
|
|
|
MessageBox.Show("Зарплата успешно обновлена!");
|
2024-12-01 17:32:41 +04:00
|
|
|
|
this.Close();
|
|
|
|
|
}
|
2024-12-01 18:08:18 +04:00
|
|
|
|
else
|
2024-12-01 17:32:41 +04:00
|
|
|
|
{
|
2024-12-01 18:08:18 +04:00
|
|
|
|
MessageBox.Show("Выберите зарплату перед сохранением!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Warning);
|
2024-12-01 17:32:41 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-01 18:08:18 +04:00
|
|
|
|
catch (Exception ex)
|
2024-12-01 17:32:41 +04:00
|
|
|
|
{
|
2024-12-01 18:08:18 +04:00
|
|
|
|
MessageBox.Show($"Ошибка при сохранении данных: {ex.Message}", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
2024-12-01 17:32:41 +04:00
|
|
|
|
}
|
2024-12-01 16:34:36 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-01 17:32:41 +04:00
|
|
|
|
}
|