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

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