终端一体化运控平台
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

116 lines
3.3 KiB

  1. using System;
  2. using System.Collections.ObjectModel;
  3. using System.Linq;
  4. using System.Threading;
  5. using BPA.Message.Enum;
  6. using BPASmartClient.Helper;
  7. using BPASmartClient.Model;
  8. using Microsoft.Toolkit.Mvvm.ComponentModel;
  9. using Microsoft.Toolkit.Mvvm.Input;
  10. using Microsoft.Toolkit.Mvvm.Messaging;
  11. namespace BPASmartClient.ViewModel
  12. {
  13. public class OrderListDialogViewModel : ObservableObject
  14. {
  15. public static bool IsAutoClose = false;
  16. public OrderListDialogViewModel()
  17. {
  18. Init();
  19. }
  20. private void Init()
  21. {
  22. CloseButton();
  23. CancelButton();
  24. ConfirmButton();
  25. if (Json<KeepDataBase>.Data.orderLists.Count > 0)
  26. {
  27. ThreadManage.GetInstance().Start(new Action(() =>
  28. {
  29. Thread.Sleep(10000);
  30. if (!IsAutoClose) WeakReferenceMessenger.Default.Send("false", "Close");
  31. }), "延时退出");
  32. }
  33. AllSelected = true;
  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. var res = orderStatusLists.Where(p => p.IsSelected == true).ToList();
  67. if (res != null)
  68. {
  69. Json<KeepDataBase>.Data.orderLists.Clear();
  70. foreach (var item in res)
  71. {
  72. item.OrderStatus = ORDER_STATUS.WAIT;
  73. Json<KeepDataBase>.Data.orderLists.Add(item);
  74. }
  75. }
  76. WeakReferenceMessenger.Default.Send("true", "Close");
  77. });
  78. }
  79. /// <summary>
  80. /// 全选标志
  81. /// </summary>
  82. public bool AllSelected
  83. {
  84. get { return _mAllSelected; }
  85. set
  86. {
  87. _mAllSelected = value;
  88. OnPropertyChanged();
  89. for (int i = 0; i < orderStatusLists.Count; i++)
  90. {
  91. orderStatusLists.ElementAt(i).IsSelected = value;
  92. }
  93. }
  94. }
  95. private bool _mAllSelected = true;
  96. public RelayCommand CloseCommand { get; set; }
  97. public RelayCommand CancelCommand { get; set; }
  98. public RelayCommand ConfirmCommand { get; set; }
  99. public ObservableCollection<OrderData> orderStatusLists
  100. {
  101. get { return Json<KeepDataBase>.Data.orderLists; }
  102. set { Json<KeepDataBase>.Data.orderLists = value; }
  103. }
  104. }
  105. }