终端一体化运控平台
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

119 строки
4.0 KiB

  1. using System;
  2. using System.Collections.ObjectModel;
  3. using System.Linq;
  4. using System.Threading;
  5. using BPA.Message;
  6. using BPA.Message.Enum;
  7. using BPASmartClient.Helper;
  8. using BPASmartClient.Model;
  9. using Microsoft.Toolkit.Mvvm.ComponentModel;
  10. using Microsoft.Toolkit.Mvvm.Input;
  11. using Microsoft.Toolkit.Mvvm.Messaging;
  12. namespace BPASmartClient.ViewModel
  13. {
  14. public class OrderListDialogViewModel : ObservableObject
  15. {
  16. public static bool IsAutoClose = false;
  17. public OrderListDialogViewModel()
  18. {
  19. Init();
  20. }
  21. private void Init()
  22. {
  23. CloseButton();
  24. CancelButton();
  25. ConfirmButton();
  26. if (Json<KeepDataBase>.Data.orderLists.Count > 0)
  27. {
  28. Message.MessageLog.GetInstance.Show($"重启软件前订单剩余{Json<KeepDataBase>.Data.orderLists.Count}个");
  29. ThreadManage.GetInstance().Start(new Action(() =>
  30. {
  31. Thread.Sleep(10000);
  32. if (!IsAutoClose) WeakReferenceMessenger.Default.Send("false", "Close");
  33. }), "延时退出");
  34. }
  35. }
  36. /// <summary>
  37. /// 关闭按钮
  38. /// </summary>
  39. private void CloseButton()
  40. {
  41. CloseCommand = new RelayCommand(() =>
  42. {
  43. Json<KeepDataBase>.Data.orderLists.Clear();
  44. WeakReferenceMessenger.Default.Send("false", "Close");
  45. Json<KeepDataBase>.Save();
  46. });
  47. }
  48. /// <summary>
  49. /// 取消按钮
  50. /// </summary>
  51. private void CancelButton()
  52. {
  53. CancelCommand = new RelayCommand(() =>
  54. {
  55. Json<KeepDataBase>.Data.orderLists.Clear();
  56. WeakReferenceMessenger.Default.Send("false", "Close");
  57. Json<KeepDataBase>.Save();
  58. });
  59. }
  60. /// <summary>
  61. /// 确定按钮
  62. /// </summary>
  63. private void ConfirmButton()
  64. {
  65. ConfirmCommand = new RelayCommand(() =>
  66. {
  67. Json<KeepDataBase>.Data.orderLists.Clear();
  68. //var res = orderStatusLists.Where(p => p.IsSelected == true).ToList();
  69. var res = orderStatusLists.Where(p => p.morkOrderPushes.Where(s => s.IsSelected == true).ToList().Count > 0).ToList();
  70. if (res != null)
  71. {
  72. Json<KeepDataBase>.Data.orderLists.Clear();
  73. foreach (var item in orderStatusLists)
  74. {
  75. ObservableCollection<MorkOrder> morkOrders = new ObservableCollection<MorkOrder>();
  76. foreach (var mork in item.morkOrderPushes)
  77. {
  78. if (mork.IsSelected) morkOrders.Add(mork);
  79. }
  80. Json<KeepDataBase>.Data.orderLists.Add(new OrderData()
  81. {
  82. DeviceId = item.DeviceId,
  83. IsAllSelect = item.IsAllSelect,
  84. morkOrderPushes = morkOrders,
  85. });
  86. /*
  87. foreach (var mo in morkOrders)
  88. {
  89. DoOrderEvent de = new DoOrderEvent();
  90. de.DeviceId = int.Parse(item.DeviceId);
  91. de.MorkOrder = mo.OrderPush;
  92. EventBus.EventBus.GetInstance().Publish(de);
  93. }*/
  94. }
  95. }
  96. WeakReferenceMessenger.Default.Send("true", "Close");
  97. });
  98. }
  99. public RelayCommand CloseCommand { get; set; }
  100. public RelayCommand CancelCommand { get; set; }
  101. public RelayCommand ConfirmCommand { get; set; }
  102. public ObservableCollection<OrderData> orderStatusLists
  103. {
  104. get { return Json<KeepDataBase>.Data.orderLists; }
  105. set { Json<KeepDataBase>.Data.orderLists = value; }
  106. }
  107. }
  108. }