UploadDrawingForm.xaml.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. using CollaborativePlatformMain.CADStartUtil;
  2. using CollaborativePlatformMain.DFEntity;
  3. using CollaborativePlatformMain.DFEntity.MessageSubUtil;
  4. using CollaborativePlatformMain.Form.MessageSubPage.Project;
  5. using CollaborativePlatformMain.Form.UserControlForm;
  6. using DFBIM.CADNETCommon.XmlConfig;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Collections.ObjectModel;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading;
  14. using System.Threading.Tasks;
  15. using System.Windows;
  16. using System.Windows.Controls;
  17. using System.Windows.Data;
  18. using System.Windows.Documents;
  19. using System.Windows.Input;
  20. using System.Windows.Media;
  21. using System.Windows.Media.Imaging;
  22. using System.Windows.Shapes;
  23. namespace CollaborativePlatformMain.Form
  24. {
  25. /// <summary>
  26. /// UploadDrawingForm.xaml 的交互逻辑
  27. /// </summary>
  28. public partial class UploadDrawingForm : Window
  29. {
  30. /// <summary>
  31. /// 父级窗体
  32. /// </summary>
  33. public OperatingFloorPage OperatingFloorPage;
  34. /// <summary>
  35. /// 是否为更新图纸
  36. /// </summary>
  37. public bool IsRenew = false;
  38. /// <summary>
  39. /// 更新、上传图纸
  40. /// </summary>
  41. /// <param name="isRenew"></param>
  42. public UploadDrawingForm(OperatingFloorPage operatingFloorPage, bool isRenew)
  43. {
  44. InitializeComponent();
  45. OperatingFloorPage = operatingFloorPage;
  46. IsRenew = isRenew;
  47. }
  48. /// <summary>
  49. /// 窗体初始化
  50. /// </summary>
  51. /// <param name="sender"></param>
  52. /// <param name="e"></param>
  53. private void Window_Loaded(object sender, RoutedEventArgs e)
  54. {
  55. if (IsRenew)
  56. {
  57. sp_duibi.Visibility = Visibility.Visible;
  58. }
  59. #region 对比版本
  60. ObservableCollection<OperatEntity> operatEntities = OperatingFloorPage.ArchOperaDatas;
  61. //版本号
  62. List<string> versions = new List<string>();
  63. foreach (var operatEntity in operatEntities)
  64. {
  65. versions.AddRange(operatEntity.SubDatas.Select(x => x.Node));
  66. }
  67. cb_dwgName.ItemsSource = null;
  68. cb_dwgName.ItemsSource = versions;
  69. #endregion
  70. }
  71. /// <summary>
  72. /// 单选框点击事件
  73. /// </summary>
  74. /// <param name="sender"></param>
  75. /// <param name="e"></param>
  76. private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
  77. {
  78. RadioButton radioButton = sender as RadioButton;
  79. if (radioButton.Content.Equals("是"))
  80. {
  81. sp_contrast.Visibility = Visibility.Visible;
  82. }
  83. else
  84. {
  85. sp_contrast.Visibility = Visibility.Collapsed;
  86. }
  87. }
  88. /// <summary>
  89. /// 上传图纸
  90. /// </summary>
  91. /// <param name="sender"></param>
  92. /// <param name="e"></param>
  93. private void Button_Click(object sender, RoutedEventArgs e)
  94. {
  95. //List<OperatEntity> operatEntities = OperatingFloorPage.AllOperatDatas;
  96. SetOPerData(ArchLayerDatas, ref OperatingFloorPage.ArchOperaDatas);
  97. SetOPerData(WarmLayerDatas, ref OperatingFloorPage.WarmOperaDatas);
  98. //更新数据
  99. OperatingFloorPage.ReplaceData();
  100. this.Close();
  101. }
  102. /// <summary>
  103. /// 更换数据
  104. /// </summary>
  105. /// <param name="floorLayerDatas"></param>
  106. /// <param name="operatEntities"></param>
  107. public void SetOPerData(List<FloorLayerData> floorLayerDatas, ref ObservableCollection<OperatEntity> operatEntities)
  108. {
  109. //D盘
  110. string dPath = Global.GetDriveLetterExceptC();
  111. //原图纸
  112. WholePictureDataConfigUtil wholePictureDataConfigUtil = new WholePictureDataConfigUtil();
  113. WholePictureData wholePictureData = wholePictureDataConfigUtil.Load<WholePictureData>(string.Format(@"{0}\DFBIM\WholePicture.config", dPath));
  114. //二级
  115. ObservableCollection<OperatEntity> twoDatas = new ObservableCollection<OperatEntity>();
  116. twoDatas.Add(new OperatEntity("原图纸", wholePictureData.Path,
  117. new ObservableCollection<OperatEntity>(), false));
  118. //对比图
  119. if (IsRenew)
  120. {
  121. //对比版本
  122. string banben = cb_dwgName.SelectedItem as string;
  123. //选择的对比范围
  124. if (cb_floor.ItemsSource != null)
  125. {
  126. List<NativeDataInfo> selNativeDatas = cb_floor.ItemsSource.Where(x => x.IsSelect).ToList();
  127. ObservableCollection<OperatEntity> duibiDatas = new ObservableCollection<OperatEntity>();
  128. foreach (var nativeDataInfo in selNativeDatas)
  129. {
  130. if (nativeDataInfo.Name.Contains("F1"))
  131. {
  132. string path = string.Format(@"{0}\DFBIM\协同演示\对比图\F1-对比.dwg", dPath);
  133. duibiDatas.Add(new OperatEntity(nativeDataInfo.Name, path,
  134. new ObservableCollection<OperatEntity>(), false));
  135. }
  136. else if (nativeDataInfo.Name.Contains("F2"))
  137. {
  138. string path = string.Format(@"{0}\DFBIM\协同演示\对比图\F2-对比.dwg", dPath);
  139. duibiDatas.Add(new OperatEntity(nativeDataInfo.Name, path,
  140. new ObservableCollection<OperatEntity>(), false));
  141. }
  142. else if (nativeDataInfo.Name.Contains("F3"))
  143. {
  144. string path = string.Format(@"{0}\DFBIM\协同演示\对比图\F3-对比.dwg", dPath);
  145. duibiDatas.Add(new OperatEntity(nativeDataInfo.Name, path,
  146. new ObservableCollection<OperatEntity>(), false));
  147. }
  148. else if (nativeDataInfo.Name.Contains("F4"))
  149. {
  150. string path = string.Format(@"{0}\DFBIM\协同演示\对比图\F4-对比.dwg", dPath);
  151. duibiDatas.Add(new OperatEntity(nativeDataInfo.Name, path,
  152. new ObservableCollection<OperatEntity>(), false));
  153. }
  154. else if (nativeDataInfo.Name.Contains("F5"))
  155. {
  156. string path = string.Format(@"{0}\DFBIM\协同演示\对比图\F5-对比.dwg", dPath);
  157. duibiDatas.Add(new OperatEntity(nativeDataInfo.Name, path,
  158. new ObservableCollection<OperatEntity>(), false));
  159. }
  160. else if (nativeDataInfo.Name.Contains("F6"))
  161. {
  162. string path = string.Format(@"{0}\DFBIM\协同演示\对比图\F6-对比.dwg", dPath);
  163. duibiDatas.Add(new OperatEntity(nativeDataInfo.Name, path,
  164. new ObservableCollection<OperatEntity>(), false));
  165. }
  166. }
  167. twoDatas.Add(new OperatEntity("对比图-" + banben, "", duibiDatas, false));
  168. }
  169. }
  170. //三级
  171. ObservableCollection<OperatEntity> threeDatas = new ObservableCollection<OperatEntity>();
  172. threeDatas.Add(new OperatEntity("整栋图", wholePictureData.Path, new ObservableCollection<OperatEntity>(), false));
  173. //四级
  174. ObservableCollection<OperatEntity> fourDatas = new ObservableCollection<OperatEntity>();
  175. foreach (var floorLayerData in floorLayerDatas)
  176. {
  177. //五级
  178. ObservableCollection<OperatEntity> fiveDatas = new ObservableCollection<OperatEntity>();
  179. List<FloorLayerData> layersDatas = floorLayerData.SubDatas;
  180. foreach (var layerData in layersDatas)
  181. {
  182. fiveDatas.Add(new OperatEntity(layerData.LayerName, "", new ObservableCollection<OperatEntity>(), true));
  183. }
  184. fourDatas.Add(new OperatEntity(floorLayerData.FloorName, floorLayerData.DWGPath, fiveDatas, false));
  185. }
  186. threeDatas.Add(new OperatEntity("分层图", "", fourDatas, false));
  187. twoDatas.Add(new OperatEntity("治理图纸", "", threeDatas, false));
  188. OperatEntity firstData = new OperatEntity(tb_dwgName.Text.ToString(), "", twoDatas, false);
  189. //添加数据
  190. foreach (var operatEntity in operatEntities)
  191. {
  192. operatEntity.SubDatas.Add(firstData);
  193. break;
  194. }
  195. }
  196. /// <summary>
  197. /// 窗体数据
  198. /// </summary>
  199. public List<FloorLayerData> ArchLayerDatas = new List<FloorLayerData>();
  200. public List<FloorLayerData> StruLayerDatas = new List<FloorLayerData>();
  201. public List<FloorLayerData> WaterLayerDatas = new List<FloorLayerData>();
  202. public List<FloorLayerData> WarmLayerDatas = new List<FloorLayerData>();
  203. public List<FloorLayerData> EleLayerDatas = new List<FloorLayerData>();
  204. /// <summary>
  205. /// 选择图纸
  206. /// </summary>
  207. /// <param name="sender"></param>
  208. /// <param name="e"></param>
  209. private void bt_xaunze_Click(object sender, RoutedEventArgs e)
  210. {
  211. //FloorDrawingForm floorDrawingForm = new FloorDrawingForm(this);
  212. //floorDrawingForm.Show();
  213. StartCADUtil.StartCADMath();
  214. MonitorFloorDataFilePath();
  215. //this.Hide();
  216. }
  217. /// <summary>
  218. /// 监听文件
  219. /// </summary>
  220. public FileSystemWatcher fileSystemWatcher;
  221. /// <summary>
  222. /// 计时器
  223. /// </summary>
  224. public System.Threading.Timer m_timer = null;
  225. /// <summary>
  226. /// 定时器触发间隔
  227. /// </summary>
  228. private int TimeoutMillis = 2000;
  229. public void MonitorFloorDataFilePath()
  230. {
  231. ArchLayerDatas = new List<FloorLayerData>();
  232. // 创建FileSystemWatcher实例
  233. fileSystemWatcher = new FileSystemWatcher();
  234. // 设置要监视的文件夹路径
  235. string dPath = Global.GetDriveLetterExceptC();
  236. fileSystemWatcher.Path = string.Format(@"{0}\DFBIM", dPath);
  237. // 设置要监视的更改类型
  238. fileSystemWatcher.NotifyFilter = NotifyFilters.LastAccess |
  239. NotifyFilters.LastWrite |
  240. NotifyFilters.FileName |
  241. NotifyFilters.DirectoryName;
  242. // 如果有需要,设置过滤条件,例如只监视txt文件
  243. fileSystemWatcher.Filter = "*.config";
  244. // 添加事件处理程序
  245. fileSystemWatcher.Changed += fsw_Changed;
  246. //fileSystemWatcher.Created += OnChanged;
  247. //fileSystemWatcher.Deleted += OnChanged;
  248. //fileSystemWatcher.Renamed += OnRenamed;
  249. // 开始监视
  250. fileSystemWatcher.EnableRaisingEvents = true;
  251. if (m_timer == null)
  252. {
  253. //设置定时器的回调函数。此时定时器未启动
  254. m_timer = new System.Threading.Timer(new TimerCallback(OnChanged),
  255. null, Timeout.Infinite, Timeout.Infinite);
  256. }
  257. }
  258. /// <summary>
  259. /// 文件监听时间
  260. /// </summary>
  261. /// <param name="sender"></param>
  262. /// <param name="e"></param>
  263. void fsw_Changed(object sender, FileSystemEventArgs e)
  264. {
  265. if (e.Name.Contains("FloorLayerData"))
  266. {
  267. //重新设置定时器的触发间隔,并且仅仅触发一次
  268. m_timer.Change(TimeoutMillis, Timeout.Infinite);
  269. }
  270. }
  271. /// <summary>
  272. /// 当文件被更改、创建或删除时调用
  273. /// </summary>
  274. /// <param name="source"></param>
  275. /// <param name="e"></param>
  276. private void OnChanged(object source)
  277. {
  278. string dPath = Global.GetDriveLetterExceptC();
  279. //读取配置文件数据
  280. FloorDataConfigUtil xmlInfo = new FloorDataConfigUtil();
  281. ArchLayerDatas.AddRange(xmlInfo.Load<List<FloorLayerData>>(string.Format(@"{0}\DFBIM\FloorLayerData.config", dPath)));
  282. Dictionary<int, string> keyValuePairs = new Dictionary<int, string>();
  283. keyValuePairs.Add(0, "风管");
  284. keyValuePairs.Add(1, "风机");
  285. keyValuePairs.Add(2, "风口");
  286. keyValuePairs.Add(3, "水管");
  287. keyValuePairs.Add(4, "套管");
  288. List<FloorLayerData> warmDatas = new List<FloorLayerData>();
  289. for (int i = 0; i < ArchLayerDatas.Count; i++)
  290. {
  291. List<FloorLayerData> layerDatas = new List<FloorLayerData>();
  292. for (int j = 0; j < 5; j++)
  293. {
  294. FloorLayerData layerData = new FloorLayerData(keyValuePairs[j]);
  295. layerDatas.Add(layerData);
  296. }
  297. warmDatas.Add(new FloorLayerData(ArchLayerDatas[i].FloorName, "", layerDatas));
  298. }
  299. WarmLayerDatas = warmDatas;
  300. //// 停止监视
  301. //fileSystemWatcher.EnableRaisingEvents = false;
  302. }
  303. /// <summary>
  304. /// 对比版本改变事件
  305. /// 目的:实时刷新对比范围
  306. /// </summary>
  307. /// <param name="sender"></param>
  308. /// <param name="e"></param>
  309. private void cb_dwgName_SelectionChanged(object sender, SelectionChangedEventArgs e)
  310. {
  311. //选中的对比版本
  312. string selValue = cb_dwgName.SelectedItem.ToString();
  313. //对比范围
  314. List<string> floorValues = new List<string>();
  315. bool isBreak = false;
  316. ObservableCollection<OperatEntity> operatEntities = OperatingFloorPage.ArchOperaDatas;
  317. foreach (var operatEntity in operatEntities)
  318. {
  319. //版本号
  320. foreach (var twoData in operatEntity.SubDatas)
  321. {
  322. if (twoData.Node == selValue)
  323. {
  324. //原图、对比图、治理图
  325. foreach (var threeData in twoData.SubDatas)
  326. {
  327. if (threeData.Node.Contains("治理"))
  328. {
  329. //整栋图、分层图
  330. foreach (var fourData in threeData.SubDatas)
  331. {
  332. if (fourData.Node.Contains("分层"))
  333. {
  334. foreach (var fiveData in fourData.SubDatas)
  335. {
  336. floorValues.Add(fiveData.Node);
  337. }
  338. }
  339. }
  340. }
  341. }
  342. isBreak = true;
  343. break;
  344. }
  345. }
  346. if (isBreak) break;
  347. }
  348. //赋值
  349. List<NativeDataInfo> nativeDataInfos = new List<NativeDataInfo>();
  350. foreach (var floorValue in floorValues)
  351. {
  352. nativeDataInfos.Add(new NativeDataInfo(Guid.NewGuid().ToString(), floorValue));
  353. }
  354. cb_floor.ItemsSource = nativeDataInfos;
  355. }
  356. }
  357. }