using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using BPA.Helper; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.Input; using BPASmartClient.SmallBatchingSystem.Views; using BPASmartClient.CustomResource.UserControls.MessageShow; using BPASmartClient.CustomResource.UserControls; using BPASmartClient.CustomResource.Pages.Model; namespace BPASmartClient.SmallBatchingSystem.ViewModels { public class RecipeControlViewModel : ObservableObject { public RecipeControlViewModel() { Recipes = Json.Data.Recipes; StartCommand = new RelayCommand((o) => { Task.Factory.StartNew(() => { if (PlcDataModel.RecipeBatchingComplete) { if (!string.IsNullOrEmpty(o?.ToString())) { int index = Array.FindIndex(Json.Data.Recipes.ToArray(), p => p.RecipeName == o.ToString()); if (index >= 0 && index < Json.Data.Recipes.Count) { App.Current.Dispatcher.Invoke(() => { var data = Json.Data.Recipes.ElementAt(index); Control.GetInstance.RunLog($"下发配方:{data.RecipeName}"); GrindArenaceousView grindArenaceousView = new GrindArenaceousView(); ActionManage.GetInstance.Send("OpenRecipeStatusMotion", data); Control.GetInstance.MakeOrderQueue.Enqueue(data); Control.GetInstance.NotifyPrompt("配方下发成功!"); grindArenaceousView.ShowDialog(); }); } } } else { //App.Current.Dispatcher.Invoke(() => //{ // NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "错误", "配方下发失败,硬件设备状态未装备就绪!"); //}); MessageNotify.GetInstance.ShowDialog($"配方下发失败,硬件设备状态未装备就绪!", DialogType.Error); Control.GetInstance.RunLog("配方下发失败,硬件设备状态未装备就绪!"); } }); }); DeviceInitCommand = new RelayCommand(() => { PlcServer.GetInstance.WriteData("M10.4", true); }); } public RelayCommand DeviceInitCommand { get; set; } public ObservableCollection Recipes { get; set; } public RelayCommand StartCommand { get; set; } } }