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

90 line
3.9 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using BPA.Helper;
  7. using System.Collections.ObjectModel;
  8. using BPA.Helper;
  9. namespace BPASmartClient.SmallBatchingSystem.ViewModels
  10. {
  11. public class NewRecipeViewModel : BaseModel
  12. {
  13. public NewRecipeViewModel()
  14. {
  15. Json<ConfigInfoModel>.Data.SiloInfoModels.ToList()?.ForEach(item => { SileName.Add(item.SiloName); });
  16. ActionManage.GetInstance.Register(new Action<object>((o) =>
  17. {
  18. if (o != null && o is RecipeInfo tempRecipeInfo)
  19. {
  20. RecipeName = tempRecipeInfo.RecipeName;
  21. tempRecipeInfo.SiloInfoModels.ToList()?.ForEach(item =>
  22. {
  23. int tempIndex = Array.FindIndex(SileName.ToArray(), p => p == item.SiloName);
  24. SiloInfos.Add(new RecipeRawMaterialInfo() { SiloName = item.SiloName, SiloWeight = item.SiloWeight, SelectIndex = tempIndex });
  25. });
  26. Index = Array.FindIndex(Json<ConfigInfoModel>.Data.Recipes.ToArray(), p => p.RecipeName == tempRecipeInfo.RecipeName);
  27. }
  28. }), "OpenNewRecipe", true);
  29. AddCommand = new BPARelayCommand(() => { SiloInfos.Add(new RecipeRawMaterialInfo()); });
  30. CancelCommand = new BPARelayCommand(() => { ActionManage.GetInstance.Send("NewRecipeViewModelClose"); });
  31. SaveCommand = new BPARelayCommand(() =>
  32. {
  33. if (Index >= 0 && Index < Json<ConfigInfoModel>.Data.OutletInfoModels.Count)
  34. {
  35. var res = Array.FindIndex(Json<ConfigInfoModel>.Data.Recipes.ToArray(), p => p.RecipeName == RecipeName);
  36. if (res >= 0 && res != Index)
  37. {
  38. ErrorInfo = "配方名称已经存在!";
  39. return;
  40. }
  41. Json<ConfigInfoModel>.Data.Recipes.ElementAt(Index).RecipeName = RecipeName;
  42. Json<ConfigInfoModel>.Data.Recipes.ElementAt(Index).SiloInfoModels.Clear();
  43. SiloInfos.ToList()?.ForEach(item =>
  44. {
  45. Json<ConfigInfoModel>.Data.Recipes.ElementAt(Index).SiloInfoModels.Add(item);
  46. });
  47. Control.GetInstance.OperationLog($"{RecipeName} 编辑完成");
  48. }
  49. else
  50. {
  51. var res = Json<ConfigInfoModel>.Data.Recipes.FirstOrDefault(p => p.RecipeName == RecipeName);
  52. if (res != null)
  53. {
  54. ErrorInfo = "配方名称已经存在!";
  55. return;
  56. }
  57. Json<ConfigInfoModel>.Data.Recipes.Add(new RecipeInfo()
  58. {
  59. RecipeName = RecipeName,
  60. SiloInfoModels = SiloInfos
  61. });
  62. Control.GetInstance.OperationLog($"{RecipeName} 添加成功");
  63. }
  64. ActionManage.GetInstance.Send("NewRecipeViewModelClose");
  65. });
  66. RemoveCommand = new BPARelayCommand<object>((o) =>
  67. {
  68. if (!string.IsNullOrEmpty(o?.ToString()))
  69. {
  70. var res = SiloInfos.FirstOrDefault(p => p.SiloName == o.ToString());
  71. if (res != null) SiloInfos.Remove(res);
  72. }
  73. });
  74. }
  75. public string RecipeName { get { return _mRecipeName; } set { _mRecipeName = value; OnPropertyChanged(); } }
  76. private string _mRecipeName;
  77. public ObservableCollection<RecipeRawMaterialInfo> SiloInfos { get; set; } = new ObservableCollection<RecipeRawMaterialInfo>();
  78. public ObservableCollection<string> SileName { get; set; } = new ObservableCollection<string>();
  79. }
  80. }