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

67 lines
2.8 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using BPA.Helper;
  8. using Microsoft.Toolkit.Mvvm.ComponentModel;
  9. using Microsoft.Toolkit.Mvvm.Input;
  10. using BPASmartClient.SmallBatchingSystem.Views;
  11. using BPASmartClient.CustomResource.UserControls.MessageShow;
  12. using BPASmartClient.CustomResource.UserControls;
  13. namespace BPASmartClient.SmallBatchingSystem.ViewModels
  14. {
  15. public class RecipeControlViewModel : ObservableObject
  16. {
  17. public RecipeControlViewModel()
  18. {
  19. Recipes = Json<ConfigInfoModel>.Data.Recipes;
  20. StartCommand = new RelayCommand<object>((o) =>
  21. {
  22. Task.Factory.StartNew(() =>
  23. {
  24. if (PlcDataModel.RecipeBatchingComplete)
  25. {
  26. if (!string.IsNullOrEmpty(o?.ToString()))
  27. {
  28. int index = Array.FindIndex(Json<ConfigInfoModel>.Data.Recipes.ToArray(), p => p.RecipeName == o.ToString());
  29. if (index >= 0 && index < Json<ConfigInfoModel>.Data.Recipes.Count)
  30. {
  31. App.Current.Dispatcher.Invoke(() =>
  32. {
  33. var data = Json<ConfigInfoModel>.Data.Recipes.ElementAt(index);
  34. Control.GetInstance.RunLog($"下发配方:{data.RecipeName}");
  35. GrindArenaceousView grindArenaceousView = new GrindArenaceousView();
  36. ActionManage.GetInstance.Send("OpenRecipeStatusMotion", data);
  37. Control.GetInstance.MakeOrderQueue.Enqueue(data);
  38. Control.GetInstance.NotifyPrompt("配方下发成功!");
  39. grindArenaceousView.ShowDialog();
  40. });
  41. }
  42. }
  43. }
  44. else
  45. {
  46. App.Current.Dispatcher.Invoke(() =>
  47. {
  48. NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "错误", "配方下发失败,硬件设备状态未装备就绪!");
  49. });
  50. Control.GetInstance.RunLog("配方下发失败,硬件设备状态未装备就绪!");
  51. }
  52. });
  53. });
  54. DeviceInitCommand = new RelayCommand(() => { PlcServer.GetInstance.WriteData("M10.3", true); });
  55. }
  56. public RelayCommand DeviceInitCommand { get; set; }
  57. public ObservableCollection<RecipeInfo> Recipes { get; set; }
  58. public RelayCommand<object> StartCommand { get; set; }
  59. }
  60. }