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.Scada.UI/ViewModels/InventoryInfo/MaterialStatisticsViewModel.cs

126 lines
4.8 KiB
C#

using Admin.Core.Model;
using Aucma.Scada.UI.Common;
using Aucma.Scada.UI;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace Aucma.Scada.UI.ViewModel.InventoryInfo
{
public partial class MaterialStatisticsViewModel : ObservableObject
{
private AppConfig appConfig = new AppConfig();//AppConfig.Instance;
private InventoryInfoBusiness _inventoryInfoBusiness = new InventoryInfoBusiness();// InventoryInfoBusiness.Instance;
public MaterialStatisticsViewModel()
{
init();
}
#region 参数定义
/// <summary>
/// 箱壳物料库存DataGrid
/// </summary>
private ObservableCollection<BaseSpaceInfo> shellMaterialStockDataGrid;
public ObservableCollection<BaseSpaceInfo> ShellMaterialStockDataGrid
{
get => shellMaterialStockDataGrid;
set => SetProperty(ref shellMaterialStockDataGrid, value);
}
/// <summary>
/// 内胆物料库存DataGrid
/// </summary>
private ObservableCollection<BaseSpaceInfo> linerMaterialStockDataGrid;
public ObservableCollection<BaseSpaceInfo> LinerMaterialStockDataGrid
{
get => linerMaterialStockDataGrid;
set => SetProperty(ref linerMaterialStockDataGrid, value);
}
/// <summary>
/// 泡前库物料库存DataGrid
/// </summary>
private ObservableCollection<BaseSpaceInfo> foamBeforeMaterialStockDataGrid;
public ObservableCollection<BaseSpaceInfo> FoamBeforeMaterialStockDataGrid
{
get => foamBeforeMaterialStockDataGrid;
set => SetProperty(ref foamBeforeMaterialStockDataGrid, value);
}
#endregion
[RelayCommand]
private async void init()
{
//箱壳物料库存
ShellMaterialStockDataGrid = new ObservableCollection<BaseSpaceInfo>();
List<BaseSpaceInfo> shellList =await _inventoryInfoBusiness.GetSpaceInfos(appConfig.shellStoreCode);
var shellResult = from m in shellList
group m by m.MaterialType into g
select new BaseSpaceInfo()
{
MaterialType = g.Key,
SpaceStock = g.Sum(m => m.SpaceStock)
};
foreach( var item in shellResult)
{
if (string.IsNullOrEmpty(item.MaterialType)) continue;
ShellMaterialStockDataGrid.Add(new BaseSpaceInfo() { MaterialType = item.MaterialType, SpaceStock = item.SpaceStock });
}
//内胆物料库存
LinerMaterialStockDataGrid = new ObservableCollection<BaseSpaceInfo>();
List<BaseSpaceInfo> linerList =await _inventoryInfoBusiness.GetSpaceInfos(appConfig.linerStoreCode);
var linerResult = from m in linerList
group m by m.MaterialType into g
select new BaseSpaceInfo()
{
MaterialType = g.Key,
SpaceStock = g.Sum(m => m.SpaceStock)
};
foreach (var item in linerResult)
{
if (string.IsNullOrEmpty(item.MaterialType)) continue;
LinerMaterialStockDataGrid.Add(new BaseSpaceInfo() { MaterialType = item.MaterialType, SpaceStock = item.SpaceStock });
}
//泡前库物料库存
FoamBeforeMaterialStockDataGrid = new ObservableCollection<BaseSpaceInfo>();
List<BaseSpaceInfo> foamBeforeList =await _inventoryInfoBusiness.GetSpaceInfos(appConfig.foamBeforeStoreCode);
var foamBeforeResult = from m in foamBeforeList
group m by m.MaterialType into g
select new BaseSpaceInfo()
{
MaterialType = g.Key,
SpaceStock = g.Sum(m => m.SpaceStock)
};
foreach (var item in foamBeforeResult)
{
if (string.IsNullOrEmpty(item.MaterialType)) continue;
FoamBeforeMaterialStockDataGrid.Add(new BaseSpaceInfo() { MaterialType = item.MaterialType, SpaceStock = item.SpaceStock });
}
}
[RelayCommand]
private void CloseWindow(object parameter)
{
var window = parameter as Window;
if (window != null)
{
window.Close();
}
}
}
}