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

175 lines
7.0 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 static int materialNum { get; set; }
  16. public ObservableCollection<FlowProcessModel> flowProcessModels { get; set; } = new ObservableCollection<FlowProcessModel>();
  17. public string currentRecipeName { get; set; }
  18. public static int currentItemId { get; set; }
  19. public RelayCommand CloseWindowCommand { get; set; }
  20. public ObservableCollection<string> FlowItems { get; set; } = new ObservableCollection<string>();
  21. public RelayCommand ConfirmCommand { get; set; }
  22. public RelayCommand AddLastFlowItemCommand { get; set; }
  23. public RelayCommand AddFrontFlowItemCommand { get; set; }
  24. public RelayCommand DeleteFlowItemCommand { get; set; }
  25. public FlowProcessSetViewModel()
  26. {
  27. Json<FlowProcessNames>.Read();
  28. // FlowProcessNames.GetInstance.Names = Json<FlowProcessNames>.Data.Names;
  29. FlowItems = Json<FlowProcessNames>.Data.Names;
  30. ActionManage.GetInstance.Register(new Action<object>((obj) =>
  31. {
  32. if (obj != null)
  33. try
  34. {
  35. currentItemId = Convert.ToInt32(obj);
  36. }
  37. catch (Exception)
  38. {
  39. }
  40. }), "CurrentItemId");
  41. //ActionManage.GetInstance.Register(new Action<object>(obj =>
  42. //{
  43. // if (obj != null)
  44. // materialNum = Convert.ToInt32(obj);
  45. //}), "MaterialNum");
  46. ActionManage.GetInstance.Register(new Action<object>(recipeName =>
  47. {
  48. if (recipeName != null)
  49. {
  50. currentRecipeName = recipeName.ToString();
  51. var res = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.FlowProcess.RecipeName == recipeName.ToString());
  52. if (res != null && res is NewRecipeModel recipe) //编辑已有工艺
  53. {
  54. foreach (var item in recipe.materialCollection)
  55. {
  56. if (!FlowItems.Contains(item.MaterialName))
  57. FlowItems.Insert(0, item.MaterialName);//下拉框
  58. }
  59. foreach (var item in recipe.FlowProcess.fpModels)
  60. {
  61. flowProcessModels.Add(new FlowProcessModel {FryMaterialNum = item.FryMaterialNum, FrySpeed = item.FrySpeed, FryWeight = item.FryWeight, FryTemperature = item.FryTemperature, FryPeriodTime = item.FryPeriodTime });
  62. }
  63. // ActionManage.GetInstance.Send("MaterialNum", recipe.materialCollection.Count);
  64. }
  65. else//创建新工艺
  66. {
  67. var name = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.RecipeName == recipeName.ToString());
  68. if (name != null)
  69. {
  70. name.FlowProcess.RecipeName = recipeName.ToString();
  71. foreach (var item in name.materialCollection)
  72. {
  73. if (!FlowItems.Contains(item.MaterialName))
  74. FlowItems.Insert(0, item.MaterialName);//下拉框
  75. }
  76. ActionManage.GetInstance.Send("MaterialNum", name.materialCollection.Count);
  77. name.FlowProcess.fpModels = flowProcessModels;
  78. }
  79. }
  80. }
  81. }), "EditFlowProcess");
  82. CloseWindowCommand = new RelayCommand(() =>
  83. {
  84. ActionManage.GetInstance.Send("CloseFlowProcessView");
  85. });
  86. ConfirmCommand = new RelayCommand(() =>
  87. {
  88. var name = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.RecipeName == currentRecipeName.ToString());
  89. if (name != null)
  90. {
  91. name.FlowProcess.RecipeName = currentRecipeName.ToString();
  92. // name.FlowProcess.fpModels = flowProcessModels;
  93. name.FlowProcess.fpModels.Clear();
  94. foreach (var item in flowProcessModels)
  95. {
  96. name.FlowProcess.fpModels.Add(new FlowProcessModel { FryMaterialNum = item.FryMaterialNum, FrySpeed = item.FrySpeed, FryWeight = item.FryWeight, FryTemperature = item.FryTemperature, FryPeriodTime = item.FryPeriodTime });
  97. }
  98. foreach (var item in name.materialCollection)
  99. {
  100. string s= Json<FlowProcessNames>.Data.Names.FirstOrDefault(p=>p == item.MaterialName);
  101. Json<FlowProcessNames>.Data.Names.Remove(s);
  102. }
  103. }
  104. Json<RecipeManage>.Save();
  105. Json<FlowProcessNames>.Save();
  106. ActionManage.GetInstance.Send("CloseFlowProcessView");
  107. });
  108. AddFrontFlowItemCommand = new RelayCommand(() =>
  109. {
  110. try
  111. {
  112. if (currentItemId == 0)
  113. {
  114. flowProcessModels.Insert(0, new FlowProcessModel());
  115. }
  116. else
  117. {
  118. flowProcessModels.Insert(currentItemId, new FlowProcessModel());
  119. currentItemId = currentItemId + 1;
  120. }
  121. }
  122. catch (Exception)
  123. {
  124. //throw;
  125. }
  126. });
  127. AddLastFlowItemCommand = new RelayCommand(() =>
  128. {
  129. try
  130. {
  131. if (flowProcessModels.Count <= 0)
  132. {
  133. flowProcessModels.Insert(0, new FlowProcessModel());
  134. }
  135. else if (currentItemId != 0)
  136. {
  137. flowProcessModels.Insert(currentItemId + 1, new FlowProcessModel());
  138. }
  139. else
  140. {
  141. flowProcessModels.Add(new FlowProcessModel());
  142. }
  143. }
  144. catch (Exception)
  145. {
  146. // throw;
  147. }
  148. });
  149. DeleteFlowItemCommand = new RelayCommand(() =>
  150. {
  151. if (flowProcessModels.Count > 0)
  152. flowProcessModels.RemoveAt(currentItemId);
  153. currentItemId = 0;
  154. });
  155. }
  156. }
  157. }