KBWindowViewModel.cs 43 KB

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