DataPageViewModel.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. using AutoMapper;
  2. using HandyControl.Controls;
  3. using LiveChartsCore.SkiaSharpView.Painting;
  4. using LiveChartsCore.SkiaSharpView;
  5. using LiveChartsCore;
  6. using LogForceTestApp.Modules.MainModule.Models;
  7. using LogoForceTestApp.Modules.MainModule.Models;
  8. using Prism.Commands;
  9. using Prism.Mvvm;
  10. using Repository;
  11. using Repository.Entiies;
  12. using SkiaSharp;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using System.Threading.Tasks;
  17. using LiveChartsCore.Measure;
  18. using LiveChartsCore.SkiaSharpView.VisualElements;
  19. namespace LogoForceTestApp.Modules.MainModule.ViewModels
  20. {
  21. public class DataPageViewModel : BindableBase
  22. {
  23. IRepository _repository;
  24. public DelegateCommand ChartCommand { get; set; }
  25. public DateTime StartDate { get; set; }
  26. public DateTime EndDate { get; set; }
  27. public DataPageViewModel(IRepository repository)
  28. {
  29. _repository = repository;
  30. StartDate = DateTime.Today;
  31. EndDate = DateTime.Today;
  32. //ChartCommand = new DelegateCommand(async () =>
  33. //{
  34. // await ChartData();
  35. //});
  36. ChartCommand = new DelegateCommand(ChartData);
  37. }
  38. private void ChartData()//private async Task ChartData()
  39. {
  40. if (EndDate < StartDate || StartDate == default)
  41. {
  42. MessageBox.Show("请选择正确的日期", "提示");
  43. return;
  44. }
  45. Yield(StartDate, EndDate);
  46. Condition(StartDate, EndDate);
  47. Quality(StartDate, EndDate);
  48. }
  49. #region 产量
  50. List<string> x_yield = new List<string>();
  51. List<double> value1_yield = new List<double>();
  52. List<double> value2_yield = new List<double>();
  53. public void Yield(DateTime start, DateTime end)
  54. {
  55. try
  56. {
  57. value1_yield.Clear();
  58. value2_yield.Clear();
  59. x_yield.Clear();
  60. var endTime = end.AddDays(1);
  61. var list = _repository.GetAllQuery<AllNumber>(c => c.DateA >= start && c.DateA <= endTime);
  62. if (list != null)
  63. {
  64. for (int i = 0; i < list.Count; i++)
  65. {
  66. x_yield.Add(list[i].DateA.ToString("MM/dd"));
  67. value1_yield.Add(list[i].PlanA);
  68. value2_yield.Add(list[i].RealityA);
  69. }
  70. SerYield(value1_yield, value2_yield, x_yield);
  71. }
  72. }
  73. catch (Exception)
  74. {
  75. }
  76. }
  77. public void SerYield(List<double> val1, List<double> val2, List<string> list)
  78. {
  79. SeriesYield[0].Values = val1;
  80. SeriesYield[1].Values = val2;
  81. XAxesYield[0].Labels = list;
  82. }
  83. public ISeries[] SeriesYield { get; set; } =
  84. {
  85. new LineSeries<double>
  86. {
  87. Name = "计划产量",
  88. //Values = new []{ 4, 2, 8, 5, 3 },
  89. GeometrySize = 12,
  90. Stroke = new LinearGradientPaint(new[]{new SKColor(240, 155, 89)}) { StrokeThickness = 5 },
  91. GeometryStroke = new LinearGradientPaint(new[]{new SKColor(240, 155, 89) }) { StrokeThickness = 5 },
  92. Fill = null,
  93. ScalesYAt = 0
  94. //Fill = new SolidColorPaint(new SKColor(255, 212, 96, 90))
  95. },
  96. new LineSeries<double>
  97. {
  98. Name = "实际产量",
  99. GeometrySize = 12,
  100. Stroke = new LinearGradientPaint(new[]{new SKColor(62, 140, 38) }) { StrokeThickness = 5 },
  101. GeometryStroke = new LinearGradientPaint(new[]{new SKColor(62, 140, 38) }) { StrokeThickness = 5 },
  102. Fill = null,
  103. ScalesYAt = 1
  104. }
  105. };
  106. public DrawMarginFrame DrawMarginFrame => new()
  107. {
  108. Stroke = new SolidColorPaint(new SKColor(45, 64, 89), 2)
  109. };
  110. public Axis[] XAxesYield { get; set; } =
  111. {
  112. new Axis
  113. {
  114. //Labels = new string[] { "1","2" ,"3" ,"4" ,"5","6","7"},
  115. LabelsPaint = new SolidColorPaint(new SKColor(0, 0, 0)),
  116. LabelsRotation = 0,
  117. ForceStepToMin = true,
  118. MinLimit=0,
  119. MinStep = 1
  120. }
  121. };
  122. public Axis[] YAxesYield { get; set; } =
  123. {
  124. new Axis
  125. {
  126. Name = "计划产量",
  127. NameTextSize = 14,
  128. NamePaint = new SolidColorPaint(new SKColor(240, 155, 89)),
  129. LabelsPaint = new SolidColorPaint(new SKColor(0, 0, 0)),
  130. MinLimit=0,
  131. //最小步长
  132. //ForceStepToMin = true,
  133. //MinStep = 5
  134. },
  135. new Axis
  136. {
  137. Name = "实际产量",
  138. NameTextSize = 14,
  139. NamePaint = new SolidColorPaint(new SKColor(62, 140, 38)),
  140. LabelsPaint = new SolidColorPaint(new SKColor(0, 0, 0)),
  141. MinLimit=0,
  142. MaxLimit=150,
  143. Position = LiveChartsCore.Measure.AxisPosition.End
  144. }
  145. };
  146. #endregion
  147. #region 生产情况
  148. List<string> x_Condition = new List<string>();
  149. List<double> value1_Condition = new List<double>();
  150. List<double> value2_Condition = new List<double>();
  151. List<double> value3_Condition = new List<double>();
  152. public void Condition(DateTime start, DateTime end)
  153. {
  154. try
  155. {
  156. value1_Condition.Clear();
  157. value2_Condition.Clear();
  158. value3_Condition.Clear();
  159. x_Condition.Clear();
  160. var endTime = end.AddDays(1);
  161. var list = _repository.GetAllQuery<AllNumber>(c => c.DateA >= start && c.DateA <= endTime);
  162. if (list != null)
  163. {
  164. for (int i = 0; i < list.Count; i++)
  165. {
  166. x_Condition.Add(list[i].DateA.ToString("MM/dd"));
  167. value1_Condition.Add(list[i].OkA);
  168. value2_Condition.Add(list[i].NgA);
  169. value3_Condition.Add(list[i].ErrA);
  170. }
  171. SerCondition(value1_Condition, value2_Condition, value3_Condition, x_Condition);
  172. }
  173. }
  174. catch (Exception)
  175. {
  176. }
  177. }
  178. public void SerCondition(List<double> val1, List<double> val2, List<double> val3, List<string> list)
  179. {
  180. SeriesCondition[0].Values = val1;
  181. SeriesCondition[1].Values = val2;
  182. SeriesCondition[2].Values = val3;
  183. XAxesCondition[0].Labels = list;
  184. }
  185. public ISeries[] SeriesCondition { get; set; } =
  186. {
  187. new LineSeries<double>
  188. {
  189. Name = "OK数量",
  190. //Values = new []{ 4, 2, 8, 5, 3 },
  191. GeometrySize = 12,
  192. Stroke = new LinearGradientPaint(new[]{new SKColor(62, 140, 38)}) { StrokeThickness = 5 },
  193. GeometryStroke = new LinearGradientPaint(new[]{new SKColor(62, 140, 38) }) { StrokeThickness = 5 },
  194. Fill = null
  195. //Fill = new SolidColorPaint(new SKColor(255, 212, 96, 90))
  196. },
  197. new LineSeries<double>
  198. {
  199. Name = "NG数量",
  200. GeometrySize = 12,
  201. Stroke = new LinearGradientPaint(new[]{new SKColor(247, 169, 195) }) { StrokeThickness = 5 },
  202. GeometryStroke = new LinearGradientPaint(new[]{new SKColor(247, 169, 195) }) { StrokeThickness = 5 },
  203. Fill = null
  204. },
  205. new LineSeries<double>
  206. {
  207. Name = "维修数量",
  208. GeometrySize = 12,
  209. Stroke = new LinearGradientPaint(new[]{new SKColor(240, 155, 89) }) { StrokeThickness = 5 },
  210. GeometryStroke = new LinearGradientPaint(new[]{new SKColor(240, 155, 89) }) { StrokeThickness = 5 },
  211. Fill = null
  212. }
  213. };
  214. public DrawMarginFrame DrawMarginFrame1 => new()
  215. {
  216. Stroke = new SolidColorPaint(new SKColor(45, 64, 89), 2)
  217. };
  218. public Axis[] XAxesCondition { get; set; } =
  219. {
  220. new Axis
  221. {
  222. //Labels = new string[] { "1","2" ,"3" ,"4" ,"5","6","7"},
  223. LabelsPaint = new SolidColorPaint(new SKColor(0, 0, 0)),
  224. LabelsRotation = 0,
  225. ForceStepToMin = true,
  226. MinLimit=0,
  227. MinStep = 1
  228. }
  229. };
  230. public Axis[] YAxesCondition { get; set; } =
  231. {
  232. new Axis
  233. {
  234. Name = "数量",
  235. NameTextSize = 14,
  236. NamePaint = new SolidColorPaint(new SKColor(45, 64, 89)),
  237. LabelsPaint = new SolidColorPaint(new SKColor(0, 0, 0)),
  238. MinLimit=0,
  239. }
  240. };
  241. #endregion
  242. #region 质量
  243. int[] qua1; int[] qua2; int[] qua3;
  244. public void Quality(DateTime start,DateTime end)
  245. {
  246. try
  247. {
  248. qua1 = new int[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  249. qua2 = new int[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  250. qua3 = new int[10] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  251. var endTime = end.AddDays(1);
  252. var list = _repository.GetAllQuery<Quality>(c => c.DateQuality >= start && c.DateQuality <= endTime);
  253. if (list != null)
  254. {
  255. for (int i = 0; i < list.Count; i++)
  256. {
  257. qua1[0] = list[i].Q1 + qua1[0]; qua1[1] = list[i].Q2 + qua1[1];
  258. qua1[2] = list[i].Q3 + qua1[2]; qua1[3] = list[i].Q4 + qua1[3];
  259. qua1[4] = list[i].Q5 + qua1[4]; qua1[5] = list[i].Q6 + qua1[5];
  260. qua1[6] = list[i].Q7 + qua1[6]; qua1[7] = list[i].Q8 + qua1[7];
  261. qua1[8] = list[i].Q9 + qua1[8]; qua1[9] = list[i].Q10 + qua1[9];
  262. qua2[0] = list[i].Q11 + qua2[0]; qua2[1] = list[i].Q12 + qua2[1];
  263. qua2[2] = list[i].Q13 + qua2[2]; qua2[3] = list[i].Q14 + qua2[3];
  264. qua2[4] = list[i].Q15 + qua2[4]; qua2[5] = list[i].Q16 + qua2[5];
  265. qua2[6] = list[i].Q17 + qua2[6]; qua2[7] = list[i].Q18 + qua2[7];
  266. qua2[8] = list[i].Q19 + qua2[8]; qua2[9] = list[i].Q20 + qua2[9];
  267. qua3[0] = list[i].Q21 + qua3[0]; qua3[1] = list[i].Q22 + qua3[1];
  268. qua3[2] = list[i].Q23 + qua3[2]; qua3[3] = list[i].Q24 + qua3[3];
  269. qua3[4] = list[i].Q25 + qua3[4]; qua3[5] = list[i].Q26 + qua3[5];
  270. qua3[6] = list[i].Q27 + qua3[6]; qua3[7] = list[i].Q28 + qua3[7];
  271. qua3[8] = list[i].Q29 + qua3[8]; qua3[9] = list[i].Q30 + qua3[9];
  272. }
  273. SerQuality1(qua1);
  274. SerQuality2(qua2);
  275. SerQuality3(qua3);
  276. }
  277. }
  278. catch (Exception)
  279. {
  280. }
  281. }
  282. #region 生产问题
  283. public void SerQuality1(int[] val)
  284. {
  285. SeriesQuality1[0].Values = val;
  286. }
  287. public ISeries[] SeriesQuality1 { get; set; } = new ISeries[]
  288. {
  289. new ColumnSeries<int>
  290. {
  291. Name = "数量",
  292. Stroke = null,
  293. DataLabelsPaint = new SolidColorPaint(new SKColor(180, 180, 180)),
  294. DataLabelsPosition = DataLabelsPosition.Top,
  295. Padding = 3,//每个条之间的距离
  296. Fill = new LinearGradientPaint(new[]{new SKColor(255, 140, 148), new SKColor(220, 237, 194) })
  297. }
  298. };
  299. public LabelVisual Title1 { get; set; } =
  300. new LabelVisual
  301. {
  302. Text = "生产问题",
  303. TextSize = 14,
  304. Padding = new LiveChartsCore.Drawing.Padding(15),
  305. Paint = new SolidColorPaint(SKColors.DarkSlateGray)
  306. };
  307. public Axis[] XAxes1 { get; set; } =
  308. {
  309. new Axis
  310. {
  311. Labels = new string[] { "螺丝未上紧","3D人脸无效" ,"螺丝漏打" ,"显示屏幕漏光" ,"胶体未打好",
  312. "对讲喇叭无声","执手过于松紧" ,"螺丝打变形" ,"理线错乱" ,"弹簧未装好" },
  313. LabelsPaint = new SolidColorPaint(new SKColor(0, 0, 0)),
  314. LabelsRotation = 90,
  315. TextSize = 12,
  316. ForceStepToMin = true,
  317. MinStep = 1
  318. }
  319. };
  320. public Axis[] YAxes1 { get; set; } =
  321. {
  322. new Axis
  323. {
  324. LabelsPaint = new SolidColorPaint(new SKColor(0, 0, 0)),
  325. MinLimit=0,
  326. }
  327. };
  328. #endregion
  329. #region 工艺问题
  330. public void SerQuality2(int[] val)
  331. {
  332. SeriesQuality2[0].Values = val;
  333. }
  334. public ISeries[] SeriesQuality2 { get; set; } = new ISeries[]
  335. {
  336. new ColumnSeries<int>
  337. {
  338. Name = "数量",
  339. Stroke = null,
  340. DataLabelsPaint = new SolidColorPaint(new SKColor(180, 180, 180)),
  341. DataLabelsPosition = DataLabelsPosition.Top,
  342. Padding = 3,//每个条之间的距离
  343. Fill = new LinearGradientPaint(new[]{new SKColor(255, 140, 148), new SKColor(220, 237, 194) })
  344. }
  345. };
  346. public LabelVisual Title2 { get; set; } =
  347. new LabelVisual
  348. {
  349. Text = "工艺问题",
  350. TextSize = 14,
  351. Padding = new LiveChartsCore.Drawing.Padding(15),
  352. Paint = new SolidColorPaint(SKColors.DarkSlateGray)
  353. };
  354. public Axis[] XAxes2 { get; set; } =
  355. {
  356. new Axis
  357. {
  358. Labels = new string[] {"对讲无声","执手问题" ,"壳体脚位不平衡" ,"前板锁芯两孔位不一致" ,"后板显示屏水印",
  359. "电池异常耗电","喷漆过厚导致组装困难" ,"设计线路太长" ,"执手靠垫片改善" ,"锁芯顶杆没固定位置"},
  360. LabelsPaint = new SolidColorPaint(new SKColor(0, 0, 0)),
  361. LabelsRotation = 90,
  362. TextSize = 12,
  363. ForceStepToMin = true,
  364. MinStep = 1
  365. }
  366. };
  367. public Axis[] YAxes2 { get; set; } =
  368. {
  369. new Axis
  370. {
  371. LabelsPaint = new SolidColorPaint(new SKColor(0, 0, 0)),
  372. MinLimit=0,
  373. }
  374. };
  375. #endregion
  376. #region 物料问题
  377. public void SerQuality3(int[] val)
  378. {
  379. SeriesQuality3[0].Values = val;
  380. }
  381. public ISeries[] SeriesQuality3 { get; set; } = new ISeries[]
  382. {
  383. new ColumnSeries<int>
  384. {
  385. Name = "数量",
  386. Stroke = null,
  387. DataLabelsPaint = new SolidColorPaint(new SKColor(180, 180, 180)),
  388. DataLabelsPosition = DataLabelsPosition.Top,
  389. Padding = 3,//每个条之间的距离
  390. Fill = new LinearGradientPaint(new[]{new SKColor(255, 140, 148), new SKColor(220, 237, 194) })
  391. }
  392. };
  393. public LabelVisual Title3 { get; set; } =
  394. new LabelVisual
  395. {
  396. Text = "物料问题",
  397. TextSize = 14,
  398. Padding = new LiveChartsCore.Drawing.Padding(15),
  399. Paint = new SolidColorPaint(SKColors.DarkSlateGray)
  400. };
  401. public Axis[] XAxes3 { get; set; } =
  402. {
  403. new Axis
  404. {
  405. Labels = new string[] {"面板变形","电机异常" ,"屏幕异常" ,"物料毛刺" ,"大屏上支架变形",
  406. "壳料划痕","显示屏水印" , "壳体脚位不平横" ,"装饰圈气泡脱皮" ,"电池异常"},
  407. LabelsPaint = new SolidColorPaint(new SKColor(0, 0, 0)),
  408. LabelsRotation = 90,
  409. TextSize = 12,
  410. ForceStepToMin = true,
  411. MinStep = 1
  412. }
  413. };
  414. public Axis[] YAxes3 { get; set; } =
  415. {
  416. new Axis
  417. {
  418. LabelsPaint = new SolidColorPaint(new SKColor(0, 0, 0)),
  419. MinLimit=0,
  420. }
  421. };
  422. #endregion
  423. #endregion
  424. }
  425. }