VmVerticalPipeCheck.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* ==============================================================================
  2. * 功能描述:VmVerticalPipeCheck
  3. * 创 建 者:Garrett
  4. * 创建日期:2019/11/5 15:25:33
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading;
  12. using System.Threading.Tasks;
  13. using FWindSoft.Revit;
  14. using FWindSoft.Wpf;
  15. using Saga.PlugIn.CreateFacility;
  16. using Saga.PlugIn.ModelCheck;
  17. using SAGA.DotNetUtils.Extend;
  18. using SAGA.DotNetUtils.WPF;
  19. using SAGA.RevitUtils;
  20. namespace Saga.PlugIn.VerticalPipeCheck
  21. {
  22. /// <summary>
  23. /// VmVerticalPipeCheck
  24. /// </summary>
  25. public class VmVerticalPipeCheck:BaseViewModelStub
  26. {
  27. public VmVerticalPipeCheck()
  28. {
  29. SaveDir = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory));
  30. }
  31. #region Property
  32. private string m_UpFilePath;
  33. /// <summary>
  34. ///
  35. /// </summary>
  36. public string UpFilePath
  37. {
  38. get { return m_UpFilePath; }
  39. set
  40. {
  41. m_UpFilePath = value;
  42. NotifyPropertyChanged("UpFilePath");
  43. }
  44. }
  45. private string m_DownFilePath;
  46. /// <summary>
  47. ///
  48. /// </summary>
  49. public string DownFilePath
  50. {
  51. get { return m_DownFilePath; }
  52. set
  53. {
  54. m_DownFilePath = value;
  55. NotifyPropertyChanged("DownFilePath");
  56. }
  57. }
  58. private string m_SaveDir;
  59. /// <summary>
  60. /// 保存路径
  61. /// </summary>
  62. public string SaveDir
  63. {
  64. get { return m_SaveDir; }
  65. set
  66. {
  67. m_SaveDir = value;
  68. NotifyPropertyChanged("SaveDir");
  69. }
  70. }
  71. private string m_SavePath;
  72. /// <summary>
  73. /// 保存路径
  74. /// </summary>
  75. public string SavePath
  76. {
  77. get { return m_SavePath; }
  78. set
  79. {
  80. m_SavePath = value;
  81. NotifyPropertyChanged("SavePath");
  82. }
  83. }
  84. private ModelCheckState m_ModelCheckState;
  85. public ModelCheckState ModelCheckState
  86. {
  87. get { return m_ModelCheckState; }
  88. set
  89. {
  90. m_ModelCheckState = value;
  91. NotifyPropertyChanged(nameof(ModelCheckState));
  92. }
  93. }
  94. #endregion
  95. [Command]
  96. public void Execute(object param)
  97. {
  98. try
  99. {
  100. switch (ModelCheckState)
  101. {
  102. case ModelCheckState.Prepare:
  103. ModelCheckState = ModelCheckState.Progress;
  104. //刷新界面
  105. WpfSysCmd.DoEvent();
  106. string savePath = Path.Combine(SaveDir,
  107. $"{UpFilePath.GetFileName()}-{DownFilePath.GetFileName()}{"立管检查报告"}{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx");
  108. //为了Ending的界面显示,出问题注释掉
  109. SavePath = savePath;
  110. var taskHandler = RevitHandlerFactory.CreateOnceHandler((a) =>
  111. {
  112. var tuple = VerticalPipeUtil.Execute(UpFilePath, DownFilePath, savePath);
  113. ModelCheckState = ModelCheckState.Ending;
  114. WinTipVPipeCheckComplete win = new WinTipVPipeCheckComplete(tuple?.Item1, tuple?.Item2);
  115. win.ShowDialog();
  116. return HandlerResult.Successed;
  117. });
  118. taskHandler.Execute(RevitCore.UIApp);
  119. break;
  120. case ModelCheckState.Progress:
  121. break;
  122. case ModelCheckState.Ending:
  123. ModelCheckState = ModelCheckState.Prepare;
  124. DownFilePath = UpFilePath;
  125. UpFilePath = "";
  126. break;
  127. }
  128. }
  129. catch (Exception e)
  130. {
  131. MessageShow.Show(e);
  132. }
  133. }
  134. public bool CanExecute(object param)
  135. {
  136. switch (ModelCheckState)
  137. {
  138. case ModelCheckState.Prepare:
  139. if (string.IsNullOrEmpty(UpFilePath) || string.IsNullOrEmpty(DownFilePath) ||
  140. string.IsNullOrEmpty(SaveDir))
  141. return false;
  142. break;
  143. }
  144. return ModelCheckState.Progress != ModelCheckState;
  145. }
  146. [Command]
  147. public void OpenDir(object param)
  148. {
  149. try
  150. {
  151. System.Diagnostics.Process.Start("explorer.exe", SaveDir);
  152. }
  153. catch (Exception e)
  154. {
  155. MessageShow.Show(e);
  156. }
  157. }
  158. public bool CanOpenDir(object param)
  159. {
  160. return true;
  161. }
  162. }
  163. }