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

NewOutletViewModel.cs 5.2 KiB

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