diff --git a/SlnMesnac.WPF/Page/ProdStatisticsPage.xaml b/SlnMesnac.WPF/Page/ProdStatisticsPage.xaml index 5493fd7..dc4f176 100644 --- a/SlnMesnac.WPF/Page/ProdStatisticsPage.xaml +++ b/SlnMesnac.WPF/Page/ProdStatisticsPage.xaml @@ -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 @@ @@ -177,7 +178,32 @@ Foreground="#FFFFFF" > - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SlnMesnac.WPF/ViewModel/ProdMgmtViewModel.cs b/SlnMesnac.WPF/ViewModel/ProdMgmtViewModel.cs index f917700..765eb06 100644 --- a/SlnMesnac.WPF/ViewModel/ProdMgmtViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/ProdMgmtViewModel.cs @@ -54,6 +54,33 @@ namespace SlnMesnac.WPF.ViewModel #region 参数定义 + + #region 日产量柱状图X轴日期 + /// + /// 日产量柱状图X轴日期 + /// + private List productionHourList = new List(); + + public List ProductionHourList + { + get { return productionHourList; } + set { productionHourList = value; } + } + #endregion + + #region 型号统计柱状图 + /// + /// 型号统计柱状图 + /// + private SeriesCollection achievement = new SeriesCollection(); + + public SeriesCollection Achievement + { + get { return achievement; } + set { achievement = value; } + } + #endregion + /// /// 工位名称 /// @@ -167,31 +194,7 @@ namespace SlnMesnac.WPF.ViewModel #endregion - #region 日产量柱状图X轴日期 - /// - /// 日产量柱状图X轴日期 - /// - private List productionHourList = new List(); - - public List ProductionHourList - { - get { return productionHourList; } - set { productionHourList = value; } - } - #endregion - - #region 型号统计柱状图 - /// - /// 型号统计柱状图 - /// - private SeriesCollection achievement = new SeriesCollection(); - - public SeriesCollection Achievement - { - get { return achievement; } - set { achievement = value; } - } - #endregion + #region 事件定义 diff --git a/SlnMesnac.WPF/ViewModel/ProdStatisticsViewModel.cs b/SlnMesnac.WPF/ViewModel/ProdStatisticsViewModel.cs index 224ec54..c22d281 100644 --- a/SlnMesnac.WPF/ViewModel/ProdStatisticsViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/ProdStatisticsViewModel.cs @@ -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(); _prodCompletionBusiness = App.ServiceProvider.GetService(); sqlClient = App.ServiceProvider.GetService(); - QueryCommand = new RelayCommand(obj => Query(obj)); - DeletePalletCommand = new RelayCommand(DeletePallet); + QueryCommand = new RelayCommand(obj => Query()); + BeginDate = DateTime.Now.AddDays(-3); EndDate = DateTime.Now; - + Query(); } + #region 参数定义 + #region 日产量柱状图X轴日期 + /// + /// 日产量柱状图X轴日期 + /// + private List outDayList = new List(); - #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 OutDayList + { + get { return outDayList; } + set { outDayList = value; } } #endregion - + #region 型号统计柱状图 /// - /// 刷新原材料出库记录及图表 + /// 投料日产量统计柱状图 /// - private async Task RefreshWmsRawOutstockDetailDataGrid(DateTime beginDate, DateTime endDate) - { - List list; - - list = await sqlClient.AsTenant().GetConnection("mes").Queryable().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 /// - /// 托盘队列DataGrid + /// 原材料投料明细DataGrid /// private ObservableCollection wmsRawOutstockDetailDataGrid = new ObservableCollection(); @@ -181,43 +154,108 @@ namespace SlnMesnac.WPF.ViewModel /// public RelayCommand QueryCommand { get; set; } - public RelayCommand DeletePalletCommand { get;set; } public RelayCommand DeleteBarCodeCommand { get; set; } #endregion - - - ///// - ///// 刷新条码队列信息 - ///// - ///// - //private void RefreshBarCodeTaskDataGrid(List barCodeTasks) - //{ - // BarCodeTaskDataGrid = new ObservableCollection(); - // 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 原材料出库记录及图表 /// - /// 移除托盘队列信息 + /// 刷新原材料出库记录 /// - /// - private void DeletePallet(string palletCode) + private async Task RefreshWmsRawOutstockDetailDataGrid(DateTime beginDate, DateTime endDate) { - _palletStowBusiness.RemovePalletInfo(palletCode); + List list; + + list = await sqlClient.AsTenant().GetConnection("mes").Queryable().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); + } } - ///// - ///// 移除小包条码队列信息 - ///// - ///// - //private void DeleteBarCode(string barCode) - //{ - // _prodCompletionBusiness.RemoveBarCode(barCode); - //} + /// + /// 刷新原材料出库图表 + /// + /// + private void RefreshWmsRawOutstockDetailChart(List list) + { + App.Current.Dispatcher.BeginInvoke((Action)(() => + { + OutAchievement.Clear(); + OutDayList.Clear(); + ChartValues achievement = new ChartValues(); + 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 + + } }