终端一体化运控平台
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

116 Zeilen
4.2 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<RawMaterialModel> RawMaterials { get; set; } = new ObservableCollection<RawMaterialModel>();
  26. public RecipeReceiveViewModel()
  27. {
  28. Json<LocaPar>.Read();
  29. Recipes = Json<LocaPar>.Data.Recipes;
  30. DetailsCommand = new RelayCommand<object>((o) =>
  31. {
  32. if (o != null && o is long num)
  33. {
  34. ActionManage.GetInstance.CancelRegister("RecipeInfo");
  35. RecipeInfosView nrv = new RecipeInfosView();
  36. var res = Json<LocaPar>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == num);
  37. ActionManage.GetInstance.Send("RecipeInfo", res);
  38. nrv.Show();
  39. MessageLog.GetInstance.ShowUserLog($"查看配方——{res.RecipeName}");
  40. }
  41. });
  42. NewRecipe = new RelayCommand(() => {
  43. RecipeInfosView nrv = new RecipeInfosView();
  44. nrv.ShowDialog();
  45. });
  46. NewSimulateRecipe = new RelayCommand(() =>
  47. {
  48. RawMaterials.Clear();
  49. string recipeName = "配方" + (Json<LocaPar>.Data.Recipes.Count + 1) + "";
  50. go:
  51. long recipeCode = new Random().Next(10000, 99999);
  52. foreach (var item in Recipes)
  53. {
  54. if (item.RecipeCode == recipeCode)
  55. {
  56. goto go;
  57. }
  58. }
  59. int trayCode = new Random().Next(1,6);
  60. for (int i = 1; i < 13; i++)
  61. {
  62. int a = new Random().Next(1, 5);
  63. if (a == 3)
  64. {
  65. a = 1;
  66. }
  67. RawMaterials.Add(new RawMaterialModel()
  68. {
  69. RawMaterialWeight = new Random().Next(10, 1000),
  70. RawMaterialBarrelNum = a,
  71. RawMaterialLocation = i,
  72. });
  73. }
  74. Json<LocaPar>.Data.Recipes.Add(new RecipeModel()
  75. {
  76. RecipeName = recipeName,
  77. RecipeCode = recipeCode,
  78. TrayCode = trayCode,
  79. RawMaterial = RawMaterials,
  80. });
  81. });
  82. ClearAllRecipe = new RelayCommand(() =>
  83. {
  84. Json<LocaPar>.Data.Recipes.Clear();
  85. Json<LocaPar>.Save();
  86. });
  87. RemoveCommand = new RelayCommand<long>((recipeCode) => {
  88. var res = Recipes.FirstOrDefault(p=>p.RecipeCode==recipeCode);
  89. if(res!=null)
  90. {
  91. Recipes.Remove(res);
  92. Json<LocaPar>.Save();
  93. }
  94. });
  95. }
  96. public RelayCommand<object> DetailsCommand { get; set; }
  97. public RelayCommand NewSimulateRecipe { get; set; }
  98. public RelayCommand ClearAllRecipe { get; set; }
  99. public RelayCommand NewRecipe { get; set; }
  100. public RelayCommand<long> RemoveCommand { get; set; }
  101. public ObservableCollection<RecipeModel> Recipes { get; set; } = new ObservableCollection<RecipeModel>();
  102. }
  103. }