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.
178 lines
6.9 KiB
C#
178 lines
6.9 KiB
C#
using Aucma.Scada.Business;
|
|
using Aucma.Scada.Model.domain;
|
|
using GalaSoft.MvvmLight;
|
|
using GalaSoft.MvvmLight.Command;
|
|
using HighWayIot.Config;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
|
|
namespace Aucma.Scada.UI.viewModel.InventoryInfo
|
|
{
|
|
public class MaterialStatisticsViewModel : ViewModelBase
|
|
{
|
|
private AppConfig appConfig = AppConfig.Instance;
|
|
private InventoryInfoBusiness _inventoryInfoBusiness = InventoryInfoBusiness.Instance;
|
|
|
|
public MaterialStatisticsViewModel()
|
|
{
|
|
CloseWindowCommand = new RelayCommand<object>(t => CloseWindow(t));
|
|
RefreshCommand = new RelayCommand(init);
|
|
init();
|
|
}
|
|
|
|
#region 参数定义
|
|
/// <summary>
|
|
/// 箱壳物料库存DataGrid
|
|
/// </summary>
|
|
private ObservableCollection<BaseSpaceInfo> shellMaterialStockDataGrid;
|
|
|
|
public ObservableCollection<BaseSpaceInfo> ShellMaterialStockDataGrid
|
|
{
|
|
get { return shellMaterialStockDataGrid; }
|
|
set { shellMaterialStockDataGrid = value; RaisePropertyChanged(() => ShellMaterialStockDataGrid); }
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 内胆物料库存DataGrid
|
|
/// </summary>
|
|
private ObservableCollection<BaseSpaceInfo> linerMaterialStockDataGrid;
|
|
|
|
public ObservableCollection<BaseSpaceInfo> LinerMaterialStockDataGrid
|
|
{
|
|
get { return linerMaterialStockDataGrid; }
|
|
set { linerMaterialStockDataGrid = value; RaisePropertyChanged(() => LinerMaterialStockDataGrid); }
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 泡前库物料库存DataGrid
|
|
/// </summary>
|
|
private ObservableCollection<BaseSpaceInfo> foamBeforeMaterialStockDataGrid;
|
|
|
|
public ObservableCollection<BaseSpaceInfo> FoamBeforeMaterialStockDataGrid
|
|
{
|
|
get { return foamBeforeMaterialStockDataGrid; }
|
|
set { foamBeforeMaterialStockDataGrid = value; RaisePropertyChanged(() => FoamBeforeMaterialStockDataGrid); }
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 泡后库物料库存DataGrid
|
|
/// </summary>
|
|
private ObservableCollection<BaseSpaceInfo> foamMaterialStockDataGrid;
|
|
|
|
public ObservableCollection<BaseSpaceInfo> FoamMaterialStockDataGrid
|
|
{
|
|
get { return foamMaterialStockDataGrid; }
|
|
set { foamMaterialStockDataGrid = value; RaisePropertyChanged(() => FoamMaterialStockDataGrid); }
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region 事件定义
|
|
public RelayCommand RefreshCommand { get; set; }
|
|
|
|
public RelayCommand<object> CloseWindowCommand { get; set; }
|
|
|
|
#endregion
|
|
|
|
private void init()
|
|
{
|
|
//箱壳物料库存
|
|
ShellMaterialStockDataGrid = new ObservableCollection<BaseSpaceInfo>();
|
|
List<BaseSpaceInfo> shellList = _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 = _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 = _inventoryInfoBusiness.GetSpaceInfos(appConfig.foamStoreCode);
|
|
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 });
|
|
}
|
|
|
|
|
|
//泡后库物料库存
|
|
FoamMaterialStockDataGrid = new ObservableCollection<BaseSpaceInfo>();
|
|
List<BaseSpaceInfo> foamList = _inventoryInfoBusiness.GetSpaceInfos(appConfig.foamStoreCode);
|
|
var foamResult = from m in foamList
|
|
group m by m.typeNameA into g
|
|
select new BaseSpaceInfo()
|
|
{
|
|
typeNameA = GetStringBetweenCommas(g.Key),
|
|
spaceStock = g.Sum(m => m.spaceStock)
|
|
};
|
|
foreach (var item in foamResult)
|
|
{
|
|
if (string.IsNullOrEmpty(item.typeNameA)) continue;
|
|
FoamMaterialStockDataGrid.Add(new BaseSpaceInfo() { typeNameA = item.typeNameA, spaceStock = item.spaceStock });
|
|
}
|
|
}
|
|
|
|
public static string GetStringBetweenCommas(string input)
|
|
{
|
|
if (string.IsNullOrEmpty(input)) return null;
|
|
int firstCommaIndex = input.IndexOf(',');
|
|
if (firstCommaIndex != -1)
|
|
{
|
|
int secondCommaIndex = input.IndexOf(',', firstCommaIndex + 1);
|
|
if (secondCommaIndex != -1)
|
|
{
|
|
return input.Substring(firstCommaIndex + 1, secondCommaIndex - firstCommaIndex - 1);
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
|
|
|
|
private void CloseWindow(object parameter)
|
|
{
|
|
var window = parameter as Window;
|
|
if (window != null)
|
|
{
|
|
window.Close();
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|