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

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