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.

145 lines
4.5 KiB
C#

using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Business;
using SlnMesnac.Model.domain;
using SlnMesnac.Model.dto;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* LAPTOP-E0N2L34V
* SlnMesnac.WPF.ViewModel
* 14008fcc-0a31-4f1e-bc80-9f9ea84d3de5
*
* WenJY
* wenjy@mesnac.com
* 2024-04-10 16:18:57
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.WPF.ViewModel
{
/// <summary>
/// 生产统计ViewModel
/// </summary>
internal class ProdStatisticsViewModel : ViewModelBase
{
private readonly PalletStowBusiness _palletStowBusiness;
private readonly ProdCompletionBusiness _prodCompletionBusiness;
public ProdStatisticsViewModel()
{
_palletStowBusiness = App.ServiceProvider.GetService<PalletStowBusiness>();
_prodCompletionBusiness = App.ServiceProvider.GetService<ProdCompletionBusiness>();
DeletePalletCommand = new RelayCommand<string>(DeletePallet);
DeleteBarCodeCommand = new RelayCommand<string> (DeleteBarCode);
var palletTask = App.ServiceProvider.GetService<List<RealPalletTask>>();
RefreshPalletTaskDataGrid(palletTask);
_palletStowBusiness.RefreshPalletTaskListEvent += RefreshPalletTaskDataGrid;
var barCodeTasks = App.ServiceProvider.GetService<List<RealBarCodeTask>>();
RefreshBarCodeTaskDataGrid(barCodeTasks);
_prodCompletionBusiness.RefreshBarCodeTaskListEvent += RefreshBarCodeTaskDataGrid;
}
#region 参数定义
/// <summary>
/// 托盘队列DataGrid
/// </summary>
private ObservableCollection<RealPalletTask> palletTaskDataGrid;
public ObservableCollection<RealPalletTask> PalletTaskDataGrid
{
get { return palletTaskDataGrid; }
set { palletTaskDataGrid = value; RaisePropertyChanged(() => PalletTaskDataGrid); }
}
/// <summary>
/// 条码队列DataGrid
/// </summary>
private ObservableCollection<RealBarCodeTask> barCodeTaskDataGrid;
public ObservableCollection<RealBarCodeTask> BarCodeTaskDataGrid
{
get { return barCodeTaskDataGrid; }
set { barCodeTaskDataGrid = value; RaisePropertyChanged(() => BarCodeTaskDataGrid); }
}
#endregion
#region 事件定义
public RelayCommand<string> DeletePalletCommand { get;set; }
public RelayCommand<string> DeleteBarCodeCommand { get; set; }
#endregion
/// <summary>
/// 刷新托盘队列信息
/// </summary>
/// <param name="palletTasks"></param>
private void RefreshPalletTaskDataGrid(List<RealPalletTask> palletTasks)
{
PalletTaskDataGrid = new ObservableCollection<RealPalletTask>();
foreach (var task in palletTasks)
{
PalletTaskDataGrid.Add(task);
}
}
/// <summary>
/// 刷新条码队列信息
/// </summary>
/// <param name="barCodeTasks"></param>
private void RefreshBarCodeTaskDataGrid(List<RealBarCodeTask> barCodeTasks)
{
BarCodeTaskDataGrid = new ObservableCollection<RealBarCodeTask>();
foreach (var task in barCodeTasks)
{
BarCodeTaskDataGrid.Add(task);
}
}
/// <summary>
/// 移除托盘队列信息
/// </summary>
/// <param name="palletCode"></param>
private void DeletePallet(string palletCode)
{
_palletStowBusiness.RemovePalletInfo(palletCode);
}
/// <summary>
/// 移除小包条码队列信息
/// </summary>
/// <param name="barCode"></param>
private void DeleteBarCode(string barCode)
{
_prodCompletionBusiness.RemoveBarCode(barCode);
}
}
}