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

119 lines
5.4 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using BPA.Helper;
  8. using BPASmartClient.SmallBatchingSystem.Views;
  9. using BPA.Helper;
  10. namespace BPASmartClient.SmallBatchingSystem.ViewModels
  11. {
  12. public class NewOutletViewModel : BaseModel
  13. {
  14. public NewOutletViewModel()
  15. {
  16. Json<ConfigInfoModel>.Data.SiloInfoModels.ToList()?.ForEach(item => { SileName.Add($"{item.SiloName}"); });
  17. ActionManage.GetInstance.Register(new Action<object>((o) =>
  18. {
  19. if (o != null && o is OutletInfoModel tempOutletInfo)
  20. {
  21. OutletName = tempOutletInfo.OutletName;
  22. OutletLoc = tempOutletInfo.OutletLoc;
  23. tempOutletInfo.SiloInfos?.ToList()?.ForEach((item =>
  24. {
  25. int tempIndex = Array.FindIndex(SileName.ToArray(), p => p == item);
  26. SiloInfos.Add(new RawMaterialInfo() { RawMaterialName = item, SelectIndex = tempIndex });
  27. }));
  28. Index = Array.FindIndex(Json<ConfigInfoModel>.Data.OutletInfoModels.ToArray(), p => p.OutletName == tempOutletInfo.OutletName);
  29. }
  30. }), "OpenNewOutlet", true);
  31. AddCommand = new BPARelayCommand(() => { SiloInfos.Add(new RawMaterialInfo()); });
  32. CancelCommand = new BPARelayCommand(() => { ActionManage.GetInstance.Send("NewOutletViewClose"); });
  33. SaveCommand = new BPARelayCommand(() =>
  34. {
  35. ObservableCollection<string> SileNames = new ObservableCollection<string>();
  36. SiloInfos.ToList()?.ForEach(item => { SileNames.Add(item.RawMaterialName); });
  37. if (Index >= 0 && Index < Json<ConfigInfoModel>.Data.OutletInfoModels.Count)
  38. {
  39. var array = Json<ConfigInfoModel>.Data.OutletInfoModels.ToArray();
  40. var res = Array.FindIndex(array, p => p.OutletName == OutletName);
  41. if (res >= 0 && res != Index)
  42. {
  43. ErrorInfo = "出料口名称已经存在!";
  44. return;
  45. }
  46. var temp = Array.FindIndex(array, p => p.OutletLoc == OutletLoc);
  47. if (temp >= 0 && temp != Index)
  48. {
  49. ErrorInfo = "出料口位置已存在!";
  50. return;
  51. }
  52. Json<ConfigInfoModel>.Data.OutletInfoModels.ElementAt(Index).OutletName = OutletName;
  53. Json<ConfigInfoModel>.Data.OutletInfoModels.ElementAt(Index).OutletLoc = OutletLoc;
  54. Json<ConfigInfoModel>.Data.OutletInfoModels.ElementAt(Index).SiloInfos.Clear();
  55. Json<ConfigInfoModel>.Data.OutletInfoModels.ElementAt(Index).SiloInfos = SileNames;
  56. Control.GetInstance.OperationLog($"{OutletName} 编辑完成");
  57. }
  58. else
  59. {
  60. var res = Json<ConfigInfoModel>.Data.OutletInfoModels.FirstOrDefault(p => p.OutletName == OutletName);
  61. if (res != null)
  62. {
  63. ErrorInfo = "出料口名称已经存在!";
  64. return;
  65. }
  66. var temp = Json<ConfigInfoModel>.Data.OutletInfoModels.FirstOrDefault(p => p.OutletLoc == OutletLoc);
  67. if (temp != null)
  68. {
  69. ErrorInfo = "出料口位置已存在!";
  70. return;
  71. }
  72. Json<ConfigInfoModel>.Data.OutletInfoModels.Add(new OutletInfoModel()
  73. {
  74. OutletLoc = OutletLoc,
  75. OutletName = OutletName,
  76. SiloInfos = SileNames
  77. });
  78. Control.GetInstance.OperationLog($"{OutletName} 添加成功");
  79. }
  80. ActionManage.GetInstance.Send("NewOutletViewClose");
  81. });
  82. RemoveCommand = new BPARelayCommand<object>((o) =>
  83. {
  84. if (!string.IsNullOrEmpty(o?.ToString()))
  85. {
  86. var res = SiloInfos.FirstOrDefault(p => p.RawMaterialName == o.ToString());
  87. if (res != null) SiloInfos.Remove(res);
  88. }
  89. });
  90. }
  91. public string OutletName { get { return _mOutletName; } set { _mOutletName = value; OnPropertyChanged(); } }
  92. private string _mOutletName;
  93. public int OutletLoc { get { return _mOutletLoc; } set { _mOutletLoc = value; OnPropertyChanged(); } }
  94. private int _mOutletLoc;
  95. public ObservableCollection<RawMaterialInfo> SiloInfos { get; set; } = new ObservableCollection<RawMaterialInfo>();
  96. public ObservableCollection<string> SileName { get; set; } = new ObservableCollection<string>();
  97. }
  98. public class RawMaterialInfo : NotifyBase
  99. {
  100. public string RawMaterialName { get { return _mRawMaterialName; } set { _mRawMaterialName = value; OnPropertyChanged(); } }
  101. private string _mRawMaterialName;
  102. public int SelectIndex { get { return _mSelectIndex; } set { _mSelectIndex = value; OnPropertyChanged(); } }
  103. private int _mSelectIndex;
  104. }
  105. }