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

96 lines
3.5 KiB

  1. using BPASmartClient.CustomResource.UserControls;
  2. using BPASmartClient.CustomResource.UserControls.MessageShow;
  3. using BPASmartClient.Helper;
  4. using BPASmartClient.Message;
  5. using FryPot_DosingSystem.Model;
  6. using Microsoft.Toolkit.Mvvm.ComponentModel;
  7. using Microsoft.Toolkit.Mvvm.Input;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Collections.ObjectModel;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading;
  14. using System.Threading.Tasks;
  15. namespace FryPot_DosingSystem.ViewModel
  16. {
  17. internal class RecipeSetDownViewModel : ObservableObject
  18. {
  19. /// <summary>
  20. /// 配方下发
  21. /// </summary>
  22. public RelayCommand<object> RecipeSetDownCommand { get; set; }
  23. /// <summary>
  24. /// 配方一键下发
  25. /// </summary>
  26. public RelayCommand AllRecipeSetDownCommand { get; set; }
  27. public ObservableCollection<NewRecipeModel> Recipes { get; set; } = new ObservableCollection<NewRecipeModel>();
  28. public RecipeSetDownViewModel()
  29. {
  30. Json<RecipeManage>.Read();
  31. Recipes =Json<RecipeManage>.Data.Recipes;
  32. RecipeSetDownCommand = new RelayCommand<object>((Id) =>
  33. {
  34. if (Id != null && Id is string strId)
  35. {
  36. var res = Recipes.FirstOrDefault(p => p.RecipeId == strId);
  37. if (res != null)
  38. {
  39. RecipeSetDown(new NewRecipeModel[] { res });
  40. //res.RecipeSetInfo = "配方下发成功";
  41. //Task.Run(() => { Thread.Sleep(1500); res.RecipeSetInfo = string.Empty; });
  42. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方下发成功!");
  43. }
  44. else
  45. {
  46. //res.RecipeSetInfo = "配方下发失败";
  47. //Task.Run(() => { Thread.Sleep(1500); res.RecipeSetInfo = string.Empty; });
  48. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "提示", $"配方下发失败!");
  49. }
  50. }
  51. });
  52. AllRecipeSetDownCommand = new RelayCommand(() =>
  53. {
  54. if (Recipes != null)
  55. {
  56. try
  57. {
  58. RecipeSetDown(Recipes.ToArray());
  59. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"所有配方下发成功!");
  60. }
  61. catch (Exception)
  62. {
  63. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "提示", $"配方下发失败!");
  64. }
  65. //Task.Run(() =>
  66. //{
  67. // foreach (var item in Recipes)
  68. // {
  69. // item.RecipeSetInfo = "下发成功";
  70. // }
  71. // Thread.Sleep(1500);
  72. // foreach (var item in Recipes)
  73. // {
  74. // item.RecipeSetInfo = string.Empty;
  75. // }
  76. //});
  77. }
  78. });
  79. }
  80. /// <summary>
  81. /// 数据下发方法
  82. /// </summary>
  83. public void RecipeSetDown(NewRecipeModel[] recipes)
  84. {
  85. ActionManage.GetInstance.Send("RecipeSetDown", recipes);
  86. }
  87. }
  88. }