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

RecipeReceiveViewModel.cs 3.4 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. DetailsCommand = new RelayCommand<object>((o) =>
  31. {
  32. if (o != null && o is string num)
  33. {
  34. ActionManage.GetInstance.CancelRegister("RecipeInfo");
  35. RecipeInfosView nrv = new RecipeInfosView();
  36. var res = Json<RemoteRecipeDataColl>.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. NewSimulateRecipe = new RelayCommand(() =>
  43. {
  44. RawMaterials.Clear();
  45. string recipeName = "配方" + (Json<RemoteRecipeDataColl>.Data.Recipes.Count + 1) + "";
  46. go:
  47. string recipeCode = new Random().Next(1000, 9999).ToString();
  48. foreach (var item in Recipes)
  49. {
  50. if (item.RecipeCode == recipeCode)
  51. {
  52. goto go;
  53. }
  54. }
  55. int trayCode = new Random().Next(1, 3);
  56. for (int i = 1; i < 16; i++)
  57. {
  58. RawMaterials.Add(new RemoteRecipeRawMaterial()
  59. {
  60. RawMaterialWeight = new Random().Next(10, 20),
  61. RawMaterialBarrelNum = (short)new Random().Next(1, 5),
  62. RawMaterialLocation = i,
  63. });
  64. }
  65. Json<RemoteRecipeDataColl>.Data.Recipes.Add(new RemoteRecipeData()
  66. {
  67. RecipeName = recipeName,
  68. RecipeCode = recipeCode,
  69. TrayCode = trayCode,
  70. RawMaterial = RawMaterials,
  71. });
  72. });
  73. ClearAllRecipe = new RelayCommand(() =>
  74. {
  75. Json<RemoteRecipeDataColl>.Data.Recipes.Clear();
  76. });
  77. }
  78. public RelayCommand<object> DetailsCommand { get; set; }
  79. public RelayCommand NewSimulateRecipe { get; set; }
  80. public RelayCommand ClearAllRecipe { get; set; }
  81. public ObservableCollection<RemoteRecipeData> Recipes { get; set; }
  82. }
  83. }