PIbd-42_Kashin_M.I_CPO_Cour.../EmployeeManagmentView/MainWindow.xaml.cs

68 lines
3.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using EmployeeManagmentBusinessLogic.BusinessLogic;
using EmployeeManagmentContracts.BusinessLogicContracts;
using EmployeeManagmentContracts.ViewModels;
using EmployeeManagmentView.Employee;
using EmployeeManagmentView.PhysicalPerson;
using System.Windows;
namespace EmployeeManagmentView
{
public partial class MainWindow : Window
{
private readonly IEmployeeLogic _employeeLogic;
private readonly IPhisicalPersonLogic _phisicalPersonLogic;
private readonly ISalaryLogic _salaryLogic;
private readonly IVacationLogic _vacationLogic;
// Constructor with Dependency Injection
public MainWindow(IEmployeeLogic employeeLogic, IPhisicalPersonLogic phisicalPersonLogic, ISalaryLogic salaryLogic, IVacationLogic vacationLogic)
{
_employeeLogic = employeeLogic;
_phisicalPersonLogic = phisicalPersonLogic;
_salaryLogic = salaryLogic;
_vacationLogic = vacationLogic;
InitializeComponent();
}
private void OpenPhysicalPersonManagementWindow(object sender, RoutedEventArgs e)
{
foreach (Window window in Application.Current.Windows)
{
if (window is PhysicalPersonManagementWindow)
{
// Если окно уже открыто, активируем его и ставим на передний план
window.Activate();
window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
window.Topmost = true; // Ставим окно на передний план
window.Topmost = false; // Сразу снимаем флаг, чтобы окно не оставалось всегда наверху
return;
}
}
var physicalPersonWindow = new PhysicalPersonManagementWindow(_phisicalPersonLogic);
physicalPersonWindow.Show();
}
private void OpenEmployeeManagementWindow(object sender, RoutedEventArgs e)
{
foreach (Window window in Application.Current.Windows)
{
if (window is EmployeeManagementWindow)
{
// Если окно уже открыто, активируем его и ставим на передний план
window.Activate();
window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
window.Topmost = true; // Ставим окно на передний план
window.Topmost = false; // Сразу снимаем флаг, чтобы окно не оставалось всегда наверху
return;
}
}
var employeeWindow = new EmployeeManagementWindow(_employeeLogic, _phisicalPersonLogic, _salaryLogic, _vacationLogic);
employeeWindow.Show();
}
}
}