109 lines
4.0 KiB
C#
109 lines
4.0 KiB
C#
using EmployeeManagmentContracts.BusinessLogicContracts;
|
||
using EmployeeManagmentContracts.ViewModels;
|
||
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.Vacation
|
||
{
|
||
/// <summary>
|
||
/// Логика взаимодействия для EditVacationWindow.xaml
|
||
/// </summary>
|
||
public partial class EditVacationWindow : Window
|
||
{
|
||
private readonly IVacationLogic _vacationLogic; // Логика для работы с отпусками
|
||
private readonly IEmployeeLogic _employeeLogic; // Логика для работы с сотрудниками
|
||
private List<VacationViewModel> _vacations;
|
||
private List<EmployeeViewModel> _employees; // Список сотрудников
|
||
|
||
public EditVacationWindow(IVacationLogic vacationLogic, IEmployeeLogic employeeLogic)
|
||
{
|
||
_vacationLogic = vacationLogic;
|
||
_employeeLogic = employeeLogic;
|
||
InitializeComponent();
|
||
LoadVacations();
|
||
}
|
||
|
||
private void LoadVacations()
|
||
{
|
||
_vacations = _vacationLogic.GetFullList();
|
||
VacationComboBox.ItemsSource = _vacations;
|
||
VacationComboBox.DisplayMemberPath = "EmployeeName";
|
||
VacationComboBox.SelectedValuePath = "Id";
|
||
}
|
||
|
||
private void VacationComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||
{
|
||
if (VacationComboBox.SelectedValue is int selectedVacationId)
|
||
{
|
||
LoadVacation(selectedVacationId);
|
||
}
|
||
}
|
||
|
||
private void LoadVacation(int vacationId)
|
||
{
|
||
var vacation = _vacationLogic.GetElement(vacationId);
|
||
if (vacation != null)
|
||
{
|
||
StartDatePicker.SelectedDate = vacation.StartData;
|
||
EndDatePicker.SelectedDate = vacation.EndData;
|
||
PassedCheckBox.IsChecked = vacation.Passed;
|
||
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Отпуск не найден", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
||
}
|
||
}
|
||
|
||
private void SearchTextBox_TextChanged(object sender, TextChangedEventArgs e)
|
||
{
|
||
var searchText = SearchTextBox.Text.ToLower();
|
||
var filteredVacations = _vacations
|
||
.Where(vac => vac.EmployeeName.ToLower().Contains(searchText))
|
||
.ToList();
|
||
|
||
VacationComboBox.ItemsSource = filteredVacations;
|
||
}
|
||
|
||
private void SaveButton_Click(object sender, RoutedEventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (VacationComboBox.SelectedValue is int selectedVacationId)
|
||
{
|
||
var updatedVacation = new VacationViewModel
|
||
{
|
||
Id = selectedVacationId,
|
||
StartData = StartDatePicker.SelectedDate.Value.ToUniversalTime(),
|
||
EndData = EndDatePicker.SelectedDate.Value.ToUniversalTime(),
|
||
Passed = PassedCheckBox.IsChecked ?? false,
|
||
};
|
||
|
||
_vacationLogic.Update(updatedVacation);
|
||
|
||
MessageBox.Show("Отпуск успешно обновлен!");
|
||
this.Close();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Выберите отпуск перед сохранением!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show($"Ошибка при сохранении данных: {ex.Message}", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
||
}
|
||
}
|
||
}
|
||
} |