75 lines
2.5 KiB
C#
75 lines
2.5 KiB
C#
|
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
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Логика взаимодействия для AddEmployeeWindow.xaml
|
|||
|
/// </summary>
|
|||
|
public partial class AddEmployeeWindow : Window
|
|||
|
{
|
|||
|
|
|||
|
private readonly IEmployeeLogic _employeeLogic;
|
|||
|
private readonly IPhisicalPersonLogic _phisicalPersonLogic;
|
|||
|
|
|||
|
public AddEmployeeWindow(IEmployeeLogic employeeLogic, IPhisicalPersonLogic phisicalPersonLogic)
|
|||
|
{
|
|||
|
_employeeLogic = employeeLogic;
|
|||
|
_phisicalPersonLogic = phisicalPersonLogic;
|
|||
|
InitializeComponent();
|
|||
|
LoadPhysicalPersons();
|
|||
|
}
|
|||
|
|
|||
|
private void LoadPhysicalPersons()
|
|||
|
{
|
|||
|
if (PhysicalPersonComboBox == null)
|
|||
|
{
|
|||
|
throw new InvalidOperationException("PhysicalPersonComboBox не инициализирован.");
|
|||
|
}
|
|||
|
|
|||
|
var persons = _phisicalPersonLogic.GetFullList();
|
|||
|
PhysicalPersonComboBox.ItemsSource = persons;
|
|||
|
PhysicalPersonComboBox.DisplayMemberPath = "Name";
|
|||
|
PhysicalPersonComboBox.SelectedValuePath = "Id";
|
|||
|
}
|
|||
|
|
|||
|
private void SaveButton_Click(object sender, RoutedEventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var model = new EmployeeViewModel
|
|||
|
{
|
|||
|
NameJob = JobNameTextBox.Text,
|
|||
|
StartJob = StartDatePicker.SelectedDate.Value.ToUniversalTime(),
|
|||
|
EndJob = EndDatePicker.SelectedDate.Value.ToUniversalTime(),
|
|||
|
Bid = float.Parse(BidTextBox.Text),
|
|||
|
PartTimeJob = PartTimeJobTextBox.Text,
|
|||
|
PhysicalPersonsId = (int?)PhysicalPersonComboBox.SelectedValue
|
|||
|
};
|
|||
|
|
|||
|
_employeeLogic.Insert(model);
|
|||
|
MessageBox.Show("Данные сотрудника успешно сохранены!");
|
|||
|
Close();
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
MessageBox.Show($"Ошибка: {ex.Message}");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|