To Be Continued
parent
147ed9b1e8
commit
7618384c13
|
|
@ -1,6 +1,15 @@
|
|||
namespace AvaloniaApplication14_Inventory_300326.Models.Factoryes;
|
||||
using AvaloniaApplication14_Inventory_300326.Models.Models;
|
||||
|
||||
public class EmployeesFactory
|
||||
namespace AvaloniaApplication14_Inventory_300326.Models.Factories;
|
||||
|
||||
public static class EmployeesFactory
|
||||
{
|
||||
|
||||
public static Employee CreateFromEmployeeVisual(EmployeeVisual employee)
|
||||
{
|
||||
Employee newEmployee = new Employee();
|
||||
newEmployee.Id = employee.Id;
|
||||
newEmployee.FullName = employee.FullName;
|
||||
newEmployee.PositionId = employee.Position.Id;
|
||||
return newEmployee;
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ using AvaloniaApplication14_Inventory_300326.Models.DataBase;
|
|||
using AvaloniaApplication14_Inventory_300326.Models.Models;
|
||||
using AvaloniaApplication14_Inventory_300326.Views;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace AvaloniaApplication14_Inventory_300326.ViewModels;
|
||||
|
|
@ -13,19 +14,53 @@ public partial class EmployeeEditingWindowViewModel : ViewModelBase
|
|||
private EmployeeEditingWindow _currentWindow;
|
||||
private IServiceProvider _serviceProvider;
|
||||
private bool _isEditing;
|
||||
private Employee _employee;
|
||||
|
||||
[ObservableProperty] private string _name;
|
||||
[ObservableProperty] private ObservableCollection<Position> _positions;
|
||||
[ObservableProperty] private Position _selectedPosition;
|
||||
|
||||
[RelayCommand]
|
||||
private void Cancel()
|
||||
{
|
||||
_currentWindow.Close();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void Confirm()
|
||||
{
|
||||
_employee.FullName = Name;
|
||||
_employee.PositionId = SelectedPosition.Id;
|
||||
using (var repo = _serviceProvider.GetService<EmployeeRepository>())
|
||||
{
|
||||
if (_isEditing)
|
||||
{
|
||||
repo.Update(_employee);
|
||||
}
|
||||
else
|
||||
{
|
||||
repo.Add(_employee);
|
||||
}
|
||||
}
|
||||
_currentWindow.Close();
|
||||
}
|
||||
public EmployeeEditingWindowViewModel(IServiceProvider serviceProvider, Employee employee)
|
||||
{
|
||||
_isEditing=!employee.IsNew();
|
||||
_serviceProvider = serviceProvider;
|
||||
_employee = employee;
|
||||
using (var repo = _serviceProvider.GetService<PositionRepository>())
|
||||
{
|
||||
Positions = new ObservableCollection<Position>(repo.GetAll());
|
||||
}
|
||||
|
||||
Name = employee.FullName;
|
||||
|
||||
}
|
||||
|
||||
public void SetScreen(EmployeeEditingWindow window)
|
||||
{
|
||||
_currentWindow = window;
|
||||
_currentWindow.ConfirmButton.Content = _isEditing ? "Изменить" : "Добавить";
|
||||
}
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ using Avalonia.Data;
|
|||
using Avalonia.Input;
|
||||
using Avalonia.LogicalTree;
|
||||
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;
|
||||
|
|
@ -44,6 +45,7 @@ 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();
|
||||
|
||||
break;
|
||||
|
|
@ -53,8 +55,8 @@ public partial class MainWindowViewModel : ViewModelBase
|
|||
var EmployeeVm = ActivatorUtilities.CreateInstance<EmployeeEditingWindowViewModel>(_serviceProvider, employee);
|
||||
var EmployeeWin = ActivatorUtilities.CreateInstance<EmployeeEditingWindow>(_serviceProvider, EmployeeVm);
|
||||
await EmployeeWin.ShowDialog(_currentWindow);
|
||||
GetTeches();
|
||||
|
||||
ShowEmployees();
|
||||
GetEmployees();
|
||||
break;
|
||||
case 2:
|
||||
|
||||
|
|
@ -171,12 +173,17 @@ public partial class MainWindowViewModel : ViewModelBase
|
|||
var vm = ActivatorUtilities.CreateInstance<EquipmentEditingWindowViewModel>(_serviceProvider, EquipmentFactory.CreateFromVisual(SelectedEquipmentVisual));
|
||||
var win = ActivatorUtilities.CreateInstance<EquipmentEditingWindow>(_serviceProvider, vm);
|
||||
await win.ShowDialog(_currentWindow);
|
||||
ShowTeches();
|
||||
GetTeches();
|
||||
}
|
||||
|
||||
private void DoubleTappedEmployeeDataGrid()
|
||||
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 void DoubleTappedPositionDataGrid()
|
||||
|
|
|
|||
|
|
@ -17,7 +17,17 @@
|
|||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Label Content="Должность: "></Label>
|
||||
<ComboBox ItemsSource="{Binding Positions}"></ComboBox>
|
||||
<ComboBox ItemsSource="{Binding Positions}" SelectedItem="{Binding SelectedPosition}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Label Content="{Binding Name}"></Label>
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Button x:Name="ConfirmButton" Command="{Binding ConfirmCommand}"></Button>
|
||||
<Button Content="Назад" Command="{Binding CancelCommand}"></Button>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
|
|
|
|||
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+69e11179169a76d62cd0fe7694460e08d81c7480")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+147ed9b1e85ec232bec24cd3ec30a7c4c274fb3a")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("AvaloniaApplication14_Inventory_300326")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("AvaloniaApplication14_Inventory_300326")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
0576c4c81a455eeddc7b366511b3dde5f0890ec0fb52f054b63d3c32f7eb7b1c
|
||||
8a899368f07641840a01d1306cc38ae23bb799c2cc2003defe76e2e5a69b0e4b
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue