148 lines
5.4 KiB
C#
148 lines
5.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Threading.Tasks;
|
|
using AvaloniaApplication14_Inventory_300326.Models.DataBase;
|
|
using AvaloniaApplication14_Inventory_300326.Models.Factories;
|
|
using AvaloniaApplication14_Inventory_300326.Models.Factoryes;
|
|
using AvaloniaApplication14_Inventory_300326.Models.Models;
|
|
using AvaloniaApplication14_Inventory_300326.Views;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using MsBox.Avalonia;
|
|
using MsBox.Avalonia.Dto;
|
|
using MsBox.Avalonia.Enums;
|
|
|
|
namespace AvaloniaApplication14_Inventory_300326.ViewModels;
|
|
|
|
public partial class MainWindowViewModel : ViewModelBase
|
|
{
|
|
private MainWindow _currentWindow;
|
|
private IServiceProvider _serviceProvider;
|
|
|
|
[ObservableProperty] private EquipmentViewModel _equipmentViewModel;
|
|
[ObservableProperty] private EmployeesViewModel _employeesViewModel;
|
|
[ObservableProperty] private PositionViewModel _positionViewModel;
|
|
|
|
[ObservableProperty] private ObservableCollection<Entity> _entities;
|
|
[ObservableProperty] private Entity _selectedEntity;
|
|
|
|
[RelayCommand]
|
|
private async Task Fire()
|
|
{
|
|
EmployeesViewModel.Fire();
|
|
}
|
|
|
|
|
|
[RelayCommand]
|
|
private async Task AddEntity()
|
|
{
|
|
switch (SelectedEntity.Id)
|
|
{
|
|
case 0:
|
|
|
|
var equipment = new Equipment();
|
|
var equipmentVm = ActivatorUtilities.CreateInstance<EquipmentEditingWindowViewModel>(_serviceProvider, equipment);
|
|
var equipmentWin = ActivatorUtilities.CreateInstance<EquipmentEditingWindow>(_serviceProvider, equipmentVm);
|
|
await equipmentWin.ShowDialog(_currentWindow);
|
|
|
|
EquipmentViewModel.ShowTeches();
|
|
EquipmentViewModel.GetTeches();
|
|
|
|
break;
|
|
case 1:
|
|
|
|
var employee = new Employee();
|
|
var employeeVm = ActivatorUtilities.CreateInstance<EmployeeEditingWindowViewModel>(_serviceProvider, employee);
|
|
var employeeWin = ActivatorUtilities.CreateInstance<EmployeeEditingWindow>(_serviceProvider, employeeVm);
|
|
await employeeWin.ShowDialog(_currentWindow);
|
|
|
|
EmployeesViewModel.ShowEmployees();
|
|
EmployeesViewModel.GetEmployees();
|
|
|
|
break;
|
|
case 2:
|
|
|
|
var position = new Position();
|
|
var positionVm = ActivatorUtilities.CreateInstance<PositionEditingWindowViewModel>(_serviceProvider, position);
|
|
var positionWin = ActivatorUtilities.CreateInstance<PositionEditingWindow>(_serviceProvider, positionVm);
|
|
await positionWin.ShowDialog(_currentWindow);
|
|
|
|
PositionViewModel.ShowPositions();
|
|
PositionViewModel.GetPositions();
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
partial void OnSelectedEntityChanged(Entity value)
|
|
{
|
|
if (_currentWindow != null)
|
|
{
|
|
switch (value.Id)
|
|
{
|
|
case 0:
|
|
|
|
EquipmentViewModel.GetTeches();
|
|
|
|
EquipmentViewModel.ShowTeches();
|
|
|
|
break;
|
|
case 1:
|
|
|
|
EmployeesViewModel.GetEmployees();
|
|
|
|
EmployeesViewModel.ShowEmployees();
|
|
|
|
break;
|
|
case 2:
|
|
|
|
PositionViewModel.GetPositions();
|
|
|
|
PositionViewModel.ShowPositions();
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//###################################################################################################################
|
|
|
|
public MainWindowViewModel(IServiceProvider serviceProvider)
|
|
{
|
|
_serviceProvider = serviceProvider;
|
|
|
|
Entities = new();
|
|
|
|
Entities.Add(new Entity(){Id = 0, Name = "Техника"});
|
|
Entities.Add(new Entity(){Id = 1, Name = "Сотрудники"});
|
|
Entities.Add(new Entity(){Id = 2, Name = "Должности"});
|
|
|
|
SelectedEntity = Entities[0];
|
|
|
|
EquipmentViewModel = _serviceProvider.GetService<EquipmentViewModel>();
|
|
EmployeesViewModel = _serviceProvider.GetService<EmployeesViewModel>();
|
|
PositionViewModel = _serviceProvider.GetService<PositionViewModel>();
|
|
}
|
|
|
|
//###################################################################################################################
|
|
|
|
public void SetScreen(MainWindow window)
|
|
{
|
|
_currentWindow = window;
|
|
EquipmentViewModel.SetScreen(_currentWindow);
|
|
EmployeesViewModel.SetScreen(_currentWindow);
|
|
PositionViewModel.SetScreen(_currentWindow);
|
|
EquipmentViewModel.ShowTeches();
|
|
INIT();
|
|
}
|
|
|
|
private void INIT()
|
|
{
|
|
_currentWindow.DataGridTech.DoubleTapped += (sender, args) => EquipmentViewModel.DoubleTappedTechDataGrid();
|
|
_currentWindow.DataGridEmployees.DoubleTapped += (sender, args) => EmployeesViewModel.DoubleTappedEmployeeDataGrid();
|
|
_currentWindow.DataGridPositions.DoubleTapped += (sender, args) => PositionViewModel.DoubleTappedPositionDataGrid();
|
|
}
|
|
} |