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

83 lines
2.6 KiB

  1. using BPASmart.Model;
  2. using BPASmart.RecipeManagement.View;
  3. using BPASmartClient.Helper;
  4. using BPASmartClient.RecipeManagement.View;
  5. using Microsoft.Toolkit.Mvvm.ComponentModel;
  6. using Microsoft.Toolkit.Mvvm.Input;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Collections.ObjectModel;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace BPASmart.RecipeManagement.ViewModel
  14. {
  15. public class RecipeManagerViewModel : ObservableObject
  16. {
  17. public ObservableCollection<Recipes> RecipeList { get; set; } = Json<LocalRecipes>.Data.locaRecipes;
  18. public RelayCommand CreateRecipeCommand { get; set; }
  19. public RelayCommand<object> EditRecipeCommand { get; set; }
  20. public RelayCommand<object> DeleteRecipeCommand { get; set; }
  21. public RelayCommand<object> PecipeSettingCommand { get; set; }
  22. private void EditRecipe(object o)
  23. {
  24. if (o == null) return;
  25. if (o is int item && item >= 0)
  26. {
  27. Globle.GlobleData.ChangeRecipes = new Recipes();
  28. Globle.GlobleData.ChangeRecipes = RecipeList[item];
  29. RecipesConfigure recipesConfigure = new RecipesConfigure();
  30. recipesConfigure.ShowDialog();
  31. }
  32. }
  33. private void DeleteRecipe(object o)
  34. {
  35. if (o == null) return;
  36. if (o is int i && i >= 0)
  37. {
  38. RecipeList.RemoveAt(i);
  39. Json<LocalRecipes>.Save();
  40. }
  41. }
  42. private void PecipeSetting(object o)
  43. {
  44. if (o == null) return;
  45. if (o is string id)
  46. {
  47. var res = Json<LocalRecipes>.Data.locaRecipes.FirstOrDefault(p => p.ID == id);
  48. if (res != null)
  49. {
  50. Globle.GlobleData.recipeTechnologyProcess = null;
  51. Globle.GlobleData.recipeTechnologyProcess = res;
  52. TechnologyProcess technologyProcess = new TechnologyProcess();
  53. technologyProcess.ShowDialog();
  54. }
  55. }
  56. }
  57. public RecipeManagerViewModel()
  58. {
  59. CreateRecipeCommand = new RelayCommand(() =>
  60. {
  61. Globle.GlobleData.ChangeRecipes = null;
  62. RecipesConfigure recipesConfigure = new RecipesConfigure();
  63. recipesConfigure.ShowDialog();
  64. });
  65. EditRecipeCommand = new RelayCommand<object>(EditRecipe);
  66. DeleteRecipeCommand = new RelayCommand<object>(DeleteRecipe);
  67. PecipeSettingCommand = new RelayCommand<object>(PecipeSetting);
  68. }
  69. }
  70. }