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

223 行
9.7 KiB

  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 FryPot_DosingSystem.View;
  7. using BPA.Helper;
  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. using System.Windows.Media.Media3D;
  16. namespace FryPot_DosingSystem.ViewModel
  17. {
  18. internal class RecipeSetViewModel : NotifyBase
  19. {
  20. ///// <summary>
  21. ///// 配方编号
  22. ///// </summary>
  23. //private int _serialNumber;
  24. //public int SerialNumber { get { return _serialNumber; } set { _serialNumber = value;OnPropertyChanged(); } }
  25. ///// <summary>
  26. ///// 配方名称
  27. ///// </summary>
  28. //private string _recipeName;
  29. //public string RecipeName { get { return _recipeName; } set { _recipeName = value; OnPropertyChanged(); } }
  30. /// <summary>
  31. /// 复制配方的Id
  32. /// </summary>
  33. public static string CopyRecipeId { get; set; }
  34. public ObservableCollection<NewRecipeModel> recipeModels { get; set; } = new ObservableCollection<NewRecipeModel>();
  35. public BPARelayCommand NewRecipe { get; set; }
  36. public BPARelayCommand SaveRecipe { get; set; }
  37. /// <summary>
  38. /// 工艺操作
  39. /// </summary>
  40. public BPARelayCommand<string> OperateFlowProcess { get; set; }
  41. /// <summary>
  42. /// 编辑配方
  43. /// </summary>
  44. public BPARelayCommand<object> EditRecipeCommand { get; set; }
  45. /// <summary>
  46. /// 复制配方
  47. /// </summary>
  48. public BPARelayCommand<object> CopyRecipeCommand { get; set; }
  49. /// <summary>
  50. /// 删除配方
  51. /// </summary>
  52. public BPARelayCommand<object> DeleteRecipeCommand { get; set; }
  53. public RecipeSetViewModel()
  54. {
  55. // Json<RecipeManage>.Read();
  56. recipeModels =Json<RecipeManage>.Data.Recipes;
  57. int count = recipeModels.Count;
  58. bool sign = false;
  59. ActionManage.GetInstance.CancelRegister("RecipeIsChange");
  60. ActionManage.GetInstance.RegisterAsync(new Action(() =>
  61. {
  62. if (!sign)
  63. {
  64. bool b = Json<RecipeManage>.Data.Recipes.Count == count ? true : false;
  65. if (!b)
  66. {
  67. MessageBoxResult result = MessageBox.Show("配方数据未保存,是否保存", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Information);
  68. if (result == MessageBoxResult.OK)
  69. {
  70. Json<RecipeManage>.Save();//保存配方
  71. count = recipeModels.Count;
  72. }
  73. else
  74. {
  75. sign = true;
  76. Json<RecipeManage>.Data.Recipes.RemoveAt(Json<RecipeManage>.Data.Recipes.Count - 1);
  77. }
  78. }
  79. }
  80. }), "RecipeIsChange");
  81. //复制指定炒锅配方
  82. ActionManage.GetInstance.Register<object>(new Action<object>((Num) => {
  83. if (Num != null&& CopyRecipeId!=null)
  84. {
  85. var res= Json<RecipeManage>.Data.Recipes.FirstOrDefault(p=>p.RecipeId==CopyRecipeId);
  86. if (res != null)
  87. {
  88. prop: string recipeID = Guid.NewGuid().ToString();//配方唯一ID,后期根据实际要求更改
  89. var res1 = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.RecipeId == recipeID);
  90. if (res1 == null)
  91. {
  92. string recipeNamec = string.Empty;
  93. if (res.RecipeName.Contains('('))
  94. {
  95. recipeNamec = res.RecipeName.Split('(')[0] + $"({Num}号锅)";
  96. }
  97. else
  98. {
  99. recipeNamec= res.RecipeName+$"({Num}号锅)";
  100. }
  101. //复制料筒配方
  102. ObservableCollection<MaterialType> collect = new ObservableCollection<MaterialType>();
  103. //浅拷贝
  104. foreach (var item in res.materialCollection)
  105. {
  106. var clone=(MaterialType)item.Clone();
  107. collect.Add(clone);
  108. }
  109. foreach (var item in collect)
  110. {
  111. if (ushort.TryParse((Num.ToString() + item.MaterialLoc.ToString().Substring(1, 2)), out ushort loc))
  112. {
  113. item.MaterialLoc = loc;
  114. }
  115. else
  116. {
  117. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"复制配方失败");
  118. return;
  119. }
  120. }
  121. //复制炒锅工艺配方
  122. FlowProcessManage FryFlow = new FlowProcessManage();
  123. FryFlow.StirTime=res.FlowProcess.StirTime;
  124. FryFlow.RecipeName = recipeNamec;
  125. FryFlow.targetWeightOffset = res.FlowProcess.targetWeightOffset;
  126. ObservableCollection<FlowProcessModel> flowCollect = new ObservableCollection<FlowProcessModel>();
  127. //浅拷贝
  128. foreach (var item in res.FlowProcess.fpModels)
  129. {
  130. var clone = (FlowProcessModel)item.Clone();
  131. flowCollect.Add(clone);
  132. }
  133. foreach (var item in flowCollect)
  134. {
  135. if (ushort.TryParse(item.FryMaterialNum, out ushort rollerNum))
  136. {
  137. item.FryMaterialNum = Num.ToString() + item.FryMaterialNum.ToString().Substring(1, 2);
  138. }
  139. }
  140. FryFlow.fpModels = flowCollect;
  141. Json<RecipeManage>.Data.Recipes.Add(new NewRecipeModel { RecipeId = recipeID, DataTime = DateTime.Now.ToShortDateString(), RecipeName = recipeNamec, materialCollection = collect, FlowProcess = FryFlow });//配方添加
  142. //Json<RecipeManage>.Save();
  143. }
  144. else
  145. {
  146. goto prop;
  147. }
  148. MessageNotify.GetInstance.ShowUserLog("复制配方成功");
  149. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"复制配方成功");
  150. }
  151. }
  152. }), "CopyPotNum");
  153. NewRecipe =new BPARelayCommand( new Action(() =>
  154. {
  155. NewRecipeView nrv = new NewRecipeView();
  156. nrv.ShowDialog();
  157. //MessageLog.GetInstance.ShowUserLog("新建配方");
  158. }));
  159. SaveRecipe =new BPARelayCommand( new Action(() =>
  160. {
  161. Json<RecipeManage>.Save();
  162. count = recipeModels.Count;
  163. NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, App.MainWindow, "提示", $"配方保存成功!");
  164. }));
  165. EditRecipeCommand = new BPARelayCommand<object>((Id) =>
  166. {
  167. if (Id != null)
  168. {
  169. ActionManage.GetInstance.CancelRegister("EditRecipe");
  170. NewRecipeView nrv = new NewRecipeView();
  171. ActionManage.GetInstance.Send("EditRecipe", Id);
  172. nrv.ShowDialog();
  173. }
  174. });
  175. DeleteRecipeCommand = new BPARelayCommand<object>((Id) =>
  176. {
  177. if (Id != null && Id is String strId)
  178. {
  179. var res = recipeModels.FirstOrDefault(p => p.RecipeId == strId);
  180. if (res != null && res is NewRecipeModel nes)
  181. {
  182. recipeModels.Remove(nes);//删除配方
  183. Json<RecipeManage>.Save();//保存配方
  184. count = recipeModels.Count;
  185. MessageNotify.GetInstance.ShowUserLog($"成功删除配方【{nes.RecipeName}】");
  186. }
  187. }
  188. });
  189. //工艺流程操作
  190. OperateFlowProcess = new BPARelayCommand<string>((recipeName) =>
  191. {
  192. if (recipeName != null && recipeName != string.Empty && recipeName != "")
  193. {
  194. ActionManage.GetInstance.CancelRegister("EditFlowProcess");
  195. FlowProcessView fps = new FlowProcessView();
  196. ActionManage.GetInstance.Send("EditFlowProcess", recipeName);
  197. fps.ShowDialog();
  198. }
  199. });
  200. //复制配方
  201. CopyRecipeCommand = new BPARelayCommand<object>((Id) => {
  202. CopyInfoView copyInfoView = new CopyInfoView();
  203. CopyRecipeId = Id.ToString() ;
  204. copyInfoView.Show();
  205. });
  206. }
  207. }
  208. }