终端一体化运控平台
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

96 satır
3.3 KiB

  1. using BPASmartClient.CustomResource.UserControls;
  2. using BPASmartClient.CustomResource.UserControls.MessageShow;
  3. using BPA.Helper;
  4. using FryPot_DosingSystem.Model;
  5. using BPA.Helper;
  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 : NotifyBase
  16. {
  17. /// <summary>
  18. /// 配方下发
  19. /// </summary>
  20. public BPARelayCommand<object> RecipeSetDownCommand { get; set; }
  21. /// <summary>
  22. /// 配方一键下发
  23. /// </summary>
  24. public BPARelayCommand 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 BPARelayCommand<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. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "提示", $"配方下发失败!");
  46. }
  47. }
  48. });
  49. AllRecipeSetDownCommand = new BPARelayCommand(() =>
  50. {
  51. if (Recipes != null)
  52. {
  53. try
  54. {
  55. RecipeSetDown(Recipes.ToArray());
  56. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"所有配方下发成功!");
  57. }
  58. catch (Exception)
  59. {
  60. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "提示", $"配方下发失败!");
  61. }
  62. //Task.Run(() =>
  63. //{
  64. // foreach (var item in Recipes)
  65. // {
  66. // item.RecipeSetInfo = "下发成功";
  67. // }
  68. // Thread.Sleep(1500);
  69. // foreach (var item in Recipes)
  70. // {
  71. // item.RecipeSetInfo = string.Empty;
  72. // }
  73. //});
  74. }
  75. });
  76. }
  77. /// <summary>
  78. /// 数据下发方法
  79. /// </summary>
  80. public void RecipeSetDown(NewRecipeModel[] recipes)
  81. {
  82. ActionManage.GetInstance.Send("RecipeSetDown", recipes);
  83. }
  84. }
  85. }