|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- using BPASmartClient.Helper;
- using FryPot_DosingSystem.Model;
- 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 NewRecipeViewModel : ObservableObject
- {
- /// <summary>
- /// 配方唯一编码,用于编辑配方
- /// </summary>
- public string recipeId { get; set; }
- /// <summary>
- /// 配料名称
- /// </summary>
- private string _recipeName;
- public string RecipeName { get { return _recipeName; } set { _recipeName = value; OnPropertyChanged(); } }
-
- public ObservableCollection<MaterialType> materials { get; set; } = new ObservableCollection<MaterialType>();
-
- public ObservableCollection<string> materialNames { get; set; } = new ObservableCollection<string>() { "肉","葱","蒜"};
-
- public RelayCommand AddRecipe { get; set; }
- public RelayCommand<string> RemoveRecipe { get; set; }
- public RelayCommand Comfirm { get; set; }
- public NewRecipeViewModel()
- {
- ActionManage.GetInstance.Register(new Action<object>(Id => {
- if (Id != null && Id is string strId)
- {
- var res = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.RecipeId == strId);
- if (res != null && res is NewRecipeModel rom)
- {
- RecipeName = rom.RecipeName;
- foreach (var item in rom.materialCollection)
- {
- materials.Add(item);
- }
- recipeId = strId;
- }
- }
- }),"EditRecipe");
- AddRecipe = new RelayCommand(() =>
- {
- pr:
- string materialCode = Guid.NewGuid().ToString();//原料唯一ID ,后期需要根据实际要求更改
- var res = materials.FirstOrDefault(p => p.MaterialCode == materialCode);
- if (res == null)
- {
- materials.Add(new MaterialType() { MaterialCode = materialCode });
- }
- else
- {
- goto pr;
- }
- });
- RemoveRecipe = new RelayCommand<string>(code =>
- {
- var res = materials.FirstOrDefault(m => m.MaterialCode == code);
- if (res != null)
- materials.Remove(res);
- });
- Comfirm = new RelayCommand(() =>
- {
- var bom = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.RecipeId == recipeId);
- if (bom == null)//新配方
- {
- prop: string recipeID = Guid.NewGuid().ToString();//配方唯一ID,后期根据实际要求更改
- var res = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.RecipeId == recipeID);
- if (res == null)
- {
- Json<RecipeManage>.Data.Recipes.Add(new NewRecipeModel { RecipeId = recipeID, RecipeName = RecipeName, materialCollection = materials });//配方添加
-
- }
- else
- {
- goto prop;
- }
- ActionManage.GetInstance.Send("CloseNewRecipeView");
- }
- else //已有配方,用于编辑
- {
- bom.materialCollection= materials;
- bom.RecipeName = RecipeName;
- ActionManage.GetInstance.Send("CloseNewRecipeView");
- }
- });
-
- }
- }
- }
|