|
- using BPASmartClient.Helper;
- using FryPot_DosingSystem.Model;
- 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 FlowProcessSetViewModel
- {
- public int Id { get; set; } = 0;
- public ObservableCollection<FlowProcessModel> flowProcessModels { get; set; } = new ObservableCollection<FlowProcessModel>();
-
- public string currnetRecipeName { get; set;}
- public RelayCommand CloseWindowCommand { get; set; }
-
- public RelayCommand ConfirmCommand { get; set; }
- public FlowProcessSetViewModel()
- {
- ActionManage.GetInstance.Register(new Action<object>(recipeName =>
- {
- if (recipeName != null)
- {
- currnetRecipeName = recipeName.ToString();
- var res = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.FlowProcess.RecipeName == recipeName.ToString());
- if (res != null && res is NewRecipeModel recipe) //编辑已有工艺
- {
- //flowProcessModels = recipe.FlowProcess.fpModels;
- foreach (var item in recipe.FlowProcess.fpModels)
- {
- flowProcessModels.Add(new FlowProcessModel { Id = item.Id, FryMaterialNum = item.FryMaterialNum, FrySpeed = item.FrySpeed, FryWeight = item.FryWeight, FryTemperature = item.FryTemperature, FryPeriodTime = item.FryPeriodTime });
- }
- }
- else//创建新工艺
- {
- var name = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p=>p.RecipeName==recipeName.ToString());
- if (name != null)
- {
- name.FlowProcess.RecipeName = recipeName.ToString();
- flowProcessModels.Add(new FlowProcessModel { Id = Id + 1, FryMaterialNum = "油" });
- Id++;
- foreach (var item in name.materialCollection)
- {
- flowProcessModels.Add(new FlowProcessModel { Id = Id + 1, FryMaterialNum = item.MaterialName });
- Id++;
- }
- name.FlowProcess.fpModels= flowProcessModels;
- }
-
- }
- }
-
-
- }), "EditFlowProcess");
- CloseWindowCommand = new RelayCommand(() =>
- {
-
- ActionManage.GetInstance.Send("CloseFlowProcessView");
- });
- ConfirmCommand = new RelayCommand(() =>
- {
- var name = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.RecipeName == currnetRecipeName.ToString());
- if (name != null)
- {
- name.FlowProcess.RecipeName = currnetRecipeName.ToString();
- name.FlowProcess.fpModels = flowProcessModels;
- }
- Json<RecipeManage>.Save();
- ActionManage.GetInstance.Send("CloseFlowProcessView");
- });
- }
- }
- }
|