增加功能
This commit is contained in:
parent
42dfa6d96c
commit
550d0b7308
@ -15,7 +15,6 @@ public class HyosungPlcService(ILogger<HyosungPlcService> logger) : IHyosungPlcS
|
||||
|
||||
public async Task StartAsync(CancellationToken token)
|
||||
{
|
||||
token = token;
|
||||
List<Task<int>> ls =
|
||||
[
|
||||
_reader.ConnectAsync(),
|
||||
|
@ -12,7 +12,20 @@ public class McPlc(string host, int port, Mitsubishi.McFrame type)
|
||||
_mc.HostName = host;
|
||||
_mc.PortNumber = port;
|
||||
_mc.CommandFrame = type;
|
||||
return await _mc.Open();
|
||||
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(1));
|
||||
var openTask = Task.Run(()=>_mc.Open(), cts.Token) ;
|
||||
|
||||
var completedTask = await Task.WhenAny(
|
||||
openTask,
|
||||
Task.Delay(Timeout.Infinite, cts.Token)
|
||||
);
|
||||
|
||||
if (completedTask != openTask)
|
||||
{
|
||||
throw new TimeoutException("PLC 连接超时 (1 秒未响应)");
|
||||
}
|
||||
|
||||
return await openTask;
|
||||
}
|
||||
|
||||
public Task<int> CloseAsync()
|
||||
|
@ -1,8 +1,13 @@
|
||||
using Seyounth.Core.Extensions;
|
||||
using Seyounth.Hyosung.Data.Entities;
|
||||
|
||||
namespace Seyounth.Hyosung.Data.Models;
|
||||
|
||||
public class Pallet : PalletEntity {
|
||||
public class Pallet : PalletEntity
|
||||
{
|
||||
public string Name =>
|
||||
$"{Type.GetDescription()}({Width}*{Height}*{Length})({HoleCount}|{(IsBigHole != null && IsBigHole.Value ? "大" : "小")})";
|
||||
|
||||
public static Pallet FromEntity(PalletEntity p)
|
||||
{
|
||||
return new Pallet()
|
||||
@ -16,6 +21,4 @@ public class Pallet : PalletEntity {
|
||||
Type = p.Type
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Seyounth.Hyosung.Data.Models;
|
||||
|
||||
public enum PalletType
|
||||
@ -5,20 +7,20 @@ public enum PalletType
|
||||
/// <summary>
|
||||
/// 纸板托盘
|
||||
/// </summary>
|
||||
Paper=0,
|
||||
[Description("纸板")] Paper = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 胶合板托盘
|
||||
/// </summary>
|
||||
Plywood = 1,
|
||||
[Description("胶合板")] Plywood = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 木板托盘
|
||||
/// </summary>
|
||||
Wood = 2,
|
||||
[Description("木托")] Wood = 2,
|
||||
|
||||
/// <summary>
|
||||
/// 蜂窝板
|
||||
/// </summary>
|
||||
Honey=3
|
||||
[Description("蜂窝板")] Honey = 3
|
||||
}
|
@ -17,22 +17,22 @@ public static class ServiceExtensions
|
||||
services.AddSingleton<ISqlSugarClient>(s =>
|
||||
{
|
||||
//#if RELEASE
|
||||
SqlSugarScope sqlSugar = new SqlSugarScope(new ConnectionConfig()
|
||||
{
|
||||
DbType = DbType.SqlServer,
|
||||
ConnectionString = connectionString,
|
||||
IsAutoCloseConnection = true,
|
||||
}
|
||||
);
|
||||
//#elif DEBUG
|
||||
// SqlSugarScope sqlSugar = new SqlSugarScope(new ConnectionConfig()
|
||||
// {
|
||||
// DbType = DbType.Sqlite,
|
||||
// ConnectionString = "Data Source=hyosung.db",
|
||||
// DbType = DbType.SqlServer,
|
||||
// ConnectionString = connectionString,
|
||||
// IsAutoCloseConnection = true,
|
||||
// InitKeyType = InitKeyType.Attribute
|
||||
// }
|
||||
// );
|
||||
//#elif DEBUG
|
||||
SqlSugarScope sqlSugar = new SqlSugarScope(new ConnectionConfig()
|
||||
{
|
||||
DbType = DbType.Sqlite,
|
||||
ConnectionString = "Data Source=hyosung.db",
|
||||
IsAutoCloseConnection = true,
|
||||
InitKeyType = InitKeyType.Attribute
|
||||
}
|
||||
);
|
||||
//#endif
|
||||
return sqlSugar;
|
||||
});
|
||||
@ -43,6 +43,7 @@ public static class ServiceExtensions
|
||||
services.AddSingleton<IAgvBinService, AgvBinService>();
|
||||
services.AddSingleton<IDictService, DictService>();
|
||||
services.AddSingleton<IHyosungWmsService, HyosungWmsService>();
|
||||
services.AddSingleton<IPalletService, PalletService>();
|
||||
return services;
|
||||
}
|
||||
|
||||
|
14
Seyounth.Hyosung.Data/Services/IPalletService.cs
Normal file
14
Seyounth.Hyosung.Data/Services/IPalletService.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using Seyounth.Hyosung.Data.Models;
|
||||
|
||||
namespace Seyounth.Hyosung.Data.Services;
|
||||
|
||||
public interface IPalletService
|
||||
{
|
||||
List<Pallet> GetPallets();
|
||||
|
||||
Task<int> AddPalletAsync(Pallet pallet);
|
||||
|
||||
Task DeletePalletAsync(Pallet pallet);
|
||||
|
||||
Task UpdatePalletAsync(Pallet pallet);
|
||||
}
|
44
Seyounth.Hyosung.Data/Services/PalletService.cs
Normal file
44
Seyounth.Hyosung.Data/Services/PalletService.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Seyounth.Hyosung.Data.Entities;
|
||||
using Seyounth.Hyosung.Data.Models;
|
||||
using Seyounth.Hyosung.Data.Repositories;
|
||||
|
||||
namespace Seyounth.Hyosung.Data.Services;
|
||||
|
||||
public class PalletService : IPalletService
|
||||
{
|
||||
private readonly List<Pallet> _pallets;
|
||||
public readonly IRepository<PalletEntity> _palletRepository;
|
||||
|
||||
public PalletService(IServiceProvider serviceProvider)
|
||||
{
|
||||
_palletRepository = serviceProvider.CreateScope().ServiceProvider
|
||||
.GetRequiredService<IRepository<PalletEntity>>();
|
||||
_pallets = _palletRepository.GetList().Select(Pallet.FromEntity).ToList();
|
||||
}
|
||||
|
||||
public List<Pallet> GetPallets()
|
||||
{
|
||||
return _pallets;
|
||||
}
|
||||
|
||||
public async Task<int> AddPalletAsync(Pallet pallet)
|
||||
{
|
||||
var id = await _palletRepository.InsertReturnIdentityAsync(pallet);
|
||||
pallet.Id = id;
|
||||
_pallets.Add(pallet);
|
||||
return id;
|
||||
}
|
||||
|
||||
public async Task DeletePalletAsync(Pallet pallet)
|
||||
{
|
||||
await _palletRepository.DeleteAsync(pallet);
|
||||
_pallets.Remove(pallet);
|
||||
}
|
||||
|
||||
public async Task UpdatePalletAsync(Pallet pallet)
|
||||
{
|
||||
await _palletRepository.UpdateAsync(pallet);
|
||||
_pallets[_pallets.IndexOf(pallet)] = pallet;
|
||||
}
|
||||
}
|
@ -32,6 +32,7 @@ public class HyosungRuntime(
|
||||
{
|
||||
//启动扫码服务
|
||||
await hyosungScannerService.StartAsync(token);
|
||||
await printer.StartAsync(token);
|
||||
//最后启动PLC服务
|
||||
hyosungPlcService.OnPlcRequestScanProduct += OnPlcRequestScanProduct;
|
||||
hyosungPlcService.OnPlcRequestScanFixture += OnPlcRequestScanFixture;
|
||||
@ -46,7 +47,7 @@ public class HyosungRuntime(
|
||||
public async Task StopAsync(CancellationToken token)
|
||||
{
|
||||
//先停止扫码服务
|
||||
// await hyosungScannerService.StopAsync(token);
|
||||
await hyosungScannerService.StopAsync(token);
|
||||
await printer.StopAsync(token);
|
||||
//先停止PLC服务
|
||||
//解绑相关事件
|
||||
|
@ -12,7 +12,7 @@ public class HyosungWorker(IHyosungRuntime runtime) : BackgroundService
|
||||
|
||||
public override async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
await runtime.StartAsync(cancellationToken);
|
||||
runtime.StartAsync(cancellationToken);
|
||||
await base.StartAsync(cancellationToken);
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ using Seyounth.Hyosung.Services;
|
||||
using Seyounth.Hyosung.ViewModels;
|
||||
using Seyounth.Hyosung.Views;
|
||||
using Seyounth.Hyosung.Views.Pages;
|
||||
using Seyounth.Hyosung.Views.Windows;
|
||||
|
||||
namespace Seyounth.Hyosung;
|
||||
|
||||
@ -40,6 +41,8 @@ public partial class App : Application
|
||||
builder.Services.AddSingleton<VarietyViewModel>();
|
||||
builder.Services.AddSingleton<HomeViewPage>();
|
||||
builder.Services.AddSingleton<HomeViewModel>();
|
||||
builder.Services.AddTransient<PalletManagerWindow>();
|
||||
builder.Services.AddSingleton<PalletManagerViewModel>();
|
||||
builder.Services.AddHyosung(builder.Configuration);
|
||||
|
||||
_host = builder.Build();
|
||||
|
12
Seyounth.Hyosung/Helpers/EnumDisplayHelper.cs
Normal file
12
Seyounth.Hyosung/Helpers/EnumDisplayHelper.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
|
||||
public class EnumDisplayHelper
|
||||
{
|
||||
public static string DisplayName(object item)
|
||||
{
|
||||
if (item == null) return "";
|
||||
var field = item.GetType().GetField(item.ToString());
|
||||
return field?.GetCustomAttribute<DescriptionAttribute>()?.Description ?? item.ToString();
|
||||
}
|
||||
}
|
24
Seyounth.Hyosung/ViewConverter/EnumDescriptionConverter.cs
Normal file
24
Seyounth.Hyosung/ViewConverter/EnumDescriptionConverter.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace Seyounth.Hyosung.ViewConverter;
|
||||
|
||||
public class EnumDescriptionConverter : IValueConverter
|
||||
{
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value == null) return null;
|
||||
|
||||
var field = value.GetType().GetField(value.ToString() ?? string.Empty);
|
||||
if (field == null) return null;
|
||||
|
||||
var attributes = field.GetCustomAttributes(typeof(DescriptionAttribute), false);
|
||||
return attributes.Length == 0 ? value.ToString() : ((DescriptionAttribute)attributes[0]).Description;
|
||||
}
|
||||
|
||||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
40
Seyounth.Hyosung/ViewConverter/PalletToStringConverter.cs
Normal file
40
Seyounth.Hyosung/ViewConverter/PalletToStringConverter.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System.Globalization;
|
||||
using System.Net.Mime;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using Seyounth.Hyosung.Data.Models;
|
||||
using Seyounth.Hyosung.ViewModels;
|
||||
|
||||
namespace Seyounth.Hyosung.ViewConverter;
|
||||
|
||||
public class PalletToStringConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is Pallet pallet)
|
||||
{
|
||||
// 这里根据 Pallet 类的属性选择合适的字符串表示
|
||||
return pallet.Name;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is string palletName)
|
||||
{
|
||||
// 这里需要根据实际情况实现反向转换逻辑
|
||||
// 例如,从名称查找对应的 Pallet 对象
|
||||
// 假设在 ViewModel 中有一个 Pallets 集合
|
||||
// 修正:获取正确的 ViewModel 引用
|
||||
var viewModel = Application.Current.MainWindow.DataContext as VarietyViewModel;
|
||||
if (viewModel != null)
|
||||
{
|
||||
return viewModel.Pallets.FirstOrDefault(p => p.Name == palletName);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
55
Seyounth.Hyosung/ViewModels/PalletManagerViewModel.cs
Normal file
55
Seyounth.Hyosung/ViewModels/PalletManagerViewModel.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Seyounth.Hyosung.Data.Models;
|
||||
using Seyounth.Hyosung.Data.Services;
|
||||
|
||||
namespace Seyounth.Hyosung.ViewModels;
|
||||
|
||||
public partial class PalletManagerViewModel : ObservableObject
|
||||
{
|
||||
[ObservableProperty] private ObservableCollection<Pallet> _pallets;
|
||||
|
||||
private readonly IPalletService _palletService;
|
||||
|
||||
public PalletManagerViewModel(IPalletService palletService)
|
||||
{
|
||||
Pallets = new ObservableCollection<Pallet>(palletService.GetPallets());
|
||||
_palletService = palletService;
|
||||
}
|
||||
|
||||
public class SavePalletCompletedMessage
|
||||
{
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void OnDeletePallet(object obj)
|
||||
{
|
||||
if (obj is Pallet pallet)
|
||||
{
|
||||
Pallets.Remove(pallet);
|
||||
_palletService.DeletePalletAsync(pallet);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Write("Object is not a Pallet");
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void OnSavePallet(object obj)
|
||||
{
|
||||
if (obj is Pallet pallet)
|
||||
{
|
||||
if (pallet.Id == 0)
|
||||
{
|
||||
_palletService.AddPalletAsync(pallet);
|
||||
}
|
||||
else
|
||||
_palletService.UpdatePalletAsync(pallet);
|
||||
}
|
||||
|
||||
WeakReferenceMessenger.Default.Send(new SavePalletCompletedMessage());
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Seyounth.Core.Extensions;
|
||||
using Seyounth.Hyosung.Data.Entities;
|
||||
@ -7,12 +8,17 @@ namespace Seyounth.Hyosung.ViewModels;
|
||||
|
||||
public partial class VarietyViewModel : ObservableObject
|
||||
{
|
||||
[ObservableProperty] private List<VarietyEntity> _varieties;
|
||||
[ObservableProperty] private ObservableCollection<Variety> _varieties;
|
||||
|
||||
[ObservableProperty] private ObservableCollection<Pallet> _pallets;
|
||||
|
||||
public IEnumerable<NeedTypeEnumItem> NeedTypeItems { get; }
|
||||
public VarietyViewModel()
|
||||
|
||||
public VarietyViewModel(PalletManagerViewModel palletManagerViewModel)
|
||||
{
|
||||
_varieties = new List<VarietyEntity>();
|
||||
Pallets = new ObservableCollection<Pallet>(palletManagerViewModel.Pallets);
|
||||
|
||||
_varieties = new ObservableCollection<Variety>();
|
||||
var needTypes = EnumHelper.GetValues<NeedType>();
|
||||
NeedTypeItems = needTypes.Select(nt => new NeedTypeEnumItem
|
||||
{
|
||||
@ -20,6 +26,4 @@ public partial class VarietyViewModel : ObservableObject
|
||||
Description = nt.GetDescription()
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
<UserControl x:Class="Seyounth.Hyosung.Views.Controls.AddVarietyControl"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Seyounth.Hyosung.Views.Controls"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300" d:DesignWidth="300">
|
||||
<StackPanel
|
||||
Margin="16">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="3*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="产品编号:" VerticalAlignment="Center" Margin="0,0,10,0"/>
|
||||
<TextBox Grid.Column="1"
|
||||
x:Name="VarietyCodeTextBox">
|
||||
</TextBox>
|
||||
</Grid>
|
||||
|
||||
<TextBox Grid.Row="1"
|
||||
x:Name="LotTextBox"
|
||||
materialDesign:HintAssist.Hint="Lot">
|
||||
</TextBox>
|
||||
</Grid>
|
||||
<StackPanel
|
||||
HorizontalAlignment="Right"
|
||||
Orientation="Horizontal">
|
||||
<Button
|
||||
Margin="0,8,8,0"
|
||||
Content="ACCEPT"
|
||||
IsDefault="True"
|
||||
Style="{StaticResource MaterialDesignFlatButton}">
|
||||
<Button.CommandParameter>
|
||||
<system:Boolean
|
||||
xmlns:system="clr-namespace:System;assembly=mscorlib">
|
||||
True
|
||||
</system:Boolean>
|
||||
</Button.CommandParameter>
|
||||
</Button>
|
||||
<Button
|
||||
Margin="0,8,8,0"
|
||||
Content="CANCEL"
|
||||
IsCancel="True"
|
||||
Style="{StaticResource MaterialDesignFlatButton}">
|
||||
<Button.CommandParameter>
|
||||
<system:Boolean
|
||||
xmlns:system="clr-namespace:System;assembly=mscorlib">
|
||||
False
|
||||
</system:Boolean>
|
||||
</Button.CommandParameter>
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</UserControl>
|
@ -1,22 +0,0 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Seyounth.Hyosung.Views.Controls;
|
||||
|
||||
public partial class AddVarietyControl : UserControl
|
||||
{
|
||||
public AddVarietyControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void CancelButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private void OkButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
@ -5,14 +5,27 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Seyounth.Hyosung.Views.Pages"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:viewConverter="clr-namespace:Seyounth.Hyosung.ViewConverter"
|
||||
xmlns:diagnostics="clr-namespace:System.Diagnostics;assembly=WindowsBase"
|
||||
xmlns:models="clr-namespace:Seyounth.Hyosung.Data.Models;assembly=Seyounth.Hyosung.Data"
|
||||
xmlns:system="clr-namespace:System;assembly=System.Runtime"
|
||||
mc:Ignorable="d"
|
||||
x:Name="VarietyRoot"
|
||||
Width="Auto"
|
||||
Height="Auto"
|
||||
d:DataContext="{d:DesignInstance local:VarietyPage,
|
||||
IsDesignTimeCreatable=True}">
|
||||
<materialDesign:DialogHost x:Name="Root"
|
||||
DialogMargin="8"
|
||||
Style="{StaticResource MaterialDesignEmbeddedDialogHost}" >
|
||||
<Page.Resources>
|
||||
<ObjectDataProvider x:Key="NeedType"
|
||||
ObjectType="{x:Type system:Enum}"
|
||||
MethodName="GetValues">
|
||||
<ObjectDataProvider.MethodParameters>
|
||||
<x:Type TypeName="models:NeedType" />
|
||||
</ObjectDataProvider.MethodParameters>
|
||||
</ObjectDataProvider>
|
||||
<viewConverter:EnumDescriptionConverter x:Key="EnumDescriptionConverter" />
|
||||
<viewConverter:PalletToStringConverter x:Key="PalletToStringConverter" />
|
||||
</Page.Resources>
|
||||
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
@ -21,42 +34,45 @@
|
||||
<ToolBarTray>
|
||||
<ToolBar ClipToBounds="False"
|
||||
Style="{StaticResource MaterialDesignToolBar}">
|
||||
<Button
|
||||
Content="{materialDesign:PackIcon Kind=Add}"
|
||||
Click="ButtonBase_OnClick"
|
||||
ToolTip="新增" />
|
||||
<Button
|
||||
Content="{materialDesign:PackIcon Kind=Edit}"
|
||||
ToolTip="编辑" />
|
||||
<Button
|
||||
Content="{materialDesign:PackIcon Kind=Delete}"
|
||||
ToolTip="删除" />
|
||||
<Separator />
|
||||
<ComboBox Margin="8"
|
||||
FontSize="20"
|
||||
VerticalAlignment="Center"
|
||||
Width="400"
|
||||
materialDesign:HintAssist.Hint="品类编号"
|
||||
materialDesign:TextFieldAssist.HasClearButton="False"
|
||||
IsEditable="False"
|
||||
ItemsSource="{Binding ViewModel.Varieties}"
|
||||
DisplayMemberPath="Code"
|
||||
Style="{StaticResource MaterialDesignFilledComboBox}">
|
||||
Style="{StaticResource MaterialDesignOutlinedComboBox}">
|
||||
</ComboBox>
|
||||
<Button
|
||||
Content="{materialDesign:PackIcon Kind=Search}"
|
||||
ToolTip="搜索" />
|
||||
<Button Content="{materialDesign:PackIcon Kind=Search}" />
|
||||
<Separator />
|
||||
<TextBox Margin="8"
|
||||
Width="100"
|
||||
FontSize="20"
|
||||
HorizontalContentAlignment="Left"
|
||||
materialDesign:HintAssist.Hint="LOT"
|
||||
Style="{StaticResource MaterialDesignOutlinedTextBox}" />
|
||||
<Button Content="{materialDesign:PackIcon Kind=Search}" />
|
||||
<Separator />
|
||||
<Button x:Name="TrayManagerButton"
|
||||
Content="{materialDesign:PackIcon Kind=ShippingPallet}"
|
||||
Click="TrayManagerButton_OnClick"
|
||||
ToolTip="托盘/隔板管理" />
|
||||
</ToolBar>
|
||||
</ToolBarTray>
|
||||
<materialDesign:Card Margin="0,10,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
|
||||
Width="Auto"
|
||||
Height="Auto"
|
||||
Grid.Row="1">
|
||||
<DataGrid x:Name="VarietyDataGrid"
|
||||
<DataGrid Grid.Row="0" x:Name="VarietyDataGrid"
|
||||
FontSize="20"
|
||||
CanUserAddRows="True"
|
||||
AutoGenerateColumns="False"
|
||||
HeadersVisibility="All"
|
||||
ItemsSource="{Binding ViewModel.Varieties, Mode=OneWay}"
|
||||
SelectionUnit="{Binding ElementName=selectionUnitComboBox, Path=SelectedValue}">
|
||||
VerticalContentAlignment="Center"
|
||||
ItemsSource="{Binding ViewModel.Varieties, Mode=OneWay}">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn
|
||||
Binding="{Binding Id}"
|
||||
Header="ID"
|
||||
Width="Auto" />
|
||||
<DataGridTextColumn
|
||||
Binding="{Binding Code}"
|
||||
Header="代码"
|
||||
@ -101,6 +117,47 @@
|
||||
Binding="{Binding TotalCount }"
|
||||
Header="个/托"
|
||||
Width="Auto" />
|
||||
<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>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<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>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<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>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<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>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
<DataGridTextColumn
|
||||
Binding="{Binding StackHeadSpec }"
|
||||
Header="垛头尺寸"
|
||||
@ -122,10 +179,35 @@
|
||||
TextBinding="{Binding NeedFilmWrapping }"
|
||||
Header="缠膜"
|
||||
Width="Auto" />
|
||||
<DataGridComboBoxColumn
|
||||
TextBinding="{Binding NeedFilmCoating }"
|
||||
Header="覆膜"
|
||||
Width="Auto" />
|
||||
<DataGridComboBoxColumn Header="覆膜" MinWidth="120"
|
||||
ItemsSource="{Binding Source={StaticResource NeedType}}"
|
||||
SelectedValueBinding="{Binding NeedFilmCoating, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
TextBinding="{Binding NeedFilmCoating}">
|
||||
<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>
|
||||
<DataGridTextColumn
|
||||
Binding="{Binding MasterLabelCount }"
|
||||
Header="主标签数量"
|
||||
@ -134,9 +216,26 @@
|
||||
Binding="{Binding SubLabelCount }"
|
||||
Header="副标签数量"
|
||||
Width="Auto" />
|
||||
<DataGridTemplateColumn Header="操作">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Button Margin="0,0,10,0" Content="保存"
|
||||
Command="{Binding ElementName=PalletWindow, 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}"
|
||||
CommandParameter="{Binding}" />
|
||||
<!-- 保存按钮,根据 DataGridRow 的 IsEditing 属性控制可见性 -->
|
||||
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</materialDesign:Card>
|
||||
</Grid>
|
||||
</materialDesign:DialogHost>
|
||||
</Page>
|
@ -1,10 +1,9 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Seyounth.Hyosung.Data.Entities;
|
||||
using Seyounth.Hyosung.Data.Models;
|
||||
using Seyounth.Hyosung.ViewModels;
|
||||
using Seyounth.Hyosung.Views.Controls;
|
||||
using Seyounth.Hyosung.Views.Windows;
|
||||
|
||||
namespace Seyounth.Hyosung.Views.Pages;
|
||||
|
||||
@ -12,25 +11,20 @@ public partial class VarietyPage : Page
|
||||
{
|
||||
public VarietyViewModel ViewModel { get; set; }
|
||||
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public VarietyPage(VarietyViewModel viewModel)
|
||||
public VarietyPage(VarietyViewModel viewModel, IServiceProvider serviceProvider)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
ViewModel = viewModel;
|
||||
DataContext = this;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
|
||||
private async void ButtonBase_OnClick(object sender, RoutedEventArgs e)
|
||||
private void TrayManagerButton_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var blankVariety = new VarietyEntity()
|
||||
;
|
||||
// 将空白对象添加到数据源中
|
||||
ViewModel.Varieties.Add(blankVariety);
|
||||
// 滚动到新添加的行并使其进入编辑状态
|
||||
VarietyDataGrid.ScrollIntoView(blankVariety);
|
||||
var index = ViewModel.Varieties.IndexOf(blankVariety);
|
||||
VarietyDataGrid.SelectedIndex = index;
|
||||
VarietyDataGrid.BeginEdit();
|
||||
var dialog = _serviceProvider.GetService<PalletManagerWindow>();
|
||||
dialog.ShowDialog();
|
||||
}
|
||||
}
|
106
Seyounth.Hyosung/Views/Windows/PalletManagerWindow.xaml
Normal file
106
Seyounth.Hyosung/Views/Windows/PalletManagerWindow.xaml
Normal file
@ -0,0 +1,106 @@
|
||||
<Window x:Class="Seyounth.Hyosung.Views.Windows.PalletManagerWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Seyounth.Hyosung.Views.Windows"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:viewConverter="clr-namespace:Seyounth.Hyosung.ViewConverter"
|
||||
xmlns:system="clr-namespace:System;assembly=System.Runtime"
|
||||
xmlns:models="clr-namespace:Seyounth.Hyosung.Data.Models;assembly=Seyounth.Hyosung.Data"
|
||||
xmlns:global="clr-namespace:"
|
||||
mc:Ignorable="d" WindowStyle="None"
|
||||
SizeToContent="WidthAndHeight"
|
||||
AllowsTransparency="True"
|
||||
x:Name="PalletWindow"
|
||||
Margin="0" Padding="0"
|
||||
d:DesignHeight="800" d:DesignWidth="600"
|
||||
d:DataContext="{d:DesignInstance local:PalletManagerWindow,
|
||||
IsDesignTimeCreatable=True}"
|
||||
WindowStartupLocation="CenterScreen">
|
||||
<Window.Resources>
|
||||
<ObjectDataProvider x:Key="PalletTypes"
|
||||
MethodName="GetValues"
|
||||
ObjectType="{x:Type system:Enum}">
|
||||
<ObjectDataProvider.MethodParameters>
|
||||
<x:Type TypeName="models:PalletType" />
|
||||
</ObjectDataProvider.MethodParameters>
|
||||
</ObjectDataProvider>
|
||||
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
|
||||
<viewConverter:EnumDescriptionConverter x:Key="EnumDescriptionConverter" />
|
||||
</Window.Resources>
|
||||
<GroupBox materialDesign:ElevationAssist.Elevation="Dp6"
|
||||
FontSize="22"
|
||||
Header="托盘\隔板管理"
|
||||
Style="{StaticResource MaterialDesignCardGroupBox}">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<DataGrid x:Name="PalletDataGrid" FontSize="20" Grid.Row="0"
|
||||
ItemsSource="{Binding ViewModel.Pallets, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
AutoGenerateColumns="False"
|
||||
CellEditEnding="DataGrid_CellEditEnding"> <!-- 添加事件处理 -->
|
||||
<DataGrid.Columns>
|
||||
<DataGridComboBoxColumn Header="托盘类型" MinWidth="120"
|
||||
ItemsSource="{Binding Source={StaticResource PalletTypes}}"
|
||||
SelectedValueBinding="{Binding Type, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
TextBinding="{Binding Type}">
|
||||
<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>
|
||||
<DataGridTextColumn Header="长度" Binding="{Binding Length}" />
|
||||
<DataGridTextColumn Header="宽度" Binding="{Binding Width}" />
|
||||
<DataGridTextColumn Header="高度" Binding="{Binding Height}" />
|
||||
<DataGridTextColumn Header="孔数" Binding="{Binding HoleCount}" />
|
||||
<DataGridCheckBoxColumn Header="大孔" Binding="{Binding IsBigHole}" />
|
||||
<DataGridTemplateColumn Header="操作">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Button Margin="0,0,10,0" Content="保存"
|
||||
Command="{Binding ElementName=PalletWindow, 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}"
|
||||
CommandParameter="{Binding}" />
|
||||
<!-- 保存按钮,根据 DataGridRow 的 IsEditing 属性控制可见性 -->
|
||||
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
<StackPanel Margin="16" Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right">
|
||||
<Button x:Name="ExitButton" Click="ExitButton_OnClick" Width="100" FontSize="22" Content="确定" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</Window>
|
39
Seyounth.Hyosung/Views/Windows/PalletManagerWindow.xaml.cs
Normal file
39
Seyounth.Hyosung/Views/Windows/PalletManagerWindow.xaml.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Seyounth.Hyosung.ViewModels;
|
||||
|
||||
namespace Seyounth.Hyosung.Views.Windows;
|
||||
|
||||
public partial class PalletManagerWindow : Window
|
||||
{
|
||||
public PalletManagerViewModel ViewModel { get; set; }
|
||||
|
||||
public PalletManagerWindow(PalletManagerViewModel viewModel)
|
||||
{
|
||||
ViewModel = viewModel;
|
||||
DataContext = this;
|
||||
InitializeComponent();
|
||||
WeakReferenceMessenger.Default.Register<PalletManagerViewModel.SavePalletCompletedMessage>(this, (r, m) =>
|
||||
{
|
||||
// 提交当前编辑并取消编辑模式
|
||||
PalletDataGrid.CommitEdit();
|
||||
PalletDataGrid.CancelEdit();
|
||||
});
|
||||
}
|
||||
|
||||
private void ExitButton_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
|
||||
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