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

99 行
3.8 KiB

  1. using BPASmartClient.Helper;
  2. using FryPot_DosingSystem.Model;
  3. using Microsoft.Toolkit.Mvvm.ComponentModel;
  4. using Microsoft.Toolkit.Mvvm.Input;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Collections.ObjectModel;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace FryPot_DosingSystem.ViewModel
  12. {
  13. internal class NewRecipeViewModel : ObservableObject
  14. {
  15. /// <summary>
  16. /// 配方唯一编码,用于编辑配方
  17. /// </summary>
  18. public string recipeId { get; set; }
  19. /// <summary>
  20. /// 配料名称
  21. /// </summary>
  22. private string _recipeName;
  23. public string RecipeName { get { return _recipeName; } set { _recipeName = value; OnPropertyChanged(); } }
  24. public ObservableCollection<MaterialType> materials { get; set; } = new ObservableCollection<MaterialType>();
  25. public ObservableCollection<string> materialNames { get; set; } = new ObservableCollection<string>() { "肉","葱","蒜"};
  26. public RelayCommand AddRecipe { get; set; }
  27. public RelayCommand<string> RemoveRecipe { get; set; }
  28. public RelayCommand Comfirm { get; set; }
  29. public NewRecipeViewModel()
  30. {
  31. ActionManage.GetInstance.Register(new Action<object>(Id => {
  32. if (Id != null && Id is string strId)
  33. {
  34. var res = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.RecipeId == strId);
  35. if (res != null && res is NewRecipeModel rom)
  36. {
  37. RecipeName = rom.RecipeName;
  38. foreach (var item in rom.materialCollection)
  39. {
  40. materials.Add(item);
  41. }
  42. recipeId = strId;
  43. }
  44. }
  45. }),"EditRecipe");
  46. AddRecipe = new RelayCommand(() =>
  47. {
  48. pr:
  49. string materialCode = Guid.NewGuid().ToString();//原料唯一ID ,后期需要根据实际要求更改
  50. var res = materials.FirstOrDefault(p => p.MaterialCode == materialCode);
  51. if (res == null)
  52. {
  53. materials.Add(new MaterialType() { MaterialCode = materialCode });
  54. }
  55. else
  56. {
  57. goto pr;
  58. }
  59. });
  60. RemoveRecipe = new RelayCommand<string>(code =>
  61. {
  62. var res = materials.FirstOrDefault(m => m.MaterialCode == code);
  63. if (res != null)
  64. materials.Remove(res);
  65. });
  66. Comfirm = new RelayCommand(() =>
  67. {
  68. var bom = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.RecipeId == recipeId);
  69. if (bom == null)//新配方
  70. {
  71. prop: string recipeID = Guid.NewGuid().ToString();//配方唯一ID,后期根据实际要求更改
  72. var res = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.RecipeId == recipeID);
  73. if (res == null)
  74. {
  75. Json<RecipeManage>.Data.Recipes.Add(new NewRecipeModel { RecipeId = recipeID, RecipeName = RecipeName, materialCollection = materials });//配方添加
  76. }
  77. else
  78. {
  79. goto prop;
  80. }
  81. ActionManage.GetInstance.Send("CloseNewRecipeView");
  82. }
  83. else //已有配方,用于编辑
  84. {
  85. bom.materialCollection= materials;
  86. bom.RecipeName = RecipeName;
  87. ActionManage.GetInstance.Send("CloseNewRecipeView");
  88. }
  89. });
  90. }
  91. }
  92. }