终端一体化运控平台
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

FlowProcessSetViewModel.cs 8.5 KiB

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年前
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年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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.Input;
  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
  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. public string currentRecipeName { get; set; }
  22. public static int currentItemId { get; set; }
  23. public RelayCommand CloseWindowCommand { get; set; }
  24. public ObservableCollection<string> FlowItems { get; set; } = new ObservableCollection<string>();
  25. public RelayCommand ConfirmCommand { get; set; }
  26. public RelayCommand AddLastFlowItemCommand { get; set; }
  27. public RelayCommand AddFrontFlowItemCommand { get; set; }
  28. public RelayCommand DeleteFlowItemCommand { get; set; }
  29. public FlowProcessSetViewModel()
  30. {
  31. Json<FlowProcessNames>.Read();
  32. // FlowProcessNames.GetInstance.Names = Json<FlowProcessNames>.Data.Names;
  33. // FlowItems = Json<FlowProcessNames>.Data.NameId;
  34. foreach (KeyValuePair<string, int> item in Json<FlowProcessNames>.Data.NameId)
  35. {
  36. FlowItems.Add(item.Key);
  37. }
  38. ActionManage.GetInstance.Register(new Action<object>((obj) =>
  39. {
  40. if (obj != null)
  41. try
  42. {
  43. currentItemId = Convert.ToInt32(obj);
  44. }
  45. catch (Exception)
  46. {
  47. }
  48. }), "CurrentItemId");
  49. //ActionManage.GetInstance.Register(new Action<object>(obj =>
  50. //{
  51. // if (obj != null)
  52. // materialNum = Convert.ToInt32(obj);
  53. //}), "MaterialNum");
  54. ActionManage.GetInstance.Register(new Action<object>(recipeName =>
  55. {
  56. if (recipeName != null)
  57. {
  58. currentRecipeName = recipeName.ToString();
  59. var res = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.FlowProcess?.RecipeName == recipeName?.ToString());
  60. if (res != null && res is NewRecipeModel recipe) //编辑已有工艺
  61. {
  62. foreach (var item in recipe.materialCollection)
  63. {
  64. if (!FlowItems.Contains(item.MaterialLoc.ToString()))
  65. FlowItems.Add(item.MaterialLoc.ToString());//下拉框
  66. }
  67. foreach (var item in recipe.FlowProcess.fpModels)
  68. {
  69. flowProcessModels.Add(new FlowProcessModel { FryMaterialNum = item.FryMaterialNum, FrySpeed = item.FrySpeed, FryWeight = item.FryWeight, FryTemperature = item.FryTemperature, FryPeriodTime = item.FryPeriodTime, SmallFirePercent = item.SmallFirePercent, MidFirePercent = item.MidFirePercent, BigFirePercent = item.BigFirePercent, StrongFirePercent = item.StrongFirePercent });
  70. }
  71. // ActionManage.GetInstance.Send("MaterialNum", recipe.materialCollection.Count);
  72. }
  73. else//创建新工艺
  74. {
  75. var name = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.RecipeName == recipeName.ToString());
  76. if (name != null)
  77. {
  78. name.FlowProcess.RecipeName = recipeName.ToString();
  79. foreach (var item in name.materialCollection)
  80. {
  81. if (!FlowItems.Contains(item.MaterialLoc.ToString()))
  82. FlowItems.Add(item.MaterialLoc.ToString());//下拉框
  83. }
  84. ActionManage.GetInstance.Send("MaterialNum", name.materialCollection.Count);
  85. name.FlowProcess.fpModels = flowProcessModels;
  86. }
  87. }
  88. }
  89. }), "EditFlowProcess");
  90. CloseWindowCommand = new RelayCommand(() =>
  91. {
  92. ActionManage.GetInstance.Send("CloseFlowProcessView");
  93. });
  94. ConfirmCommand = new RelayCommand(() =>
  95. {
  96. var name = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.RecipeName == currentRecipeName.ToString());
  97. if (name != null)
  98. {
  99. name.FlowProcess.RecipeName = currentRecipeName.ToString();
  100. //工艺桶号重复性检测
  101. foreach (var item in name.materialCollection)
  102. {
  103. var res = flowProcessModels.Where(p => p.FryMaterialNum == item.MaterialLoc.ToString());
  104. if (res.Count() > 1)
  105. {
  106. // NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "提示", $"保存失败,桶号重复!");
  107. MessageNotify.GetInstance.ShowUserLog("保存失败,桶号重复");
  108. MessageBox.Show("保存失败,桶号重复", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
  109. return;
  110. }
  111. }
  112. // name.FlowProcess.fpModels = flowProcessModels;
  113. name.FlowProcess.fpModels.Clear();
  114. foreach (var item in flowProcessModels)
  115. {
  116. name.FlowProcess.fpModels.Add(new FlowProcessModel { FryMaterialNum = item.FryMaterialNum, FrySpeed = item.FrySpeed, FryWeight = item.FryWeight, FryTemperature = item.FryTemperature, FryPeriodTime = item.FryPeriodTime, SmallFirePercent = item.SmallFirePercent, MidFirePercent = item.MidFirePercent, BigFirePercent = item.BigFirePercent, StrongFirePercent = item.StrongFirePercent });
  117. }
  118. //foreach (var item in name.materialCollection)
  119. //{
  120. // string s= Json<FlowProcessNames>.Data.Names.FirstOrDefault(p=>p == item.MaterialLoc.ToString());
  121. // Json<FlowProcessNames>.Data.Names.Remove(s);
  122. //}
  123. }
  124. Json<RecipeManage>.Save();
  125. Json<FlowProcessNames>.Save();
  126. ActionManage.GetInstance.Send("CloseFlowProcessView");
  127. });
  128. AddFrontFlowItemCommand = new RelayCommand(() =>
  129. {
  130. try
  131. {
  132. if (currentItemId == 0)
  133. {
  134. flowProcessModels.Insert(0, new FlowProcessModel());
  135. }
  136. else
  137. {
  138. flowProcessModels.Insert(currentItemId, new FlowProcessModel());
  139. currentItemId = currentItemId + 1;
  140. }
  141. }
  142. catch (Exception)
  143. {
  144. //throw;
  145. }
  146. });
  147. AddLastFlowItemCommand = new RelayCommand(() =>
  148. {
  149. try
  150. {
  151. if (flowProcessModels.Count <= 0)
  152. {
  153. flowProcessModels.Insert(0, new FlowProcessModel());
  154. }
  155. else if (currentItemId != 0)
  156. {
  157. flowProcessModels.Insert(currentItemId + 1, new FlowProcessModel());
  158. }
  159. else
  160. {
  161. flowProcessModels.Add(new FlowProcessModel());
  162. }
  163. }
  164. catch (Exception)
  165. {
  166. // throw;
  167. }
  168. });
  169. DeleteFlowItemCommand = new RelayCommand(() =>
  170. {
  171. if (flowProcessModels.Count > 0)
  172. flowProcessModels.RemoveAt(currentItemId);
  173. currentItemId = 0;
  174. });
  175. }
  176. }
  177. }