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

dev
liuwf 1 month ago
parent 886c7f746c
commit ca3a76f6e5

@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 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:local="clr-namespace:SlnMesnac.WPF.Page"
xmlns:cvt="clr-namespace:SlnMesnac.WPF.ConvertTo" xmlns:cvt="clr-namespace:SlnMesnac.WPF.ConvertTo"
mc:Ignorable="d" mc:Ignorable="d"
@ -95,12 +96,12 @@
<Button Margin="10 0" <Button Margin="10 0"
Content="时间查询" Command="{Binding QueryCommand}" Content="时间查询" Command="{Binding QueryCommand}"
Style="{StaticResource BUTTON_AGREE}" Background="LimeGreen"> Style="{StaticResource BUTTON_AGREE}" Background="LimeGreen">
<Button.CommandParameter> <!--<Button.CommandParameter>
<MultiBinding Converter="{StaticResource QueryConvert}"> <MultiBinding Converter="{StaticResource QueryConvert}">
<Binding ElementName="BeginTime" Path="Text"/> <Binding ElementName="BeginTime" Path="Text"/>
<Binding ElementName="EndTime" Path="Text"/> <Binding ElementName="EndTime" Path="Text"/>
</MultiBinding> </MultiBinding>
</Button.CommandParameter> </Button.CommandParameter>-->
</Button> </Button>
</WrapPanel> </WrapPanel>
</Border> </Border>
@ -177,6 +178,31 @@ Foreground="#FFFFFF" >
<Border Grid.Row="0" BorderBrush="CadetBlue" BorderThickness="0,0,0,0" CornerRadius="0" Background="Transparent" Margin="1,6,5,5" > <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"/> <TextBlock Text="日投料统计图" FontSize="20" FontWeight="Bold" Foreground="#0288d1" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border> </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> </Grid>
</Border> </Border>

@ -54,6 +54,33 @@ namespace SlnMesnac.WPF.ViewModel
#region 参数定义 #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>
/// 工位名称 /// 工位名称
/// </summary> /// </summary>
@ -167,31 +194,7 @@ namespace SlnMesnac.WPF.ViewModel
#endregion #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 事件定义 #region 事件定义

@ -1,5 +1,8 @@
using GalaSoft.MvvmLight; using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Command;
using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using SlnMesnac.Business; using SlnMesnac.Business;
using SlnMesnac.Model.domain; using SlnMesnac.Model.domain;
@ -14,6 +17,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Media;
#region << 版 本 注 释 >> #region << 版 本 注 释 >>
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
@ -53,75 +57,44 @@ namespace SlnMesnac.WPF.ViewModel
_palletStowBusiness = App.ServiceProvider.GetService<PalletStowBusiness>(); _palletStowBusiness = App.ServiceProvider.GetService<PalletStowBusiness>();
_prodCompletionBusiness = App.ServiceProvider.GetService<ProdCompletionBusiness>(); _prodCompletionBusiness = App.ServiceProvider.GetService<ProdCompletionBusiness>();
sqlClient = App.ServiceProvider.GetService<ISqlSugarClient>(); sqlClient = App.ServiceProvider.GetService<ISqlSugarClient>();
QueryCommand = new RelayCommand<object>(obj => Query(obj)); QueryCommand = new RelayCommand<object>(obj => Query());
DeletePalletCommand = new RelayCommand<string>(DeletePallet);
BeginDate = DateTime.Now.AddDays(-3); BeginDate = DateTime.Now.AddDays(-3);
EndDate = DateTime.Now; EndDate = DateTime.Now;
Query();
} }
#region 参数定义
#region 日产量柱状图X轴日期
/// <summary>
/// 日产量柱状图X轴日期
/// </summary>
private List<string> outDayList = new List<string>();
#region 时间查询 public List<string> OutDayList
private async Task Query(object obj)
{ {
try get { return outDayList; }
{ set { outDayList = value; }
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 #endregion
#region 型号统计柱状图
/// <summary> /// <summary>
/// 刷新原材料出库记录及图表 /// 投料日产量统计柱状图
/// </summary> /// </summary>
private async Task RefreshWmsRawOutstockDetailDataGrid(DateTime beginDate, DateTime endDate) private SeriesCollection outAchievement = new SeriesCollection();
{
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();
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);
}
}));
// 刷新图表 public SeriesCollection OutAchievement
// ModelList(list); {
} get { return outAchievement; }
set { outAchievement = value; }
} }
#endregion
#region 参数定义
private DateTime _BeginDate; private DateTime _BeginDate;
public DateTime BeginDate public DateTime BeginDate
{ {
@ -151,7 +124,7 @@ namespace SlnMesnac.WPF.ViewModel
/// <summary> /// <summary>
/// 托盘队列DataGrid /// 原材料投料明细DataGrid
/// </summary> /// </summary>
private ObservableCollection<WmsRawOutstockDetail> wmsRawOutstockDetailDataGrid = new ObservableCollection<WmsRawOutstockDetail>(); private ObservableCollection<WmsRawOutstockDetail> wmsRawOutstockDetailDataGrid = new ObservableCollection<WmsRawOutstockDetail>();
@ -181,43 +154,108 @@ namespace SlnMesnac.WPF.ViewModel
/// </summary> /// </summary>
public RelayCommand<object> QueryCommand { get; set; } public RelayCommand<object> QueryCommand { get; set; }
public RelayCommand<string> DeletePalletCommand { get;set; }
public RelayCommand<string> DeleteBarCodeCommand { get; set; } public RelayCommand<string> DeleteBarCodeCommand { get; set; }
#endregion #endregion
#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
///// <summary> #region 原材料出库记录及图表
///// 刷新条码队列信息 /// <summary>
///// </summary> /// 刷新原材料出库记录
///// <param name="barCodeTasks"></param> /// </summary>
//private void RefreshBarCodeTaskDataGrid(List<RealBarCodeTask> barCodeTasks) private async Task RefreshWmsRawOutstockDetailDataGrid(DateTime beginDate, DateTime endDate)
//{ {
// BarCodeTaskDataGrid = new ObservableCollection<RealBarCodeTask>(); List<WmsRawOutstockDetail> list;
// foreach (var task in barCodeTasks)
// { list = await sqlClient.AsTenant().GetConnection("mes").Queryable<WmsRawOutstockDetail>().Where(x => x.WarehouseId == 311 && x.OutstockTime >= beginDate && x.OutstockTime <= endDate).OrderByDescending(t => t.OutstockTime).ToListAsync();
// BarCodeTaskDataGrid.Add(task);
// } 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>
/// 移除托盘队列信息 /// 刷新原材料出库图表
/// </summary> /// </summary>
/// <param name="palletCode"></param> /// <param name="list"></param>
private void DeletePallet(string palletCode) private void RefreshWmsRawOutstockDetailChart(List<WmsRawOutstockDetail> list)
{ {
_palletStowBusiness.RemovePalletInfo(palletCode); 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
///// <summary>
///// 移除小包条码队列信息
///// </summary>
///// <param name="barCode"></param>
//private void DeleteBarCode(string barCode)
//{
// _prodCompletionBusiness.RemoveBarCode(barCode);
//}
} }
} }

Loading…
Cancel
Save