KBWindowViewModel.cs 42 KB

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