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

TechnologyProcessViewModel.cs 4.3 KiB

2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
2 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. }