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;
|
2024-12-07 23:36:29 +04:00
|
|
|
|
using System.Security.AccessControl;
|
2024-12-01 16:34:36 +04:00
|
|
|
|
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
|
|
|
|
|
{
|
2024-12-01 18:08:18 +04:00
|
|
|
|
private readonly IVacationLogic _vacationLogic; // Логика для работы с отпусками
|
|
|
|
|
private readonly IEmployeeLogic _employeeLogic; // Логика для работы с сотрудниками
|
2024-12-07 23:36:29 +04:00
|
|
|
|
private readonly IPhisicalPersonLogic _phisicalPersonLogic;
|
2024-12-01 18:08:18 +04:00
|
|
|
|
private List<VacationViewModel> _vacations;
|
|
|
|
|
private List<EmployeeViewModel> _employees; // Список сотрудников
|
2024-12-01 16:34:36 +04:00
|
|
|
|
|
2024-12-07 23:36:29 +04:00
|
|
|
|
public EditVacationWindow(IVacationLogic vacationLogic, IEmployeeLogic employeeLogic, IPhisicalPersonLogic phisicalPersonLogic)
|
2024-12-01 16:34:36 +04:00
|
|
|
|
{
|
|
|
|
|
_vacationLogic = vacationLogic;
|
2024-12-01 17:32:41 +04:00
|
|
|
|
_employeeLogic = employeeLogic;
|
2024-12-07 23:36:29 +04:00
|
|
|
|
_phisicalPersonLogic = phisicalPersonLogic;
|
2024-12-01 16:34:36 +04:00
|
|
|
|
InitializeComponent();
|
2024-12-01 18:08:18 +04:00
|
|
|
|
LoadVacations();
|
2024-12-01 17:32:41 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-01 18:08:18 +04:00
|
|
|
|
private void LoadVacations()
|
|
|
|
|
{
|
|
|
|
|
_vacations = _vacationLogic.GetFullList();
|
|
|
|
|
VacationComboBox.ItemsSource = _vacations;
|
2024-12-07 23:59:01 +04:00
|
|
|
|
VacationComboBox.DisplayMemberPath = "DisplayName";
|
2024-12-01 18:08:18 +04:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-07 23:36:29 +04:00
|
|
|
|
private void NameTextBox_PreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// Разрешаем только буквы
|
|
|
|
|
e.Handled = !char.IsLetter(e.Text, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void NameTextBox_TextChanged(object sender, TextChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var textBox = sender as TextBox;
|
|
|
|
|
if (textBox == null) return;
|
|
|
|
|
|
|
|
|
|
// Получаем текущий текст
|
|
|
|
|
string currentText = textBox.Text;
|
|
|
|
|
|
|
|
|
|
// Если текст не пустой, преобразуем первую букву в заглавную, а остальные в строчные
|
|
|
|
|
if (!string.IsNullOrEmpty(currentText))
|
|
|
|
|
{
|
|
|
|
|
// Разбиваем строку по пробелам, чтобы обрабатывать каждое слово отдельно
|
|
|
|
|
var words = currentText.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < words.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
// Преобразуем первую букву в заглавную, а остальные в строчные
|
|
|
|
|
words[i] = char.ToUpper(words[i][0]) + words[i].Substring(1).ToLower();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Объединяем слова обратно в строку и обновляем текст
|
|
|
|
|
textBox.Text = string.Join(" ", words);
|
|
|
|
|
|
|
|
|
|
// Устанавливаем курсор в конец текста
|
|
|
|
|
textBox.SelectionStart = textBox.Text.Length;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void TelephoneTextBox_PreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
e.Handled = !char.IsDigit(e.Text, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TelephoneTextBox_TextChanged(object sender, TextChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var textBox = sender as TextBox;
|
|
|
|
|
if (textBox == null) return;
|
|
|
|
|
|
|
|
|
|
// Удаляем все символы, кроме цифр
|
|
|
|
|
string rawInput = new string(textBox.Text.Where(char.IsDigit).ToArray());
|
|
|
|
|
|
|
|
|
|
// Добавляем "7" по умолчанию
|
|
|
|
|
if (!rawInput.StartsWith("7"))
|
|
|
|
|
rawInput = "7" + rawInput;
|
|
|
|
|
|
|
|
|
|
if (rawInput.Length > 11) rawInput = rawInput.Substring(0, 11);
|
|
|
|
|
|
|
|
|
|
// Форматируем как +7 (XXX) XXX-XX-XX
|
|
|
|
|
if (rawInput.Length <= 1)
|
|
|
|
|
textBox.Text = "+7 ";
|
|
|
|
|
else if (rawInput.Length <= 4)
|
|
|
|
|
textBox.Text = $"+7 ({rawInput.Substring(1)}";
|
|
|
|
|
else if (rawInput.Length <= 7)
|
|
|
|
|
textBox.Text = $"+7 ({rawInput.Substring(1, 3)}) {rawInput.Substring(4)}";
|
|
|
|
|
else if (rawInput.Length <= 9)
|
|
|
|
|
textBox.Text = $"+7 ({rawInput.Substring(1, 3)}) {rawInput.Substring(4, 3)}-{rawInput.Substring(7)}";
|
|
|
|
|
else
|
|
|
|
|
textBox.Text = $"+7 ({rawInput.Substring(1, 3)}) {rawInput.Substring(4, 3)}-{rawInput.Substring(7, 2)}-{rawInput.Substring(9)}";
|
|
|
|
|
|
|
|
|
|
// Устанавливаем курсор в конец
|
|
|
|
|
textBox.SelectionStart = textBox.Text.Length;
|
|
|
|
|
}
|
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 (VacationComboBox.SelectedValue is int selectedVacationId)
|
2024-12-01 17:32:41 +04:00
|
|
|
|
{
|
2024-12-01 18:08:18 +04:00
|
|
|
|
var updatedVacation = new VacationViewModel
|
2024-12-01 17:32:41 +04:00
|
|
|
|
{
|
2024-12-01 18:08:18 +04:00
|
|
|
|
Id = selectedVacationId,
|
|
|
|
|
StartData = StartDatePicker.SelectedDate.Value.ToUniversalTime(),
|
|
|
|
|
EndData = EndDatePicker.SelectedDate.Value.ToUniversalTime(),
|
2024-12-01 17:32:41 +04:00
|
|
|
|
Passed = PassedCheckBox.IsChecked ?? false,
|
|
|
|
|
};
|
|
|
|
|
|
2024-12-01 18:08:18 +04:00
|
|
|
|
_vacationLogic.Update(updatedVacation);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|