终端一体化运控平台
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

144 satır
6.3 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.DosingHKProject.Model;
  13. using BPASmartClient.DosingHKProject.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.DosingHKProject.Model.Siemens;
  21. using BPASmartClient.DosingHKProject.Model.GVL;
  22. using BPASmartClient.DosingProject;
  23. namespace BPASmartClient.DosingHKProject.ViewModel
  24. {
  25. public class RecipeReceiveViewModel : ObservableObject
  26. {
  27. //ObservableCollection<RemoteRecipeRawMaterial> RawMaterials { get; set; } = new ObservableCollection<RemoteRecipeRawMaterial>();
  28. public RecipeReceiveViewModel()
  29. {
  30. IsUseLocalRecipe = GVL_SmallStation.GetInstance.IsUseLocalRecipe;
  31. IsUseWindSendDosing = GVL_SmallStation.GetInstance.IsUseLocalRecipe;
  32. //Json<LocaPar>.Read();
  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. var res = Json<LocalRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == cnt);
  44. if (res != null)
  45. {
  46. Json<LocalRecipeDataColl>.Data.Recipes.Remove(res);
  47. MessageLog.GetInstance.ShowUserLog($"删除配方——{res.RecipeName}");
  48. }
  49. }
  50. });
  51. DetailsCommand = new RelayCommand<object>((o) =>
  52. {
  53. if (o != null && o is string cnt)
  54. {
  55. ActionManage.GetInstance.Send("CloseNewRemoteRecipeView");
  56. NewLocalRecipeView nrv = new NewLocalRecipeView();
  57. var res = Json<LocalRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == cnt);
  58. if (res != null)
  59. {
  60. ActionManage.GetInstance.Send("LocalRecipeEdit", res);
  61. nrv.Show();
  62. MessageLog.GetInstance.ShowUserLog($"编辑配方——{res.RecipeName}");
  63. }
  64. }
  65. });
  66. IssueRecipe = new RelayCommand<object>((o) =>
  67. {
  68. if (IsUseLocalRecipe == false)
  69. {
  70. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "错误", $"未处于本地模拟配方状态!");
  71. return;
  72. }
  73. else
  74. {
  75. if (o != null && o is string cnt)
  76. {
  77. var res = Json<LocalRecipeDataColl>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == cnt);
  78. if (res != null)
  79. {
  80. MessageLog.GetInstance.ShowUserLog($"下发配方——{res.RecipeName}");
  81. }
  82. }
  83. }
  84. });
  85. NewSimulateRecipe = new RelayCommand(() =>
  86. {
  87. ObservableCollection<RemoteRecipeRawMaterial> RawMaterials = new ObservableCollection<RemoteRecipeRawMaterial>();
  88. string recipeName = "配方" + (Json<LocalRecipeDataColl>.Data.Recipes.Count + 1) + "";
  89. go:
  90. string recipeCode = new Random().Next(1000, 9999).ToString();
  91. foreach (var item in Json<LocalRecipeDataColl>.Data.Recipes)
  92. {
  93. if (item.RecipeCode == recipeCode)
  94. {
  95. goto go;
  96. }
  97. }
  98. int trayCode = new Random().Next(1, 3);
  99. for (int i = 1; i < 16; i++)
  100. {
  101. RawMaterials.Add(new RemoteRecipeRawMaterial()
  102. {
  103. RawMaterialName = "原料" + i,
  104. RawMaterialWeight = new Random().Next(200, 300),
  105. RawMaterialBarrelNum = (short)new Random().Next(1, 5),
  106. RawMaterialLocation = i,
  107. });
  108. }
  109. var res = Array.FindIndex(Json<LocalRecipeDataColl>.Data.Recipes.ToArray(), p => p.RecipeCode == recipeCode);
  110. if (res < 0)
  111. {
  112. Json<LocalRecipeDataColl>.Data.Recipes.Add(new RemoteRecipeData()
  113. {
  114. RecipeName = recipeName,
  115. RecipeCode = recipeCode,
  116. TrayCode = trayCode,
  117. RawMaterial = RawMaterials,
  118. });
  119. }
  120. });
  121. ClearAllRecipe = new RelayCommand(() =>
  122. {
  123. Json<LocalRecipeDataColl>.Data.Recipes.Clear();
  124. });
  125. }
  126. public bool IsUseLocalRecipe { get { return _mIsUseLocalRecipe; }set { _mIsUseLocalRecipe = value; OnPropertyChanged(); } }
  127. private bool _mIsUseLocalRecipe = GVL_SmallStation.GetInstance.IsUseLocalRecipe;
  128. public bool IsUseWindSendDosing { get { return _mIsUseWindSendDosing; } set { _mIsUseWindSendDosing = value;OnPropertyChanged(); } }
  129. private bool _mIsUseWindSendDosing = GVL_SmallStation.GetInstance.IsUseLocalRecipe;
  130. public RelayCommand<object> DetailsCommand { get; set; }
  131. public RelayCommand<object> IssueRecipe { get; set; }
  132. public RelayCommand<object> RemoveRecipe { get; set; }
  133. public RelayCommand NewSimulateRecipe { get;set; }
  134. public RelayCommand ClearAllRecipe { get; set; }
  135. public RelayCommand NewRecipe { get; set; }
  136. public ObservableCollection<RemoteRecipeData> Recipes { get; set; }
  137. }
  138. }