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