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

199 lignes
9.4 KiB

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