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

112 строки
3.6 KiB

  1. using BPASmart.Model;
  2. using BPASmart.RecipeManagement.View;
  3. using BPASmartClient.CustomResource.UserControls;
  4. using BPASmartClient.CustomResource.UserControls.MessageShow;
  5. using BPASmartClient.Helper;
  6. using BPASmartClient.RecipeManagement.View;
  7. using Microsoft.Toolkit.Mvvm.ComponentModel;
  8. using Microsoft.Toolkit.Mvvm.Input;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Collections.ObjectModel;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows;
  16. namespace BPASmart.RecipeManagement.ViewModel
  17. {
  18. public class RecipeManagerViewModel : ObservableObject
  19. {
  20. public ObservableCollection<Recipes> RecipeList { get; set; } = Json<LocalRecipes>.Data.locaRecipes;
  21. /// <summary>
  22. /// 创建配方
  23. /// </summary>
  24. public RelayCommand CreateRecipeCommand { get; set; }
  25. public RelayCommand<object> EditRecipeCommand { get; set; }
  26. public RelayCommand<object> DeleteRecipeCommand { get; set; }
  27. /// <summary>
  28. /// 配方工艺
  29. /// </summary>
  30. public RelayCommand<object> PecipeSettingCommand { get; set; }
  31. /// <summary>
  32. /// 配方下发
  33. /// </summary>
  34. public RelayCommand<object> PecipeStartCommand { get; set; }
  35. private void EditRecipe(object o)
  36. {
  37. if (o == null) return;
  38. if (o is int item && item >= 0)
  39. {
  40. Globle.GlobleData.ChangeRecipes = new Recipes();
  41. Globle.GlobleData.ChangeRecipes = RecipeList[item];
  42. RecipesConfigure recipesConfigure = new RecipesConfigure();
  43. recipesConfigure.ShowDialog();
  44. }
  45. }
  46. private void DeleteRecipe(object o)
  47. {
  48. if (o == null) return;
  49. if (o is int i && i >= 0)
  50. {
  51. RecipeList.RemoveAt(i);
  52. Json<LocalRecipes>.Save();
  53. }
  54. }
  55. private void PecipeSetting(object o)
  56. {
  57. if (o == null) return;
  58. if (o is string id)
  59. {
  60. var res = Json<LocalRecipes>.Data.locaRecipes.FirstOrDefault(p => p.ID == id);
  61. if (res != null)
  62. {
  63. Globle.GlobleData.recipeTechnologyProcess = null;
  64. Globle.GlobleData.recipeTechnologyProcess = res;
  65. TechnologyProcess technologyProcess = new TechnologyProcess();
  66. technologyProcess.ShowDialog();
  67. }
  68. }
  69. }
  70. private void PecipeStart(object o)
  71. {
  72. if (o == null) return;
  73. if (o is string id)
  74. {
  75. var res = Json<LocalRecipes>.Data.locaRecipes.FirstOrDefault(p => p.ID == id);
  76. if (res != null)
  77. {
  78. //下发配方
  79. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "提示", $"配方下发成功!");
  80. }
  81. }
  82. }
  83. public RecipeManagerViewModel()
  84. {
  85. CreateRecipeCommand = new RelayCommand(() =>
  86. {
  87. Globle.GlobleData.ChangeRecipes = null;
  88. RecipesConfigure recipesConfigure = new RecipesConfigure();
  89. recipesConfigure.ShowDialog();
  90. });
  91. EditRecipeCommand = new RelayCommand<object>(EditRecipe);
  92. DeleteRecipeCommand = new RelayCommand<object>(DeleteRecipe);
  93. PecipeSettingCommand = new RelayCommand<object>(PecipeSetting);
  94. PecipeStartCommand = new RelayCommand<object>(PecipeStart);
  95. }
  96. }
  97. }