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.

343 lines
13 KiB
C#

1 year ago
using Admin.Core.IService;
1 year ago
using Admin.Core.Model.Model_New;
using Admin.Core.Service;
1 year ago
using Aucma.Core.OldBoxFoam.Business;
1 year ago
using Aucma.Core.OldBoxFoam.Models;
1 year ago
using Aucma.Core.OldBoxFoam.Views;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
using LiveCharts.Wpf;
using LiveCharts;
1 year ago
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
1 year ago
using System.Timers;
1 year ago
using System.Windows;
using Admin.Core.Model;
using NPOI.SS.Formula.Functions;
using System.Windows.Documents;
1 year ago
using static Npgsql.Replication.PgOutput.Messages.RelationMessage;
using System.Windows.Media;
1 year ago
namespace Aucma.Core.OldBoxFoam.ViewModels
{
/**
*
*
* */
public partial class RealRoadPageViewModel : ObservableObject
{
protected readonly IBoxFoamPlanServices? _boxFoamPlanServices;
1 year ago
private IOldBoxFoamTypeServices? _oldBoxFoamTypeServices;
private IBoxFoamDataServices? _boxFoamDataServices;
1 year ago
System.Timers.Timer timer2 = new System.Timers.Timer(3000);
1 year ago
public RealRoadPageViewModel()
{
YAxisLabelFormatter = value => Math.Round(value, 2).ToString();
1 year ago
_boxFoamPlanServices = App.ServiceProvider.GetService<IBoxFoamPlanServices>();
1 year ago
_oldBoxFoamTypeServices = App.ServiceProvider.GetService<IOldBoxFoamTypeServices>();
_boxFoamDataServices = App.ServiceProvider.GetService<IBoxFoamDataServices>();
1 year ago
//InitData();
1 year ago
Collection.RefreshSpaceEvent += InitData;
1 year ago
timer2.Elapsed += new System.Timers.ElapsedEventHandler(InitData); //到达时间的时候执行事件;
timer2.AutoReset = true;//设置是执行一次false还是一直执行(true)
timer2.Enabled = true;//需要调用 timer.Start()或者timer.Enabled = true来启动它
timer2.Start();//timer.Start()的内部原理还是设置timer.Enabled = true;
//RefreshHourOutPutChart();
//RefreshMaterialTypeChart();
}
#region 参数定义
private Func<double, string> _yAxisLabelFormatter;
public Func<double, string> YAxisLabelFormatter
{
get { return _yAxisLabelFormatter; }
set
{
_yAxisLabelFormatter = value;
OnPropertyChanged(nameof(YAxisLabelFormatter));
}
}
/// <summary>
/// 小时产量统计图表
/// </summary>
private SeriesCollection _hourAchievement = new SeriesCollection();
public SeriesCollection HourAchievement
{
get { return _hourAchievement; }
set
{
_hourAchievement = value;
OnPropertyChanged(nameof(HourAchievement));
}
}
/// <summary>
/// 小时产量统计图表X轴
/// </summary>
private List<string> _hourOutPutList;
public List<string> HourOutPutList
{
get { return _hourOutPutList; }
set
{
_hourOutPutList = value;
OnPropertyChanged(nameof(HourOutPutList));
}
1 year ago
}
1 year ago
/// <summary>
/// 型号统计图表
/// </summary>
private SeriesCollection _materialTypeAchievement = new SeriesCollection();
public SeriesCollection MaterialTypeAchievement
{
get { return _materialTypeAchievement; }
set
{
_materialTypeAchievement = value;
OnPropertyChanged(nameof(MaterialTypeAchievement));
}
}
private List<string> _materialTypeOutPutList;
public List<string> MaterialTypeOutPutList
{
get { return _materialTypeOutPutList; }
set
{
_materialTypeOutPutList = value;
OnPropertyChanged(nameof(MaterialTypeOutPutList));
}
}
#endregion
1 year ago
public async void InitData(object? sender, ElapsedEventArgs e)
1 year ago
{
1 year ago
List<OldBoxFoamType> list = await _oldBoxFoamTypeServices.QueryAsync();
if(list != null)
1 year ago
{
if(list.Count > 0)
1 year ago
{
list = list.OrderBy(x=>x.ObjId).ToList();
int totalItems = list.Count;
int half = totalItems / 2;
List<OldBoxFoamType> spaceInfoLeft = list.Take(half).ToList();
List<OldBoxFoamType> spaceInfoRight = list.Skip(half).ToList();
System.Windows.Application.Current.Dispatcher.Invoke((Action)(() =>
1 year ago
{
ListItems.Clear();
if (spaceInfoLeft == null) return;
for (int i = 0; i < spaceInfoLeft.Count; i++)
{
ListItems.Add(new OldBoxFoamTypeModel()
{
SpaceName = $"东线{i + 1}",
Local = spaceInfoLeft[i].Local,
Status = spaceInfoLeft[i].Storeamount == 3 ? "1" : "0",
Storeamount = spaceInfoLeft[i].Storeamount,
MaterialCode = spaceInfoLeft[i].MaterialCode,
MaterialName = spaceInfoLeft[i].MaterialName,
Boxtype = spaceInfoLeft[i].Boxtype,
1 year ago
});
}
if (spaceInfoRight == null) return;
for (int i = 0; i < spaceInfoRight.Count; i++)
{
ListItems.Add(new OldBoxFoamTypeModel()
{
SpaceName = $"西线{i + 1}",
Local = spaceInfoRight[i].Local,
Status = spaceInfoRight[i].Storeamount == 3 ? "1" : "0",
Storeamount = spaceInfoRight[i].Storeamount,
MaterialCode = spaceInfoRight[i].MaterialCode,
MaterialName = spaceInfoRight[i].MaterialName,
Boxtype = spaceInfoRight[i].Boxtype,
1 year ago
});
}
}));
1 year ago
}
}
1 year ago
}
1 year ago
#region 初始化datagrid
private ObservableCollection<OldBoxFoamTypeModel> listItems = new ObservableCollection<OldBoxFoamTypeModel>();
public ObservableCollection<OldBoxFoamTypeModel> ListItems
1 year ago
{
1 year ago
get { return listItems; }
set
{
listItems = value;
OnPropertyChanged();//属性通知
}
1 year ago
}
#endregion
1 year ago
/// <summary>
/// 更新货道信息
1 year ago
/// </summary>
/// <param name="spaceDetailModel"></param>
1 year ago
public async void InitData(List<SpaceDetailModel> spaceDetailModel)
1 year ago
{
if (spaceDetailModel == null) return;
1 year ago
var spaceList = _oldBoxFoamTypeServices.QueryAsync().Result;
List<OldBoxFoamType> storeList = new List<OldBoxFoamType>();
foreach (var item in spaceDetailModel)
1 year ago
{
1 year ago
var space = spaceList.FirstOrDefault(x=>x.ObjId == item.ObjId);
if(spaceList != null)
1 year ago
{
if(spaceDetailModel.Count > 0)
1 year ago
{
1 year ago
var spaceInfo = space;
spaceInfo.Storeamount = item.StoreAmount;
spaceInfo.Boxtype = item.StoreType;
1 year ago
storeList.Add(spaceInfo);
//_oldBoxFoamTypeServices.UpdateAsync(spaceInfo);
1 year ago
}
}
}
1 year ago
if (storeList!=null&&storeList.Count>0)
{
await _oldBoxFoamTypeServices.UpdateAsync(storeList);
}
RefreshHourOutPutChart();
RefreshMaterialTypeChart();
}
/// <summary>
/// 小时统计图表
/// </summary>
private void RefreshHourOutPutChart()
{
ChartValues<double> hourAchievement = new ChartValues<double>();
HourOutPutList = new List<string>();
App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
DateTime now = DateTime.Now;
// 判断当前是否是白班时间段
if (now.Hour >= 8 && now.Hour < 20)
{
HourOutPutList = new List<string>() { "8:00", "9:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00" };
}
else
{
HourOutPutList = new List<string>() { "20:00", "21:00", "22:00", "23:00", "00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", "0:007" };
}
var hourFoamDataList = _boxFoamDataServices.Query(x=>x.ProductLineCode == "CX_01" && x.StationCode == "1105");
List<int> hours = new List<int>();
if (hourFoamDataList != null)
{
hourAchievement.Add(hourFoamDataList.Sum(x => x.AnHour));
hourAchievement.Add(hourFoamDataList.Sum(x => x.TwoHour));
hourAchievement.Add(hourFoamDataList.Sum(x => x.ThreeHour));
hourAchievement.Add(hourFoamDataList.Sum(x => x.FourHour));
hourAchievement.Add(hourFoamDataList.Sum(x => x.FiveHour));
hourAchievement.Add(hourFoamDataList.Sum(x => x.SixHour));
hourAchievement.Add(hourFoamDataList.Sum(x => x.SevenHour));
hourAchievement.Add(hourFoamDataList.Sum(x => x.EightHour));
hourAchievement.Add(hourFoamDataList.Sum(x => x.NineHour));
hourAchievement.Add(hourFoamDataList.Sum(x => x.TenHour));
hourAchievement.Add(hourFoamDataList.Sum(x => x.ElevenHour));
hourAchievement.Add(hourFoamDataList.Sum(x => x.TwelveHour));
}
var shellColumn = new ColumnSeries();
shellColumn.DataLabels = true;
shellColumn.Title = "小时产量";
shellColumn.Values = hourAchievement;
1 year ago
shellColumn.Foreground = Brushes.White;
1 year ago
if (HourAchievement.Count > 0)
{
for (int i = 0; i < hourAchievement.Count; i++)
{
//hours
HourAchievement.FirstOrDefault().Values[i] = hourAchievement.ElementAt(i);
}
}
else
{
HourAchievement.Add(shellColumn);
}
}));
}
/// <summary>
/// 型号统计图表
/// </summary>
private void RefreshMaterialTypeChart()
{
ChartValues<double> materialTypeAchievement = new ChartValues<double>();
MaterialTypeOutPutList = new List<string>();
App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
DateTime now = DateTime.Now;
var hourFoamDataList = _boxFoamDataServices.Query(x => x.ProductLineCode == "CX_01" && x.StationCode == "1105");
if (hourFoamDataList != null)
{
var grouped = hourFoamDataList.GroupBy(x => x.Fixtureboxtype);
foreach (var item in grouped)
{
var flattenedList = item.SelectMany(p => new[] { p.AnHour, p.TwoHour, p.ThreeHour, p.FourHour, p.FiveHour, p.SixHour, p.SevenHour, p.EightHour, p.NineHour, p.TenHour, p.ElevenHour, p.TwelveHour }).ToList();
MaterialTypeOutPutList.Add(item.Key);
materialTypeAchievement.Add(flattenedList.Sum());
}
}
var shellColumn = new ColumnSeries();
shellColumn.DataLabels = true;
shellColumn.Title = "型号统计";
shellColumn.Values = materialTypeAchievement;
1 year ago
shellColumn.Foreground = Brushes.White;
if (MaterialTypeAchievement.Count > 0)
{
for (int i = 0; i < materialTypeAchievement.Count; i++)
{
MaterialTypeAchievement.FirstOrDefault().Values[i] = materialTypeAchievement.ElementAt(i);
}
}
else
{
MaterialTypeAchievement.Add(shellColumn);
}
}));
1 year ago
}
1 year ago
}
}