Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

118 řádky
3.6 KiB

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