终端一体化运控平台
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.
 
 
 

82 lines
3.6 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&&res.FlowProcess.fpModels.Count==res.materialCollection.Count+1) //编辑已有工艺
  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. if (name.FlowProcess.fpModels.Count > 0)
  41. {
  42. name.FlowProcess.fpModels.Clear();
  43. }
  44. name.FlowProcess.RecipeName = recipeName.ToString();
  45. flowProcessModels.Add(new FlowProcessModel { Id = Id + 1, FryMaterialNum = "油" });
  46. Id++;
  47. foreach (var item in name.materialCollection)
  48. {
  49. flowProcessModels.Add(new FlowProcessModel { Id = Id + 1, FryMaterialNum = item.MaterialName });
  50. Id++;
  51. }
  52. name.FlowProcess.fpModels= flowProcessModels;
  53. }
  54. }
  55. }
  56. }), "EditFlowProcess");
  57. CloseWindowCommand = new RelayCommand(() =>
  58. {
  59. ActionManage.GetInstance.Send("CloseFlowProcessView");
  60. });
  61. ConfirmCommand = new RelayCommand(() =>
  62. {
  63. var name = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.RecipeName == currnetRecipeName.ToString());
  64. if (name != null)
  65. {
  66. name.FlowProcess.RecipeName = currnetRecipeName.ToString();
  67. name.FlowProcess.fpModels = flowProcessModels;
  68. }
  69. Json<RecipeManage>.Save();
  70. ActionManage.GetInstance.Send("CloseFlowProcessView");
  71. });
  72. }
  73. }
  74. }