2025-04-10 16:20:00 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
using Avalonia.Controls.Notifications;
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
|
using Seyounth.Hyosung.Data.Models;
|
|
|
|
using Seyounth.Hyosung.Data.Services;
|
|
|
|
using Seyounth.Hyosung.Runtime;
|
|
|
|
using SukiUI.Toasts;
|
|
|
|
|
|
|
|
namespace Seyounth.Hyosung.Ava.ViewModels;
|
|
|
|
|
|
|
|
public partial class HomeViewModel : ObservableObject
|
|
|
|
{
|
|
|
|
[ObservableProperty] private ObservableCollection<Variety> _varieties;
|
|
|
|
|
|
|
|
[ObservableProperty] private Variety _selectedVariety;
|
|
|
|
|
|
|
|
[ObservableProperty] private List<string> _yarnCarTypes;
|
|
|
|
|
|
|
|
[ObservableProperty] private List<string> _yarnCarSideType;
|
|
|
|
|
|
|
|
[ObservableProperty] private int _selectedYarnCarTypeIndex;
|
|
|
|
|
|
|
|
[ObservableProperty] private int _selectedYarnCarSideTypeIndex;
|
|
|
|
|
2025-06-02 17:15:40 +08:00
|
|
|
[ObservableProperty] private bool _isSendToErp;
|
|
|
|
|
2025-04-10 16:20:00 +08:00
|
|
|
|
|
|
|
private readonly IVarietyService _varietyService;
|
|
|
|
|
|
|
|
private readonly IHyosungRuntime _runtime;
|
|
|
|
|
|
|
|
private readonly ISukiToastManager _toastManager;
|
|
|
|
|
2025-06-02 17:15:40 +08:00
|
|
|
|
|
|
|
partial void OnIsSendToErpChanged(bool value)
|
|
|
|
{
|
|
|
|
if (_runtime is not null)
|
|
|
|
_runtime.SetIsSendToErp(value);
|
|
|
|
}
|
|
|
|
|
2025-04-10 16:20:00 +08:00
|
|
|
public HomeViewModel(IVarietyService varietyService, IHyosungRuntime runtime, ISukiToastManager toastManager)
|
|
|
|
{
|
2025-06-02 17:15:40 +08:00
|
|
|
IsSendToErp = runtime.GetIsSendToErp();
|
2025-04-10 16:20:00 +08:00
|
|
|
_varietyService = varietyService;
|
|
|
|
_runtime = runtime;
|
|
|
|
_toastManager = toastManager;
|
|
|
|
YarnCarTypes =
|
|
|
|
[
|
|
|
|
"A",
|
|
|
|
"B",
|
|
|
|
"C",
|
|
|
|
"D"
|
|
|
|
];
|
|
|
|
|
|
|
|
YarnCarSideType =
|
|
|
|
[
|
|
|
|
"正面",
|
|
|
|
"反面"
|
|
|
|
];
|
|
|
|
SelectedYarnCarTypeIndex = 0;
|
|
|
|
SelectedYarnCarSideTypeIndex = 0;
|
|
|
|
NavigatedTo();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void NavigatedTo()
|
|
|
|
{
|
|
|
|
Varieties = new ObservableCollection<Variety>(_varietyService.GetAll());
|
|
|
|
}
|
|
|
|
|
|
|
|
[RelayCommand]
|
|
|
|
private void OnChangeVariety()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
SelectedVariety.YarnCarType = SelectedYarnCarTypeIndex + 1;
|
|
|
|
SelectedVariety.YarnCarSide = SelectedYarnCarSideTypeIndex + 1;
|
|
|
|
_runtime.SendVarietyToPlcAsync(SelectedVariety);
|
|
|
|
_toastManager.CreateToast()
|
|
|
|
.WithTitle("发送成功")
|
|
|
|
.Dismiss().After(TimeSpan.FromSeconds(3))
|
|
|
|
.OfType(NotificationType.Success)
|
|
|
|
.Dismiss().ByClicking()
|
|
|
|
.Queue();
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
_toastManager.CreateToast()
|
|
|
|
.WithTitle("发送失败")
|
|
|
|
.WithContent(e.Message)
|
|
|
|
.Dismiss().After(TimeSpan.FromSeconds(3))
|
|
|
|
.OfType(NotificationType.Error)
|
|
|
|
.Dismiss().ByClicking()
|
|
|
|
.Queue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[RelayCommand]
|
|
|
|
private void OnChangeVarietyLastNo()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
_varietyService.SetLastNo(SelectedVariety.Id, SelectedVariety.LastNo.Value);
|
|
|
|
_toastManager.CreateToast()
|
|
|
|
.WithTitle("更改控制号成功")
|
|
|
|
.Dismiss().After(TimeSpan.FromSeconds(3))
|
|
|
|
.OfType(NotificationType.Success)
|
|
|
|
.Dismiss().ByClicking()
|
|
|
|
.Queue();
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
_toastManager.CreateToast()
|
|
|
|
.WithTitle("更改控制号失败")
|
|
|
|
.WithContent(e.Message)
|
|
|
|
.Dismiss().After(TimeSpan.FromSeconds(3))
|
|
|
|
.OfType(NotificationType.Error)
|
|
|
|
.Dismiss().ByClicking()
|
|
|
|
.Queue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|