终端一体化运控平台
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

96 lines
3.4 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. }
  43. else
  44. {
  45. //res.RecipeSetInfo = "配方下发失败";
  46. //Task.Run(() => { Thread.Sleep(1500); res.RecipeSetInfo = string.Empty; });
  47. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "提示", $"配方下发失败!");
  48. }
  49. }
  50. });
  51. AllRecipeSetDownCommand = new RelayCommand(() =>
  52. {
  53. if (Recipes != null)
  54. {
  55. try
  56. {
  57. RecipeSetDown(Recipes.ToArray());
  58. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"所有配方下发成功!");
  59. }
  60. catch (Exception)
  61. {
  62. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "提示", $"配方下发失败!");
  63. }
  64. //Task.Run(() =>
  65. //{
  66. // foreach (var item in Recipes)
  67. // {
  68. // item.RecipeSetInfo = "下发成功";
  69. // }
  70. // Thread.Sleep(1500);
  71. // foreach (var item in Recipes)
  72. // {
  73. // item.RecipeSetInfo = string.Empty;
  74. // }
  75. //});
  76. }
  77. });
  78. }
  79. /// <summary>
  80. /// 数据下发方法
  81. /// </summary>
  82. public void RecipeSetDown(NewRecipeModel[] recipes)
  83. {
  84. ActionManage.GetInstance.Send("RecipeSetDown", recipes);
  85. }
  86. }
  87. }