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

145 lines
5.8 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.Toolkit.Mvvm.ComponentModel;
  7. using System.Collections.ObjectModel;
  8. using Microsoft.Toolkit.Mvvm.Input;
  9. using BPASmartClient.Helper;
  10. using BPASmartClient.JXJFoodBigStation.Model;
  11. using BPASmartClient.CustomResource.Pages.Model;
  12. using BPASmartClient.JXJFoodBigStation.Model.Siemens;
  13. using System.Windows.Forms;
  14. namespace BPASmartClient.JXJFoodBigStation.ViewModel
  15. {
  16. public class RecipeInfosViewModel : ObservableObject
  17. {
  18. public RecipeInfosViewModel()
  19. {
  20. ActionManage.GetInstance.Register(new Action<object>((o) =>
  21. {
  22. if (o != null && o is RecipeModel rm)
  23. {
  24. RecipeName = rm.RecipeName;
  25. RecipeCode = rm.RecipeCode;
  26. TrayCode = rm.TrayCode;
  27. //RawMaterialsInfo = rm.RawMaterial;
  28. //var rest = RawMaterialsInfo.GetHashCode();
  29. foreach (var item in rm.RawMaterial)
  30. {
  31. RawMaterialsInfo.Add(item);
  32. }
  33. }
  34. }), "RecipeInfo");
  35. AddRecipe = new RelayCommand(() => {
  36. RawMaterialsInfo.Add(new RawMaterialModel());
  37. });
  38. Comfirm = new RelayCommand(() =>
  39. {
  40. var bom= Json<LocaPar>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == RecipeCode);
  41. if (bom == null)//新配方
  42. {
  43. var name= Json<LocaPar>.Data.Recipes.FirstOrDefault(p => p.RecipeName == RecipeName);
  44. if (name == null)
  45. {
  46. go:
  47. long recipeCode = new Random().Next(10000, 99999);
  48. var res = Json<LocaPar>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == recipeCode);
  49. if (res == null)
  50. {
  51. Json<LocaPar>.Data.Recipes.Add(new RecipeModel { RecipeCode = recipeCode, RawMaterial= RawMaterialsInfo,RecipeName=RecipeName,TrayCode=TrayCode});
  52. Json<LocaPar>.Save();
  53. }
  54. else
  55. {
  56. goto go;
  57. }
  58. ActionManage.GetInstance.Send("CloseRecipeInfosView");
  59. }
  60. else
  61. {
  62. MessageBox.Show("配方名称重复,请重命名!!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  63. }
  64. }
  65. else//编辑已有配方
  66. {
  67. bom.RawMaterial.Clear();
  68. foreach (var item in RawMaterialsInfo)
  69. {
  70. bom.RawMaterial.Add(item);
  71. }
  72. bom.RecipeName = RecipeName;
  73. Json<LocaPar>.Save();
  74. ActionManage.GetInstance.Send("CloseRecipeInfosView");
  75. }
  76. });
  77. SaveAs = new RelayCommand(() => {
  78. var bom = Json<LocaPar>.Data.Recipes.FirstOrDefault(p => p.RecipeName == RecipeName);
  79. var rec = Json<LocaPar>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == RecipeCode);
  80. if (bom == null && rec != null)//配方名称更改
  81. {
  82. prop: long recipeCode = new Random().Next(10000, 99999);//配方唯一ID,后期根据实际要求更改
  83. var res = Json<LocaPar>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == recipeCode);
  84. if (res == null)
  85. {
  86. Json<LocaPar>.Data.Recipes.Add(new RecipeModel { RecipeCode = recipeCode, RawMaterial = RawMaterialsInfo, RecipeName = RecipeName, TrayCode = TrayCode });//配方添加
  87. Json<LocaPar>.Save();
  88. }
  89. else
  90. {
  91. goto prop;
  92. }
  93. ActionManage.GetInstance.Send("CloseRecipeInfosView");
  94. }
  95. else
  96. {
  97. MessageBox.Show("另存配方失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  98. }
  99. ActionManage.GetInstance.Send("CloseNewRecipeView");
  100. });
  101. RemoveRecipe = new RelayCommand<int>((materilaName) => {
  102. var res= RawMaterialsInfo.FirstOrDefault(p=>p.RawMaterialLocation==materilaName);
  103. if (res != null)
  104. RawMaterialsInfo.Remove(res);
  105. });
  106. //ReturnPage = new RelayCommand(() =>
  107. //{
  108. // ActionManage.GetInstance.Send("CloseRecipeInfosView");
  109. //});
  110. }
  111. public string RecipeName { get { return _mRecipeName; } set { _mRecipeName = value; OnPropertyChanged(); } }
  112. private string _mRecipeName;
  113. public long RecipeCode { get { return _mRecipeCode; } set { _mRecipeCode = value; OnPropertyChanged(); } }
  114. private long _mRecipeCode;
  115. public int TrayCode { get { return _mTrayCode; } set { _mTrayCode = value; OnPropertyChanged(); } }
  116. private int _mTrayCode;
  117. public RelayCommand ReturnPage { get; set; }
  118. public RelayCommand AddRecipe { get; set; }
  119. public RelayCommand Comfirm { get; set; }
  120. public RelayCommand SaveAs { get; set; }
  121. public RelayCommand<int> RemoveRecipe { get; set; }
  122. public ObservableCollection<RawMaterialModel> RawMaterialsInfo { get; set; } = new ObservableCollection<RawMaterialModel>() ;
  123. }
  124. }