From 56429cdf7de54dd637accfd53e8d0dd2427f2a74 Mon Sep 17 00:00:00 2001
From: anerx <512464164@qq.com>
Date: Mon, 17 Mar 2025 01:56:27 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.idea/.idea.Seyounth.Hyosung/.idea/.name | 1 +
.../.idea/MarsCodeWorkspaceAppSettings.xml | 7 +
.idea/.idea.Seyounth.Hyosung/.idea/vcs.xml | 6 +
Seyounth.Hyosung.Data/Models/Variety.cs | 3 +-
Seyounth.Hyosung.Data/ServiceExtensions.cs | 11 +
Seyounth.Hyosung/App.xaml.cs | 9 +-
Seyounth.Hyosung/Models/StackModel.cs | 19 ++
Seyounth.Hyosung/ViewModels/HomeViewModel.cs | 32 +++
.../ViewModels/MainWindowViewModel.cs | 9 -
Seyounth.Hyosung/Views/MainWindow.xaml | 10 +-
Seyounth.Hyosung/Views/MainWindow.xaml.cs | 15 +-
.../Views/Pages/HomeViewPage.xaml | 191 +++++++++++++++++-
.../Views/Pages/HomeViewPage.xaml.cs | 60 ++++--
13 files changed, 319 insertions(+), 54 deletions(-)
create mode 100644 .idea/.idea.Seyounth.Hyosung/.idea/.name
create mode 100644 .idea/.idea.Seyounth.Hyosung/.idea/MarsCodeWorkspaceAppSettings.xml
create mode 100644 .idea/.idea.Seyounth.Hyosung/.idea/vcs.xml
create mode 100644 Seyounth.Hyosung/Models/StackModel.cs
create mode 100644 Seyounth.Hyosung/ViewModels/HomeViewModel.cs
diff --git a/.idea/.idea.Seyounth.Hyosung/.idea/.name b/.idea/.idea.Seyounth.Hyosung/.idea/.name
new file mode 100644
index 0000000..8279f94
--- /dev/null
+++ b/.idea/.idea.Seyounth.Hyosung/.idea/.name
@@ -0,0 +1 @@
+Seyounth.Hyosung
\ No newline at end of file
diff --git a/.idea/.idea.Seyounth.Hyosung/.idea/MarsCodeWorkspaceAppSettings.xml b/.idea/.idea.Seyounth.Hyosung/.idea/MarsCodeWorkspaceAppSettings.xml
new file mode 100644
index 0000000..d4033ac
--- /dev/null
+++ b/.idea/.idea.Seyounth.Hyosung/.idea/MarsCodeWorkspaceAppSettings.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.Seyounth.Hyosung/.idea/vcs.xml b/.idea/.idea.Seyounth.Hyosung/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/.idea.Seyounth.Hyosung/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Seyounth.Hyosung.Data/Models/Variety.cs b/Seyounth.Hyosung.Data/Models/Variety.cs
index be26976..523e24f 100644
--- a/Seyounth.Hyosung.Data/Models/Variety.cs
+++ b/Seyounth.Hyosung.Data/Models/Variety.cs
@@ -4,6 +4,7 @@ namespace Seyounth.Hyosung.Data.Models;
public class Variety
{
+ public string Name => $"{Id} - {Code} - {StackingLayers}";
public int Id { get; set; }
public string Code { get; set; }
@@ -87,7 +88,7 @@ public class Variety
NeedFilmCoating = entity.NeedFilmCoating,
MasterLabelCount = entity.MasterLabelCount,
SubLabelCount = entity.SubLabelCount,
- MiddlePallet = Pallet.FromEntity( pallets.First(x => x.Id == entity.MiddlePalletId)),
+ 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
diff --git a/Seyounth.Hyosung.Data/ServiceExtensions.cs b/Seyounth.Hyosung.Data/ServiceExtensions.cs
index d5f39cf..c8c2cc1 100644
--- a/Seyounth.Hyosung.Data/ServiceExtensions.cs
+++ b/Seyounth.Hyosung.Data/ServiceExtensions.cs
@@ -16,6 +16,7 @@ public static class ServiceExtensions
var connectionString = configuration.GetConnectionString("DefaultConnection");
services.AddSingleton(s =>
{
+#if RELEASE
SqlSugarScope sqlSugar = new SqlSugarScope(new ConnectionConfig()
{
DbType = DbType.SqlServer,
@@ -23,6 +24,16 @@ public static class ServiceExtensions
IsAutoCloseConnection = true,
}
);
+#elif DEBUG
+ SqlSugarScope sqlSugar = new SqlSugarScope(new ConnectionConfig()
+ {
+ DbType = DbType.Sqlite,
+ ConnectionString = "Data Source=hyosung.db",
+ IsAutoCloseConnection = true,
+ InitKeyType = InitKeyType.Attribute
+ }
+ );
+#endif
return sqlSugar;
});
services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
diff --git a/Seyounth.Hyosung/App.xaml.cs b/Seyounth.Hyosung/App.xaml.cs
index 2ea052d..41bef76 100644
--- a/Seyounth.Hyosung/App.xaml.cs
+++ b/Seyounth.Hyosung/App.xaml.cs
@@ -2,6 +2,8 @@
using System.Data;
using System.IO;
using System.Reflection;
+using System.Runtime.InteropServices;
+using System.Text;
using System.Windows;
using System.Windows.Threading;
using Microsoft.Extensions.Configuration;
@@ -36,7 +38,10 @@ public partial class App : Application
builder.Services.AddSingleton();
builder.Services.AddSingleton();
builder.Services.AddSingleton();
+ builder.Services.AddSingleton();
+ builder.Services.AddSingleton();
builder.Services.AddHyosung(builder.Configuration);
+
_host = builder.Build();
}
@@ -59,10 +64,10 @@ public partial class App : Application
{
_host.Services.UseHyosung();
_host.StartAsync();
- }catch(Exception ex)
+ }
+ catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
-
}
}
\ No newline at end of file
diff --git a/Seyounth.Hyosung/Models/StackModel.cs b/Seyounth.Hyosung/Models/StackModel.cs
new file mode 100644
index 0000000..e70e7f6
--- /dev/null
+++ b/Seyounth.Hyosung/Models/StackModel.cs
@@ -0,0 +1,19 @@
+using System.Collections.ObjectModel;
+using Seyounth.Hyosung.Data.Models;
+
+namespace Seyounth.Hyosung.Models;
+
+public class StackModel
+{
+ public string TrayCode { get; set; } = "NoData";
+
+ public string VarietyCode { get; set; } = "NoData";
+
+ public int Layers { get; set; }
+
+ public int TotalCount { get; set; }
+
+ public int CurrentCount { get; set; }
+
+ public ObservableCollection Yarns { get; set; } = new();
+}
\ No newline at end of file
diff --git a/Seyounth.Hyosung/ViewModels/HomeViewModel.cs b/Seyounth.Hyosung/ViewModels/HomeViewModel.cs
new file mode 100644
index 0000000..5dc903b
--- /dev/null
+++ b/Seyounth.Hyosung/ViewModels/HomeViewModel.cs
@@ -0,0 +1,32 @@
+using System.Collections.ObjectModel;
+using CommunityToolkit.Mvvm.ComponentModel;
+using Seyounth.Hyosung.Data.Models;
+using Seyounth.Hyosung.Data.Services;
+using Seyounth.Hyosung.Models;
+
+namespace Seyounth.Hyosung.ViewModels;
+
+public partial class HomeViewModel : ObservableObject
+{
+ [ObservableProperty] private StackModel _stack1;
+
+ [ObservableProperty] private StackModel _stack2;
+
+ [ObservableProperty] private ObservableCollection _varieties;
+
+ [ObservableProperty] private List _yarnCarTypes;
+
+ [ObservableProperty] private Variety _selectedVariety;
+
+ public HomeViewModel(IVarietyService varietyService)
+ {
+ _stack1 = new StackModel();
+ _stack2 = new StackModel();
+ _yarnCarTypes = new List();
+ _yarnCarTypes.Add("A");
+ _yarnCarTypes.Add("B");
+ _yarnCarTypes.Add("C");
+ _yarnCarTypes.Add("D");
+ _varieties = new ObservableCollection(varietyService.GetAll());
+ }
+}
\ No newline at end of file
diff --git a/Seyounth.Hyosung/ViewModels/MainWindowViewModel.cs b/Seyounth.Hyosung/ViewModels/MainWindowViewModel.cs
index bba4873..dbcb039 100644
--- a/Seyounth.Hyosung/ViewModels/MainWindowViewModel.cs
+++ b/Seyounth.Hyosung/ViewModels/MainWindowViewModel.cs
@@ -11,18 +11,9 @@ public partial class MainWindowViewModel : ObservableObject
{
[ObservableProperty] private string _applicationTitle = "Hyosung - Seyounth Auto";
- [ObservableProperty] private List varieties;
-
- [ObservableProperty] private List yarnCar=new();
-
public MainWindowViewModel(IVarietyService varietyService)
{
- Varieties = varietyService.GetAll();
- YarnCar.Add("A");
- YarnCar.Add("B");
- YarnCar.Add("C");
- YarnCar.Add("D");
}
[RelayCommand]
diff --git a/Seyounth.Hyosung/Views/MainWindow.xaml b/Seyounth.Hyosung/Views/MainWindow.xaml
index b9a24f3..f738b98 100644
--- a/Seyounth.Hyosung/Views/MainWindow.xaml
+++ b/Seyounth.Hyosung/Views/MainWindow.xaml
@@ -69,14 +69,8 @@
Text="仪表盘" />
-
-
-
-
-
-
-
-
+
diff --git a/Seyounth.Hyosung/Views/MainWindow.xaml.cs b/Seyounth.Hyosung/Views/MainWindow.xaml.cs
index ceab680..92b1aa9 100644
--- a/Seyounth.Hyosung/Views/MainWindow.xaml.cs
+++ b/Seyounth.Hyosung/Views/MainWindow.xaml.cs
@@ -14,22 +14,15 @@ public partial class MainWindow
{
public MainWindowViewModel ViewModel { get; }
- private readonly IHyosungRuntime hyosungRuntime;
- public MainWindow(MainWindowViewModel viewModel, VarietyPage varietyPage,IHyosungRuntime hyosung)
+ public MainWindow(MainWindowViewModel viewModel,
+ VarietyPage varietyPage,
+ HomeViewPage homeViewPage)
{
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);
+ HomeFrame.Content = homeViewPage;
}
}
\ No newline at end of file
diff --git a/Seyounth.Hyosung/Views/Pages/HomeViewPage.xaml b/Seyounth.Hyosung/Views/Pages/HomeViewPage.xaml
index d1e6417..d42969c 100644
--- a/Seyounth.Hyosung/Views/Pages/HomeViewPage.xaml
+++ b/Seyounth.Hyosung/Views/Pages/HomeViewPage.xaml
@@ -1,14 +1,189 @@
+ xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
+ mc:Ignorable="d"
+ d:DesignHeight="800" d:DesignWidth="1500"
+ d:DataContext="{d:DesignInstance local:HomeViewPage,
+ IsDesignTimeCreatable=True}">
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
\ No newline at end of file
diff --git a/Seyounth.Hyosung/Views/Pages/HomeViewPage.xaml.cs b/Seyounth.Hyosung/Views/Pages/HomeViewPage.xaml.cs
index 164c190..ee4cd2f 100644
--- a/Seyounth.Hyosung/Views/Pages/HomeViewPage.xaml.cs
+++ b/Seyounth.Hyosung/Views/Pages/HomeViewPage.xaml.cs
@@ -1,17 +1,9 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
+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;
+using MaterialDesignThemes.Wpf;
+using Seyounth.Hyosung.Data.Models;
+using Seyounth.Hyosung.Runtime;
+using Seyounth.Hyosung.ViewModels;
namespace Seyounth.Hyosung.Views.Pages
{
@@ -20,9 +12,47 @@ namespace Seyounth.Hyosung.Views.Pages
///
public partial class HomeViewPage : Page
{
- public HomeViewPage()
+ public HomeViewModel ViewModel { get; set; }
+
+ private readonly IHyosungRuntime _runtime;
+
+ public HomeViewPage(HomeViewModel viewModel, IHyosungRuntime runtime)
{
+ _runtime = runtime;
+ ViewModel = viewModel;
+ DataContext = this;
InitializeComponent();
}
+
+ private void ChangeVarietyButton_OnClick(object sender, RoutedEventArgs e)
+ {
+ var variety = VarietyComboBox.SelectedItem as Variety;
+ if (variety == null)
+ {
+ MessageBox.Show("请选择要切换的品种");
+ return;
+ }
+
+ ChangeVarietyButton.Content = "切换中";
+ ButtonProgressAssist.SetIsIndicatorVisible(ChangeVarietyButton, true);
+ ChangeVarietyButton.IsEnabled = false;
+
+ variety.YarnCarSide = 1;
+ variety.YarnCarType = YarnCarTypeComboBox.SelectedIndex + 1;
+ _runtime.SendVarietyToPlcAsync(variety)
+ .ContinueWith(task =>
+ {
+ if (task.IsCompletedSuccessfully)
+ {
+ ChangeVarietyButton.Content = "切换";
+ ButtonProgressAssist.SetIsIndicatorVisible(ChangeVarietyButton, false);
+ ChangeVarietyButton.IsEnabled = true;
+ }
+ else
+ {
+ MessageBox.Show(task.Exception?.Message, "切换失败");
+ }
+ });
+ }
}
-}
+}
\ No newline at end of file