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.

107 lines
3.2 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. }
  31. #region 属性
  32. ObservableCollection<SaleLog> _Result;
  33. public ObservableCollection<SaleLog> Result
  34. {
  35. get => _Result;
  36. set => SetAndNotify(ref _Result, value);
  37. }
  38. ObservableCollection<AdDTO> _Ad;
  39. public ObservableCollection<AdDTO> Ad
  40. {
  41. get => _Ad;
  42. set => SetAndNotify(ref _Ad, value);
  43. }
  44. #endregion
  45. #region 方法
  46. private void MainThread()
  47. {
  48. ThreadManage.GetInstance().StartLong(new Action(() =>
  49. {
  50. try
  51. {
  52. //1.检测网络上下线
  53. bool network = HKHelper.GetInstance().GetNetworkState();
  54. if (network != DataBus.NetWordState)
  55. {
  56. if (network) HandyControl.Controls.Growl.InfoGlobal("网络连接成功");
  57. else HandyControl.Controls.Growl.InfoGlobal("系统已离线,请连接网络!!!");
  58. DataBus.NetWordState = network;
  59. }
  60. Thread.Sleep(3000);
  61. }
  62. catch (Exception ex)
  63. {
  64. HandyControl.Controls.Growl.InfoGlobal(ex.Message);
  65. }
  66. }), "循环状态监测线程", false);
  67. }
  68. #endregion
  69. #region 命令
  70. /// <summary>
  71. /// 广告位置
  72. /// </summary>
  73. /// <param name="input"></param>
  74. public void UpdateAction(AdDTO input)
  75. {
  76. input.IsActive = !input.IsActive;
  77. var SC = System.Windows.Forms.Screen.AllScreens.Count();
  78. if (SC >= 1)
  79. {
  80. if (input.IsActive)
  81. {
  82. if (!DataBus.AdStatus.ContainsKey(input.Device))
  83. {
  84. var win = new Views.AdWindow(input.Ad);
  85. DataBus.AdStatus.Add(input.Device, win);
  86. win.Show();
  87. }
  88. }
  89. else
  90. {
  91. if (DataBus.AdStatus.ContainsKey(input.Device))
  92. {
  93. DataBus.AdStatus[input.Device].Close();
  94. DataBus.AdStatus.Remove(input.Device);
  95. }
  96. }
  97. }
  98. }
  99. #endregion
  100. }
  101. }