You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
- using BPASmartClient.Helper;
- using BPASmartClient.Message;
- 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;
-
- 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 Action NewRecipe { get; set; }
-
- public Action SaveRecipe { 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;
- NewRecipe = new Action(() =>
- {
- NewRecipeView nrv = new NewRecipeView();
- nrv.ShowDialog();
- MessageLog.GetInstance.Show("新建配方");
- });
- SaveRecipe = new Action(() => {
- Json<RecipeManage>.Save();
- });
- 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();//保存配方
- }
- }
- });
- }
- }
- }
|