diff --git a/AvaloniaApplication14_Inventory_300326/Models/DataBase/EmployeeRepository.cs b/AvaloniaApplication14_Inventory_300326/Models/DataBase/EmployeeRepository.cs index a7e3b4c..f1cdfb5 100644 --- a/AvaloniaApplication14_Inventory_300326/Models/DataBase/EmployeeRepository.cs +++ b/AvaloniaApplication14_Inventory_300326/Models/DataBase/EmployeeRepository.cs @@ -41,7 +41,32 @@ public class EmployeeRepository : BaseRepository, IDisposable } return result; } + public List? GetAllFrom0() + { + string sql = "SELECT * FROM `Employees` WHERE Id > 0"; + List result = new List(); + try + { + using var mc = new MySqlCommand(sql, connection); + using var reader = mc.ExecuteReader(); + while (reader.Read()) + { + Employee employee = new Employee() + { + Id = reader.GetInt32("Id"), + FullName = reader.GetString("FullName"), + PositionId = reader.GetInt32("PositionId"), + }; + result.Add(employee); + } + } + catch (Exception e) + { + Console.WriteLine(e); + } + return result; + } public override Employee? GetById(int id) { string sql = "SELECT * FROM `Employees` WHERE Id = @Id"; diff --git a/AvaloniaApplication14_Inventory_300326/Models/DataBase/PositionRepository.cs b/AvaloniaApplication14_Inventory_300326/Models/DataBase/PositionRepository.cs index dfc579c..2825ab6 100644 --- a/AvaloniaApplication14_Inventory_300326/Models/DataBase/PositionRepository.cs +++ b/AvaloniaApplication14_Inventory_300326/Models/DataBase/PositionRepository.cs @@ -37,7 +37,28 @@ public class PositionRepository : BaseRepository, IDisposable return result; } - + public List? GetAllFrom0() + { + List result = new List(); + string sql = "SELECT * FROM Positions WHERE Id > 0"; + using (var mc = new MySqlCommand(sql, connection)) + { + using (var reader = mc.ExecuteReader()) + { + while (reader.Read()) + { + Position position = new Position() + { + Id = reader.GetInt32("Id"), + Name = reader.GetString("Name"), + }; + result.Add(position); + } + } + } + + return result; + } public override Position? GetById(int id) { string sql = "SELECT * FROM Positions WHERE Id = @Id"; diff --git a/AvaloniaApplication14_Inventory_300326/Models/Factories/EmployeesFactory.cs b/AvaloniaApplication14_Inventory_300326/Models/Factories/EmployeesFactory.cs index 0174a1d..cbb3973 100644 --- a/AvaloniaApplication14_Inventory_300326/Models/Factories/EmployeesFactory.cs +++ b/AvaloniaApplication14_Inventory_300326/Models/Factories/EmployeesFactory.cs @@ -1,10 +1,16 @@ +using System; using AvaloniaApplication14_Inventory_300326.Models.Models; namespace AvaloniaApplication14_Inventory_300326.Models.Factories; -public static class EmployeesFactory +public class EmployeesFactory { - public static Employee CreateFromEmployeeVisual(EmployeeVisual employee) + private IServiceProvider _serviceProvider; + public EmployeesFactory(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + public Employee CreateFromEmployeeVisual(EmployeeVisual employee) { Employee newEmployee = new Employee(); newEmployee.Id = employee.Id; diff --git a/AvaloniaApplication14_Inventory_300326/Models/Factories/EmployeesVisualFactory.cs b/AvaloniaApplication14_Inventory_300326/Models/Factories/EmployeesVisualFactory.cs index 62eb032..7f5dcf0 100644 --- a/AvaloniaApplication14_Inventory_300326/Models/Factories/EmployeesVisualFactory.cs +++ b/AvaloniaApplication14_Inventory_300326/Models/Factories/EmployeesVisualFactory.cs @@ -1,14 +1,39 @@ +using System; +using System.Collections.Generic; +using AvaloniaApplication14_Inventory_300326.Models.DataBase; using AvaloniaApplication14_Inventory_300326.Models.Models; +using Microsoft.Extensions.DependencyInjection; namespace AvaloniaApplication14_Inventory_300326.Models.Factoryes; -public static class EmployeesVisualFactory +public class EmployeesVisualFactory { - public static EmployeeVisual CreateFromEmployee(Employee employee) + private IServiceProvider _serviceProvider; + public EmployeesVisualFactory(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + + public EmployeeVisual CreateFromEmployee(Employee employee) { var result = new EmployeeVisual(); result.Id = employee.Id; result.FullName = employee.FullName; return result; } + public List ConvertListEmplToEmplVis(List employees) + { + List result = new List(); + foreach (var item in employees) + { + EmployeeVisual eve = new EmployeeVisual(); + using (var posRepo = _serviceProvider.GetRequiredService()) + { + eve = CreateFromEmployee(item); + eve.Position = posRepo.GetById(item.PositionId); + } + result.Add(eve); + } + return result; + } } \ No newline at end of file diff --git a/AvaloniaApplication14_Inventory_300326/Models/Factories/EquipmentFactory.cs b/AvaloniaApplication14_Inventory_300326/Models/Factories/EquipmentFactory.cs index dcdef66..2740164 100644 --- a/AvaloniaApplication14_Inventory_300326/Models/Factories/EquipmentFactory.cs +++ b/AvaloniaApplication14_Inventory_300326/Models/Factories/EquipmentFactory.cs @@ -3,9 +3,14 @@ using AvaloniaApplication14_Inventory_300326.Models.Models; namespace AvaloniaApplication14_Inventory_300326.Models.Factoryes; -public static class EquipmentFactory +public class EquipmentFactory { - public static Equipment CreateFromVisual(EquipmentVisual visual) + private IServiceProvider _serviceProvider; + public EquipmentFactory(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + public Equipment CreateFromVisual(EquipmentVisual visual) { var result = new Equipment(); diff --git a/AvaloniaApplication14_Inventory_300326/Models/Factories/EquipmentVisualFactory.cs b/AvaloniaApplication14_Inventory_300326/Models/Factories/EquipmentVisualFactory.cs index 741428e..2f95b78 100644 --- a/AvaloniaApplication14_Inventory_300326/Models/Factories/EquipmentVisualFactory.cs +++ b/AvaloniaApplication14_Inventory_300326/Models/Factories/EquipmentVisualFactory.cs @@ -1,11 +1,21 @@ using System; +using System.Collections.Generic; +using AvaloniaApplication14_Inventory_300326.Models.DataBase; using AvaloniaApplication14_Inventory_300326.Models.Models; +using Microsoft.Extensions.DependencyInjection; namespace AvaloniaApplication14_Inventory_300326.Models.Factoryes; -public static class EquipmentVisualFactory +public class EquipmentVisualFactory { - public static EquipmentVisual CreateFromEquipment(Equipment equipment) + private IServiceProvider _serviceProvider; + + public EquipmentVisualFactory(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + + public EquipmentVisual CreateFromEquipment(Equipment equipment) { var result = new EquipmentVisual(); @@ -19,4 +29,20 @@ public static class EquipmentVisualFactory return result; } + + public List ConvertListEqToEqVis(List equipments) + { + List result = new List(); + foreach (var item in equipments) + { + EquipmentVisual eq = new EquipmentVisual(); + using (var empRepo = _serviceProvider.GetRequiredService()) + { + eq = CreateFromEquipment(item); + eq.CurrentEmployee = empRepo.GetById(item.CurrentEmployeeId); + } + result.Add(eq); + } + return result; + } } \ No newline at end of file diff --git a/AvaloniaApplication14_Inventory_300326/Program.cs b/AvaloniaApplication14_Inventory_300326/Program.cs index 1b7b1f6..c5cbc78 100644 --- a/AvaloniaApplication14_Inventory_300326/Program.cs +++ b/AvaloniaApplication14_Inventory_300326/Program.cs @@ -2,6 +2,8 @@ using System; using AvaloniaApplication14_Di_test_1125.Models; using AvaloniaApplication14_Inventory_300326.Models.DataBase; +using AvaloniaApplication14_Inventory_300326.Models.Factories; +using AvaloniaApplication14_Inventory_300326.Models.Factoryes; using AvaloniaApplication14_Inventory_300326.ViewModels; using AvaloniaApplication14_Inventory_300326.Views; using Microsoft.Extensions.Configuration; @@ -30,6 +32,13 @@ sealed class Program service.AddTransient(); service.AddTransient(); service.AddTransient(); + service.AddTransient(); + service.AddTransient(); + service.AddTransient(); + service.AddSingleton(); + service.AddSingleton(); + service.AddSingleton(); + service.AddSingleton(); }).Build(); diff --git a/AvaloniaApplication14_Inventory_300326/ViewModels/EmployeeEditingWindowViewModel.cs b/AvaloniaApplication14_Inventory_300326/ViewModels/EmployeeEditingWindowViewModel.cs index fb1fe48..7dd27ec 100644 --- a/AvaloniaApplication14_Inventory_300326/ViewModels/EmployeeEditingWindowViewModel.cs +++ b/AvaloniaApplication14_Inventory_300326/ViewModels/EmployeeEditingWindowViewModel.cs @@ -102,6 +102,10 @@ public partial class EmployeeEditingWindowViewModel : ViewModelBase FullName = employee.FullName; SelectedPosition = Positions.FirstOrDefault(p => p.Id == employee.PositionId); } + else + { + SelectedPosition = Positions[0]; + } } diff --git a/AvaloniaApplication14_Inventory_300326/ViewModels/EmployeesViewModel.cs b/AvaloniaApplication14_Inventory_300326/ViewModels/EmployeesViewModel.cs new file mode 100644 index 0000000..9b169ca --- /dev/null +++ b/AvaloniaApplication14_Inventory_300326/ViewModels/EmployeesViewModel.cs @@ -0,0 +1,87 @@ +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 Microsoft.Extensions.DependencyInjection; +using MsBox.Avalonia; +using MsBox.Avalonia.Enums; + +namespace AvaloniaApplication14_Inventory_300326.ViewModels; + +public partial class EmployeesViewModel : ViewModelBase +{ + private IServiceProvider _serviceProvider; + private MainWindow _currentWindow; + + private EmployeesVisualFactory _employeesVisualFactory; + private EmployeesFactory _employeesFactory; + + [ObservableProperty] private ObservableCollection _employees; + [ObservableProperty] private EmployeeVisual _selectedEmployeeVisual; + + public EmployeesViewModel(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + + _employeesVisualFactory = _serviceProvider.GetService(); + _employeesFactory = _serviceProvider.GetService(); + } + + public async Task Fire() + { + List temp = null; + using (var repo = _serviceProvider.GetService()) + { + temp = repo.DoesEmployeeHaveEquipments(SelectedEmployeeVisual.Id); + } + + if (temp != null) + { + if (temp.Count > 0) + { + string errorMessage = "За выбранным сотрудником числится следующие вещи: \n"; + foreach (var item in temp) + { + errorMessage += $"{item.Name} \n"; + } + var win = MessageBoxManager.GetMessageBoxStandard("Ошибка", errorMessage, ButtonEnum.Ok, Icon.Error); + await win.ShowWindowDialogAsync(_currentWindow); + } + } + } + + public async Task DoubleTappedEmployeeDataGrid() + { + var EmployeeVm = ActivatorUtilities.CreateInstance(_serviceProvider, _employeesFactory.CreateFromEmployeeVisual(SelectedEmployeeVisual)); + var EmployeeWin = ActivatorUtilities.CreateInstance(_serviceProvider, EmployeeVm); + await EmployeeWin.ShowDialog(_currentWindow); + ShowEmployees(); + GetEmployees(); + } + + public void ShowEmployees() + { + _currentWindow.ScrollViewerDataGridTech.IsVisible = false; + _currentWindow.ScrollViewerDataGridEmpl.IsVisible = true; + _currentWindow.ScrollViewerDataGridPos.IsVisible = false; + } + + public void GetEmployees() + { + using (var employeeRepository = _serviceProvider.GetService()) + { + var employees = employeeRepository.GetAllFrom0(); + Employees = new ObservableCollection(_employeesVisualFactory.ConvertListEmplToEmplVis(employees)); + } + } + public void SetScreen(MainWindow window) + { + _currentWindow = window; + } +} \ No newline at end of file diff --git a/AvaloniaApplication14_Inventory_300326/ViewModels/EquipmentEditingWindowViewModel.cs b/AvaloniaApplication14_Inventory_300326/ViewModels/EquipmentEditingWindowViewModel.cs index b718017..d01289e 100644 --- a/AvaloniaApplication14_Inventory_300326/ViewModels/EquipmentEditingWindowViewModel.cs +++ b/AvaloniaApplication14_Inventory_300326/ViewModels/EquipmentEditingWindowViewModel.cs @@ -18,6 +18,9 @@ public partial class EquipmentEditingWindowViewModel : ViewModelBase private EquipmentVisual _equipment; private IServiceProvider _serviceProvider; + private EquipmentFactory _equipmentFactory; + private EquipmentVisualFactory _equipmentVisualFactory; + [ObservableProperty] private string _name; [ObservableProperty] private string _invNumber; [ObservableProperty] private DateTimeOffset? _date; @@ -40,11 +43,11 @@ public partial class EquipmentEditingWindowViewModel : ViewModelBase { if (_isEditing) { - repo.Update(EquipmentFactory.CreateFromVisual(_equipment)); + repo.Update(_equipmentFactory.CreateFromVisual(_equipment)); } else { - repo.Add(EquipmentFactory.CreateFromVisual(_equipment)); + repo.Add(_equipmentFactory.CreateFromVisual(_equipment)); } } _currentWindow.Close(); @@ -60,22 +63,34 @@ public partial class EquipmentEditingWindowViewModel : ViewModelBase { _serviceProvider = serviceProvider; _isEditing = !equipment.IsNew(); + + _equipmentFactory = _serviceProvider.GetService(); + _equipmentVisualFactory = _serviceProvider.GetService(); + using (var repo = _serviceProvider.GetService()) { - _equipment = EquipmentVisualFactory.CreateFromEquipment(equipment); + _equipment = _equipmentVisualFactory.CreateFromEquipment(equipment); _equipment.CurrentEmployee = repo.GetById(equipment.CurrentEmployeeId); } - Name = _equipment.Name; - InvNumber = _equipment.InvNumber; - Date = _equipment.Date; - Cost = _equipment.Cost; - IsWrittenOff = _equipment.IsWrittenOff; using (var repo = _serviceProvider.GetService()) { Employees = new ObservableCollection(repo.GetAll()); } - CurrentEmployee = Employees.FirstOrDefault(o => o.Id == equipment.CurrentEmployeeId); + if (_isEditing) + { + Name = _equipment.Name; + InvNumber = _equipment.InvNumber; + Date = _equipment.Date; + Cost = _equipment.Cost; + IsWrittenOff = _equipment.IsWrittenOff; + CurrentEmployee = Employees.FirstOrDefault(o => o.Id == equipment.CurrentEmployeeId); + } + else + { + CurrentEmployee = Employees[0]; + Date = DateTimeOffset.Now; + } } public void SetWindow(EquipmentEditingWindow window) { diff --git a/AvaloniaApplication14_Inventory_300326/ViewModels/EquipmentViewModel.cs b/AvaloniaApplication14_Inventory_300326/ViewModels/EquipmentViewModel.cs new file mode 100644 index 0000000..d03ec36 --- /dev/null +++ b/AvaloniaApplication14_Inventory_300326/ViewModels/EquipmentViewModel.cs @@ -0,0 +1,62 @@ +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.Factoryes; +using AvaloniaApplication14_Inventory_300326.Models.Models; +using AvaloniaApplication14_Inventory_300326.Views; +using CommunityToolkit.Mvvm.ComponentModel; +using Microsoft.Extensions.DependencyInjection; + +namespace AvaloniaApplication14_Inventory_300326.ViewModels; + +public partial class EquipmentViewModel : ViewModelBase +{ + private IServiceProvider _serviceProvider; + private MainWindow _currentWindow; + + private EquipmentFactory _equipmentFactory; + private EquipmentVisualFactory _equipmentVisualFactory; + + [ObservableProperty] private ObservableCollection _techs; + [ObservableProperty] private EquipmentVisual _selectedEquipmentVisual; + + public EquipmentViewModel(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + + _equipmentFactory = _serviceProvider.GetRequiredService(); + _equipmentVisualFactory = _serviceProvider.GetRequiredService(); + + GetTeches(); + } + + public void GetTeches() + { + using (var equipmentRepository = _serviceProvider.GetService()) + { + List teches = equipmentRepository.GetAll(); + Techs = new ObservableCollection(_equipmentVisualFactory.ConvertListEqToEqVis(teches)); + } + } + + public async Task DoubleTappedTechDataGrid() + { + var vm = ActivatorUtilities.CreateInstance(_serviceProvider, _equipmentFactory.CreateFromVisual(SelectedEquipmentVisual)); + var win = ActivatorUtilities.CreateInstance(_serviceProvider, vm); + await win.ShowDialog(_currentWindow); + ShowTeches(); + GetTeches(); + } + public void ShowTeches() + { + _currentWindow.ScrollViewerDataGridTech.IsVisible = true; + _currentWindow.ScrollViewerDataGridEmpl.IsVisible = false; + _currentWindow.ScrollViewerDataGridPos.IsVisible = false; + } + public void SetScreen(MainWindow window) + { + _currentWindow = window; + } +} \ No newline at end of file diff --git a/AvaloniaApplication14_Inventory_300326/ViewModels/MainWindowViewModel.cs b/AvaloniaApplication14_Inventory_300326/ViewModels/MainWindowViewModel.cs index 0674325..cbcef2c 100644 --- a/AvaloniaApplication14_Inventory_300326/ViewModels/MainWindowViewModel.cs +++ b/AvaloniaApplication14_Inventory_300326/ViewModels/MainWindowViewModel.cs @@ -21,37 +21,17 @@ 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 _entities; [ObservableProperty] private Entity _selectedEntity; - [ObservableProperty] private ObservableCollection _techs; - [ObservableProperty] private ObservableCollection _employees; - [ObservableProperty] private ObservableCollection _positions; - [ObservableProperty] private EquipmentVisual _selectedEquipmentVisual; - [ObservableProperty] private EmployeeVisual _selectedEmployeeVisual; - [ObservableProperty] private Position _selectedPosition; [RelayCommand] private async Task Fire() { - List temp = null; - using (var repo = _serviceProvider.GetService()) - { - temp = repo.DoesEmployeeHaveEquipments(SelectedEmployeeVisual.Id); - } - - if (temp != null) - { - if (temp.Count > 0) - { - string errorMessage = "За выбранным сотрудником числится следующие вещи: \n"; - foreach (var item in temp) - { - errorMessage += $"{item.Name} \n"; - } - var win = MessageBoxManager.GetMessageBoxStandard("Ошибка", errorMessage, ButtonEnum.Ok, Icon.Error); - await win.ShowWindowDialogAsync(_currentWindow); - } - } + EmployeesViewModel.Fire(); } @@ -66,8 +46,9 @@ public partial class MainWindowViewModel : ViewModelBase var EquipmentVm = ActivatorUtilities.CreateInstance(_serviceProvider, equipment); var EquipmentWin = ActivatorUtilities.CreateInstance(_serviceProvider, EquipmentVm); await EquipmentWin.ShowDialog(_currentWindow); - ShowTeches(); - GetTeches(); + + EquipmentViewModel.ShowTeches(); + EquipmentViewModel.GetTeches(); break; case 1: @@ -76,8 +57,9 @@ public partial class MainWindowViewModel : ViewModelBase var EmployeeVm = ActivatorUtilities.CreateInstance(_serviceProvider, employee); var EmployeeWin = ActivatorUtilities.CreateInstance(_serviceProvider, EmployeeVm); await EmployeeWin.ShowDialog(_currentWindow); - ShowEmployees(); - GetEmployees(); + + EmployeesViewModel.ShowEmployees(); + EmployeesViewModel.GetEmployees(); break; case 2: @@ -93,23 +75,23 @@ public partial class MainWindowViewModel : ViewModelBase { case 0: - GetTeches(); + EquipmentViewModel.GetTeches(); - ShowTeches(); + EquipmentViewModel.ShowTeches(); break; case 1: - GetEmployees(); + EmployeesViewModel.GetEmployees(); - ShowEmployees(); + EmployeesViewModel.ShowEmployees(); break; case 2: - GetPositions(); + PositionViewModel.GetPositions(); - ShowPositions(); + PositionViewModel.ShowPositions(); break; } @@ -130,136 +112,28 @@ public partial class MainWindowViewModel : ViewModelBase Entities.Add(new Entity(){Id = 2, Name = "Должности"}); SelectedEntity = Entities[0]; - - - using (var equipmentRepository = _serviceProvider.GetService()) - { - List equipments = equipmentRepository.GetAll(); - Techs = new ObservableCollection(ConvertListEqToEqVis(equipments)); - } + + EquipmentViewModel = _serviceProvider.GetService(); + EmployeesViewModel = _serviceProvider.GetService(); + PositionViewModel = _serviceProvider.GetService(); } //################################################################################################################### - - - - private void GetTeches() - { - using (var equipmentRepository = _serviceProvider.GetService()) - { - List teches = equipmentRepository.GetAll(); - Techs = new ObservableCollection(ConvertListEqToEqVis(teches)); - } - } - public void GetEmployees() - { - using (var employeeRepository = _serviceProvider.GetService()) - { - var employees = employeeRepository.GetAll(); - Employees = new ObservableCollection(ConvertListEmplToEmplVis(employees)); - } - } - - public void GetPositions() - { - using (var positionRepository = _serviceProvider.GetService()) - { - var positions = positionRepository.GetAll(); - Positions = new ObservableCollection(positions); - } - } - - public void ShowTeches() - { - _currentWindow.ScrollViewerDataGridTech.IsVisible = true; - _currentWindow.ScrollViewerDataGridEmpl.IsVisible = false; - _currentWindow.ScrollViewerDataGridPos.IsVisible = false; - } - public void ShowEmployees() - { - _currentWindow.ScrollViewerDataGridTech.IsVisible = false; - _currentWindow.ScrollViewerDataGridEmpl.IsVisible = true; - _currentWindow.ScrollViewerDataGridPos.IsVisible = false; - } - public void ShowPositions() - { - _currentWindow.ScrollViewerDataGridTech.IsVisible = false; - _currentWindow.ScrollViewerDataGridEmpl.IsVisible = false; - _currentWindow.ScrollViewerDataGridPos.IsVisible = true; - } - - private async Task DoubleTappedTechDataGrid() - { - var vm = ActivatorUtilities.CreateInstance(_serviceProvider, EquipmentFactory.CreateFromVisual(SelectedEquipmentVisual)); - var win = ActivatorUtilities.CreateInstance(_serviceProvider, vm); - await win.ShowDialog(_currentWindow); - ShowTeches(); - GetTeches(); - } - - private async Task DoubleTappedEmployeeDataGrid() - { - var EmployeeVm = ActivatorUtilities.CreateInstance(_serviceProvider, EmployeesFactory.CreateFromEmployeeVisual(SelectedEmployeeVisual)); - var EmployeeWin = ActivatorUtilities.CreateInstance(_serviceProvider, EmployeeVm); - await EmployeeWin.ShowDialog(_currentWindow); - ShowEmployees(); - GetEmployees(); - } - - private async Task DoubleTappedPositionDataGrid() - { - var PositionVm = ActivatorUtilities.CreateInstance(_serviceProvider, SelectedPosition); - var win = ActivatorUtilities.CreateInstance(_serviceProvider, PositionVm); - await win.ShowDialog(_currentWindow); - ShowPositions(); - GetPositions(); - } - - public List ConvertListEqToEqVis(List equipments) - { - List result = new List(); - foreach (var item in equipments) - { - EquipmentVisual eq = new EquipmentVisual(); - using (var empRepo = _serviceProvider.GetRequiredService()) - { - eq = EquipmentVisualFactory.CreateFromEquipment(item); - eq.CurrentEmployee = empRepo.GetById(item.CurrentEmployeeId); - } - result.Add(eq); - } - return result; - } - - public List ConvertListEmplToEmplVis(List employees) - { - List result = new List(); - foreach (var item in employees) - { - EmployeeVisual eve = new EmployeeVisual(); - using (var posRepo = _serviceProvider.GetRequiredService()) - { - eve = EmployeesVisualFactory.CreateFromEmployee(item); - eve.Position = posRepo.GetById(item.PositionId); - } - result.Add(eve); - } - return result; - } - public void SetScreen(MainWindow window) { _currentWindow = window; - Console.WriteLine(window); - ShowTeches(); + EquipmentViewModel.SetScreen(_currentWindow); + EmployeesViewModel.SetScreen(_currentWindow); + PositionViewModel.SetScreen(_currentWindow); + EquipmentViewModel.ShowTeches(); INIT(); } private void INIT() { - _currentWindow.DataGridTech.DoubleTapped += (sender, args) => DoubleTappedTechDataGrid(); - _currentWindow.DataGridEmployees.DoubleTapped += (sender, args) => DoubleTappedEmployeeDataGrid(); - _currentWindow.DataGridPositions.DoubleTapped += (sender, args) => DoubleTappedPositionDataGrid(); + _currentWindow.DataGridTech.DoubleTapped += (sender, args) => EquipmentViewModel.DoubleTappedTechDataGrid(); + _currentWindow.DataGridEmployees.DoubleTapped += (sender, args) => EmployeesViewModel.DoubleTappedEmployeeDataGrid(); + _currentWindow.DataGridPositions.DoubleTapped += (sender, args) => PositionViewModel.DoubleTappedPositionDataGrid(); } } \ No newline at end of file diff --git a/AvaloniaApplication14_Inventory_300326/ViewModels/PositionViewModel.cs b/AvaloniaApplication14_Inventory_300326/ViewModels/PositionViewModel.cs new file mode 100644 index 0000000..88a62de --- /dev/null +++ b/AvaloniaApplication14_Inventory_300326/ViewModels/PositionViewModel.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.ObjectModel; +using System.Threading.Tasks; +using AvaloniaApplication14_Inventory_300326.Models.DataBase; +using AvaloniaApplication14_Inventory_300326.Models.Models; +using AvaloniaApplication14_Inventory_300326.Views; +using CommunityToolkit.Mvvm.ComponentModel; +using Microsoft.Extensions.DependencyInjection; + +namespace AvaloniaApplication14_Inventory_300326.ViewModels; + +public partial class PositionViewModel : ViewModelBase +{ + private IServiceProvider _serviceProvider; + private MainWindow _currentWindow; + + [ObservableProperty] private ObservableCollection _positions; + [ObservableProperty] private Position _selectedPosition; + + public PositionViewModel(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + public void GetPositions() + { + using (var positionRepository = _serviceProvider.GetService()) + { + var positions = positionRepository.GetAllFrom0(); + Positions = new ObservableCollection(positions); + } + } + + public void ShowPositions() + { + _currentWindow.ScrollViewerDataGridTech.IsVisible = false; + _currentWindow.ScrollViewerDataGridEmpl.IsVisible = false; + _currentWindow.ScrollViewerDataGridPos.IsVisible = true; + } + + public async Task DoubleTappedPositionDataGrid() + { + var PositionVm = ActivatorUtilities.CreateInstance(_serviceProvider, SelectedPosition); + var win = ActivatorUtilities.CreateInstance(_serviceProvider, PositionVm); + await win.ShowDialog(_currentWindow); + ShowPositions(); + GetPositions(); + } + public void SetScreen(MainWindow window) + { + _currentWindow = window; + } +} \ No newline at end of file diff --git a/AvaloniaApplication14_Inventory_300326/Views/EmployeeEditingWindow.axaml b/AvaloniaApplication14_Inventory_300326/Views/EmployeeEditingWindow.axaml index 5692360..c5cf592 100644 --- a/AvaloniaApplication14_Inventory_300326/Views/EmployeeEditingWindow.axaml +++ b/AvaloniaApplication14_Inventory_300326/Views/EmployeeEditingWindow.axaml @@ -27,7 +27,7 @@ - + diff --git a/AvaloniaApplication14_Inventory_300326/Views/MainWindow.axaml b/AvaloniaApplication14_Inventory_300326/Views/MainWindow.axaml index 8587e91..980ecc9 100644 --- a/AvaloniaApplication14_Inventory_300326/Views/MainWindow.axaml +++ b/AvaloniaApplication14_Inventory_300326/Views/MainWindow.axaml @@ -23,7 +23,7 @@ - + @@ -36,7 +36,7 @@ - + @@ -50,7 +50,7 @@ - + diff --git a/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/Avalonia/Resources.Inputs.cache b/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/Avalonia/Resources.Inputs.cache index 4931bd1..a4c28e3 100644 --- a/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/Avalonia/Resources.Inputs.cache +++ b/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/Avalonia/Resources.Inputs.cache @@ -1 +1 @@ -2a84cdfd20fd3ba333d939c83e85ef60a8d19237a93d0faa0b7453529059536d +f4607182817b4da112c839dc3641843ca8fe5f3fe96e5c9bfc3ea48aad6b3fdd diff --git a/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/Avalonia/resources b/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/Avalonia/resources index cdb1324..400c1da 100644 Binary files a/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/Avalonia/resources and b/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/Avalonia/resources differ diff --git a/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/AvaloniaApplication14_Inventory_300326.AssemblyInfo.cs b/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/AvaloniaApplication14_Inventory_300326.AssemblyInfo.cs index e8b6257..0610a87 100644 --- a/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/AvaloniaApplication14_Inventory_300326.AssemblyInfo.cs +++ b/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/AvaloniaApplication14_Inventory_300326.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("AvaloniaApplication14_Inventory_300326")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+aeb0013a062acd378099c740807360d515c81abe")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+70111810c1836182b0f37d93a7e8b2e96bbb6f90")] [assembly: System.Reflection.AssemblyProductAttribute("AvaloniaApplication14_Inventory_300326")] [assembly: System.Reflection.AssemblyTitleAttribute("AvaloniaApplication14_Inventory_300326")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/AvaloniaApplication14_Inventory_300326.AssemblyInfoInputs.cache b/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/AvaloniaApplication14_Inventory_300326.AssemblyInfoInputs.cache index 4b48c1e..069a514 100644 --- a/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/AvaloniaApplication14_Inventory_300326.AssemblyInfoInputs.cache +++ b/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/AvaloniaApplication14_Inventory_300326.AssemblyInfoInputs.cache @@ -1 +1 @@ -202b4e7895223083a77909f91fbe1a27b39e500114519106f4377d3e9113ba9a +9dbe6ffb36df0983dc0fb68e296275034be5aec8e886a3b04e3c9808d6290db8 diff --git a/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/AvaloniaApplication14_Inventory_300326.csproj.CoreCompileInputs.cache b/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/AvaloniaApplication14_Inventory_300326.csproj.CoreCompileInputs.cache index 0ab1dfe..c6e1a21 100644 --- a/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/AvaloniaApplication14_Inventory_300326.csproj.CoreCompileInputs.cache +++ b/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/AvaloniaApplication14_Inventory_300326.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -40dcb0cffdab5c0643c31952ff7fdad779ded408c005a8c22e32baa5f4058328 +c2031e9ca0ec9cc885b404c236a3d1a4ba002b484190fb82bd2d8f148778b16d diff --git a/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/AvaloniaApplication14_Inventory_300326.dll b/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/AvaloniaApplication14_Inventory_300326.dll index 905b4f6..2ed0171 100644 Binary files a/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/AvaloniaApplication14_Inventory_300326.dll and b/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/AvaloniaApplication14_Inventory_300326.dll differ diff --git a/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/AvaloniaApplication14_Inventory_300326.pdb b/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/AvaloniaApplication14_Inventory_300326.pdb index 8cf4582..f441fae 100644 Binary files a/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/AvaloniaApplication14_Inventory_300326.pdb and b/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/AvaloniaApplication14_Inventory_300326.pdb differ diff --git a/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/ref/AvaloniaApplication14_Inventory_300326.dll b/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/ref/AvaloniaApplication14_Inventory_300326.dll index 535bd62..2ad9779 100644 Binary files a/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/ref/AvaloniaApplication14_Inventory_300326.dll and b/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/ref/AvaloniaApplication14_Inventory_300326.dll differ diff --git a/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/refint/AvaloniaApplication14_Inventory_300326.dll b/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/refint/AvaloniaApplication14_Inventory_300326.dll index 535bd62..2ad9779 100644 Binary files a/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/refint/AvaloniaApplication14_Inventory_300326.dll and b/AvaloniaApplication14_Inventory_300326/obj/Debug/net9.0/refint/AvaloniaApplication14_Inventory_300326.dll differ diff --git a/AvaloniaApplication14_Inventory_300326/obj/rider.project.model.nuget.info b/AvaloniaApplication14_Inventory_300326/obj/rider.project.model.nuget.info index c399e25..10fdab7 100644 --- a/AvaloniaApplication14_Inventory_300326/obj/rider.project.model.nuget.info +++ b/AvaloniaApplication14_Inventory_300326/obj/rider.project.model.nuget.info @@ -1 +1 @@ -17763047588415830 \ No newline at end of file +17763141913838317 \ No newline at end of file diff --git a/AvaloniaApplication14_Inventory_300326/obj/rider.project.restore.info b/AvaloniaApplication14_Inventory_300326/obj/rider.project.restore.info index f4c3d0c..acdc386 100644 --- a/AvaloniaApplication14_Inventory_300326/obj/rider.project.restore.info +++ b/AvaloniaApplication14_Inventory_300326/obj/rider.project.restore.info @@ -1 +1 @@ -17763047593305837 \ No newline at end of file +17763836796197075 \ No newline at end of file