终端一体化运控平台
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

115 rader
5.1 KiB

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