WinSelectCheckFloors.xaml.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.ComponentModel;
  5. using System.Globalization;
  6. using System.Linq;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Input;
  11. using SAGA.DotNetUtils.Extend;
  12. using SAGA.MBI.Common;
  13. using SAGA.MBI.DataArrange;
  14. using SAGA.MBI.Model;
  15. using SAGA.MBI.ToolsData.CheckBase;
  16. namespace SAGA.MBI.ToolsData.ModeCheck
  17. {
  18. /// <summary>
  19. /// WinModeCheckSetting.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class WinSelectCheckFloors : INotifyPropertyChanged
  22. {
  23. private CheckType m_CheckType;
  24. public WinSelectCheckFloors()
  25. {
  26. InitializeComponent();
  27. Init();
  28. this.DataContext = this;
  29. }
  30. private void Init()
  31. {
  32. ProjectList = MBIControl.ProjectTree.Children;
  33. if (ProjectList.FirstOrDefault() != null)
  34. SetTreeItemState(ProjectList.FirstOrDefault(), false);
  35. }
  36. #region BindingProperty
  37. private ObservableCollection<TreeNodeItem> m_ProjectList;
  38. public ObservableCollection<TreeNodeItem> ProjectList
  39. {
  40. get { return m_ProjectList; }
  41. set { m_ProjectList = value; }
  42. }
  43. public event PropertyChangedEventHandler PropertyChanged;
  44. #endregion
  45. #region Action
  46. private void ButtonNext_OnClick(object sender, RoutedEventArgs e)
  47. {
  48. if (CanExecute())
  49. {
  50. this.DialogResult = true;
  51. }
  52. }
  53. private bool CanExecute()
  54. {
  55. bool result = DalProjectTree.GetSelectedBuilding()?.Id != null; ;
  56. if (!result)
  57. {
  58. MessageBox.Show("请选择需要检查的建筑");
  59. if (ProjectList.FirstOrDefault() != null)
  60. SetTreeItemState(ProjectList.FirstOrDefault(), true);
  61. }
  62. return result;
  63. }
  64. #endregion
  65. private void TreeItem_Click(object sender, RoutedEventArgs e)
  66. {
  67. if (sender is CheckBox chk)
  68. {
  69. bool state = chk.IsChecked == true;
  70. if (chk.DataContext is TreeNodeItem node)
  71. {
  72. SetTreeItemState(node, state);
  73. }
  74. }
  75. }
  76. /// <summary>
  77. /// 设置节点状态
  78. /// </summary>
  79. /// <param name="node"></param>
  80. /// <param name="state"></param>
  81. private void SetTreeItemState(TreeNodeItem node, bool state)
  82. {
  83. node.IsSelected = state;
  84. SetChildrenState(node, state);
  85. SetParentState(node, state);
  86. }
  87. /// <summary>
  88. /// 设置子节点状态
  89. /// </summary>
  90. /// <param name="node"></param>
  91. /// <param name="state"></param>
  92. private void SetChildrenState(TreeNodeItem node, bool state)
  93. {
  94. foreach (TreeNodeItem child in node.Children)
  95. {
  96. child.IsSelected = state;
  97. }
  98. }
  99. /// <summary>
  100. /// 设置父节点状态
  101. /// </summary>
  102. /// <param name="node"></param>
  103. /// <param name="state"></param>
  104. private void SetParentState(TreeNodeItem node, bool state)
  105. {
  106. if (node.Parent != null)
  107. {
  108. if (node.Parent.Item is MProject)
  109. {
  110. if (state)
  111. {
  112. foreach (var child in node.Parent.Children)
  113. {
  114. if (child != node)
  115. {
  116. child.IsSelected = false;
  117. SetChildrenState(child, false);
  118. }
  119. }
  120. }
  121. }
  122. node.Parent.IsSelected = node.Parent.Children.Any(t => t.IsSelected);
  123. SetParentState(node.Parent, state);
  124. }
  125. }
  126. }
  127. }