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

131 рядки
4.3 KiB

  1. using BPASmart.Model;
  2. using BPASmartClient.Helper;
  3. using Microsoft.Toolkit.Mvvm.ComponentModel;
  4. using Microsoft.Toolkit.Mvvm.Input;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Collections.ObjectModel;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace BPASmart.RecipeManagement.ViewModel
  12. {
  13. public class TechnologyProcessViewModel : ObservableObject
  14. {
  15. public static int currentItemId;
  16. public int Id { get { return _id; } set { _id = value; OnPropertyChanged(); } }
  17. private int _id = 0;
  18. public ObservableCollection<TechnologyProcessModel> technologyProcessModels { get; set; } = new ObservableCollection<TechnologyProcessModel>();
  19. public string currentRecipeName { get { return _currentRecipeName; } set { _currentRecipeName = value; OnPropertyChanged(); } }
  20. private string _currentRecipeName = string.Empty;
  21. public RelayCommand CloseWindowCommand { get; set; }
  22. public ObservableCollection<string> meterailItems { get; set; } = new ObservableCollection<string>();
  23. public RelayCommand ConfirmCommand { get; set; }
  24. public RelayCommand AddLastFlowItemCommand { get; set; }
  25. public RelayCommand AddFrontFlowItemCommand { get; set; }
  26. public RelayCommand DeleteFlowItemCommand { get; set; }
  27. public TechnologyProcessViewModel()
  28. {
  29. foreach (var item in Globle.GlobleData.recipeTechnologyProcess.recipeMaterials)
  30. {
  31. meterailItems.Add(item.Name);
  32. }
  33. ActionManage.GetInstance.Register(new Action<object>((obj) =>
  34. {
  35. if (obj != null)
  36. try
  37. {
  38. currentItemId = Convert.ToInt32(obj);
  39. }
  40. catch (Exception)
  41. {
  42. }
  43. }), "CurrentItemId");
  44. technologyProcessModels = Globle.GlobleData.recipeTechnologyProcess.TechnologyProcessModels;
  45. CloseWindowCommand = new RelayCommand(() =>
  46. {
  47. ActionManage.GetInstance.Send("CloseTechnologyProcessView");
  48. });
  49. ConfirmCommand = new RelayCommand(() =>
  50. {
  51. var res = Json<LocalRecipes>.Data.locaRecipes.FirstOrDefault(p => p.ID == Globle.GlobleData.recipeTechnologyProcess.ID);
  52. if (res != null)
  53. {
  54. res.TechnologyProcessModels = technologyProcessModels;
  55. }
  56. Json<LocalRecipes>.Save();
  57. ;
  58. ActionManage.GetInstance.Send("CloseTechnologyProcessView");
  59. });
  60. AddFrontFlowItemCommand = new RelayCommand(() =>
  61. {
  62. try
  63. {
  64. if (currentItemId == 0)
  65. {
  66. technologyProcessModels.Insert(0, new TechnologyProcessModel());
  67. }
  68. else
  69. {
  70. technologyProcessModels.Insert(currentItemId, new TechnologyProcessModel());
  71. currentItemId = currentItemId + 1;
  72. }
  73. }
  74. catch (Exception)
  75. {
  76. //throw;
  77. }
  78. });
  79. AddLastFlowItemCommand = new RelayCommand(() =>
  80. {
  81. try
  82. {
  83. if (technologyProcessModels.Count <= 0)
  84. {
  85. technologyProcessModels.Insert(0, new TechnologyProcessModel());
  86. }
  87. else if (currentItemId != 0)
  88. {
  89. technologyProcessModels.Insert(currentItemId + 1, new TechnologyProcessModel());
  90. }
  91. else
  92. {
  93. technologyProcessModels.Add(new TechnologyProcessModel());
  94. }
  95. }
  96. catch (Exception)
  97. {
  98. // throw;
  99. }
  100. });
  101. DeleteFlowItemCommand = new RelayCommand(() =>
  102. {
  103. if (technologyProcessModels.Count > 0)
  104. technologyProcessModels.RemoveAt(currentItemId);
  105. currentItemId = 0;
  106. });
  107. }
  108. }
  109. }