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

125 lines
4.6 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<string> OperateFlowProcess { get; set; }
  35. /// <summary>
  36. /// 编辑配方
  37. /// </summary>
  38. public RelayCommand<object> EditRecipeCommand { get; set; }
  39. /// <summary>
  40. /// 删除配方
  41. /// </summary>
  42. public RelayCommand<object> DeleteRecipeCommand { get; set; }
  43. public RecipeSetViewModel()
  44. {
  45. Json<RecipeManage>.Read();
  46. recipeModels =Json<RecipeManage>.Data.Recipes;
  47. int count = recipeModels.Count;
  48. bool sign = false;
  49. ActionManage.GetInstance.CancelRegister("RecipeIsChange");
  50. ActionManage.GetInstance.Register(new Action(() =>
  51. {
  52. if (!sign)
  53. {
  54. bool b = Json<RecipeManage>.Data.Recipes.Count == count ? true : false;
  55. if (!b)
  56. {
  57. MessageBoxResult result = MessageBox.Show("配方数据未保存,是否保存", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Information);
  58. if (result == MessageBoxResult.OK)
  59. {
  60. Json<RecipeManage>.Save();//保存配方
  61. count = recipeModels.Count;
  62. }
  63. else
  64. {
  65. sign = true;
  66. }
  67. }
  68. }
  69. }), "RecipeIsChange");
  70. NewRecipe =new RelayCommand( new Action(() =>
  71. {
  72. NewRecipeView nrv = new NewRecipeView();
  73. nrv.ShowDialog();
  74. //MessageLog.GetInstance.ShowUserLog("新建配方");
  75. }));
  76. SaveRecipe =new RelayCommand( new Action(() =>
  77. {
  78. Json<RecipeManage>.Save();
  79. count = recipeModels.Count;
  80. }));
  81. EditRecipeCommand = new RelayCommand<object>((Id) =>
  82. {
  83. if (Id != null)
  84. {
  85. ActionManage.GetInstance.CancelRegister("EditRecipe");
  86. NewRecipeView nrv = new NewRecipeView();
  87. ActionManage.GetInstance.Send("EditRecipe", Id);
  88. nrv.ShowDialog();
  89. }
  90. });
  91. DeleteRecipeCommand = new RelayCommand<object>((Id) =>
  92. {
  93. if (Id != null && Id is String strId)
  94. {
  95. var res = recipeModels.FirstOrDefault(p => p.RecipeId == strId);
  96. if (res != null && res is NewRecipeModel nes)
  97. {
  98. recipeModels.Remove(res);//删除配方
  99. Json<RecipeManage>.Save();//保存配方
  100. count = recipeModels.Count;
  101. }
  102. }
  103. });
  104. //工艺流程操作
  105. OperateFlowProcess = new RelayCommand<string>((recipeName) =>
  106. {
  107. if (recipeName != null && recipeName != string.Empty && recipeName != "")
  108. {
  109. ActionManage.GetInstance.CancelRegister("EditFlowProcess");
  110. FlowProcessView fps = new FlowProcessView();
  111. ActionManage.GetInstance.Send("EditFlowProcess", recipeName);
  112. fps.ShowDialog();
  113. }
  114. });
  115. }
  116. }
  117. }