修改BUG增加功能

This commit is contained in:
zhangzhuo 2025-03-16 23:38:23 +08:00
parent 34014ed142
commit ba6cb6e03b
10 changed files with 117 additions and 10 deletions

View File

@ -2,4 +2,20 @@ using Seyounth.Hyosung.Data.Entities;
namespace Seyounth.Hyosung.Data.Models;
public class Pallet : PalletEntity;
public class Pallet : PalletEntity {
public static Pallet FromEntity(PalletEntity p)
{
return new Pallet()
{
Height = p.Height,
Width = p.Width,
Length = p.Length,
HoleCount = p.HoleCount,
Id = p.Id,
IsBigHole = p.IsBigHole,
Type = p.Type
};
}
}

View File

@ -15,5 +15,10 @@ public enum PalletType
/// <summary>
/// 木板托盘
/// </summary>
Wood = 2
Wood = 2,
/// <summary>
/// 蜂窝板
/// </summary>
Honey=3
}

View File

@ -87,13 +87,13 @@ public class Variety
NeedFilmCoating = entity.NeedFilmCoating,
MasterLabelCount = entity.MasterLabelCount,
SubLabelCount = entity.SubLabelCount,
MiddlePallet = (Pallet)pallets.First(x => x.Id == entity.MiddlePalletId),
TopAndBottomPallet = (Pallet)pallets.First(x => x.Id == entity.TopAndBottomPalletId),
Tray = (Pallet)pallets.First(x => x.Id == entity.TrayId),
MiddlePallet = Pallet.FromEntity( pallets.First(x => x.Id == entity.MiddlePalletId)),
TopAndBottomPallet = Pallet.FromEntity(pallets.First(x => x.Id == entity.TopAndBottomPalletId)),
Tray = Pallet.FromEntity(pallets.First(x => x.Id == entity.TrayId)),
HasBox = entity.HasBox
};
if (entity.PaperTrayId != null && entity.PaperTrayId != 0)
variety.PaperTray = (Pallet)pallets.First(x => x.Id == entity.PaperTrayId);
variety.PaperTray = Pallet.FromEntity(pallets.First(x => x.Id == entity.PaperTrayId));
return variety;
}
@ -146,6 +146,7 @@ public class Variety
ls.Add((short)Tray.Length);
ls.Add((short)Tray.Width);
ls.Add((short)Tray.Height);
ls.Add((short)(HasBox ? 70 : 0));
if (PaperTray is null)
{
ls.Add(0);

View File

@ -12,6 +12,8 @@ public interface IVarietyService
/// <returns></returns>
Task<Variety?> GetVarietyByCodeAsync(string code, int? layers = null);
List<Variety> GetAll();
Task<Variety> GetById(int id);
/// <summary>

View File

@ -50,7 +50,7 @@ public class VarietyService : IVarietyService
public async Task<List<Pallet>> GetPalletsAsync()
{
return _palletsCache.Select(p => (Pallet)p).ToList();
return _palletsCache.Select(p =>Pallet.FromEntity(p)).ToList();
}
public async Task AddPalletAsync(Pallet pallet)
@ -58,4 +58,9 @@ public class VarietyService : IVarietyService
var entity = await _palletRepository.InsertReturnEntityAsync(pallet);
_palletsCache.Add(entity);
}
public List<Variety> GetAll()
{
return _varietiesCache.Select(v=>Variety.Create(v, _palletsCache.ToList())).ToList();
}
}

View File

@ -2,12 +2,28 @@ using System.Diagnostics.Metrics;
using System.Windows;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Seyounth.Hyosung.Data.Models;
using Seyounth.Hyosung.Data.Services;
namespace Seyounth.Hyosung.ViewModels;
public partial class MainWindowViewModel : ObservableObject
{
[ObservableProperty] private string _applicationTitle = "Hyosung - Seyounth Auto";
[ObservableProperty] private List<Variety> varieties;
[ObservableProperty] private List<string> yarnCar=new();
public MainWindowViewModel(IVarietyService varietyService)
{
Varieties = varietyService.GetAll();
YarnCar.Add("A");
YarnCar.Add("B");
YarnCar.Add("C");
YarnCar.Add("D");
}
[RelayCommand]
private void OnExit()

View File

@ -69,8 +69,14 @@
Text="仪表盘" />
</StackPanel>
</TabItem.Header>
<Grid
Width="100" />
<Grid>
<StackPanel Orientation="Horizontal">
<ComboBox Margin="20" MinWidth="150" x:Name="VarietyCombox" ItemsSource="{Binding ViewModel.Varieties}" DisplayMemberPath="Code"/>
<ComboBox Margin="20" MinWidth="80" x:Name="YarnCarCombox" ItemsSource="{Binding ViewModel.YarnCar}"/>
<Button Margin="20" Content="发送" Click="Button_Click"/>
</StackPanel>
</Grid>
</TabItem>
<TabItem x:Name="VarietyTabItem">
<TabItem.Header>

View File

@ -1,4 +1,7 @@
using System.Windows;
using Seyounth.Hyosung.Data.Models;
using Seyounth.Hyosung.Data.Services;
using Seyounth.Hyosung.Runtime;
using Seyounth.Hyosung.ViewModels;
using Seyounth.Hyosung.Views.Pages;
@ -11,11 +14,22 @@ public partial class MainWindow
{
public MainWindowViewModel ViewModel { get; }
public MainWindow(MainWindowViewModel viewModel, VarietyPage varietyPage)
private readonly IHyosungRuntime hyosungRuntime;
public MainWindow(MainWindowViewModel viewModel, VarietyPage varietyPage,IHyosungRuntime hyosung)
{
ViewModel = viewModel;
DataContext = this;
InitializeComponent();
VarietyFrame.Content = varietyPage;
hyosungRuntime = hyosung;
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
var variety = VarietyCombox.SelectedItem as Variety;
variety.YarnCarSide = 1;
variety.YarnCarType = YarnCarCombox.SelectedIndex + 1;
await hyosungRuntime.SendVarietyToPlcAsync(variety);
}
}

View File

@ -0,0 +1,14 @@
<Page x:Class="Seyounth.Hyosung.Views.Pages.HomeViewPage"
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.Pages"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="HomeViewPage">
<Grid>
</Grid>
</Page>

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Seyounth.Hyosung.Views.Pages
{
/// <summary>
/// HomeViewPage.xaml 的交互逻辑
/// </summary>
public partial class HomeViewPage : Page
{
public HomeViewPage()
{
InitializeComponent();
}
}
}