using BPASmartClient.CustomResource.Pages.Model; using BPASmartClient.CustomResource.UserControls; using BPASmartClient.CustomResource.UserControls.MessageShow; using BPASmartClient.Helper; using BPASmartClient.JXJFoodBigStation.Model; using BPASmartClient.JXJFoodBigStation.Model.Siemens; using BPASmartClient.JXJFoodBigStation.View; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.Toolkit.Mvvm.Input; 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:ObservableObject { 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; } = new ObservableCollection(); public RelayCommand StartCommand { get; set; } public RelayCommand SelectRecipesCommand { get; set; } public RecipeSendDownViewModel() { var tempcoll = new ObservableCollection(); foreach (var item in Json.Data.SelectedRecipes) { if (!Json.Data.Recipes.Any(p => p.RecipeCode.Equals(item.RecipeCode) && p.RecipeName.Equals(item.RecipeName) && p.IsWashingBarrel == item.IsWashingBarrel && p.TrayCode == item.TrayCode)) { tempcoll.Add(item); } } foreach (var item in tempcoll) { Json.Data.SelectedRecipes.Remove(item); } Json.Save(); tempcoll.Clear(); SelectedRecipes = Json.Data.SelectedRecipes; StartCommand = new RelayCommand((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 RelayCommand(() => { var selectView = new SelectRecipesView(); selectView.ShowDialog(); SelectedRecipes.Clear(); 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(); }); } } }