123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- 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 WinModeCheckSetting : INotifyPropertyChanged
- {
- private CheckType m_CheckType;
- public WinModeCheckSetting(List<ICheckBase> checkItems, CheckType checkType)
- {
- InitializeComponent();
- m_CheckType = checkType;
- myListbox.ItemsSource = checkItems;
- Init();
- this.DataContext = this;
- }
- private void Init()
- {
- ProjectList = MBIControl.ProjectTree.Children;
- if (ProjectList.FirstOrDefault() != null)
- SetTreeItemState(ProjectList.FirstOrDefault(), true);
- SavePath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
- $"{MBIControl.ProjectCur}{m_CheckType.GetDescription()}检查结果.xlsx");
- OFImage = CommonTool.GetBtnImagePath(SavePath);
- }
- #region BindingProperty
- private ObservableCollection<TreeNodeItem> m_ProjectList;
- public ObservableCollection<TreeNodeItem> ProjectList
- {
- get { return m_ProjectList; }
- set { m_ProjectList = value; }
- }
- private string m_SavePath;
- /// <summary>
- /// 保存路径
- /// </summary>
- public string SavePath
- {
- get { return m_SavePath; }
- set
- {
- m_SavePath = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SavePath)));
- }
- }
- private string m_OFImage;
- /// <summary>
- /// 打开关闭按钮图片
- /// </summary>
- public string OFImage
- {
- get { return m_OFImage; }
- set { m_OFImage = value; }
- }
- public event PropertyChangedEventHandler PropertyChanged;
- #endregion
- #region Action
- private void SelectFile_Click(object sender, RoutedEventArgs e)
- {
- SavePath = DCRExport.GetExportPath(SavePath);
- }
- 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);
- }
- else
- {
- var list = myListbox.ItemsSource as List<ICheckBase>;
- result = list.Any(t => t.RIsChecked);
- if (!result)
- {
- MessageBox.Show("请至少选择一个检查项");
- }
- }
- return result;
- }
- #endregion
- /// <summary>
- /// 获取数据检查上下文
- /// </summary>
- /// <param name="savepath"></param>
- /// <returns></returns>
- public CheckContext GetCheckContext()
- {
- CheckContext context = new CheckContext();
- context.BuildingId = DalProjectTree.GetSelectedBuilding()?.Id;
- context.SavePath = SavePath;
- context.TemplatePath = CheckOperation.GetSaveTemplatePath(m_CheckType);
- return context;
- }
- 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);
- CheckCheckItem();
- }
- /// <summary>
- /// 获取检查项的默认选状态
- /// </summary>
- private void CheckCheckItem()
- {
- var floors = DalProjectTree.GetSelectedFloors();
- if (floors.Count <= 1)
- {
- var checkItems = myListbox.ItemsSource as List<ICheckBase>;
- checkItems?.ForEach(t => { if (t is ModeCheckBase mbase) if (mbase.RIsNeedTwoMoreFloors) t.RIsChecked = false; });
- }
- }
- /// <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);
- }
- }
- private void CheckItem_Click(object sender, RoutedEventArgs e)
- {
- if (sender is CheckBox chk)
- {
- if (chk.IsChecked == true)
- {
- var checkItem = chk.DataContext as ModeCheckBase;
- if (checkItem.RIsNeedTwoMoreFloors)
- {
- MessageBox.Show("请选择两个及以上楼层再检查此项");
- }
- }
- }
- }
- private void CheckItemInverse_OnMouseDown(object sender, MouseButtonEventArgs e)
- {
- var items = myListbox.ItemsSource as List<ICheckBase>;
- if (items != null)
- {
- foreach (ICheckBase checkBase in items)
- {
- if (!checkBase.RIsReadOnly)
- {
- checkBase.RIsChecked = !checkBase.RIsChecked;
- }
- }
- }
- }
- }
- }
|