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

164 lines
7.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.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. using BPASmartClient.JXJFoodSmallStation.Model.GVL;
  22. namespace BPASmartClient.JXJFoodSmallStation.ViewModel
  23. {
  24. public class RecipeReceiveViewModel : ObservableObject
  25. {
  26. //ObservableCollection<RemoteRecipeRawMaterial> RawMaterials { get; set; } = new ObservableCollection<RemoteRecipeRawMaterial>();
  27. public RecipeReceiveViewModel()
  28. {
  29. IsUseLocalRecipe = GVL_SmallStation.GetInstance.IsUseLocalRecipe;
  30. IsUseWindSendDosing = GVL_SmallStation.GetInstance.IsUseWindSend;
  31. //Json<LocaPar>.Read();
  32. Recipes = Json<LocalRecipeDataColl>.Data.Recipes;
  33. NewRecipe = new RelayCommand(() =>
  34. {
  35. NewLocalRecipeView NewLocalRecipe = new NewLocalRecipeView();
  36. NewLocalRecipe.ShowDialog();
  37. });
  38. RemoveRecipe = new RelayCommand<object>((o) =>
  39. {
  40. if (o != null && o is string cnt)
  41. {
  42. var res = Json<LocalRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == cnt);
  43. if (res != null)
  44. {
  45. Json<LocalRecipeDataColl>.Data.Recipes.Remove(res);
  46. MessageNotify.GetInstance.ShowUserLog($"删除配方——{res.RecipeName}");
  47. }
  48. }
  49. });
  50. DetailsCommand = new RelayCommand<object>((o) =>
  51. {
  52. if (o != null && o is string cnt)
  53. {
  54. ActionManage.GetInstance.Send("CloseNewRemoteRecipeView");
  55. NewLocalRecipeView nrv = new NewLocalRecipeView();
  56. var res = Json<LocalRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == cnt);
  57. if (res != null)
  58. {
  59. ActionManage.GetInstance.Send("LocalRecipeEdit", res);
  60. nrv.Show();
  61. MessageNotify.GetInstance.ShowUserLog($"编辑配方——{res.RecipeName}");
  62. }
  63. }
  64. });
  65. IssueRecipe = new RelayCommand<object>((o) =>
  66. {
  67. if (IsUseLocalRecipe == false)
  68. {
  69. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "错误", $"未处于本地模拟配方状态!");
  70. return;
  71. }
  72. else
  73. {
  74. if (o != null && o is string cnt)
  75. {
  76. var res = Json<LocalRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == cnt);
  77. var res1 = Json<RemoteRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == cnt);
  78. if (res1 != null)
  79. {
  80. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "错误", $"远程已经存在该配方!");
  81. return;
  82. }
  83. if (res != null && res1 ==null)
  84. {
  85. ActionManage.GetInstance.Send("LocalSimulationRecipeIssue", res);
  86. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"{res.RecipeName}配方下发成功!");
  87. MessageNotify.GetInstance.ShowUserLog($"下发本地模拟配方——{res.RecipeName}");
  88. }
  89. }
  90. }
  91. });
  92. NewSimulateRecipe = new RelayCommand(() =>
  93. {
  94. ObservableCollection<RemoteRecipeRawMaterial> RawMaterials = new ObservableCollection<RemoteRecipeRawMaterial>();
  95. string recipeName = "配方" + (Json<LocalRecipeDataColl>.Data.Recipes.Count + 1) + "";
  96. go:
  97. string recipeCode = new Random().Next(1000, 9999).ToString();
  98. foreach (var item in Json<LocalRecipeDataColl>.Data.Recipes)
  99. {
  100. if (item.RecipeCode == recipeCode)
  101. {
  102. goto go;
  103. }
  104. }
  105. int trayCode = new Random().Next(1, 3);
  106. for (int i = 1; i < 16; i++)
  107. {
  108. RawMaterials.Add(new RemoteRecipeRawMaterial()
  109. {
  110. RawMaterialName = "原料" + i,
  111. RawMaterialWeight = new Random().Next(200, 300),
  112. RawMaterialBarrelNum = (short)new Random().Next(1, 5),
  113. RawMaterialLocation = i,
  114. });
  115. }
  116. if (GVL_SmallStation.GetInstance.IsUseWindSend && trayCode == 1)
  117. {
  118. for (int i = 1; i < 6; i++)
  119. {
  120. RawMaterials.Add(new RemoteRecipeRawMaterial()
  121. {
  122. RawMaterialName = "粉料" + i,
  123. RawMaterialWeight = new Random().Next(200, 300),
  124. RawMaterialLocation = i,
  125. RawMaterialBarrelNum = 7
  126. });
  127. }
  128. }
  129. var res = Array.FindIndex(Json<LocalRecipeDataColl>.Data.Recipes.ToArray(), p => p.RecipeCode == recipeCode);
  130. if (res < 0)
  131. {
  132. Json<LocalRecipeDataColl>.Data.Recipes.Add(new RemoteRecipeData()
  133. {
  134. RecipeName = recipeName,
  135. RecipeCode = recipeCode,
  136. TrayCode = trayCode,
  137. RawMaterial = RawMaterials,
  138. });
  139. }
  140. });
  141. ClearAllRecipe = new RelayCommand(() =>
  142. {
  143. Json<LocalRecipeDataColl>.Data.Recipes.Clear();
  144. });
  145. }
  146. public bool IsUseLocalRecipe { get { return _mIsUseLocalRecipe; }set { _mIsUseLocalRecipe = value; OnPropertyChanged(); } }
  147. private bool _mIsUseLocalRecipe ;
  148. public bool IsUseWindSendDosing { get { return _mIsUseWindSendDosing; } set { _mIsUseWindSendDosing = value;OnPropertyChanged(); } }
  149. private bool _mIsUseWindSendDosing ;
  150. public RelayCommand<object> DetailsCommand { get; set; }
  151. public RelayCommand<object> IssueRecipe { get; set; }
  152. public RelayCommand<object> RemoveRecipe { get; set; }
  153. public RelayCommand NewSimulateRecipe { get;set; }
  154. public RelayCommand ClearAllRecipe { get; set; }
  155. public RelayCommand NewRecipe { get; set; }
  156. public ObservableCollection<RemoteRecipeData> Recipes { get; set; }
  157. }
  158. }