KBWindowViewModel.cs 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  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. var res1=Products.ProductCollection.FirstOrDefault(p => p.Name == GVariable.ProductTypeName);
  350. if (res1 != null)
  351. {
  352. ProductProblem = res1.QuestionType1;
  353. ProcessProblem = res1.QuestionType2;
  354. MaterialProblem = res1.QuestionType3;
  355. }
  356. SerQuality1(qua1, ProductProblem);
  357. SerQuality2(qua2, ProcessProblem);
  358. SerQuality3(qua3, MaterialProblem);
  359. }
  360. }
  361. catch (Exception ex)
  362. {
  363. _logger.Error("KB_ShowQuality:" + ex);
  364. }
  365. }
  366. #region 生产问题
  367. public void SerQuality1(int[] val,ObservableCollection<string> xlabel)
  368. {
  369. SeriesQuality1[0].Values = val;
  370. XAxes1[0].Labels = xlabel;
  371. }
  372. public ISeries[] SeriesQuality1 { get; set; } = new ISeries[]
  373. {
  374. new ColumnSeries<int>
  375. {
  376. Name = "数量",
  377. //Values = new[] {23, 27, 22, 29, 24 ,21,11,45,32,19},
  378. Stroke = null,
  379. DataLabelsPaint = new SolidColorPaint(new SKColor(180, 180, 180)),
  380. DataLabelsPosition = DataLabelsPosition.Top,
  381. Padding = 3,//每个条之间的距离
  382. //Fill = new LinearGradientPaint(
  383. // new [] { new SKColor(255, 140, 148), new SKColor(220, 237, 194) },
  384. // new SKPoint(0.5f, 0),
  385. // new SKPoint(0.5f, 1))
  386. Fill = new LinearGradientPaint(new[]{new SKColor(255, 140, 148), new SKColor(220, 237, 194) })
  387. }
  388. };
  389. public Axis[] XAxes1 { get; set; } =
  390. {
  391. new Axis
  392. {
  393. // Labels = new string[] { "螺丝未上紧","3D人脸无效" ,"螺丝漏打" ,"显示屏幕漏光" ,"胶体未打好",
  394. // "对讲喇叭无声","执手过于松紧" ,"螺丝打变形" ,"理线错乱" ,"弹簧未装好" },
  395. LabelsPaint = new SolidColorPaint(new SKColor(100, 100, 100)),
  396. LabelsRotation = 90,
  397. TextSize = 12,
  398. ForceStepToMin = true,
  399. MinStep = 1
  400. }
  401. };
  402. public Axis[] YAxes1 { get; set; } =
  403. {
  404. new Axis
  405. {
  406. LabelsPaint = new SolidColorPaint(new SKColor(100, 100, 100)),
  407. MinLimit=0,
  408. //最小步长
  409. //ForceStepToMin = true,
  410. //MinStep = 5
  411. }
  412. };
  413. #endregion
  414. #region 工艺问题
  415. public void SerQuality2(int[] val, ObservableCollection<string> xlabel)
  416. {
  417. SeriesQuality2[0].Values = val;
  418. XAxes2[0].Labels= xlabel;
  419. }
  420. public ISeries[] SeriesQuality2 { get; set; } = new ISeries[]
  421. {
  422. new ColumnSeries<int>
  423. {
  424. Name = "数量",
  425. //Values = new[] {23, 27, 22, 29, 24 ,21,11,45,32,19},
  426. Stroke = null,
  427. DataLabelsPaint = new SolidColorPaint(new SKColor(180, 180, 180)),
  428. DataLabelsPosition = DataLabelsPosition.Top,
  429. Padding = 3,//每个条之间的距离
  430. //Fill = new LinearGradientPaint(
  431. // new [] { new SKColor(255, 140, 148), new SKColor(220, 237, 194) },
  432. // new SKPoint(0.5f, 0),
  433. // new SKPoint(0.5f, 1))
  434. Fill = new LinearGradientPaint(new[]{new SKColor(255, 140, 148), new SKColor(220, 237, 194) })
  435. }
  436. };
  437. public Axis[] XAxes2 { get; set; } =
  438. {
  439. new Axis
  440. {
  441. //Labels = new string[] {"对讲无声","执手问题" ,"壳体脚位不平衡" ,"前板锁芯两孔位不一致" ,"后板显示屏水印",
  442. // "电池异常耗电","喷漆过厚导致组装困难" ,"设计线路太长" ,"执手靠垫片改善" ,"锁芯顶杆没固定位置"},
  443. LabelsPaint = new SolidColorPaint(new SKColor(100, 100, 100)),
  444. LabelsRotation = 90,
  445. TextSize = 12,
  446. ForceStepToMin = true,
  447. MinStep = 1
  448. }
  449. };
  450. public Axis[] YAxes2 { get; set; } =
  451. {
  452. new Axis
  453. {
  454. LabelsPaint = new SolidColorPaint(new SKColor(100, 100, 100)),
  455. MinLimit=0,
  456. //最小步长
  457. //ForceStepToMin = true,
  458. //MinStep = 5
  459. }
  460. };
  461. #endregion
  462. #region 物料问题
  463. public void SerQuality3(int[] val, ObservableCollection<string> xlabel)
  464. {
  465. SeriesQuality3[0].Values = val;
  466. XAxes3[0].Labels= xlabel;
  467. }
  468. public ISeries[] SeriesQuality3 { get; set; } = new ISeries[]
  469. {
  470. new ColumnSeries<int>
  471. {
  472. Name = "数量",
  473. //Values = new[] {23, 27, 22, 29, 24 ,21,11,45,32,19},
  474. Stroke = null,
  475. DataLabelsPaint = new SolidColorPaint(new SKColor(180, 180, 180)),
  476. DataLabelsPosition = DataLabelsPosition.Top,
  477. Padding = 3,//每个条之间的距离
  478. //Fill = new LinearGradientPaint(
  479. // new [] { new SKColor(255, 140, 148), new SKColor(220, 237, 194) },
  480. // new SKPoint(0.5f, 0),
  481. // new SKPoint(0.5f, 1))
  482. Fill = new LinearGradientPaint(new[]{new SKColor(255, 140, 148), new SKColor(220, 237, 194) })
  483. }
  484. };
  485. public Axis[] XAxes3 { get; set; } =
  486. {
  487. new Axis
  488. {
  489. //Labels = new string[] {"面板变形","电机异常" ,"屏幕异常" ,"物料毛刺" ,"大屏上支架变形",
  490. // "壳料划痕","显示屏水印" , "壳体脚位不平横" ,"装饰圈气泡脱皮" ,"电池异常"},
  491. LabelsPaint = new SolidColorPaint(new SKColor(100, 100, 100)),
  492. LabelsRotation = 90,
  493. TextSize = 12,
  494. ForceStepToMin = true,
  495. MinStep = 1
  496. }
  497. };
  498. public Axis[] YAxes3 { get; set; } =
  499. {
  500. new Axis
  501. {
  502. LabelsPaint = new SolidColorPaint(new SKColor(100, 100, 100)),
  503. MinLimit=0,
  504. //最小步长
  505. //ForceStepToMin = true,
  506. //MinStep = 5
  507. }
  508. };
  509. #endregion
  510. #endregion
  511. #region 人员管理
  512. //int nums;
  513. //private void ShowPeope(string opername)
  514. //{
  515. // var value = repository.GetAllQuery<Information>(c => c.OperatorCode == opername && c.CreateTime == DateTime.Today);
  516. // if (value.Count != 0)
  517. // {
  518. // nums = value.Count();
  519. // PerManagement(opername, nums);
  520. // }
  521. //}
  522. int[] nums = new int[30];
  523. private void ShowPeope(string[] opername)
  524. {
  525. PerManage = new List<Person>();
  526. PerManage1 = new List<Person>();
  527. PerManage2 = new List<Person>();
  528. for (int i = 0; i < opername.Length; i++)
  529. {
  530. if (opername[i] == null || string.IsNullOrEmpty(opername[i]))
  531. {
  532. continue;
  533. }
  534. var value = repository.GetAllQuery<Information>(c => c.OperatorCode == opername[i] && c.CreateTime == DateTime.Today);
  535. if (value.Count != 0)
  536. {
  537. nums[i] = value.Count();
  538. PerManagement(opername[i], nums[i]);
  539. }
  540. var num= repository.GetAllQuery<Information>(c => c.OperatorCode == opername[i] && c.CreateTime <= DateTime.Today&& c.CreateTime >= DateTime.Today.AddDays(-9));
  541. if (num.Count != 0)
  542. {
  543. nums[i] = value.Count();
  544. PerManagement2(opername[i], nums[i]);
  545. }
  546. }
  547. }
  548. public List<Person> PerManage { get; set; }
  549. private List<Person> PerManage1 { get; set; }
  550. private List<Person> PerManage2 { get; set; }
  551. public void PerManagement(string ename, int yield)
  552. {
  553. //PerManage = new List<Person>();//放在外面就累加,放这里就不累加一直刷
  554. PerManage1.Add(new Person { Id = new Guid(), EmployeeName = ename, Yield = yield });
  555. var m = PerManage1.OrderByDescending(x => x.Yield).ToList();//降序
  556. PerManage = m;
  557. //if (m.Count >= 3)
  558. //{
  559. // FirstName = PerManage[0].EmployeeName;
  560. // SecondName = PerManage[1].EmployeeName;
  561. // ThirdName = PerManage[2].EmployeeName;
  562. //}
  563. }
  564. public void PerManagement2(string ename, int yield)
  565. {
  566. PerManage2.Add(new Person { Id = new Guid(), EmployeeName = ename, Yield = yield });
  567. var m = PerManage2.OrderByDescending(x => x.Yield).ToList();//降序
  568. PerManage = m;
  569. if (m.Count >= 3)
  570. {
  571. FirstName = PerManage[0].EmployeeName;
  572. SecondName = PerManage[1].EmployeeName;
  573. ThirdName = PerManage[2].EmployeeName;
  574. }
  575. }
  576. #endregion
  577. #region 仓库
  578. public void ShowHouse()
  579. {
  580. try
  581. {
  582. //var list = repository.GetAllQuery<House>(c => c.DateH == str);//查一个集合
  583. var list = repository.GetFirstDefault<House>(c => c.DateH == DateTime.Today);
  584. if (list != null)
  585. {
  586. var dto = _mapper.Map<HouseDto>(list);
  587. System.Windows.Application.Current.Dispatcher.Invoke(new Action(() =>
  588. {
  589. MyHouse.Clear();
  590. MyHouse.Add(dto);
  591. if (list.LackH==null)
  592. {
  593. list.LackH = "0";
  594. }
  595. if (list.UsedH == null)
  596. {
  597. list.UsedH = "0";
  598. }
  599. if (list.TotalH == null)
  600. {
  601. list.TotalH = "0";
  602. }
  603. SerHouse(double.Parse(list.LackH), double.Parse(list.UsedH), double.Parse(list.TotalH));
  604. }));
  605. }
  606. }
  607. catch (Exception ex)
  608. {
  609. _logger.Error("KB_ShowHouse:" + ex);
  610. }
  611. }
  612. public IEnumerable<ISeries> Series13 { get; set; }
  613. public double GaugeTotal13 { get; set; }
  614. public double InitialRotation13 { get; set; }
  615. public double MaxAngle13 { get; set; }
  616. /// <summary>
  617. /// "缺料订单数","已领料订单数" ,"当日订单数"
  618. /// </summary>
  619. /// <param name="a">小</param>
  620. /// <param name="b">中</param>
  621. /// <param name="c">最大</param>
  622. public void SerHouse(double a, double b, double c)
  623. {
  624. GaugeTotal13 = c;//最大数
  625. InitialRotation13 = 90;
  626. MaxAngle13 = 270;
  627. void SetStyle13(string name, PieSeries<ObservableValue> series)
  628. {
  629. series.Name = name;
  630. series.DataLabelsPosition = PolarLabelsPosition.Start;
  631. series.DataLabelsFormatter =
  632. point => $"{point.Context.Series.Name} {point.Coordinate.PrimaryValue}";
  633. series.DataLabelsSize = 16;
  634. series.InnerRadius = 20;
  635. series.RelativeInnerRadius = 4;
  636. series.RelativeOuterRadius = 4;
  637. series.DataLabelsPaint = new SolidColorPaint(new SKColor(150, 150, 150));
  638. }
  639. Series13 = GaugeGenerator.BuildSolidGauge(
  640. new GaugeItem(a, series => SetStyle13("缺料订单数", series)),
  641. new GaugeItem(b, series => SetStyle13("已领料订单数", series)),
  642. new GaugeItem(c, series => SetStyle13("当日订单数", series)),
  643. new GaugeItem(GaugeItem.Background, series =>
  644. {
  645. series.InnerRadius = 20;
  646. series.RelativeInnerRadius = 10;
  647. series.RelativeOuterRadius = 10;
  648. }));
  649. }
  650. #endregion
  651. #region 设备状态
  652. public void AlarmOK()
  653. {
  654. ImgLight1 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  655. ImgLight2 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  656. ImgLight3 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  657. ImgLight4 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  658. ImgLight5 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  659. ImgLight6 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  660. ImgLight7 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  661. ImgLight8 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  662. ImgLight9 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  663. ImgLight10 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  664. ImgLight11 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  665. ImgLight12 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  666. ImgLight13 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  667. ImgLight14 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  668. ImgLight21 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  669. ImgLight22 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  670. ImgLight23 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  671. }
  672. private void GetAlarmMessage(Dictionary<string, string> dictionary)//dictionary 就是接收到的信息
  673. {
  674. var keys = new List<string>(dictionary.Keys);
  675. for (int i = 0; i < keys.Count; i++)
  676. {
  677. var key = keys[i];
  678. var value = dictionary[key];
  679. #region 号机
  680. //1号机
  681. if ((key == "1101" && value == "报警"))
  682. {
  683. ImgLight1 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  684. }
  685. if ((key == "1141.15" && value == "缺料"))
  686. {
  687. ImgLight1 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  688. }
  689. //2号机
  690. if ((key == "1102" && value == "报警"))
  691. {
  692. ImgLight2 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  693. }
  694. if ((key == "1142.15" && value == "缺料"))
  695. {
  696. ImgLight2 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  697. }
  698. //3号机
  699. if ((key == "1103" && value == "报警"))
  700. {
  701. ImgLight3 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  702. }
  703. if ((key == "1143.15" && value == "缺料"))
  704. {
  705. ImgLight3 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  706. }
  707. //4号机
  708. if ((key == "1104" && value == "报警"))
  709. {
  710. ImgLight4 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  711. }
  712. if ((key == "1144.15" && value == "缺料"))
  713. {
  714. ImgLight4 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  715. }
  716. //5号机
  717. if ((key == "1105" && value == "报警"))
  718. {
  719. ImgLight5 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  720. }
  721. if ((key == "1145.15" && value == "缺料"))
  722. {
  723. ImgLight5 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  724. }
  725. //6号机
  726. if ((key == "1106" && value == "报警"))
  727. {
  728. ImgLight6 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  729. }
  730. if ((key == "1146.15" && value == "缺料"))
  731. {
  732. ImgLight6 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  733. }
  734. //7号机
  735. if ((key == "1110" && value == "报警"))
  736. {
  737. ImgLight7 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  738. }
  739. if ((key == "1150.15" && value == "缺料"))
  740. {
  741. ImgLight7 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  742. }
  743. //8号机
  744. if ((key == "1111" && value == "报警"))
  745. {
  746. ImgLight8 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  747. }
  748. if ((key == "1151.15" && value == "缺料"))
  749. {
  750. ImgLight8 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  751. }
  752. //9号机
  753. if ((key == "1112" && value == "报警"))
  754. {
  755. ImgLight9 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  756. }
  757. if ((key == "1152.15" && value == "缺料"))
  758. {
  759. ImgLight9 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  760. }
  761. //10号机
  762. if ((key == "1113" && value == "报警"))
  763. {
  764. ImgLight10 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  765. }
  766. if ((key == "1153.15" && value == "缺料"))
  767. {
  768. ImgLight10 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  769. }
  770. //11号机
  771. if ((key == "1117" && value == "报警"))
  772. {
  773. ImgLight11 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  774. }
  775. if ((key == "1157.15" && value == "缺料"))
  776. {
  777. ImgLight11 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  778. }
  779. //12号机
  780. if ((key == "1118" && value == "报警"))
  781. {
  782. ImgLight12 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  783. }
  784. if ((key == "1158.15" && value == "缺料"))
  785. {
  786. ImgLight12 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  787. }
  788. //13号机
  789. if ((key == "1119" && value == "报警"))
  790. {
  791. ImgLight13 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  792. }
  793. if ((key == "1159.15" && value == "缺料"))
  794. {
  795. ImgLight13 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  796. }
  797. //14号机
  798. if ((key == "1120" && value == "报警"))
  799. {
  800. ImgLight14 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  801. }
  802. if ((key == "1160.15" && value == "缺料"))
  803. {
  804. ImgLight14 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  805. }
  806. #endregion
  807. #region 螺丝机
  808. //螺丝机1
  809. if ((key == "1107" && value == "报警"))
  810. {
  811. ImgLight15 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  812. }
  813. if ((key == "1107" && value == "正常"))
  814. {
  815. ImgLight15 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  816. }
  817. //螺丝机2
  818. if ((key == "1108" && value == "报警"))
  819. {
  820. ImgLight16 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  821. }
  822. if ((key == "1108" && value == "正常"))
  823. {
  824. ImgLight16 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  825. }
  826. //螺丝机3
  827. if ((key == "1115" && value == "报警"))
  828. {
  829. ImgLight17 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  830. }
  831. if ((key == "1115" && value == "正常"))
  832. {
  833. ImgLight17 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  834. }
  835. //螺丝机4
  836. if ((key == "1116" && value == "报警"))
  837. {
  838. ImgLight18 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  839. }
  840. if ((key == "1116" && value == "正常"))
  841. {
  842. ImgLight18 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  843. }
  844. //螺丝机5
  845. if ((key == "1121" && value == "报警"))
  846. {
  847. ImgLight19 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  848. }
  849. if ((key == "1121" && value == "正常"))
  850. {
  851. ImgLight19 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  852. }
  853. //螺丝机6
  854. if ((key == "1122" && value == "报警"))
  855. {
  856. ImgLight20 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  857. }
  858. if ((key == "1122" && value == "正常"))
  859. {
  860. ImgLight20 = System.Windows.Forms.Application.StartupPath + @"\image\绿灯.png";
  861. }
  862. #endregion
  863. //提升机
  864. if ((key == "1100" && value == "报警") || (key == "1124" && value == "报警") || (key == "D1125" && value == "报警"))
  865. {
  866. ImgLight21 = System.Windows.Forms.Application.StartupPath + @"\image\红灯.png";
  867. }
  868. //检测
  869. if ((key == "1166.0" && value == "缺料") || (key == "1166.1" && value == "缺料") || (key == "D1166.2" && value == "缺料") || (key == "D1166.3" && value == "缺料"))
  870. {
  871. ImgLight22 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  872. }
  873. //返修
  874. if ((key == "1166.4" && value == "缺料") || (key == "1166.5" && value == "缺料") || (key == "D1166.6" && value == "缺料"))
  875. {
  876. ImgLight23 = System.Windows.Forms.Application.StartupPath + @"\image\黄灯.png";
  877. }
  878. }
  879. }
  880. #endregion
  881. #region 生产进度
  882. double changeDay; double okrate;
  883. List<string> xlabel = new List<string>();
  884. List<double> listval1 = new List<double>();
  885. List<double> listval2 = new List<double>();
  886. public void ShowProcess()
  887. {
  888. try
  889. {
  890. listval1.Clear();
  891. listval2.Clear();
  892. xlabel.Clear();
  893. //for (int i = 1; i < 20; i++)
  894. //{
  895. // changeDay = -i;
  896. // var list = repository.GetFirstDefault<AllNumber>(c => c.DateA == DateTime.Today.AddDays(changeDay));
  897. // if (list != null)
  898. // {
  899. // if (list.RealityA!=0)
  900. // {
  901. // listval1.Add(list.RealityA);
  902. // okrate = Math.Round((list.OkA / list.RealityA) * 100, 2);
  903. // listval2.Add(okrate);
  904. // xlabel.Add(list.DateA.ToString("MM-dd"));
  905. // if (listval1.Count >= 7)
  906. // {
  907. // break;
  908. // }
  909. // }
  910. // }
  911. //}
  912. DateTime start = DateTime.Now.AddDays(-((int)DateTime.Now.DayOfWeek - 1));
  913. DateTime end = start.AddDays(7);
  914. start = new DateTime(start.Year, start.Month, start.Day, 0, 0, 0);
  915. end = new DateTime(end.Year, end.Month, end.Day, 0, 0, 0);
  916. var list = repository.GetAllQuery<AllNumber>(c => c.DateA >=start&&c.DateA<end);
  917. if (list != null)
  918. {
  919. for (int i = 0; i < list.Count; i++)
  920. {
  921. listval1.Add(list[i].RealityA);
  922. okrate = Math.Round((list[i].OkA / list[i].RealityA) * 100, 2);
  923. listval2.Add(okrate);
  924. xlabel.Add(list[i].DateA.ToString("MM-dd"));
  925. }
  926. }
  927. SerLine(listval1, listval2, xlabel);
  928. }
  929. catch (Exception ex)
  930. {
  931. _logger.Error("KB_ShowProcess:" + ex);
  932. }
  933. }
  934. public void SerLine(List<double> val1, List<double> val2, List<string> list)
  935. {
  936. SeriesLine[0].Values = val1;
  937. SeriesLine[1].Values = val2;
  938. XAxesLine[0].Labels = list;
  939. }
  940. public ISeries[] SeriesLine { get; set; } =
  941. {
  942. new LineSeries<double>
  943. {
  944. Name = "产量",
  945. //Values = new []{ 4, 2, 8, 5, 3 },
  946. GeometrySize = 12,
  947. Stroke = new LinearGradientPaint(new[]{ new SKColor(100, 135, 15), new SKColor(255, 212, 96)}) { StrokeThickness = 5 },
  948. GeometryStroke = new LinearGradientPaint(new[]{ new SKColor(100, 135, 15), new SKColor(255, 212, 96)}) { StrokeThickness = 5 },
  949. Fill = null,
  950. ScalesYAt = 0
  951. //Fill = new SolidColorPaint(new SKColor(255, 212, 96, 90))
  952. },
  953. new LineSeries<double>
  954. {
  955. Name = "合格率(%)",
  956. GeometrySize = 12,
  957. Stroke = new LinearGradientPaint(new[]{ new SKColor(100, 62, 99), new SKColor(255, 137, 219) }) { StrokeThickness = 5 },
  958. GeometryStroke = new LinearGradientPaint(new[]{ new SKColor(100, 62, 99), new SKColor(255, 137, 219)}) { StrokeThickness = 5 },
  959. Fill = null,
  960. ScalesYAt = 1
  961. }
  962. };
  963. public LabelVisual PcTitle { get; set; } =
  964. new LabelVisual
  965. {
  966. Text = "近一周产量趋势",
  967. TextSize = 16,
  968. Padding = new LiveChartsCore.Drawing.Padding(15),
  969. Paint = new SolidColorPaint(new SKColor(47, 152, 255))
  970. };
  971. public DrawMarginFrame DrawMarginFrame => new()
  972. {
  973. Stroke = new SolidColorPaint(new SKColor(45, 64, 89), 2)
  974. };
  975. public Axis[] XAxesLine { get; set; } =
  976. {
  977. new Axis
  978. {
  979. //Labels = new string[] { "1","2" ,"3" ,"4" ,"5","6","7"},
  980. LabelsPaint = new SolidColorPaint(new SKColor(100, 100, 100)),
  981. LabelsRotation = 0,
  982. ForceStepToMin = true,
  983. MinLimit=0,
  984. MinStep = 1
  985. }
  986. };
  987. public Axis[] YAxesLine { get; set; } =
  988. {
  989. new Axis
  990. {
  991. Name = "产量",
  992. NameTextSize = 14,
  993. NamePaint = new SolidColorPaint(new SKColor(153, 194, 40)),
  994. LabelsPaint = new SolidColorPaint(new SKColor(100, 100, 100)),
  995. MinLimit=0,
  996. //最小步长
  997. //ForceStepToMin = true,
  998. //MinStep = 5
  999. },
  1000. new Axis
  1001. {
  1002. Name = "合格率(%)",
  1003. NameTextSize = 14,
  1004. NamePaint = new SolidColorPaint(new SKColor(255, 137, 219)),
  1005. LabelsPaint = new SolidColorPaint(new SKColor(100, 100, 100)),
  1006. MinLimit=0,
  1007. MaxLimit=150,
  1008. Position = LiveChartsCore.Measure.AxisPosition.End
  1009. }
  1010. };
  1011. #endregion
  1012. #region 当前订单情况
  1013. public void ShowOrder(string str)
  1014. {
  1015. var customRepo = new CustomRepository();
  1016. try
  1017. {
  1018. //DateTime max = DateTime.Today.AddDays(1);
  1019. //DateTime min = DateTime.Today.AddDays(-1);
  1020. DateTime d = DateTime.Today;
  1021. var list = customRepo.GetFirstDefault<ICMO>(c => c.FBillNo == str);
  1022. if (list != null)
  1023. {
  1024. BillNo = str;
  1025. AuxQty = (double)list.FAuxQty;
  1026. }
  1027. var ps = repository.GetFirstDefault<ProStatus>(c => c.OrdNoS == str);
  1028. if (ps != null)
  1029. {
  1030. Finished = ps.RealityS;
  1031. }
  1032. }
  1033. catch (Exception ex)
  1034. {
  1035. _logger.Error("KB_ShowOrder:"+ex);
  1036. }
  1037. }
  1038. #endregion
  1039. #region 实时产量
  1040. public void ShowNowProcess()
  1041. {
  1042. try
  1043. {
  1044. var allnumbers = repository.GetFirstDefault<AllNumber>(c => c.DateA == DateTime.Today);
  1045. if (allnumbers != null)
  1046. {
  1047. TotalNum = allnumbers.RealityA;
  1048. if (allnumbers.OkA <= 0)
  1049. {
  1050. allnumbers.OkA= 0;
  1051. repository.Update(allnumbers);
  1052. }
  1053. PassNum = allnumbers.OkA;
  1054. }
  1055. }
  1056. catch (Exception ex)
  1057. {
  1058. _logger.Error("KB_ShowNowProcess:" + ex);
  1059. }
  1060. }
  1061. #endregion
  1062. }
  1063. }