DataPageViewModel.cs 18 KB

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