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

87 rivejä
2.9 KiB

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