123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- /* ==============================================================================
- * 功能描述:CheckOperation
- * 创 建 者:Garrett
- * 创建日期:2018/11/29 17:22:05
- * ==============================================================================*/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using Autodesk.Revit.DB;
- using Autodesk.Revit.UI;
- using FWindSoft.Wpf;
- using NPOI.SS.UserModel;
- using SAGA.DotNetUtils.Extend;
- using SAGA.DotNetUtils.Others;
- using SAGA.RevitUtils.MEP;
- namespace Saga.PlugIn.ModelCheck
- {
- /// <summary>
- /// CheckOperation
- /// </summary>
- public class CheckOperation
- {
- /// <summary>
- /// 获取模型检查的检查项
- /// </summary>
- /// <returns></returns>
- public static List<ICheckBase> GetModeCheckItems()
- {
- List<ModeCheckBase> list = new List<ModeCheckBase>();
- var sagaSignCheck = new SagaSignCheck();
- var types = Assembly.GetCallingAssembly().GetTypes();
- foreach (var type in types)
- {
- if (type.IsSubclassOf(typeof(ModeCheckBase)))
- {
- var attribute = type.GetCustomAttribute<ParseIgnoreAttribute>();
- if (attribute != null)
- continue;
- var constructor = type.GetConstructor(Type.EmptyTypes);
- if (constructor == null)
- continue;
- if (constructor.Invoke(null) is ModeCheckBase checkBase)
- list.Add(checkBase);
- }
- }
- list.Sort(new CommonComparer<ModeCheckBase>((a, b) =>
- {
- var attribute = a.GetType().GetCustomAttribute<ParseIndexAttribute>();
- int i1 = 0;
- if (attribute != null)
- i1 = attribute.Index;
- attribute = b.GetType().GetCustomAttribute<ParseIndexAttribute>();
- int i2 = 0;
- if (attribute != null)
- i2 = attribute.Index;
- return i1.CompareTo(i2);
- }));
- list.ForEach(t =>
- {
- t.SetBaseCheck(sagaSignCheck);
- t.RIsChecked = true;
- });
- list.Insert(0, sagaSignCheck);
- return list.ToList<ICheckBase>();
- }
- /// <summary>
- /// 执行检查并保存
- /// </summary>
- /// <param name="list"></param>
- /// <param name="context"></param>
- public static void Execute(List<ICheckBase> list, Document doc, string savePath, VMModelCheck vm)
- {
- //检查
- list.ForEach(t =>
- {
- t.Check2(doc);
- vm.CurrentIndex++;
- WpfSysCmd.DoEvent();
- });
- //重置workbook准备保存结果
- DCRExport.ClearWorkbook(DCRExport.MCRPath);
- //保存
- list.ForEach(t => t.Export2());
- ExportResultSummary(list);
- DCRExport.Save(savePath, DCRExport.GetWorkbook());
- }
- /// <summary>
- /// 检查结果汇总
- /// </summary>
- /// <param name="list"></param>
- /// <param name="context"></param>
- private static void ExportResultSummary(List<ICheckBase> list)
- {
- try
- {
- IWorkbook book = DCRExport.GetWorkbook();
- string sheetName = "检查结果汇总";
- ISheet sheet = book.GetSheet(sheetName);
- #region 添加数据
- int index = 0;
- foreach (var result in list)
- {
- //数量过多,只显示有问题的
- //if (result.IsRight) continue;
- index++;
- IRow rowN = sheet.CreateRow(index);
- DataCheckNPOIStyle style = result.IsRight ? DataCheckNPOIStyle.Content : DataCheckNPOIStyle.Error;
- int i = 0;
- rowN.AddCell(i++, result.Name, DataCheckNPOIStyle.HyperLink, true);
- //链接到指定页签
- var cellN0 = rowN.GetCell(i - 1);
- cellN0.Hyperlink = DCRExport.CreateLink(result.Name);
- rowN.AddCell(i++, result.RIsChecked ? "是" : "否", style);
- //检查,并且结果为不通过
- string rowN4 = !result.IsRight && result.RIsChecked ? "包含问题数据" : "";
- rowN.AddCell(i++, rowN4, style);
- }
- #endregion
- }
- catch (Exception e)
- {
- MessageShowBase.Show(e);
- }
- }
- }
- }
|