终端一体化运控平台
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

91 Zeilen
3.4 KiB

  1. using BPASmartClient.Helper;
  2. using BPASmartClient.Model;
  3. using BPASmartClient.MorkM.Model;
  4. using Microsoft.Toolkit.Mvvm.ComponentModel;
  5. using Microsoft.Toolkit.Mvvm.Input;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace BPASmartClient.MorkM.ViewModel
  12. {
  13. internal class SimOrderConfitViewModel: ObservableObject
  14. {
  15. bool IsEdit = false;
  16. SimOrderVisibleData simOrderVisibleData;
  17. string DeviceType = string.Empty;
  18. public SimOrderConfitViewModel()
  19. {
  20. // DeviceType = GeneralConfig.StartDevice;
  21. ActionManage.GetInstance.Register(new Action<object>((o) =>
  22. {
  23. if (o != null)
  24. {
  25. if (o is SimOrderVisibleData sim)
  26. {
  27. Name = sim.Text;
  28. Max = sim.MaxValue;
  29. Min = sim.MinValue;
  30. IsEdit = true;
  31. simOrderVisibleData = sim;
  32. }
  33. }
  34. }), "SendSimData");
  35. ConfirmCommand = new RelayCommand(() =>
  36. {
  37. //if (!Json<KeepDataBase>.Data.simOrderConfig.ContainsKey(DeviceType))
  38. //{
  39. // Json<KeepDataBase>.Data.simOrderConfig.TryAdd(DeviceType, new ObservableCollection<SimOrderVisibleData>());
  40. //}
  41. if (!IsEdit)
  42. {
  43. Json<KeepDataBase>.Data.simOrderConfig.Add(new SimOrderVisibleData()
  44. {
  45. IsEnable = true,
  46. IsSelected = true,
  47. Text = Name,
  48. Loc = Min,
  49. MaxValue = Max,
  50. MinValue = Min,
  51. });
  52. }
  53. else
  54. {
  55. int index = Array.FindIndex(Json<KeepDataBase>.Data.simOrderConfig.ToArray(), p => p.Text == simOrderVisibleData.Text);
  56. if (index >= 0 && index < Json<KeepDataBase>.Data.simOrderConfig.Count())
  57. {
  58. Json<KeepDataBase>.Data.simOrderConfig.ElementAt(index).Text = Name;
  59. Json<KeepDataBase>.Data.simOrderConfig.ElementAt(index).MinValue = Min;
  60. Json<KeepDataBase>.Data.simOrderConfig.ElementAt(index).MaxValue = Max;
  61. Json<KeepDataBase>.Data.simOrderConfig.ElementAt(index).IsEnable = simOrderVisibleData.IsEnable;
  62. Json<KeepDataBase>.Data.simOrderConfig.ElementAt(index).IsSelected = simOrderVisibleData.IsSelected;
  63. }
  64. }
  65. ActionManage.GetInstance.Send("SimOrderConfitViewModelExit");
  66. });
  67. CancelCommand = new RelayCommand(() => { ActionManage.GetInstance.Send("SimOrderConfitViewModelExit"); });
  68. }
  69. public RelayCommand ConfirmCommand { get; set; }
  70. public RelayCommand CancelCommand { get; set; }
  71. public string Name { get { return _mName; } set { _mName = value; OnPropertyChanged();; } }
  72. private string _mName;
  73. public ushort Min { get { return _mMin; } set { _mMin = value; OnPropertyChanged(); } }
  74. private ushort _mMin;
  75. public ushort Max { get { return _mMax; } set { _mMax = value; OnPropertyChanged(); } }
  76. private ushort _mMax;
  77. }
  78. }