add-添加生产统计-投料日统计图表

dev
liuwf 1 month ago
parent 886c7f746c
commit ca3a76f6e5

@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:local="clr-namespace:SlnMesnac.WPF.Page"
xmlns:cvt="clr-namespace:SlnMesnac.WPF.ConvertTo"
mc:Ignorable="d"
@ -95,12 +96,12 @@
<Button Margin="10 0"
Content="时间查询" Command="{Binding QueryCommand}"
Style="{StaticResource BUTTON_AGREE}" Background="LimeGreen">
<Button.CommandParameter>
<!--<Button.CommandParameter>
<MultiBinding Converter="{StaticResource QueryConvert}">
<Binding ElementName="BeginTime" Path="Text"/>
<Binding ElementName="EndTime" Path="Text"/>
</MultiBinding>
</Button.CommandParameter>
</Button.CommandParameter>-->
</Button>
</WrapPanel>
</Border>
@ -177,7 +178,32 @@ Foreground="#FFFFFF" >
<Border Grid.Row="0" BorderBrush="CadetBlue" BorderThickness="0,0,0,0" CornerRadius="0" Background="Transparent" Margin="1,6,5,5" >
<TextBlock Text="日投料统计图" FontSize="20" FontWeight="Bold" Foreground="#0288d1" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
<Border Grid.Row="1" BorderBrush="#0288d1" BorderThickness="0" CornerRadius="5" Background="Transparent" >
<lvc:CartesianChart Series="{Binding OutAchievement, UpdateSourceTrigger=PropertyChanged}" LegendLocation="Top" Foreground="White" DisableAnimations="True">
<lvc:CartesianChart.DataTooltip >
<lvc:DefaultTooltip SelectionMode="OnlySender" BulletSize="10" Foreground="Black"></lvc:DefaultTooltip>
</lvc:CartesianChart.DataTooltip>
<lvc:CartesianChart.AxisX >
<lvc:Axis Labels="{Binding OutDayList}" FontSize="18" Foreground="White" LabelsRotation="0" DisableAnimations="True" Position="LeftBottom" >
<lvc:Axis.Separator>
<lvc:Separator Visibility="Hidden" Step="1" StrokeThickness="1.5" StrokeDashArray="0" Stroke="#404F56" >
</lvc:Separator>
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisX>
<lvc:CartesianChart.AxisY>
<lvc:Axis FontSize="18" Foreground="White" MinValue="0">
<lvc:Axis.Separator>
<lvc:Separator Step="10" Visibility="Hidden" StrokeThickness="1" StrokeDashArray="3" Stroke="#404F56" >
</lvc:Separator>
</lvc:Axis.Separator>
</lvc:Axis>
</lvc:CartesianChart.AxisY>
</lvc:CartesianChart>
</Border>
</Grid>
</Border>
<Border Grid.Row="2" Grid.Column="1" BorderBrush="#1254AB" BorderThickness="2" CornerRadius="5" Background="Transparent" Margin="1,1,5,5">

@ -54,6 +54,33 @@ namespace SlnMesnac.WPF.ViewModel
#region 参数定义
#region 日产量柱状图X轴日期
/// <summary>
/// 日产量柱状图X轴日期
/// </summary>
private List<string> productionHourList = new List<string>();
public List<string> ProductionHourList
{
get { return productionHourList; }
set { productionHourList = value; }
}
#endregion
#region 型号统计柱状图
/// <summary>
/// 型号统计柱状图
/// </summary>
private SeriesCollection achievement = new SeriesCollection();
public SeriesCollection Achievement
{
get { return achievement; }
set { achievement = value; }
}
#endregion
/// <summary>
/// 工位名称
/// </summary>
@ -167,31 +194,7 @@ namespace SlnMesnac.WPF.ViewModel
#endregion
#region 日产量柱状图X轴日期
/// <summary>
/// 日产量柱状图X轴日期
/// </summary>
private List<string> productionHourList = new List<string>();
public List<string> ProductionHourList
{
get { return productionHourList; }
set { productionHourList = value; }
}
#endregion
#region 型号统计柱状图
/// <summary>
/// 型号统计柱状图
/// </summary>
private SeriesCollection achievement = new SeriesCollection();
public SeriesCollection Achievement
{
get { return achievement; }
set { achievement = value; }
}
#endregion
#region 事件定义

@ -1,5 +1,8 @@
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Business;
using SlnMesnac.Model.domain;
@ -14,6 +17,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
@ -53,75 +57,44 @@ namespace SlnMesnac.WPF.ViewModel
_palletStowBusiness = App.ServiceProvider.GetService<PalletStowBusiness>();
_prodCompletionBusiness = App.ServiceProvider.GetService<ProdCompletionBusiness>();
sqlClient = App.ServiceProvider.GetService<ISqlSugarClient>();
QueryCommand = new RelayCommand<object>(obj => Query(obj));
DeletePalletCommand = new RelayCommand<string>(DeletePallet);
QueryCommand = new RelayCommand<object>(obj => Query());
BeginDate = DateTime.Now.AddDays(-3);
EndDate = DateTime.Now;
Query();
}
#region 参数定义
#region 日产量柱状图X轴日期
/// <summary>
/// 日产量柱状图X轴日期
/// </summary>
private List<string> outDayList = new List<string>();
#region 时间查询
private async Task Query(object obj)
{
try
{
if (EndDate <= BeginDate)
{
Application.Current.Dispatcher.Invoke(() =>
{
Msg.MsgShow("结束时间要大于开始时间", 2, 3);
});
return;
}
else
{
await RefreshWmsRawOutstockDetailDataGrid(BeginDate, EndDate);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
public List<string> OutDayList
{
get { return outDayList; }
set { outDayList = value; }
}
#endregion
#region 型号统计柱状图
/// <summary>
/// 刷新原材料出库记录及图表
/// 投料日产量统计柱状图
/// </summary>
private async Task RefreshWmsRawOutstockDetailDataGrid(DateTime beginDate, DateTime endDate)
{
List<WmsRawOutstockDetail> list;
list = await sqlClient.AsTenant().GetConnection("mes").Queryable<WmsRawOutstockDetail>().Where(x => x.WarehouseId==311 && x.OutstockTime >= beginDate && x.OutstockTime <= endDate).OrderBy(t => t.OutstockTime).ToListAsync();
private SeriesCollection outAchievement = new SeriesCollection();
if (list != null && list.Count > 0)
{
await App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
WmsRawOutstockDetailDataGrid.Clear();
int i = 1;
foreach (WmsRawOutstockDetail verify in list)
{
verify.RawOutstockDetailId = i++;
WmsRawOutstockDetailDataGrid.Add(verify);
}
}));
// 刷新图表
// ModelList(list);
}
public SeriesCollection OutAchievement
{
get { return outAchievement; }
set { outAchievement = value; }
}
#endregion
#region 参数定义
private DateTime _BeginDate;
public DateTime BeginDate
{
@ -151,7 +124,7 @@ namespace SlnMesnac.WPF.ViewModel
/// <summary>
/// 托盘队列DataGrid
/// 原材料投料明细DataGrid
/// </summary>
private ObservableCollection<WmsRawOutstockDetail> wmsRawOutstockDetailDataGrid = new ObservableCollection<WmsRawOutstockDetail>();
@ -181,43 +154,108 @@ namespace SlnMesnac.WPF.ViewModel
/// </summary>
public RelayCommand<object> QueryCommand { get; set; }
public RelayCommand<string> DeletePalletCommand { get;set; }
public RelayCommand<string> DeleteBarCodeCommand { get; set; }
#endregion
///// <summary>
///// 刷新条码队列信息
///// </summary>
///// <param name="barCodeTasks"></param>
//private void RefreshBarCodeTaskDataGrid(List<RealBarCodeTask> barCodeTasks)
//{
// BarCodeTaskDataGrid = new ObservableCollection<RealBarCodeTask>();
// foreach (var task in barCodeTasks)
// {
// BarCodeTaskDataGrid.Add(task);
// }
//}
#region 时间查询
private async Task Query()
{
try
{
if (EndDate <= BeginDate)
{
Application.Current.Dispatcher.Invoke(() =>
{
Msg.MsgShow("结束时间要大于开始时间", 2, 3);
});
return;
}
else
{
await RefreshWmsRawOutstockDetailDataGrid(BeginDate, EndDate);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
#endregion
#region 原材料出库记录及图表
/// <summary>
/// 移除托盘队列信息
/// 刷新原材料出库记录
/// </summary>
/// <param name="palletCode"></param>
private void DeletePallet(string palletCode)
private async Task RefreshWmsRawOutstockDetailDataGrid(DateTime beginDate, DateTime endDate)
{
_palletStowBusiness.RemovePalletInfo(palletCode);
List<WmsRawOutstockDetail> list;
list = await sqlClient.AsTenant().GetConnection("mes").Queryable<WmsRawOutstockDetail>().Where(x => x.WarehouseId == 311 && x.OutstockTime >= beginDate && x.OutstockTime <= endDate).OrderByDescending(t => t.OutstockTime).ToListAsync();
if (list != null && list.Count > 0)
{
await App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
WmsRawOutstockDetailDataGrid.Clear();
int i = 1;
foreach (WmsRawOutstockDetail verify in list)
{
verify.RawOutstockDetailId = i++;
WmsRawOutstockDetailDataGrid.Add(verify);
}
}));
// 刷新图表
RefreshWmsRawOutstockDetailChart(list);
}
}
///// <summary>
///// 移除小包条码队列信息
///// </summary>
///// <param name="barCode"></param>
//private void DeleteBarCode(string barCode)
//{
// _prodCompletionBusiness.RemoveBarCode(barCode);
//}
/// <summary>
/// 刷新原材料出库图表
/// </summary>
/// <param name="list"></param>
private void RefreshWmsRawOutstockDetailChart(List<WmsRawOutstockDetail> list)
{
App.Current.Dispatcher.BeginInvoke((Action)(() =>
{
OutAchievement.Clear();
OutDayList.Clear();
ChartValues<ObservablePoint> achievement = new ChartValues<ObservablePoint>();
var listByDate = list
.GroupBy(detail => detail.OutstockTime.Value.Date) // 按日期分组
.Select(group => new
{
Date = group.Key,
TotalAmount = group.Count() // 统计出库数量
})
.ToList();
int i = 0;
foreach (var item in listByDate)
{
outDayList.Add(item.Date.ToString("MM-dd"));
achievement.Add(new ObservablePoint(i++, double.Parse(item.TotalAmount.ToString())));
}
//加一个汇总柱状图
outDayList.Add("合计");
achievement.Add(new ObservablePoint(i, list.Count));
var column = new ColumnSeries();
column.DataLabels = true;
column.Title = "日投料量";
column.Values = achievement;
column.Foreground = Brushes.White;
OutAchievement.Add(column);
}));
}
#endregion
}
}

Loading…
Cancel
Save