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

113 lines
4.6 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.Toolkit.Mvvm.ComponentModel;
  7. using System.Collections.Concurrent;
  8. using System.Collections.ObjectModel;
  9. using System.Windows;
  10. using BPASmartClient.Helper;
  11. using Microsoft.Toolkit.Mvvm.Input;
  12. using BPASmartClient.JXJFoodBigStation.Model;
  13. using BPASmartClient.JXJFoodBigStation.View;
  14. using BPASmartClient.CustomResource.UserControls;
  15. using BPASmartClient.CustomResource.UserControls.Model;
  16. using BPASmartClient.CustomResource.UserControls.Enum;
  17. using System.Windows.Media;
  18. using BPASmartClient.CustomResource.UserControls.MessageShow;
  19. using BPASmartClient.CustomResource.Pages.Model;
  20. using BPASmartClient.JXJFoodBigStation.Model.Siemens;
  21. namespace BPASmartClient.JXJFoodBigStation.ViewModel
  22. {
  23. public class RecipeReceiveViewModel : ObservableObject
  24. {
  25. public ObservableCollection<RawMaterial> RawMaterials { get; set; } = new ObservableCollection<RawMaterial>();
  26. public RecipeReceiveViewModel()
  27. {
  28. IsUseLocalRecipe = GVL_BigStation.IsUseLocalRecipe;
  29. Json<LocalRecipe>.Read();
  30. Recipes = Json<LocalRecipe>.Data.Recipes;
  31. DetailsCommand = new RelayCommand<object>((o) =>
  32. {
  33. if (o != null && o is string num)
  34. {
  35. ActionManage.GetInstance.CancelRegister("RecipeInfo");
  36. RecipeInfosView nrv = new RecipeInfosView();
  37. var res = Json<LocalRecipe>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == num);
  38. ActionManage.GetInstance.Send("RecipeInfo", res);
  39. nrv.Show();
  40. MessageNotify.GetInstance.ShowUserLog($"查看配方——{res.RecipeName}");
  41. }
  42. });
  43. NewRecipe = new RelayCommand(() =>
  44. {
  45. RecipeInfosView nrv = new RecipeInfosView();
  46. nrv.ShowDialog();
  47. });
  48. //模拟配方
  49. //NewSimulateRecipe = new RelayCommand(() =>
  50. //{
  51. // RawMaterials.Clear();
  52. // string recipeName = "配方" + (Json<LocaPar>.Data.Recipes.Count + 1) + "";
  53. //go:
  54. // string recipeCode = new Random().Next(10000, 99999).ToString();
  55. // foreach (var item in Recipes)
  56. // {
  57. // if (item.RecipeCode == recipeCode)
  58. // {
  59. // goto go;
  60. // }
  61. // }
  62. // int trayCode = new Random().Next(1,6);
  63. // for (int i = 1; i < 13; i++)
  64. // {
  65. // int a = new Random().Next(1, 5);
  66. // if (a == 3)
  67. // {
  68. // a = 1;
  69. // }
  70. // RawMaterials.Add(new RawMaterialModel()
  71. // {
  72. // RawMaterialWeight = new Random().Next(10, 1000),
  73. // RawMaterialBarrelNum = a,
  74. // RawMaterialLocation = i,
  75. // });
  76. // }
  77. // Json<LocaPar>.Data.Recipes.Add(new RecipeModel()
  78. // {
  79. // RecipeName = recipeName,
  80. // RecipeCode = recipeCode,
  81. // TrayCode = trayCode,
  82. // RawMaterial = RawMaterials,
  83. // });
  84. // Json<LocaPar>.Save();
  85. //});
  86. ClearAllRecipe = new RelayCommand(() =>
  87. {
  88. Json<LocalRecipe>.Data.Recipes.Clear();
  89. Json<LocalRecipe>.Save();
  90. });
  91. RemoveCommand = new RelayCommand<string>((recipeCode) =>
  92. {
  93. var res = Recipes.FirstOrDefault(p => p.RecipeCode == recipeCode);
  94. if (res != null)
  95. {
  96. Recipes.Remove(res);
  97. Json<LocalRecipe>.Save();
  98. }
  99. });
  100. }
  101. public RelayCommand<object> DetailsCommand { get; set; }
  102. // public RelayCommand NewSimulateRecipe { get; set; }
  103. public RelayCommand ClearAllRecipe { get; set; }
  104. public RelayCommand NewRecipe { get; set; }
  105. public bool IsUseLocalRecipe { get { return _isUseLocalRecipe; } set { _isUseLocalRecipe = value; OnPropertyChanged(); } }
  106. public bool _isUseLocalRecipe { get; set; }
  107. public RelayCommand<string> RemoveCommand { get; set; }
  108. public ObservableCollection<RecipeData> Recipes { get; set; } = new ObservableCollection<RecipeData>();
  109. }
  110. }