DocumentSetNodes.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.ComponentModel;
  5. using System.Linq;
  6. namespace PRSDesktop
  7. {
  8. public class DocumentSetNode : INotifyPropertyChanged
  9. {
  10. private DocumentSetNodes _owner = null;
  11. public ObservableCollection<DocumentSetNode> Children => _owner.GetChilden(_id);
  12. private Guid _id;
  13. public Guid ID
  14. {
  15. get { return _id; }
  16. set
  17. {
  18. _id = value;
  19. RaisedOnPropertyChanged("ID");
  20. }
  21. }
  22. private Guid _parent;
  23. public Guid Parent
  24. {
  25. get { return _parent; }
  26. set
  27. {
  28. _parent = value;
  29. RaisedOnPropertyChanged("Parent");
  30. }
  31. }
  32. private string _description;
  33. public string Description
  34. {
  35. get { return _description; }
  36. set
  37. {
  38. _description = value;
  39. RaisedOnPropertyChanged("Description");
  40. }
  41. }
  42. private string _details;
  43. public string Details
  44. {
  45. get { return _details; }
  46. set
  47. {
  48. _details = value;
  49. RaisedOnPropertyChanged("Details");
  50. }
  51. }
  52. public Dictionary<String,String> Blocks { get; private set; }
  53. public event PropertyChangedEventHandler PropertyChanged;
  54. public void RaisedOnPropertyChanged(string propertyName)
  55. {
  56. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  57. }
  58. public DocumentSetNode(DocumentSetNodes owner)
  59. {
  60. _owner = owner;
  61. Blocks = new Dictionary<String,String>();
  62. foreach (var column in owner.Columns)
  63. Blocks[column] = "";
  64. }
  65. public DocumentSetNode(DocumentSetNodes owner, Guid id, Guid parent) : this(owner)
  66. {
  67. _id = id;
  68. _parent = parent;
  69. }
  70. }
  71. public class DocumentSetNodes
  72. {
  73. private List<DocumentSetNode> _nodes = null;
  74. public ObservableCollection<DocumentSetNode> Nodes => new ObservableCollection<DocumentSetNode>(_nodes.Where(x=>x.Parent == Guid.Empty));
  75. public IEnumerable<String> Columns { get; private set; }
  76. public DocumentSetNodes(IEnumerable<String> columns)
  77. {
  78. _nodes = new List<DocumentSetNode>();
  79. Columns = columns;
  80. }
  81. public DocumentSetNode Add(Guid id, Guid parent)
  82. {
  83. var node = new DocumentSetNode(this, id, parent);
  84. _nodes.Add(node);
  85. return node;
  86. }
  87. public ObservableCollection<DocumentSetNode> GetChilden(Guid id)
  88. {
  89. return new ObservableCollection<DocumentSetNode>(_nodes.Where(x => x.Parent.Equals(id) && (x.ID != id)));
  90. }
  91. public DocumentSetNode? GetNode(Guid id)
  92. {
  93. return _nodes.FirstOrDefault(x => x.ID == id);
  94. }
  95. }
  96. }