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

81 regels
2.8 KiB

  1. using BPASmartClient.Helper;
  2. using BPASmartClient.Message;
  3. using FryPot_DosingSystem.Model;
  4. using FryPot_DosingSystem.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 FryPot_DosingSystem.ViewModel
  14. {
  15. internal class RecipeSetViewModel : ObservableObject
  16. {
  17. ///// <summary>
  18. ///// 配方编号
  19. ///// </summary>
  20. //private int _serialNumber;
  21. //public int SerialNumber { get { return _serialNumber; } set { _serialNumber = value;OnPropertyChanged(); } }
  22. ///// <summary>
  23. ///// 配方名称
  24. ///// </summary>
  25. //private string _recipeName;
  26. //public string RecipeName { get { return _recipeName; } set { _recipeName = value; OnPropertyChanged(); } }
  27. public ObservableCollection<NewRecipeModel> recipeModels { get; set; } = new ObservableCollection<NewRecipeModel>();
  28. public Action NewRecipe { get; set; }
  29. public Action SaveRecipe { get; set; }
  30. /// <summary>
  31. /// 编辑配方
  32. /// </summary>
  33. public RelayCommand<object> EditRecipeCommand { get; set; }
  34. /// <summary>
  35. /// 删除配方
  36. /// </summary>
  37. public RelayCommand<object> DeleteRecipeCommand { get; set; }
  38. public RecipeSetViewModel()
  39. {
  40. Json<RecipeManage>.Read();
  41. recipeModels = Json<RecipeManage>.Data.Recipes;
  42. NewRecipe = new Action(() =>
  43. {
  44. NewRecipeView nrv = new NewRecipeView();
  45. nrv.ShowDialog();
  46. MessageLog.GetInstance.Show("新建配方");
  47. });
  48. SaveRecipe = new Action(() => {
  49. Json<RecipeManage>.Save();
  50. });
  51. EditRecipeCommand = new RelayCommand<object>((Id) =>
  52. {
  53. if (Id != null)
  54. {
  55. ActionManage.GetInstance.CancelRegister("EditRecipe");
  56. NewRecipeView nrv = new NewRecipeView();
  57. ActionManage.GetInstance.Send("EditRecipe", Id);
  58. nrv.ShowDialog();
  59. }
  60. });
  61. DeleteRecipeCommand = new RelayCommand<object>((Id) =>
  62. {
  63. if (Id != null && Id is String strId)
  64. {
  65. var res= recipeModels.FirstOrDefault(p => p.RecipeId == strId);
  66. if (res != null && res is NewRecipeModel nes)
  67. {
  68. recipeModels.Remove(res);//删除配方
  69. Json<RecipeManage>.Save();//保存配方
  70. }
  71. }
  72. });
  73. }
  74. }
  75. }