using BPASmartClient.CustomResource.Pages.Model; using BPASmartClient.CustomResource.UserControls; using BPASmartClient.CustomResource.UserControls.MessageShow; using BPA.Helper; using BPASmartClient.JXJFoodBigStation.Model; using BPASmartClient.JXJFoodBigStation.Model.Siemens; using BPASmartClient.JXJFoodBigStation.View; using BPA.Helper; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BPASmartClient.JXJFoodBigStation.ViewModel { internal class RecipeSendDownViewModel:NotifyBase { public ObservableCollection Recipes { get; set; } = Json.Data.Recipes; /// /// 当前正在制作的配方 /// public static ObservableCollection recipeProcesses { get; set; } = new ObservableCollection(); /// /// 等待制作的配方 /// public static ObservableCollection UserTreeWait { get; set; } = new ObservableCollection(); /// /// 已完成的配方 /// public static ObservableCollection UserTreeCompelete { get; set; } = new ObservableCollection(); /// /// 筛选后的配方列表。 /// public static ObservableCollection SelectedRecipes { get; set; } public BPARelayCommand StartCommand { get; set; } public BPARelayCommand SelectRecipesCommand { get; set; } public RecipeSendDownViewModel() { SelectedRecipes= Json.Data.SelectedRecipes; StartCommand = new BPARelayCommand((recipeName) => { if (recipeName != null) { if (GVL_BigStation.IsUseLocalRecipe) { if (!MessageNotify.GetInstance.ShowDialog($"请确认,是否下发配方【{recipeName}】?")) { return; } //配方下发逻辑 var res = Recipes.FirstOrDefault(p => p.RecipeName == recipeName); if (res != null) { if (!Json.Data.Recipes.Any(p=>p.RecipeCode==res.RecipeCode)) { res.RecipesSource = RecipeSource.本地; Json.Data.Recipes.Add(res); MessageNotify.GetInstance.ShowRunLog($"接收手动下发配方:【{recipeName}】"); MessageNotify.GetInstance.ShowUserLog($"手动下发配方:【{recipeName}】完成"); NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "成功", $"配方下发完成"); } else { NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "失败", $"配方下发失败,已下发过此配方。"); } } } else { NoticeDemoViewModel.OpenMsg(EnumPromptType.Warn, App.MainWindow, "警告", $"未处于本地配方模式,无法下发配方"); } } }); SelectRecipesCommand = new BPARelayCommand(() => { var selectView = new SelectRecipesView(); selectView.ShowDialog(); Json.Data.SelectedRecipes.Clear(); foreach ( var recipe in SelectRecipesViewModel.SelectRecipes ) { if ( recipe != null && !Json.Data.SelectedRecipes.Any(p=>p.RecipeCode==recipe.RecipeCode)) { Json.Data.SelectedRecipes.Add(recipe); } } //不保存会导致下次打开本地配方下发页面,会重新读取之前存储的文件。 Json.Save(); }); } } }