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

68 lines
2.2 KiB
C#
Raw Normal View History

using EmployeeManagmentBusinessLogic.BusinessLogic;
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>
/// Логика взаимодействия для AddVacationWindow.xaml
/// </summary>
public partial class AddVacationWindow : Window
{
private readonly IVacationLogic _vacationLogic;
private readonly IEmployeeLogic _employeeLogic;
public AddVacationWindow(IVacationLogic vacationLogic, IEmployeeLogic employeeLogic)
{
_vacationLogic = vacationLogic;
_employeeLogic = employeeLogic;
InitializeComponent();
LoadEmployees();
}
private void LoadEmployees()
{
var employees = _employeeLogic.GetFullList();
EmployeeComboBox.ItemsSource = employees;
EmployeeComboBox.DisplayMemberPath = "NameJob";
EmployeeComboBox.SelectedValuePath = "Id";
}
private void SaveButton_Click(object sender, RoutedEventArgs e)
{
try
{
var vacation = new VacationViewModel
{
StartData = StartDatePicker.SelectedDate.Value.ToUniversalTime(),
EndData = EndDatePicker.SelectedDate.Value.ToUniversalTime(),
Passed = PassedCheckBox.IsChecked ?? false,
EmployeeId = (int?)EmployeeComboBox.SelectedValue
};
_vacationLogic.Insert(vacation);
MessageBox.Show("Отпуск успешно сохранен!");
Close();
}
catch (Exception ex)
{
MessageBox.Show($"Ошибка: {ex.Message}");
}
}
}
}