KBWindowViewModel.cs 45 KB

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