终端一体化运控平台
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

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