终端一体化运控平台
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

227 Zeilen
10 KiB

  1. using BPASmartClient.CustomResource.Pages.Model;
  2. using BPASmartClient.CustomResource.UserControls;
  3. using BPASmartClient.CustomResource.UserControls.MessageShow;
  4. using BPASmartClient.Helper;
  5. using FryPot_DosingSystem.Model;
  6. using Microsoft.Toolkit.Mvvm.ComponentModel;
  7. using Microsoft.Toolkit.Mvvm.Input;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Collections.ObjectModel;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows;
  15. namespace FryPot_DosingSystem.ViewModel
  16. {
  17. internal class FlowProcessSetViewModel:ObservableObject
  18. {
  19. public int Id { get; set; } = 0;
  20. public static int materialNum { get; set; }
  21. public ObservableCollection<FlowProcessModel> flowProcessModels { get; set; } = new ObservableCollection<FlowProcessModel>();
  22. /// <summary>
  23. /// 目标重量偏差
  24. /// </summary>
  25. public string targetWeightOffset { get { return _targetWeightOffset; } set { _targetWeightOffset = value;OnPropertyChanged(); } }
  26. private string _targetWeightOffset="0";
  27. public string currentRecipeName { get; set; }
  28. public static int currentItemId { get; set; }
  29. public RelayCommand CloseWindowCommand { get; set; }
  30. public ObservableCollection<string> FlowItems { get; set; } = new ObservableCollection<string>();
  31. public RelayCommand ConfirmCommand { get; set; }
  32. public RelayCommand AddLastFlowItemCommand { get; set; }
  33. public RelayCommand AddFrontFlowItemCommand { get; set; }
  34. public RelayCommand DeleteFlowItemCommand { get; set; }
  35. public FlowProcessSetViewModel()
  36. {
  37. Json<FlowProcessNames>.Read();
  38. // FlowProcessNames.GetInstance.Names = Json<FlowProcessNames>.Data.Names;
  39. // FlowItems = Json<FlowProcessNames>.Data.NameId;
  40. foreach (KeyValuePair<string, int> item in Json<FlowProcessNames>.Data.NameId)
  41. {
  42. FlowItems.Add(item.Key);
  43. }
  44. ActionManage.GetInstance.Register(new Action<object>((obj) =>
  45. {
  46. if (obj != null)
  47. try
  48. {
  49. currentItemId = Convert.ToInt32(obj);
  50. }
  51. catch (Exception)
  52. {
  53. }
  54. }), "CurrentItemId");
  55. //ActionManage.GetInstance.Register(new Action<object>(obj =>
  56. //{
  57. // if (obj != null)
  58. // materialNum = Convert.ToInt32(obj);
  59. //}), "MaterialNum");
  60. ActionManage.GetInstance.Register(new Action<object>(recipeName =>
  61. {
  62. if (recipeName != null)
  63. {
  64. currentRecipeName = recipeName.ToString();
  65. var res = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.FlowProcess?.RecipeName == recipeName?.ToString());
  66. if (res != null && res is NewRecipeModel recipe) //编辑已有工艺
  67. {
  68. targetWeightOffset = recipe.FlowProcess.targetWeightOffset.ToString();
  69. foreach (var item in recipe.materialCollection)
  70. {
  71. if (!FlowItems.Contains(item.MaterialLoc.ToString()))
  72. FlowItems.Add(item.MaterialLoc.ToString());//下拉框
  73. }
  74. foreach (var item in recipe.FlowProcess.fpModels)
  75. {
  76. flowProcessModels.Add(new FlowProcessModel { FryMaterialNum = item.FryMaterialNum, FrySpeed = item.FrySpeed, FryWeight = item.FryWeight, TargeWeight=item.TargeWeight, FryTemperature = item.FryTemperature, FryPeriodTime = item.FryPeriodTime, SmallFirePercent = item.SmallFirePercent, MidFirePercent = item.MidFirePercent, BigFirePercent = item.BigFirePercent, StrongFirePercent = item.StrongFirePercent });
  77. }
  78. // ActionManage.GetInstance.Send("MaterialNum", recipe.materialCollection.Count);
  79. }
  80. else//创建新工艺
  81. {
  82. var name = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.RecipeName == recipeName.ToString());
  83. if (name != null)
  84. {
  85. name.FlowProcess.RecipeName = recipeName.ToString();
  86. foreach (var item in name.materialCollection)
  87. {
  88. if (!FlowItems.Contains(item.MaterialLoc.ToString()))
  89. FlowItems.Add(item.MaterialLoc.ToString());//下拉框
  90. }
  91. ActionManage.GetInstance.Send("MaterialNum", name.materialCollection.Count);
  92. //name.FlowProcess.fpModels = flowProcessModels;
  93. }
  94. }
  95. }
  96. }), "EditFlowProcess");
  97. CloseWindowCommand = new RelayCommand(() =>
  98. {
  99. ActionManage.GetInstance.Send("CloseFlowProcessView");
  100. });
  101. ConfirmCommand = new RelayCommand(() =>
  102. {
  103. var name = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.RecipeName == currentRecipeName.ToString());
  104. if (name != null)
  105. {
  106. name.FlowProcess.RecipeName = currentRecipeName.ToString();
  107. if (float.TryParse(targetWeightOffset.Trim(), out float offset))
  108. {
  109. name.FlowProcess.targetWeightOffset = offset;//目标重量偏差
  110. }
  111. else
  112. {
  113. MessageBox.Show("非法目标重量偏差设置", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
  114. name.FlowProcess.targetWeightOffset = 0.0F;
  115. return;
  116. }
  117. //工艺桶号重复性检测
  118. foreach (var item in name.materialCollection)
  119. {
  120. var res = flowProcessModels.Where(p => p.FryMaterialNum == item.MaterialLoc.ToString());
  121. if (res.Count() > 1)
  122. {
  123. // NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "提示", $"保存失败,桶号重复!");
  124. MessageNotify.GetInstance.ShowUserLog("保存失败,桶号重复");
  125. MessageBox.Show("保存失败,桶号重复", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
  126. return;
  127. }
  128. }
  129. //工艺步骤中清洗工艺重复性检测
  130. if (flowProcessModels.FirstOrDefault(p=>p.FryMaterialNum=="清洗")!=null)
  131. {
  132. if (flowProcessModels.Where(p => p.FryMaterialNum == "清洗").Count() > 1||flowProcessModels.IndexOf(flowProcessModels.FirstOrDefault(p => p.FryMaterialNum == "清洗"))<flowProcessModels.Count-1)
  133. {
  134. MessageNotify.GetInstance.ShowUserLog("保存失败,清洗工艺重复或非法配置");
  135. MessageBox.Show("保存失败,清洗工艺重复或非法配置", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
  136. return;
  137. }
  138. }
  139. // name.FlowProcess.fpModels = flowProcessModels;
  140. name.FlowProcess.fpModels.Clear();
  141. foreach (var item in flowProcessModels)
  142. {
  143. name.FlowProcess.fpModels.Add(new FlowProcessModel { FryMaterialNum = item.FryMaterialNum, FrySpeed = item.FrySpeed, FryWeight = item.FryWeight,TargeWeight=item.TargeWeight, FryTemperature = item.FryTemperature, FryPeriodTime = item.FryPeriodTime, SmallFirePercent = item.SmallFirePercent, MidFirePercent = item.MidFirePercent, BigFirePercent = item.BigFirePercent, StrongFirePercent = item.StrongFirePercent });
  144. }
  145. //foreach (var item in name.materialCollection)
  146. //{
  147. // string s= Json<FlowProcessNames>.Data.Names.FirstOrDefault(p=>p == item.MaterialLoc.ToString());
  148. // Json<FlowProcessNames>.Data.Names.Remove(s);
  149. //}
  150. }
  151. Json<RecipeManage>.Save();
  152. Json<FlowProcessNames>.Save();
  153. ActionManage.GetInstance.Send("CloseFlowProcessView");
  154. });
  155. AddFrontFlowItemCommand = new RelayCommand(() =>
  156. {
  157. try
  158. {
  159. if (currentItemId == 0)
  160. {
  161. flowProcessModels.Insert(0, new FlowProcessModel());
  162. }
  163. else
  164. {
  165. flowProcessModels.Insert(currentItemId, new FlowProcessModel());
  166. currentItemId = currentItemId + 1;
  167. }
  168. }
  169. catch (Exception)
  170. {
  171. //throw;
  172. }
  173. });
  174. AddLastFlowItemCommand = new RelayCommand(() =>
  175. {
  176. try
  177. {
  178. if (flowProcessModels.Count <= 0)
  179. {
  180. flowProcessModels.Insert(0, new FlowProcessModel());
  181. }
  182. else if (currentItemId != 0)
  183. {
  184. flowProcessModels.Insert(currentItemId + 1, new FlowProcessModel());
  185. }
  186. else
  187. {
  188. flowProcessModels.Add(new FlowProcessModel());
  189. }
  190. }
  191. catch (Exception)
  192. {
  193. // throw;
  194. }
  195. });
  196. DeleteFlowItemCommand = new RelayCommand(() =>
  197. {
  198. if (flowProcessModels.Count > 0)
  199. flowProcessModels.RemoveAt(currentItemId);
  200. currentItemId = 0;
  201. });
  202. }
  203. }
  204. }