终端一体化运控平台
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

FlowProcessSetViewModel.cs 11 KiB

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