To Be Continued
parent
70111810c1
commit
cca23316cc
|
|
@ -41,7 +41,32 @@ public class EmployeeRepository : BaseRepository<Employee>, IDisposable
|
|||
}
|
||||
return result;
|
||||
}
|
||||
public List<Employee>? GetAllFrom0()
|
||||
{
|
||||
string sql = "SELECT * FROM `Employees` WHERE Id > 0";
|
||||
List<Employee> result = new List<Employee>();
|
||||
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";
|
||||
|
|
|
|||
|
|
@ -37,7 +37,28 @@ public class PositionRepository : BaseRepository<Position>, IDisposable
|
|||
|
||||
return result;
|
||||
}
|
||||
public List<Position>? GetAllFrom0()
|
||||
{
|
||||
List<Position> result = new List<Position>();
|
||||
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";
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<EmployeeVisual> ConvertListEmplToEmplVis(List<Employee> employees)
|
||||
{
|
||||
List<EmployeeVisual> result = new List<EmployeeVisual>();
|
||||
foreach (var item in employees)
|
||||
{
|
||||
EmployeeVisual eve = new EmployeeVisual();
|
||||
using (var posRepo = _serviceProvider.GetRequiredService<PositionRepository>())
|
||||
{
|
||||
eve = CreateFromEmployee(item);
|
||||
eve.Position = posRepo.GetById(item.PositionId);
|
||||
}
|
||||
result.Add(eve);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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<EquipmentVisual> ConvertListEqToEqVis(List<Equipment> equipments)
|
||||
{
|
||||
List<EquipmentVisual> result = new List<EquipmentVisual>();
|
||||
foreach (var item in equipments)
|
||||
{
|
||||
EquipmentVisual eq = new EquipmentVisual();
|
||||
using (var empRepo = _serviceProvider.GetRequiredService<EmployeeRepository>())
|
||||
{
|
||||
eq = CreateFromEquipment(item);
|
||||
eq.CurrentEmployee = empRepo.GetById(item.CurrentEmployeeId);
|
||||
}
|
||||
result.Add(eq);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -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<EquipmentRepository>();
|
||||
service.AddTransient<PositionRepository>();
|
||||
service.AddTransient<EquipmentEditingWindow>();
|
||||
service.AddTransient<PositionViewModel>();
|
||||
service.AddTransient<EmployeesViewModel>();
|
||||
service.AddTransient<EquipmentViewModel>();
|
||||
service.AddSingleton<EquipmentVisualFactory>();
|
||||
service.AddSingleton<EquipmentFactory>();
|
||||
service.AddSingleton<EmployeesVisualFactory>();
|
||||
service.AddSingleton<EmployeesFactory>();
|
||||
|
||||
}).Build();
|
||||
|
||||
|
|
|
|||
|
|
@ -102,6 +102,10 @@ public partial class EmployeeEditingWindowViewModel : ViewModelBase
|
|||
FullName = employee.FullName;
|
||||
SelectedPosition = Positions.FirstOrDefault(p => p.Id == employee.PositionId);
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectedPosition = Positions[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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<EmployeeVisual> _employees;
|
||||
[ObservableProperty] private EmployeeVisual _selectedEmployeeVisual;
|
||||
|
||||
public EmployeesViewModel(IServiceProvider serviceProvider)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
|
||||
_employeesVisualFactory = _serviceProvider.GetService<EmployeesVisualFactory>();
|
||||
_employeesFactory = _serviceProvider.GetService<EmployeesFactory>();
|
||||
}
|
||||
|
||||
public async Task Fire()
|
||||
{
|
||||
List<Equipment> temp = null;
|
||||
using (var repo = _serviceProvider.GetService<EquipmentRepository>())
|
||||
{
|
||||
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<EmployeeEditingWindowViewModel>(_serviceProvider, _employeesFactory.CreateFromEmployeeVisual(SelectedEmployeeVisual));
|
||||
var EmployeeWin = ActivatorUtilities.CreateInstance<EmployeeEditingWindow>(_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<EmployeeRepository>())
|
||||
{
|
||||
var employees = employeeRepository.GetAllFrom0();
|
||||
Employees = new ObservableCollection<EmployeeVisual>(_employeesVisualFactory.ConvertListEmplToEmplVis(employees));
|
||||
}
|
||||
}
|
||||
public void SetScreen(MainWindow window)
|
||||
{
|
||||
_currentWindow = window;
|
||||
}
|
||||
}
|
||||
|
|
@ -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<EquipmentFactory>();
|
||||
_equipmentVisualFactory = _serviceProvider.GetService<EquipmentVisualFactory>();
|
||||
|
||||
using (var repo = _serviceProvider.GetService<EmployeeRepository>())
|
||||
{
|
||||
_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<EmployeeRepository>())
|
||||
{
|
||||
Employees = new ObservableCollection<Employee>(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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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<EquipmentVisual> _techs;
|
||||
[ObservableProperty] private EquipmentVisual _selectedEquipmentVisual;
|
||||
|
||||
public EquipmentViewModel(IServiceProvider serviceProvider)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
|
||||
_equipmentFactory = _serviceProvider.GetRequiredService<EquipmentFactory>();
|
||||
_equipmentVisualFactory = _serviceProvider.GetRequiredService<EquipmentVisualFactory>();
|
||||
|
||||
GetTeches();
|
||||
}
|
||||
|
||||
public void GetTeches()
|
||||
{
|
||||
using (var equipmentRepository = _serviceProvider.GetService<EquipmentRepository>())
|
||||
{
|
||||
List<Equipment> teches = equipmentRepository.GetAll();
|
||||
Techs = new ObservableCollection<EquipmentVisual>(_equipmentVisualFactory.ConvertListEqToEqVis(teches));
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DoubleTappedTechDataGrid()
|
||||
{
|
||||
var vm = ActivatorUtilities.CreateInstance<EquipmentEditingWindowViewModel>(_serviceProvider, _equipmentFactory.CreateFromVisual(SelectedEquipmentVisual));
|
||||
var win = ActivatorUtilities.CreateInstance<EquipmentEditingWindow>(_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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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<Entity> _entities;
|
||||
[ObservableProperty] private Entity _selectedEntity;
|
||||
[ObservableProperty] private ObservableCollection<EquipmentVisual> _techs;
|
||||
[ObservableProperty] private ObservableCollection<EmployeeVisual> _employees;
|
||||
[ObservableProperty] private ObservableCollection<Position> _positions;
|
||||
[ObservableProperty] private EquipmentVisual _selectedEquipmentVisual;
|
||||
[ObservableProperty] private EmployeeVisual _selectedEmployeeVisual;
|
||||
[ObservableProperty] private Position _selectedPosition;
|
||||
|
||||
[RelayCommand]
|
||||
private async Task Fire()
|
||||
{
|
||||
List<Equipment> temp = null;
|
||||
using (var repo = _serviceProvider.GetService<EquipmentRepository>())
|
||||
{
|
||||
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<EquipmentEditingWindowViewModel>(_serviceProvider, equipment);
|
||||
var EquipmentWin = ActivatorUtilities.CreateInstance<EquipmentEditingWindow>(_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<EmployeeEditingWindowViewModel>(_serviceProvider, employee);
|
||||
var EmployeeWin = ActivatorUtilities.CreateInstance<EmployeeEditingWindow>(_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;
|
||||
}
|
||||
|
|
@ -131,135 +113,27 @@ public partial class MainWindowViewModel : ViewModelBase
|
|||
|
||||
SelectedEntity = Entities[0];
|
||||
|
||||
|
||||
using (var equipmentRepository = _serviceProvider.GetService<EquipmentRepository>())
|
||||
{
|
||||
List<Equipment> equipments = equipmentRepository.GetAll();
|
||||
Techs = new ObservableCollection<EquipmentVisual>(ConvertListEqToEqVis(equipments));
|
||||
}
|
||||
EquipmentViewModel = _serviceProvider.GetService<EquipmentViewModel>();
|
||||
EmployeesViewModel = _serviceProvider.GetService<EmployeesViewModel>();
|
||||
PositionViewModel = _serviceProvider.GetService<PositionViewModel>();
|
||||
}
|
||||
|
||||
//###################################################################################################################
|
||||
|
||||
|
||||
|
||||
private void GetTeches()
|
||||
{
|
||||
using (var equipmentRepository = _serviceProvider.GetService<EquipmentRepository>())
|
||||
{
|
||||
List<Equipment> teches = equipmentRepository.GetAll();
|
||||
Techs = new ObservableCollection<EquipmentVisual>(ConvertListEqToEqVis(teches));
|
||||
}
|
||||
}
|
||||
|
||||
public void GetEmployees()
|
||||
{
|
||||
using (var employeeRepository = _serviceProvider.GetService<EmployeeRepository>())
|
||||
{
|
||||
var employees = employeeRepository.GetAll();
|
||||
Employees = new ObservableCollection<EmployeeVisual>(ConvertListEmplToEmplVis(employees));
|
||||
}
|
||||
}
|
||||
|
||||
public void GetPositions()
|
||||
{
|
||||
using (var positionRepository = _serviceProvider.GetService<PositionRepository>())
|
||||
{
|
||||
var positions = positionRepository.GetAll();
|
||||
Positions = new ObservableCollection<Position>(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<EquipmentEditingWindowViewModel>(_serviceProvider, EquipmentFactory.CreateFromVisual(SelectedEquipmentVisual));
|
||||
var win = ActivatorUtilities.CreateInstance<EquipmentEditingWindow>(_serviceProvider, vm);
|
||||
await win.ShowDialog(_currentWindow);
|
||||
ShowTeches();
|
||||
GetTeches();
|
||||
}
|
||||
|
||||
private async Task DoubleTappedEmployeeDataGrid()
|
||||
{
|
||||
var EmployeeVm = ActivatorUtilities.CreateInstance<EmployeeEditingWindowViewModel>(_serviceProvider, EmployeesFactory.CreateFromEmployeeVisual(SelectedEmployeeVisual));
|
||||
var EmployeeWin = ActivatorUtilities.CreateInstance<EmployeeEditingWindow>(_serviceProvider, EmployeeVm);
|
||||
await EmployeeWin.ShowDialog(_currentWindow);
|
||||
ShowEmployees();
|
||||
GetEmployees();
|
||||
}
|
||||
|
||||
private async Task DoubleTappedPositionDataGrid()
|
||||
{
|
||||
var PositionVm = ActivatorUtilities.CreateInstance<PositionEditingWindowViewModel>(_serviceProvider, SelectedPosition);
|
||||
var win = ActivatorUtilities.CreateInstance<PositionEditingWindow>(_serviceProvider, PositionVm);
|
||||
await win.ShowDialog(_currentWindow);
|
||||
ShowPositions();
|
||||
GetPositions();
|
||||
}
|
||||
|
||||
public List<EquipmentVisual> ConvertListEqToEqVis(List<Equipment> equipments)
|
||||
{
|
||||
List<EquipmentVisual> result = new List<EquipmentVisual>();
|
||||
foreach (var item in equipments)
|
||||
{
|
||||
EquipmentVisual eq = new EquipmentVisual();
|
||||
using (var empRepo = _serviceProvider.GetRequiredService<EmployeeRepository>())
|
||||
{
|
||||
eq = EquipmentVisualFactory.CreateFromEquipment(item);
|
||||
eq.CurrentEmployee = empRepo.GetById(item.CurrentEmployeeId);
|
||||
}
|
||||
result.Add(eq);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<EmployeeVisual> ConvertListEmplToEmplVis(List<Employee> employees)
|
||||
{
|
||||
List<EmployeeVisual> result = new List<EmployeeVisual>();
|
||||
foreach (var item in employees)
|
||||
{
|
||||
EmployeeVisual eve = new EmployeeVisual();
|
||||
using (var posRepo = _serviceProvider.GetRequiredService<PositionRepository>())
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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<Position> _positions;
|
||||
[ObservableProperty] private Position _selectedPosition;
|
||||
|
||||
public PositionViewModel(IServiceProvider serviceProvider)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
public void GetPositions()
|
||||
{
|
||||
using (var positionRepository = _serviceProvider.GetService<PositionRepository>())
|
||||
{
|
||||
var positions = positionRepository.GetAllFrom0();
|
||||
Positions = new ObservableCollection<Position>(positions);
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowPositions()
|
||||
{
|
||||
_currentWindow.ScrollViewerDataGridTech.IsVisible = false;
|
||||
_currentWindow.ScrollViewerDataGridEmpl.IsVisible = false;
|
||||
_currentWindow.ScrollViewerDataGridPos.IsVisible = true;
|
||||
}
|
||||
|
||||
public async Task DoubleTappedPositionDataGrid()
|
||||
{
|
||||
var PositionVm = ActivatorUtilities.CreateInstance<PositionEditingWindowViewModel>(_serviceProvider, SelectedPosition);
|
||||
var win = ActivatorUtilities.CreateInstance<PositionEditingWindow>(_serviceProvider, PositionVm);
|
||||
await win.ShowDialog(_currentWindow);
|
||||
ShowPositions();
|
||||
GetPositions();
|
||||
}
|
||||
public void SetScreen(MainWindow window)
|
||||
{
|
||||
_currentWindow = window;
|
||||
}
|
||||
}
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
<Button Grid.Row="2" Grid.Column="0" x:Name="ConfirmButton" Command="{Binding ConfirmCommand}" VerticalAlignment="Bottom"></Button>
|
||||
<Button Grid.Row="2" Grid.Column="1" Content="Назад" Command="{Binding CancelCommand}" VerticalAlignment="Bottom"></Button>
|
||||
<Button Grid.Row="2" Grid.Column="2" Content="Уволить" Command="{Binding FireCommand}" VerticalAlignment="Bottom"></Button>
|
||||
<Button Grid.Row="2" Grid.Column="2" Content="Уволить" x:Name="FireButton" Command="{Binding FireCommand}" VerticalAlignment="Bottom"></Button>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
<Button Content="Добавить" Margin="10,0,0,0" Command="{Binding AddEntityCommand}"></Button>
|
||||
</StackPanel>
|
||||
<ScrollViewer Grid.Row="1" x:Name="ScrollViewerDataGridTech">
|
||||
<DataGrid x:Name="DataGridTech" ItemsSource="{Binding Techs}" SelectedItem="{Binding SelectedEquipmentVisual}" IsReadOnly="True">
|
||||
<DataGrid x:Name="DataGridTech" ItemsSource="{Binding EquipmentViewModel.Techs}" SelectedItem="{Binding EquipmentViewModel.SelectedEquipmentVisual}" IsReadOnly="True">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="Инвентарный номер" Binding="{Binding InvNumber}"></DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Название" Binding="{Binding Name}"></DataGridTextColumn>
|
||||
|
|
@ -36,7 +36,7 @@
|
|||
</ScrollViewer>
|
||||
|
||||
<ScrollViewer Grid.Row="1" x:Name="ScrollViewerDataGridEmpl">
|
||||
<DataGrid x:Name="DataGridEmployees" ItemsSource="{Binding Employees}" SelectedItem="{Binding SelectedEmployeeVisual}" IsReadOnly="True">
|
||||
<DataGrid x:Name="DataGridEmployees" ItemsSource="{Binding EmployeesViewModel.Employees}" SelectedItem="{Binding EmployeesViewModel.SelectedEmployeeVisual}" IsReadOnly="True">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="ФИО" Binding="{Binding FullName}"></DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Должность" Binding="{Binding Position.Name}"></DataGridTextColumn>
|
||||
|
|
@ -50,7 +50,7 @@
|
|||
</ScrollViewer>
|
||||
|
||||
<ScrollViewer Grid.Row="1" x:Name="ScrollViewerDataGridPos">
|
||||
<DataGrid x:Name="DataGridPositions" ItemsSource="{Binding Positions}" IsReadOnly="True">
|
||||
<DataGrid x:Name="DataGridPositions" ItemsSource="{Binding PositionViewModel.Positions}" IsReadOnly="True">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="Название" Binding="{Binding Name}"></DataGridTextColumn>
|
||||
</DataGrid.Columns>
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
2a84cdfd20fd3ba333d939c83e85ef60a8d19237a93d0faa0b7453529059536d
|
||||
f4607182817b4da112c839dc3641843ca8fe5f3fe96e5c9bfc3ea48aad6b3fdd
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -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")]
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
202b4e7895223083a77909f91fbe1a27b39e500114519106f4377d3e9113ba9a
|
||||
9dbe6ffb36df0983dc0fb68e296275034be5aec8e886a3b04e3c9808d6290db8
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
40dcb0cffdab5c0643c31952ff7fdad779ded408c005a8c22e32baa5f4058328
|
||||
c2031e9ca0ec9cc885b404c236a3d1a4ba002b484190fb82bd2d8f148778b16d
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1 +1 @@
|
|||
17763047588415830
|
||||
17763141913838317
|
||||
|
|
@ -1 +1 @@
|
|||
17763047593305837
|
||||
17763836796197075
|
||||
Loading…
Reference in New Issue