PIbd-42_Kashin_M.I_CPO_Cour.../EmployeeManagmentView/Employee/Vacation/EditVacationWindow.xaml.cs

79 lines
2.6 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<EmployeeViewModel> _employees;
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)
{
}
}
}