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

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