using BPASmartClient.CustomResource.Pages.Model; using BPASmartClient.CustomResource.UserControls; using BPASmartClient.CustomResource.UserControls.MessageShow; using BPASmartClient.Helper; using FryPot_DosingSystem.Model; using FryPot_DosingSystem.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; using System.Windows; namespace FryPot_DosingSystem.ViewModel { internal class RecipeSetViewModel : ObservableObject { ///// ///// 配方编号 ///// //private int _serialNumber; //public int SerialNumber { get { return _serialNumber; } set { _serialNumber = value;OnPropertyChanged(); } } ///// ///// 配方名称 ///// //private string _recipeName; //public string RecipeName { get { return _recipeName; } set { _recipeName = value; OnPropertyChanged(); } } public ObservableCollection recipeModels { get; set; } = new ObservableCollection(); public RelayCommand NewRecipe { get; set; } public RelayCommand SaveRecipe { get; set; } /// /// 工艺操作 /// public RelayCommand OperateFlowProcess { get; set; } /// /// 编辑配方 /// public RelayCommand EditRecipeCommand { get; set; } /// /// 删除配方 /// public RelayCommand DeleteRecipeCommand { get; set; } public RecipeSetViewModel() { Json.Read(); recipeModels =Json.Data.Recipes; int count = recipeModels.Count; bool sign = false; ActionManage.GetInstance.CancelRegister("RecipeIsChange"); ActionManage.GetInstance.RegisterAsync(new Action(() => { if (!sign) { bool b = Json.Data.Recipes.Count == count ? true : false; if (!b) { MessageBoxResult result = MessageBox.Show("配方数据未保存,是否保存", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Information); if (result == MessageBoxResult.OK) { Json.Save();//保存配方 count = recipeModels.Count; } else { sign = true; } } } }), "RecipeIsChange"); NewRecipe =new RelayCommand( new Action(() => { NewRecipeView nrv = new NewRecipeView(); nrv.ShowDialog(); //MessageLog.GetInstance.ShowUserLog("新建配方"); })); SaveRecipe =new RelayCommand( new Action(() => { Json.Save(); count = recipeModels.Count; NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方保存成功!"); })); EditRecipeCommand = new RelayCommand((Id) => { if (Id != null) { ActionManage.GetInstance.CancelRegister("EditRecipe"); NewRecipeView nrv = new NewRecipeView(); ActionManage.GetInstance.Send("EditRecipe", Id); nrv.ShowDialog(); } }); DeleteRecipeCommand = new RelayCommand((Id) => { if (Id != null && Id is String strId) { var res = recipeModels.FirstOrDefault(p => p.RecipeId == strId); if (res != null && res is NewRecipeModel nes) { recipeModels.Remove(res);//删除配方 Json.Save();//保存配方 count = recipeModels.Count; } } }); //工艺流程操作 OperateFlowProcess = new RelayCommand((recipeName) => { if (recipeName != null && recipeName != string.Empty && recipeName != "") { ActionManage.GetInstance.CancelRegister("EditFlowProcess"); FlowProcessView fps = new FlowProcessView(); ActionManage.GetInstance.Send("EditFlowProcess", recipeName); fps.ShowDialog(); } }); } } }