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

109 lines
4.0 KiB

  1. using BPASmartClient.CustomResource.Pages.Model;
  2. using BPASmartClient.Helper;
  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. using System.Windows;
  14. namespace FryPot_DosingSystem.ViewModel
  15. {
  16. internal class RecipeSetViewModel : ObservableObject
  17. {
  18. ///// <summary>
  19. ///// 配方编号
  20. ///// </summary>
  21. //private int _serialNumber;
  22. //public int SerialNumber { get { return _serialNumber; } set { _serialNumber = value;OnPropertyChanged(); } }
  23. ///// <summary>
  24. ///// 配方名称
  25. ///// </summary>
  26. //private string _recipeName;
  27. //public string RecipeName { get { return _recipeName; } set { _recipeName = value; OnPropertyChanged(); } }
  28. public ObservableCollection<NewRecipeModel> recipeModels { get; set; } = new ObservableCollection<NewRecipeModel>();
  29. public RelayCommand NewRecipe { get; set; }
  30. public RelayCommand SaveRecipe { get; set; }
  31. /// <summary>
  32. /// 编辑配方
  33. /// </summary>
  34. public RelayCommand<object> EditRecipeCommand { get; set; }
  35. /// <summary>
  36. /// 删除配方
  37. /// </summary>
  38. public RelayCommand<object> DeleteRecipeCommand { get; set; }
  39. public RecipeSetViewModel()
  40. {
  41. Json<RecipeManage>.Read();
  42. recipeModels =Json<RecipeManage>.Data.Recipes;
  43. int count = recipeModels.Count;
  44. bool sign = false;
  45. ActionManage.GetInstance.CancelRegister("RecipeIsChange");
  46. ActionManage.GetInstance.Register(new Action(() =>
  47. {
  48. if (!sign)
  49. {
  50. bool b = Json<RecipeManage>.Data.Recipes.Count == count ? true : false;
  51. if (!b)
  52. {
  53. MessageBoxResult result = MessageBox.Show("配方数据未保存,是否保存", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Information);
  54. if (result == MessageBoxResult.OK)
  55. {
  56. Json<RecipeManage>.Save();//保存配方
  57. count = recipeModels.Count;
  58. }
  59. else
  60. {
  61. sign = true;
  62. }
  63. }
  64. }
  65. }), "RecipeIsChange");
  66. NewRecipe =new RelayCommand( new Action(() =>
  67. {
  68. NewRecipeView nrv = new NewRecipeView();
  69. nrv.ShowDialog();
  70. //MessageLog.GetInstance.ShowUserLog("新建配方");
  71. }));
  72. SaveRecipe =new RelayCommand( new Action(() =>
  73. {
  74. Json<RecipeManage>.Save();
  75. count = recipeModels.Count;
  76. }));
  77. EditRecipeCommand = new RelayCommand<object>((Id) =>
  78. {
  79. if (Id != null)
  80. {
  81. ActionManage.GetInstance.CancelRegister("EditRecipe");
  82. NewRecipeView nrv = new NewRecipeView();
  83. ActionManage.GetInstance.Send("EditRecipe", Id);
  84. nrv.ShowDialog();
  85. }
  86. });
  87. DeleteRecipeCommand = new RelayCommand<object>((Id) =>
  88. {
  89. if (Id != null && Id is String strId)
  90. {
  91. var res = recipeModels.FirstOrDefault(p => p.RecipeId == strId);
  92. if (res != null && res is NewRecipeModel nes)
  93. {
  94. recipeModels.Remove(res);//删除配方
  95. Json<RecipeManage>.Save();//保存配方
  96. count = recipeModels.Count;
  97. }
  98. }
  99. });
  100. }
  101. }
  102. }