| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480 |
- using OxyPlot;
- using OxyPlot.Axes;
- using OxyPlot.Legends;
- using OxyPlot.Series;
- using Prism.Commands;
- using Prism.Ioc;
- using Prism.Mvvm;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows.Documents;
- using TeamAAS_VP.Core;
- using TeamAAS_VP.Data;
- using TeamAAS_VP.Interfaces;
- using TeamAAS_VP.Models;
- using TeamAAS_VP.Resources.Languages;
- using TeamAAS_VP.Services;
- using static MaterialDesignThemes.Wpf.Theme.ToolBar;
- namespace TeamAAS_VP.ViewModels.Statistics
- {
- public class ProductionStatementViewModel : BindableBase
- {
- IContainerProvider _container;
- ISystemDatabaseService _systemDatabaseService;
- IProductService _productService;
- Management management;
- #region 属性
- private Int64 _TotalCount;
- /// <summary>
- /// 总产能
- /// </summary>
- public Int64 TotalCount
- {
- get { return _TotalCount; }
- set { SetProperty(ref _TotalCount, value); }
- }
- private Int64 _MonthCount;
- /// <summary>
- /// 月产能
- /// </summary>
- public Int64 MonthCount
- {
- get { return _MonthCount; }
- set { SetProperty(ref _MonthCount, value); }
- }
- private Int64 _WeekCount;
- /// <summary>
- /// 周产能
- /// </summary>
- public Int64 WeekCount
- {
- get { return _WeekCount; }
- set { SetProperty(ref _WeekCount, value); }
- }
- private Int64 _DayCount;
- /// <summary>
- /// 日产能
- /// </summary>
- public Int64 DayCount
- {
- get { return _DayCount; }
- set { SetProperty(ref _DayCount, value); }
- }
- private PlotModel _YieldChartModel;
- /// <summary>
- /// 良率图表Model的mvvm属性,可通知UI更新
- /// </summary>
- public PlotModel YieldChartModel
- {
- get { return _YieldChartModel; }
- set { SetProperty(ref _YieldChartModel, value); }
- }
- private PlotModel _MonthChartModel;
- /// <summary>
- /// 月产能
- /// </summary>
- public PlotModel MonthChartModel
- {
- get { return _MonthChartModel; }
- set { SetProperty(ref _MonthChartModel, value); }
- }
- private PlotModel _WeekChartModel;
- /// <summary>
- /// 周产能
- /// </summary>
- public PlotModel WeekChartModel
- {
- get { return _WeekChartModel; }
- set { SetProperty(ref _WeekChartModel, value); }
- }
- private PlotModel _DayChartModel;
- /// <summary>
- /// 日产能
- /// </summary>
- public PlotModel DayChartModel
- {
- get { return _DayChartModel; }
- set { SetProperty(ref _DayChartModel, value); }
- }
- #endregion
- #region 命令
- private DelegateCommand _LoadedCommand;
- public DelegateCommand LoadedCommand =>
- _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
- #endregion
- #region 事件
- #endregion
- public ProductionStatementViewModel(IContainerProvider container, ISystemDatabaseService systemDatabaseService, IProductService productService)
- {
- _container = container;
- _systemDatabaseService = systemDatabaseService;
- _productService = productService;
- }
- #region 方法
- async void ExecuteLoadedCommand()
- {
- var currentproduct = _productService.GetCurrentProduct();
- if (currentproduct == null) return;
- await App.Current.Dispatcher.InvokeAsync(new Action(async () =>
- {
- YieldChartModel = CreateYieldChartModel(await _systemDatabaseService.GetProductionByCategoriesAsync(currentproduct.Name));
- TotalCount = await _systemDatabaseService.GetOverallProductionAsync(currentproduct.Name);
- MonthCount = await _systemDatabaseService.GetCurrentMonthProductionAsync(currentproduct.Name);
- WeekCount = await _systemDatabaseService.GetCurrentWeekProductionAsync(currentproduct.Name);
- DayCount = await _systemDatabaseService.GetTodayProductionAsync(currentproduct.Name);
- MonthChartModel = CreateMonth(await _systemDatabaseService.GetMonthlyProductionByDayAndCategoryAsync(currentproduct.Name));
- WeekChartModel = CreateWeek(await _systemDatabaseService.GetWeeklyProductionByDayAndCategoryAsync(currentproduct.Name));
- DayChartModel = CreateDay(await _systemDatabaseService.GetDailyProductionByHourAndCategoryAsync(currentproduct.Name));
- }));
- }
- /// <summary>
- /// 创建产量图表模型
- /// </summary>
- /// <returns></returns>
- private PlotModel CreateYieldChartModel(Dictionary<string, int> Items)
- {
- List<PieSlice> PieSlices = new List<PieSlice>();
- PieSlices = new List<PieSlice>();
- foreach (var item in Items)
- {
- PieSlices.Add(new PieSlice(item.Key, (double)item.Value));
- }
- var model = new PlotModel { Title = Lang.产能统计 };
- var series = new PieSeries
- {
- StrokeThickness = 1.0,
- InsideLabelPosition = 0.5,
- AngleSpan = 360,
- StartAngle = 0
- };
- foreach (var slice in PieSlices)
- {
- series.Slices.Add(slice);
- }
- model.Series.Add(series);
- return model;
- }
- /// <summary>
- /// 创建月统计模型
- /// </summary>
- /// <param name="Items"></param>
- /// <returns></returns>
- private PlotModel CreateMonth(Dictionary<DateTime, Dictionary<string, int>> Items)
- {
- var model = new PlotModel { Title = Lang.当前月产能统计 };
- // 添加图例说明
- model.Legends.Add(new Legend
- {
- LegendPlacement = LegendPlacement.Outside,
- LegendPosition = LegendPosition.RightMiddle,
- LegendOrientation = LegendOrientation.Vertical,
- LegendBorderThickness = 0,
- LegendTextColor = OxyColors.LightGray
- }); ;
- // 定义第一个Y轴y1,显示数量
- var ay1 = new LinearAxis()
- {
- Key = "y1",
- Title = Lang.数量,
- TitlePosition = 1,
- Minimum = 0,
- Position = AxisPosition.Left,
- IsZoomEnabled = false,
- IsPanEnabled = false,
- TickStyle = TickStyle.None,
- MinorTickSize = 0,
- MajorGridlineStyle = LineStyle.Solid,
- MajorGridlineColor = OxyColor.Parse("#F3F3F3"),
- };
- var now = DateTime.Now;
- var monthStart = DateTimeAxis.ToDouble(new DateTime(now.Year, now.Month, 1));
- var temp = new DateTime(now.Year, now.Month, 1);
- var monthEnd = DateTimeAxis.ToDouble(temp.AddMonths(1).AddDays(-1));
- // 定义X轴为日期轴
- //var minValue = DateTimeAxis.ToDouble(Items.Keys.ElementAt(0));
- //var maxValue = DateTimeAxis.ToDouble(Items.Keys.ElementAt(Items.Keys.Count - 1));
- var ax = new DateTimeAxis()
- {
- Minimum = monthStart,
- Maximum = monthEnd,
- StringFormat = $"dd{Lang.日}",
- MajorStep = 1,
- Position = AxisPosition.Bottom,
- Angle = 45,
- IsZoomEnabled = false,
- IsPanEnabled = false,
- TickStyle = TickStyle.None,
- MinorTickSize = 0,
- MajorGridlineStyle = LineStyle.Solid,
- MajorGridlineColor = OxyColor.Parse("#F3F3F3"),
- };
- model.Axes.Add(ay1);
- model.Axes.Add(ax);
- if (Items.Count <= 0)
- {
- return model;
- }
- foreach (var category in Items.First().Value.Keys)
- {
- var barSeries = new LinearBarSeries { Title = category };
- barSeries.YAxisKey = "y1";
- barSeries.BarWidth = 10;
- // 点击时弹出的label内容
- barSeries.TrackerFormatString = $"{0}\r\n{2:dd}{Lang.日}: {4:0}";
- foreach (var item in Items)
- {
- if (item.Value.ContainsKey(category))
- {
- barSeries.Points.Add(new OxyPlot.DataPoint(DateTimeAxis.ToDouble(item.Key), (double)(item.Value[category])));
- }
- else
- {
- barSeries.Points.Add(new OxyPlot.DataPoint(DateTimeAxis.ToDouble(item.Key), 0));
- }
- }
- model.Series.Add(barSeries);
- }
- var Series = new LineSeries { Title = Lang.总产量 };
- Series.YAxisKey = "y1";
- Series.TrackerFormatString = $"{0}\r\n{2:dd}{Lang.日}: {4:0}";
- foreach (var item in Items)
- {
- Int64 count = 0;
- foreach (var item1 in item.Value)
- {
- count += item1.Value;
- }
- Series.Points.Add(new OxyPlot.DataPoint(DateTimeAxis.ToDouble(item.Key), (double)count));
- }
- model.Series.Add(Series);
- return model;
- }
- /// <summary>
- /// 创建周统计模型
- /// </summary>
- /// <param name="Items"></param>
- /// <returns></returns>
- private PlotModel CreateWeek(Dictionary<int, Dictionary<string, int>> Items)
- {
- var model = new PlotModel { Title = Lang.当前周产能统计 };
- // 添加图例说明
- model.Legends.Add(new Legend
- {
- LegendPlacement = LegendPlacement.Outside,
- LegendPosition = LegendPosition.RightMiddle,
- LegendOrientation = LegendOrientation.Vertical,
- LegendBorderThickness = 0,
- LegendTextColor = OxyColors.LightGray
- });
- // 定义第一个Y轴y1,显示数量
- var ay1 = new LinearAxis()
- {
- Key = "y1",
- Title = Lang.数量,
- Minimum = 0,
- Position = AxisPosition.Left,
- IsZoomEnabled = false,
- IsPanEnabled = false,
- TickStyle = TickStyle.None,
- MinorTickSize = 0,
- MajorGridlineStyle = LineStyle.Solid,
- MajorGridlineColor = OxyColor.Parse("#F3F3F3"),
- };
- // 定义X轴为日期轴
- var ax = new LinearAxis()
- {
- Minimum = 0,
- Maximum = 7.5,
- MajorStep = 1,
- Position = AxisPosition.Bottom,
- StringFormat = $"{Lang.周} 0",
- Angle = 0,
- IsZoomEnabled = false,
- IsPanEnabled = false,
- TickStyle = TickStyle.None,
- MinorTickSize = 0,
- MajorGridlineStyle = LineStyle.Solid,
- MajorGridlineColor = OxyColor.Parse("#F3F3F3"),
- };
- model.Axes.Add(ay1);
- model.Axes.Add(ax);
- if (Items.Count <= 0)
- {
- return model;
- }
- foreach (var category in Items.First().Value.Keys)
- {
- var barSeries = new LinearBarSeries { Title = category };
- barSeries.YAxisKey = "y1";
- barSeries.BarWidth = 10;
- // 点击时弹出的label内容
- barSeries.TrackerFormatString = $"{0}\r\n{Lang.周}{2:0}: {4:0}";
- foreach (var item in Items)
- {
- if (item.Value.ContainsKey(category))
- {
- barSeries.Points.Add(new OxyPlot.DataPoint(DateTimeAxis.ToDouble(item.Key), (double)(item.Value[category])));
- }
- else
- {
- barSeries.Points.Add(new OxyPlot.DataPoint(DateTimeAxis.ToDouble(item.Key), 0));
- }
- }
- model.Series.Add(barSeries);
- }
- var Series = new LineSeries { Title = Lang.当前周产能统计 };
- Series.YAxisKey = "y1";
- Series.TrackerFormatString = $"{0}\r\n{2:dd}{Lang.日}: {4:0}";
- foreach (var item in Items)
- {
- Int64 count = 0;
- foreach (var item1 in item.Value)
- {
- count += item1.Value;
- }
- Series.Points.Add(new OxyPlot.DataPoint(DateTimeAxis.ToDouble(item.Key), (double)count));
- }
- model.Series.Add(Series);
- return model;
- }
- /// <summary>
- /// 创建日统计模型
- /// </summary>
- /// <param name="Items"></param>
- /// <returns></returns>
- private PlotModel CreateDay(Dictionary<int, Dictionary<string, int>> Items)
- {
- var model = new PlotModel { Title = Lang.当前日产能统计 };
- // 添加图例说明
- model.Legends.Add(new Legend
- {
- LegendPlacement = LegendPlacement.Outside,
- LegendPosition = LegendPosition.RightMiddle,
- LegendOrientation = LegendOrientation.Vertical,
- LegendBorderThickness = 0,
- LegendTextColor = OxyColors.LightGray
- });
- // 定义第一个Y轴y1,显示数量
- var ay1 = new LinearAxis()
- {
- Key = "y1",
- Title = $"{Lang.数量}",
- Minimum = 0,
- Position = AxisPosition.Left,
- IsZoomEnabled = false,
- IsPanEnabled = false,
- TickStyle = TickStyle.None,
- MinorTickSize = 0,
- MajorGridlineStyle = LineStyle.Solid,
- MajorGridlineColor = OxyColor.Parse("#F3F3F3"),
- };
- // 定义X轴为小时
- var ax = new LinearAxis()
- {
- Minimum = 0,
- Maximum = 24.5,
- MajorStep = 1,
- StringFormat = "0 H",
- Position = AxisPosition.Bottom,
- Angle = 0,
- IsZoomEnabled = false,
- IsPanEnabled = false,
- TickStyle = TickStyle.None,
- MinorTickSize = 0,
- MajorGridlineStyle = LineStyle.Solid,
- MajorGridlineColor = OxyColor.Parse("#F3F3F3"),
- };
- model.Axes.Add(ay1);
- model.Axes.Add(ax);
- if (Items.Count<=0)
- {
- return model;
- }
- foreach (var category in Items.First().Value.Keys)
- {
- var barSeries = new LinearBarSeries { Title = category };
- barSeries.YAxisKey = "y1";
- barSeries.BarWidth = 10;
- // 点击时弹出的label内容
- barSeries.TrackerFormatString = "{0}\r\n{2:0}Hours: {4:0}";
- foreach (var item in Items)
- {
- barSeries.Points.Add(new OxyPlot.DataPoint(LinearAxis.ToDouble(item.Key), (double)(item.Value[category])));
- }
- model.Series.Add(barSeries);
- }
- var Series = new LineSeries { Title = Lang.总产量 };
- Series.YAxisKey = "y1";
- Series.TrackerFormatString = $"{0}\r\n{2:dd}{Lang.小时}: {4:0}";
- foreach (var item in Items)
- {
- Int64 count = 0;
- foreach (var item1 in item.Value)
- {
- count += item1.Value;
- }
- Series.Points.Add(new OxyPlot.DataPoint(DateTimeAxis.ToDouble(item.Key), (double)count));
- }
- model.Series.Add(Series);
- return model;
- }
- #endregion
- }
- }
|