RecordViewModel.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using SWRIS.Dtos;
  2. using SWRIS.Enums;
  3. using SWRIS.Extensions;
  4. using System.Collections.Generic;
  5. using System.Collections.ObjectModel;
  6. using System.ComponentModel;
  7. using System.Linq;
  8. namespace SWRIS.Models.ViewModel
  9. {
  10. public class RecordViewModel : INotifyPropertyChanged
  11. {
  12. private GetRecordsInputDto searchInput = new GetRecordsInputDto();
  13. private ObservableCollection<RecordDto> records = new ObservableCollection<RecordDto>();
  14. private bool isAllSelected = false;
  15. public List<KeyAndValueDto> RiskLevels { get; set; } = new List<KeyAndValueDto>() { new KeyAndValueDto { Key = null, Value = "全部" } };
  16. public List<KeyAndValueDto> Ropes { get; set; } = new List<KeyAndValueDto>() { new KeyAndValueDto { Key = null, Value = "全部" } };
  17. public GetRecordsInputDto SearchInput
  18. {
  19. get => searchInput;
  20. set { searchInput = value; OnPropertyChanged("SearchInput"); }
  21. }
  22. public ObservableCollection<RecordDto> Records
  23. {
  24. get => records;
  25. set
  26. {
  27. records = value;
  28. OnPropertyChanged("Records");
  29. }
  30. }
  31. public bool ShowExport
  32. {
  33. get
  34. {
  35. #if DEBUG
  36. return true;
  37. #else
  38. return false;
  39. #endif
  40. }
  41. }
  42. public RecordViewModel()
  43. {
  44. RiskLevels.AddRange(TypeExtension.ToKeyAndDescriptionList(typeof(RiskLevel)).OrderBy(c => c.Key));
  45. Ropes.AddRange(App.Config.Equipments.Select(c => new KeyAndValueDto
  46. {
  47. Key = c.RopeNumber,
  48. Value = c.RopeName
  49. }));
  50. }
  51. public bool IsAllSelected
  52. {
  53. get => isAllSelected;
  54. set
  55. {
  56. if (isAllSelected != value)
  57. {
  58. isAllSelected = value;
  59. OnPropertyChanged("IsAllSelected");
  60. // 当全选复选框状态改变时,更新所有项的选择状态
  61. if (Records != null)
  62. {
  63. foreach (var item in Records)
  64. {
  65. item.IsSelected = value;
  66. }
  67. }
  68. }
  69. }
  70. }
  71. public event PropertyChangedEventHandler PropertyChanged;
  72. protected internal virtual void OnPropertyChanged(string propertyName)
  73. {
  74. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  75. }
  76. }
  77. }