KBWindowViewModel.cs 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074
  1. using LiveChartsCore.SkiaSharpView.Extensions;
  2. using LiveChartsCore;
  3. using LogoForceTestApp.Modules.MainModule.Models;
  4. using Prism.Events;
  5. using Prism.Mvvm;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Timers;
  10. using LiveChartsCore.SkiaSharpView.Painting;
  11. using SkiaSharp;
  12. using LiveChartsCore.Measure;
  13. using Repository;
  14. using Repository.Entiies;
  15. using LiveChartsCore.SkiaSharpView;
  16. using System.Collections.ObjectModel;
  17. using LiveChartsCore.SkiaSharpView.VisualElements;
  18. using LiveChartsCore.Defaults;
  19. using FontFamily = System.Windows.Media.FontFamily;
  20. using AutoMapper;
  21. using System.Windows;
  22. using ZXing.Maxicode;
  23. using System.Numerics;
  24. using System.Windows.Documents;
  25. using LiveChartsCore.ConditionalDraw;
  26. using LiveChartsCore.Themes;
  27. using System.Threading.Tasks;
  28. using System.Data.SqlTypes;
  29. using System.Threading;
  30. using Timer = System.Timers.Timer;
  31. namespace LogoForceTestApp.Modules.MainModule.ViewModels
  32. {
  33. public class KBWindowViewModel : BindableBase
  34. {
  35. #region
  36. IRepository repository;
  37. private readonly IEventAggregator _eventAggregator;
  38. public ObservableCollection<HouseDto> MyHouse { get; set; }
  39. private readonly IMapper _mapper;
  40. //private readonly List<House> _myHouse;
  41. private string timeNow = DateTime.Now.ToString();
  42. public string TimeNow
  43. {
  44. get => timeNow;
  45. set { SetProperty(ref timeNow, value); }
  46. }
  47. private System.Timers.Timer _timer;
  48. public IEnumerable<ISeries> Series { get; set; }
  49. int[] outwork = new int[3];
  50. public string TotalPer { get; set; }
  51. public string ActualPer { get; set; }
  52. public string FallIllPer { get; set; }
  53. public string AbsenPer { get; set; }
  54. #region 产量
  55. public string BillNo { get; set; }
  56. public double AuxQty { get; set; }
  57. public double Finished { get; set; }
  58. private double _finishRate;
  59. public double FinishRate
  60. {
  61. get { return (Finished / Convert.ToDouble(AuxQty)) * 100; }
  62. set { SetProperty(ref _finishRate, value); }
  63. }
  64. #endregion
  65. #region 灯
  66. public string ImgLight1 { get; set; }//1号机
  67. public string ImgLight2 { get; set; }
  68. public string ImgLight3 { get; set; }
  69. public string ImgLight4 { get; set; }
  70. public string ImgLight5 { get; set; }
  71. public string ImgLight6 { get; set; }
  72. public string ImgLight7 { get; set; }
  73. public string ImgLight8 { get; set; }
  74. public string ImgLight9 { get; set; }
  75. public string ImgLight10 { get; set; }
  76. public string ImgLight11 { get; set; }
  77. public string ImgLight12 { get; set; }
  78. public string ImgLight13 { get; set; }
  79. public string ImgLight14 { get; set; }
  80. public string ImgLight15 { get; set; }//螺丝机
  81. public string ImgLight16 { get; set; }
  82. public string ImgLight17 { get; set; }
  83. public string ImgLight18 { get; set; }
  84. public string ImgLight19 { get; set; }
  85. public string ImgLight20 { get; set; }
  86. public string ImgLight21 { get; set; }//提升机
  87. public string ImgLight22 { get; set; }//检测机
  88. public string ImgLight23 { get; set; }//返修机
  89. #endregion
  90. public double TotalNum { get; set; }
  91. public double PassNum { get; set; }
  92. public string FirstName { get; set; }
  93. public string SecondName { get; set; }
  94. public string ThirdName { get; set; }
  95. #endregion
  96. public KBWindowViewModel(IRepository repository, IEventAggregator eventAggregator, IMapper mapper)
  97. {
  98. this.repository = repository;
  99. this._eventAggregator = eventAggregator;
  100. Series = new List<ISeries>();
  101. #region timer
  102. _timer = new Timer();
  103. _timer.Interval = 1000;
  104. _timer.Elapsed += _timer_Elapsed;
  105. _timer.Start();
  106. #endregion
  107. #region chart显示文字
  108. string name = "微软雅黑";
  109. SKTypeface skTypeface = SKTypeface.FromFamilyName(name);
  110. if (skTypeface.FamilyName != name)
  111. {
  112. // 字体加载失败了
  113. skTypeface.Dispose();
  114. }
  115. FontFamily fontFamily = new(name);
  116. foreach (string familyNamesValue in fontFamily.FamilyNames.Values)
  117. {
  118. skTypeface = SKTypeface.FromFamilyName(familyNamesValue);
  119. if (skTypeface.FamilyName == familyNamesValue)
  120. break;
  121. else
  122. {
  123. skTypeface.Dispose();
  124. }
  125. }
  126. LiveChartsSkiaSharp.DefaultSKTypeface = skTypeface;
  127. #endregion
  128. _eventAggregator.GetEvent<AlarmEvent>().Subscribe(GetAlarmMessage);//接收另一个viewmodel的信息
  129. MyHouse = new ObservableCollection<HouseDto>();
  130. _mapper = mapper;
  131. _eventAggregator.GetEvent<OperatorNameEvent>().Subscribe(ShowPeope);
  132. _eventAggregator.GetEvent<QuestEvent>().Subscribe(ShowOrder);
  133. Task.Factory.StartNew(Main, TaskCreationOptions.LongRunning);
  134. }
  135. private void Main()
  136. {
  137. while (true)
  138. {
  139. try
  140. {
  141. ShowHouse();
  142. ShowQuality();
  143. ShowOutWork();
  144. AlarmOK();
  145. double d = Convert.ToDouble(((PassNum / TotalNum) * 100).ToString("0.00"));
  146. PassRate(d);
  147. ShowNowProcess();
  148. ShowProcess();
  149. }
  150. catch (ObjectDisposedException ex)
  151. {
  152. }
  153. finally
  154. {
  155. Thread.Sleep(5000);
  156. }
  157. }
  158. }
  159. private void _timer_Elapsed(object sender, ElapsedEventArgs e)
  160. {
  161. TimeNow = DateTime.Now.ToString();
  162. }
  163. #region 合格率
  164. public void PassRate(double passRate)
  165. {
  166. Series = GaugeGenerator.BuildSolidGauge(
  167. new GaugeItem(passRate, series =>
  168. {
  169. series.Fill = new SolidColorPaint(SKColors.YellowGreen);
  170. series.DataLabelsSize = 23;
  171. series.DataLabelsPaint = new SolidColorPaint(SKColors.LightPink);
  172. series.DataLabelsPosition = PolarLabelsPosition.ChartCenter;
  173. series.InnerRadius = 40;
  174. }),
  175. new GaugeItem(GaugeItem.Background, series =>
  176. {
  177. series.InnerRadius = 40;
  178. series.Fill = new SolidColorPaint(new SKColor(100, 181, 246, 90));
  179. }));
  180. }
  181. #endregion
  182. #region 出勤率
  183. public void ShowOutWork()
  184. {
  185. try
  186. {
  187. var list = repository.GetFirstDefault<OutofWork>(c => c.DateOutWork == DateTime.Today);
  188. if (list != null)
  189. {
  190. outwork[0] = list.Actual;
  191. outwork[1] = list.FallIll;
  192. outwork[2] = list.Absenteeism;
  193. int total = outwork[2] + outwork[1] + outwork[0];
  194. OutWork(outwork[2], outwork[1], outwork[0], total);
  195. string a = ((double)outwork[0] / (double)total).ToString("P");
  196. string b = ((double)outwork[1] / (double)total).ToString("P");
  197. string c = ((double)outwork[2] / (double)total).ToString("P");
  198. TotalPer = $"应到人数:{total}";
  199. ActualPer = $"实到人数:{outwork[0]}【{a}】";
  200. FallIllPer = $"请假人数:{outwork[1]}【{b}】";
  201. AbsenPer = $"旷工人数:{outwork[2]}【{c}】";
  202. }
  203. }
  204. catch (Exception ex)
  205. {
  206. }
  207. }
  208. public IEnumerable<ISeries> Series12 { get; set; }
  209. public double GaugeTotal12 { get; set; }
  210. public double InitialRotation12 { get; set; }
  211. public double MaxAngle12 { get; set; }
  212. /// <summary>
  213. /// "旷工人数","请假人数" ,"实到人数","应到人数"
  214. /// </summary>
  215. /// <param name="a"></param>
  216. /// <param name="b"></param>
  217. /// <param name="c"></param>
  218. /// <param name="d"></param>
  219. public void OutWork(int a, int b, int c, int d)
  220. {
  221. GaugeTotal12 = d;//最大数
  222. InitialRotation12 = 90;
  223. MaxAngle12 = 270;
  224. void SetStyle12(string name, PieSeries<ObservableValue> series)
  225. {
  226. series.Name = name;
  227. series.DataLabelsPosition = PolarLabelsPosition.Start;
  228. series.DataLabelsFormatter =
  229. point => $"{point.Context.Series.Name} {point.Coordinate.PrimaryValue}";
  230. series.DataLabelsSize = 16;
  231. series.InnerRadius = 20;
  232. series.RelativeInnerRadius = 4;
  233. series.RelativeOuterRadius = 4;
  234. series.DataLabelsPaint = new SolidColorPaint(new SKColor(150, 150, 150));
  235. }
  236. Series12 = GaugeGenerator.BuildSolidGauge(
  237. new GaugeItem(a, series => SetStyle12("旷工人数", series)),
  238. new GaugeItem(b, series => SetStyle12("请假人数", series)),
  239. new GaugeItem(c, series => SetStyle12("实到人数", series)),
  240. new GaugeItem(d, series => SetStyle12("应到人数", series)),
  241. new GaugeItem(GaugeItem.Background, series =>
  242. {
  243. series.InnerRadius = 20;
  244. series.RelativeInnerRadius = 10;
  245. series.RelativeOuterRadius = 10;
  246. }));
  247. }
  248. //public IEnumerable<ISeries> SeriesOutWork { get; set; }
  249. //private static int _index = 0;
  250. //private static string[] _names = new[] { "实到", "请假", "旷工" };
  251. //public void OutWork(int[] val)
  252. //{
  253. // SeriesOutWork = val.AsPieSeries((value, series) =>
  254. // {
  255. // series.Name = _names[_index++ % _names.Length];
  256. // series.DataLabelsPosition = LiveChartsCore.Measure.PolarLabelsPosition.Outer; // mark
  257. // series.DataLabelsSize = 10;
  258. // series.DataLabelsPaint = new SolidColorPaint(new SKColor(180, 180, 180));
  259. // //series.DataLabelsFormatter =
  260. // // point =>
  261. // // $"This slide takes {point.Coordinate.PrimaryValue} " +
  262. // // $"out of {point.StackedValue!.Total} parts";
  263. // //series.ToolTipLabelFormatter = point => $"{point.StackedValue!.Share:P2}";
  264. // series.ToolTipLabelFormatter =
  265. // point =>
  266. // {
  267. // var pv = point.Coordinate.PrimaryValue;
  268. // var sv = point.StackedValue!;
  269. // var a = $"{pv}/{sv.Total}{Environment.NewLine}{sv.Share:P2}";
  270. // return a;
  271. // };
  272. // series.DataLabelsFormatter =
  273. // point =>
  274. // {
  275. // var pv = point.Coordinate.PrimaryValue;
  276. // var sv = point.StackedValue!;
  277. // var a = $"{series.Name}{Environment.NewLine}{sv.Share:P2}";
  278. // return a;
  279. // };
  280. // });
  281. //}
  282. #endregion
  283. #region 质量
  284. int[] qua1 = new int[10]; int[] qua2 = new int[10]; int[] qua3 = new int[10];
  285. public void ShowQuality()
  286. {
  287. try
  288. {
  289. //string str = DateTime.Now.ToString("yyyy/MM/dd");
  290. DateTime dt = DateTime.Today;
  291. var list = repository.GetFirstDefault<Quality>(c => c.DateQuality == dt);
  292. if (list != null)
  293. {
  294. qua1[0] = list.Q1; qua1[1] = list.Q2; qua1[2] = list.Q3; qua1[3] = list.Q4; qua1[4] = list.Q5;
  295. qua1[5] = list.Q6; qua1[6] = list.Q7; qua1[7] = list.Q8; qua1[8] = list.Q9; qua1[9] = list.Q10;
  296. qua2[0] = list.Q11; qua2[1] = list.Q12; qua2[2] = list.Q13; qua2[3] = list.Q14; qua2[4] = list.Q15;
  297. qua2[5] = list.Q16; qua2[6] = list.Q17; qua2[7] = list.Q18; qua2[8] = list.Q19; qua2[9] = list.Q20;
  298. qua3[0] = list.Q21; qua3[1] = list.Q22; qua3[2] = list.Q23; qua3[3] = list.Q24; qua3[4] = list.Q25;
  299. qua3[5] = list.Q26; qua3[6] = list.Q27; qua3[7] = list.Q28; qua3[8] = list.Q29; qua3[9] = list.Q30;
  300. SerQuality1(qua1);
  301. SerQuality2(qua2);
  302. SerQuality3(qua3);
  303. }
  304. }
  305. catch (Exception)
  306. {
  307. }
  308. }
  309. #region 生产问题
  310. public void SerQuality1(int[] val)
  311. {
  312. SeriesQuality1[0].Values = val;
  313. }
  314. public ISeries[] SeriesQuality1 { get; set; } = new ISeries[]
  315. {
  316. new ColumnSeries<int>
  317. {
  318. Name = "数量",
  319. //Values = new[] {23, 27, 22, 29, 24 ,21,11,45,32,19},
  320. Stroke = null,
  321. DataLabelsPaint = new SolidColorPaint(new SKColor(180, 180, 180)),
  322. DataLabelsPosition = DataLabelsPosition.Top,
  323. Padding = 3,//每个条之间的距离
  324. //Fill = new LinearGradientPaint(
  325. // new [] { new SKColor(255, 140, 148), new SKColor(220, 237, 194) },
  326. // new SKPoint(0.5f, 0),
  327. // new SKPoint(0.5f, 1))
  328. Fill = new LinearGradientPaint(new[]{new SKColor(255, 140, 148), new SKColor(220, 237, 194) })
  329. }
  330. };
  331. public Axis[] XAxes1 { get; set; } =
  332. {
  333. new Axis
  334. {
  335. Labels = new string[] { "螺丝未上紧","3D人脸无效" ,"螺丝漏打" ,"显示屏幕漏光" ,"胶体未打好",
  336. "对讲喇叭无声","执手过于松紧" ,"螺丝打变形" ,"理线错乱" ,"弹簧未装好" },
  337. LabelsPaint = new SolidColorPaint(new SKColor(100, 100, 100)),
  338. LabelsRotation = 90,
  339. TextSize = 12,
  340. ForceStepToMin = true,
  341. MinStep = 1
  342. }
  343. };
  344. public Axis[] YAxes1 { get; set; } =
  345. {
  346. new Axis
  347. {
  348. LabelsPaint = new SolidColorPaint(new SKColor(100, 100, 100)),
  349. MinLimit=0,
  350. //最小步长
  351. //ForceStepToMin = true,
  352. //MinStep = 5
  353. }
  354. };
  355. #endregion
  356. #region 工艺问题
  357. public void SerQuality2(int[] val)
  358. {
  359. SeriesQuality2[0].Values = val;
  360. }
  361. public ISeries[] SeriesQuality2 { get; set; } = new ISeries[]
  362. {
  363. new ColumnSeries<int>
  364. {
  365. Name = "数量",
  366. //Values = new[] {23, 27, 22, 29, 24 ,21,11,45,32,19},
  367. Stroke = null,
  368. DataLabelsPaint = new SolidColorPaint(new SKColor(180, 180, 180)),
  369. DataLabelsPosition = DataLabelsPosition.Top,
  370. Padding = 3,//每个条之间的距离
  371. //Fill = new LinearGradientPaint(
  372. // new [] { new SKColor(255, 140, 148), new SKColor(220, 237, 194) },
  373. // new SKPoint(0.5f, 0),
  374. // new SKPoint(0.5f, 1))
  375. Fill = new LinearGradientPaint(new[]{new SKColor(255, 140, 148), new SKColor(220, 237, 194) })
  376. }
  377. };
  378. public Axis[] XAxes2 { get; set; } =
  379. {
  380. new Axis
  381. {
  382. Labels = new string[] {"对讲无声","执手问题" ,"壳体脚位不平衡" ,"前板锁芯两孔位不一致" ,"后板显示屏水印",
  383. "电池异常耗电","喷漆过厚导致组装困难" ,"设计线路太长" ,"执手靠垫片改善" ,"锁芯顶杆没固定位置"},
  384. LabelsPaint = new SolidColorPaint(new SKColor(100, 100, 100)),
  385. LabelsRotation = 90,
  386. TextSize = 12,
  387. ForceStepToMin = true,
  388. MinStep = 1
  389. }
  390. };
  391. public Axis[] YAxes2 { get; set; } =
  392. {
  393. new Axis
  394. {
  395. LabelsPaint = new SolidColorPaint(new SKColor(100, 100, 100)),
  396. MinLimit=0,
  397. //最小步长
  398. //ForceStepToMin = true,
  399. //MinStep = 5
  400. }
  401. };
  402. #endregion
  403. #region 物料问题
  404. public void SerQuality3(int[] val)
  405. {
  406. SeriesQuality3[0].Values = val;
  407. }
  408. public ISeries[] SeriesQuality3 { get; set; } = new ISeries[]
  409. {
  410. new ColumnSeries<int>
  411. {
  412. Name = "数量",
  413. //Values = new[] {23, 27, 22, 29, 24 ,21,11,45,32,19},
  414. Stroke = null,
  415. DataLabelsPaint = new SolidColorPaint(new SKColor(180, 180, 180)),
  416. DataLabelsPosition = DataLabelsPosition.Top,
  417. Padding = 3,//每个条之间的距离
  418. //Fill = new LinearGradientPaint(
  419. // new [] { new SKColor(255, 140, 148), new SKColor(220, 237, 194) },
  420. // new SKPoint(0.5f, 0),
  421. // new SKPoint(0.5f, 1))
  422. Fill = new LinearGradientPaint(new[]{new SKColor(255, 140, 148), new SKColor(220, 237, 194) })
  423. }
  424. };
  425. public Axis[] XAxes3 { get; set; } =
  426. {
  427. new Axis
  428. {
  429. Labels = new string[] {"面板变形","电机异常" ,"屏幕异常" ,"物料毛刺" ,"大屏上支架变形",
  430. "壳料划痕","显示屏水印" , "壳体脚位不平横" ,"装饰圈气泡脱皮" ,"电池异常"},
  431. LabelsPaint = new SolidColorPaint(new SKColor(100, 100, 100)),
  432. LabelsRotation = 90,
  433. TextSize = 12,
  434. ForceStepToMin = true,
  435. MinStep = 1
  436. }
  437. };
  438. public Axis[] YAxes3 { get; set; } =
  439. {
  440. new Axis
  441. {
  442. LabelsPaint = new SolidColorPaint(new SKColor(100, 100, 100)),
  443. MinLimit=0,
  444. //最小步长
  445. //ForceStepToMin = true,
  446. //MinStep = 5
  447. }
  448. };
  449. #endregion
  450. #endregion
  451. #region 人员管理
  452. //int nums;
  453. //private void ShowPeope(string opername)
  454. //{
  455. // var value = repository.GetAllQuery<Information>(c => c.OperatorCode == opername && c.CreateTime == DateTime.Today);
  456. // if (value.Count != 0)
  457. // {
  458. // nums = value.Count();
  459. // PerManagement(opername, nums);
  460. // }
  461. //}
  462. int[] nums = new int[30];
  463. private void ShowPeope(string[] opername)
  464. {
  465. PerManage = new List<Person>();
  466. PerManage1 = new List<Person>();
  467. PerManage2 = new List<Person>();
  468. for (int i = 0; i < opername.Length; i++)
  469. {
  470. if (opername[i] == null || string.IsNullOrEmpty(opername[i]))
  471. {
  472. continue;
  473. }
  474. var value = repository.GetAllQuery<Information>(c => c.OperatorCode == opername[i] && c.CreateTime == DateTime.Today);
  475. if (value.Count != 0)
  476. {
  477. nums[i] = value.Count();
  478. PerManagement(opername[i], nums[i]);
  479. }
  480. var num= repository.GetAllQuery<Information>(c => c.OperatorCode == opername[i] && c.CreateTime <= DateTime.Today&& c.CreateTime >= DateTime.Today.AddDays(-9));
  481. if (num.Count != 0)
  482. {
  483. nums[i] = value.Count();
  484. PerManagement2(opername[i], nums[i]);
  485. }
  486. }
  487. }
  488. public List<Person> PerManage { get; set; }
  489. private List<Person> PerManage1 { get; set; }
  490. private List<Person> PerManage2 { get; set; }
  491. public void PerManagement(string ename, int yield)
  492. {
  493. //PerManage = new List<Person>();//放在外面就累加,放这里就不累加一直刷
  494. PerManage1.Add(new Person { Id = new Guid(), EmployeeName = ename, Yield = yield });
  495. var m = PerManage1.OrderByDescending(x => x.Yield).ToList();//降序
  496. PerManage = m;
  497. //if (m.Count >= 3)
  498. //{
  499. // FirstName = PerManage[0].EmployeeName;
  500. // SecondName = PerManage[1].EmployeeName;
  501. // ThirdName = PerManage[2].EmployeeName;
  502. //}
  503. }
  504. public void PerManagement2(string ename, int yield)
  505. {
  506. PerManage2.Add(new Person { Id = new Guid(), EmployeeName = ename, Yield = yield });
  507. var m = PerManage2.OrderByDescending(x => x.Yield).ToList();//降序
  508. PerManage = m;
  509. if (m.Count >= 3)
  510. {
  511. FirstName = PerManage[0].EmployeeName;
  512. SecondName = PerManage[1].EmployeeName;
  513. ThirdName = PerManage[2].EmployeeName;
  514. }
  515. }
  516. #endregion
  517. #region 仓库
  518. public void ShowHouse()
  519. {
  520. try
  521. {
  522. //var list = repository.GetAllQuery<House>(c => c.DateH == str);//查一个集合
  523. var list = repository.GetFirstDefault<House>(c => c.DateH == DateTime.Today);
  524. if (list != null)
  525. {
  526. var dto = _mapper.Map<HouseDto>(list);
  527. Application.Current.Dispatcher.Invoke(new Action(() =>
  528. {
  529. MyHouse.Clear();
  530. MyHouse.Add(dto);
  531. SerHouse(double.Parse(list.LackH), double.Parse(list.UsedH), double.Parse(list.TotalH));
  532. }));
  533. }
  534. }
  535. catch (Exception ex)
  536. {
  537. }
  538. }
  539. public IEnumerable<ISeries> Series13 { get; set; }
  540. public double GaugeTotal13 { get; set; }
  541. public double InitialRotation13 { get; set; }
  542. public double MaxAngle13 { get; set; }
  543. /// <summary>
  544. /// "缺料订单数","已领料订单数" ,"当日订单数"
  545. /// </summary>
  546. /// <param name="a">小</param>
  547. /// <param name="b">中</param>
  548. /// <param name="c">最大</param>
  549. public void SerHouse(double a, double b, double c)
  550. {
  551. GaugeTotal13 = c;//最大数
  552. InitialRotation13 = 90;
  553. MaxAngle13 = 270;
  554. void SetStyle13(string name, PieSeries<ObservableValue> series)
  555. {
  556. series.Name = name;
  557. series.DataLabelsPosition = PolarLabelsPosition.Start;
  558. series.DataLabelsFormatter =
  559. point => $"{point.Context.Series.Name} {point.Coordinate.PrimaryValue}";
  560. series.DataLabelsSize = 16;
  561. series.InnerRadius = 20;
  562. series.RelativeInnerRadius = 4;
  563. series.RelativeOuterRadius = 4;
  564. series.DataLabelsPaint = new SolidColorPaint(new SKColor(150, 150, 150));
  565. }
  566. Series13 = GaugeGenerator.BuildSolidGauge(
  567. new GaugeItem(a, series => SetStyle13("缺料订单数", series)),
  568. new GaugeItem(b, series => SetStyle13("已领料订单数", series)),
  569. new GaugeItem(c, series => SetStyle13("当日订单数", series)),
  570. new GaugeItem(GaugeItem.Background, series =>
  571. {
  572. series.InnerRadius = 20;
  573. series.RelativeInnerRadius = 10;
  574. series.RelativeOuterRadius = 10;
  575. }));
  576. }
  577. #endregion
  578. #region 设备状态
  579. public void AlarmOK()
  580. {
  581. ImgLight1 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  582. ImgLight2 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  583. ImgLight3 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  584. ImgLight4 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  585. ImgLight5 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  586. ImgLight6 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  587. ImgLight7 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  588. ImgLight8 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  589. ImgLight9 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  590. ImgLight10 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  591. ImgLight11 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  592. ImgLight12 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  593. ImgLight13 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  594. ImgLight14 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  595. ImgLight21 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  596. ImgLight22 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  597. ImgLight23 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  598. }
  599. private void GetAlarmMessage(Dictionary<string, string> dictionary)//dictionary 就是接收到的信息
  600. {
  601. var keys = new List<string>(dictionary.Keys);
  602. for (int i = 0; i < keys.Count; i++)
  603. {
  604. var key = keys[i];
  605. var value = dictionary[key];
  606. #region 号机
  607. //1号机
  608. if ((key == "1101" && value == "报警"))
  609. {
  610. ImgLight1 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  611. }
  612. if ((key == "1141.15" && value == "缺料"))
  613. {
  614. ImgLight1 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  615. }
  616. //2号机
  617. if ((key == "1102" && value == "报警"))
  618. {
  619. ImgLight2 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  620. }
  621. if ((key == "1142.15" && value == "缺料"))
  622. {
  623. ImgLight2 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  624. }
  625. //3号机
  626. if ((key == "1103" && value == "报警"))
  627. {
  628. ImgLight3 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  629. }
  630. if ((key == "1143.15" && value == "缺料"))
  631. {
  632. ImgLight3 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  633. }
  634. //4号机
  635. if ((key == "1104" && value == "报警"))
  636. {
  637. ImgLight4 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  638. }
  639. if ((key == "1144.15" && value == "缺料"))
  640. {
  641. ImgLight4 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  642. }
  643. //5号机
  644. if ((key == "1105" && value == "报警"))
  645. {
  646. ImgLight5 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  647. }
  648. if ((key == "1145.15" && value == "缺料"))
  649. {
  650. ImgLight5 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  651. }
  652. //6号机
  653. if ((key == "1106" && value == "报警"))
  654. {
  655. ImgLight6 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  656. }
  657. if ((key == "1146.15" && value == "缺料"))
  658. {
  659. ImgLight6 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  660. }
  661. //7号机
  662. if ((key == "1110" && value == "报警"))
  663. {
  664. ImgLight7 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  665. }
  666. if ((key == "1150.15" && value == "缺料"))
  667. {
  668. ImgLight7 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  669. }
  670. //8号机
  671. if ((key == "1111" && value == "报警"))
  672. {
  673. ImgLight8 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  674. }
  675. if ((key == "1151.15" && value == "缺料"))
  676. {
  677. ImgLight8 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  678. }
  679. //9号机
  680. if ((key == "1112" && value == "报警"))
  681. {
  682. ImgLight9 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  683. }
  684. if ((key == "1152.15" && value == "缺料"))
  685. {
  686. ImgLight9 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  687. }
  688. //10号机
  689. if ((key == "1113" && value == "报警"))
  690. {
  691. ImgLight10 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  692. }
  693. if ((key == "1153.15" && value == "缺料"))
  694. {
  695. ImgLight10 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  696. }
  697. //11号机
  698. if ((key == "1117" && value == "报警"))
  699. {
  700. ImgLight11 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  701. }
  702. if ((key == "1157.15" && value == "缺料"))
  703. {
  704. ImgLight11 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  705. }
  706. //12号机
  707. if ((key == "1118" && value == "报警"))
  708. {
  709. ImgLight12 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  710. }
  711. if ((key == "1158.15" && value == "缺料"))
  712. {
  713. ImgLight12 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  714. }
  715. //13号机
  716. if ((key == "1119" && value == "报警"))
  717. {
  718. ImgLight13 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  719. }
  720. if ((key == "1159.15" && value == "缺料"))
  721. {
  722. ImgLight13 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  723. }
  724. //14号机
  725. if ((key == "1120" && value == "报警"))
  726. {
  727. ImgLight14 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  728. }
  729. if ((key == "1160.15" && value == "缺料"))
  730. {
  731. ImgLight14 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  732. }
  733. #endregion
  734. #region 螺丝机
  735. //螺丝机1
  736. if ((key == "1107" && value == "报警"))
  737. {
  738. ImgLight15 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  739. }
  740. if ((key == "1107" && value == "正常"))
  741. {
  742. ImgLight15 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  743. }
  744. //螺丝机2
  745. if ((key == "1108" && value == "报警"))
  746. {
  747. ImgLight16 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  748. }
  749. if ((key == "1108" && value == "正常"))
  750. {
  751. ImgLight16 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  752. }
  753. //螺丝机3
  754. if ((key == "1115" && value == "报警"))
  755. {
  756. ImgLight17 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  757. }
  758. if ((key == "1115" && value == "正常"))
  759. {
  760. ImgLight17 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  761. }
  762. //螺丝机4
  763. if ((key == "1116" && value == "报警"))
  764. {
  765. ImgLight18 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  766. }
  767. if ((key == "1116" && value == "正常"))
  768. {
  769. ImgLight18 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  770. }
  771. //螺丝机5
  772. if ((key == "1121" && value == "报警"))
  773. {
  774. ImgLight19 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  775. }
  776. if ((key == "1121" && value == "正常"))
  777. {
  778. ImgLight19 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  779. }
  780. //螺丝机6
  781. if ((key == "1122" && value == "报警"))
  782. {
  783. ImgLight20 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  784. }
  785. if ((key == "1122" && value == "正常"))
  786. {
  787. ImgLight20 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  788. }
  789. #endregion
  790. //提升机
  791. if ((key == "1100" && value == "报警") || (key == "1124" && value == "报警") || (key == "D1125" && value == "报警"))
  792. {
  793. ImgLight21 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  794. }
  795. //检测
  796. if ((key == "1166.0" && value == "缺料") || (key == "1166.1" && value == "缺料") || (key == "D1166.2" && value == "缺料") || (key == "D1166.3" && value == "缺料"))
  797. {
  798. ImgLight22 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  799. }
  800. //返修
  801. if ((key == "1166.4" && value == "缺料") || (key == "1166.5" && value == "缺料") || (key == "D1166.6" && value == "缺料"))
  802. {
  803. ImgLight23 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  804. }
  805. }
  806. }
  807. #endregion
  808. #region 生产进度
  809. double changeDay; double okrate;
  810. List<string> xlabel = new List<string>();
  811. List<double> listval1 = new List<double>();
  812. List<double> listval2 = new List<double>();
  813. public void ShowProcess()
  814. {
  815. try
  816. {
  817. listval1.Clear();
  818. listval2.Clear();
  819. xlabel.Clear();
  820. //for (int i = 1; i < 20; i++)
  821. //{
  822. // changeDay = -i;
  823. // var list = repository.GetFirstDefault<AllNumber>(c => c.DateA == DateTime.Today.AddDays(changeDay));
  824. // if (list != null)
  825. // {
  826. // if (list.RealityA!=0)
  827. // {
  828. // listval1.Add(list.RealityA);
  829. // okrate = Math.Round((list.OkA / list.RealityA) * 100, 2);
  830. // listval2.Add(okrate);
  831. // xlabel.Add(list.DateA.ToString("MM-dd"));
  832. // if (listval1.Count >= 7)
  833. // {
  834. // break;
  835. // }
  836. // }
  837. // }
  838. //}
  839. DateTime start = DateTime.Now.AddDays(-((int)DateTime.Now.DayOfWeek - 1));
  840. DateTime end = start.AddDays(7);
  841. start = new DateTime(start.Year, start.Month, start.Day, 0, 0, 0);
  842. end = new DateTime(end.Year, end.Month, end.Day, 0, 0, 0);
  843. var list = repository.GetAllQuery<AllNumber>(c => c.DateA >=start&&c.DateA<end);
  844. if (list != null)
  845. {
  846. for (int i = 0; i < list.Count; i++)
  847. {
  848. listval1.Add(list[i].RealityA);
  849. okrate = Math.Round((list[i].OkA / list[i].RealityA) * 100, 2);
  850. listval2.Add(okrate);
  851. xlabel.Add(list[i].DateA.ToString("MM-dd"));
  852. }
  853. }
  854. SerLine(listval1, listval2, xlabel);
  855. }
  856. catch (Exception)
  857. {
  858. }
  859. }
  860. public void SerLine(List<double> val1, List<double> val2, List<string> list)
  861. {
  862. SeriesLine[0].Values = val1;
  863. SeriesLine[1].Values = val2;
  864. XAxesLine[0].Labels = list;
  865. }
  866. public ISeries[] SeriesLine { get; set; } =
  867. {
  868. new LineSeries<double>
  869. {
  870. Name = "产量",
  871. //Values = new []{ 4, 2, 8, 5, 3 },
  872. GeometrySize = 12,
  873. Stroke = new LinearGradientPaint(new[]{ new SKColor(100, 135, 15), new SKColor(255, 212, 96)}) { StrokeThickness = 5 },
  874. GeometryStroke = new LinearGradientPaint(new[]{ new SKColor(100, 135, 15), new SKColor(255, 212, 96)}) { StrokeThickness = 5 },
  875. Fill = null,
  876. ScalesYAt = 0
  877. //Fill = new SolidColorPaint(new SKColor(255, 212, 96, 90))
  878. },
  879. new LineSeries<double>
  880. {
  881. Name = "合格率(%)",
  882. GeometrySize = 12,
  883. Stroke = new LinearGradientPaint(new[]{ new SKColor(100, 62, 99), new SKColor(255, 137, 219) }) { StrokeThickness = 5 },
  884. GeometryStroke = new LinearGradientPaint(new[]{ new SKColor(100, 62, 99), new SKColor(255, 137, 219)}) { StrokeThickness = 5 },
  885. Fill = null,
  886. ScalesYAt = 1
  887. }
  888. };
  889. public LabelVisual PcTitle { get; set; } =
  890. new LabelVisual
  891. {
  892. Text = "近一周产量趋势",
  893. TextSize = 16,
  894. Padding = new LiveChartsCore.Drawing.Padding(15),
  895. Paint = new SolidColorPaint(new SKColor(47, 152, 255))
  896. };
  897. public DrawMarginFrame DrawMarginFrame => new()
  898. {
  899. Stroke = new SolidColorPaint(new SKColor(45, 64, 89), 2)
  900. };
  901. public Axis[] XAxesLine { get; set; } =
  902. {
  903. new Axis
  904. {
  905. //Labels = new string[] { "1","2" ,"3" ,"4" ,"5","6","7"},
  906. LabelsPaint = new SolidColorPaint(new SKColor(100, 100, 100)),
  907. LabelsRotation = 0,
  908. ForceStepToMin = true,
  909. MinLimit=0,
  910. MinStep = 1
  911. }
  912. };
  913. public Axis[] YAxesLine { get; set; } =
  914. {
  915. new Axis
  916. {
  917. Name = "产量",
  918. NameTextSize = 14,
  919. NamePaint = new SolidColorPaint(new SKColor(153, 194, 40)),
  920. LabelsPaint = new SolidColorPaint(new SKColor(100, 100, 100)),
  921. MinLimit=0,
  922. //最小步长
  923. //ForceStepToMin = true,
  924. //MinStep = 5
  925. },
  926. new Axis
  927. {
  928. Name = "合格率(%)",
  929. NameTextSize = 14,
  930. NamePaint = new SolidColorPaint(new SKColor(255, 137, 219)),
  931. LabelsPaint = new SolidColorPaint(new SKColor(100, 100, 100)),
  932. MinLimit=0,
  933. MaxLimit=150,
  934. Position = LiveChartsCore.Measure.AxisPosition.End
  935. }
  936. };
  937. #endregion
  938. #region 当前订单情况
  939. public void ShowOrder(string str)
  940. {
  941. var customRepo = new CustomRepository();
  942. try
  943. {
  944. //DateTime max = DateTime.Today.AddDays(1);
  945. //DateTime min = DateTime.Today.AddDays(-1);
  946. DateTime d = DateTime.Today;
  947. var list = customRepo.GetFirstDefault<ICMO>(c => c.FBillNo == str);
  948. if (list != null)
  949. {
  950. BillNo = str;
  951. AuxQty = (double)list.FAuxQty;
  952. }
  953. }
  954. catch (Exception ex)
  955. {
  956. }
  957. try
  958. {
  959. var ps = repository.GetFirstDefault<ProStatus>(c => c.OrdNoS==str);
  960. if (ps != null)
  961. {
  962. Finished = ps.RealityS;
  963. }
  964. }
  965. catch (Exception)
  966. {
  967. }
  968. }
  969. #endregion
  970. #region 实时产量
  971. public void ShowNowProcess()
  972. {
  973. try
  974. {
  975. var allnumbers = repository.GetFirstDefault<AllNumber>(c => c.DateA == DateTime.Today);
  976. if (allnumbers != null)
  977. {
  978. TotalNum = allnumbers.RealityA;
  979. if (allnumbers.OkA <= 0)
  980. {
  981. allnumbers.OkA= 0;
  982. repository.Update(allnumbers);
  983. }
  984. PassNum = allnumbers.OkA;
  985. }
  986. }
  987. catch (Exception)
  988. {
  989. }
  990. }
  991. #endregion
  992. }
  993. }