using Admin.Core.Common; using Admin.Core.IService; using Admin.Core.Model; using Admin.Core.Service; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using Microsoft.Extensions.DependencyInjection; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Windows; namespace Aucma.Core.SheetMetal.ViewModels { public partial class MaterialStatisticsViewModel : ObservableObject { private readonly IBaseSpaceInfoServices _baseSpaceInfoServices; public MaterialStatisticsViewModel() { _baseSpaceInfoServices = App.ServiceProvider.GetService(); Refresh(); } #region 刷新 [RelayCommand] private async void Refresh() { string shellStoreCode = Appsettings.app("StoreInfo", "shellStoreCode"); string linerStoreCode = Appsettings.app("StoreInfo", "linerStoreCode"); string foamBeforeStoreCode = Appsettings.app("StoreInfo", "foamBeforeStoreCode"); //箱壳物料库存 ShellMaterialStockDataGrid = new ObservableCollection(); List shellList =await _baseSpaceInfoServices.GetSpaceInfosByStoreCode(shellStoreCode); shellList.OrderBy(x => x.ObjId); 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(); List linerList =await _baseSpaceInfoServices.GetSpaceInfosByStoreCode(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(); List foamBeforeList =await _baseSpaceInfoServices.GetSpaceInfosByStoreCode(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 }); } } #endregion #region 关闭窗口 [RelayCommand] private void CloseWindow(object parameter) { var window = parameter as Window; if (window != null) { window.Close(); } } #endregion #region 参数定义 /// /// 箱壳物料库存DataGrid /// private ObservableCollection shellMaterialStockDataGrid; public ObservableCollection ShellMaterialStockDataGrid { get => shellMaterialStockDataGrid; set => SetProperty(ref shellMaterialStockDataGrid, value); } /// /// 内胆物料库存DataGrid /// private ObservableCollection linerMaterialStockDataGrid; public ObservableCollection LinerMaterialStockDataGrid { get => linerMaterialStockDataGrid; set => SetProperty(ref linerMaterialStockDataGrid, value); } /// /// 泡前库物料库存DataGrid /// private ObservableCollection foamBeforeMaterialStockDataGrid; public ObservableCollection FoamBeforeMaterialStockDataGrid { get => foamBeforeMaterialStockDataGrid; set => SetProperty(ref foamBeforeMaterialStockDataGrid, value); } #endregion } }