using AutoMapper; using HandyControl.Controls; using LiveChartsCore.SkiaSharpView.Painting; using LiveChartsCore.SkiaSharpView; using LiveChartsCore; using LogForceTestApp.Modules.MainModule.Models; using LogoForceTestApp.Modules.MainModule.Models; using Prism.Commands; using Prism.Mvvm; using Repository; using Repository.Entiies; using SkiaSharp; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using LiveChartsCore.Measure; using LiveChartsCore.SkiaSharpView.VisualElements; using System.Collections.ObjectModel; using LogoForceTestApp.Modules.MainModule.Method; using Prism.Ioc; namespace LogoForceTestApp.Modules.MainModule.ViewModels { public class DataPageViewModel : BindableBase { IRepository _repository; IContainerProvider _container; public string BillNo { get; set; } public DelegateCommand ChartCommand { get; set; } public DateTime StartDate { get; set; } public DateTime EndDate { get; set; } private MulProductModel _Products; public MulProductModel Products { get { return _Products; } set { SetProperty(ref _Products, value); } } private ObservableCollection _ProductProblem = new ObservableCollection(); public ObservableCollection ProductProblem { get { return _ProductProblem; } set { SetProperty(ref _ProductProblem, value); } } private ObservableCollection _ProcessProblem = new ObservableCollection(); public ObservableCollection ProcessProblem { get { return _ProcessProblem; } set { SetProperty(ref _ProcessProblem, value); } } private ObservableCollection _MaterialProblem = new ObservableCollection(); public ObservableCollection MaterialProblem { get { return _MaterialProblem; } set { SetProperty(ref _MaterialProblem, value); } } public DataPageViewModel(IRepository repository, IContainerProvider container) { _repository = repository; _container = container; StartDate = DateTime.Today; EndDate = DateTime.Today; Products = _container.Resolve(); if (Products == null) { Products = new MulProductModel(); } //ChartCommand = new DelegateCommand(async () => //{ // await ChartData(); //}); ChartCommand = new DelegateCommand(ChartData); } private void ChartData()//private async Task ChartData() { if (EndDate < StartDate || StartDate == default) { MessageBox.Show("请选择正确的日期", "提示"); return; } Yield(StartDate, EndDate); Condition(StartDate, EndDate); Quality(StartDate, EndDate); } #region 产量 List x_yield = new List(); List value1_yield = new List(); List value2_yield = new List(); public void Yield(DateTime start, DateTime end) { try { value1_yield.Clear(); value2_yield.Clear(); x_yield.Clear(); var endTime = end.AddDays(1); var list = _repository.GetAllQuery(c => c.DateA >= start && c.DateA <= endTime); if (list != null) { for (int i = 0; i < list.Count; i++) { x_yield.Add(list[i].DateA.ToString("MM/dd")); value1_yield.Add(list[i].PlanA); value2_yield.Add(list[i].RealityA); } SerYield(value1_yield, value2_yield, x_yield); } } catch (Exception) { } } public void SerYield(List val1, List val2, List list) { SeriesYield[0].Values = val1; SeriesYield[1].Values = val2; XAxesYield[0].Labels = list; } public ISeries[] SeriesYield { get; set; } = { new LineSeries { Name = "计划产量", //Values = new []{ 4, 2, 8, 5, 3 }, GeometrySize = 12, Stroke = new LinearGradientPaint(new[]{new SKColor(240, 155, 89)}) { StrokeThickness = 5 }, GeometryStroke = new LinearGradientPaint(new[]{new SKColor(240, 155, 89) }) { StrokeThickness = 5 }, Fill = null, ScalesYAt = 0 //Fill = new SolidColorPaint(new SKColor(255, 212, 96, 90)) }, new LineSeries { Name = "实际产量", GeometrySize = 12, Stroke = new LinearGradientPaint(new[]{new SKColor(62, 140, 38) }) { StrokeThickness = 5 }, GeometryStroke = new LinearGradientPaint(new[]{new SKColor(62, 140, 38) }) { StrokeThickness = 5 }, Fill = null, ScalesYAt = 1 } }; public DrawMarginFrame DrawMarginFrame => new() { Stroke = new SolidColorPaint(new SKColor(45, 64, 89), 2) }; public Axis[] XAxesYield { get; set; } = { new Axis { //Labels = new string[] { "1","2" ,"3" ,"4" ,"5","6","7"}, LabelsPaint = new SolidColorPaint(new SKColor(0, 0, 0)), LabelsRotation = 0, ForceStepToMin = true, MinLimit=0, MinStep = 1 } }; public Axis[] YAxesYield { get; set; } = { new Axis { Name = "计划产量", NameTextSize = 14, NamePaint = new SolidColorPaint(new SKColor(240, 155, 89)), LabelsPaint = new SolidColorPaint(new SKColor(0, 0, 0)), MinLimit=0, //最小步长 //ForceStepToMin = true, //MinStep = 5 }, new Axis { Name = "实际产量", NameTextSize = 14, NamePaint = new SolidColorPaint(new SKColor(62, 140, 38)), LabelsPaint = new SolidColorPaint(new SKColor(0, 0, 0)), MinLimit=0, MaxLimit=150, Position = LiveChartsCore.Measure.AxisPosition.End } }; #endregion #region 生产情况 List x_Condition = new List(); List value1_Condition = new List(); List value2_Condition = new List(); List value3_Condition = new List(); public void Condition(DateTime start, DateTime end) { try { value1_Condition.Clear(); value2_Condition.Clear(); value3_Condition.Clear(); x_Condition.Clear(); var endTime = end.AddDays(1); var list = _repository.GetAllQuery(c => c.DateA >= start && c.DateA <= endTime); if (list != null) { for (int i = 0; i < list.Count; i++) { x_Condition.Add(list[i].DateA.ToString("MM/dd")); value1_Condition.Add(list[i].OkA); value2_Condition.Add(list[i].NgA); value3_Condition.Add(list[i].ErrA); } SerCondition(value1_Condition, value2_Condition, value3_Condition, x_Condition); } } catch (Exception) { } } public void SerCondition(List val1, List val2, List val3, List list) { SeriesCondition[0].Values = val1; SeriesCondition[1].Values = val2; SeriesCondition[2].Values = val3; XAxesCondition[0].Labels = list; } public ISeries[] SeriesCondition { get; set; } = { new LineSeries { Name = "OK数量", //Values = new []{ 4, 2, 8, 5, 3 }, GeometrySize = 12, Stroke = new LinearGradientPaint(new[]{new SKColor(62, 140, 38)}) { StrokeThickness = 5 }, GeometryStroke = new LinearGradientPaint(new[]{new SKColor(62, 140, 38) }) { StrokeThickness = 5 }, Fill = null //Fill = new SolidColorPaint(new SKColor(255, 212, 96, 90)) }, new LineSeries { Name = "NG数量", GeometrySize = 12, Stroke = new LinearGradientPaint(new[]{new SKColor(247, 169, 195) }) { StrokeThickness = 5 }, GeometryStroke = new LinearGradientPaint(new[]{new SKColor(247, 169, 195) }) { StrokeThickness = 5 }, Fill = null }, new LineSeries { Name = "维修数量", GeometrySize = 12, Stroke = new LinearGradientPaint(new[]{new SKColor(240, 155, 89) }) { StrokeThickness = 5 }, GeometryStroke = new LinearGradientPaint(new[]{new SKColor(240, 155, 89) }) { StrokeThickness = 5 }, Fill = null } }; public DrawMarginFrame DrawMarginFrame1 => new() { Stroke = new SolidColorPaint(new SKColor(45, 64, 89), 2) }; public Axis[] XAxesCondition { get; set; } = { new Axis { //Labels = new string[] { "1","2" ,"3" ,"4" ,"5","6","7"}, LabelsPaint = new SolidColorPaint(new SKColor(0, 0, 0)), LabelsRotation = 0, ForceStepToMin = true, MinLimit=0, MinStep = 1 } }; public Axis[] YAxesCondition { get; set; } = { new Axis { Name = "数量", NameTextSize = 14, NamePaint = new SolidColorPaint(new SKColor(45, 64, 89)), LabelsPaint = new SolidColorPaint(new SKColor(0, 0, 0)), MinLimit=0, } }; #endregion #region 质量 int[] qua1; int[] qua2; int[] qua3; public void Quality(DateTime start,DateTime end) { try { qua1 = new int[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; qua2 = new int[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; qua3 = new int[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; var endTime = end.AddDays(1); var list = _repository.GetAllQuery(c => c.ProTName==BillNo); if (list != null) { for (int i = 0; i < list.Count; i++) { qua1[0] = list[i].Q1 + qua1[0]; qua1[1] = list[i].Q2 + qua1[1]; qua1[2] = list[i].Q3 + qua1[2]; qua1[3] = list[i].Q4 + qua1[3]; qua1[4] = list[i].Q5 + qua1[4]; qua1[5] = list[i].Q6 + qua1[5]; qua1[6] = list[i].Q7 + qua1[6]; qua1[7] = list[i].Q8 + qua1[7]; qua1[8] = list[i].Q9 + qua1[8]; qua1[9] = list[i].Q10 + qua1[9]; qua2[0] = list[i].Q11 + qua2[0]; qua2[1] = list[i].Q12 + qua2[1]; qua2[2] = list[i].Q13 + qua2[2]; qua2[3] = list[i].Q14 + qua2[3]; qua2[4] = list[i].Q15 + qua2[4]; qua2[5] = list[i].Q16 + qua2[5]; qua2[6] = list[i].Q17 + qua2[6]; qua2[7] = list[i].Q18 + qua2[7]; qua2[8] = list[i].Q19 + qua2[8]; qua2[9] = list[i].Q20 + qua2[9]; qua3[0] = list[i].Q21 + qua3[0]; qua3[1] = list[i].Q22 + qua3[1]; qua3[2] = list[i].Q23 + qua3[2]; qua3[3] = list[i].Q24 + qua3[3]; qua3[4] = list[i].Q25 + qua3[4]; qua3[5] = list[i].Q26 + qua3[5]; qua3[6] = list[i].Q27 + qua3[6]; qua3[7] = list[i].Q28 + qua3[7]; qua3[8] = list[i].Q29 + qua3[8]; qua3[9] = list[i].Q30 + qua3[9]; } var res1 = Products.ProductCollection.FirstOrDefault(p => p.Name == GVariable.ProductTypeName); if (res1 != null) { ProductProblem = res1.QuestionType1; ProcessProblem = res1.QuestionType2; MaterialProblem = res1.QuestionType3; } SerQuality1(qua1, ProductProblem); SerQuality2(qua2, ProcessProblem); SerQuality3(qua3, MaterialProblem); } } catch (Exception) { } } #region 生产问题 public void SerQuality1(int[] val,ObservableCollection xlabel) { SeriesQuality1[0].Values = val; XAxes1[0].Labels = xlabel; } public ISeries[] SeriesQuality1 { get; set; } = new ISeries[] { new ColumnSeries { Name = "数量", Stroke = null, DataLabelsPaint = new SolidColorPaint(new SKColor(180, 180, 180)), DataLabelsPosition = DataLabelsPosition.Top, Padding = 3,//每个条之间的距离 Fill = new LinearGradientPaint(new[]{new SKColor(255, 140, 148), new SKColor(220, 237, 194) }) } }; public LabelVisual Title1 { get; set; } = new LabelVisual { Text = "生产问题", TextSize = 14, Padding = new LiveChartsCore.Drawing.Padding(15), Paint = new SolidColorPaint(SKColors.DarkSlateGray) }; public Axis[] XAxes1 { get; set; } = { new Axis { //Labels = new string[] { "螺丝未上紧","3D人脸无效" ,"螺丝漏打" ,"显示屏幕漏光" ,"胶体未打好", // "对讲喇叭无声","执手过于松紧" ,"螺丝打变形" ,"理线错乱" ,"弹簧未装好" }, LabelsPaint = new SolidColorPaint(new SKColor(0, 0, 0)), LabelsRotation = 90, TextSize = 12, ForceStepToMin = true, MinStep = 1 } }; public Axis[] YAxes1 { get; set; } = { new Axis { LabelsPaint = new SolidColorPaint(new SKColor(0, 0, 0)), MinLimit=0, } }; #endregion #region 工艺问题 public void SerQuality2(int[] val, ObservableCollection xlabel) { SeriesQuality2[0].Values = val; XAxes2[0].Labels = xlabel; } public ISeries[] SeriesQuality2 { get; set; } = new ISeries[] { new ColumnSeries { Name = "数量", Stroke = null, DataLabelsPaint = new SolidColorPaint(new SKColor(180, 180, 180)), DataLabelsPosition = DataLabelsPosition.Top, Padding = 3,//每个条之间的距离 Fill = new LinearGradientPaint(new[]{new SKColor(255, 140, 148), new SKColor(220, 237, 194) }) } }; public LabelVisual Title2 { get; set; } = new LabelVisual { Text = "工艺问题", TextSize = 14, Padding = new LiveChartsCore.Drawing.Padding(15), Paint = new SolidColorPaint(SKColors.DarkSlateGray) }; public Axis[] XAxes2 { get; set; } = { new Axis { //Labels = new string[] {"对讲无声","执手问题" ,"壳体脚位不平衡" ,"前板锁芯两孔位不一致" ,"后板显示屏水印", // "电池异常耗电","喷漆过厚导致组装困难" ,"设计线路太长" ,"执手靠垫片改善" ,"锁芯顶杆没固定位置"}, LabelsPaint = new SolidColorPaint(new SKColor(0, 0, 0)), LabelsRotation = 90, TextSize = 12, ForceStepToMin = true, MinStep = 1 } }; public Axis[] YAxes2 { get; set; } = { new Axis { LabelsPaint = new SolidColorPaint(new SKColor(0, 0, 0)), MinLimit=0, } }; #endregion #region 物料问题 public void SerQuality3(int[] val, ObservableCollection xlabel) { SeriesQuality3[0].Values = val; XAxes3[0].Labels = xlabel; } public ISeries[] SeriesQuality3 { get; set; } = new ISeries[] { new ColumnSeries { Name = "数量", Stroke = null, DataLabelsPaint = new SolidColorPaint(new SKColor(180, 180, 180)), DataLabelsPosition = DataLabelsPosition.Top, Padding = 3,//每个条之间的距离 Fill = new LinearGradientPaint(new[]{new SKColor(255, 140, 148), new SKColor(220, 237, 194) }) } }; public LabelVisual Title3 { get; set; } = new LabelVisual { Text = "物料问题", TextSize = 14, Padding = new LiveChartsCore.Drawing.Padding(15), Paint = new SolidColorPaint(SKColors.DarkSlateGray) }; public Axis[] XAxes3 { get; set; } = { new Axis { //Labels = new string[] {"面板变形","电机异常" ,"屏幕异常" ,"物料毛刺" ,"大屏上支架变形", // "壳料划痕","显示屏水印" , "壳体脚位不平横" ,"装饰圈气泡脱皮" ,"电池异常"}, LabelsPaint = new SolidColorPaint(new SKColor(0, 0, 0)), LabelsRotation = 90, TextSize = 12, ForceStepToMin = true, MinStep = 1 } }; public Axis[] YAxes3 { get; set; } = { new Axis { LabelsPaint = new SolidColorPaint(new SKColor(0, 0, 0)), MinLimit=0, } }; #endregion #endregion } }