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

61 строка
1.9 KiB

  1. using BPASmart.Model.配方;
  2. using BPASmartClient.Helper;
  3. using BPASmartClient.RecipeManagement.View;
  4. using Microsoft.Toolkit.Mvvm.ComponentModel;
  5. using Microsoft.Toolkit.Mvvm.Input;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Collections.ObjectModel;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace BPASmart.RecipeManagement.ViewModel
  13. {
  14. public class RecipeManagerViewModel:ObservableObject
  15. {
  16. public ObservableCollection<Recipes> RecipeList { get; set; } = Json<LocalRecipes>.Data.locaRecipes;
  17. public RelayCommand CreateRecipeCommand { get; set; }
  18. public RelayCommand<object> EditRecipeCommand { get; set; }
  19. public RelayCommand<object> DeleteRecipeCommand { get; set; }
  20. private void EditRecipe(object o)
  21. {
  22. if (o == null) return;
  23. if (o is int item && item >= 0)
  24. {
  25. Globle.GlobleData.ChangeRecipes = new Recipes();
  26. Globle.GlobleData.ChangeRecipes = RecipeList[item];
  27. RecipesConfigure recipesConfigure = new RecipesConfigure();
  28. recipesConfigure.ShowDialog();
  29. }
  30. }
  31. private void DeleteRecipe(object o)
  32. {
  33. if (o == null) return;
  34. if (o is int i && i >= 0)
  35. {
  36. RecipeList.RemoveAt(i);
  37. Json<LocalRecipes>.Save();
  38. }
  39. }
  40. public RecipeManagerViewModel()
  41. {
  42. CreateRecipeCommand = new RelayCommand(() =>
  43. {
  44. Globle.GlobleData.ChangeRecipes = null;
  45. RecipesConfigure recipesConfigure = new RecipesConfigure();
  46. recipesConfigure.ShowDialog();
  47. });
  48. EditRecipeCommand = new RelayCommand<object>(EditRecipe);
  49. DeleteRecipeCommand = new RelayCommand<object>(DeleteRecipe);
  50. }
  51. }
  52. }