终端一体化运控平台
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 

78 рядки
3.3 KiB

  1. using BPASmartClient.Helper;
  2. using FryPot_DosingSystem.Model;
  3. using Microsoft.Toolkit.Mvvm.Input;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Collections.ObjectModel;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace FryPot_DosingSystem.ViewModel
  11. {
  12. internal class FlowProcessSetViewModel
  13. {
  14. public int Id { get; set; } = 0;
  15. public ObservableCollection<FlowProcessModel> flowProcessModels { get; set; } = new ObservableCollection<FlowProcessModel>();
  16. public string currnetRecipeName { get; set;}
  17. public RelayCommand CloseWindowCommand { get; set; }
  18. public RelayCommand ConfirmCommand { get; set; }
  19. public FlowProcessSetViewModel()
  20. {
  21. ActionManage.GetInstance.Register(new Action<object>(recipeName =>
  22. {
  23. if (recipeName != null)
  24. {
  25. currnetRecipeName = recipeName.ToString();
  26. var res = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.FlowProcess.RecipeName == recipeName.ToString());
  27. if (res != null && res is NewRecipeModel recipe) //编辑已有工艺
  28. {
  29. //flowProcessModels = recipe.FlowProcess.fpModels;
  30. foreach (var item in recipe.FlowProcess.fpModels)
  31. {
  32. flowProcessModels.Add(new FlowProcessModel { Id = item.Id, FryMaterialNum = item.FryMaterialNum, FrySpeed = item.FrySpeed, FryWeight = item.FryWeight, FryTemperature = item.FryTemperature, FryPeriodTime = item.FryPeriodTime });
  33. }
  34. }
  35. else//创建新工艺
  36. {
  37. var name = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p=>p.RecipeName==recipeName.ToString());
  38. if (name != null)
  39. {
  40. name.FlowProcess.RecipeName = recipeName.ToString();
  41. flowProcessModels.Add(new FlowProcessModel { Id = Id + 1, FryMaterialNum = "油" });
  42. Id++;
  43. foreach (var item in name.materialCollection)
  44. {
  45. flowProcessModels.Add(new FlowProcessModel { Id = Id + 1, FryMaterialNum = item.MaterialName });
  46. Id++;
  47. }
  48. name.FlowProcess.fpModels= flowProcessModels;
  49. }
  50. }
  51. }
  52. }), "EditFlowProcess");
  53. CloseWindowCommand = new RelayCommand(() =>
  54. {
  55. ActionManage.GetInstance.Send("CloseFlowProcessView");
  56. });
  57. ConfirmCommand = new RelayCommand(() =>
  58. {
  59. var name = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.RecipeName == currnetRecipeName.ToString());
  60. if (name != null)
  61. {
  62. name.FlowProcess.RecipeName = currnetRecipeName.ToString();
  63. name.FlowProcess.fpModels = flowProcessModels;
  64. }
  65. Json<RecipeManage>.Save();
  66. ActionManage.GetInstance.Send("CloseFlowProcessView");
  67. });
  68. }
  69. }
  70. }