终端一体化运控平台
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

170 строки
7.7 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. namespace BPASmartClient.JXJFoodSmallStation.ViewModel
  23. {
  24. public class RecipeReceiveViewModel : ObservableObject
  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 RelayCommand(() =>
  34. {
  35. NewLocalRecipeView NewLocalRecipe = new NewLocalRecipeView();
  36. NewLocalRecipe.ShowDialog();
  37. });
  38. RemoveRecipe = new RelayCommand<object>((o) =>
  39. {
  40. if (o != null && o is string cnt)
  41. {
  42. var res = Json<LocalRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == cnt);
  43. if (res != null)
  44. {
  45. Json<LocalRecipeDataColl>.Data.Recipes.Remove(res);
  46. MessageNotify.GetInstance.ShowUserLog($"删除配方——{res.RecipeName}");
  47. }
  48. }
  49. });
  50. DetailsCommand = new RelayCommand<object>((o) =>
  51. {
  52. if (o != null && o is string cnt)
  53. {
  54. ActionManage.GetInstance.Send("CloseNewRemoteRecipeView");
  55. NewLocalRecipeView nrv = new NewLocalRecipeView();
  56. var res = Json<LocalRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == cnt);
  57. if (res != null)
  58. {
  59. ActionManage.GetInstance.Send("LocalRecipeEdit", res);
  60. nrv.Show();
  61. MessageNotify.GetInstance.ShowUserLog($"编辑配方——{res.RecipeName}");
  62. }
  63. }
  64. });
  65. IssueRecipe = new RelayCommand<object>((o) =>
  66. {
  67. if (IsUseLocalRecipe == false)
  68. {
  69. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "错误", $"未处于本地模拟配方状态!");
  70. return;
  71. }
  72. else
  73. {
  74. if (o != null && o is string cnt)
  75. {
  76. var res = Json<LocalRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == cnt);
  77. var res1 = Json<RemoteRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == cnt);
  78. if (res1 != null)
  79. {
  80. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "错误", $"远程已经存在该配方!");
  81. return;
  82. }
  83. if (res != null && res1 ==null)
  84. {
  85. ActionManage.GetInstance.Send("LocalSimulationRecipeIssue", res);
  86. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"{res.RecipeName}配方下发成功!");
  87. MessageNotify.GetInstance.ShowUserLog($"下发本地模拟配方——{res.RecipeName}");
  88. }
  89. }
  90. }
  91. });
  92. NewSimulateRecipe = new RelayCommand(() =>
  93. {
  94. ObservableCollection<RemoteRecipeRawMaterial> RawMaterials = new ObservableCollection<RemoteRecipeRawMaterial>();
  95. string recipeName = "配方" + (Json<LocalRecipeDataColl>.Data.Recipes.Count + 1) + "";
  96. go:
  97. string recipeCode = new Random().Next(1000, 9999).ToString();
  98. foreach (var item in Json<LocalRecipeDataColl>.Data.Recipes)
  99. {
  100. if (item.RecipeCode == recipeCode)
  101. {
  102. goto go;
  103. }
  104. }
  105. int trayCode = new Random().Next(1, 2);
  106. for (int i = 1; i < 16; i++)
  107. {
  108. RawMaterials.Add(new RemoteRecipeRawMaterial()
  109. {
  110. RawMaterialName = "原料" + i,
  111. RawMaterialType = "小料",
  112. RawMaterialWeight = (float)Math.Round(new Random().Next(200, 300) * 0.001 ,3),
  113. RawMaterialBarrelNum = (short)new Random().Next(6, 9),
  114. RawMaterialLocation = i,
  115. });
  116. }
  117. if (GVL_SmallStation.GetInstance.IsUseWindSend && trayCode == 1)
  118. {
  119. for (int i = 1; i < 6; i++)
  120. {
  121. RawMaterials.Add(new RemoteRecipeRawMaterial()
  122. {
  123. RawMaterialName = "粉料" + i,
  124. RawMaterialType = "粉料",
  125. RawMaterialWeight = new Random().Next(1, 6),
  126. RawMaterialLocation = i,
  127. RawMaterialBarrelNum = 3
  128. });
  129. }
  130. }
  131. var res = Array.FindIndex(Json<LocalRecipeDataColl>.Data.Recipes.ToArray(), p => p.RecipeCode == recipeCode);
  132. if (res < 0)
  133. {
  134. Json<LocalRecipeDataColl>.Data.Recipes.Add(new RemoteRecipeData()
  135. {
  136. RecipeName = recipeName,
  137. RecipeCode = recipeCode,
  138. TrayCode = trayCode,
  139. RawMaterial = RawMaterials,
  140. });
  141. }
  142. });
  143. ClearAllRecipe = new RelayCommand(() =>
  144. {
  145. Json<LocalRecipeDataColl>.Data.Recipes.Clear();
  146. });
  147. }
  148. public bool NotUseSmallDosing { get { return _mNotUseSmallDosing; } set { _mNotUseSmallDosing = value; OnPropertyChanged(); } }
  149. private bool _mNotUseSmallDosing;
  150. public bool IsUseLocalRecipe { get { return _mIsUseLocalRecipe; }set { _mIsUseLocalRecipe = value; OnPropertyChanged(); } }
  151. private bool _mIsUseLocalRecipe ;
  152. public bool IsUseWindSendDosing { get { return _mIsUseWindSendDosing; } set { _mIsUseWindSendDosing = value;OnPropertyChanged(); } }
  153. private bool _mIsUseWindSendDosing ;
  154. public RelayCommand<object> DetailsCommand { get; set; }
  155. public RelayCommand<object> IssueRecipe { get; set; }
  156. public RelayCommand<object> RemoveRecipe { get; set; }
  157. public RelayCommand NewSimulateRecipe { get;set; }
  158. public RelayCommand ClearAllRecipe { get; set; }
  159. public RelayCommand NewRecipe { get; set; }
  160. public ObservableCollection<RemoteRecipeData> Recipes { get; set; }
  161. }
  162. }