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

FlowProcessSetViewModel.cs 11 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. private string _stirTime="0";
  28. /// <summary>
  29. /// 秘制配方搅拌时间
  30. /// </summary>
  31. public string StirTime
  32. {
  33. get { return _stirTime; }
  34. set { _stirTime = value; OnPropertyChanged(); }
  35. }
  36. public string currentRecipeName { get; set; }
  37. public static int currentItemId { get; set; }
  38. public RelayCommand CloseWindowCommand { get; set; }
  39. public ObservableCollection<string> FlowItems { get; set; } = new ObservableCollection<string>();
  40. public RelayCommand ConfirmCommand { get; set; }
  41. public RelayCommand AddLastFlowItemCommand { get; set; }
  42. public RelayCommand AddFrontFlowItemCommand { get; set; }
  43. public RelayCommand DeleteFlowItemCommand { get; set; }
  44. public FlowProcessSetViewModel()
  45. {
  46. Json<FlowProcessNames>.Read();
  47. // FlowProcessNames.GetInstance.Names = Json<FlowProcessNames>.Data.Names;
  48. // FlowItems = Json<FlowProcessNames>.Data.NameId;
  49. foreach (KeyValuePair<string, int> item in Json<FlowProcessNames>.Data.NameId)
  50. {
  51. FlowItems.Add(item.Key);
  52. }
  53. ActionManage.GetInstance.Register(new Action<object>((obj) =>
  54. {
  55. if (obj != null)
  56. try
  57. {
  58. currentItemId = Convert.ToInt32(obj);
  59. }
  60. catch (Exception)
  61. {
  62. }
  63. }), "CurrentItemId");
  64. //ActionManage.GetInstance.Register(new Action<object>(obj =>
  65. //{
  66. // if (obj != null)
  67. // materialNum = Convert.ToInt32(obj);
  68. //}), "MaterialNum");
  69. ActionManage.GetInstance.Register(new Action<object>(recipeName =>
  70. {
  71. if (recipeName != null)
  72. {
  73. currentRecipeName = recipeName.ToString();
  74. var res = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.FlowProcess?.RecipeName == recipeName?.ToString());
  75. if (res != null && res is NewRecipeModel recipe) //编辑已有工艺
  76. {
  77. targetWeightOffset = recipe.FlowProcess.targetWeightOffset.ToString();
  78. StirTime=recipe.FlowProcess.StirTime.ToString();
  79. foreach (var item in recipe.materialCollection)
  80. {
  81. if (!FlowItems.Contains(item.MaterialLoc.ToString()))
  82. FlowItems.Add(item.MaterialLoc.ToString());//下拉框
  83. }
  84. foreach (var item in recipe.FlowProcess.fpModels)
  85. {
  86. 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 });
  87. }
  88. // ActionManage.GetInstance.Send("MaterialNum", recipe.materialCollection.Count);
  89. }
  90. else//创建新工艺
  91. {
  92. var name = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.RecipeName == recipeName.ToString());
  93. if (name != null)
  94. {
  95. name.FlowProcess.RecipeName = recipeName.ToString();
  96. foreach (var item in name.materialCollection)
  97. {
  98. if (!FlowItems.Contains(item.MaterialLoc.ToString()))
  99. FlowItems.Add(item.MaterialLoc.ToString());//下拉框
  100. }
  101. ActionManage.GetInstance.Send("MaterialNum", name.materialCollection.Count);
  102. //name.FlowProcess.fpModels = flowProcessModels;
  103. }
  104. }
  105. }
  106. }), "EditFlowProcess");
  107. CloseWindowCommand = new RelayCommand(() =>
  108. {
  109. ActionManage.GetInstance.Send("CloseFlowProcessView");
  110. });
  111. ConfirmCommand = new RelayCommand(() =>
  112. {
  113. var name = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.RecipeName == currentRecipeName.ToString());
  114. if (name != null)
  115. {
  116. name.FlowProcess.RecipeName = currentRecipeName.ToString();
  117. if (float.TryParse(targetWeightOffset.Trim(), out float offset))
  118. {
  119. name.FlowProcess.targetWeightOffset = offset;//目标重量偏差
  120. }
  121. else
  122. {
  123. MessageBox.Show("非法目标重量偏差设置", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
  124. name.FlowProcess.targetWeightOffset = 0.0F;
  125. return;
  126. }
  127. if (ushort.TryParse(StirTime.Trim(), out ushort time))
  128. {
  129. name.FlowProcess.StirTime = time;//秘制配方搅拌时间
  130. }
  131. else
  132. {
  133. MessageBox.Show("非法秘制配方搅拌时间设置", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
  134. name.FlowProcess.StirTime = 0;
  135. return;
  136. }
  137. //工艺桶号重复性检测
  138. foreach (var item in name.materialCollection)
  139. {
  140. var res = flowProcessModels.Where(p => p.FryMaterialNum == item.MaterialLoc.ToString());
  141. if (res.Count() > 1)
  142. {
  143. // NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "提示", $"保存失败,桶号重复!");
  144. MessageNotify.GetInstance.ShowUserLog("保存失败,桶号重复");
  145. MessageBox.Show("保存失败,桶号重复", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
  146. return;
  147. }
  148. }
  149. //工艺步骤中清洗工艺重复性检测
  150. if (flowProcessModels.FirstOrDefault(p=>p.FryMaterialNum=="清洗")!=null)
  151. {
  152. if (flowProcessModels.Where(p => p.FryMaterialNum == "清洗").Count() > 1||flowProcessModels.IndexOf(flowProcessModels.FirstOrDefault(p => p.FryMaterialNum == "清洗"))<flowProcessModels.Count-1)
  153. {
  154. MessageNotify.GetInstance.ShowUserLog("保存失败,清洗工艺重复或非法配置");
  155. MessageBox.Show("保存失败,清洗工艺重复或非法配置", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
  156. return;
  157. }
  158. }
  159. // name.FlowProcess.fpModels = flowProcessModels;
  160. name.FlowProcess.fpModels.Clear();
  161. foreach (var item in flowProcessModels)
  162. {
  163. 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 });
  164. }
  165. //foreach (var item in name.materialCollection)
  166. //{
  167. // string s= Json<FlowProcessNames>.Data.Names.FirstOrDefault(p=>p == item.MaterialLoc.ToString());
  168. // Json<FlowProcessNames>.Data.Names.Remove(s);
  169. //}
  170. }
  171. Json<RecipeManage>.Save();
  172. Json<FlowProcessNames>.Save();
  173. ActionManage.GetInstance.Send("CloseFlowProcessView");
  174. });
  175. AddFrontFlowItemCommand = new RelayCommand(() =>
  176. {
  177. try
  178. {
  179. if (currentItemId == 0)
  180. {
  181. flowProcessModels.Insert(0, new FlowProcessModel());
  182. }
  183. else
  184. {
  185. flowProcessModels.Insert(currentItemId, new FlowProcessModel());
  186. currentItemId = currentItemId + 1;
  187. }
  188. }
  189. catch (Exception)
  190. {
  191. //throw;
  192. }
  193. });
  194. AddLastFlowItemCommand = new RelayCommand(() =>
  195. {
  196. try
  197. {
  198. if (flowProcessModels.Count <= 0)
  199. {
  200. flowProcessModels.Insert(0, new FlowProcessModel());
  201. }
  202. else if (currentItemId != 0)
  203. {
  204. flowProcessModels.Insert(currentItemId + 1, new FlowProcessModel());
  205. }
  206. else
  207. {
  208. flowProcessModels.Add(new FlowProcessModel());
  209. }
  210. }
  211. catch (Exception)
  212. {
  213. // throw;
  214. }
  215. });
  216. DeleteFlowItemCommand = new RelayCommand(() =>
  217. {
  218. if (flowProcessModels.Count > 0)
  219. flowProcessModels.RemoveAt(currentItemId);
  220. currentItemId = 0;
  221. });
  222. }
  223. }
  224. }