|
@@ -0,0 +1,154 @@
|
|
|
|
+/* ==============================================================================
|
|
|
|
+ * 功能描述:检查BimID是否重复,多个岗位对应一个模型
|
|
|
|
+ * 创 建 者:Garrett
|
|
|
|
+ * 创建日期:2018/12/13 17:25:22
|
|
|
|
+ * ==============================================================================*/
|
|
|
|
+using SAGA.MBI.Calc;
|
|
|
|
+using SAGA.MBI.DataArrange;
|
|
|
|
+using SAGA.MBI.Model;
|
|
|
|
+using SAGA.MBI.RequestData;
|
|
|
|
+using SAGA.MBI.WinView.Upload;
|
|
|
|
+using SAGA.RevitUtils.Extends;
|
|
|
|
+using System;
|
|
|
|
+using System.Collections.Generic;
|
|
|
|
+using System.IO;
|
|
|
|
+using System.Linq;
|
|
|
|
+using System.Text;
|
|
|
|
+using System.Threading.Tasks;
|
|
|
|
+using DevExpress.Data.Helpers;
|
|
|
|
+using Microsoft.Win32;
|
|
|
|
+using NPOI.SS.UserModel;
|
|
|
|
+using NPOI.XSSF.UserModel;
|
|
|
|
+using SAGA.DotNetUtils.Extend;
|
|
|
|
+using SAGA.DotNetUtils.Logger;
|
|
|
|
+using SAGA.DotNetUtils.Others;
|
|
|
|
+using SAGA.MBI.Common;
|
|
|
|
+using SAGA.MBI.Tools;
|
|
|
|
+
|
|
|
|
+namespace SAGA.MBI.ToolsData
|
|
|
|
+{
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// CheckDuplicationBIMId
|
|
|
|
+ /// </summary>
|
|
|
|
+ class CheckDuplicationBIMId
|
|
|
|
+ {
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 检查BIMId是否重复
|
|
|
|
+ /// </summary>
|
|
|
|
+ public static void CheckAll()
|
|
|
|
+ {
|
|
|
|
+ List<IEnumerable<IGrouping<string, MRevitEquipBase>>> groupss=new List<IEnumerable<IGrouping<string, MRevitEquipBase>>>();
|
|
|
|
+ foreach (TreeNodeItem buildingItem in MBIControl.ProjectTree.Children)
|
|
|
|
+ {
|
|
|
|
+ string buildingId = buildingItem.Item.Id;
|
|
|
|
+ groupss.Add(Check(buildingId));
|
|
|
|
+ }
|
|
|
|
+ ExportToExcel(groupss);
|
|
|
|
+ }
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 检查BIMId是否重复
|
|
|
|
+ /// </summary>
|
|
|
|
+ private static IEnumerable<IGrouping<string, MRevitEquipBase>> Check(string buildingId)
|
|
|
|
+ {
|
|
|
|
+ var dutys = DalCommon.GetAllDutys(buildingId);
|
|
|
|
+ var bybimidGroups = dutys.GroupBy(t => t.BimID);
|
|
|
|
+ var exceptionGroups = bybimidGroups.Where(t => t.Count() >= 2 && !t.Key.IsOnlyDutyNoModelBIMID());
|
|
|
|
+ return exceptionGroups;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 导出数据
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="xyzsList"></param>
|
|
|
|
+ public static void ExportToExcel(List<IEnumerable<IGrouping<string, MRevitEquipBase>>> groupss)
|
|
|
|
+ {
|
|
|
|
+ SaveFileDialog sflg = new SaveFileDialog();
|
|
|
|
+ sflg.Filter = "Excel(*.xlsx)|*.xlsx";
|
|
|
|
+ if (sflg.ShowDialog() != true) return;
|
|
|
|
+ string fileName = sflg.FileName;
|
|
|
|
+ IWorkbook book = new XSSFWorkbook();
|
|
|
|
+ ISheet sheet = book.CreateSheet("Summary");
|
|
|
|
+ foreach (IEnumerable<IGrouping<string, MRevitEquipBase>> groups in groupss)
|
|
|
|
+ {
|
|
|
|
+ ExportToExcel(sheet, groups, fileName);
|
|
|
|
+ }
|
|
|
|
+ Save(book, fileName);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 导出数据到指定目录
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="xyzsList"></param>
|
|
|
|
+ /// <param name="fileName"></param>
|
|
|
|
+ private static void ExportToExcel(ISheet sheet, IEnumerable<IGrouping<string, MRevitEquipBase>> groups, string fileName)
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ #region 添加表头
|
|
|
|
+
|
|
|
|
+ IRow row = sheet.CreateRow(0);
|
|
|
|
+ NPOI.SS.UserModel.ICell cell0 = row.CreateCell(0);
|
|
|
|
+ cell0.SetCellType(NPOI.SS.UserModel.CellType.String);
|
|
|
|
+ cell0.SetCellValue("BIMID");
|
|
|
|
+
|
|
|
|
+ ICell cell1 = row.CreateCell(1);
|
|
|
|
+ cell1.SetCellType(CellType.String);
|
|
|
|
+ cell1.SetCellValue("DutyId");
|
|
|
|
+
|
|
|
|
+ #endregion
|
|
|
|
+
|
|
|
|
+ #region 添加数据
|
|
|
|
+
|
|
|
|
+ int index = 1;
|
|
|
|
+ foreach (var group in groups)
|
|
|
|
+ {
|
|
|
|
+ var bimid = group.Key;
|
|
|
|
+ var dutys = "";
|
|
|
|
+ foreach (var equip in group)
|
|
|
|
+ {
|
|
|
|
+ dutys += equip.Id + ";";
|
|
|
|
+ }
|
|
|
|
+ IRow rowN = sheet.CreateRow(index);
|
|
|
|
+ NPOI.SS.UserModel.ICell cellN0 = rowN.CreateCell(0);
|
|
|
|
+ cellN0.SetCellType(NPOI.SS.UserModel.CellType.String);
|
|
|
|
+ cellN0.SetCellValue(bimid);
|
|
|
|
+
|
|
|
|
+ ICell cellN1 = rowN.CreateCell(1);
|
|
|
|
+ cellN1.SetCellType(CellType.String);
|
|
|
|
+ cellN1.SetCellValue(dutys);
|
|
|
|
+ index++;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ #endregion
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e)
|
|
|
|
+ {
|
|
|
|
+ MessageShowBase.Show(e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static void Save(IWorkbook book, string fileName)
|
|
|
|
+ {
|
|
|
|
+ #region 写入
|
|
|
|
+
|
|
|
|
+ MemoryStream ms = new MemoryStream();
|
|
|
|
+ book.Write(ms);
|
|
|
|
+
|
|
|
|
+ using (System.IO.FileStream fs = new System.IO.FileStream(fileName, FileMode.Create, FileAccess.Write))
|
|
|
|
+ {
|
|
|
|
+ byte[] data = ms.ToArray();
|
|
|
|
+ fs.Write(data, 0, data.Length);
|
|
|
|
+ fs.Flush();
|
|
|
|
+ }
|
|
|
|
+ ms.Close();
|
|
|
|
+ ms.Dispose();
|
|
|
|
+
|
|
|
|
+ #endregion
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|