终端一体化运控平台
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.
 
 
 

110 line
3.5 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. }
  87. WeakReferenceMessenger.Default.Send("true", "Close");
  88. });
  89. }
  90. public RelayCommand CloseCommand { get; set; }
  91. public RelayCommand CancelCommand { get; set; }
  92. public RelayCommand ConfirmCommand { get; set; }
  93. public ObservableCollection<OrderData> orderStatusLists
  94. {
  95. get { return Json<KeepDataBase>.Data.orderLists; }
  96. set { Json<KeepDataBase>.Data.orderLists = value; }
  97. }
  98. }
  99. }