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

81 regels
2.6 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. }
  39. res.RecipeSetInfo = "配方下发成功";
  40. Task.Run(() => { Thread.Sleep(1500);res.RecipeSetInfo = string.Empty; });
  41. }
  42. });
  43. AllRecipeSetDownCommand = new RelayCommand(() =>
  44. {
  45. if (Recipes != null)
  46. {
  47. //foreach (var recipeModel in Recipes)
  48. //{
  49. // RecipeSetDown(recipeModel);
  50. //}
  51. RecipeSetDown(Recipes.ToArray());
  52. Task.Run(() =>
  53. {
  54. foreach (var item in Recipes)
  55. {
  56. item.RecipeSetInfo = "下发成功";
  57. }
  58. Thread.Sleep(1500);
  59. foreach (var item in Recipes)
  60. {
  61. item.RecipeSetInfo = string.Empty;
  62. }
  63. });
  64. }
  65. });
  66. }
  67. /// <summary>
  68. /// 数据下发方法
  69. /// </summary>
  70. public void RecipeSetDown(NewRecipeModel[] recipes)
  71. {
  72. ActionManage.GetInstance.Send("RecipeSetDown", recipes);
  73. }
  74. }
  75. }