using CommunityToolkit.Mvvm.ComponentModel; using LiveCharts.Defaults; using LiveCharts.Wpf; using LiveCharts; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Media; using System.Collections.ObjectModel; using Admin.Core.IService; using Admin.Core.Service; using Microsoft.Extensions.DependencyInjection; using Admin.Core.Common; using Admin.Core.Tasks; namespace Aucma.Core.BoxFoam.ViewModels { public partial class FoamMonitorPageViewModel : ObservableObject { private readonly IBoxFoamDataServices _boxFoamDataServices; public FoamMonitorPageViewModel() { _boxFoamDataServices = App.ServiceProvider.GetService(); Job_BoxFoamData_Quartz.RefreshBoxFoamDataDelegateEvent += InitData; Task.WaitAll(InitEveryDayMethod(), InitData()); } //public void InitStatus() //{ // for (int i = 0; i < 12; i++) // { // Color.Add("Red"); // } //} #region 日产量 /// /// 每日生产 /// /// private Task InitEveryDayMethod() { #region 按时间统计 ChartValues achievement = new ChartValues { new ObservablePoint(0, 12), new ObservablePoint(1, 14), new ObservablePoint(2, 28), new ObservablePoint(3, 2), new ObservablePoint(4, 29), new ObservablePoint(5, 29), new ObservablePoint(6, 7), new ObservablePoint(7, 31), new ObservablePoint(8, 13), new ObservablePoint(9, 11), new ObservablePoint(10, 8), new ObservablePoint(11, 5) }; var column = new ColumnSeries(); column.DataLabels = true; column.Title = "当日小时产量统计"; column.Values = achievement; column.Foreground = Brushes.White; //柱子宽度 //column.Width = 30; //column.MaxColumnWidth = 30; //column.LabelsPosition = BarLabelPosition.Perpendicular; //column.Fill = new SolidColorBrush(Color.FromRgb(34, 139, 34)); //柱状图颜色填充 //column.LabelPoint = p => p.Y.ToString(); //柱状图数据显示位置 ProductionHourList = new List() { "7:30", "8:30", "9:30", "10:30", "11:30", "12:30", "13:30", "14:30", "15:30", "16:30", "17:30", "18:30" }; //Formatter = value => value.ToString("N"); Achievement.Add(column); #endregion #region 按类型统计 ChartValues achievement2 = new ChartValues(); Random random2 = new Random(); for (int i = 0; i < 2; i++) { achievement2.Add(random2.Next(0,50)); } var column2 = new ColumnSeries(); column2.DataLabels = true; column2.Title = "当日型号产量统计"; column2.Values = achievement2; column2.Foreground = Brushes.White; ModelStatistics.Add(column2); MaterialNameList = new List() { "玻璃门,SC-439", "玻璃门,SC-439,AC" }; #endregion //await InitExecMethod(); return Task.CompletedTask; } #endregion #region 日产量柱状图X轴日期 /// /// 日产量柱状图X轴日期 /// private List productionHourList; public List ProductionHourList { get { return productionHourList; } set { productionHourList = value; } } #endregion #region 型号统计 #region 型号统计柱状图x轴物料类型 /// /// 型号统计柱状图x轴物料类型 /// private List materialNameList; public List MaterialNameList { get { return materialNameList; } set { materialNameList = value; } } #endregion #region 型号统计柱状图 /// /// 型号统计柱状图 /// private SeriesCollection modelStatistics = new SeriesCollection(); public SeriesCollection ModelStatistics { get { return modelStatistics; } set { modelStatistics = value; } } #endregion #endregion #region 日产量柱状图 /// /// 日产量柱状图 /// private SeriesCollection achievement = new SeriesCollection(); public SeriesCollection Achievement { get { return achievement; } set { achievement = value; } } #endregion #region 颜色 /// /// 颜色 /// private ObservableCollection _color = new ObservableCollection(); public ObservableCollection Color { get => _color; set => SetProperty(ref _color, value); } #endregion #region 总计 private int _totle = 0; public int Totle { get => _totle; set => SetProperty(ref _totle, value); } #endregion #region 夹具状态 private ObservableCollection _statusColor = new ObservableCollection(); public ObservableCollection StatusColor { get => _statusColor; set => SetProperty(ref _statusColor, value); } #endregion #region 夹具名称 private ObservableCollection _fixtureName = new ObservableCollection(); public ObservableCollection FixtureName { get => _fixtureName; set => SetProperty(ref _fixtureName, value); } #endregion #region 夹具产量 /// ///夹具产量 /// private ObservableCollection _production = new ObservableCollection(); public ObservableCollection Production { get => _production; set => SetProperty(ref _production, value); } #endregion #region 发泡量 /// /// 发泡量 /// private ObservableCollection _foamVolume = new ObservableCollection(); public ObservableCollection FoamVolume { get => _foamVolume; set => SetProperty(ref _foamVolume, value); } #endregion #region 内侧温度 private ObservableCollection _internalTemperature = new ObservableCollection(); public ObservableCollection InternalTemperature { get => _internalTemperature; set => SetProperty(ref _internalTemperature, value); } #endregion #region 侧板温度温度 private ObservableCollection _outsideTemperature = new ObservableCollection(); public ObservableCollection OutsideTemperature { get => _outsideTemperature; set => SetProperty(ref _outsideTemperature, value); } #endregion #region 夹具节拍 private ObservableCollection _beat = new ObservableCollection(); public ObservableCollection Beat { get => _beat; set => SetProperty(ref _beat, value); } #endregion /// /// 初始化发泡数据 /// /// public async Task InitData() { int total = 0; var list = await _boxFoamDataServices.QueryAsync(); foreach (var item in list) { if (item.BoxFixturestatus == 1) StatusColor.Add("Green"); if (item.BoxFixturestatus == 0) StatusColor.Add("Red"); FixtureName.Add(item.BoxFixturetype); Production.Add(item.BoxFixtureproduction.ToString()); FoamVolume.Add(item.FoamVolume); InternalTemperature.Add(item.BoxClosebetatemperature.ToString()); OutsideTemperature.Add(item.BoxFixturesideplate.ToString()); Beat.Add(item.BoxBeat); total += item.BoxFixtureproduction; } Totle = total; } } }