终端一体化运控平台
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

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