终端一体化运控平台
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

118 satır
3.9 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. ThreadManage.GetInstance().Start(new Action(() =>
  29. {
  30. Thread.Sleep(10000);
  31. if (!IsAutoClose) WeakReferenceMessenger.Default.Send("false", "Close");
  32. }), "延时退出");
  33. }
  34. }
  35. /// <summary>
  36. /// 关闭按钮
  37. /// </summary>
  38. private void CloseButton()
  39. {
  40. CloseCommand = new RelayCommand(() =>
  41. {
  42. Json<KeepDataBase>.Data.orderLists.Clear();
  43. WeakReferenceMessenger.Default.Send("false", "Close");
  44. Json<KeepDataBase>.Save();
  45. });
  46. }
  47. /// <summary>
  48. /// 取消按钮
  49. /// </summary>
  50. private void CancelButton()
  51. {
  52. CancelCommand = new RelayCommand(() =>
  53. {
  54. Json<KeepDataBase>.Data.orderLists.Clear();
  55. WeakReferenceMessenger.Default.Send("false", "Close");
  56. Json<KeepDataBase>.Save();
  57. });
  58. }
  59. /// <summary>
  60. /// 确定按钮
  61. /// </summary>
  62. private void ConfirmButton()
  63. {
  64. ConfirmCommand = new RelayCommand(() =>
  65. {
  66. Json<KeepDataBase>.Data.orderLists.Clear();
  67. //var res = orderStatusLists.Where(p => p.IsSelected == true).ToList();
  68. var res = orderStatusLists.Where(p => p.morkOrderPushes.Where(s => s.IsSelected == true).ToList().Count > 0).ToList();
  69. if (res != null)
  70. {
  71. Json<KeepDataBase>.Data.orderLists.Clear();
  72. foreach (var item in orderStatusLists)
  73. {
  74. ObservableCollection<MorkOrder> morkOrders = new ObservableCollection<MorkOrder>();
  75. foreach (var mork in item.morkOrderPushes)
  76. {
  77. if (mork.IsSelected) morkOrders.Add(mork);
  78. }
  79. Json<KeepDataBase>.Data.orderLists.Add(new OrderData()
  80. {
  81. DeviceId = item.DeviceId,
  82. IsAllSelect = item.IsAllSelect,
  83. morkOrderPushes = morkOrders,
  84. });
  85. /*
  86. foreach (var mo in morkOrders)
  87. {
  88. DoOrderEvent de = new DoOrderEvent();
  89. de.DeviceId = int.Parse(item.DeviceId);
  90. de.MorkOrder = mo.OrderPush;
  91. EventBus.EventBus.GetInstance().Publish(de);
  92. }*/
  93. }
  94. }
  95. WeakReferenceMessenger.Default.Send("true", "Close");
  96. });
  97. }
  98. public RelayCommand CloseCommand { get; set; }
  99. public RelayCommand CancelCommand { get; set; }
  100. public RelayCommand ConfirmCommand { get; set; }
  101. public ObservableCollection<OrderData> orderStatusLists
  102. {
  103. get { return Json<KeepDataBase>.Data.orderLists; }
  104. set { Json<KeepDataBase>.Data.orderLists = value; }
  105. }
  106. }
  107. }