终端一体化运控平台
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

RecipeReceiveViewModel.cs 9.4 KiB

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