CheckOperation.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* ==============================================================================
  2. * 功能描述:CheckOperation
  3. * 创 建 者:Garrett
  4. * 创建日期:2018/11/29 17:22:05
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Reflection;
  10. using Autodesk.Revit.DB;
  11. using Autodesk.Revit.UI;
  12. using FWindSoft.Wpf;
  13. using NPOI.SS.UserModel;
  14. using SAGA.DotNetUtils.Extend;
  15. using SAGA.DotNetUtils.Others;
  16. using SAGA.RevitUtils.MEP;
  17. namespace Saga.PlugIn.ModelCheck
  18. {
  19. /// <summary>
  20. /// CheckOperation
  21. /// </summary>
  22. public class CheckOperation
  23. {
  24. /// <summary>
  25. /// 获取模型检查的检查项
  26. /// </summary>
  27. /// <returns></returns>
  28. public static List<ICheckBase> GetModeCheckItems()
  29. {
  30. List<ModeCheckBase> list = new List<ModeCheckBase>();
  31. var sagaSignCheck = new SagaSignCheck();
  32. var types = Assembly.GetCallingAssembly().GetTypes();
  33. foreach (var type in types)
  34. {
  35. if (type.IsSubclassOf(typeof(ModeCheckBase)))
  36. {
  37. var attribute = type.GetCustomAttribute<ParseIgnoreAttribute>();
  38. if (attribute != null)
  39. continue;
  40. var constructor = type.GetConstructor(Type.EmptyTypes);
  41. if (constructor == null)
  42. continue;
  43. if (constructor.Invoke(null) is ModeCheckBase checkBase)
  44. list.Add(checkBase);
  45. }
  46. }
  47. list.Sort(new CommonComparer<ModeCheckBase>((a, b) =>
  48. {
  49. var attribute = a.GetType().GetCustomAttribute<ParseIndexAttribute>();
  50. int i1 = 0;
  51. if (attribute != null)
  52. i1 = attribute.Index;
  53. attribute = b.GetType().GetCustomAttribute<ParseIndexAttribute>();
  54. int i2 = 0;
  55. if (attribute != null)
  56. i2 = attribute.Index;
  57. return i1.CompareTo(i2);
  58. }));
  59. list.ForEach(t =>
  60. {
  61. t.SetBaseCheck(sagaSignCheck);
  62. t.RIsChecked = true;
  63. });
  64. list.Insert(0, sagaSignCheck);
  65. return list.ToList<ICheckBase>();
  66. }
  67. /// <summary>
  68. /// 执行检查并保存
  69. /// </summary>
  70. /// <param name="list"></param>
  71. /// <param name="context"></param>
  72. public static void Execute(List<ICheckBase> list, Document doc, string savePath, VMModelCheck vm)
  73. {
  74. //检查
  75. list.ForEach(t =>
  76. {
  77. t.Check2(doc);
  78. vm.CurrentIndex++;
  79. WpfSysCmd.DoEvent();
  80. });
  81. //重置workbook准备保存结果
  82. DCRExport.ClearWorkbook(DCRExport.MCRPath);
  83. //保存
  84. list.ForEach(t => t.Export2());
  85. ExportResultSummary(list);
  86. DCRExport.Save(savePath, DCRExport.GetWorkbook());
  87. }
  88. /// <summary>
  89. /// 检查结果汇总
  90. /// </summary>
  91. /// <param name="list"></param>
  92. /// <param name="context"></param>
  93. private static void ExportResultSummary(List<ICheckBase> list)
  94. {
  95. try
  96. {
  97. IWorkbook book = DCRExport.GetWorkbook();
  98. string sheetName = "检查结果汇总";
  99. ISheet sheet = book.GetSheet(sheetName);
  100. #region 添加数据
  101. int index = 0;
  102. foreach (var result in list)
  103. {
  104. //数量过多,只显示有问题的
  105. //if (result.IsRight) continue;
  106. index++;
  107. IRow rowN = sheet.CreateRow(index);
  108. DataCheckNPOIStyle style = result.IsRight ? DataCheckNPOIStyle.Content : DataCheckNPOIStyle.Error;
  109. int i = 0;
  110. rowN.AddCell(i++, result.Name, DataCheckNPOIStyle.HyperLink, true);
  111. //链接到指定页签
  112. var cellN0 = rowN.GetCell(i - 1);
  113. cellN0.Hyperlink = DCRExport.CreateLink(result.Name);
  114. rowN.AddCell(i++, result.RIsChecked ? "是" : "否", style);
  115. //检查,并且结果为不通过
  116. string rowN4 = !result.IsRight && result.RIsChecked ? "包含问题数据" : "";
  117. rowN.AddCell(i++, rowN4, style);
  118. }
  119. #endregion
  120. }
  121. catch (Exception e)
  122. {
  123. MessageShowBase.Show(e);
  124. }
  125. }
  126. }
  127. }