You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AUCMA_SCADA/Aucma.Core.BoxFoam/ViewModels/FoamPlanPageViewModel.cs

153 lines
4.9 KiB
C#

1 year ago
using Admin.Core.IService;
using Admin.Core.Service;
using Aucma.Core.BoxFoam.Views;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.Extensions.DependencyInjection;
1 year ago
using System;
using System.Collections.Generic;
1 year ago
using System.Collections.ObjectModel;
1 year ago
using System.Linq;
using System.Text;
using System.Threading;
1 year ago
using System.Threading.Tasks;
1 year ago
using System.Windows;
1 year ago
namespace Aucma.Core.BoxFoam.ViewModels
{
/**
*
*
* */
public partial class FoamPlanPageViewModel : ObservableObject
{
1 year ago
protected readonly IBoxFoamPlanServices? _boxFoamPlanServices;
1 year ago
public FoamPlanPageViewModel()
{
1 year ago
_boxFoamPlanServices = App.ServiceProvider.GetService<IBoxFoamPlanServices>();
WeakReferenceMessenger.Default.Register<string>(this, Recive);
Task.Run(() =>
{
while (true)
{
InitData();
Thread.Sleep(3000);
}
});
1 year ago
}
public void InitData()
1 year ago
{
try
{
Id.Clear();
MaterialCode.Clear();
MaterialName.Clear();
PlanAmount.Clear();
ComplateAmount.Clear();
DifferenceAmount.Clear();
var task = _boxFoamPlanServices.QueryAsync(x => x.ProductLineCode == "CX_02" && x.StationCode == "1005" && x.ShiftType == 1).Result;
if (task == null) return;
task.OrderBy(d => d.ObjId);
foreach (var item in task)
{
Id.Add(item.ObjId);
MaterialCode.Add(item.MaterialCode);
MaterialName.Add(item.MaterialName);
PlanAmount.Add(item.PlanAmount);
ComplateAmount.Add(item.CompleteAmount);
DifferenceAmount.Add(item.PlanAmount - item.CompleteAmount);
}
}catch(Exception ex)
1 year ago
{
Console.WriteLine($"刷新计划列表异常:{ex.Message}");
1 year ago
}
}
#region MyRegion
private ObservableCollection<int> _id = new ObservableCollection<int>();
public ObservableCollection<int> Id
{
get => _id;
set => SetProperty(ref _id, value);
}
private ObservableCollection<string> _materialCode = new ObservableCollection<string>();
public ObservableCollection<string> MaterialCode
{
get => _materialCode;
set => SetProperty(ref _materialCode, value);
}
private ObservableCollection<string> _materialName = new ObservableCollection<string>();
public ObservableCollection<string> MaterialName
{
get => _materialName;
set => SetProperty(ref _materialName, value);
}
private ObservableCollection<int> _planAmount = new ObservableCollection<int>();
public ObservableCollection<int> PlanAmount
{
get => _planAmount;
set => SetProperty(ref _planAmount, value);
}
private ObservableCollection<int> _complateAmount = new ObservableCollection<int>();
public ObservableCollection<int> ComplateAmount
{
get => _complateAmount;
set => SetProperty(ref _complateAmount, value);
}
//difference
private ObservableCollection<int> _differenceAmount = new ObservableCollection<int>();
public ObservableCollection<int> DifferenceAmount
{
get => _differenceAmount;
set => SetProperty(ref _differenceAmount, value);
}
1 year ago
#endregion
[RelayCommand]
public void AddPlan(string objId)
{
SplitPlanView plan = new SplitPlanView(objId);
plan.Show();
}
[RelayCommand]
public async void ClearPlan(string objId)
{
MessageBoxResult msg = MessageBox.Show("确定要删除吗?", "系统提醒", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);
if (MessageBoxResult.Yes == msg)
1 year ago
{
int id = Id.ElementAt(int.Parse(objId)-1);
_boxFoamPlanServices.DeleteByIdAsync(id).Wait();
InitData();
MessageBox.Show("执行计划删除成功", "系统信息");
1 year ago
}
}
private void Recive(object recipient, string message)
{
if (message == "RefreshTask")
{
ClearData();
}
}
public void ClearData()
{
Id.Clear();
MaterialCode.Clear();
MaterialName.Clear();
PlanAmount.Clear();
ComplateAmount.Clear();
DifferenceAmount.Clear();
1 year ago
}
}
}