using Aucma.Scada.Business; using Aucma.Scada.Model.domain; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using HighWayIot.Config; using HighWayIot.Repository.service; using LiveCharts.Wpf; using LiveCharts; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Media; namespace Aucma.Scada.UI.viewModel.InventoryInfo { public class MaterialStatisticsViewModel:ViewModelBase { private AppConfig appConfig = AppConfig.Instance; private InventoryInfoBusiness _inventoryInfoBusiness = InventoryInfoBusiness.Instance; private RegisterServices registerServices = RegisterServices.Instance; private readonly ISysUserInfoService _sysUserInfoServices; public MaterialStatisticsViewModel() { _sysUserInfoServices = registerServices.GetService(); CloseWindowCommand = new RelayCommand(t => CloseWindow(t)); RefreshCommand = new RelayCommand(init); init(); } #region 参数定义 /// /// 箱壳物料库存DataGrid /// private ObservableCollection shellMaterialStockDataGrid; public ObservableCollection ShellMaterialStockDataGrid { get { return shellMaterialStockDataGrid; } set { shellMaterialStockDataGrid = value; RaisePropertyChanged(() => ShellMaterialStockDataGrid); } } /// /// 内胆物料库存DataGrid /// private ObservableCollection linerMaterialStockDataGrid; public ObservableCollection LinerMaterialStockDataGrid { get { return linerMaterialStockDataGrid; } set { linerMaterialStockDataGrid = value; RaisePropertyChanged(() => LinerMaterialStockDataGrid); } } /// /// 泡前库物料库存DataGrid /// private ObservableCollection foamBeforeMaterialStockDataGrid; public ObservableCollection FoamBeforeMaterialStockDataGrid { get { return foamBeforeMaterialStockDataGrid; } set { foamBeforeMaterialStockDataGrid = value; RaisePropertyChanged(() => FoamBeforeMaterialStockDataGrid); } } #endregion #region 事件定义 public RelayCommand RefreshCommand { get; set; } public RelayCommand CloseWindowCommand { get; set; } #endregion private void init() { //箱壳物料库存 ShellMaterialStockDataGrid = new ObservableCollection(); List shellList = _inventoryInfoBusiness.GetSpaceInfos(appConfig.shellStoreCode); var shellResult = from m in shellList group m by m.materialType into g select new BaseSpaceInfo() { materialType = g.Key, typeNameA = g.First().typeNameA, spaceStock = g.Sum(m => m.spaceStock) }; foreach( var item in shellResult) { if (string.IsNullOrEmpty(item.materialType)) continue; ShellMaterialStockDataGrid.Add(new BaseSpaceInfo() { materialType = item.materialType, typeNameA = item.typeNameA,spaceStock = item.spaceStock }); } //内胆物料库存 LinerMaterialStockDataGrid = new ObservableCollection(); List linerList = _inventoryInfoBusiness.GetSpaceInfos(appConfig.linerStoreCode); var linerResult = from m in linerList group m by m.materialType into g select new BaseSpaceInfo() { materialType = g.Key, typeNameA = g.First().typeNameA, spaceStock = g.Sum(m => m.spaceStock) }; foreach (var item in linerResult) { if (string.IsNullOrEmpty(item.materialType)) continue; LinerMaterialStockDataGrid.Add(new BaseSpaceInfo() { materialType = item.materialType, typeNameA = item.typeNameA, spaceStock = item.spaceStock }); } //泡前库物料库存 FoamBeforeMaterialStockDataGrid = new ObservableCollection(); List foamBeforeList = _inventoryInfoBusiness.GetSpaceInfos(appConfig.foamBeforeStoreCode); var foamBeforeResult = from m in foamBeforeList group m by m.materialType into g select new BaseSpaceInfo() { materialType = g.Key, typeNameA = g.First().typeNameA, spaceStock = g.Sum(m => m.spaceStock) }; foreach (var item in foamBeforeResult) { if (string.IsNullOrEmpty(item.materialType)) continue; FoamBeforeMaterialStockDataGrid.Add(new BaseSpaceInfo() { materialType = item.materialType, typeNameA = item.typeNameA, spaceStock = item.spaceStock }); } //夹具状态 RefreshModeStatus(); } private void CloseWindow(object parameter) { var window = parameter as Window; if (window != null) { window.Close(); } } #region 刷新夹具统计 /// /// 刷新夹具统计 /// private void RefreshModeStatus() { try { App.Current.Dispatcher.Invoke((Action)(async () => { var modeStatus = await _sysUserInfoServices.StatisticalModelStatus(); if (modeStatus != null) { if (Achievement.Count != 0) Achievement.Clear(); ModeTypeList = new List(); ChartValues achievement = new ChartValues(); int hour = 0; foreach (var item in modeStatus) { achievement.Add(Convert.ToInt32(item.YValue)); ModeTypeList.Add(item.XValue); hour++; } #region 按夹具状态统计 Achievement.Add(new ColumnSeries { DataLabels = true, Title = "夹具状态", ScalesYAt = 0, Values = achievement, Fill = new SolidColorBrush(Color.FromRgb(15, 209, 226)), Foreground = Brushes.CadetBlue, FontSize = 18 }); #endregion } })); } catch (Exception ex) { } } #endregion #region 夹具状态统计 #region 夹具状态统计 /// /// 夹具状态统计 /// private List modeTypeList; public List ModeTypeList { get { return modeTypeList; } set { modeTypeList = value; } } #endregion /// /// 夹具状态统计 /// private SeriesCollection achievement = new SeriesCollection(); public SeriesCollection Achievement { get { return achievement; } set { achievement = value; } } #endregion } }