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

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