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

108 lines
4.5 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.JXJFoodSmallStation.Model;
  13. using BPASmartClient.JXJFoodSmallStation.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.JXJFoodSmallStation.Model.Siemens;
  21. using BPASmartClient.JXJFoodSmallStation.Model.GVL;
  22. namespace BPASmartClient.JXJFoodSmallStation.ViewModel
  23. {
  24. public class RecipeReceiveViewModel : ObservableObject
  25. {
  26. //ObservableCollection<RemoteRecipeRawMaterial> RawMaterials { get; set; } = new ObservableCollection<RemoteRecipeRawMaterial>();
  27. public RecipeReceiveViewModel()
  28. {
  29. //Json<LocaPar>.Read();
  30. Recipes = Json<LocalRecipeDataColl>.Data.Recipes;
  31. NewRecipe = new RelayCommand(() =>
  32. {
  33. NewLocalRecipeView NewLocalRecipe = new NewLocalRecipeView();
  34. NewLocalRecipe.ShowDialog();
  35. });
  36. DetailsCommand = new RelayCommand<object>((o) =>
  37. {
  38. if (o != null && o is string cnt)
  39. {
  40. ActionManage.GetInstance.Send("CloseNewRemoteRecipeView");
  41. NewLocalRecipeView nrv = new NewLocalRecipeView();
  42. var res = Json<LocalRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == cnt);
  43. if (res != null)
  44. {
  45. ActionManage.GetInstance.Send("LocalRecipeEdit", res);
  46. nrv.Show();
  47. MessageLog.GetInstance.ShowUserLog($"查看配方——{res.RecipeName}");
  48. }
  49. }
  50. });
  51. NewSimulateRecipe = new RelayCommand(() =>
  52. {
  53. ObservableCollection<RemoteRecipeRawMaterial> RawMaterials = new ObservableCollection<RemoteRecipeRawMaterial>();
  54. string recipeName = "配方" + (Json<LocalRecipeDataColl>.Data.Recipes.Count + 1) + "";
  55. go:
  56. string recipeCode = new Random().Next(1000, 9999).ToString();
  57. foreach (var item in Json<LocalRecipeDataColl>.Data.Recipes)
  58. {
  59. if (item.RecipeCode == recipeCode)
  60. {
  61. goto go;
  62. }
  63. }
  64. int trayCode = new Random().Next(1, 3);
  65. for (int i = 1; i < 16; i++)
  66. {
  67. if ( i == 7 || i == 8 || i == 15)
  68. {
  69. }
  70. else
  71. {
  72. RawMaterials.Add(new RemoteRecipeRawMaterial()
  73. {
  74. RawMaterialName = "原料" + i,
  75. RawMaterialWeight = new Random().Next(200, 300),
  76. RawMaterialBarrelNum = (short)new Random().Next(1, 5),
  77. RawMaterialLocation = i,
  78. });
  79. }
  80. }
  81. var res = Array.FindIndex(Json<LocalRecipeDataColl>.Data.Recipes.ToArray(), p => p.RecipeCode == recipeCode);
  82. if (res < 0)
  83. {
  84. Json<LocalRecipeDataColl>.Data.Recipes.Add(new RemoteRecipeData()
  85. {
  86. RecipeName = recipeName,
  87. RecipeCode = recipeCode,
  88. TrayCode = trayCode,
  89. RawMaterial = RawMaterials,
  90. });
  91. }
  92. });
  93. ClearAllRecipe = new RelayCommand(() =>
  94. {
  95. Json<LocalRecipeDataColl>.Data.Recipes.Clear();
  96. });
  97. }
  98. public RelayCommand<object> DetailsCommand { get; set; }
  99. public RelayCommand NewSimulateRecipe { get;set; }
  100. public RelayCommand ClearAllRecipe { get; set; }
  101. public RelayCommand NewRecipe { get; set; }
  102. public ObservableCollection<RemoteRecipeData> Recipes { get; set; }=new ObservableCollection<RemoteRecipeData>() { new RemoteRecipeData() { } };
  103. }
  104. }