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

130 рядки
5.1 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. Json<RecipeManage>.Data.Recipes.RemoveAt(Json<RecipeManage>.Data.Recipes.Count - 1);
  69. }
  70. }
  71. }
  72. }), "RecipeIsChange");
  73. NewRecipe =new RelayCommand( new Action(() =>
  74. {
  75. NewRecipeView nrv = new NewRecipeView();
  76. nrv.ShowDialog();
  77. //MessageLog.GetInstance.ShowUserLog("新建配方");
  78. }));
  79. SaveRecipe =new RelayCommand( new Action(() =>
  80. {
  81. Json<RecipeManage>.Save();
  82. count = recipeModels.Count;
  83. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方保存成功!");
  84. }));
  85. EditRecipeCommand = new RelayCommand<object>((Id) =>
  86. {
  87. if (Id != null)
  88. {
  89. ActionManage.GetInstance.CancelRegister("EditRecipe");
  90. NewRecipeView nrv = new NewRecipeView();
  91. ActionManage.GetInstance.Send("EditRecipe", Id);
  92. nrv.ShowDialog();
  93. }
  94. });
  95. DeleteRecipeCommand = new RelayCommand<object>((Id) =>
  96. {
  97. if (Id != null && Id is String strId)
  98. {
  99. var res = recipeModels.FirstOrDefault(p => p.RecipeId == strId);
  100. if (res != null && res is NewRecipeModel nes)
  101. {
  102. recipeModels.Remove(nes);//删除配方
  103. Json<RecipeManage>.Save();//保存配方
  104. count = recipeModels.Count;
  105. MessageNotify.GetInstance.ShowUserLog($"成功删除配方【{nes.RecipeName}】");
  106. }
  107. }
  108. });
  109. //工艺流程操作
  110. OperateFlowProcess = new RelayCommand<string>((recipeName) =>
  111. {
  112. if (recipeName != null && recipeName != string.Empty && recipeName != "")
  113. {
  114. ActionManage.GetInstance.CancelRegister("EditFlowProcess");
  115. FlowProcessView fps = new FlowProcessView();
  116. ActionManage.GetInstance.Send("EditFlowProcess", recipeName);
  117. fps.ShowDialog();
  118. }
  119. });
  120. }
  121. }
  122. }