终端一体化运控平台
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

98 rindas
4.1 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.DosingSystem.Model;
  13. using System.Threading;
  14. using BPASmartClient.CustomResource.Pages.Model;
  15. namespace BPASmartClient.DosingSystem.ViewModel
  16. {
  17. public class RecipeControlViewModel : ObservableObject
  18. {
  19. ConcurrentQueue<string> devices = new ConcurrentQueue<string>();
  20. public RecipeControlViewModel()
  21. {
  22. Recipes = Json<LocaPar>.Data.Recipes;
  23. StartCommand = new RelayCommand<object>((o) =>
  24. {
  25. if (o != null && o is string deviceName)
  26. {
  27. //Task.Run(new Action(() =>
  28. //{
  29. int index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == deviceName);
  30. if (index >= 0 && index < Recipes.Count)
  31. {
  32. Recipes.ElementAt(index).IsEnable = false;
  33. //foreach (var item in Recipes.ElementAt(index).RawMaterials)
  34. //{
  35. // DeviceInquire.GetInstance.GetDevice(item.DeviceIp)?.Start(item.RawMaterialWeight);//启动写入
  36. //}
  37. }
  38. //}));
  39. MessageLog.GetInstance.ShowUserLog($"下发工单 { Recipes.ElementAt(index).RecipeName}");
  40. devices.Enqueue(deviceName);
  41. }
  42. });
  43. ThreadManage.GetInstance().StartLong(new Action(() =>
  44. {
  45. if (devices.Count > 0)
  46. {
  47. int index = Array.FindIndex(Recipes.ToArray(), p => p.RecipeName == devices.ElementAt(0));
  48. if (index >= 0 && index < Recipes.Count)
  49. {
  50. Recipes.ElementAt(index).Are.Reset();
  51. Recipes.ElementAt(index).IsEnable = false;
  52. foreach (var item in Recipes.ElementAt(index).RawMaterials)
  53. {
  54. DeviceInquire.GetInstance.GetDevice(item.DeviceIp)?.Start(item.RawMaterialWeight);//启动写入
  55. }
  56. Recipes.ElementAt(index).Are.WaitOne();
  57. devices.TryDequeue(out string deviceName);
  58. }
  59. }
  60. Thread.Sleep(100);
  61. }), "启动配发下发");
  62. ThreadManage.GetInstance().StartLong(new Action(() =>
  63. {
  64. for (int i = 0; i < Recipes.Count; i++)
  65. {
  66. for (int m = 0; m < Recipes.ElementAt(i).RawMaterials.Count; m++)
  67. {
  68. var RunStatus = DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(m).DeviceIp).deviceStatus.RunStatus;
  69. Recipes.ElementAt(i).RawMaterials.ElementAt(m).RecipeStatus = RunStatus;
  70. var res = Recipes.ElementAt(i).RawMaterials.Where(p => p.RecipeStatus == 3).ToList();
  71. if (res != null && res.Count == Recipes.ElementAt(i).RawMaterials.Count)
  72. {
  73. for (int r = 0; r < Recipes.ElementAt(i).RawMaterials.Count; r++)
  74. {
  75. DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(r).DeviceIp).StatusReset();
  76. }
  77. Recipes.ElementAt(i).IsEnable = true;
  78. Recipes.ElementAt(i).Are.Set();
  79. }
  80. }
  81. }
  82. Thread.Sleep(100);
  83. }), "RecipeControlViewModelStatusInquire");
  84. }
  85. public RelayCommand<object> StartCommand { get; set; }
  86. public ObservableCollection<RecipeModel> Recipes { get; set; }
  87. }
  88. }