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

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