|
- 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
- {
- ///// <summary>
- ///// 配方编号
- ///// </summary>
- //private int _serialNumber;
- //public int SerialNumber { get { return _serialNumber; } set { _serialNumber = value;OnPropertyChanged(); } }
- ///// <summary>
- ///// 配方名称
- ///// </summary>
- //private string _recipeName;
- //public string RecipeName { get { return _recipeName; } set { _recipeName = value; OnPropertyChanged(); } }
-
- public ObservableCollection<NewRecipeModel> recipeModels { get; set; } = new ObservableCollection<NewRecipeModel>();
-
- public RelayCommand NewRecipe { get; set; }
-
- public RelayCommand SaveRecipe { get; set; }
- /// <summary>
- /// 工艺操作
- /// </summary>
- public RelayCommand<string> OperateFlowProcess { get; set; }
- /// <summary>
- /// 编辑配方
- /// </summary>
- public RelayCommand<object> EditRecipeCommand { get; set; }
- /// <summary>
- /// 删除配方
- /// </summary>
- public RelayCommand<object> DeleteRecipeCommand { get; set; }
-
- public RecipeSetViewModel()
- {
- Json<RecipeManage>.Read();
- recipeModels =Json<RecipeManage>.Data.Recipes;
- int count = recipeModels.Count;
- bool sign = false;
- ActionManage.GetInstance.CancelRegister("RecipeIsChange");
- ActionManage.GetInstance.RegisterAsync(new Action(() =>
- {
- if (!sign)
- {
- bool b = Json<RecipeManage>.Data.Recipes.Count == count ? true : false;
- if (!b)
- {
- MessageBoxResult result = MessageBox.Show("配方数据未保存,是否保存", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Information);
- if (result == MessageBoxResult.OK)
- {
- Json<RecipeManage>.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<RecipeManage>.Save();
- count = recipeModels.Count;
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方保存成功!");
- }));
- EditRecipeCommand = new RelayCommand<object>((Id) =>
- {
- if (Id != null)
- {
- ActionManage.GetInstance.CancelRegister("EditRecipe");
- NewRecipeView nrv = new NewRecipeView();
- ActionManage.GetInstance.Send("EditRecipe", Id);
- nrv.ShowDialog();
- }
- });
- DeleteRecipeCommand = new RelayCommand<object>((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<RecipeManage>.Save();//保存配方
- count = recipeModels.Count;
- }
- }
- });
- //工艺流程操作
- OperateFlowProcess = new RelayCommand<string>((recipeName) =>
- {
- if (recipeName != null && recipeName != string.Empty && recipeName != "")
- {
- ActionManage.GetInstance.CancelRegister("EditFlowProcess");
- FlowProcessView fps = new FlowProcessView();
- ActionManage.GetInstance.Send("EditFlowProcess", recipeName);
- fps.ShowDialog();
- }
-
- });
- }
- }
- }
|