增加相应功能
This commit is contained in:
parent
550d0b7308
commit
a82b05bd60
@ -23,6 +23,10 @@ public interface IVarietyService
|
||||
/// <returns></returns>
|
||||
Task AddVarietyAsync(Variety variety);
|
||||
|
||||
Task UpdateVarietyAsync(Variety variety);
|
||||
|
||||
Task DeleteVarietyAsync(Variety variety);
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有托盘信息
|
||||
/// </summary>
|
||||
|
@ -10,22 +10,23 @@ public class VarietyService : IVarietyService
|
||||
{
|
||||
private readonly IRepository<VarietyEntity> _varietyRepository;
|
||||
private readonly IRepository<PalletEntity> _palletRepository;
|
||||
private readonly ConcurrentBag<VarietyEntity> _varietiesCache;
|
||||
private readonly ConcurrentBag<PalletEntity> _palletsCache;
|
||||
private readonly List<VarietyEntity> _varietiesCache;
|
||||
private readonly List<PalletEntity> _palletsCache;
|
||||
|
||||
public VarietyService(IServiceProvider provider)
|
||||
{
|
||||
try
|
||||
{
|
||||
_varietyRepository = provider.CreateScope().ServiceProvider.GetRequiredService<IRepository<VarietyEntity>>();
|
||||
_varietyRepository =
|
||||
provider.CreateScope().ServiceProvider.GetRequiredService<IRepository<VarietyEntity>>();
|
||||
_palletRepository = provider.CreateScope().ServiceProvider.GetRequiredService<IRepository<PalletEntity>>();
|
||||
_varietiesCache = new ConcurrentBag<VarietyEntity>(_varietyRepository.GetList());
|
||||
_palletsCache = new ConcurrentBag<PalletEntity>(_palletRepository.GetList());
|
||||
}catch(Exception e)
|
||||
_varietiesCache = new List<VarietyEntity>(_varietyRepository.GetList());
|
||||
_palletsCache = new List<PalletEntity>(_palletRepository.GetList());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public async Task<Variety?> GetVarietyByCodeAsync(string code, int? layers = null)
|
||||
@ -44,13 +45,33 @@ public class VarietyService : IVarietyService
|
||||
|
||||
public async Task AddVarietyAsync(Variety variety)
|
||||
{
|
||||
var entity = await _varietyRepository.InsertReturnEntityAsync(variety.ToEntity());
|
||||
_varietiesCache.Add(entity);
|
||||
try
|
||||
{
|
||||
var entity = await _varietyRepository.InsertReturnEntityAsync(variety.ToEntity());
|
||||
_varietiesCache.Add(entity);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public async Task UpdateVarietyAsync(Variety variety)
|
||||
{
|
||||
await _varietyRepository.UpdateAsync(variety.ToEntity());
|
||||
_varietiesCache[_varietiesCache.IndexOf(variety.ToEntity())] = variety.ToEntity();
|
||||
}
|
||||
|
||||
public async Task DeleteVarietyAsync(Variety variety)
|
||||
{
|
||||
await _varietyRepository.DeleteAsync(variety.ToEntity());
|
||||
_varietiesCache.Remove(variety.ToEntity());
|
||||
}
|
||||
|
||||
public async Task<List<Pallet>> GetPalletsAsync()
|
||||
{
|
||||
return _palletsCache.Select(p =>Pallet.FromEntity(p)).ToList();
|
||||
return _palletsCache.Select(Pallet.FromEntity).ToList();
|
||||
}
|
||||
|
||||
public async Task AddPalletAsync(Pallet pallet)
|
||||
@ -61,6 +82,6 @@ public class VarietyService : IVarietyService
|
||||
|
||||
public List<Variety> GetAll()
|
||||
{
|
||||
return _varietiesCache.Select(v=>Variety.Create(v, _palletsCache.ToList())).ToList();
|
||||
return _varietiesCache.Select(v => Variety.Create(v, _palletsCache.ToList())).ToList();
|
||||
}
|
||||
}
|
@ -1,8 +1,11 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Seyounth.Core.Extensions;
|
||||
using Seyounth.Hyosung.Data.Entities;
|
||||
using Seyounth.Hyosung.Data.Models;
|
||||
using Seyounth.Hyosung.Data.Services;
|
||||
|
||||
namespace Seyounth.Hyosung.ViewModels;
|
||||
|
||||
@ -12,13 +15,18 @@ public partial class VarietyViewModel : ObservableObject
|
||||
|
||||
[ObservableProperty] private ObservableCollection<Pallet> _pallets;
|
||||
|
||||
|
||||
public IEnumerable<NeedTypeEnumItem> NeedTypeItems { get; }
|
||||
|
||||
public VarietyViewModel(PalletManagerViewModel palletManagerViewModel)
|
||||
private readonly IVarietyService _varietyService;
|
||||
|
||||
public VarietyViewModel(PalletManagerViewModel palletManagerViewModel, IVarietyService varietyService)
|
||||
{
|
||||
Pallets = new ObservableCollection<Pallet>(palletManagerViewModel.Pallets);
|
||||
|
||||
_varieties = new ObservableCollection<Variety>();
|
||||
_varietyService = varietyService;
|
||||
|
||||
_varieties = new ObservableCollection<Variety>(varietyService.GetAll());
|
||||
var needTypes = EnumHelper.GetValues<NeedType>();
|
||||
NeedTypeItems = needTypes.Select(nt => new NeedTypeEnumItem
|
||||
{
|
||||
@ -26,4 +34,38 @@ public partial class VarietyViewModel : ObservableObject
|
||||
Description = nt.GetDescription()
|
||||
});
|
||||
}
|
||||
|
||||
public class SavePalletCompletedMessage
|
||||
{
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void OnDeletePallet(object obj)
|
||||
{
|
||||
if (obj is Variety variety)
|
||||
{
|
||||
Varieties.Remove(variety);
|
||||
_varietyService.DeleteVarietyAsync(variety);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Write("Object is not a Pallet");
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void OnSavePallet(object obj)
|
||||
{
|
||||
if (obj is Variety variety)
|
||||
{
|
||||
if (variety.Id == 0)
|
||||
{
|
||||
_varietyService.AddVarietyAsync(variety);
|
||||
}
|
||||
else
|
||||
_varietyService.UpdateVarietyAsync(variety);
|
||||
}
|
||||
|
||||
WeakReferenceMessenger.Default.Send(new PalletManagerViewModel.SavePalletCompletedMessage());
|
||||
}
|
||||
}
|
@ -61,13 +61,14 @@
|
||||
ToolTip="托盘/隔板管理" />
|
||||
</ToolBar>
|
||||
</ToolBarTray>
|
||||
<DataGrid Grid.Row="0" x:Name="VarietyDataGrid"
|
||||
<DataGrid Margin="16" Grid.Row="1" x:Name="VarietyDataGrid"
|
||||
FontSize="20"
|
||||
CanUserAddRows="True"
|
||||
AutoGenerateColumns="False"
|
||||
HeadersVisibility="All"
|
||||
VerticalContentAlignment="Center"
|
||||
ItemsSource="{Binding ViewModel.Varieties, Mode=OneWay}">
|
||||
ItemsSource="{Binding ViewModel.Varieties, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
CellEditEnding="DataGrid_CellEditEnding">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn
|
||||
Binding="{Binding Id}"
|
||||
@ -120,9 +121,10 @@
|
||||
<DataGridTemplateColumn Header="蜂窝板(中间)">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<ComboBox SelectedValue="{Binding Path=MiddlePallet}"
|
||||
ItemsSource="{Binding Path=ViewModel.Pallets,RelativeSource={RelativeSource AncestorType={x:Type Page},Mode=FindAncestor}}"
|
||||
DisplayMemberPath="Name">
|
||||
<ComboBox
|
||||
SelectedValue="{Binding Path=MiddlePallet,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
ItemsSource="{Binding Path=ViewModel.Pallets,RelativeSource={RelativeSource AncestorType={x:Type Page},Mode=FindAncestor}}"
|
||||
DisplayMemberPath="Name">
|
||||
</ComboBox>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
@ -130,10 +132,11 @@
|
||||
<DataGridTemplateColumn Header="蜂窝板(上下)">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<ComboBox SelectedValue="{Binding Path=MiddlePallet}"
|
||||
ItemsSource="{Binding Path=ViewModel.Pallets,RelativeSource={RelativeSource AncestorType={x:Type Page},Mode=FindAncestor}}"
|
||||
DisplayMemberPath="Name"
|
||||
materialDesign:TextFieldAssist.HasClearButton="True">
|
||||
<ComboBox
|
||||
SelectedValue="{Binding Path=TopAndBottomPallet,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
ItemsSource="{Binding Path=ViewModel.Pallets,RelativeSource={RelativeSource AncestorType={x:Type Page},Mode=FindAncestor}}"
|
||||
DisplayMemberPath="Name"
|
||||
materialDesign:TextFieldAssist.HasClearButton="True">
|
||||
</ComboBox>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
@ -141,9 +144,10 @@
|
||||
<DataGridTemplateColumn Header="托盘">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<ComboBox SelectedValue="{Binding Path=MiddlePallet}"
|
||||
ItemsSource="{Binding Path=ViewModel.Pallets,RelativeSource={RelativeSource AncestorType={x:Type Page},Mode=FindAncestor}}"
|
||||
DisplayMemberPath="Name" materialDesign:TextFieldAssist.HasClearButton="True">
|
||||
<ComboBox
|
||||
SelectedValue="{Binding Path=Tray,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
ItemsSource="{Binding Path=ViewModel.Pallets,RelativeSource={RelativeSource AncestorType={x:Type Page},Mode=FindAncestor}}"
|
||||
DisplayMemberPath="Name" materialDesign:TextFieldAssist.HasClearButton="True">
|
||||
</ComboBox>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
@ -151,9 +155,10 @@
|
||||
<DataGridTemplateColumn Header="纸板">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<ComboBox SelectedValue="{Binding Path=MiddlePallet}"
|
||||
ItemsSource="{Binding Path=ViewModel.Pallets,RelativeSource={RelativeSource AncestorType={x:Type Page},Mode=FindAncestor}}"
|
||||
DisplayMemberPath="Name" materialDesign:TextFieldAssist.HasClearButton="True">
|
||||
<ComboBox
|
||||
SelectedValue="{Binding Path=PaperTray,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
ItemsSource="{Binding Path=ViewModel.Pallets,RelativeSource={RelativeSource AncestorType={x:Type Page},Mode=FindAncestor}}"
|
||||
DisplayMemberPath="Name" materialDesign:TextFieldAssist.HasClearButton="True">
|
||||
</ComboBox>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
@ -166,19 +171,122 @@
|
||||
Binding="{Binding StackHeadCount }"
|
||||
Header="垛头数量"
|
||||
Width="Auto" />
|
||||
<DataGridComboBoxColumn
|
||||
TextBinding="{Binding NeedTopBoard }"
|
||||
ItemsSource="{Binding }"
|
||||
Header="顶板"
|
||||
Width="Auto" />
|
||||
<DataGridComboBoxColumn
|
||||
TextBinding="{Binding NeedAngleBeam }"
|
||||
Header="护角"
|
||||
Width="Auto" />
|
||||
<DataGridComboBoxColumn
|
||||
TextBinding="{Binding NeedFilmWrapping }"
|
||||
Header="缠膜"
|
||||
Width="Auto" />
|
||||
<DataGridComboBoxColumn Header="顶板" MinWidth="120"
|
||||
ItemsSource="{Binding Source={StaticResource NeedType}}"
|
||||
SelectedValueBinding="{Binding NeedTopBoard, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
TextBinding="{Binding NeedTopBoard}">
|
||||
<DataGridComboBoxColumn.ElementStyle>
|
||||
<Style TargetType="ComboBox" BasedOn="{StaticResource {x:Type ComboBox}}">
|
||||
<Setter Property="ItemTemplate">
|
||||
<Setter.Value>
|
||||
<DataTemplate>
|
||||
<TextBlock
|
||||
Text="{Binding Converter={StaticResource EnumDescriptionConverter}}" />
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</DataGridComboBoxColumn.ElementStyle>
|
||||
<DataGridComboBoxColumn.EditingElementStyle>
|
||||
<Style TargetType="ComboBox" BasedOn="{StaticResource {x:Type ComboBox}}">
|
||||
<Setter Property="ItemTemplate">
|
||||
<Setter.Value>
|
||||
<DataTemplate>
|
||||
<TextBlock
|
||||
Text="{Binding Converter={StaticResource EnumDescriptionConverter}}" />
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</DataGridComboBoxColumn.EditingElementStyle>
|
||||
</DataGridComboBoxColumn>
|
||||
<DataGridComboBoxColumn Header="护角" MinWidth="120"
|
||||
ItemsSource="{Binding Source={StaticResource NeedType}}"
|
||||
SelectedValueBinding="{Binding NeedAngleBeam, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
TextBinding="{Binding NeedAngleBeam}">
|
||||
<DataGridComboBoxColumn.ElementStyle>
|
||||
<Style TargetType="ComboBox" BasedOn="{StaticResource {x:Type ComboBox}}">
|
||||
<Setter Property="ItemTemplate">
|
||||
<Setter.Value>
|
||||
<DataTemplate>
|
||||
<TextBlock
|
||||
Text="{Binding Converter={StaticResource EnumDescriptionConverter}}" />
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</DataGridComboBoxColumn.ElementStyle>
|
||||
<DataGridComboBoxColumn.EditingElementStyle>
|
||||
<Style TargetType="ComboBox" BasedOn="{StaticResource {x:Type ComboBox}}">
|
||||
<Setter Property="ItemTemplate">
|
||||
<Setter.Value>
|
||||
<DataTemplate>
|
||||
<TextBlock
|
||||
Text="{Binding Converter={StaticResource EnumDescriptionConverter}}" />
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</DataGridComboBoxColumn.EditingElementStyle>
|
||||
</DataGridComboBoxColumn>
|
||||
<DataGridComboBoxColumn Header="打包带" MinWidth="120"
|
||||
ItemsSource="{Binding Source={StaticResource NeedType}}"
|
||||
SelectedValueBinding="{Binding NeedPackStrap, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
TextBinding="{Binding NeedPackStrap}">
|
||||
<DataGridComboBoxColumn.ElementStyle>
|
||||
<Style TargetType="ComboBox" BasedOn="{StaticResource {x:Type ComboBox}}">
|
||||
<Setter Property="ItemTemplate">
|
||||
<Setter.Value>
|
||||
<DataTemplate>
|
||||
<TextBlock
|
||||
Text="{Binding Converter={StaticResource EnumDescriptionConverter}}" />
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</DataGridComboBoxColumn.ElementStyle>
|
||||
<DataGridComboBoxColumn.EditingElementStyle>
|
||||
<Style TargetType="ComboBox" BasedOn="{StaticResource {x:Type ComboBox}}">
|
||||
<Setter Property="ItemTemplate">
|
||||
<Setter.Value>
|
||||
<DataTemplate>
|
||||
<TextBlock
|
||||
Text="{Binding Converter={StaticResource EnumDescriptionConverter}}" />
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</DataGridComboBoxColumn.EditingElementStyle>
|
||||
</DataGridComboBoxColumn>
|
||||
<DataGridComboBoxColumn Header="缠膜" MinWidth="120"
|
||||
ItemsSource="{Binding Source={StaticResource NeedType}}"
|
||||
SelectedValueBinding="{Binding NeedFilmWrapping, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
TextBinding="{Binding NeedFilmWrapping}">
|
||||
<DataGridComboBoxColumn.ElementStyle>
|
||||
<Style TargetType="ComboBox" BasedOn="{StaticResource {x:Type ComboBox}}">
|
||||
<Setter Property="ItemTemplate">
|
||||
<Setter.Value>
|
||||
<DataTemplate>
|
||||
<TextBlock
|
||||
Text="{Binding Converter={StaticResource EnumDescriptionConverter}}" />
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</DataGridComboBoxColumn.ElementStyle>
|
||||
<DataGridComboBoxColumn.EditingElementStyle>
|
||||
<Style TargetType="ComboBox" BasedOn="{StaticResource {x:Type ComboBox}}">
|
||||
<Setter Property="ItemTemplate">
|
||||
<Setter.Value>
|
||||
<DataTemplate>
|
||||
<TextBlock
|
||||
Text="{Binding Converter={StaticResource EnumDescriptionConverter}}" />
|
||||
</DataTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</DataGridComboBoxColumn.EditingElementStyle>
|
||||
</DataGridComboBoxColumn>
|
||||
<DataGridComboBoxColumn Header="覆膜" MinWidth="120"
|
||||
ItemsSource="{Binding Source={StaticResource NeedType}}"
|
||||
SelectedValueBinding="{Binding NeedFilmCoating, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
@ -221,13 +329,13 @@
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Button Margin="0,0,10,0" Content="保存"
|
||||
Command="{Binding ElementName=PalletWindow, Path=DataContext.ViewModel.SavePalletCommand}"
|
||||
Command="{Binding ElementName=VarietyRoot, Path=DataContext.ViewModel.SavePalletCommand}"
|
||||
CommandParameter="{Binding}"
|
||||
Visibility="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Path=IsEditing, Converter={StaticResource BooleanToVisibilityConverter}}" />
|
||||
<!-- 删除按钮 -->
|
||||
<Button Content="删除"
|
||||
Background="Red"
|
||||
Command="{Binding ElementName=PalletWindow, Path=DataContext.ViewModel.DeletePalletCommand}"
|
||||
Command="{Binding ElementName=VarietyRoot, Path=DataContext.ViewModel.DeletePalletCommand}"
|
||||
CommandParameter="{Binding}" />
|
||||
<!-- 保存按钮,根据 DataGridRow 的 IsEditing 属性控制可见性 -->
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Seyounth.Hyosung.Data.Entities;
|
||||
using Seyounth.Hyosung.ViewModels;
|
||||
@ -19,6 +20,12 @@ public partial class VarietyPage : Page
|
||||
ViewModel = viewModel;
|
||||
DataContext = this;
|
||||
InitializeComponent();
|
||||
WeakReferenceMessenger.Default.Register<PalletManagerViewModel.SavePalletCompletedMessage>(this, (r, m) =>
|
||||
{
|
||||
// 提交当前编辑并取消编辑模式
|
||||
VarietyDataGrid.CommitEdit();
|
||||
VarietyDataGrid.CancelEdit();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -27,4 +34,13 @@ public partial class VarietyPage : Page
|
||||
var dialog = _serviceProvider.GetService<PalletManagerWindow>();
|
||||
dialog.ShowDialog();
|
||||
}
|
||||
|
||||
private void DataGrid_CellEditEnding(object? sender, DataGridCellEditEndingEventArgs e)
|
||||
{
|
||||
if (e.EditAction == DataGridEditAction.Commit)
|
||||
{
|
||||
var binding = e.EditingElement.GetBindingExpression(TextBox.TextProperty);
|
||||
binding?.UpdateSource();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user