To Be Continued
parent
114de77f0d
commit
e7b75a0b73
|
|
@ -137,4 +137,21 @@ public class EquipmentRepository : BaseRepository<Equipment>, IDisposable
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ValidateInvNumber(string invNumber)
|
||||
{
|
||||
string sql = "select * from `Equipment` where InvNumber=@invNumber";
|
||||
using(var mc = new MySqlCommand(sql, connection))
|
||||
{
|
||||
mc.Parameters.AddWithValue("@invNumber", invNumber);
|
||||
using (var reader = mc.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -113,9 +113,9 @@ public partial class EmployeeEditingWindowViewModel : ViewModelBase
|
|||
{
|
||||
_currentWindow = window;
|
||||
_currentWindow.ConfirmButton.Content = _isEditing ? "Изменить" : "Добавить";
|
||||
if (_isEditing)
|
||||
if (!_isEditing)
|
||||
{
|
||||
|
||||
_currentWindow.FireButton.IsVisible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using AvaloniaApplication14_Inventory_300326.Models.DataBase;
|
||||
using AvaloniaApplication14_Inventory_300326.Models.Factoryes;
|
||||
using AvaloniaApplication14_Inventory_300326.Models.Models;
|
||||
|
|
@ -8,6 +9,8 @@ using AvaloniaApplication14_Inventory_300326.Views;
|
|||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using MsBox.Avalonia;
|
||||
using MsBox.Avalonia.Enums;
|
||||
|
||||
namespace AvaloniaApplication14_Inventory_300326.ViewModels;
|
||||
|
||||
|
|
@ -26,29 +29,46 @@ public partial class EquipmentEditingWindowViewModel : ViewModelBase
|
|||
[ObservableProperty] private DateTimeOffset? _date;
|
||||
[ObservableProperty] private decimal _cost;
|
||||
[ObservableProperty] private bool _isWrittenOff;
|
||||
[ObservableProperty] private string _isWrittenOffString;
|
||||
[ObservableProperty] private Employee _currentEmployee;
|
||||
[ObservableProperty] private ObservableCollection<Employee> _employees;
|
||||
|
||||
[RelayCommand]
|
||||
private void Confrm()
|
||||
private async Task Confrm()
|
||||
{
|
||||
_equipment.InvNumber = InvNumber;
|
||||
_equipment.Date = Date;
|
||||
_equipment.Cost = Cost;
|
||||
_equipment.IsWrittenOff = IsWrittenOff;
|
||||
_equipment.CurrentEmployee = CurrentEmployee;
|
||||
_equipment.Name = Name;
|
||||
|
||||
using (var repo = _serviceProvider.GetService<EquipmentRepository>())
|
||||
{
|
||||
if (_isEditing)
|
||||
{
|
||||
repo.Update(_equipmentFactory.CreateFromVisual(_equipment));
|
||||
}
|
||||
else
|
||||
{
|
||||
repo.Add(_equipmentFactory.CreateFromVisual(_equipment));
|
||||
}
|
||||
_equipment.InvNumber = InvNumber;
|
||||
_equipment.Date = Date;
|
||||
_equipment.Cost = Cost;
|
||||
_equipment.IsWrittenOff = IsWrittenOff;
|
||||
_equipment.CurrentEmployee = CurrentEmployee;
|
||||
_equipment.Name = Name;
|
||||
|
||||
if (_isEditing)
|
||||
{
|
||||
repo.Update(_equipmentFactory.CreateFromVisual(_equipment));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (repo.ValidateInvNumber(InvNumber))
|
||||
{
|
||||
if (Cost>0)
|
||||
{
|
||||
repo.Add(_equipmentFactory.CreateFromVisual(_equipment));
|
||||
}
|
||||
else
|
||||
{
|
||||
var ErrorWin = MessageBoxManager.GetMessageBoxStandard("Ошибка", "Стоимость должна быть больше 0", ButtonEnum.Ok, Icon.Error);
|
||||
await ErrorWin.ShowWindowDialogAsync(_currentWindow);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var ErrorWin = MessageBoxManager.GetMessageBoxStandard("Ошибка", "Объект с таким инвентарным номером уже существует", ButtonEnum.Ok, Icon.Error);
|
||||
await ErrorWin.ShowWindowDialogAsync(_currentWindow);
|
||||
}
|
||||
}
|
||||
}
|
||||
_currentWindow.Close();
|
||||
}
|
||||
|
|
@ -80,6 +100,7 @@ public partial class EquipmentEditingWindowViewModel : ViewModelBase
|
|||
Date = _equipment.Date;
|
||||
Cost = _equipment.Cost;
|
||||
IsWrittenOff = _equipment.IsWrittenOff;
|
||||
IsWrittenOffString = _equipment.IsWrittenOff?"Да":"Нет";
|
||||
CurrentEmployee = _equipment.CurrentEmployee;
|
||||
Employees = new ObservableCollection<Employee>();
|
||||
Employees.Add(CurrentEmployee);
|
||||
|
|
@ -102,10 +123,12 @@ public partial class EquipmentEditingWindowViewModel : ViewModelBase
|
|||
if (_isEditing)
|
||||
{
|
||||
_currentWindow.CurrentEmployeeBox.IsVisible = false;
|
||||
_currentWindow.IsWrittenOffCheckBox.IsVisible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentWindow.CurrentEmployeeLabel.IsVisible = false;
|
||||
_currentWindow.IsWrittenOffLabel.IsVisible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -43,9 +43,9 @@ public partial class MainWindowViewModel : ViewModelBase
|
|||
case 0:
|
||||
|
||||
var equipment = new Equipment();
|
||||
var EquipmentVm = ActivatorUtilities.CreateInstance<EquipmentEditingWindowViewModel>(_serviceProvider, equipment);
|
||||
var EquipmentWin = ActivatorUtilities.CreateInstance<EquipmentEditingWindow>(_serviceProvider, EquipmentVm);
|
||||
await EquipmentWin.ShowDialog(_currentWindow);
|
||||
var equipmentVm = ActivatorUtilities.CreateInstance<EquipmentEditingWindowViewModel>(_serviceProvider, equipment);
|
||||
var equipmentWin = ActivatorUtilities.CreateInstance<EquipmentEditingWindow>(_serviceProvider, equipmentVm);
|
||||
await equipmentWin.ShowDialog(_currentWindow);
|
||||
|
||||
EquipmentViewModel.ShowTeches();
|
||||
EquipmentViewModel.GetTeches();
|
||||
|
|
@ -54,15 +54,24 @@ public partial class MainWindowViewModel : ViewModelBase
|
|||
case 1:
|
||||
|
||||
var employee = new Employee();
|
||||
var EmployeeVm = ActivatorUtilities.CreateInstance<EmployeeEditingWindowViewModel>(_serviceProvider, employee);
|
||||
var EmployeeWin = ActivatorUtilities.CreateInstance<EmployeeEditingWindow>(_serviceProvider, EmployeeVm);
|
||||
await EmployeeWin.ShowDialog(_currentWindow);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
using System;
|
||||
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;
|
||||
|
||||
|
|
@ -11,24 +13,38 @@ public partial class PositionEditingWindowViewModel : ViewModelBase
|
|||
private IServiceProvider _serviceProvider;
|
||||
private bool _isEditing;
|
||||
private PositionEditingWindow _currentWindow;
|
||||
private Position _position;
|
||||
|
||||
[ObservableProperty] private string _positionName;
|
||||
|
||||
[RelayCommand]
|
||||
private void Cancel()
|
||||
{
|
||||
|
||||
_currentWindow.Close();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void Confirm()
|
||||
{
|
||||
|
||||
_position.Name = PositionName;
|
||||
using (var _positionRepository = _serviceProvider.GetService<PositionRepository>())
|
||||
{
|
||||
if (_isEditing)
|
||||
{
|
||||
_positionRepository.Update(_position);
|
||||
}
|
||||
else
|
||||
{
|
||||
_positionRepository.Add(_position);
|
||||
}
|
||||
}
|
||||
_currentWindow.Close();
|
||||
}
|
||||
public PositionEditingWindowViewModel(IServiceProvider serviceProvider, Position position)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
_isEditing = !position.IsNew();
|
||||
_position = position;
|
||||
if (_isEditing)
|
||||
{
|
||||
PositionName = position.Name;
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ public partial class PositionViewModel : ViewModelBase
|
|||
|
||||
public async Task DoubleTappedPositionDataGrid()
|
||||
{
|
||||
var PositionVm = ActivatorUtilities.CreateInstance<PositionEditingWindowViewModel>(_serviceProvider, SelectedPosition);
|
||||
var win = ActivatorUtilities.CreateInstance<PositionEditingWindow>(_serviceProvider, PositionVm);
|
||||
var positionVm = ActivatorUtilities.CreateInstance<PositionEditingWindowViewModel>(_serviceProvider, SelectedPosition);
|
||||
var win = ActivatorUtilities.CreateInstance<PositionEditingWindow>(_serviceProvider, positionVm);
|
||||
await win.ShowDialog(_currentWindow);
|
||||
ShowPositions();
|
||||
GetPositions();
|
||||
|
|
|
|||
|
|
@ -33,7 +33,8 @@
|
|||
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Label Content="Списано ли: "></Label>
|
||||
<CheckBox IsChecked="{Binding IsWrittenOff}"></CheckBox>
|
||||
<CheckBox x:Name="IsWrittenOffCheckBox" IsChecked="{Binding IsWrittenOff}"></CheckBox>
|
||||
<Label x:Name="IsWrittenOffLabel" Content="{Binding IsWrittenOffString}"></Label>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal">
|
||||
|
|
|
|||
|
|
@ -41,16 +41,11 @@
|
|||
<DataGridTextColumn Header="ФИО" Binding="{Binding FullName}"></DataGridTextColumn>
|
||||
<DataGridTextColumn Header="Должность" Binding="{Binding Position.Name}"></DataGridTextColumn>
|
||||
</DataGrid.Columns>
|
||||
<DataGrid.ContextMenu>
|
||||
<ContextMenu>
|
||||
<Button Content="Уволить" Command="{Binding FireCommand}"></Button>
|
||||
</ContextMenu>
|
||||
</DataGrid.ContextMenu>
|
||||
</DataGrid>
|
||||
</ScrollViewer>
|
||||
|
||||
<ScrollViewer Grid.Row="1" x:Name="ScrollViewerDataGridPos">
|
||||
<DataGrid x:Name="DataGridPositions" ItemsSource="{Binding PositionViewModel.Positions}" IsReadOnly="True">
|
||||
<DataGrid x:Name="DataGridPositions" ItemsSource="{Binding PositionViewModel.Positions}" SelectedItem="{Binding PositionViewModel.SelectedPosition}" IsReadOnly="True">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="Название" Binding="{Binding Name}"></DataGridTextColumn>
|
||||
</DataGrid.Columns>
|
||||
|
|
@ -59,7 +54,10 @@
|
|||
</Grid>
|
||||
</TabItem>
|
||||
<TabItem Header="Операции">
|
||||
|
||||
<StackPanel>
|
||||
<Button Content="Передача техники"></Button>
|
||||
<Button Content="Списание техники"></Button>
|
||||
</StackPanel>
|
||||
</TabItem>
|
||||
<TabItem Header="Отчеты">
|
||||
|
||||
|
|
|
|||
|
|
@ -6,13 +6,15 @@
|
|||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="AvaloniaApplication14_Inventory_300326.Views.PositionEditingWindow"
|
||||
x:DataType="vm:PositionEditingWindowViewModel"
|
||||
Title="PositionEditingWindow">
|
||||
Title="PositionEditingWindow"
|
||||
WindowStartupLocation="CenterOwner"
|
||||
SizeToContent="WidthAndHeight">
|
||||
|
||||
<Grid RowDefinitions="* *" ColumnDefinitions="* *">
|
||||
<Grid RowDefinitions="Auto *" ColumnDefinitions="Auto *">
|
||||
<Label Content="Название должности: "></Label>
|
||||
<TextBox Grid.Row="0" Grid.Column="1"></TextBox>
|
||||
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding PositionName}"></TextBox>
|
||||
<Button Grid.Row="1" Grid.Column="0" x:Name="ConfirmButton" Command="{Binding ConfirmCommand}"></Button>
|
||||
<Button Grid.Row="1" Grid.Column="1" Command="{Binding CancelCommand}"></Button>
|
||||
<Button Grid.Row="1" Grid.Column="1" Content="Закрыть" Command="{Binding CancelCommand}"></Button>
|
||||
</Grid>
|
||||
|
||||
</Window>
|
||||
|
|
|
|||
|
|
@ -1,13 +1,16 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using AvaloniaApplication14_Inventory_300326.ViewModels;
|
||||
|
||||
namespace AvaloniaApplication14_Inventory_300326.Views;
|
||||
|
||||
public partial class PositionEditingWindow : Window
|
||||
{
|
||||
public PositionEditingWindow()
|
||||
public PositionEditingWindow(PositionEditingWindowViewModel vm)
|
||||
{
|
||||
DataContext = vm;
|
||||
InitializeComponent();
|
||||
vm.SetWindow(this);
|
||||
}
|
||||
}
|
||||
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+cca23316ccaf6ff854c560608fe74ea070bdd85a")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+114de77f0db0da5ab82bfb620f42bf9b0cec4498")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("AvaloniaApplication14_Inventory_300326")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("AvaloniaApplication14_Inventory_300326")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
63e3e38dd183c9ac63856099ca701d49eeb37cffc3fb48b85df28a550d81ee4f
|
||||
fda96c39694f07179b132880ffdf1ac5e54167a8724825f882522f81db71ce13
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue