add-添加首页图表刷新统计

dev
liuwf 1 month ago
parent 11f71fb97b
commit 06f6b8b906

@ -176,7 +176,7 @@
<!--日产量-->
<Border Grid.Row="1" BorderBrush="Green" BorderThickness="0" CornerRadius="5" Background="Transparent" Margin="1,1,5,5">
<Border Grid.Row="1" BorderBrush="#0288d1" BorderThickness="0" CornerRadius="5" Background="Transparent" >
<lvc:CartesianChart Series="{Binding ModelStatistics, UpdateSourceTrigger=PropertyChanged}" LegendLocation="Top" Foreground="White" DisableAnimations="True">
<lvc:CartesianChart Series="{Binding Achievement, UpdateSourceTrigger=PropertyChanged}" LegendLocation="Top" Foreground="White" DisableAnimations="True">
<lvc:CartesianChart.DataTooltip >
<lvc:DefaultTooltip SelectionMode="OnlySender" BulletSize="10" Foreground="Black"></lvc:DefaultTooltip>
</lvc:CartesianChart.DataTooltip>

@ -23,6 +23,14 @@ using static System.Net.Mime.MediaTypeNames;
using Application = System.Windows.Application;
using LiveCharts;
using System.Threading;
using SlnMesnac.Repository.service;
using LiveCharts.Defaults;
using static MaterialDesignThemes.Wpf.Theme.ToolBar;
using LiveCharts.Wpf;
using System.Windows.Media;
using System.Windows.Threading;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using SlnMesnac.Config;
namespace SlnMesnac.WPF.ViewModel
{
@ -37,11 +45,13 @@ namespace SlnMesnac.WPF.ViewModel
private readonly PalletStowBusiness? _palletStowBusiness;
private readonly IMesBaseBarcodeInfoService? _mesBaseBarcodeInfoService;
private readonly ProdCompletionBusiness? _prodCompletionBusiness;
private ObservableCollection<dynamic> listItems = new ObservableCollection<dynamic>();
#region 参数定义
/// <summary>
@ -93,7 +103,7 @@ namespace SlnMesnac.WPF.ViewModel
get { return beginTime; }
set { beginTime = value; RaisePropertyChanged(nameof(BeginTime)); }
}
/// <summary>
/// 计划数量
/// </summary>
@ -133,7 +143,7 @@ namespace SlnMesnac.WPF.ViewModel
get { return compleRoution; }
set { compleRoution = value; RaisePropertyChanged(nameof(CompleRoution)); }
}
/// <summary>
/// 计划列表DataGrid
/// </summary>
@ -198,13 +208,14 @@ namespace SlnMesnac.WPF.ViewModel
public ProdMgmtViewModel()
{
StartProdPlanCommand = new RelayCommand<string>(obj => StartProdPlan(obj));
StopProdPlanCommand = new RelayCommand<string>(obj => StopProdPlan(obj));
_logger = App.ServiceProvider.GetService<ILogger<ProdMgmtViewModel>>();
_prodMgmtBusiness = App.ServiceProvider.GetService<ProdMgmtBusiness>();
_palletStowBusiness = App.ServiceProvider.GetService<PalletStowBusiness>();
_prodCompletionBusiness = App.ServiceProvider.GetService<ProdCompletionBusiness>();
_mesBaseBarcodeInfoService = App.ServiceProvider.GetService<IMesBaseBarcodeInfoService>();
Task.Run(() =>
{
_prodMgmtBusiness.RefreshProdPlanListEvent += RefreshPlanDataGrid;
@ -212,22 +223,33 @@ namespace SlnMesnac.WPF.ViewModel
_prodMgmtBusiness.PrintMessageToListBoxEvent += PrintMessageToListBox;
_prodMgmtBusiness.InitProdPlan();
});
//Task.Run(() =>
//{
// _palletStowBusiness.PrintMessageToListBoxEvent += PrintMessageToListBox;
// _palletStowBusiness.Init();
//});
Task.Run(() =>
{
_prodCompletionBusiness.PrintMessageToListBoxEvent += PrintMessageToListBox;
// _prodCompletionBusiness.Init();
// _prodCompletionBusiness.Init();
});
Init();
}
private void Init()
{
RefreChart();
DispatcherTimer _timer = new DispatcherTimer();
_timer.Interval = TimeSpan.FromMinutes(5);
_timer.Tick += Timer_Tick;
_timer.Start();
}
private void Timer_Tick(object sender, EventArgs e)
{
RefreChart();
}
public void test()
{
// gunHelper.InstanceSerialPort();
@ -285,13 +307,14 @@ namespace SlnMesnac.WPF.ViewModel
});
var info = list.Where(x => x.PlanStatus == PlanStatusEnum.).ToList();
if(info.Count > 0)
if (info.Count > 0)
{
RefreshPlanExec(info.First());
}
}
}catch(Exception ex)
}
catch (Exception ex)
{
_logger.LogError($"生产计划刷新异常:{ex.Message}");
}
@ -306,11 +329,11 @@ namespace SlnMesnac.WPF.ViewModel
try
{
//先检查是否有正在执行的计划
var hasPlan = planInfoDataGrid.Where(x=>x.PlanStatus== PlanStatusEnum.).FirstOrDefault();
if(hasPlan != null)
var hasPlan = planInfoDataGrid.Where(x => x.PlanStatus == PlanStatusEnum.).FirstOrDefault();
if (hasPlan != null)
{
var result = MessageBox.Show("有正在执行的计划,是否确认切换计划!","确认", MessageBoxButton.YesNo);
if(result == MessageBoxResult.Yes)
var result = MessageBox.Show("有正在执行的计划,是否确认切换计划!", "确认", MessageBoxButton.YesNo);
if (result == MessageBoxResult.Yes)
{
hasPlan.PlanStatus = PlanStatusEnum.;
_prodMgmtBusiness.UpdateProdPlan(hasPlan);
@ -339,7 +362,7 @@ namespace SlnMesnac.WPF.ViewModel
_logger.LogError($"开始事件处理异常:{e.Message}");
}
}
/// <summary>
/// 暂停生产计划事件
/// </summary>
@ -359,7 +382,7 @@ namespace SlnMesnac.WPF.ViewModel
PrintMessageToListBox($"暂停执行{obj}计划");
_prodMgmtBusiness.UpdateProdPlan(info);
this.RefreshPlanExec(null);
}
catch (Exception e)
@ -376,7 +399,7 @@ namespace SlnMesnac.WPF.ViewModel
/// <param name="materialName"></param>
/// <param name="msg"></param>
/// <returns></returns>
private bool MatPutInValidHandleEvent(int validType,MesProductPlan productPlan, string materialName,string msg)
private bool MatPutInValidHandleEvent(int validType, MesProductPlan productPlan, string materialName, string msg)
{
var result = false;
@ -440,8 +463,68 @@ namespace SlnMesnac.WPF.ViewModel
/// </summary>
private async void RefreChart()
{
ProductionHourList = 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","20:00" };
try
{
await Task.Run(() =>
{
ProductionHourList = 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", "20:00" };
List<MesBaseBarcodeInfo> list = _mesBaseBarcodeInfoService.Query(x => x.bindTime != null && x.bindTime >= DateTime.Now.Date && x.bindTime <= DateTime.Now.AddDays(1)).ToList();
if (list != null && list.Count > 0)
{
Dictionary<string, int> hourProductionCount = new Dictionary<string, int>();
// 初始化字典每个小时的产量初始为0
foreach (var hour in ProductionHourList)
{
hourProductionCount[hour] = 0;
}
// 遍历查询结果,统计每个小时的产量
foreach (var item in list)
{
// 获取 bindTime 的小时部分
string hour = item.bindTime.Value.ToString("H:00");
// 如果小时在 ProductionHourList 中,则统计该小时的产量
if (hourProductionCount.ContainsKey(hour))
{
hourProductionCount[hour]++;
}
}
Application.Current.Dispatcher.Invoke(() =>
{
Achievement.Clear();
ChartValues<ObservablePoint> achievement = new ChartValues<ObservablePoint>();
int i = 0;
foreach (var kvp in hourProductionCount)
{
achievement.Add(new ObservablePoint(i++, kvp.Value));
}
//加一个汇总柱状图
ProductionHourList.Add("合计");
achievement.Add(new ObservablePoint(i, list.Count));
var column = new ColumnSeries();
column.DataLabels = true;
column.Title = "小时产量";
column.Values = achievement;
column.Foreground = Brushes.White;
Achievement.Add(column);
});
}
else
{
// ProductionHourList.Clear();
Achievement.Clear();
}
});
}catch(Exception ex)
{
_logger.LogError($"产量统计图表异常:{ex.Message}");
}
}
}
}

Loading…
Cancel
Save