123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Globalization;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Input;
- using SAGA.DotNetUtils.Extend;
- using SAGA.MBI.Common;
- using SAGA.MBI.DataArrange;
- using SAGA.MBI.Model;
- using SAGA.MBI.ToolsData.CheckBase;
- namespace SAGA.MBI.ToolsData.ModeCheck
- {
- /// <summary>
- /// WinModeCheckSetting.xaml 的交互逻辑
- /// </summary>
- public partial class WinSelectCheckFloors : INotifyPropertyChanged
- {
- private CheckType m_CheckType;
- public WinSelectCheckFloors()
- {
- InitializeComponent();
- Init();
- this.DataContext = this;
- }
- private void Init()
- {
- ProjectList = MBIControl.ProjectTree.Children;
- if (ProjectList.FirstOrDefault() != null)
- SetTreeItemState(ProjectList.FirstOrDefault(), false);
- }
- #region BindingProperty
- private ObservableCollection<TreeNodeItem> m_ProjectList;
- public ObservableCollection<TreeNodeItem> ProjectList
- {
- get { return m_ProjectList; }
- set { m_ProjectList = value; }
- }
-
- public event PropertyChangedEventHandler PropertyChanged;
- #endregion
- #region Action
-
- private void ButtonNext_OnClick(object sender, RoutedEventArgs e)
- {
- if (CanExecute())
- {
- this.DialogResult = true;
- }
- }
- private bool CanExecute()
- {
- bool result = DalProjectTree.GetSelectedBuilding()?.Id != null; ;
- if (!result)
- {
- MessageBox.Show("请选择需要检查的建筑");
- if (ProjectList.FirstOrDefault() != null)
- SetTreeItemState(ProjectList.FirstOrDefault(), true);
- }
- return result;
- }
- #endregion
-
- private void TreeItem_Click(object sender, RoutedEventArgs e)
- {
- if (sender is CheckBox chk)
- {
- bool state = chk.IsChecked == true;
- if (chk.DataContext is TreeNodeItem node)
- {
- SetTreeItemState(node, state);
- }
- }
- }
- /// <summary>
- /// 设置节点状态
- /// </summary>
- /// <param name="node"></param>
- /// <param name="state"></param>
- private void SetTreeItemState(TreeNodeItem node, bool state)
- {
- node.IsSelected = state;
- SetChildrenState(node, state);
- SetParentState(node, state);
- }
- /// <summary>
- /// 设置子节点状态
- /// </summary>
- /// <param name="node"></param>
- /// <param name="state"></param>
- private void SetChildrenState(TreeNodeItem node, bool state)
- {
- foreach (TreeNodeItem child in node.Children)
- {
- child.IsSelected = state;
- }
- }
- /// <summary>
- /// 设置父节点状态
- /// </summary>
- /// <param name="node"></param>
- /// <param name="state"></param>
- private void SetParentState(TreeNodeItem node, bool state)
- {
- if (node.Parent != null)
- {
- if (node.Parent.Item is MProject)
- {
- if (state)
- {
- foreach (var child in node.Parent.Children)
- {
- if (child != node)
- {
- child.IsSelected = false;
- SetChildrenState(child, false);
- }
- }
- }
- }
- node.Parent.IsSelected = node.Parent.Children.Any(t => t.IsSelected);
- SetParentState(node.Parent, state);
- }
- }
- }
- }
|