154 lines
5.6 KiB
C#
154 lines
5.6 KiB
C#
using System;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Avalonia.Controls.Notifications;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using CommunityToolkit.Mvvm.Messaging;
|
|
using Seyounth.Hyosung.Data.Models;
|
|
using Seyounth.Hyosung.Data.Services;
|
|
using SukiUI.Toasts;
|
|
|
|
namespace Seyounth.Hyosung.Ava.ViewModels;
|
|
|
|
public partial class VarietyManagerViewModel : ObservableObject
|
|
{
|
|
[ObservableProperty] private ObservableCollection<Variety> _varieties;
|
|
[ObservableProperty] private ObservableCollection<Pallet> _pallets;
|
|
|
|
[ObservableProperty] private ObservableCollection<Pallet> _honeyPallets = new();
|
|
|
|
[ObservableProperty] private ObservableCollection<Pallet> _paperPallets = new();
|
|
|
|
[ObservableProperty] private ObservableCollection<Pallet> _trays = new();
|
|
|
|
|
|
private readonly ISukiToastManager _toastManager;
|
|
private readonly IVarietyService _varietyService;
|
|
private readonly IPalletService _palletService;
|
|
|
|
public void Reload()
|
|
{
|
|
Pallets = new ObservableCollection<Pallet>(_palletService.GetPallets());
|
|
HoneyPallets = new ObservableCollection<Pallet>(Pallets.Where(p => p.Type == PalletType.Honey));
|
|
var papers = Pallets.Where(p => p.Type == PalletType.Paper).ToList();
|
|
papers.Add(new Pallet());
|
|
papers = papers.OrderBy(p => p.Length).ToList();
|
|
PaperPallets = new ObservableCollection<Pallet>(papers);
|
|
Trays = new ObservableCollection<Pallet>(Pallets.Where(p =>
|
|
p.Type is PalletType.Plywood or PalletType.Wood));
|
|
var varieties = _varietyService.GetAll().Select(v =>
|
|
{
|
|
// 匹配相同ID的托盘对象
|
|
v.TopAndBottomPallet = HoneyPallets.FirstOrDefault(p => p.Id == v.TopAndBottomPallet.Id);
|
|
v.MiddlePallet = HoneyPallets.FirstOrDefault(p => p.Id == v.MiddlePallet.Id);
|
|
v.Tray = Trays.FirstOrDefault(p => p.Id == v.Tray.Id);
|
|
v.PaperTray = v.PaperTray is null
|
|
? PaperPallets.First()
|
|
: PaperPallets.FirstOrDefault(p =>
|
|
p.Id == v.PaperTray.Id);
|
|
return v;
|
|
});
|
|
|
|
Varieties = new ObservableCollection<Variety>(varieties);
|
|
}
|
|
|
|
public VarietyManagerViewModel(IVarietyService varietyService, ISukiToastManager toastManager,
|
|
IPalletService palletService)
|
|
{
|
|
_toastManager = toastManager;
|
|
_palletService = palletService;
|
|
_varietyService = varietyService;
|
|
Reload();
|
|
}
|
|
|
|
|
|
[RelayCommand]
|
|
private void AddNewRow()
|
|
{
|
|
Varieties.Add(new Variety());
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void OnCopyNew(object obj)
|
|
{
|
|
if (obj is Variety variety)
|
|
{
|
|
var newVariety = new Variety
|
|
{
|
|
Id = variety.Id,
|
|
TopAndBottomPallet = variety.TopAndBottomPallet,
|
|
MiddlePallet = variety.MiddlePallet,
|
|
Tray = variety.Tray,
|
|
PaperTray = variety.PaperTray,
|
|
StackingLayers = variety.StackingLayers,
|
|
YarnCarType = variety.YarnCarType,
|
|
NeedAngleBeam = variety.NeedAngleBeam,
|
|
NeedFilmCoating = variety.NeedFilmCoating,
|
|
NeedFilmWrapping = variety.NeedFilmWrapping,
|
|
HasBox = variety.HasBox,
|
|
Specifications = variety.Specifications,
|
|
InnerDiameter = variety.InnerDiameter,
|
|
LastNo = variety.LastNo,
|
|
OuterDiameter = variety.OuterDiameter,
|
|
TotalCount = variety.TotalCount,
|
|
YarnDiameter = variety.YarnDiameter,
|
|
YarnThickness = variety.YarnThickness,
|
|
MasterLabelCount = variety.MasterLabelCount,
|
|
NeedPackStrap = variety.NeedPackStrap,
|
|
NeedTopBoard = variety.NeedTopBoard,
|
|
PaperTubeHeight = variety.PaperTubeHeight,
|
|
StackHeadCount = variety.StackHeadCount,
|
|
SubLabelCount = variety.SubLabelCount,
|
|
YarnCarSide = variety.YarnCarSide,
|
|
StackHeadSpec = variety.StackHeadSpec,
|
|
Code = variety.Code,
|
|
ControlNo = variety.ControlNo,
|
|
GrossWeight = variety.GrossWeight,
|
|
NetWeight = variety.NetWeight,
|
|
SingleWeight = variety.SingleWeight,
|
|
IsTurn = variety.IsTurn,
|
|
Lot = variety.Lot,
|
|
};
|
|
Varieties.Add(newVariety);
|
|
}
|
|
}
|
|
|
|
|
|
[RelayCommand]
|
|
private void OnDeletePallet(object obj)
|
|
{
|
|
if (obj is Variety variety)
|
|
{
|
|
Varieties.Remove(variety);
|
|
_varietyService.DeleteVarietyAsync(variety);
|
|
_toastManager.CreateToast()
|
|
.WithTitle("删除成功")
|
|
.Dismiss().After(TimeSpan.FromSeconds(3))
|
|
.OfType(NotificationType.Success)
|
|
.Dismiss().ByClicking()
|
|
.Queue();
|
|
}
|
|
else
|
|
{
|
|
Console.Write("Object is not a Pallet");
|
|
}
|
|
}
|
|
|
|
[RelayCommand]
|
|
private async Task OnSavePallet(object obj)
|
|
{
|
|
if (obj is Variety variety)
|
|
{
|
|
await _varietyService.AddVarietyAsync(variety);
|
|
_toastManager.CreateToast()
|
|
.WithTitle("保存成功")
|
|
.Dismiss().After(TimeSpan.FromSeconds(3))
|
|
.OfType(NotificationType.Success)
|
|
.Dismiss().ByClicking()
|
|
.Queue();
|
|
//Pallets = new ObservableCollection<Pallet>(_palletService.GetPallets());
|
|
}
|
|
}
|
|
} |