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

128 lines
4.9 KiB

  1. using BPASmartClient.CustomResource.Pages.Model;
  2. using BPASmartClient.CustomResource.UserControls;
  3. using BPASmartClient.CustomResource.UserControls.MessageShow;
  4. using BPASmartClient.Helper;
  5. using FryPot_DosingSystem.Model;
  6. using FryPot_DosingSystem.View;
  7. using Microsoft.Toolkit.Mvvm.ComponentModel;
  8. using Microsoft.Toolkit.Mvvm.Input;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Collections.ObjectModel;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows;
  16. namespace FryPot_DosingSystem.ViewModel
  17. {
  18. internal class RecipeSetViewModel : ObservableObject
  19. {
  20. ///// <summary>
  21. ///// 配方编号
  22. ///// </summary>
  23. //private int _serialNumber;
  24. //public int SerialNumber { get { return _serialNumber; } set { _serialNumber = value;OnPropertyChanged(); } }
  25. ///// <summary>
  26. ///// 配方名称
  27. ///// </summary>
  28. //private string _recipeName;
  29. //public string RecipeName { get { return _recipeName; } set { _recipeName = value; OnPropertyChanged(); } }
  30. public ObservableCollection<NewRecipeModel> recipeModels { get; set; } = new ObservableCollection<NewRecipeModel>();
  31. public RelayCommand NewRecipe { get; set; }
  32. public RelayCommand SaveRecipe { get; set; }
  33. /// <summary>
  34. /// 工艺操作
  35. /// </summary>
  36. public RelayCommand<string> OperateFlowProcess { get; set; }
  37. /// <summary>
  38. /// 编辑配方
  39. /// </summary>
  40. public RelayCommand<object> EditRecipeCommand { get; set; }
  41. /// <summary>
  42. /// 删除配方
  43. /// </summary>
  44. public RelayCommand<object> DeleteRecipeCommand { get; set; }
  45. public RecipeSetViewModel()
  46. {
  47. Json<RecipeManage>.Read();
  48. recipeModels =Json<RecipeManage>.Data.Recipes;
  49. int count = recipeModels.Count;
  50. bool sign = false;
  51. ActionManage.GetInstance.CancelRegister("RecipeIsChange");
  52. ActionManage.GetInstance.RegisterAsync(new Action(() =>
  53. {
  54. if (!sign)
  55. {
  56. bool b = Json<RecipeManage>.Data.Recipes.Count == count ? true : false;
  57. if (!b)
  58. {
  59. MessageBoxResult result = MessageBox.Show("配方数据未保存,是否保存", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Information);
  60. if (result == MessageBoxResult.OK)
  61. {
  62. Json<RecipeManage>.Save();//保存配方
  63. count = recipeModels.Count;
  64. }
  65. else
  66. {
  67. sign = true;
  68. }
  69. }
  70. }
  71. }), "RecipeIsChange");
  72. NewRecipe =new RelayCommand( new Action(() =>
  73. {
  74. NewRecipeView nrv = new NewRecipeView();
  75. nrv.ShowDialog();
  76. //MessageLog.GetInstance.ShowUserLog("新建配方");
  77. }));
  78. SaveRecipe =new RelayCommand( new Action(() =>
  79. {
  80. Json<RecipeManage>.Save();
  81. count = recipeModels.Count;
  82. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方保存成功!");
  83. }));
  84. EditRecipeCommand = new RelayCommand<object>((Id) =>
  85. {
  86. if (Id != null)
  87. {
  88. ActionManage.GetInstance.CancelRegister("EditRecipe");
  89. NewRecipeView nrv = new NewRecipeView();
  90. ActionManage.GetInstance.Send("EditRecipe", Id);
  91. nrv.ShowDialog();
  92. }
  93. });
  94. DeleteRecipeCommand = new RelayCommand<object>((Id) =>
  95. {
  96. if (Id != null && Id is String strId)
  97. {
  98. var res = recipeModels.FirstOrDefault(p => p.RecipeId == strId);
  99. if (res != null && res is NewRecipeModel nes)
  100. {
  101. recipeModels.Remove(res);//删除配方
  102. Json<RecipeManage>.Save();//保存配方
  103. count = recipeModels.Count;
  104. }
  105. }
  106. });
  107. //工艺流程操作
  108. OperateFlowProcess = new RelayCommand<string>((recipeName) =>
  109. {
  110. if (recipeName != null && recipeName != string.Empty && recipeName != "")
  111. {
  112. ActionManage.GetInstance.CancelRegister("EditFlowProcess");
  113. FlowProcessView fps = new FlowProcessView();
  114. ActionManage.GetInstance.Send("EditFlowProcess", recipeName);
  115. fps.ShowDialog();
  116. }
  117. });
  118. }
  119. }
  120. }