CheckOperation.cs 4.0 KB

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