终端一体化运控平台
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

156 wiersze
6.8 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using BPA.Helper;
  7. using System.Collections.Concurrent;
  8. using System.Collections.ObjectModel;
  9. using System.Windows;
  10. using BPA.Helper;
  11. using BPASmartClient.JXJFoodBigStation.Model;
  12. using BPASmartClient.JXJFoodBigStation.View;
  13. using BPASmartClient.CustomResource.UserControls;
  14. using BPASmartClient.CustomResource.UserControls.Model;
  15. using BPASmartClient.CustomResource.UserControls.Enum;
  16. using System.Windows.Media;
  17. using BPASmartClient.CustomResource.UserControls.MessageShow;
  18. using BPASmartClient.CustomResource.Pages.Model;
  19. using BPASmartClient.JXJFoodBigStation.Model.Siemens;
  20. namespace BPASmartClient.JXJFoodBigStation.ViewModel
  21. {
  22. public class RecipeReceiveViewModel : NotifyBase
  23. {
  24. public ObservableCollection<RawMaterial> RawMaterials { get; set; } = new ObservableCollection<RawMaterial>();
  25. public RecipeReceiveViewModel()
  26. {
  27. IsUseLocalRecipe = GVL_BigStation.IsUseLocalRecipe;
  28. Json<LocalRecipe>.Read();
  29. Recipes = Json<LocalRecipe>.Data.Recipes;
  30. DetailsCommand = new BPARelayCommand<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<LocalRecipe>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == num);
  37. ActionManage.GetInstance.Send("RecipeInfo", res);
  38. nrv.Show();
  39. MessageNotify.GetInstance.ShowUserLog($"编辑配方,配方名称:【{res.RecipeName}】");
  40. }
  41. });
  42. NewRecipe = new BPARelayCommand(() =>
  43. {
  44. RecipeInfosView nrv = new RecipeInfosView();
  45. nrv.ShowDialog();
  46. });
  47. //RefreshRecipe = new BPARelayCommand(() =>
  48. //{
  49. // foreach (var item in ProcessControl.GetInstance.RawMaterialsInfo)
  50. // {
  51. // RawMaterialNames.Add(item.RawMaterialName);
  52. // }
  53. // foreach (var item in Json<LocalRecipe>.Data.Recipes)
  54. // {
  55. // foreach (var tep in item.RawMaterial)
  56. // {
  57. // if (RawMaterialNames.Contains(tep.RawMaterialName))
  58. // {
  59. // int index = Array.FindIndex(ProcessControl.GetInstance.RawMaterialsInfo.ToArray(), p => p.RawMaterialName == tep.RawMaterialName);
  60. // tep.RawMaterialLocation = ProcessControl.GetInstance.RawMaterialsInfo.ElementAt(index).RawMaterialLocation;
  61. // }
  62. // }
  63. // }
  64. //});
  65. //模拟配方
  66. //NewSimulateRecipe = new BPARelayCommand(() =>
  67. //{
  68. // RawMaterials.Clear();
  69. // string recipeName = "配方" + (Json<LocaPar>.Data.Recipes.Count + 1) + "";
  70. //go:
  71. // string recipeCode = new Random().Next(10000, 99999).ToString();
  72. // foreach (var item in Recipes)
  73. // {
  74. // if (item.RecipeCode == recipeCode)
  75. // {
  76. // goto go;
  77. // }
  78. // }
  79. // int trayCode = new Random().Next(1,6);
  80. // for (int i = 1; i < 13; i++)
  81. // {
  82. // int a = new Random().Next(1, 5);
  83. // if (a == 3)
  84. // {
  85. // a = 1;
  86. // }
  87. // RawMaterials.Add(new RawMaterialModel()
  88. // {
  89. // RawMaterialWeight = new Random().Next(10, 1000),
  90. // RawMaterialBarrelNum = a,
  91. // RawMaterialLocation = i,
  92. // });
  93. // }
  94. // Json<LocaPar>.Data.Recipes.Add(new RecipeModel()
  95. // {
  96. // RecipeName = recipeName,
  97. // RecipeCode = recipeCode,
  98. // TrayCode = trayCode,
  99. // RawMaterial = RawMaterials,
  100. // });
  101. // Json<LocaPar>.Save();
  102. //});
  103. ClearAllRecipe = new BPARelayCommand(() =>
  104. {
  105. if (!MessageNotify.GetInstance.ShowDialog($"请确认,是否删除所有本地配方?",DialogType.Warning))
  106. {
  107. return;
  108. }
  109. Json<LocalRecipe>.Data.Recipes.Clear();
  110. Json<LocalRecipe>.Data.SelectedRecipes.Clear();
  111. Json<LocalRecipe>.Save();
  112. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "成功", $"本地配方已全部删除!");
  113. MessageNotify.GetInstance.ShowUserLog($"手动清除所有配方。");
  114. });
  115. RemoveCommand = new BPARelayCommand<string>((recipeCode) =>
  116. {
  117. if (!MessageNotify.GetInstance.ShowDialog($"请确认,是否删除配方【{recipeCode}】?",DialogType.Warning))
  118. {
  119. return;
  120. }
  121. var res = Recipes.FirstOrDefault(p => p.RecipeCode == recipeCode);
  122. var res1 = Json<LocalRecipe>.Data.SelectedRecipes.FirstOrDefault(p => p.RecipeCode == recipeCode);
  123. if (res1 is not null)
  124. {
  125. Json<LocalRecipe>.Data.SelectedRecipes.Remove(res1);
  126. }
  127. if (res != null)
  128. {
  129. Recipes.Remove(res);
  130. Json<LocalRecipe>.Save();
  131. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "成功", $"配方删除完成");
  132. MessageNotify.GetInstance.ShowUserLog($"手动删除【{res.RecipeName}】配方,编号:【{recipeCode}】,");
  133. }
  134. });
  135. }
  136. public BPARelayCommand<object> DetailsCommand { get; set; }
  137. // public BPARelayCommand NewSimulateRecipe { get; set; }
  138. public BPARelayCommand ClearAllRecipe { get; set; }
  139. public BPARelayCommand NewRecipe { get; set; }
  140. public BPARelayCommand RefreshRecipe { get; set; }
  141. public bool IsUseLocalRecipe { get { return _isUseLocalRecipe; } set { _isUseLocalRecipe = value; OnPropertyChanged(); } }
  142. public bool _isUseLocalRecipe { get; set; }
  143. public BPARelayCommand<string> RemoveCommand { get; set; }
  144. public ObservableCollection<RecipeData> Recipes { get; set; } = new ObservableCollection<RecipeData>();
  145. public ObservableCollection<string> RawMaterialNames { get; set; } = new ObservableCollection<string>();
  146. }
  147. }