You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
5.6 KiB

  1. using BPA.Helper;
  2. using DTO;
  3. using HKCardOUT.Helper;
  4. using HKCardOUT.Logic.Service;
  5. using Stylet;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Collections.ObjectModel;
  9. using System.Linq;
  10. using System.Threading;
  11. using System.Windows.Media;
  12. using HKControl;
  13. using System.Collections.Concurrent;
  14. namespace HKCardOUT.ViewModels
  15. {
  16. public class AdWindowViewModel : NotifyBase
  17. {
  18. public AdWindowViewModel()
  19. {
  20. for (int i = 0; i < 6; i++)
  21. {
  22. Foods.Add("");
  23. }
  24. }
  25. #region 属性
  26. public AdInfoModel LAdInfo { get { return _mLAdInfo; } set { _mLAdInfo = value; OnPropertyChanged(); } }
  27. private AdInfoModel _mLAdInfo = new AdInfoModel();
  28. public AdInfoModel RAdinfo { get { return _mRAdinfo; } set { _mRAdinfo = value; OnPropertyChanged(); } }
  29. private AdInfoModel _mRAdinfo = new AdInfoModel();
  30. public ObservableCollection<string> Foods { get; set; } = new ObservableCollection<string>();
  31. #endregion
  32. void FoodsInit(int[] ScreenLoc)
  33. {
  34. string GateId = string.Empty;
  35. GateId = DataBus.StoreInfo.Devices.Where(t => t.Address == $"0{ScreenLoc[0]}" || t.Address == $"0{ScreenLoc[1]}").Select(t => t.GateId).FirstOrDefault();
  36. var res = DataBus.Menu.GateFood.Where(t => t.GateId == GateId)?.Select(t => t.Foods)?.FirstOrDefault();
  37. if (res != null)
  38. {
  39. App.Current.Dispatcher.Invoke(() =>
  40. {
  41. for (int i = 0; i < Foods.Count; i++)
  42. {
  43. if (i >= 0 && i < res.Count)
  44. Foods[i] = res.ElementAt(i);
  45. }
  46. });
  47. }
  48. }
  49. public void InitData(int[] BindScreen)
  50. {
  51. FoodsInit(BindScreen);
  52. ThreadManage.GetInstance().StartLong(() => {
  53. if (DateTime.Now.Hour == 16)
  54. {
  55. LAdInfo.AInfo = new ObservableCollection<ScreenInfoDto>();
  56. RAdinfo.AInfo = new ObservableCollection<ScreenInfoDto>();
  57. }
  58. Thread.Sleep(5000);
  59. }, "清理屏幕数据", true);
  60. ThreadManage.GetInstance().StartLong(() =>
  61. {
  62. var model = (new HKCore()).PullDaySaleLog(BindScreen);
  63. if (BindScreen[1] == 6)
  64. LAdInfo.Gate = $"1号档口";
  65. if (BindScreen[1] == 4)
  66. LAdInfo.Gate = $"3号档口";
  67. if (BindScreen[1] == 2)
  68. LAdInfo.Gate = $"5号档口";
  69. if (BindScreen[0] == 5)
  70. RAdinfo.Gate = $"2号档口";
  71. if (BindScreen[0] == 3)
  72. RAdinfo.Gate = $"4号档口";
  73. if (BindScreen[0] == 1)
  74. RAdinfo.Gate = $"6号档口";
  75. LAdInfo.Count = model.Where(t => t.Key == $"{BindScreen[1]}").FirstOrDefault().Value;
  76. RAdinfo.Count = model.Where(t => t.Key == $"{BindScreen[0]}").FirstOrDefault().Value;
  77. if (Main.GetInstance.GetIsConnect(BindScreen[1]))
  78. LAdInfo.Msg = Main.GetInstance.GetIsSwipe(BindScreen[1]) ? "正常" : "异常";
  79. else
  80. LAdInfo.Msg = "未连接";
  81. if (Main.GetInstance.GetIsConnect(BindScreen[0]))
  82. RAdinfo.Msg = Main.GetInstance.GetIsSwipe(BindScreen[0]) ? "正常" : "异常";
  83. else
  84. RAdinfo.Msg = "未连接";
  85. for (int i = 0; i < BindScreen.Length; i++)
  86. {
  87. if (DataBus.SaleLogDtoList.ContainsKey(BindScreen[i].ToString()))
  88. {
  89. if (DataBus.SaleLogDtoList[BindScreen[i].ToString()].Count > 0)
  90. {
  91. if (DataBus.SaleLogDtoList[BindScreen[i].ToString()].TryDequeue(out SaleLogDto info))
  92. {
  93. ScreenInfoDto data = new ScreenInfoDto
  94. {
  95. CardNo = info.CardNo,
  96. UserName = "",
  97. Location = info.Location,
  98. };
  99. data.UserName = DataBus.UserListDto
  100. .Where(t => t.Cards.Select(x => x.CardNum).Contains(data.CardNo))
  101. .Select(x => x.Name).FirstOrDefault();
  102. App.Current.Dispatcher.Invoke(() =>
  103. {
  104. if (LAdInfo.Info != null && !string.IsNullOrEmpty(LAdInfo.Info.UserName))
  105. LAdInfo.AInfo.Insert(0, LAdInfo.Info); LAdInfo.Info.Time = DateTime.Now.ToString("HH:mm:ss");
  106. if (RAdinfo.Info != null && !string.IsNullOrEmpty(RAdinfo.Info.UserName))
  107. RAdinfo.AInfo.Insert(0, RAdinfo.Info); RAdinfo.Info.Time = DateTime.Now.ToString("HH:mm:ss");
  108. });
  109. LAdInfo.Info = data.Location == $"{BindScreen[1]}" ? data : new ScreenInfoDto();
  110. RAdinfo.Info = data.Location == $"{BindScreen[0]}" ? data : new ScreenInfoDto();
  111. }
  112. }
  113. }
  114. }
  115. Thread.Sleep(10);
  116. }, $"屏幕刷卡信息{BindScreen[0]}-{BindScreen[1]}", true);
  117. }
  118. }
  119. }