CheckOperation.cs 4.7 KB

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