终端一体化运控平台
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

238 lignes
11 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. using BPASmartClient.JXJFoodSmallStation.View;
  23. namespace BPASmartClient.JXJFoodSmallStation.ViewModel
  24. {
  25. public class RecipeReceiveViewModel : ObservableObject
  26. {
  27. //ObservableCollection<RemoteRecipeRawMaterial> RawMaterials { get; set; } = new ObservableCollection<RemoteRecipeRawMaterial>();
  28. public RecipeReceiveViewModel()
  29. {
  30. NotUseSmallDosing = GVL_SmallStation.GetInstance.NotUseSmallStation;
  31. IsUseLocalRecipe = GVL_SmallStation.GetInstance.IsUseLocalRecipe;
  32. IsUseWindSendDosing = GVL_SmallStation.GetInstance.IsUseWindSend;
  33. var tempcoll = new ObservableCollection<RemoteRecipeData>();
  34. foreach (var item in Json<LocalRecipeDataColl>.Data.SelectedRecipes)
  35. {
  36. if (!Json<LocalRecipeDataColl>.Data.Recipes.Any(p=>p.RecipeCode.Equals(item.RecipeCode)&&p.RecipeName.Equals(item.RecipeName)&&p.TrayCode==item.TrayCode))
  37. {
  38. tempcoll.Add(item);
  39. }
  40. }
  41. foreach (var item in tempcoll)
  42. {
  43. Json<LocalRecipeDataColl>.Data.SelectedRecipes.Remove(item);
  44. }
  45. Json<LocalRecipeDataColl>.Save();
  46. tempcoll.Clear();
  47. Recipes = Json<LocalRecipeDataColl>.Data.Recipes;
  48. NewRecipe = new RelayCommand(() =>
  49. {
  50. NewLocalRecipeView NewLocalRecipe = new NewLocalRecipeView();
  51. NewLocalRecipe.ShowDialog();
  52. });
  53. RemoveRecipe = new RelayCommand<object>((o) =>
  54. {
  55. if (o != null && o is string cnt)
  56. {
  57. if (MessageNotify.GetInstance.ShowDialog($"请确认,是否删除订单【{cnt}】?"))
  58. {
  59. var res = Json<LocalRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == cnt);
  60. if (res != null)
  61. {
  62. Json<LocalRecipeDataColl>.Data.Recipes.Remove(res);
  63. Json<LocalRecipeDataColl>.Save();
  64. MessageNotify.GetInstance.ShowUserLog($"删除配方——{res.RecipeName}");
  65. }
  66. }
  67. }
  68. });
  69. DetailsCommand = new RelayCommand<object>((o) =>
  70. {
  71. if (o != null && o is string cnt)
  72. {
  73. if (MessageNotify.GetInstance.ShowDialog($"请确认,是否进行编辑订单【{cnt}】操作?"))
  74. {
  75. //ActionManage.GetInstance.Send("CloseNewRemoteRecipeView");
  76. NewLocalRecipeView nrv = new NewLocalRecipeView();
  77. var res = Json<LocalRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == cnt);
  78. if (res != null)
  79. {
  80. ActionManage.GetInstance.Send("LocalRecipeEdit", res);
  81. nrv.ShowDialog();
  82. MessageNotify.GetInstance.ShowUserLog($"编辑配方——{res.RecipeName}");
  83. }
  84. }
  85. }
  86. });
  87. IssueRecipe = new RelayCommand<object>((o) =>
  88. {
  89. if (IsUseLocalRecipe == false)
  90. {
  91. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "错误", $"未处于本地模拟配方状态!");
  92. return;
  93. }
  94. else
  95. {
  96. if (o != null && o is string cnt)
  97. {
  98. var res = Json<LocalRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == cnt);
  99. var res1 = Json<RemoteRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == cnt);
  100. if (MessageNotify.GetInstance.ShowDialog($"请确认,是否进行下发订单【{cnt}】操作?"))
  101. {
  102. if (res1 != null)
  103. {
  104. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "错误", $"远程已经存在该配方!");
  105. return;
  106. }
  107. if (res != null && res1 == null)
  108. {
  109. ActionManage.GetInstance.Send("LocalSimulationRecipeIssue", res);
  110. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"{res.RecipeName}配方下发成功!");
  111. MessageNotify.GetInstance.ShowUserLog($"下发本地模拟配方,配方名称:【{res.RecipeName}】");
  112. }
  113. GVL_SmallStation.GetInstance.LatestIssueRecipe=DateTime.Now;
  114. }
  115. }
  116. }
  117. });
  118. NewSimulateRecipe = new RelayCommand(() =>
  119. {
  120. ObservableCollection<RemoteRecipeRawMaterial> RawMaterials = new ObservableCollection<RemoteRecipeRawMaterial>();
  121. string recipeName = "配方" + (Json<LocalRecipeDataColl>.Data.Recipes.Count + 1) + "";
  122. go:
  123. string recipeCode = new Random().Next(1000, 9999).ToString();
  124. foreach (var item in Json<LocalRecipeDataColl>.Data.Recipes)
  125. {
  126. if (item.RecipeCode == recipeCode)
  127. {
  128. goto go;
  129. }
  130. }
  131. int trayCode = new Random().Next(1, 2);
  132. for (int i = 1; i < 16; i++)
  133. {
  134. RawMaterials.Add(new RemoteRecipeRawMaterial()
  135. {
  136. RawMaterialName = "原料" + i,
  137. RawMaterialType = "小料",
  138. RawMaterialWeight = (float)Math.Round(new Random().Next(200, 300) * 0.001, 3),
  139. RawMaterialBarrelNum = (short)new Random().Next(6, 9),
  140. RawMaterialLocation = i,
  141. });
  142. }
  143. if (GVL_SmallStation.GetInstance.IsUseWindSend && trayCode == 1)
  144. {
  145. for (int i = 1; i < 6; i++)
  146. {
  147. RawMaterials.Add(new RemoteRecipeRawMaterial()
  148. {
  149. RawMaterialName = "粉料" + i,
  150. RawMaterialType = "粉料",
  151. RawMaterialWeight = new Random().Next(1, 6),
  152. RawMaterialLocation = i,
  153. RawMaterialBarrelNum = 3
  154. });
  155. }
  156. }
  157. var res = Array.FindIndex(Json<LocalRecipeDataColl>.Data.Recipes.ToArray(), p => p.RecipeCode == recipeCode);
  158. if (res < 0)
  159. {
  160. var newRemoteRecipedata = new RemoteRecipeData()
  161. {
  162. RecipeName = recipeName,
  163. RecipeCode = recipeCode,
  164. TrayCode = trayCode,
  165. RawMaterial = RawMaterials,
  166. RecipesSource=RecipeSource.本地,
  167. };
  168. Json<LocalRecipeDataColl>.Data.Recipes.Add(newRemoteRecipedata);
  169. //新增了配方之后应该默认显示出来。
  170. Json<LocalRecipeDataColl>.Data.SelectedRecipes.Add(newRemoteRecipedata);
  171. Json<LocalRecipeDataColl>.Save();
  172. MessageNotify.GetInstance.ShowUserLog("新增一条本地模拟配方。");
  173. }
  174. });
  175. ClearAllRecipe = new RelayCommand(() =>
  176. {
  177. if (MessageNotify.GetInstance.ShowDialog("请确认,是否清除所有本地配方?", DialogType.Warning))
  178. {
  179. Json<LocalRecipeDataColl>.Data.Recipes.Clear();
  180. Json<LocalRecipeDataColl>.Data.SelectedRecipes.Clear();
  181. Json<LocalRecipeDataColl>.Save();
  182. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"本地配方清空成功。");
  183. MessageNotify.GetInstance.ShowUserLog("手动清除所有本地配方");
  184. }
  185. });
  186. SelectedRecipes = Json<LocalRecipeDataColl>.Data.SelectedRecipes;
  187. SelectRecipesCommand = new RelayCommand(() =>
  188. {
  189. var selectView = new SelectRecipesView();
  190. selectView.ShowDialog();
  191. Json<LocalRecipeDataColl>.Data.SelectedRecipes.Clear();
  192. foreach (var recipe in SelectRecipesViewModel.SelectRecipes)
  193. {
  194. if (recipe != null && !Json<LocalRecipeDataColl>.Data.SelectedRecipes.Any(p => p.RecipeCode == recipe.RecipeCode))
  195. {
  196. Json<LocalRecipeDataColl>.Data.SelectedRecipes.Add(recipe);
  197. }
  198. }
  199. //不保存会导致下次打开本地配方下发页面,会重新读取之前存储的文件。
  200. Json<LocalRecipeDataColl>.Save();
  201. MessageNotify.GetInstance.ShowUserLog("筛选了一次配方。");
  202. });
  203. }
  204. public bool NotUseSmallDosing { get { return _mNotUseSmallDosing; } set { _mNotUseSmallDosing = value; OnPropertyChanged(); } }
  205. private bool _mNotUseSmallDosing;
  206. public bool IsUseLocalRecipe { get { return _mIsUseLocalRecipe; } set { _mIsUseLocalRecipe = value; OnPropertyChanged(); } }
  207. private bool _mIsUseLocalRecipe;
  208. public bool IsUseWindSendDosing { get { return _mIsUseWindSendDosing; } set { _mIsUseWindSendDosing = value; OnPropertyChanged(); } }
  209. private bool _mIsUseWindSendDosing;
  210. /// <summary>
  211. /// 筛选后的配方列表。
  212. /// </summary>
  213. public static ObservableCollection<RemoteRecipeData> SelectedRecipes { get; set; }
  214. public RelayCommand<object> DetailsCommand { get; set; }
  215. public RelayCommand<object> IssueRecipe { get; set; }
  216. public RelayCommand<object> RemoveRecipe { get; set; }
  217. public RelayCommand NewSimulateRecipe { get; set; }
  218. public RelayCommand ClearAllRecipe { get; set; }
  219. public RelayCommand NewRecipe { get; set; }
  220. public RelayCommand SelectRecipesCommand { get; set; }
  221. public ObservableCollection<RemoteRecipeData> Recipes { get; set; }
  222. }
  223. }