WinModeCheckSetting.xaml.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 WinModeCheckSetting : INotifyPropertyChanged
  22. {
  23. private CheckType m_CheckType;
  24. public WinModeCheckSetting(List<ICheckBase> checkItems, CheckType checkType)
  25. {
  26. InitializeComponent();
  27. m_CheckType = checkType;
  28. myListbox.ItemsSource = checkItems;
  29. Init();
  30. this.DataContext = this;
  31. }
  32. private void Init()
  33. {
  34. ProjectList = MBIControl.ProjectTree.Children;
  35. if (ProjectList.FirstOrDefault() != null)
  36. SetTreeItemState(ProjectList.FirstOrDefault(), true);
  37. SavePath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
  38. $"{MBIControl.ProjectCur}{m_CheckType.GetDescription()}检查结果.xlsx");
  39. OFImage = CommonTool.GetBtnImagePath(SavePath);
  40. }
  41. #region BindingProperty
  42. private ObservableCollection<TreeNodeItem> m_ProjectList;
  43. public ObservableCollection<TreeNodeItem> ProjectList
  44. {
  45. get { return m_ProjectList; }
  46. set { m_ProjectList = value; }
  47. }
  48. private string m_SavePath;
  49. /// <summary>
  50. /// 保存路径
  51. /// </summary>
  52. public string SavePath
  53. {
  54. get { return m_SavePath; }
  55. set
  56. {
  57. m_SavePath = value;
  58. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SavePath)));
  59. }
  60. }
  61. private string m_OFImage;
  62. /// <summary>
  63. /// 打开关闭按钮图片
  64. /// </summary>
  65. public string OFImage
  66. {
  67. get { return m_OFImage; }
  68. set { m_OFImage = value; }
  69. }
  70. public event PropertyChangedEventHandler PropertyChanged;
  71. #endregion
  72. #region Action
  73. private void SelectFile_Click(object sender, RoutedEventArgs e)
  74. {
  75. SavePath = DCRExport.GetExportPath(SavePath);
  76. }
  77. private void ButtonNext_OnClick(object sender, RoutedEventArgs e)
  78. {
  79. if (CanExecute())
  80. {
  81. this.DialogResult = true;
  82. }
  83. }
  84. private bool CanExecute()
  85. {
  86. bool result = DalProjectTree.GetSelectedBuilding()?.Id != null; ;
  87. if (!result)
  88. {
  89. MessageBox.Show("请选择需要检查的建筑");
  90. if (ProjectList.FirstOrDefault() != null)
  91. SetTreeItemState(ProjectList.FirstOrDefault(), true);
  92. }
  93. else
  94. {
  95. var list = myListbox.ItemsSource as List<ICheckBase>;
  96. result = list.Any(t => t.RIsChecked);
  97. if (!result)
  98. {
  99. MessageBox.Show("请至少选择一个检查项");
  100. }
  101. }
  102. return result;
  103. }
  104. #endregion
  105. /// <summary>
  106. /// 获取数据检查上下文
  107. /// </summary>
  108. /// <param name="savepath"></param>
  109. /// <returns></returns>
  110. public CheckContext GetCheckContext()
  111. {
  112. CheckContext context = new CheckContext();
  113. context.BuildingId = DalProjectTree.GetSelectedBuilding()?.Id;
  114. context.SavePath = SavePath;
  115. context.TemplatePath = CheckOperation.GetSaveTemplatePath(m_CheckType);
  116. return context;
  117. }
  118. private void TreeItem_Click(object sender, RoutedEventArgs e)
  119. {
  120. if (sender is CheckBox chk)
  121. {
  122. bool state = chk.IsChecked == true;
  123. if (chk.DataContext is TreeNodeItem node)
  124. {
  125. SetTreeItemState(node, state);
  126. }
  127. }
  128. }
  129. /// <summary>
  130. /// 设置节点状态
  131. /// </summary>
  132. /// <param name="node"></param>
  133. /// <param name="state"></param>
  134. private void SetTreeItemState(TreeNodeItem node, bool state)
  135. {
  136. node.IsSelected = state;
  137. SetChildrenState(node, state);
  138. SetParentState(node, state);
  139. CheckCheckItem();
  140. }
  141. /// <summary>
  142. /// 获取检查项的默认选状态
  143. /// </summary>
  144. private void CheckCheckItem()
  145. {
  146. var floors = DalProjectTree.GetSelectedFloors();
  147. if (floors.Count <= 1)
  148. {
  149. var checkItems = myListbox.ItemsSource as List<ICheckBase>;
  150. checkItems?.ForEach(t => { if (t is ModeCheckBase mbase) if (mbase.RIsNeedTwoMoreFloors) t.RIsChecked = false; });
  151. }
  152. }
  153. /// <summary>
  154. /// 设置子节点状态
  155. /// </summary>
  156. /// <param name="node"></param>
  157. /// <param name="state"></param>
  158. private void SetChildrenState(TreeNodeItem node, bool state)
  159. {
  160. foreach (TreeNodeItem child in node.Children)
  161. {
  162. child.IsSelected = state;
  163. }
  164. }
  165. /// <summary>
  166. /// 设置父节点状态
  167. /// </summary>
  168. /// <param name="node"></param>
  169. /// <param name="state"></param>
  170. private void SetParentState(TreeNodeItem node, bool state)
  171. {
  172. if (node.Parent != null)
  173. {
  174. if (node.Parent.Item is MProject)
  175. {
  176. if (state)
  177. {
  178. foreach (var child in node.Parent.Children)
  179. {
  180. if (child != node)
  181. {
  182. child.IsSelected = false;
  183. SetChildrenState(child, false);
  184. }
  185. }
  186. }
  187. }
  188. node.Parent.IsSelected = node.Parent.Children.Any(t => t.IsSelected);
  189. SetParentState(node.Parent, state);
  190. }
  191. }
  192. private void CheckItem_Click(object sender, RoutedEventArgs e)
  193. {
  194. if (sender is CheckBox chk)
  195. {
  196. if (chk.IsChecked == true)
  197. {
  198. var checkItem = chk.DataContext as ModeCheckBase;
  199. if (checkItem.RIsNeedTwoMoreFloors)
  200. {
  201. MessageBox.Show("请选择两个及以上楼层再检查此项");
  202. }
  203. }
  204. }
  205. }
  206. private void CheckItemInverse_OnMouseDown(object sender, MouseButtonEventArgs e)
  207. {
  208. var items = myListbox.ItemsSource as List<ICheckBase>;
  209. if (items != null)
  210. {
  211. foreach (ICheckBase checkBase in items)
  212. {
  213. if (!checkBase.RIsReadOnly)
  214. {
  215. checkBase.RIsChecked = !checkBase.RIsChecked;
  216. }
  217. }
  218. }
  219. }
  220. }
  221. }