|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- 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 static int materialNum { get; set; }
- public ObservableCollection<FlowProcessModel> flowProcessModels { get; set; } = new ObservableCollection<FlowProcessModel>();
-
- public string currentRecipeName { get; set; }
- public static int currentItemId { get; set; }
- public RelayCommand CloseWindowCommand { get; set; }
-
- public ObservableCollection<string> FlowItems { get; set; } = new ObservableCollection<string>();
- public RelayCommand ConfirmCommand { get; set; }
- public RelayCommand AddLastFlowItemCommand { get; set; }
- public RelayCommand AddFrontFlowItemCommand { get; set; }
- public RelayCommand DeleteFlowItemCommand { get; set; }
- public FlowProcessSetViewModel()
- {
- Json<FlowProcessNames>.Read();
- // FlowProcessNames.GetInstance.Names = Json<FlowProcessNames>.Data.Names;
- FlowItems = Json<FlowProcessNames>.Data.Names;
- ActionManage.GetInstance.Register(new Action<object>((obj) =>
- {
- if (obj != null)
- try
- {
- currentItemId = Convert.ToInt32(obj);
- }
- catch (Exception)
- {
-
- }
- }), "CurrentItemId");
- //ActionManage.GetInstance.Register(new Action<object>(obj =>
- //{
- // if (obj != null)
- // materialNum = Convert.ToInt32(obj);
- //}), "MaterialNum");
- ActionManage.GetInstance.Register(new Action<object>(recipeName =>
- {
- if (recipeName != null)
- {
- currentRecipeName = recipeName.ToString();
- var res = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.FlowProcess.RecipeName == recipeName.ToString());
- if (res != null && res is NewRecipeModel recipe) //编辑已有工艺
- {
- foreach (var item in recipe.materialCollection)
- {
- if (!FlowItems.Contains(item.MaterialName))
- FlowItems.Insert(0, item.MaterialName);//下拉框
- }
- foreach (var item in recipe.FlowProcess.fpModels)
- {
- flowProcessModels.Add(new FlowProcessModel {FryMaterialNum = item.FryMaterialNum, FrySpeed = item.FrySpeed, FryWeight = item.FryWeight, FryTemperature = item.FryTemperature, FryPeriodTime = item.FryPeriodTime });
- }
-
- // ActionManage.GetInstance.Send("MaterialNum", recipe.materialCollection.Count);
- }
- else//创建新工艺
- {
- var name = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.RecipeName == recipeName.ToString());
- if (name != null)
- {
- name.FlowProcess.RecipeName = recipeName.ToString();
-
- foreach (var item in name.materialCollection)
- {
-
- if (!FlowItems.Contains(item.MaterialName))
- FlowItems.Insert(0, item.MaterialName);//下拉框
- }
- ActionManage.GetInstance.Send("MaterialNum", name.materialCollection.Count);
- 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 == currentRecipeName.ToString());
- if (name != null)
- {
- name.FlowProcess.RecipeName = currentRecipeName.ToString();
- // name.FlowProcess.fpModels = flowProcessModels;
- name.FlowProcess.fpModels.Clear();
- foreach (var item in flowProcessModels)
- {
- name.FlowProcess.fpModels.Add(new FlowProcessModel { FryMaterialNum = item.FryMaterialNum, FrySpeed = item.FrySpeed, FryWeight = item.FryWeight, FryTemperature = item.FryTemperature, FryPeriodTime = item.FryPeriodTime });
- }
- foreach (var item in name.materialCollection)
- {
- string s= Json<FlowProcessNames>.Data.Names.FirstOrDefault(p=>p == item.MaterialName);
- Json<FlowProcessNames>.Data.Names.Remove(s);
- }
- }
- Json<RecipeManage>.Save();
-
-
- Json<FlowProcessNames>.Save();
- ActionManage.GetInstance.Send("CloseFlowProcessView");
- });
-
- AddFrontFlowItemCommand = new RelayCommand(() =>
- {
- try
- {
- if (currentItemId == 0)
- {
- flowProcessModels.Insert(0, new FlowProcessModel());
- }
- else
- {
- flowProcessModels.Insert(currentItemId, new FlowProcessModel());
- currentItemId = currentItemId + 1;
- }
- }
- catch (Exception)
- {
-
- //throw;
- }
-
- });
- AddLastFlowItemCommand = new RelayCommand(() =>
- {
- try
- {
- if (flowProcessModels.Count <= 0)
- {
- flowProcessModels.Insert(0, new FlowProcessModel());
-
- }
- else if (currentItemId != 0)
- {
- flowProcessModels.Insert(currentItemId + 1, new FlowProcessModel());
- }
- else
- {
- flowProcessModels.Add(new FlowProcessModel());
- }
- }
- catch (Exception)
- {
-
- // throw;
- }
- });
- DeleteFlowItemCommand = new RelayCommand(() =>
- {
- if (flowProcessModels.Count > 0)
- flowProcessModels.RemoveAt(currentItemId);
- currentItemId = 0;
- });
- }
- }
- }
|