123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452 |
- 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;
- namespace LogoForceTestApp.Modules.MainModule.ViewModels
- {
- public class DataPageViewModel : BindableBase
- {
- IRepository _repository;
- public DelegateCommand ChartCommand { get; set; }
- public DateTime StartDate { get; set; }
- public DateTime EndDate { get; set; }
- public DataPageViewModel(IRepository repository)
- {
- _repository = repository;
- StartDate = DateTime.Today;
- EndDate = DateTime.Today;
- //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<string> x_yield = new List<string>();
- List<double> value1_yield = new List<double>();
- List<double> value2_yield = new List<double>();
- 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<AllNumber>(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<double> val1, List<double> val2, List<string> list)
- {
- SeriesYield[0].Values = val1;
- SeriesYield[1].Values = val2;
- XAxesYield[0].Labels = list;
- }
- public ISeries[] SeriesYield { get; set; } =
- {
- new LineSeries<double>
- {
- 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<double>
- {
- 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<string> x_Condition = new List<string>();
- List<double> value1_Condition = new List<double>();
- List<double> value2_Condition = new List<double>();
- List<double> value3_Condition = new List<double>();
- 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<AllNumber>(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<double> val1, List<double> val2, List<double> val3, List<string> list)
- {
- SeriesCondition[0].Values = val1;
- SeriesCondition[1].Values = val2;
- SeriesCondition[2].Values = val3;
- XAxesCondition[0].Labels = list;
- }
- public ISeries[] SeriesCondition { get; set; } =
- {
- new LineSeries<double>
- {
- 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<double>
- {
- 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<double>
- {
- 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<Quality>(c => c.DateQuality >= start && c.DateQuality <= endTime);
- 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];
- }
- SerQuality1(qua1);
- SerQuality2(qua2);
- SerQuality3(qua3);
- }
- }
- catch (Exception)
- {
- }
- }
- #region 生产问题
- public void SerQuality1(int[] val)
- {
- SeriesQuality1[0].Values = val;
- }
- public ISeries[] SeriesQuality1 { get; set; } = new ISeries[]
- {
- new ColumnSeries<int>
- {
- 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)
- {
- SeriesQuality2[0].Values = val;
- }
- public ISeries[] SeriesQuality2 { get; set; } = new ISeries[]
- {
- new ColumnSeries<int>
- {
- 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)
- {
- SeriesQuality3[0].Values = val;
- }
- public ISeries[] SeriesQuality3 { get; set; } = new ISeries[]
- {
- new ColumnSeries<int>
- {
- 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
- }
- }
|