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

105 satır
4.4 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; }
  37. public RelayCommand<string> StartCommand { get; set; }
  38. public RelayCommand SelectRecipesCommand { get; set; }
  39. public RecipeSendDownViewModel()
  40. {
  41. SelectedRecipes= Json<LocalRecipe>.Data.SelectedRecipes;
  42. StartCommand = new RelayCommand<string>((recipeName) =>
  43. {
  44. if (recipeName != null)
  45. {
  46. if (GVL_BigStation.IsUseLocalRecipe)
  47. {
  48. if (!MessageNotify.GetInstance.ShowDialog($"请确认,是否下发配方【{recipeName}】?"))
  49. {
  50. return;
  51. }
  52. //配方下发逻辑
  53. var res = Recipes.FirstOrDefault(p => p.RecipeName == recipeName);
  54. if (res != null)
  55. {
  56. if (!Json<RemoteRecipe>.Data.Recipes.Any(p=>p.RecipeCode==res.RecipeCode))
  57. {
  58. res.RecipesSource = RecipeSource.本地;
  59. Json<RemoteRecipe>.Data.Recipes.Add(res);
  60. MessageNotify.GetInstance.ShowRunLog($"接收手动下发配方:【{recipeName}】");
  61. MessageNotify.GetInstance.ShowUserLog($"手动下发配方:【{recipeName}】完成");
  62. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "成功", $"配方下发完成");
  63. }
  64. else
  65. {
  66. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "失败", $"配方下发失败,已下发过此配方。");
  67. }
  68. }
  69. }
  70. else
  71. {
  72. NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", $"未处于本地配方模式,无法下发配方");
  73. }
  74. }
  75. });
  76. SelectRecipesCommand = new RelayCommand(() =>
  77. {
  78. var selectView = new SelectRecipesView();
  79. selectView.ShowDialog();
  80. Json<LocalRecipe>.Data.SelectedRecipes.Clear();
  81. foreach ( var recipe in SelectRecipesViewModel.SelectRecipes )
  82. {
  83. if ( recipe != null && !Json<LocalRecipe>.Data.SelectedRecipes.Any(p=>p.RecipeCode==recipe.RecipeCode))
  84. {
  85. Json<LocalRecipe>.Data.SelectedRecipes.Add(recipe);
  86. }
  87. }
  88. //不保存会导致下次打开本地配方下发页面,会重新读取之前存储的文件。
  89. Json<LocalRecipe>.Save();
  90. });
  91. }
  92. }
  93. }