终端一体化运控平台
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

138 lignes
5.7 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 RecipeData 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 RawMaterial());
  37. });
  38. Comfirm = new RelayCommand(() =>
  39. {
  40. var bom= Json<LocalRecipe>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == RecipeCode);
  41. if (bom == null)//新配方
  42. {
  43. var name= Json<LocalRecipe>.Data.Recipes.FirstOrDefault(p => p.RecipeName == RecipeName);
  44. if (name == null)
  45. {
  46. go:
  47. string recipeCode = new Random().Next(10000, 32767).ToString();
  48. var res = Json<LocalRecipe>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == recipeCode);
  49. if (res == null)
  50. {
  51. Json<LocalRecipe>.Data.Recipes.Add(new RecipeData { RecipeCode = recipeCode, RawMaterial= RawMaterialsInfo,RecipeName=RecipeName,TrayCode=TrayCode});
  52. Json<LocalRecipe>.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. bom.TrayCode = TrayCode;
  74. Json<LocalRecipe>.Save();
  75. ActionManage.GetInstance.Send("CloseRecipeInfosView");
  76. }
  77. });
  78. SaveAs = new RelayCommand(() => {
  79. var bom = Json<LocalRecipe>.Data.Recipes.FirstOrDefault(p => p.RecipeName == RecipeName);
  80. var rec = Json<LocalRecipe>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == RecipeCode);
  81. if (bom == null && rec != null)//配方名称更改
  82. {
  83. prop: string recipeCode = new Random().Next(10000, 99999).ToString();//配方唯一ID,后期根据实际要求更改
  84. var res = Json<LocalRecipe>.Data.Recipes.FirstOrDefault(p => p.RecipeCode == recipeCode);
  85. if (res == null)
  86. {
  87. Json<LocalRecipe>.Data.Recipes.Add(new RecipeData { RecipeCode = recipeCode, RawMaterial = RawMaterialsInfo, RecipeName = RecipeName, TrayCode = TrayCode });//配方添加
  88. Json<LocalRecipe>.Save();
  89. }
  90. else
  91. {
  92. goto prop;
  93. }
  94. ActionManage.GetInstance.Send("CloseRecipeInfosView");
  95. }
  96. else
  97. {
  98. MessageBox.Show("另存配方失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  99. }
  100. ActionManage.GetInstance.Send("CloseNewRecipeView");
  101. });
  102. RemoveRecipe = new RelayCommand<string>((materilaName) => {
  103. var res = RawMaterialsInfo.FirstOrDefault(p => p.RawMaterialName == materilaName);
  104. if (res != null)
  105. RawMaterialsInfo.Remove(res);
  106. });
  107. }
  108. public string RecipeName { get { return _mRecipeName; } set { _mRecipeName = value; OnPropertyChanged(); } }
  109. private string _mRecipeName;
  110. public string RecipeCode { get { return _mRecipeCode; } set { _mRecipeCode = value; OnPropertyChanged(); } }
  111. private string _mRecipeCode;
  112. public int TrayCode { get { return _mTrayCode; } set { _mTrayCode = value; OnPropertyChanged(); } }
  113. private int _mTrayCode;
  114. public RelayCommand ReturnPage { get; set; }
  115. public RelayCommand AddRecipe { get; set; }
  116. public RelayCommand Comfirm { get; set; }
  117. public RelayCommand SaveAs { get; set; }
  118. public RelayCommand<string> RemoveRecipe { get; set; }
  119. public ObservableCollection<RawMaterial> RawMaterialsInfo { get; set; } = new ObservableCollection<RawMaterial>() ;
  120. }
  121. }