123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- /* ==============================================================================
- * 功能描述:检查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 CorrectAll()
- {
- List<IEnumerable<IGrouping<string, MRevitEquipBase>>> groupss=new List<IEnumerable<IGrouping<string, MRevitEquipBase>>>();
- foreach (TreeNodeItem buildingItem in MBIControl.ProjectTree.Children)
- {
- string buildingId = buildingItem.Item.Id;
- var groups=(Check(buildingId));
- if (groups == null) continue;
- Correct(groups);
- }
- }
- /// <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>
- /// 修正Bimdid重复数据,保留信息点最全的
- /// </summary>
- /// <param name="groups"></param>
- private static void Correct(IEnumerable<IGrouping<string, MRevitEquipBase>> groups)
- {
- foreach (IGrouping<string, MRevitEquipBase> equipBases in groups)
- {
- var list=equipBases.ToList();
- list.Sort((x, y) => { return x.CloundJObject.Count.CompareTo(y.CloundJObject.Count);});
- for (int i = 0; i < list.Count-1; i++)
- {
- var item = list[i];
- item.DelObject();
- }
- }
- }
- /// <summary>
- /// 导出数据
- /// </summary>
- /// <param name="xyzsList"></param>
- private 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
- }
- }
- }
|