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

121 rivejä
5.2 KiB

  1. using BPASmartClient.CustomResource.Pages.Model;
  2. using BPASmartClient.CustomResource.UserControls;
  3. using BPASmartClient.CustomResource.UserControls.MessageShow;
  4. using BPASmartClient.Helper;
  5. using BPASmartClient.JXJFoodBigStation.Model;
  6. using BPASmartClient.JXJFoodBigStation.Model.Siemens;
  7. using BPASmartClient.JXJFoodBigStation.View;
  8. using Microsoft.Toolkit.Mvvm.ComponentModel;
  9. using Microsoft.Toolkit.Mvvm.Input;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Collections.ObjectModel;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. namespace BPASmartClient.JXJFoodBigStation.ViewModel
  17. {
  18. internal class RecipeSendDownViewModel:ObservableObject
  19. {
  20. public ObservableCollection<RecipeData> Recipes { get; set; } = Json<LocalRecipe>.Data.Recipes;
  21. /// <summary>
  22. /// 当前正在制作的配方
  23. /// </summary>
  24. public static ObservableCollection<RawMaterial> recipeProcesses { get; set; } = new ObservableCollection<RawMaterial>();
  25. /// <summary>
  26. /// 等待制作的配方
  27. /// </summary>
  28. public static ObservableCollection<RecipeData> UserTreeWait { get; set; } = new ObservableCollection<RecipeData>();
  29. /// <summary>
  30. /// 已完成的配方
  31. /// </summary>
  32. public static ObservableCollection<RecipeData> UserTreeCompelete { get; set; } = new ObservableCollection<RecipeData>();
  33. /// <summary>
  34. /// 筛选后的配方列表。
  35. /// </summary>
  36. public static ObservableCollection<RecipeData> SelectedRecipes { get; set; } = new ObservableCollection<RecipeData>();
  37. public RelayCommand<string> StartCommand { get; set; }
  38. public RelayCommand SelectRecipesCommand { get; set; }
  39. public RecipeSendDownViewModel()
  40. {
  41. var tempcoll = new ObservableCollection<RecipeData>();
  42. foreach (var item in Json<LocalRecipe>.Data.SelectedRecipes)
  43. {
  44. if (!Json<LocalRecipe>.Data.Recipes.Any(p => p.RecipeCode.Equals(item.RecipeCode)
  45. && p.RecipeName.Equals(item.RecipeName) && p.IsWashingBarrel == item.IsWashingBarrel
  46. && p.TrayCode == item.TrayCode))
  47. {
  48. tempcoll.Add(item);
  49. }
  50. }
  51. foreach (var item in tempcoll)
  52. {
  53. Json<LocalRecipe>.Data.SelectedRecipes.Remove(item);
  54. }
  55. Json<LocalRecipe>.Save();
  56. tempcoll.Clear();
  57. SelectedRecipes = Json<LocalRecipe>.Data.SelectedRecipes;
  58. StartCommand = new RelayCommand<string>((recipeName) =>
  59. {
  60. if (recipeName != null)
  61. {
  62. if (GVL_BigStation.IsUseLocalRecipe)
  63. {
  64. if (!MessageNotify.GetInstance.ShowDialog($"请确认,是否下发配方【{recipeName}】?"))
  65. {
  66. return;
  67. }
  68. //配方下发逻辑
  69. var res = Recipes.FirstOrDefault(p => p.RecipeName == recipeName);
  70. if (res != null)
  71. {
  72. if (!Json<RemoteRecipe>.Data.Recipes.Any(p=>p.RecipeCode==res.RecipeCode))
  73. {
  74. res.RecipesSource = RecipeSource.本地;
  75. Json<RemoteRecipe>.Data.Recipes.Add(res);
  76. MessageNotify.GetInstance.ShowRunLog($"接收手动下发配方:【{recipeName}】");
  77. MessageNotify.GetInstance.ShowUserLog($"手动下发配方:【{recipeName}】完成");
  78. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "成功", $"配方下发完成");
  79. }
  80. else
  81. {
  82. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "失败", $"配方下发失败,已下发过此配方。");
  83. }
  84. }
  85. }
  86. else
  87. {
  88. NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", $"未处于本地配方模式,无法下发配方");
  89. }
  90. }
  91. });
  92. SelectRecipesCommand = new RelayCommand(() =>
  93. {
  94. var selectView = new SelectRecipesView();
  95. selectView.ShowDialog();
  96. SelectedRecipes.Clear();
  97. Json<LocalRecipe>.Data.SelectedRecipes.Clear();
  98. foreach ( var recipe in SelectRecipesViewModel.SelectRecipes )
  99. {
  100. if ( recipe != null && !Json<LocalRecipe>.Data.SelectedRecipes.Any(p=>p.RecipeCode==recipe.RecipeCode))
  101. {
  102. Json<LocalRecipe>.Data.SelectedRecipes.Add(recipe);
  103. }
  104. }
  105. //不保存会导致下次打开本地配方下发页面,会重新读取之前存储的文件。
  106. Json<LocalRecipe>.Save();
  107. });
  108. }
  109. }
  110. }