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
3.6 KiB

  1. using DTO;
  2. using HKCardOUT.Helper;
  3. using HKCardOUT.Logic.Model;
  4. using HKCardOUT.Logic.Service;
  5. using Stylet;
  6. using StyletIoC;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Collections.ObjectModel;
  10. using System.Linq;
  11. using System.Threading;
  12. using System.Windows.Documents;
  13. namespace HKCardOUT.ViewModels
  14. {
  15. public class RootViewModel : Conductor<IScreen>
  16. {
  17. IContainer Container;
  18. public RootViewModel(IContainer Container)
  19. {
  20. this.Container = Container;
  21. MainThread();
  22. }
  23. protected override void OnViewLoaded()
  24. {
  25. ThreadManage.GetInstance().Start(() =>
  26. {
  27. Result = new ObservableCollection<SaleLog>(this.Container.Get<HKCore>().PullDaySaleLog());
  28. Thread.Sleep(3000);
  29. }, "消费记录查询");
  30. var Init = DataBus.StoreInfo?.Devices.Join(DataBus.StoreInfo?.Stalls, t => t.GateId, x => x.Id, (t, x) => new AdDTO
  31. {
  32. Ad = x.Remaek,
  33. IsActive = false,
  34. Device =t.Name,
  35. Stalls=x.Name
  36. }).ToList();
  37. if (Init != null)
  38. Ad = new ObservableCollection<AdDTO>(Init);
  39. }
  40. #region 属性
  41. ObservableCollection<SaleLog> _Result;
  42. public ObservableCollection<SaleLog> Result
  43. {
  44. get => _Result;
  45. set => SetAndNotify(ref _Result, value);
  46. }
  47. ObservableCollection<AdDTO> _Ad;
  48. public ObservableCollection<AdDTO> Ad
  49. {
  50. get => _Ad;
  51. set => SetAndNotify(ref _Ad, value);
  52. }
  53. #endregion
  54. #region 方法
  55. private void MainThread()
  56. {
  57. ThreadManage.GetInstance().StartLong(new Action(() =>
  58. {
  59. try
  60. {
  61. //1.检测网络上下线
  62. bool network = HKHelper.GetInstance().GetNetworkState();
  63. if (network != DataBus.NetWordState)
  64. {
  65. if (network) HandyControl.Controls.Growl.InfoGlobal("网络连接成功");
  66. else HandyControl.Controls.Growl.InfoGlobal("系统已离线,请连接网络!!!");
  67. DataBus.NetWordState = network;
  68. }
  69. Thread.Sleep(3000);
  70. }
  71. catch (Exception ex)
  72. {
  73. HandyControl.Controls.Growl.InfoGlobal(ex.Message);
  74. }
  75. }), "循环状态监测线程", false);
  76. }
  77. #endregion
  78. #region 命令
  79. /// <summary>
  80. /// 广告位置
  81. /// </summary>
  82. /// <param name="input"></param>
  83. public void UpdateAction(AdDTO input)
  84. {
  85. input.IsActive = !input.IsActive;
  86. var SC = System.Windows.Forms.Screen.AllScreens.Count();
  87. if (SC >= 1)
  88. {
  89. if (input.IsActive)
  90. {
  91. if (!DataBus.AdStatus.ContainsKey(input.Device))
  92. {
  93. var win = new Views.AdWindow(input.Ad);
  94. DataBus.AdStatus.Add(input.Device, win);
  95. win.Show();
  96. }
  97. }
  98. else
  99. {
  100. if (DataBus.AdStatus.ContainsKey(input.Device))
  101. {
  102. DataBus.AdStatus[input.Device].Close();
  103. DataBus.AdStatus.Remove(input.Device);
  104. }
  105. }
  106. }
  107. }
  108. #endregion
  109. }
  110. }