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.

116 lines
4.8 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. {
  54. var model = (new HKCore()).PullDaySaleLog(BindScreen);
  55. LAdInfo.Gate = $"{BindScreen[1]}号档口";
  56. RAdinfo.Gate = $"{BindScreen[0]}号档口";
  57. LAdInfo.Count = model.Where(t => t.Key == $"{BindScreen[1]}").FirstOrDefault().Value;
  58. RAdinfo.Count = model.Where(t => t.Key == $"{BindScreen[0]}").FirstOrDefault().Value;
  59. if (Main.GetInstance.GetIsConnect(BindScreen[1]))
  60. LAdInfo.Msg = Main.GetInstance.GetIsSwipe(BindScreen[1]) ? "正常" : "异常";
  61. else
  62. LAdInfo.Msg = "未连接";
  63. if (Main.GetInstance.GetIsConnect(BindScreen[0]))
  64. RAdinfo.Msg = Main.GetInstance.GetIsSwipe(BindScreen[0]) ? "正常" : "异常";
  65. else
  66. RAdinfo.Msg = "未连接";
  67. for (int i = 0; i < BindScreen.Length; i++)
  68. {
  69. if (DataBus.SaleLogDtoList.ContainsKey(BindScreen[i].ToString()))
  70. {
  71. if (DataBus.SaleLogDtoList[BindScreen[i].ToString()].Count > 0)
  72. {
  73. if (DataBus.SaleLogDtoList[BindScreen[i].ToString()].TryDequeue(out SaleLogDto info))
  74. {
  75. ScreenInfoDto data = new ScreenInfoDto
  76. {
  77. CardNo = info.CardNo,
  78. UserName = "",
  79. Location = info.Location,
  80. };
  81. data.UserName = DataBus.UserListDto
  82. .Where(t => t.Cards.Select(x => x.CardNum).Contains(data.CardNo))
  83. .Select(x => x.Name).FirstOrDefault();
  84. App.Current.Dispatcher.Invoke(() =>
  85. {
  86. if (LAdInfo.Info != null && !string.IsNullOrEmpty(LAdInfo.Info.UserName))
  87. LAdInfo.AInfo.Insert(0, LAdInfo.Info); LAdInfo.Info.Time = DateTime.Now.ToString("HH:mm:ss");
  88. if (RAdinfo.Info != null && !string.IsNullOrEmpty(RAdinfo.Info.UserName))
  89. RAdinfo.AInfo.Insert(0, RAdinfo.Info); RAdinfo.Info.Time = DateTime.Now.ToString("HH:mm:ss");
  90. });
  91. LAdInfo.Info = data.Location == $"{BindScreen[1]}" ? data : new ScreenInfoDto();
  92. RAdinfo.Info = data.Location == $"{BindScreen[0]}" ? data : new ScreenInfoDto();
  93. }
  94. }
  95. }
  96. }
  97. Thread.Sleep(10);
  98. }, $"屏幕刷卡信息{BindScreen[0]}-{BindScreen[1]}", true);
  99. }
  100. }
  101. }