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.

158 lines
4.8 KiB
C#

using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.ObjectModel;
using log4net;
using Aucma.Core.DoorFoam.Common;
using LiveCharts;
using System.Collections.Generic;
using Admin.Core.Model;
using Admin.Core.Service;
using LiveCharts.Wpf;
using Admin.Core.IService;
using Microsoft.Extensions.DependencyInjection;
using System.Threading.Tasks;
using System.Windows.Media;
using Admin.Core.Model.ViewModels;
using Pipelines.Sockets.Unofficial.Arenas;
using NPOI.SS.Formula.Functions;
using Aucma.Core.DoorFoam.Models;
using Aucma.Core.DoorFoam.Business;
using System.Threading;
using System.Collections;
using NPOI.Util;
using SqlSugar;
using System.Linq;
/*
* 首页信息
*/
namespace Aucma.Core.DoorFoam.ViewModels
{
public partial class IndexPageViewModel : ObservableObject
{
private static readonly log4net.ILog log = LogManager.GetLogger(typeof(IndexPageViewModel));
private DoorCollection doorCollection = new DoorCollection();
public IndexPageViewModel()
{
doorCollection.RefreshDoorFoamMachineEvent += info =>
{
RefreshDoorFoamMachineDataGrid(info);
};
Task.Run(() =>
{
Thread.Sleep(30000);
doorCollection.startCollect();
});
}
#region 获取今天的数据
/// <summary>
/// 获取今天的数据
/// </summary>
/// <returns></returns>
private void InitEveryDayMethodAsync(List<DoorModeRealTimeModel> mode)
{
if (mode == null) return;
foreach (var modeItem in mode)
{
DoorFp1DataGrid.Add(modeItem);
}
}
#endregion
#region 获取今天的数据
/// <summary>
/// 获取今天的数据
/// </summary>
/// <returns></returns>
private void InitEveryDayMethod2Async(List<DoorModeRealTimeModel> mode)
{
if (mode == null) return;
foreach (var modeItem in mode)
{
DoorFp1DataGrid.Add(modeItem);
}
}
#endregion
#region 初始化datagrid
private ObservableCollection<DoorModeRealTimeModel> _doorFp1DataGrid = new ObservableCollection<DoorModeRealTimeModel>();
public ObservableCollection<DoorModeRealTimeModel> DoorFp1DataGrid
{
get { return _doorFp1DataGrid; }
set
{
_doorFp1DataGrid = value;
OnPropertyChanged();//属性通知
}
}
#endregion
#region 初始化datagrid
private ObservableCollection<DoorModeRealTimeModel> _doorFp2DataGrid = new ObservableCollection<DoorModeRealTimeModel>();
public ObservableCollection<DoorModeRealTimeModel> DoorFp2DataGrid
{
get { return _doorFp1DataGrid; }
set
{
_doorFp1DataGrid = value;
OnPropertyChanged();//属性通知
}
}
#endregion
private string _stationName;
public string StationName
{
get { return _stationName; }
set
{
_stationName = DateTime.Now.ToString();
SetProperty(ref _stationName, value);
}
}
private ObservableCollection<DoorFoamMachine> dataGridItemLeft = new ObservableCollection<DoorFoamMachine>();
private IEnumerable doorFoamMachineDataGrid_Left;
public IEnumerable DoorFoamMachineDataGrid_Left
{
get { return doorFoamMachineDataGrid_Left; }
set { doorFoamMachineDataGrid_Left = value; OnPropertyChanged(); }
}
private ObservableCollection<DoorFoamMachine> dataGridItemRight = new ObservableCollection<DoorFoamMachine>();
private IEnumerable doorFoamMachineDataGrid_Right;
public IEnumerable DoorFoamMachineDataGrid_Right
{
get { return doorFoamMachineDataGrid_Right; }
set { doorFoamMachineDataGrid_Right = value; OnPropertyChanged(); }
}
private void RefreshDoorFoamMachineDataGrid(List<DoorFoamMachine> data)
{
dataGridItemLeft = new ObservableCollection<DoorFoamMachine>();
int totalItems = data.Count;
int half = totalItems / 2;
List<DoorFoamMachine> doorFoamMachineLeft = data.Take(half).ToList();
List<DoorFoamMachine> doorFoamMachineRight = data.Skip(half).ToList();
doorFoamMachineLeft.ForEach(x=> dataGridItemLeft.Add(x));
DoorFoamMachineDataGrid_Left = dataGridItemLeft;
doorFoamMachineRight.ForEach(x=>dataGridItemRight.Add(x));
DoorFoamMachineDataGrid_Right = doorFoamMachineRight;
}
}
}